Re: [SQL] Questions about embedded-sql!

From: "Gene Selkov, Jr(dot)" <selkovjr(at)mcs(dot)anl(dot)gov>
To: "Anna Langer" <anna_langer(at)hotmail(dot)com>, pgsql-interfaces(at)postgreSQL(dot)org
Subject: Re: [SQL] Questions about embedded-sql!
Date: 1999-04-20 13:30:02
Message-ID: 199904201429.JAA28430@antares.mcs.anl.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

With the subject like this, you will get more help from the INTERFACES list.

> 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 about embedded-sql in C or C++? Does anybody know where we
> can find anyting about CURSOR?
>
> We really need some help!!!!
>
> Anna and Maria

The piece you quoted does not look like embedded sql to me, but you're
the boss ;-)

It should, however work, if all of the following is true:

1. You have a running postmaster and it accepts connections from your client
2. The database you are connecting to exists and has the table test1
3. The connection whose handle you are referring to (conn) was
established and you did not get any errors from it.

Also, when sending a SELECT statement with libpq, you are supposed to
check the result against PGRES_TUPLES_OK. You will use
PGRES_COMMAND_OK to check the status of those commands that don't
return any tuples, such as CREATE or INSERT.

Always check conn->errorMessage in case of errors to find what causes them

You don't have to use cursors, but that's about all you can do if your
client must be able to page through lots of results.

Now if you really meant using embedded sql, take a look at

/whatever_is_your_postgres_source_dir/src/interfaces/ecpg/test

--Gene

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Kent Perrier 1999-04-20 13:55:18 Compiling jdbc for Linux and Solaris
Previous Message Karl DeBisschop 1999-04-20 13:17:42 Re: [GENERAL] problem when vacuuming. . .