[pgsql-jp: 27333] Cのfunctionについて

Shigeru Matsumoto matsu @ awh.co.jp
2002年 9月 5日 (木) 18:47:41 JST


This is a multi-part message in MIME format.

------=_NextPart_000_0011_01C2550C.B7132950
Content-Type: text/plain;
	charset="iso-2022-jp"
Content-Transfer-Encoding: 7bit

こんばんわ、matsuと申します。

redhat7.2
postgresql-7.2.1

以下のようなC関数を作成し、test.soを作成しました。

-------- test.c ----------
#include <stdio.h>
#include <string.h>

#include "postgres.h"

char* test(int2 i) {
   char* h = "----";
   static char s[40];

   sprintf(s, "%d", i);
   strcat(s, h);

   return(s);
}
windowsのC++環境では、test(2)の結果が「2----」となりました。

$ cc -fpic -c -I /usr/local/src/postgresql-7.2.1/src/inclide -I /usr/include
test.c
$ cc -shared -o test.so test.o

hoge=# create function test(int2) return char as'/xxxx/test.so' language
'c';
hoge=# select test(t.field1) from t where t.id = 100;

だと、エラーになります。
解決策を教えて頂けないでしょうか。

よろしくお願いします。




------=_NextPart_000_0011_01C2550C.B7132950
Content-Type: text/html;
	charset="iso-2022-jp"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-2022-jp">
<META content=3D"MSHTML 6.00.2715.400" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#80c49e>
<DIV><FONT face=3D"MS UI Gothic" =
size=3D2>=1B$B$3$s$P$s$o!"=1B(Bmatsu=1B$B$H?=3D$7$^$9!#=1B(B</FONT></DIV>=

<DIV><FONT face=3D"MS UI Gothic" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2>redhat7.2</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2>postgresql-7.2.1</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"MS UI Gothic" =
size=3D2>=1B$B0J2<$N$h$&$J=1B(BC=1B$B4X?t$r:n @ .$7!"=1B(Btest.so=1B$B$r:n@=
.$7$^$7$?!#=1B(B</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2>-------- test.c =
----------</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2>#include =
&lt;stdio.h&gt;</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2>#include =
&lt;string.h&gt;</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2>#include =
"postgres.h"</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2>char* test(int2 i) =
{</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2>&nbsp;&nbsp; char* h =3D=20
"----";</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2>&nbsp;&nbsp; static char=20
s[40];</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2>&nbsp;&nbsp; sprintf(s, "%d",=20
i);</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2>&nbsp;&nbsp; strcat(s, =
h);</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2>&nbsp;&nbsp; =
return(s);</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2>}</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic"=20
size=3D2>windows=1B$B$N=1B(BC++=1B$B4D6-$G$O!"=1B(Btest(2)=1B$B$N7k2L$,!V=
=1B(B2----=1B$B!W$H$J$j$^$7$?!#=1B(B</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2></FONT>&nbsp;</DIV>
<DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2>$ cc -fpic -c -I=20
/usr/local/src/postgresql-7.2.1/src/inclide -I /usr/include =
test.c</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2>$ cc -shared -o test.so=20
test.o</FONT></DIV></DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2>hoge=3D# create function =
test(int2) return=20
char as'/xxxx/test.so' language 'c';</FONT></DIV>
<DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2>hoge=3D# select test(t.field1) =
from t where=20
t.id =3D 100;</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"MS UI Gothic" =
size=3D2>=1B$B$@$H!"%(%i!<$K$J$j$^$9!#=1B(B</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic" =
size=3D2>=1B$B2r7h:v$r65$($FD:$1$J$$$G$7$g$&$+!#=1B(B</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"MS UI Gothic" =
size=3D2>=1B$B$h$m$7$/$*4j$$$7$^$9!#=1B(B</FONT></DIV></DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"MS UI Gothic" =
size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0011_01C2550C.B7132950--





pgsql-jp メーリングリストの案内