Received: from barbar.esat.kuleuven.ac.be (root@barbar.esat.kuleuven.ac.be [134.58.56.153]) by hub.org (8.9.1/8.8.8) with ESMTP id DAA05865 for ; Thu, 22 Oct 1998 03:38:26 -0400 (EDT) (envelope-from joris.esch@esat.kuleuven.ac.be) Received: from tintin (kn-10-0-30-224.kotnet.kuleuven.ac.be [10.0.30.224]) by barbar (version 8.8.5) with SMTP id JAA17099; Thu, 22 Oct 1998 09:37:58 +0200 (METDST) Organization: ESAT, K.U.Leuven, Belgium From: Joris Esch Reply-To: joris.esch@esat.kuleuven.ac.be To: "Vasquez, Jason" Subject: Re: [INTERFACES] PgConnection Date: Thu, 22 Oct 1998 09:33:02 +0200 X-Mailer: KMail [version 0.7.9] Content-Type: Multipart/Mixed; boundary="Boundary-=_XrJmOWFrxsjyBldbEFSArCBynEcd" References: Cc: pgsql-interfaces@hub.org MIME-Version: 1.0 Message-Id: <98102209370100.02006@tintin> --Boundary-=_XrJmOWFrxsjyBldbEFSArCBynEcd Content-Type: text/plain Content-Transfer-Encoding: 8bit On Wed, 21 Oct 1998, you wrote: >I have just installed PostgreSQL, and the installation took place with no >problems/errors. > >I've read the documentation about using the C++ interface to Postgres, but I >seem to be havin trouble getting anything to compile. Following the example >included with the distribution, I have done something similar to this: > >#include >#include > >void main() { > PgDatabase data ("foo"); > >yadayadayada >} > >Whenever I do this, I get a compile error stating that there is an undefined >reference to PgConnection. Has anyone had a similar situation, or know how >to remedy this? > >Thanks, >-Jason Hello: look at the attached code. I hope it's usefull for you. good luck joris -- joris esch, student in electrical engineering Power is knowledge. --Boundary-=_XrJmOWFrxsjyBldbEFSArCBynEcd Content-Type: text/x-c++; name="test3.cpp" Content-Transfer-Encoding: 8bit Content-Description: test3.cpp Content-Disposition: attachment; filename="test3.cpp" /* test3.cpp joris esch 3.10.1998 */ // compile with: // c++ test3.cpp -o test3 -lpq -lpq++ #include "test3.h" void main() { bool verbose = true; char* dbname= "template1"; /* make a connection to the database */ if (verbose) { cout << "Trying to connect to db " << dbname << '\n';; // << " on host " << pghost; } ; // PgDatabase inherits from PgConnection PgDatabase *conn=new PgDatabase(dbname); // give error messages if conn is not ok if (conn->Status()!=0){ cerr << "Connection status: " << conn->Status() <<'\n'; cerr << "Connection failed." << '\n'; cerr << "Database name: " << conn->DBName() << '\n'; cerr << conn->ErrorMessage() << '\n'; //end execution here... or use exception handling...cfr. ch8 exit(1); //Stroustrup page 116 0== okidoki, 1!=okidoki //throw "Connection failed"; }; if (verbose) {cout << "Connection succeeded.\n";}; cout << "You are currently connected to db: " << conn->DBName() << '\n'; //cout << "Let's do a query"; //see if i can do query... if (conn->ExecTuplesOk("DECLARE mycursor BINARY CURSOR FOR select * from pg_database")){// 1 means Ok int no_t=conn->Tuples(); int no_f=conn->Fields(); if (verbose) { cout << "The number of tuples in the query: " << conn->Tuples() << '\n'; cout << "The number of fields in the query: " << conn->Fields() << '\n'; } cout << "The query results: \n"; for(int i=0;i < no_t; i++){ for(int j=0;j < no_f; j++){ cout << conn->GetValue(i,j) << '\t'; //cout << conn->GetValue(i,j) << '\n'; } cout << '\n'; } } else{ cout << "Execution of query failed\n";//conn } //conn->Exec("DECLARE mycursor BINARY CURSOR FOR select * from test"); //return 0; } --Boundary-=_XrJmOWFrxsjyBldbEFSArCBynEcd Content-Type: text/x-c; name="test3.h" Content-Transfer-Encoding: 8bit Content-Description: test3.h Content-Disposition: attachment; filename="test3.h" /* test3.h joris esch 3.10.1998 */ #include #include //typedef int Error; --Boundary-=_XrJmOWFrxsjyBldbEFSArCBynEcd--