On 11/19/06, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> "Rajesh Kumar Mallah" <mallah.rajesh@gmail.com> writes:
> > In our webapps, we use the same username to connect to the database
> > for all kind of updates. Hence we are not able to makeout whoo modified
> > what . However at application level we have different "userid" for
> different
> > users of the system. we want to somehow pass this "userid" to the
> databasee
> > server and accesss it from the triggers that implement the audit
> functions.
>
> Perhaps it would be better to make your "userid" be the actual database
> user? But anyway, the custom GUC variable facility might serve your
> needs.
> http://www.postgresql.org/docs/8.1/static/runtime-config-custom.html
Dear Tom,
Thanks for the suggestion , it seems to be working.
i used GetConfigOption of guc.c to retrieve the value.
I am setting the variable from psql eg:
SET general.employee to 101;
I hope what i am doing is correct . I have very little
experience in using C for triggers. can you please tell
if its fine.
in postgresql.conf i declared.
custom_variable_classes = 'general'
And inside the TRIGGER FUNCTION i use the below
------------ x------------------------ int employee = 0 ; /* int for holding employee_id */ char *employee_str ; /*
forstoring result for GetConfigOption */
employee_str = (char *) GetConfigOption("general.employee") ;
if (employee_str != NULL) { employee = atoi(employee_str); }
-------------x----------------------------
also if i do not cast using (char *) the compiler gives a warning:
audit_trail.c:82: warning: assignment discards qualifiers from pointer
target type
why so?
I have verified that the variable is isolated in transaction and
serves my purpose.
Regards
Mallah.
>
> regards, tom lane
>