Python, MySQLdb and escaping table names?

前端 未结 3 1989
萌比男神i
萌比男神i 2020-12-11 17:13

I may be missing something obvious, but I can\'t figure out how my code is different from various examples I see in the online documentation for MySQLdb.

I\'m fairly

3条回答
  •  無奈伤痛
    2020-12-11 18:05

    You cannot use DB-API for metadata; you will need to make replacements yourself outside of the execute() call.

    query = 'SELECT MAX(%%s) FROM `%s`' % (table,)
    cursor.execute(query, (countcol,))
    

    Obviously you should not do this if table comes from an outside source.

提交回复
热议问题