// compile it by (very long command) // g++ -Wl,-rpath,/usr/local/lib -I/usr/local/pgsql/include -I/usr/kerberos/include -DHAVE_NAMESPACE_STD -DHAVE_CXX_STRING_HEADER -DDLLIMPORT="" -Wno-deprecated -L/usr/local/pgsql/lib -L/usr/kerberos/lib -lpq++ psql.cpp // // run it by // ./a.out #include #include void error(const char *mess) { cerr << "### " << mess << endl; exit(1); } int main() { //connect to db PgDatabase db("host=sql.csic.umd.edu dbname=YOUR_USERNAME" " user=YOUR_USERNAME password=YOUR_PASSWORD"); if (db.ConnectionBad()) error(db.ErrorMessage()); //create table if (!db.ExecCommandOk("CREATE TABLE hello (message VARCHAR(32))")) error("CREATE TABLE failed."); //insert data if (!db.ExecCommandOk("INSERT INTO hello VALUES('Hello World!')")) error("INSERT failed."); //select query if (!db.ExecTuplesOk("SELECT * FROM hello")) error("SELECT failed."); for (int i = 0; i < db.Tuples(); i++) for (int j = 0; j < db.Fields(); j++) cout << "[" << i << "," << j << "]" << db.GetValue(i,j) << endl; }