Search Postgresql Archives

Re: which function should i invoke to create a table and insert tuples?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



sunpeng wrote:
it's in source codes,actually i'm writting codes in postgresql source codes,just to verify some of my ideas. C language is used.

you would pass the SQL statements to do what you want to the various libpq library functions...


something like...

   PGconn *conn;
   PGresult *res;

   conn = PQconnectdb("dbname=mydatabase");
   if (PQstatus(conn) != CONNECTION_OK) {
   fprintf(stderr, "Connection to database failed: %s",
   PQerrorMessage(conn));
   exit_nicely(conn);
   }

   res = PQexec(conn, "create table test (id serial, num int, value
   text);");
   if (PQresultStatus(res) != PGRES_COMMAND_OK) {
   fprintf(stderr, "BEGIN command failed: %s", PQerrorMessage(conn));
   PQclear(res);
   exit_nicely(conn);
   }
       ...



most folks would probably put the PQexec() and status tests into a function to simplify things.


--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux