java - How do I set a variable in MySQL 5.5 using JDO and DataNucleus? -


as part of audit logging process, need set variable @user_id in code before running insert into... statement. insert initiate trigger uses @user_id.

i have tried following queries:

set @user_id = 5 

this not work because resultset cannot null (and query returns nothing)

select 51 @user_id 

this not work because again, resultset cannot null in java

select @user_id := 51 

this not work because : character translated parameter token when running queries using persistencemanager , query object.

so, using datanucleus, how can set variable trigger statement succeeds necessary information auditing purposes?

my java code run queries follows:

persistencemanager pm = getpersistencemanager(); // own function persistencemanager query q = pm.newquery("javax.jdo.query.sql", "query here"); q.execute(); 

if cannot done, other options can try achieve same result?

edit: using google app engine, , therefore stored procedures not available me.

i couldn't find way around issues described above, instead used different approach i'll explain:

i created table named transaction_properties has 2 columns: user_id , connection_id.

before each transaction commit, insert transaction_properties table id of user (which know @ stage), , mysql placeholder connection_id(), outputs current connection id.

in trigger, use following statements find user_id transaction:

declare user_id bigint;  select `userid` user_id `transaction_properties` `transaction_id` = connection_id() limit 1;  if user_id null   set user_id = -1; end if; 

i can reference declared variable user_id in insert audit table elsewhere in trigger.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -