I have such program which works from "C" OK. Creates a table if they dont exists.
PGresult *result;
conn = PG_connect();
if (conn)
{
if (!PG_begin(conn))
{
char strtable[512] = {0};
sprintf(strtable, "%s", "CREATE TABLE IF NOT EXISTS mytable");
strcat(strtable, " (setting TEXT, value TEXT, rez1 TEXT, rez2 TEXT)");
result = PQexec(conn, strtable);
if (PQresultStatus(result) != PGRES_COMMAND_OK)
{
printf("CREATE TABLE failed: %s\n", PQerrorMessage(conn));
PQclear(result);
exit_nicely(conn);
}
PQclear(result);
PG_end(conn);
}
}
PQfinish(conn);
That mean I am connected properly.
But for why (on earth) in the same code and situation this query don't work?
sprintf(strtable, "%s%s", "SELECT 1 FROM pg_tables WHERE tablename=", "\'invli\'");
I allways get PQresultStatus(result) = 2 and PQerrorMessage(conn) without any text!
All of that I uses from npgsql without problems. Additional question, how is best to get relsults from such simple queries, or "COUNT" which have only one information? In npgsql I uses "ExecuteScalar" function.