Reputation: 10191
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.
Upvotes: 1
Views: 1288
Reputation: 133492
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.
Upvotes: 1