I have the code below for update query. It works but it doesnt update the table.
my line
if (PQresultStatus(res) == PGRES_TUPLES_OK) {
puts("basariyla degistirildi");
printf("islem tamam");
exit(0);
}
doesnt print anything. Where is my falt? Here is the all code:
int main() {
PGconn *conn;
PGresult *res;
int rec_count;
int row;
int col;
if (PQstatus(conn) == CONNECTION_BAD) {
puts("We were unable to connect to the database");
exit(0);
}
res = PQexec(conn, "UPDATE public.users SET unique_id='5' WHERE ID ='2'");
if (PQresultStatus(res) == PGRES_TUPLES_OK) {
puts("basariyla degistirildi");
printf("islem tamam");
exit(0);
}
What is the value of res from PQexec()? What is the value of PQresultStatus(res)? If not the expected value, then what is the value? What does the documentation for PQexec() say for this code?
int main()
{
PGconn* conn;
PGresult* res;
int rec_count;
int row;
int col;
conn = PQconnectdb("dbname=usr host=localhost user=admin password=mypwd");
if (PQstatus(conn) == CONNECTION_BAD)
{
puts("We were unable to connect to the database");
exit(0);
}
res = PQexec(conn, "UPDATE public.users SET unique_id='5' WHERE ID ='2'");
if (PQresultStatus(res) == PGRES_TUPLES_OK)
{
puts("basariyla degistirildi");
printf("islem tamam");
exit(0);
}
rec_count = PQntuples(res);
PQclear(res);
PQfinish(conn);
return 0;
}
There's code missing (headers), you need to post a short, self-contained, correct (and hopefully compileable) example: http://www.sscce.org/
Not everyone here knows anything about the 3rd party library you use, what is it, let alone uses it.