Dynamic loading (datatype mismatch) - Mailing list pgsql-general

From Jasbinder Bali
Subject Dynamic loading (datatype mismatch)
Date
Msg-id a47902760608240908q6abf70d9u90d57f1ecdb25747@mail.gmail.com
Whole thread Raw
List pgsql-general
Hi,

I am dynamically loading a shared object in a function.


CREATE OR REPLACE FUNCTION sp_trigger_raw_email(int4, char)
  RETURNS bool AS
'/usr/local/pgsql/jsbali/parser', 'test'
  LANGUAGE 'c' VOLATILE STRICT;
ALTER FUNCTION sp_trigger_raw_email(int4, text) OWNER TO postgres;   

signature of test is
test (int, char*)

Also, function sp_trigger_raw_email gets invoked as a result of trigger action

The function that invokes sp_trigger_raw_email is as follows


CREATE OR REPLACE FUNCTION func_trigger_raw_email()
  RETURNS "trigger" AS
$BODY$
BEGIN
   PERFORM sp_trigger_raw_email(NEW.id, NEW.raw_email);
   RETURN NEW;
END;
$BODY$
  LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION func_trigger_raw_email() OWNER TO postgres;
----------------------------------------------------------------------------------------------------------------------------------------

My problems are as follows:

1. After i execute the function sp_raw_email_trigger, the second  argument  automatically  gets changed
    from char to bpchar. Don't know if this is dangerous.

2. function test(int, char*) has char* as its second parameter and i declare the arguments of the function that calls it as (int4, char).
   Is this a mismatch??
  
3. Test stores the values supplied to it in a table.

test(int caseno, char *rawemail)
{
   EXEC SQL CONNECT TO dbxyz;
 
   EXEC SQL BEGIN DECLARE SECTION;
        int id = caseno;
        char *email = rawemail;
   EXEC SQL END DECLARE SECTION;

   EXEC SQL INSERT INTO headers (id, header_content) VALUES (:id, :email);
   EXEC SQL COMMIT;

}


Now the value of rawemail argument the actually is supplied to it from the trigger using NEW.raw_email is as follows:

-----------------------------------------------
'From simon@simon-cozens.org Tue Apr 15 20:24:47 2003
X-MultiHeader: one
X-MultiHeader: two
X-MultiHeader: three
From: Simon Cozens <simon@simon-cozens.org>
To: test
Bcc: simon@twingle.net
Subject: foo
Mime-Version: 1.0
Content-Type: image/gif
Content-Disposition: attachment; filename="1.gif"
Content-Transfer-Encoding: base64
X-Operating-System: Linux deep-dark-truthful-mirror 2.4.9
X-POM: The Moon is Waxing Gibbous (98% of Full)
X-Addresses: The simon@cozens.net address is deprecated due to being broken. simon@brecon.co.uk still works, but simon-cozens.org or netthink.co.uk are preferred.
X-Mutt-Fcc: =outbox-200304
Status: RO
Content-Length: 1205
Lines: 17

R0lGODlhDAAMAPcAAAAAAAgICBAQEBgYGCkpKTExMTk5OUpKSoyMjJSUlJycnKWlpbW1tc7O
zufn5+/v7/f39///////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/////////////////////////////////ywAAAAADAAMAAAIXwAjRICQwIAAAQYUQBAYwUEB
AAACEIBYwMHAhxARNIAIoAAEBBAPOICwkSMCjBAXlKQYgCMABSsjtuQI02UAlC9jFgBJMyYC
CCgRMODoseFElx0tCvxYIEAAAwkWRggIADs=

'
----------------------------------------------


But what gets stored in header table is
just a 'T' with some junk characters.

Don't know if its because of a datatype mismatch or wrong copy command
used in the DECLARE SECTION i.e. char *email = rawemail;

I'm being too verbose here to include each phase of the problem.

Thanks and regards,
Jas

pgsql-general by date:

Previous
From: "Joe Kramer"
Date:
Subject: Large database design advice
Next
From: "Harald Armin Massa"
Date:
Subject: Re: Large database design advice