Re: a question about mysqldb

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric Wertman

    Re: a question about mysqldb

    Just to make sure I understand what you are showing me here:
    columns = ('tID', 'tNote')
    table_name = 'tmp'
    sql = 'select %s from %s where tID=:1' % ( ', '.join(columns) , table_name)
    cursor.execute( sql, (1,))
    >
    # sql is now 'select tID, tNote from tmp where tID=:1'
    # note the comma in argument tuple to execute (1,)

    This means I could use this type of syntax?

    sql = 'SELECT (date,time,name ,size,count,stu ff,flavor) FROM crazyTable
    where monster=:1 and feet=:2 and price=:3'

    cursor.execute( sql,('cookie',' 3',77.44))

    ?

    I've not encountered that argument style before.
  • Carsten Haese

    #2
    Re: a question about mysqldb

    Eric Wertman wrote:
    This means I could use this type of syntax?
    >
    sql = 'SELECT (date,time,name ,size,count,stu ff,flavor) FROM crazyTable
    where monster=:1 and feet=:2 and price=:3'
    >
    cursor.execute( sql,('cookie',' 3',77.44))
    >
    ?
    That depends on which database and DB-API module you're using. Numeric
    parameter style definitely works with sqlite and InformixDB, and I think
    it works with cx_Oracle and mxODBC. Last I checked, it didn't work with
    any PostgreSQL module nor with MySQLdb, but I haven't checked recently
    enough to state categorically that it doesn't work.

    For a definitive answer, check the documentation for the DB-API module
    you're using.

    --
    Carsten Haese

    Comment

    Working...