2
繼續從this previous question: 在PostgreSQL源代碼中有一個名爲postgres.c
的文件,位於src/backend/tcop
。裏面有一個叫做exec_simple_query()
的功能。我想在postgres.c
的同一文件夾中添加一行,該行的名稱爲start_create_profile()
,位於另一個名爲test.c
的文件中。擴展postgresql代碼
我在eclipse上使用linux(kubuntu/ubuntu)。我跟着本教程創建環境http://wiki.postgresql.org/wiki/Working_with_Eclipse
這是test.c的:
#include "postgres.h"
#ifndef PROGPROFILE_H_
#define PROGPROFILE_H_
/* interfaces */
extern void start_create_profile(List *querytree_list);
extern void create_profile();
extern void check_anomaly(List *querytree_list);
#endif /* Test ProgProf */
void start_create_profile(List *querytree_list){
ListCell *l;
ListCell *tl;
FILE *f;
//if the file exist just open and write
//else create and write
f = fopen ("QueryParsed.txt", "a+");
Query *query_idr = (Query *)linitial(querytree_list);
// CMD_SELECT=0 CMD_INSERT=1 CMD_UPDATE=2
switch (query_idr->commandType)
{
case CMD_SELECT:
fputs("CMD_SELECT, ", f);
break;
case CMD_INSERT:
fputs("CMD_INSERT, ", f);
break;
case CMD_UPDATE:
fputs("CMD_UPDATE, ", f);
break;
default:
break;
}
//to have the ID of the table
foreach(l, query_idr->rtable){
Oid tab_idT = ((RangeTblEntry *) lfirst(l)) ->relid;
//char temp1[10];
char *tab_idTConverted = itoa(tab_idT);
/* This is not a table */
if (tab_idT == 0)
continue;
fputs(" tab_id: , ", f);
fputs(tab_idTConverted, f);
}
//to have the name of the targer list
foreach(tl, query_idr->targetList){
TargetEntry *tle = (TargetEntry *) lfirst(tl);
Oid tab_id = tle->resorigtbl;
int tab_idCast=(int)tab_id;
//char temp[10];
char *tab_idConverted = itoa(tab_idCast);
char *resname=tle->resname;
fputs("Name of column: ", f);
fputs(resname, f);
fputs(" ID: ", f);
fputs(tab_idConverted, f);
fputs("\n", f);
}
//close the file that we write
fputs("$", f);
fclose (f);
}
void create_profile(){
}
void check_anomaly(List *querytree_list){
}
但是,當我點擊構建我得到這個錯誤:
Description Path Resource Location Type
make: *** [all] Error 2 pgsql C/C++ Problem
make[1]: *** [all] Error 2 pgsql C/C++ Problem
make[2]: *** [postgres] Error 1 pgsql C/C++ Problem
undefined reference to `start_create_profile' /pgsql/src/backend/tcop postgres.c C/C++ Problem
我認爲這個問題必須與修改postgres源代碼有關。任何想法??
感謝
您如何看待exec_simple_query()應該知道如何找到start_create_profile()? – 2013-02-27 01:46:48
謝謝你的時間。我不知道如何將test.c與postgreSQL鏈接起來。鏈接它們正是我所不知道的 – Alex 2013-02-27 02:04:32
函數exec_simple_query()調用函數pgstat_report_activity()。當編譯器編譯postgres.c時,它如何知道如何找到pgstat_report_activity()? (提示:它不會猜測。) – 2013-02-27 02:20:56