Received: from www.fr.netcentrex.net (unknown [62.161.167.249]) by postgresql.org (Postfix) with ESMTP id E2075475AB0 for ; Thu, 28 Feb 2002 10:44:46 -0500 (EST) Received: from TINTIN ([213.56.166.199]) by www.fr.netcentrex.net with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id FT11G50Q; Thu, 28 Feb 2002 16:44:42 +0100 Message-ID: <0b7c01c1c06e$d687e3d0$c7a638d5@fr.netcentrex.net> Reply-To: =?iso-8859-1?Q?C=E9line_Rivi=E8re?= From: =?iso-8859-1?Q?C=E9line_Rivi=E8re?= To: Subject: CREATE FUNCTION and LANGUAGE 'C' Date: Thu, 28 Feb 2002 16:44:42 +0100 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0B79_01C1C077.383E9030" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Archive-Number: 200203/41 X-Sequence-Number: 6923 This is a multi-part message in MIME format. ------=_NextPart_000_0B79_01C1C077.383E9030 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello, I'm trying to call a C function (C++ in fact but I think, it's not a proble= m) from a stored procedure (using CREATE FUNCTION). ------------------------------------------------------- This is the creation of my stored procedure: CREATE FUNCTION Get_Length(TEXT)=20 RETURNS INTEGER AS '/home/ncxusers/criviere/TOOLS/lib/tools.so', 'Get_Length' LANGUAGE 'C'; This is the C implementation of GetLength : #include #include "postgres.h" #include "fmgr.h" PG_FUNCTION_INFO_V1(file_open); extern "C" Datum file_open (PG_FUNCTION_ARGS) { char *szName =3D PG_GETARG_CSTRING(0); long lgLength =3D strlen(szName); PG_RETURN_UINT32(lgLength); } This is the result of the execution : TestVersioning=3D# select file_open('abcdefgh') as v_result; v_result=20 ---------- 2 (1 row) ------------------------------------------------------- Why does it return 2 and not 8 (length of 'abcdef') ? Thanks for your help. C=E9line PS: I think I have a problem with string manipulation.=20 Because I also have a 2nd issue when trying to return a variable of type TE= XT (or VARCHAR).=20 The following error occurs :=20 pqReadData() -- backend closed the channel unexpectedly. This probably means the backend terminated abnormally before or while processing the request. The connection to the server was lost. Attempting reset: Failed. ------=_NextPart_000_0B79_01C1C077.383E9030 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hello,
 = ;
I'm trying t= o call a C=20 function (C++ in fact but I think, it's not a problem) from a
stored proce= dure (using=20 CREATE FUNCTION).
 
-------------------------------------------------------
This is the = creation of=20 my stored procedure:
 
CREATE FUNCTION Get_Leng= th(TEXT)=20
RETURNS INTEGER
AS
 '/home/ncxusers/criviere/TOOLS/lib/tools= .so',=20 'Get_Length'
LANGUAGE 'C';
 = ;
This is the = C=20 implementation of GetLength :
 = ;
#include=20 <stdio.h>
#include "postgres.h"#include=20 "fmgr.h"
 
PG_FUNCTION_INFO_V1(file_open);
 
extern "C" Datum f= ile_open=20 (PG_FUNCTION_ARGS)
{
 char *szName =3D=20 PG_GETARG_CSTRING(0);
 long lgLength =3D=20 strlen(szName);
 PG_RETURN_UINT32(lgLength);
}
=
 = ;
 
This is the result of the ex= ecution=20 :
 
TestVersioning=3D# select file_open('abcdefgh') as=20 v_result;
 v_result=20
----------
        2
(1=20 row)
-------------------------------------------------------
 
Why does it return 2 and not= 8=20 (length of 'abcdef') ?
 
Thanks for your help.=
 
C=E9line
 
PS:
I think I have a problem wit= h string=20 manipulation.
Because I also have a 2nd is= sue=20 when trying to return a va= riable of=20 type TEXT (or VARCHAR).
The following error occurs := =20
 
pqReadD= ata() --=20 backend closed the channel=20 unexpectedly.
        This probably m= eans=20 the backend terminated abnormally
      &n= bsp;=20 before or while processing the request.
The connection to the server was= =20 lost. Attempting reset:=20 Failed
.
------=_NextPart_000_0B79_01C1C077.383E9030--