1

这是关于我能想到的用来说明我的问题的最基本的 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 节中找到了 PQescapeLiteral:转义字符串以包含在 SQL 命令中。我有来自 yum 的最新版本的 libpq 和 libpq-devel,所以我很确定它应该被定义。

如果有人能指出我正确的方向,我将不胜感激。

4

1 回答 1

1

它对我来说很好用,带有 PostgreSQL 9.0.1 标头。您使用的是哪个版本的 postgresql 头文件和库?PQescapeLiteral 显然是在 9.0 中添加的:http: //developer.postgresql.org/pgdocs/postgres/release-9-0.html#AEN104548

您期望 libpq.so 在哪里?您显示带有 -I 开关的编译器命令以在非标准位置定位头文件,但没有相应的 -L 开关来定位库。

于 2011-01-07T00:19:59.837 回答