Database Reference
In-Depth Information
if (result == NULL || PQresultStatus(result) !=
PGRES_COMMAND_OK)
{
fprintf(stderr, "failed to execute query using PQexec\n");
fprintf(stderr, "%s", PQerrorMessage(conn));
return -1;
}
result = PQexec(conn, "INSERT INTO foo VALUES(1, 'bar-1')");
if (result == NULL || PQresultStatus(result) !=
PGRES_COMMAND_OK)
{
fprintf(stderr, "failed to execute query using PQexec\n");
fprintf(stderr, "%s", PQerrorMessage(conn));
return -1;
}
/* Execute a query using PQexecParams */
result = PQexecParams(conn, "INSERT INTO foo VALUES($1, $2)",
2, paramTypes, (const char *
const*)paramValues, paramLengths,
paramFormats, 0);
if (result == NULL || PQresultStatus(result) !=
PGRES_COMMAND_OK)
{
fprintf(stderr, "failed to execute query using
PQexecParams\n");
fprintf(stderr, "%s", PQerrorMessage(conn));
return -1;
}
/* Execute a prepared query */
result = PQprepare(conn, "test", "INSERT INTO foo VALUES($1,
$2)", 2, paramTypes);
paramValues[0] = "3";
paramValues[1] = "bar-3";
result = PQexecPrepared(conn, "test", 2, (const char *
const*)paramValues, paramLengths,
paramFormats, 0);
if (result == NULL || PQresultStatus(result) !=
PGRES_COMMAND_OK)
{
 
Search WWH ::




Custom Search