agora inbox for postgres@postgres.berkeley.edu
help / color / mirror / Atom feedPQExec inside a C function?
4+ messages / 3 participants
[nested] [flat]
* PQExec inside a C function?
@ 1994-06-28 03:31 Bruce Thomson <bruce@comu11.auckland.ac.nz>
1994-06-28 06:48 ` Re: PQExec inside a C function? Paul M. Aoki <aoki@CS.Berkeley.EDU>
0 siblings, 1 reply; 4+ messages in thread
From: Bruce Thomson @ 1994-06-28 03:31 UTC (permalink / raw)
To: legacy; +Cc: Bruce Thomson <bruce@ccvcom.auckland.ac.nz>
I am trying to call a user function from within the monitor that should
do some PQExec'd insertions into a table.
The function is shown below.
Unfortunately, I get the following results from 'monitor'.
Can I execute embedded postquel statements in this way?
If not, what would be the best way to eventually call an external program,
and insert its results (from an output file) into a table, all from a
monitor retrieve command?
Thanks for any help.
-----------------------------------------------
Welcome to the POSTGRES terminal monitor
Go
* define function isert_row (language="C", returntype=int4)
arg is (int4)
as "/home/sun/bruce/postgres/pqexec/insert.so"\g
Query sent to backend is "define function isert_row (language="C", returntype=int4) arg is (int4) as "/home/sun/bruce/postgres/pqexec/insert.so""
DEFINE
Go
* load "/home/sun/bruce/postgres/pqexec/insert.so"\g
Query sent to backend is "load "/home/sun/bruce/postgres/pqexec/insert.so""
LOAD
Go
* retrieve (result=insert_row(5))\g
Query sent to backend is "retrieve (result=insert_row(5))"
FATAL: no response from backend: detected in dump_data
Go
* retrieve (twoval.all)\g
Query sent to backend is "retrieve (twoval.all)"
FATAL: no response from backend: detected in PQexec
Go
* \q
Broken pipe
-----------------------------
#include <stdio.h>
#include "tmp/libpq.h"
int insert_row(x)
int x;
{
char append_line[100]; /* care not to run over the length */
PQsetdb ("external");
PQexec("begin");
sprintf(append_line,"append twovals(x1=%d,x2=%d)",x,x*2);
PQexec(append_line);
PQexec("end");
PQfinish();
return(0);
}
-------------------------------
-----------------------------------------------------------------------------
Bruce Thomson bruce@comu11.auckland.ac.nz
e-mail for pgp key
-----------------------------------------------------------------------------
==============================================================================
To add/remove yourself to/from the POSTGRES mailing list: send mail with
the subject line ADD or DEL to "postgres-request@postgres.Berkeley.EDU"
If this fails, send mail to "post_questions@postgres.Berkeley.EDU" and
a human will deal with it. DO NOT post to the "postgres" mailing list.
==============================================================================
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: PQExec inside a C function?
1994-06-28 03:31 PQExec inside a C function? Bruce Thomson <bruce@comu11.auckland.ac.nz>
@ 1994-06-28 06:48 ` Paul M. Aoki <aoki@CS.Berkeley.EDU>
0 siblings, 0 replies; 4+ messages in thread
From: Paul M. Aoki @ 1994-06-28 06:48 UTC (permalink / raw)
To: Bruce Thomson <bruce@comu11.auckland.ac.nz>; +Cc: legacy
bruce@comu11.auckland.ac.nz (Bruce Thomson) writes:
> I am trying to call a user function from within the monitor that should
> do some PQExec'd insertions into a table.
> PQsetdb ("external");
> PQexec("begin");
^^^^^
> sprintf(append_line,"append twovals(x1=%d,x2=%d)",x,x*2);
> PQexec(append_line);
> PQexec("end");
^^^
if this is postgres 4.x, x<2, this won't work at all.
if this is 4.2, you stand some chance but you don't want to use begin/end.
(all backend "libpq" calls are executed in the same transaction already.)
you also don't want to link your function with libpq, *ever*, if it's going
to be used in the backend -- there are equivalent functions in the backend.
i don't think you need to do PQsetdb since you're already in a backend
that is attached to a database.
in general this interface has a lot of problems. i don't particularly
recommend it though the alternative (direct access method calls) isn't
very nice either.
--
Paul M. Aoki | CS Div., Dept. of EECS, UCB | aoki@CS.Berkeley.EDU
| Berkeley, CA 94720-1776 | ...!uunet!ucbvax!aoki
==============================================================================
To add/remove yourself to/from the POSTGRES mailing list: send mail with
the subject line ADD or DEL to "postgres-request@postgres.Berkeley.EDU"
If this fails, send mail to "post_questions@postgres.Berkeley.EDU" and
a human will deal with it. DO NOT post to the "postgres" mailing list.
==============================================================================
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: PQExec inside a C function?
@ 1994-06-28 07:47 J.Plewe <joerg.plewe@mpi-dortmund.mpg.de>
0 siblings, 0 replies; 4+ messages in thread
From: J.Plewe @ 1994-06-28 07:47 UTC (permalink / raw)
To: legacy
>
> I am trying to call a user function from within the monitor that should
> do some PQExec'd insertions into a table.
>
> The function is shown below.
>
>
>
> Unfortunately, I get the following results from 'monitor'.
> Can I execute embedded postquel statements in this way?
>
> If not, what would be the best way to eventually call an external program,
> and insert its results (from an output file) into a table, all from a
> monitor retrieve command?
>
> Go
> * define function isert_row (language="C", returntype=int4)
> arg is (int4)
> as "/home/sun/bruce/postgres/pqexec/insert.so"\g
>
> Query sent to backend is "define function isert_row (language="C", returntype=int4) arg is (int4) as "/home/sun/bruce/postgres/pqexec/insert.so""
> DEFINE
> Go
> * load "/home/sun/bruce/postgres/pqexec/insert.so"\g
>
> Query sent to backend is "load "/home/sun/bruce/postgres/pqexec/insert.so""
> LOAD
> Go
> * retrieve (result=insert_row(5))\g
>
> -----------------------------
> #include <stdio.h>
> #include "tmp/libpq.h"
>
> int insert_row(x)
> int x;
> {
> char append_line[100]; /* care not to run over the length */
>
> PQsetdb ("external");
> PQexec("begin");
> sprintf(append_line,"append twovals(x1=%d,x2=%d)",x,x*2);
> PQexec(append_line);
> PQexec("end");
> PQfinish();
> return(0);
> }
> -------------------------------
Hi!
I wonder how you managed to come so far, because I dealt with a similar
problem this night on my linux-pg4.2.
I did some investigations this morning and found some things about this:
Using the functions PQsetdb() and PQfinish() should cause some trouble,
because theire symbols are not defined in the postgres executable.
So you have to link your object with libpq.a.
This on the other hand should cause trouble using the 'load' command,
because now you have duplicate symbols (e.g. PQexec() in the postgres
executable as well as in your dot-oh file).
Maybe its legal to write such functions omitting PQsetdb() and PQfinish()?
The following PQxxxx-Symbols are defined in the postgres executable:
nm postgres | grep PQ
000175ec T _GetPQChar
00017660 T _GetPQInt4
000176f4 T _GetPQStr
0011bc90 B _PQAsyncNotifyWaiting
00046ef0 t _PQGetTupleBlock
00047224 T _PQappendNotify
000470e4 T _PQcleanNotify
000470b4 T _PQclear
0011ac90 B _PQerrormsg
00044f74 T _PQexec
00044e70 T _PQfn
00046cf8 T _PQfname
00046a04 T _PQfnameGroup
00046c6c T _PQfnumber
00046978 T _PQfnumberGroup
00046d94 T _PQftype
00046b48 T _PQgetgroup
00047074 T _PQgetlength
00045980 T _PQgetline
00047034 T _PQgetvalue
00046aa0 T _PQgroup
00046c04 T _PQnfields
00046910 T _PQnfieldsGroup
00046864 T _PQngroups
00046850 T _PQninstances
000468f8 T _PQninstancesGroup
000471fc T _PQnotifies
00047180 T _PQnotifies_init
00046620 T _PQnportals
00046824 T _PQntuples
00046890 T _PQntuplesGroup
000467a0 T _PQparray
000466c0 T _PQpnames
00045a5c T _PQputline
0004721c T _PQremoveNotify
000467f8 T _PQrulep
00046e38 T _PQsametype
00046604 T _PQtrace
000eff9c D _PQtracep
00046614 T _PQuntrace
000175c8 T _SetPQSocket
00045000 T _pqtest_PQexec
00045244 T _pqtest_PQfn
As a guess, perhaps you try your source without PQsetdb() and PQfinish()???
- Joerg
*********************************************************************
Dipl. Phys. Joerg Plewe joerg.plewe@mpi-dortmund.mpg.de
MPI fuer molekulare Physiologie
Rheinlanddamm 201
44139 Dortmund
Germany +49 (0)231 1206 384
*********************************************************************
==============================================================================
To add/remove yourself to/from the POSTGRES mailing list: send mail with
the subject line ADD or DEL to "postgres-request@postgres.Berkeley.EDU"
If this fails, send mail to "post_questions@postgres.Berkeley.EDU" and
a human will deal with it. DO NOT post to the "postgres" mailing list.
==============================================================================
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: PQExec inside a C function?
@ 1994-06-28 11:20 J.Plewe <joerg.plewe@mpi-dortmund.mpg.de>
0 siblings, 0 replies; 4+ messages in thread
From: J.Plewe @ 1994-06-28 11:20 UTC (permalink / raw)
To: legacy
> bruce@comu11.auckland.ac.nz (Bruce Thomson) writes:
> > I am trying to call a user function from within the monitor that should
> > do some PQExec'd insertions into a table.
>
> > PQsetdb ("external");
> > PQexec("begin");
> ^^^^^
> > sprintf(append_line,"append twovals(x1=%d,x2=%d)",x,x*2);
> > PQexec(append_line);
> > PQexec("end");
> ^^^
>
> if this is postgres 4.x, x<2, this won't work at all.
>
> if this is 4.2, you stand some chance but you don't want to use begin/end.
> (all backend "libpq" calls are executed in the same transaction already.)
> you also don't want to link your function with libpq, *ever*, if it's going
> to be used in the backend -- there are equivalent functions in the backend.
> i don't think you need to do PQsetdb since you're already in a backend
> that is attached to a database.
To my opinion, PQsetdb ist *not* defined in the backend, so you cannot even
use it.
I tried to do a PQexec without PQsetdb, and it worked as expected.
- Joerg
*********************************************************************
Dipl. Phys. Joerg Plewe joerg.plewe@mpi-dortmund.mpg.de
MPI fuer molekulare Physiologie
Rheinlanddamm 201
44139 Dortmund
Germany +49 (0)231 1206 384
*********************************************************************
==============================================================================
To add/remove yourself to/from the POSTGRES mailing list: send mail with
the subject line ADD or DEL to "postgres-request@postgres.Berkeley.EDU"
If this fails, send mail to "post_questions@postgres.Berkeley.EDU" and
a human will deal with it. DO NOT post to the "postgres" mailing list.
==============================================================================
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~1994-06-28 11:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1994-06-28 03:31 PQExec inside a C function? Bruce Thomson <bruce@comu11.auckland.ac.nz>
1994-06-28 06:48 ` Paul M. Aoki <aoki@CS.Berkeley.EDU>
1994-06-28 07:47 Re: PQExec inside a C function? J.Plewe <joerg.plewe@mpi-dortmund.mpg.de>
1994-06-28 11:20 Re: PQExec inside a C function? J.Plewe <joerg.plewe@mpi-dortmund.mpg.de>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox