digglife / ibm-db

Automatically exported from code.google.com/p/ibm-db
0 stars 0 forks source link

Set SQL_ATTR_INFO_PROGRAMNAME connection attribute #144

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Set 'Application Name' when monitoring applications with 'db2 list application' 
so they not appear as 'python'.

USR1 python         27172      192.168.12.132.51577.131212110440                
              USR1DB  1

setting programName = PID on db2cli.ini will show python connections as below

USR1 CLI9137:3      52375      192.168.12.132.60187.131210122205                
              USR1DB  1

That's useful but could it be possible to change that to a custom string?
The connection attribute to set is SQL_ATTR_INFO_PROGRAMNAME. I tried to 
manually defined and set it but did not work.

>>> import ibm_db_dbi ; conn = ibm_db_dbi.connect("db2") ; cursor = 
conn.cursor()
>>> ibm_db_dbi.ibm_db.SQL_ATTR_INFO_PROGRAMNAME = 2516 # from sqlcli1.h
>>> ibm_db_dbi.SQL_ATTR_INFO_PROGRAMNAME = 
ibm_db_dbi.ibm_db.SQL_ATTR_INFO_PROGRAMNAME
>>> opt = {ibm_db_dbi.SQL_ATTR_INFO_PROGRAMNAME: 'luis_app'}
>>> conn.set_option(opt)

'Application name' still reported as 'python'

Original issue reported on code.google.com by south.mi...@gmail.com on 12 Dec 2013 at 2:41

GoogleCodeExporter commented 9 years ago
Added the constant to ibm_db.c and ibm_db_dbi.py and installed the module but 
did not work
# ibm_db.c
PyModule_AddIntConstant(m, "SQL_ATTR_INFO_PROGRAMNAME", 
SQL_ATTR_INFO_PROGRAMNAME);

# ibm_db_dbi.py
SQL_ATTR_INFO_PROGRAMNAME = ibm_db.SQL_ATTR_INFO_PROGRAMNAME

The constant looks like correctly added

Python 2.6.8 (unknown, May 29 2012, 22:30:44) 
[GCC 4.3.4 [gcc-4_3-branch revision 152973]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ibm_db_dbi
>>> ibm_db_dbi.__version__
'2.0.4.1'

>>> ibm_db_dbi.SQL_ATTR_INFO_PROGRAMNAME
2516

Original comment by south.mi...@gmail.com on 12 Dec 2013 at 3:55

GoogleCodeExporter commented 9 years ago
SQL_ATTR_INFO_PROGRAMNAME need to be set before the connection establish, after 
that you can't be set this.

To set SQL_ATTR_INFO_PROGRAMNAME connection attribute you need to pass it in 
conn_option as follows

>>>
opt = {ibm_db_dbi.SQL_ATTR_INFO_PROGRAMNAME : 'luis_app'}
conn = ibm_db_dbi.connect("db2", conn_options=opt)
<<<

Thanks,
Rahul

Original comment by rahul.pr...@in.ibm.com on 13 Dec 2013 at 11:27

GoogleCodeExporter commented 9 years ago
Thanks Rahul, it worked! The code in the previous comment worked with
my patched version of the module and failed on the unmodified one.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'SQL_ATTR_INFO_PROGRAMNAME'

The code below works with the unmodified version, 1.0.6 in my test.

<ibm_db_dbi.Connection object at 0x7e3750>

Any plans to add the constant on future versions?

Best
Luis

Original comment by south.mi...@gmail.com on 13 Dec 2013 at 12:44

GoogleCodeExporter commented 9 years ago
I will add this constant to our next release, but I will add it for ibm_db 
driver only. This should not create any problem to you since it is accessible 
to program as following manner 

>>>
import ibm_db
opt = {ibm_db.SQL_ATTR_INFO_PROGRAMNAME : 'luis_app'}
conn = ibm_db_dbi.connect("db2", conn_options=opt)
<<< 

Original comment by rahul.pr...@in.ibm.com on 16 Dec 2013 at 9:23

GoogleCodeExporter commented 9 years ago
Thanks. It also accessible as below, right?

import ibm_db_dbi
opt = {ibm_db_dbi.ibm_db.SQL_ATTR_INFO_PROGRAMNAME : 'luis_app'}

Original comment by south.mi...@gmail.com on 16 Dec 2013 at 12:45

GoogleCodeExporter commented 9 years ago
FYI, programName = PID on db2cli.ini seems to conflict with my compiled version 
of the module and causes a segmentation fault

 segfault at 0 ip 00007ffff34c698e sp 00007fffffffb058 error 6 in libdb2.so.1[7ffff2efb000+15b6000]

The module works well if programName option is not present.

Original comment by south.mi...@gmail.com on 16 Dec 2013 at 1:58