Thread: Free Pascal and Postgresql Functions, Possible?

Free Pascal and Postgresql Functions, Possible?

From
Tony Caduto
Date:
Has there ever been any discussion on
using Free Pascal to create functions (C Style)?


I know pascal can be used to create user defined functions in other
databases like Firebird (which was originally coded in C and now C++)

Thanks


Tony

Re: Free Pascal and Postgresql Functions, Possible?

From
Martijn van Oosterhout
Date:
On Sun, Dec 11, 2005 at 10:03:57PM -0600, Tony Caduto wrote:
> Has there ever been any discussion on
> using Free Pascal to create functions (C Style)?
>
>
> I know pascal can be used to create user defined functions in other
> databases like Firebird (which was originally coded in C and now C++)

Has anyone tried? PostgreSQL doesn't particluarly care what language a
function was written in, just as long as the calling convention
matches.

That said, pascal has historically had a different calling convention
and that is likely to cause the most issues.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachment

Re: Free Pascal and Postgresql Functions, Possible?

From
Bernd Helmle
Date:
--On Montag, Dezember 12, 2005 11:16:19 +0100 Martijn van Oosterhout
<kleptog@svana.org> wrote:

> On Sun, Dec 11, 2005 at 10:03:57PM -0600, Tony Caduto wrote:
>> Has there ever been any discussion on
>> using Free Pascal to create functions (C Style)?
>>
>>
>> I know pascal can be used to create user defined functions in other
>> databases like Firebird (which was originally coded in C and now C++)
>

Thought about that some time ago, too...

> Has anyone tried? PostgreSQL doesn't particluarly care what language a
> function was written in, just as long as the calling convention
> matches.
>
> That said, pascal has historically had a different calling convention
> and that is likely to cause the most issues.

Free Pascal offers the cdecl modifier, which allows to declare and access
functions with C style call convention. However, someone needs to write the
necessary interface to the internal PostgreSQL structures that are needed
for UDFs.

>
> Have a nice day,

dito

--
  Thanks

                    Bernd


Re: Free Pascal and Postgresql Functions, Possible?

From
Tony Caduto
Date:
Martijn van Oosterhout wrote:
  > That said, pascal has historically had a different calling convention
> and that is likely to cause the most issues.
>
> Have a nice day,


I know Delphi/Kylix can create C style DLLs and SOs with the C style
calling convention, so I "assume" Free Pascal does as well.

Is there any special C headers (for creating functions that return
results?) that are PG specific that would need to be ported to Pascal?

Tony

Re: Free Pascal and Postgresql Functions, Possible?

From
Tony Caduto
Date:
>>
>> That said, pascal has historically had a different calling convention
>> and that is likely to cause the most issues.
>
>
> Free Pascal offers the cdecl modifier, which allows to declare and
> access functions with C style call convention. However, someone needs to
> write the necessary interface to the internal PostgreSQL structures that
> are needed for UDFs.
>
>>
>> Have a nice day,
>
>
> dito
>


Sounds like it may be possible then.
Man, if someone where to come up with a simple example on just doing
something like adding two numbers or similar it might convince a few
Delphi/Kylix/Freepascal users to switch over from Firebird/Interbase.

I guess I could help with such a task if someone with C experience could
help also.  I have Freepascal/Lazarus installed as well as Kylix.

Does anyone know what header would need to be ported to Pascal?

Later,

Tony






Re: Free Pascal and Postgresql Functions, Possible?

From
Martijn van Oosterhout
Date:
On Mon, Dec 12, 2005 at 08:43:52AM -0600, Tony Caduto wrote:
> I know Delphi/Kylix can create C style DLLs and SOs with the C style
> calling convention, so I "assume" Free Pascal does as well.
>
> Is there any special C headers (for creating functions that return
> results?) that are PG specific that would need to be ported to Pascal?

Well, I don't know about any special C headers. The examples in the
documentation tell you what you need for various features. However, I
think the most important header would be fmgr.h since that is how the C
functions get arguments from and return data to the server. With a few
declarations for things like palloc you should be able to do most
things.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachment

Re: Free Pascal and Postgresql Functions, Possible?

From
Tom Lane
Date:
Martijn van Oosterhout <kleptog@svana.org> writes:
> On Mon, Dec 12, 2005 at 08:43:52AM -0600, Tony Caduto wrote:
>> Is there any special C headers (for creating functions that return
>> results?) that are PG specific that would need to be ported to Pascal?

> Well, I don't know about any special C headers. The examples in the
> documentation tell you what you need for various features. However, I
> think the most important header would be fmgr.h since that is how the C
> functions get arguments from and return data to the server. With a few
> declarations for things like palloc you should be able to do most
> things.

It'd depend hugely on what you want to accomplish.  For a self-contained
computational function that you don't mind using "version 0" call
convention for, you might not need any headers at all, just write the
thing as a regular cdecl function.  The next steps up would be access to
palloc (so you could return pass-by-reference datatypes), elog (for
error reporting), and fmgr.h (so you could use version-1 call
convention, which is more portable than version-0 and can deal with
NULLs).  If you wanted to do stuff that involved poking into the
backend's internal data structures, I think by far the path of least
resistance is to forget Pascal and use C ...

            tom "hacked Pascal in the '70s" lane