#198 MySQLdb.connect does not follow db-API 2.0

MySQLdb-1.2
closed
Andy Dustman
MySQLdb (285)
5
2012-09-19
2006-08-01
Mario Frasca
No

in footnote 1 the Python Database API Specification
v2.0 states:

As a guideline the connection constructor parameters
should be implemented as keyword parameters for more
intuitive use and follow this order of parameters:

dsn Data source name as string
user User name as string (optional)
password Password as string (optional)
host Hostname (optional)
database Database name (optional)

E.g. a connect could look like this:

connect(dsn='myhost:MYDB',user='guido',password='234$')
<<<

MySQLdb.connect uses passwd instead of password and db
instead of database.

Discussion

  • Andy Dustman
    Andy Dustman
    2006-08-01

    Logged In: YES
    user_id=71372

    Duplicate of bug #1515243. You'll excuse me if I don't
    break every MySQLdb application ever written. And please
    note the word "guideline", which is not same as
    "requirement". MySQL has no concept of a dsn anyway.

     
  • Mario Frasca
    Mario Frasca
    2006-08-01

    Logged In: YES
    user_id=512199

    excused! obviously!

    python offers keyword parameters, so it could be possible to
    accept both the 'guideline' syntax and the legacy one.

    I am willing to post a patch in this direction.

     
  • Mario Frasca
    Mario Frasca
    2006-08-01

    Logged In: YES
    user_id=512199

    but you already use kword parameters...
    what about this:

    if kwargs.has_key('database') and not kwargs.has_key('db'):
    kwargs2['db'] = kwargs2['database']
    del kwargs2['database']
    if kwargs.has_key('password') and not kwargs.has_key('passwd'):
    kwargs2['passwd'] = kwargs2['password']
    del kwargs2['password']