|< < 32 > >|

Postgres C API

Inserting rows

// Insert a row { const char* params[] = {"5", "five"}; res = PQexecParams(cnxn, "insert into A(x, s) values($1, $2)", 2, // Number of inputs NULL, // Postgres will deduce input types params, // Parameters as strings NULL, // Parameter lengths, not needed for text params NULL, // Parameter formats, not needed for text params 0); // Obtain results in text format if (PQresultStatus(res) != PGRES_COMMAND_OK) { PQclear(res); oops(cnxn, "insert failed"); } printf("Rows inserted: %s\n", PQcmdTuples(res)); PQclear(res); ... const char* params[] = {"-6", NULL}; res = PQexecParams(cnxn, "insert into A(x, s) values($1, $2)", ...); }

|< < 32 > >|