加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql – libpq,带参数插入

发布时间:2020-12-13 15:56:16 所属栏目:百科 来源:网络整理
导读:我想知道我是否可以使用libpq直接从C/C++进行参数化查询,而不是使用字符串,如果这样的代码看起来怎么样? string tblins = "";tblins = "INSERT INTO " + commtable + " " "(vdoc,bdoc,mytime,txml) VALUES (" "'" + cxml.vdoc + "'," + cxml.bdoc + "," //i
我想知道我是否可以使用libpq直接从C/C++进行参数化查询,而不是使用字符串,如果这样的代码看起来怎么样?

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());

谢谢.

解决方法

是的,您可以使用PQexecParams函数,如 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[].

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读