Hi,
I have problems using 'varchar' and 'text' arguments for C functions.
Perhaps I am doing something wrong. I get garbage when I want to use
the arguments passed to the function. See the example:
My function as defined in my C program:
/*===========================================*/
PG_FUNCTION_INFO_V1(Test_Function);
Datum Test_Function(PG_FUNCTION_ARGS) /* varChar(10) varChar Text*/
{
VarChar* arg0_varChar10 = PG_GETARG_VARCHAR_P(0);
VarChar* arg1_varChar = PG_GETARG_VARCHAR_P(1);
text* arg2_textp = PG_GETARG_VARCHAR_P(2);
ereport( INFO, ( errcode( ERRCODE_SUCCESSFUL_COMPLETION ),
errmsg("Inputs :\n\targ0: %s\n\targ1: %s\n\targ2:
%s\n",VARDATA(arg0_varChar10), VARDATA(arg1_varChar),
VARDATA(arg2_textp))));
PG_RETURN_INT32(0);
}
/*=============================================*/
I run the following in PostgreSQL 8.4 to create the function:
------------------------------------------------
CREATE OR REPLACE FUNCTION Test_Function(varchar(10), varchar, text)
RETURNS integer
AS '$libdir/myDir/myLib', 'Test_Function'
LANGUAGE C
VOLATILE
STRICT
SECURITY DEFINER;
------------------------------------------------
The output I get when I call the function:
--------------------------------------------
My_database=# SELECT Test_Function('arg0', 'arg1', 'arg2');
is:
INFO: Inputs :
arg0: arg&#65533;V"&#65533;
arg1: arg1&#65533;&#65533;O"
arg2: arg2&#65533;&#65533;O"
test_function
---------------
0
(1 row)
--------------------------------------------
What is the 'garbage' I see at the end of the output?
Am I calling the correct functions in my C code to retrieve the
arguments and then the correct ones to display them?
In my original function I want to send the name of an entity to the
database and then add the name to a table but this is a problem if the
name is garbled.
Using: PostgreSQL 8.4
OS: Linux Ubuntu 9.10 Karmic Koala
--
Carel Combrink
s25291930(at)tuks(dot)co(dot)za
This message and attachments are subject to a disclaimer. Please refer
to www.it.up.ac.za/documentation/governance/disclaimer/ for full
details. / Hierdie boodskap en aanhangsels is aan 'n vrywaringsklousule
onderhewig. Volledige besonderhede is by
www.it.up.ac.za/documentation/governance/disclaimer/ beskikbaar.