我已经阅读了文档,但仍然不清楚如何使用此函数将此命令发送到服务器:
INSERT INTO table_1($1,$2,$3);
我写的这个函数:
void add_data_to_db(char table){
const char data[2][2] = {"12","me"};
re = PQexecParams(connection,
"INSERT INTO test_table($1,$2)",
2,data,NULL,NULL,NULL,0
);
}
但在编译过程中,会出现以下错误:
db.c: In function ‘add_data_to_db’:
db.c:40:6: warning: passing argument 4 of ‘PQexecParams’ from incompatible pointer type [-Wincompatible-pointer-types]
40 | 2,data,NULL,NULL,NULL,0
| ^~~~
| |
| const char (*)[2]
In file included from db.c:2:
/usr/include/libpq-fe.h:391:18: note: expected ‘const Oid *’ {aka ‘const unsigned int *’} but argument is of type ‘const char (*)[2]’
391 | extern PGresult *PQexecParams(PGconn *conn,
| ^~~~~~~~~~~~
1条答案
按热度按时间wixjitnu1#
文档描述
PQexecParams
:参数值不是第四个参数,而是第五个参数。
第四个论点,如果不是左
NULL
,是一个具有描述参数类型的对象ID的数组。注意,在c中,字符串
"me"
不占用两个字节,但占用三个字节(必须包含最后的零字节)。