Re: Method to determine if in a transaction?
Posted in 2006
Matt:
Yout can create your own 2 line C UDR (User Defined Routine) to return
this information. Below are the step and code you can use. I did this
on Solaris 2.8 and version 10 of informix.
Hope ths helps,
John
===============SOURCE CODE FOR trans.c======================
#include "incl/public/milib.h"
mi_integer istransaction()
{
return (mi_transaction_state() == MI_NO_XACT ? 0 : 1 );
}
STEP to CREATE AND REGISGER A UDR
=======================================================
# Compile the program
cc -c -xarch=v9 -I$INFORMIXDIR trans.c
# Link to create a shared library
ld -G -o trans.so trans.o
# Create a well know place to store your libraries
mkdir $INFORMIXDIR/lib/myfuncs
# Move you new library to this location
cp trans.so $INFORMIXDIR/lib/myfuncs
# Create a database for testing
dbaccess - -<<END
drop database trans;
create database trans with log;END
# Register your new function
dbaccess trans -<<END
create function istrans() returning integerEXTERNAL NAME "$INFORMIXDIR/lib/myfuncs/trans.so(istransaction)"
LANGUAGE C;
END
# Try your new function
dbaccess trans -<<END
execute function istrans();
begin work;
execute function istrans();
commit work;
END
Matt Penning wrote:
> Is there a way, in SPL, to determine if you are already in a transaction
> or not? I know it is possible to try to create a new transaction and
> then catch the exception if it fails, but I am wondering if there is a
> simpler approach - a global variable or something.