前端之家收集整理的这篇文章主要介绍了
libpqxx查询postgresql数据库表的通用方法,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
//g++testpqxx.cpp-otestpqxx`pkg-config--libs--cflagslibpqxxlibpq`
//g++testpqxx.cpp-otestpqxx-I/opt/Postgresql/9.4/include/-L/opt/Postgresql/9.4/lib-lpqxx-lpq
#include<iostream>
#include<pqxx/pqxx>
usingnamespacepqxx;
usingnamespacestd;
intmain()
{
try
{
connectionconn("dbname=yout-dbuser=your-usrpassword=your-passwd\
hostaddr=127.0.0.1port=5432");
conn.set_client_encoding("UTF8");
workw(conn);
resultr=w.exec("SELECT*FROMyour-table");
for(result::const_iteratorrow=r.begin();row!=r.end();++row)
{
for(tuple::const_iteratorcol=row->begin();col!=row->end();++col)
cout<<col->c_str()<<'\t';
cout<<endl;
}
}
catch(exception&e)
{
cerr<<e.what()<<endl;
return1;
}
return0;
}