ITPub博客

首页 > > > postgresql提供了C语言的libpq接口 有表test((id int,

postgresql提供了C语言的libpq接口 有表test((id int,

作者:doudourabbit 时间:2019-04-25 11:29:54 0 删除 编辑

postgresql提供了C语言的libpq接口 有表test((id int,name varchar) insert into test values(1056,'postgresa') insert into test values(1055,'postgresb') insert into test values(1057,'postgresc')

如果: 在C程序里面 paramValues[0] = "1056"; res = PQexecParams(conn,"select * from test where id = $1;",1,NUll,paramValues,NULL,NULL,0); 可以正常执行 如果 paramValues[0] = "id";(此处不让这个变量值为表中的一个值,而是赋值为一个字段的名字) res = PQexecParams(conn,"select * from test where $1 = 1056;",1,NULL,paramValues,NULL,NULL,0); 这样的话就无法正确执行了,会返回错误信息 The database operation failed : ERROR: invalid input syntax for integer: "id" 或者paramValues[0] = "id" res = PQexecParams(conn,"select * from test order by $1 asc;",1,NULL,paramValues,NULL,NULL,0); 输出的结果 id name

1056 postgresa
1055 postgresb
1057 postgresc
并没有进行排序 这样的话就是无法把字段值作为一个参数放到sql语句中了,不知道是我有的参数没有照顾到还是这样根本行不通,如果不行的话有没有什么解决的办法呢?


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4809/viewspace-3159695/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-25

  • 博文量
    193
  • 访问量
    1438