Re: how to call the function--pqCatenateResultError()

Lists: pgsql-hackers
From: _石头 <tanjia76(at)qq(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: how to call the function--pqCatenateResultError()
Date: 2011-06-28 03:57:07
Message-ID: tencent_1C7659F147F5199D2897BBD2@qq.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello!~

Now i encounter a function call problem in PostgreSQL's psql module!

The situation is as follow:
In ./src/bin/psql/common.c, I want to call the function pqCatenateResultError().
Function pqCatenateResultError() is declared in ./src/interfaces/libpq/libpq-init.h
extern void pqCatenateResultError(PGresult *res, const char *msg);
and is defined in ./src/interfaces/libpq/fe-exec.c
void
pqCatenateResultError(PGresult *res, const char *msg)
{
PQExpBufferData errorBuf;
if (!res || !msg)
return;
initPQExpBuffer(&errorBuf);
if (res->errMsg)
appendPQExpBufferStr(&errorBuf, res->errMsg);
appendPQExpBufferStr(&errorBuf, msg);
pqSetResultError(res, errorBuf.data);
termPQExpBuffer(&errorBuf);
}

To call this function in ./common.c, I include 'libpq-init.h' in ./src/bin/psql/common.h .
As ./common.c include the header file 'common.h'.

But when I use pqCatenateResultError() in ./common.c, It appears "undefined reference to pqCatenateResultError()" first.

So I include 'extern void pqCatenateResultError(PGresult *res, const char *msg);' at the begining of './common.c' .
But this change make no difference to the result.

I do not know why this happened! Someone hlep me! Thank you.

There is another situation similar to the situation above:
Function PQexec() is declared in ./src/interfaces/libpq/libpq-fe.h and defined in ./src/interfaces/libpq/fe-exec.c
extern PGresult *PQexec(PGconn *conn, const char *query);
I can call this function with no error happening!

These two situation puzzled me!~

From: Stone


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: _石头 <tanjia76(at)qq(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: how to call the function--pqCatenateResultError()
Date: 2011-06-30 12:47:11
Message-ID: BANLkTi=b=UFginQFoa+EzuhnygNYsDRy+Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2011/6/27 _石头 <tanjia76(at)qq(dot)com>:
> Hello!~
>
>        Now i encounter a function call problem in PostgreSQL's psql module!
>
>        The situation is as follow:
>         In ./src/bin/psql/common.c, I want to call the
> function pqCatenateResultError().
>         Function pqCatenateResultError() is declared in
> ./src/interfaces/libpq/libpq-init.h
>                                     extern void
> pqCatenateResultError(PGresult *res, const char *msg);
>         and is defined in ./src/interfaces/libpq/fe-exec.c
>                                void
>                                pqCatenateResultError(PGresult *res, const
> char *msg)
>                               {
>                           PQExpBufferData errorBuf;
>                           if (!res || !msg)
>                              return;
>                           initPQExpBuffer(&errorBuf);
>                           if (res->errMsg)
>                   appendPQExpBufferStr(&errorBuf, res->errMsg);
>                           appendPQExpBufferStr(&errorBuf, msg);
>                           pqSetResultError(res, errorBuf.data);
>                           termPQExpBuffer(&errorBuf);
>                               }
>       To call this function in ./common.c, I include 'libpq-init.h' in
> ./src/bin/psql/common.h .
>       As ./common.c include the header file 'common.h'.
>      But when I use pqCatenateResultError() in ./common.c, It appears
> "undefined reference to pqCatenateResultError()" first.
>
>      So I include 'extern void pqCatenateResultError(PGresult *res, const
> char *msg);' at the begining of './common.c' .
>      But this change make no difference to the result.
>
>       I do not know why this happened! Someone hlep me!  Thank you.
>       There is another situation similar to the situation above:
>       Function PQexec() is declared in ./src/interfaces/libpq/libpq-fe.h and
> defined in ./src/interfaces/libpq/fe-exec.c
>                              extern PGresult *PQexec(PGconn *conn, const
> char *query);
>       I can call this function with no error happening!
>       These two situation puzzled me!~

Are you developing on Windows, by any chance?

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company