waliwali / ibm-db

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

ibm_db_dbi - connect / pconnect methods should accept **kwargs instead of a dictionary #107

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I think the connect / pconnect methods in ibm_db_dbi should accept **kwargs 
intead of a dictionary. DBAPI is vague about this, but from looking at other 
libraries, ibm_db_dbi seems to be the only one that expects a dictionary for 
the 6th parameter. Psycopg2, for example, has 2 extra keyword arguments plus 
**kwargs, while pymssql just uses a bunch of keyword arguments.

By changing to **kwargs, the code can be simplified and also be more compatible 
with how SQLAlchemy's create_connect_args() works, e.g. we can have the more 
natural:

return ((dsn, conn_args['username'],'','',''), {'xxx': 'yyy'})

instead of:

return ((dsn, conn_args['username'],'','',''), {'conn_options': {'xxx': 'yyy'}})

Original issue reported on code.google.com by sok...@gmail.com on 2 May 2012 at 1:43

Attachments:

GoogleCodeExporter commented 9 years ago
Note that the diff has to be applied on top of the one in issue 103. And it 
breaks backward compatibility :)

Original comment by sok...@gmail.com on 2 May 2012 at 1:50

GoogleCodeExporter commented 9 years ago
Why you think that "return ((dsn, conn_args['username'],'','',''), {'xxx': 
'yyy'})" statement will not work with ibm_db_dbi, in this statement also you 
are passing a dictionary  "{'xxx': 'yyy'}" in sixth argument.

Original comment by rahul.pr...@in.ibm.com on 8 May 2012 at 9:38

GoogleCodeExporter commented 9 years ago
The following shall illustrate why...

def func1(arg1, arg2, params):
    print 'func1 called with', arg1, arg2, params

def func2(arg1, arg2, **kwargs):
    print 'func2 called with', arg1, arg2, kwargs

list_params = ('a', 'b')
dict_params = {'c': 123}
try:
    func1(*list_params, **dict_params)
except:
    assert True
func2(*list_params, **dict_params)

Original comment by sok...@gmail.com on 8 May 2012 at 12:07

GoogleCodeExporter commented 9 years ago
Could you please provide me the error message which you are getting while 
passing the argument through SQLAlchemny.

Original comment by rahul.pr...@in.ibm.com on 16 May 2012 at 12:31

GoogleCodeExporter commented 9 years ago
In ibm_db_sa/ibm_db.py, put something into the dictionary in either this line:

return ((dsn, uid, pwd,'',''), {})

or this line:

return ((dsn, conn_args['username'],'','',''), {})

For example:

return ((dsn, conn_args['username'],'','',''), {'abc': 123})

Then, create an engine and connect:

>>> from sqlalchemy.engine import create_engine
>>> engine = create_engine('ibm_db_sa://user:password@localhost:1234/test')
>>> engine.connect()

This will raise error "DBAPIError: (TypeError) connect() got an unexpected 
keyword argument 'abc' None None"

Original comment by sok...@gmail.com on 16 May 2012 at 12:46