View Full Version : [ClanLib 2.3] PostgreSQL backend

06-12-2013, 12:49 PM
Hi, here is a PostgreSQL backend for clanLib-2.3 (https://github.com/Zenol/ClanPgsql/releases/tag/2.3v1).

It implements more or less the same capabilities of clanSqlite, and allow switching from clanSqlite code to clanPgsql just by changing the connection line*

It depends on libpq, wich can be installed with distro's packages, and compiled with visual C++ (not tested) : http://www.postgresql.org/docs/8.3/static/install-win32-libpq.html.
It has a very liberal bsd-like licence, wich enable using for everything (i think about commercial uses).

Here, I give you a svn diff from the current clan-2.3 svn HEAD. You should probably read it carefully, since it paches autotools config, and I don't really know how to use them. There is a Setup/Test file to check if libpq is well installed, so basicaly, it should (If I'v done my job well) work out of the box if you have libpq installed (otherwise, it's just an apt/yum/yaourt install with linux distro).

It also change a little bit of Sqlite & Database, just to add one value to an enum (I take care that it shouldn't brake anything (API/ABI), but I'm not a library maintainer, so please take a look). It's due to the fact that PostgreSQL give more flexibility about transactions than Sqlite, and the Database interface was designed around Sqlite. If I didn't done that, any backend would have to
1) Lie and do not do what's expected for one of the enumerated types
2) Only provide realy restricted behavior wich is not the default provided by the database.
So postgresql or not postgresql, I think it's a good thing to provide a 'default behavior' value.

If you have any question, I'm ready to answer :)

I would also like to write some detailed documentation about wich functionality is/isnt provided, how to connect, some links to the right PostgreSQL documentation pages, and facts like "you can have more than one reader, but only one transaction by connection", "it use the synchronous api", "get all results at the same time", "wich kind of error can happend when doing a query", "when is the query really executed (actualy reader constructor)", ...
So if you have a good place where to write it, tell me.

* It's not true. Table and field escaping should be made by '"' and not '`'. Also, you can't use the last_row_id function which will always return -1. Creating a transaction locking everything doesn't make sens with postgreSql, so you have to lock explicitely the tables you are working on, just by executing a one-line query after a transaction was started.

Edit : The 3.0 backend is available as the master branch (https://github.com/Zenol/ClanPgsql)of the repository.

09-05-2013, 08:35 PM
General note.

This would be nice as an example ClanLib 3.0, in Examples/Database.

Like how Examples/Sound/Mikmod is a good example of plugin music players.

09-06-2013, 01:10 PM
Actualy, the library is now available as a separated binary (.a/.so) at github : https://github.com/Zenol/ClanPgsql

I can provide easily (and I will) a ClanLib 3.0 version, but I haven't the time to check (and maybe adapt) the build system to windows.

Maybe I can branch and tag 2.3, move master to 3.0 and branch the build system for windows latter. Sounds the better solution.

09-06-2013, 04:22 PM
Btw, thanks alot for this - I might need it for my project :)

09-06-2013, 10:49 PM
I've just ported the library to Clanlib 3.0 (https://github.com/Zenol/ClanPgsql)(It's the master branch of the git repository).

Should install with cmake and make install. For windows, cmake should be generating a visual studio project that should compile (maybe you'll have to set some compile flag by hand, don't know).

Didn't tested it, but it compile on linux. If anything goes wrong (I really hope it won't) you can tell me and I'll try to find the time to dig it.

09-19-2013, 11:22 AM
I have added a link to it, on http://clanlib.org/contributions.html