/* * Test case for PQsendDescribePrepared * Need first to run this query on the database connection is made * to: * CREATE TABLE aa (a int); */ #include #define DB_CONN_STR "host=localhost dbname=ioltas" #define SQL_FETCH_AA "select a from aa where a = $1" int main(int argc, char *argv[]) { PGconn* conn; PGresult* res; int status; if ((conn = PQconnectdb(DB_CONN_STR)) == NULL) fprintf(stderr, "Connect to '%s' failed", DB_CONN_STR); if (PQstatus(conn) != CONNECTION_OK) fprintf(stderr, "Connect to '%s' failed: %s", DB_CONN_STR, PQerrorMessage(conn)); if ((res = PQprepare(conn, "sql_fetch_aa", SQL_FETCH_AA, 2, NULL)) == NULL) fprintf(stderr, "Preparing statement '%s' failed", SQL_FETCH_AA); if (PQresultStatus(res) != PGRES_COMMAND_OK) fprintf(stderr, "Preparing statement '%s' failed: %s", SQL_FETCH_AA, PQerrorMessage(conn)); PQclear(res); /* Call getParameterDescription */ if (PQsendDescribePrepared(conn, "sql_fetch_aa") == 0) fprintf(stderr, "Call to PQsendDescribePrepared failed: %s", PQerrorMessage(conn)); if ((res = PQgetResult(conn)) == NULL) fprintf(stderr, "Describe statement '%s' failed: %s", SQL_FETCH_AA, PQerrorMessage(conn)); if (PQresultStatus(res) != PGRES_COMMAND_OK) fprintf(stderr, "Preparing statement '%s' failed: %s", SQL_FETCH_AA, PQerrorMessage(conn)); PQclear(res); return 0; }