Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libpq, insert with parameters

I am wondering if I can make parameterized queries directly from C/C++ with libpq instead of using strings and if do how should this code look's like?

string tblins = "";
tblins = "INSERT INTO " + commtable + " "
         "(vdoc, bdoc, mytime, txml) VALUES ("
         "'" + cxml.vdoc + "', "
             + cxml.bdoc + ", " //integer
         "'" + cxml.mytime + "', "
         "'" + cxml.txml + "')";

result = PQexec(conn, tblins.c_str());

Thanks.

like image 303
Wine Too Avatar asked Jun 04 '13 01:06

Wine Too


1 Answers

Yes, you can use the PQexecParams function as explained in the documentation.

If parameters are used, they are referred to in the command string as $1, $2, etc. nParams is the number of parameters supplied; it is the length of the arrays paramTypes[], paramValues[], paramLengths[], and paramFormats[].

like image 170
Greg Hewgill Avatar answered Nov 06 '22 13:11

Greg Hewgill