
Hello,

	Sorry to disturb the hacker list for a question that seems not so hard.
But I got no answers elsewhere...
    Is is definitively impossible to use C++ to define new SQL functions or operators
in SQL ? (I need this in order to use a big geometric library, to produce e.g. polygon
intersections, or harder).

	       I manage to add C functions, with a

	       create function ... returns .. as language 'c';

 but the linking style of c++ is rather different.
Do you have an idea ?
    
Thanks,

David
dgross@lri.fr

Fri, 17 Jul 1998 10:59:17 +0200 (MET DST)
David Gross <David.Gross@lri.fr>
using C++ to define new functions
David Gross wrote:
> 
> Hello,
> 
>         Sorry to disturb the hacker list for a question that seems not so hard.
> But I got no answers elsewhere...
>     Is is definitively impossible to use C++ to define new SQL functions or operators
> in SQL ? (I need this in order to use a big geometric library, to produce e.g. polygon
> intersections, or harder).
>[...]
>  but the linking style of c++ is rather different.
> Do you have an idea ?

How about using extern "C" {...} ?

Mike

-- 
WWW: http://www.lodz.pdi.net/~mimo  tel: Int. Acc. Code + 48 42 2148340
add: Michal Mosiewicz  *  Bugaj 66 m.54 *  95-200 Pabianice  *   POLAND

Mon, 20 Jul 1998 01:46:27 +0200
Michal Mosiewicz <mimo@interdata.com.pl>
Re: [HACKERS] using C++ to define new functions
Michal Mosiewicz <mimo@interdata.com.pl> writes:
> David Gross wrote:
>> but the linking style of c++ is rather different.
>> Do you have an idea ?

> How about using extern "C" {...} ?

I think the major problem here is that David would probably like the
constructors for any global-level variables in his C++ code to be called
when his shared library is loaded into the backend.  (If his C++ code
hasn't got *any* global variables with nontrivial constructors, then
he could maybe survive without this.  But it'd be a necessary part of
a general-purpose solution.)

This is doable.  I routinely use a system that does dynamic loading
of C++ code (Ptolemy, http://ptolemy.eecs.berkeley.edu).  It's fairly
messy and unportable however, because you have to be aware of the
machine-and-compiler-dependent conventions for naming and finding
the global constructors.

David would probably also want to link the C++ library into the backend
(as a shared library, otherwise the linker will optimize it away) so
that his shared library doesn't need to include C++ library routines.
There might be a few other little changes to make in the link that
builds the backend.

In short, this could be supported if we wanted to invest a sufficient
amount of effort in it.  I'm not sure it's worth the trouble.

			regards, tom lane

Mon, 20 Jul 1998 10:48:11 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: [HACKERS] using C++ to define new functions 