/*************************************************************************** mainCpq.c - description ------------------- begin : 六 7月 19 2003 copyright : (C) 2003 by nan sha Itpark email : zuojin@itpark85 ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include int main() { PGconn *conn; PGresult *res; char *pghost = NULL; char *pgport =NULL; char *pgoptions =NULL; char *pgtty = NULL; char *dbname ="test_db";/**数据库名*/ int i = 0,t = 0,s,k; conn = PQsetdb(pghost,pgport,pgoptions,pgtty,dbname); if (PQstatus(conn) == CONNECTION_BAD) { fprintf(stderr,"Connection to database '%s' failed!\n",dbname); PQfinish(conn); return 0; } res = PQexec(conn,"SELECT * FROM test"); if( PQresultStatus(res) != PGRES_TUPLES_OK) { fprintf(stderr,"Exec Query Fauled!\n"); PQclear(res); return 0; } i = PQntuples(res);/**取得查询的结果的记录的数量*/ t = PQnfields(res);/**取得字段数量*/ for(s=0;s