Re: Getting to learn libpqxx

From: "Matt Fitzgerald" <mfitzgerald75(at)optushome(dot)com(dot)au>
To: "'Michiel Lange'" <michiel(at)minas(dot)demon(dot)nl>
Cc: <pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: Getting to learn libpqxx
Date: 2003-04-10 22:26:17
Message-ID: 000801c2ffb0$34457790$0000fea9@macros
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Try compiling with the C++ compiler:

g++ -o source source.cpp

(You don't need to specify the .h extensions in C++)

-Matt

-----Original Message-----
From: Michiel Lange [mailto:michiel(at)minas(dot)demon(dot)nl]
Sent: Friday, 11 April 2003 6:59 AM
To: Matt Fitzgerald
Cc: 'Michiel Lange'; pgsql-interfaces(at)postgresql(dot)org
Subject: Re: [INTERFACES] Getting to learn libpqxx

Ok... here are some answers:

Yes, pqxx/connection.h is in the include path, the errormessage I would get
would be very different...

I compile the source with gcc: gcc source.cpp -o source
the libraries should be in place, I placed them in /usr/local/lib (and ran
ldconfig)

I will try the #include <sstream.h> (I believe you forgot the .h), but from
what I remember the
char foo[234];

foo = bar << "blah" << bla;

would be perfectly valid... but I can be mistaken... I will try your
suggestion and see if it will help...
yet, the problem that the declaration (Connstring *db;) is not valid...

Michiel
At 17:32 10-4-2003 +1000, Matt Fitzgerald wrote:
>Ok... some stupid questions:
>
>1. I take it pqxx/connection.h is in the include path?
>2. If so, what command are you using to compile the source?
>
>Also, your connection string is not built correctly, 'connstring' is not a
>class, thus it doesn't support any overloaded operators such as '<<' & '+'
>etc.
>
>Do some thing like this:
>
>#include <sstream>
>
>std::stringstream connstring;
>
>connstring << "host=" << host << "database=" << dbase << "username=" <<
>uname << "password=" << passwd;
>
>// call connection constructor something like this:
>Connection *db = new Connection(connstring.str().c_str());
>
>
>Etc.. etc.. also, as 'bool Immediate' defaults to 'true' you don't have to
>specify it.
>
>Regards,
> -Matt
>
>
>
>
>-----Original Message-----
>From: pgsql-interfaces-owner(at)postgresql(dot)org
>[mailto:pgsql-interfaces-owner(at)postgresql(dot)org] On Behalf Of Michiel Lange
>Sent: Thursday, 10 April 2003 8:31 AM
>To: pgsql-interfaces(at)postgresql(dot)org
>Subject: [INTERFACES] Getting to learn libpqxx
>
>Hello everybody again,
>
>I went out to investigate and try if I could master libpqxx, for libpq++
>works not at all. Seeing it is discontinued, and people are encouraged to
>use libpqxx, I was so bold as to try that ;-)
>
>Only to discover that there is hardly any documentation on how to access
>stuff... now I, myself am more a C-programmer, and I know C++ is pretty
>much different... it is really hard for me to think in classes and stuff,
>to think object-oriented...
>
>So, now you know I am an earthling :P
>
>I tried this kind of approach, the idea was to start out simple... so don't
>laugh at the attempt ...
>
>#include <pqxx/connection.h>
>
>int main(int argc, char *argv[])
>{
> Connection *db;
> char uname[250]; // username
> char passwd[250]; // password
> char host[250]; //hostname
> char passwd[250]; //password
> char dbase[250]; //database name
> char connstring[1264];
> ... some output and input to get values for all these char
arrays...
>
> connstring = "host=" >> host >> "database=" >> dbase >>
"username="
> >>
>uname >> "password=" >> passwd;
> db = new Connection(connstring,true);
>
> if(db->is_open())
> {
> cout << "Connection succesful!" << endl;
> cout << db->Options();
> }
> else
> {
> cout << "Something went wrong... oops" << endl;
> }
> delete db;
> return 0;
>}
>
>I get my first errors at "Connection *db" declaration... there is no
>Connection defined...
>Can anyone point out how to reference the classes libpqxx has?
>
>Also I was curious if my connstring was correctly built, but that is
>another subject I think... One other very important thing would be: how can
>I find out the error PostgreSQL will throw at me when I did something ugly?
>At least I can find out the problem, when I make one then...
>
>Michiel
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Don't 'kill -9' the postmaster

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Nigel J. Andrews 2003-04-10 22:40:54 Re: [HACKERS] More thoughts about FE/BE protocol
Previous Message Bruce Badger 2003-04-10 22:14:46 Re: [HACKERS] More thoughts about FE/BE protocol