This is a discussion on RE: Method to determine if in a transaction? within the Informix forums, part of the Database Server Software category; --> John Miller provided a simple C UDR to return the transaction state: ===============SOURCE CODE FOR trans.c====================== #include "incl/public/milib.h" mi_integer ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| John Miller provided a simple C UDR to return the transaction state: ===============SOURCE CODE FOR trans.c====================== #include "incl/public/milib.h" mi_integer istransaction() { return (mi_transaction_state() == MI_NO_XACT ? 0 : 1 ); } =============== This would be an easy option for DBINFO or something similar, I would think, and a useful extension for SPL. You may add this to the feature request list under my name and company, if you like. The handy thing about SPL as opposed to C UDR's is that it does not have to be recompiled if your application is on multiple platforms. Even if the code is as simple as John's, it has to be source-controlled, compiled, and tested on each platform. I was having a discussion with someone off-group who did not think this was worth asking for because we all have access to examples of how to find this in SPL with a simple error handler. (Search for txstate.spl in http://www.iiug.org/software/archive/spl_jl_20021010 for example.) On the other hand, try explaining to a newbie why this is necessary, especially when the database server knows whether or not the thread is in a transaction. Sincerely, Christopher Coleman Steering Committee President Kansas City Informix Users Group www.iiug.org/kciug Database Analyst Pharmacy Division Mediware Information Systems, Inc. |
| |||
| In IDS, you can do this without writing an C code. The function f() below returns the values returned by mi_transaction_state. 0 -- Not in a transaction. 1 -- in a multi-statement transaction [started with begin work] 2 -- in an implicitly started transaction. Non-zero value indicates you're in a transaction. cheers, Keshav. create database foo with log; > create function f() returns int > external name '(mi_transaction_state)' language c; Routine created. > execute function f(); (expression) 0 1 row(s) retrieved. > > begin work; Started transaction. > execute function f(); (expression) 1 1 row(s) retrieved. > commit work; Data committed. > select f() from systables where tabid = 1; (expression) 2 1 row(s) retrieved. > |
| ||||
| Thanks! It hadn't occurred to me that one could simply create a function that maps to an existing C DataBlade routine, that could be useful for other things too, I suspect. - Matt keshava.news@gmail.com wrote: > In IDS, you can do this without writing an C code. > > The function f() below returns the values returned by > mi_transaction_state. > 0 -- Not in a transaction. > 1 -- in a multi-statement transaction [started with begin work] > 2 -- in an implicitly started transaction. > > Non-zero value indicates you're in a transaction. > > cheers, > > Keshav. > > create database foo with log; > > >>create function f() returns int >>external name '(mi_transaction_state)' language c; > > > Routine created. > > >>execute function f(); > > > > (expression) > > 0 > > 1 row(s) retrieved. > > >>begin work; > > > Started transaction. > > >>execute function f(); > > > > (expression) > > 1 > > 1 row(s) retrieved. > > >>commit work; > > > Data committed. > > > >>select f() from systables where tabid = 1; > > > > (expression) > > 2 > > 1 row(s) retrieved. > > > |
| Thread Tools | |
| Display Modes | |
|
|