pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedQuestions about embedded-sql!
4+ messages / 4 participants
[nested] [flat]
* Questions about embedded-sql!
@ 1999-04-20 02:18 Anna Langer <anna_langer@hotmail.com>
1999-04-20 14:10 ` Re: [SQL] Questions about embedded-sql! Maarten Boekhold <boekhold@tibco.com>
1999-04-20 14:35 ` Re: [SQL] Questions about embedded-sql! Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 2 replies; 4+ messages in thread
From: Anna Langer @ 1999-04-20 02:18 UTC (permalink / raw)
To: pgsql-sql
Hi!
We are having some problems with writing embedded-sql. We want to
write like this but it doesn't work. test1 is our table in our
database.
res = PQexec(conn, "select * from test1");
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
{
fprintf(stderr, "DECLARE CURSOR command failed\n");
PQclear(res);
exit_nicely(conn);
}
PQclear(res);
In the example that we have get this part from are they using CURSORS.
Do you have to use them? Does anybody know where we can find some
examples anbout embedded-sql in C or C++? Does anybody know where we
can find anyting about CURSOR?
We really need some help!!!!
Anna and Maria
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [SQL] Questions about embedded-sql!
1999-04-20 02:18 Questions about embedded-sql! Anna Langer <anna_langer@hotmail.com>
@ 1999-04-20 14:10 ` Maarten Boekhold <boekhold@tibco.com>
1 sibling, 0 replies; 4+ messages in thread
From: Maarten Boekhold @ 1999-04-20 14:10 UTC (permalink / raw)
To: Anna Langer <anna_langer@hotmail.com>; +Cc: pgsql-sql
Anna Langer wrote:
>
> Hi!
>
> We are having some problems with writing embedded-sql. We want to
> write like this but it doesn't work. test1 is our table in our
> database.
>
> res = PQexec(conn, "select * from test1");
> if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
> {
> fprintf(stderr, "DECLARE CURSOR command failed\n");
> PQclear(res);
> exit_nicely(conn);
> }
> PQclear(res);
"select * from test1" is not a 'command', at least not as libpq is
concerned. A select statement is some 'data-returning' thingie, so
you'll want to check for PGRES_TUPLES_OK instead of PGRES_COMMAND_OK.
> In the example that we have get this part from are they using CURSORS.
> Do you have to use them? Does anybody know where we can find some
Yes, cursors are very handy. It allows you to get to your datarows one
at a time without having to load them all into the memory of your
application. Basically:
BEGIN; --- cursors only work inside a transaction
DECLARE c CURSOR FOR select * from test1;
FETCH IN c; --- gets the first row
FETCH IN c; --- gets the second row
END; --- gets rid of the cursor *and* the transaction
> examples anbout embedded-sql in C or C++? Does anybody know where we
> can find anyting about CURSOR?
btw. what you are doing is not embedded SQL. You are using the Call
Level API (CLI). Embedded SQL enables you to put SQL statements inside
your program without having to bother with this CLI (i.e. the stuff you
do above). It does however require a pre-processor. You run this
preprocessor over your source code before you run the compiler. The
preprocessor converts all the SQL statements into the appropriate CLI
instructions. Postgresql has such a preprocessor for embedded SQL, it's
called ecpg. Read all about it in its documentation.
Maarten
--
Maarten Boekhold, boekhold@tibco.com
TIBCO Finance Technology Inc.
The Atrium
Strawinskylaan 3051
1077 ZX Amsterdam, The Netherlands
tel: +31 20 3012158, fax: +31 20 3012358
http://www.tibco.com
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [SQL] Questions about embedded-sql!
1999-04-20 02:18 Questions about embedded-sql! Anna Langer <anna_langer@hotmail.com>
@ 1999-04-20 14:35 ` Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 4+ messages in thread
From: Tom Lane @ 1999-04-20 14:35 UTC (permalink / raw)
To: Anna Langer <anna_langer@hotmail.com>; +Cc: pgsql-sql
"Anna Langer" <anna_langer@hotmail.com> writes:
> We are having some problems with writing embedded-sql. We want to
> write like this but it doesn't work. test1 is our table in our
> database.
> res = PQexec(conn, "select * from test1");
> if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
> {
> fprintf(stderr, "DECLARE CURSOR command failed\n");
> ...
A successful SELECT query will return status PGRES_TUPLES_OK,
not PGRES_COMMAND_OK. You probably adapted this code from
an example that was executing a command that cannot return
tuples (DECLARE CURSOR, no doubt?). PGRES_COMMAND_OK is the
right thing in that case.
You should read the documentation and sample programs
for libpq ...
regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [SQL] Questions about embedded-sql!
@ 1999-04-20 12:30 Magnum Ind. da Amazonia S/A <relmag@intervista.com.br>
0 siblings, 0 replies; 4+ messages in thread
From: Magnum Ind. da Amazonia S/A @ 1999-04-20 12:30 UTC (permalink / raw)
To: pgsql-sql
anna_langer@hotmail.com wrote:
>
> Hi!
>
> We are having some problems with writing embedded-sql.
...
> res = PQexec(conn, "select * from test1");
> if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
> {
> fprintf(stderr, "DECLARE CURSOR command failed\n");
> PQclear(res);
> exit_nicely(conn);
> }
> PQclear(res);
>
...
>
> We really need some help!!!!
>
> Anna and Maria
Hi Anna and Maria
The sample code above is not embedded-sql.
What do you really need? Help in embedded-sql or
help in the use of "libpq"?
You can find some sample in both case in postgres'
documentation.
(if you use postgres 6.3.2 have same typos errors
in documentation in postscript format, in html is
right)
Paulo
System Manager
jpbsilva@intervista.com.br
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~1999-04-20 14:35 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-04-20 02:18 Questions about embedded-sql! Anna Langer <anna_langer@hotmail.com>
1999-04-20 14:10 ` Maarten Boekhold <boekhold@tibco.com>
1999-04-20 14:35 ` Tom Lane <tgl@sss.pgh.pa.us>
1999-04-20 12:30 Re: [SQL] Questions about embedded-sql! Magnum Ind. da Amazonia S/A <relmag@intervista.com.br>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox