PQescapeLiteral 未定义?
这是我能想到的最基本的 libpq 示例来说明我的问题。这里的目标只是打印出转义的字符串。
#include <iostream>
#include <libpq-fe.h>
#include <string.h>
using namespace std;
int main(){
PGconn *db;
char connstring[] = "dbname=TheInternet";
db = PQconnectdb(connstring);
char url[] = "http://www.goo'gle.com/";
cout<<PQescapeLiteral(db, (const char *)url, (size_t) strlen(url))<<"\n";
}
编译时
g++ PQescapeLiteral_test.cpp -lpq
当我用:甚至用:
g++ PQescapeLiteral.cpp -I/usr/include/pgsql:/usr/include/pgsql/server:/usr/include/pgsql/server/libpq -lpq
,我收到错误:
PQescapeLiteral.cpp: In function ‘int main()’:
PQescapeLiteral.cpp:12: error: ‘PQescapeLiteral’ was not declared in this scope
我在 pgsql 9.0 手册中的第 31.3.4.: 转义字符串以包含在 SQL 命令中找到了 PQescapeLiteral。我有 yum 的最新版本的 libpq 和 libpq-devel,所以我很确定它应该被定义。
如果有人能指出我正确的方向,我将不胜感激。
This is about the most basic libpq example I could think of to illustrate my problem. The goal here is just to print out the escaped string.
#include <iostream>
#include <libpq-fe.h>
#include <string.h>
using namespace std;
int main(){
PGconn *db;
char connstring[] = "dbname=TheInternet";
db = PQconnectdb(connstring);
char url[] = "http://www.goo'gle.com/";
cout<<PQescapeLiteral(db, (const char *)url, (size_t) strlen(url))<<"\n";
}
When I compile with:
g++ PQescapeLiteral_test.cpp -lpq
or even with:
g++ PQescapeLiteral.cpp -I/usr/include/pgsql:/usr/include/pgsql/server:/usr/include/pgsql/server/libpq -lpq
I get the error:
PQescapeLiteral.cpp: In function ‘int main()’:
PQescapeLiteral.cpp:12: error: ‘PQescapeLiteral’ was not declared in this scope
I found PQescapeLiteral in the manual for pgsql 9.0 in section 31.3.4.: Escaping Strings for Inclusion in SQL Commands. I have the most recent version of libpq and libpq-devel from yum so I'm pretty sure it's supposed to be defined.
If someone can point me in the right direction I'd appreciate it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它对我来说工作得很好,带有 PostgreSQL 9.0.1 标头。您使用的是哪个版本的 postgresql 头文件和库? PQescapeLiteral 显然是在 9.0 中添加的:http://developer.postgresql。 org/pgdocs/postgres/release-9-0.html#AEN104548
你期望 libpq.so 在哪里?您显示带有 -I 开关的编译器命令以将头文件定位在非标准位置,但没有相应的 -L 开关来定位库。
It works fine for me, with PostgreSQL 9.0.1 headers. Which version of the postgresql headers and library are you using? PQescapeLiteral was apparently added in 9.0: http://developer.postgresql.org/pgdocs/postgres/release-9-0.html#AEN104548
Where are you expecting libpq.so to be? You show a compiler command with -I switches to locate the headers files in a non-standard location, but no corresponding -L switch to locate the libary.