2011-01-06 7 views
1

이것은 내 문제를 설명하기 위해 생각할 수있는 가장 기본적인 libpq 예제입니다. 여기서 목표는 이스케이프 된 문자열을 인쇄하는 것입니다.PQescapeLiteral이 정의되지 않았습니까?

g++ PQescapeLiteral_test.cpp -lpq 

또는과 : 내가 컴파일 할 때

#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"; 
} 

내가 pgSQL에 대한 설명서에 PQescapeLiteral을 발견

PQescapeLiteral.cpp: In function ‘int main()’: 
PQescapeLiteral.cpp:12: error: ‘PQescapeLiteral’ was not declared in this scope 

:

g++ PQescapeLiteral.cpp -I/usr/include/pgsql:/usr/include/pgsql/server:/usr/include/pgsql/server/libpq -lpq 

나는 오류 9.0 절의 9.0 절. 이스케이프 문자열 f 또는 SQL 명령에 포함. yum에서 libpq와 libpq-devel의 가장 최신 버전을 가지고 있기 때문에 정의되어야한다고 확신합니다.

사람이 올바른 방향으로 날 지점 수 있다면 나는 그것을 감사하겠습니다.

답변

1

그것은 PostgreSQL의 9.0.1 헤더, 나를 위해 잘 작동합니다. 어떤 버전의 postgresql 헤더와 라이브러리를 사용하고 있습니까? PQescapeLiteral 분명히 9.0에서 추가되었다 : http://developer.postgresql.org/pgdocs/postgres/release-9-0.html#AEN104548

은 어디 libpq.so 것으로 기대하고있다? 비표준 위치의 헤더 파일을 찾기 위해 -I 스위치를 사용하여 컴파일러 명령을 표시하지만 libary를 찾기 위해 해당 -L 스위치는 없습니다.

+0

libpqxx i686 1 : 3.0.2-4.fc13 fedora libpqxx-devel i686 1 : 3.0.2-4.fc13 fedora ... postgres 8.4.5 ...이게 될 수도 있습니다! 나는 최신을 설치하려고 노력할 것이다 :) – KeatsKelleher