pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joris Esch <joris.esch@esat.kuleuven.ac.be>
To: Vasquez, Jason <Jason.Vasquez@Connect.Xerox.com>
Cc: pgsql-interfaces@hub.org
Subject: Re: [INTERFACES] PgConnection
Date: Thu, 22 Oct 1998 09:33:02 +0200
Message-ID: <98102209370100.02006@tintin> (raw)
References: <C1CB538EFB88D111A60200805FBB99118B7663@CINMSG1>

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 <iostream.h>
>#include <libpq++.h>
>
>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.
	

Attachments:

test3.cpp (text/x-c++, 1.8K) download /* 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; }
test3.h (text/x-c, 100B) download /* test3.h joris esch 3.10.1998 */ #include <libpq++.h> #include <iostream> //typedef int Error;

view thread (6+ messages)  latest in thread

Message-ID: <98102209370100.02006@tintin>
Permalink:  ../98102209370100.02006@tintin/
Also on:    postgresql.org/message-id/98102209370100.02006@tintin

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: joris.esch@esat.kuleuven.ac.be, Jason.Vasquez@Connect.Xerox.com, pgsql-interfaces@hub.org
  Subject: Re: [INTERFACES] PgConnection
  In-Reply-To: <98102209370100.02006@tintin>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox