首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >扩展postgresql代码

扩展postgresql代码
EN

Stack Overflow用户
提问于 2013-02-27 09:19:10
回答 1查看 325关注 0票数 2

this previous question之后:在PostgreSQL源代码中,src/backend/tcop中有一个名为postgres.c的文件。里面有一个名为exec_simple_query()的函数。我想添加一行调用start_create_profile()的代码行,该代码行位于与postgres.c相同的文件夹中的另一个名为test.c的文件中。

我正在linux上使用eclipse (kubuntu/ubuntu)。我按照本教程创建了环境http://wiki.postgresql.org/wiki/Working_with_Eclipse

这是test.c:

代码语言:javascript
复制
#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){

}

但是,当我单击build时,我得到了这个错误:

代码语言:javascript
复制
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源代码有关。有什么想法吗?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-27 12:06:27

您可以解决在src/backend/tcop的makefile对象中添加test.o的问题。

一个实例可以是

代码语言:javascript
复制
subdir = src/backend/tcop
top_builddir = ../../..
include $(top_builddir)/src/Makefile.global

OBJS= dest.o fastpath.o postgres.o pquery.o utility.o test.o

ifneq (,$(filter $(PORTNAME),cygwin win32))
override CPPFLAGS += -DWIN32_STACK_RLIMIT=$(WIN32_STACK_RLIMIT)
endif

include $(top_srcdir)/src/backend/common.mk
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15102536

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档