Re: Libpq question

From: John Townsend <jtownsend(at)advancedformulas(dot)com>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Libpq question
Date: 2012-05-21 14:54:56
Message-ID: 4FBA5740.4050002@advancedformulas.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 5/21/2012 7:56 AM, Merlin Moncure wrote:
> On Sun, May 20, 2012 at 2:52 PM, John Townsend
> <jtownsend(at)advancedformulas(dot)com> wrote:
>> By by-passing the "dll" (or "so" on Linux) library I mean you write function
>> or procedure calls to the server that is running as a service on Windows.
>> You don't use the library with its 160 exported functions. You connect
>> directly to the server thus saving one layer of protocols. To do this, you
>> have to translate all the c functions you need (not just the headers or ".h"
>> files) into pascal. Not a trivial task!
> It is possible to write functions and procedures on the server but
> they must still be invoked from the client side. Currently the only
> way to use any server side features is through the frontend/backend
> protocol. libpq is a library that handles the frontend side of the
> processing -- that's why the header is named libpq-fe.h: it's for the
> front end. You can bypass libpq but that would mean you'd have to
> write your own client side handler for the protocol -- definitely a
> non-trivial project and you'd probably end up with something worse
> than libpq unless you are an expert programmer.
Therein lies the problem, - I am not an expert. I know quite a bit about
Delphi & SQL, but that's it.

But to be a good you need to know both languages *_very well_*, that is
C++ and pascal. Translating the header files is easy, that's why most
developers use libpq.dll or .so. One uses only about 20 or so functions
- that is - for most projects. Translating the C++ function body (some
are pretty long and complex) takes more knowledge, not only about C but
about PostGreSQL.

Also, you must then translate all the _internal functions_ that libpq
uses. There are currently 160 functions exported.

This kind of a project was done all the time by Borland programmers in
the past.

>
> In other words, you can bypass libpq itself but not the protocol. To
> bypass the protocol, start moving your code into server functions.
Using pascal (Delphi or FPC). How would this be done? This is the
ultimate goal.

>> Would it be worth it? Depends, but for most situations would not give you
>> more speed. With FPC comes a nice utility called h2pas.exe that does a
>> decent job and can save you a lot of time. You still have to clean some
>> translations.
> I believe Zeos has an already converted .pas file for libpq.

Yes, they have translated the most used functions, the c header files,
that is. My count shows ~ 70 out of 160.

Thanks for your reply.

John

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Cédric Villemain 2012-05-21 15:09:53 Re: help understanding the bitmap heap scan costs
Previous Message Tom Lane 2012-05-21 14:09:51 Re: Libpq question