how to execute update query with PQexec?

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;

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;
}
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?
28 posts later (was there a film?), it's time you knew about this.
https://www.cplusplus.com/articles/jEywvCM9/
Sod please, suslucoder,

Learn to use code tags, they make reading and commenting on source code MUCH easier!

How to use code tags: http://www.cplusplus.com/articles/jEywvCM9/

There are other tags available.

How to use tags: http://www.cplusplus.com/articles/z13hAqkS/

HINT: you can edit your post and add code tags.

Some formatting & indentation would not hurt either

Why do you continue to resist using code tags?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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.
Topic archived. No new replies allowed.