Thread: c++ program to connect to postgre database

c++ program to connect to postgre database

From
ramon rhey serrano
Date:
Hello,

I'm thinking of making a program in C++ (API) that will connect, read, and write to a PostgreSQL database. I honestly have no idea where to start and how to implement it in C++ using Dev C++ IDE.
Any help would be greatly appreciated.
Thanks.

Sincerely,
Rhey
 


New Email addresses available on Yahoo!
Get the Email name you've always wanted on the new @ymail and @rocketmail.
Hurry before someone else does!

Re: c++ program to connect to postgre database

From
John R Pierce
Date:
ramon rhey serrano wrote:
> Hello,
>
> I'm thinking of making a program in C++ (API) that will connect, read,
> and write to a PostgreSQL database. I honestly have no idea where to
> start and how to implement it in C++ using Dev C++ IDE.
> Any help would be greatly appreciated.

C++ easily calls C libaries...  I'd probably use libpq calls, see
http://www.postgresql.org/docs/current/static/libpq.html


there is an available C++ wrapper on this also, see
http://pqxx.org/development/libpqxx/



Re: c++ program to connect to postgre database

From
John R Pierce
Date:
ramon rhey serrano wrote:
> Hi Sir John,
>
> Thanks for the links and reply.
> I downloaded this "libpqxx-3.0" but i really don't know what to do
> with the file and where to put them. I'm still having hard time how to
> start the C++ program using Dev C++ as my IDE, what files do i need to
> install, what headers to use, how the basic flow of program should
> look like (maybe for a simple database connection). I already
> installed PostgreSQL version 1.8.4 in my PC (windows). I have basic
> understanding and background in C++ programming, but totally new to
> PostgreSQL database system.

as I said earlier, I'd probably just use C API calls to libpq, and do my
own C++ wrappings.    C++ libraries pretty much have to be compiled for
the speciifc compiler environment, so I'd have to assume youd load the
libpqxx project source into your IDE, and build it.

with libpq, the OS should already have the .so (or dll if you're on
windows), and .h files, so you'd simply #include <libpq-fe.h>  and call
the various functions using :: in front of the code to indicate they are
not part of a class.  you might have to tell the IDE where the libpq h
and .so files are if they aren't in a standard system library locations
like /usr/include and /usr/lib

I've never used that IDE so I have no idea of the specifics of how you
configure it with new libraries or include files.

Re: c++ program to connect to postgre database

From
Pedro Doria Meunier
Date:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Rey,

If you give QT4 a try I might be able to help you there ;-)

Regards

Pedro Doria Meunier
GSM: +351 96 17 20 188
Skype: pdoriam




ramon rhey serrano wrote:
> <!-- DIV {margin:0px;} -->
> Hello,
>
> I'm thinking of making a program in C++ (API) that will connect,
> read, and write to a PostgreSQL database. I honestly have no idea
> where to start and how to implement it in C++ using Dev C++ IDE.
> Any help would be greatly appreciated.
> Thanks.
>
> Sincerely,
> Rhey
>
>
> ----------------------------------------------------------------------
> New Email addresses available on Yahoo!
> <http://sg.rd.yahoo.com/aa/mail/domainchoice/mail/signature/*http://mail.promotions.yahoo.com/newdomains/aa/>
>
> Get the Email name you've always wanted on the new @ymail and
> @rocketmail.
> Hurry before someone else does!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD4DBQFKVbp+2FH5GXCfxAsRAi0WAKC1LxYxa9TVzOy6/MN7+UA5mYfcfQCYsCvz
LdGheJTQJcWApVisqDeS+w==
=yx4r
-----END PGP SIGNATURE-----


Re: c++ program to connect to postgre database

From
Rainer Bauer
Date:
John R Pierce schrieb:

>ramon rhey serrano wrote:
>> Hi Sir John,
>>
>> Thanks for the links and reply.
>> I downloaded this "libpqxx-3.0" but i really don't know what to do
>> with the file and where to put them. I'm still having hard time how to
>> start the C++ program using Dev C++ as my IDE, what files do i need to
>> install, what headers to use, how the basic flow of program should
>> look like (maybe for a simple database connection). I already
>> installed PostgreSQL version 1.8.4 in my PC (windows). I have basic
>> understanding and background in C++ programming, but totally new to
>> PostgreSQL database system.
>
>as I said earlier, I'd probably just use C API calls to libpq, and do my
>own C++ wrappings.    C++ libraries pretty much have to be compiled for
>the speciifc compiler environment, so I'd have to assume youd load the
>libpqxx project source into your IDE, and build it.

The best C++ library I came across so far is SOCI:
<http://soci.sourceforge.net/>

Maybe this could be a good starting point for Ramon since he is familiar with
C++.

Rainer

Re: c++ program to connect to postgre database

From
Peter Geoghegan
Date:
I'm a big libpqxx user, and can confirm that it's a great wrapper, but
good luck getting it to build in Dev-c++, which hasn't had a new
release in 4 years and isn't supported by pqxx. I'm not sure of the
specifics, but Dev-c++ uses a MinGW port of GCC. libpqxx does support
MinGW, but probably not the Dev-C++ flavour.

I suggest you download visual studio 2008 express, and use that to
build libpqxx. No one uses Dev-C++ anymore anyway.

Regards,
Peter Geoghegan