unable to find string literal operator ‘operator""ID’ with ‘const char [56]’, ‘long unsigned int’ arguments

I have the line below in my code.
I got this error :
unable to find string literal operator ‘operator""ID’ with ‘const char [56]’, ‘long unsigned int’ arguments.
I must write ID with " " because its uppercase, postgresql accept it with double quotes.
How can i solve this error?


1
2
3
4

res = PQexec(conn,  "UPDATE public.epp_commands SET unique_id='5' WHERE "ID"='2'");

If the string itself has double-quotes in it, you need to escape those, with \" instead of just ".

See example at bottom of page: https://en.cppreference.com/w/cpp/language/escape
I try to do it but im still getting this error
I couldnt find my mistake :((

error: unable to find string literal operator ‘operator""command_group_id’ with ‘const char [76]’, ‘long unsigned int’ arguments
ress = PQexec(conn,("UPDATE public.epp_group_commands SET \"command_flag\" ='1' WHERE \"group_id\"='"command_group_id+"'").c_str());
A + is missing if command_group_id is actually a std::string:

ress = PQexec(conn,("UPDATE public.epp_group_commands SET \"command_flag\" ='1' WHERE \"group_id\"='"+command_group_id+"'").c_str()); // Note: +command_group_id
command group id is not a string. i want to convert it a string in this query
I try to use std::to_string but its not work

error: cannot convert ‘std::__cxx11::basic_string<char>’ to ‘const char*’ for argument ‘2’ to ‘PGresult* PQexec(PGconn*, const char*)’


 
      res = PQexec(conn,"UPDATE public.epp_group_commands SET \"command_flag\" ='1' WHERE \"group_id\"='"+std::to_string(command_group_id)+"'");
Last edited on
You forgot the ).c_str() at the end of the string.
You need to build the whole thing up as std::string then convert to c_str at the last moment.

1
2
3
4
5
6
7
// also uses string folding to keep long strings readable
std::string cmd = "UPDATE public.epp_group_commands "
       "SET \"command_flag\" ='1' "
       "WHERE \"group_id\"='";
cmd += command_group_id;
cmd += "'";
res = PQexec(conn, cmd.c_str());
thank you so much
Topic archived. No new replies allowed.