pgtest.cpp
application/octet-stream
Filename: pgtest.cpp
Type: application/octet-stream
Part: 0
#include <iostream>
#include <stdio.h>
#include "pgconnection.h"
#include "pgdatabase.h"
class mydb : public PgDatabase {
public:
mydb():PgDatabase() { }
mydb(string& constr) : PgDatabase(constr.c_str()) { }
~mydb() { }
};
int main() {
#ifdef _C_ // This won't execute, because _C_ we won't define.
// variables.
char *pghost = NULL,
*pgport = NULL,
*pgoptions = NULL,
*pgtty = NULL,
*dbName = "alertdb";
// get a connection from postgres
//string conn = "dbname='alertdb';
PGconn *conn = PQsetdb(pghost, pgport, pgoptions, pgtty, dbName);
cout << "After getting connection.\n";
#else
// The below calls will give segmentation fault...
// To test, uncomment any of the below lines.
//PgDatabase *conn = new PgDatabase();
//PgDatabase *conn = new PgDatabase("user=sandesh dbname=alertdb");
//PgConnection *conn = new PgConnection();
//PgConnection *conn = new PgConnection("user=sandesh dbname=alertdb");
// This will work.
mydb* conn = new mydb("user=sandesh dbname=alertdb");
PgDatabase conn = PgDatabase ;
cout << "got con\n";
conn->Exec("SELECT * FROM temp;");
cout << "Executed query. \n";
// But, if we delete the mydb object, ...
//delete conn; // Gives segmentation fault
#endif
}