Dear PostgreSQL Gurus,
I need your help. I have created a UDT that has both text
and binary functions (func_IN and func_recv) to recieve
text and binary data. I have also added some other functions
for new type that takes binary and text input. Everything
seems to be working fine if I am using psql. I can load and query
data. However, I cannot seem to insert data using LibPQ. It calls
func_recv functions on the server side but doesn't get the
data it expects. I have created the type be of variable length
and am 'detoasting' the data inside recv function to make sure
data input is properly parsed.
Included below is a snippet of code cut and places from various
functions that I am using to insert. On server side when I try to print
input data size and values I get incorrect results.
I didn't find much documentation but thought this should have
worked. Please point any thing that I didn't do right. Also, another
function that takes binary input in the very same manner and can be
invoked at sql level seems to work just fine.
Thanks,
Brijesh
Client side code:
********************************************** sprintf(m_psql," Insert into %s (UDTCOL) VALUES " " ($1)",
TEST_TABLE);
m_paramTypes[0] = 50415; //OID for the new type from pg_type table m_paramValues[0] = "A text string to test the data
input"; m_paramSizes[0] = strlen(m_paramValues[0]); m_paramFormats[0] = PG_BINARY_FORMAT; m_res = PQprepare(m_pgconn,
m_stmtName,m_psql,1,m_paramTypes); if (PQresultStatus(m_res) != PGRES_COMMAND_OK) { .... .... }
m_res = PQexecPrepared(m_pgconn, m_stmtName, 1,
m_paramValues, (const int *) m_paramSizes, (const int *) m_paramFormats,
m_resFormat);
if (PQresultStatus(m_res) != PGRES_COMMAND_OK && PQresultStatus(m_res) != PGRES_TUPLES_OK) {
}
Server side code:
**********************************************
Datum func_Recv(PG_FUNCTION_ARGS)
{ FUNC_BINARY_FORMAT *input = (FUNC_BINARY_FORMAT *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
elog(NOTICE," Binary DATA_LEN = %d\n",VARSIZE(input)); elog(NOTICE," Binary DATA CONTENT= %s\n",VARDATA(input));