更新操作
#include <stdio.h>
#include <stdlib.h>
#include <libpq-fe.h>
static void
exit_nicely(PGconn *conn)
{
PQfinish(conn);
exit(1);
}
int
main(int argc, char **argv)
{
const char *conninfo;
PGconn *conn;
PGresult *res;
int nFields;
int i,j;
if (argc > 1)
conninfo = argv[1];
else
conninfo = "dbname=postgres port=42121 host='10.44.133.171' application_name=test connect_timeout=5 sslmode=allow user='test' password='test_1234'";
conn = PQconnectdb(conninfo);
if (PQstatus(conn) != CONNECTION_OK)
{
fprintf(stderr, "Connection to database failed: %s",
PQerrorMessage(conn));
exit_nicely(conn);
}
res = PQexec(conn, "update customer_t1 set c_customer_sk = 1000 where c_customer_name = 'li'");
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
fprintf(stderr, "UPDATE command failed: %s", PQerrorMessage(conn));
PQclear(res);
exit_nicely(conn);
}
/* 关闭数据库连接并清理 */
PQfinish(conn);
return 0;
}