Unix Technical Forum

RE: Method to determine if in a transaction?

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 ...


Go Back   Unix Technical Forum > Database Server Software > Informix

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-20-2008, 11:37 AM
Christopher Coleman
 
Posts: n/a
Default RE: Method to determine if in a transaction?

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-20-2008, 11:39 AM
keshava.news@gmail.com
 
Posts: n/a
Default Re: Method to determine if in a transaction?

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.

>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-20-2008, 11:39 AM
Matt Penning
 
Posts: n/a
Default Re: Method to determine if in a transaction?

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.
>
>
>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:27 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com