Re: Need a way to know SessionID
Posted in 1997
You can get the running session id in the sysmaster:syslocks table by just
selecting in the syslocks table itself, where the bitwise flags has the
appropriate bit value set (sorry I can't remember here the exact value).
This works on all hosts running only one processor. On multiprocessor
systems, you must find a way to restrain the selection, for example
allowing only one connection with the same USER. In that case, the system
function USER can be used to restrain completely the search.
Put that select within a small procedure sessionid() which returns an
integer, so that you can use session_id() instead of DBINFO("sessionid").
I have not seen any problem with that method on the previous 7.1x servers I
used (I used it to completely emulate the Sybase-specific embedded
subtransaction feature, which allow a consistant development of procedures
which use sub-procedures that can also be called alone as a single
transaction). But now I have upgraded to 7.22 so the sessionid() more
safely returns DBINFO("sessionid").
Example to support Sybase-specific embedded subtransactions:
CREATE TABLE sessions(
sessionid int not null,
trancount int not null
) LOCK MODE ROW;then use the session id to see if the session exists in the session table.
If not, BEGIN WORK, and insert a line with transaction count 1 in the
sessions table, and return; if already exists, simply increment the
transaction count, continuing the supposedly running transaction in the
current session.
In case of commit, decrement the transaction count, and if it falls back to
zero, COMMIT WORK, then delete the line from the sessions table.
In case of ROLLBACK, just call ROLLBACK WORK, this will delete the active
session in the session table.
You may include all that within small procedures like begintran(),
committran() and rollbacktran(), so that they will be eaisly used.
Performance of that method is really good.
The Lock Mode Row in the sessions table is important to avoid multisession
interlocking which will always occur if you forget it, because the session
table rows are short and one page may contain many active sessions running
transactions. In Page locking mode, only one session could be running at
one time, and chances of deadlocks are more probable of occuring, in
addition to the dramatic slowdown of transactions to to the contention on
the sessions table.
Drew <asimpson@matcom2.fcic.usda.gov> a 'crit dans l'article
<33B80028.11C2@matcom2.fcic.usda.gov>...
> > Hi,
> >
> > DBINFO('sessionid') will do, I reckon:>
>
> Hi,
>
> DBINFO('sessionid') returns a -728 on Informix7.13.> Does anyone know a way of getting session id using 7.13 release?
>
> Drew
>