Problem with format string / MySQL cursor
timaranz at gmail.com
timaranz at gmail.com
Thu Oct 18 15:44:36 EDT 2007
On Oct 19, 7:32 am, Florian Lindner <Florian.Lind... at xgm.de> wrote:
> Hello,
> I have a string:
>
> INSERT INTO mailboxes (`name`, `login`, `home`, `maildir`, `uid`,
> `gid`, `password`) VALUES (%s, %s, %s, %s, %i, %i, %s)
>
> that is passed to a MySQL cursor from MySQLdb:
>
> ret = cursor.execute(sql, paras)
>
> paras is:
>
> ('flindner', 'te... at florian-lindner.de', '/home/flindner/', '/home/
> flindner/Mail/test', 1001, 1001, '123')
>
> But that gives me an error:
>
> Traceback (most recent call last):
> File "account.py", line 188, in ?
> main()
> File "account.py", line 33, in main
> execute(action, account_type, options)
> File "account.py", line 129, in execute
> executeSQL(sql, options.username, options.login, options.home,
> options.directory, options.uid, options.gid, options.password)
> File "/home/flindner/common.py", line 29, in executeSQL
> ret = cursor.execute(sql, paras)
> File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line
> 148, in execute
> query = query % db.literal(args)
> TypeError: int argument required
>
> I don't see errors in the format string or some other problem....
>
> What's wrong?
>
> Thanks,
>
> Florian
You should be using '?' for parameter bindings in your sql string not
python format specifiers (you are after all writing sql here not
python).
INSERT INTO mailboxes (`name`, `login`, `home`, `maildir`, `uid`,
`gid`, `password`) VALUES (?, ?, ?, ?, ?, ?, ?)
Cheers
Tim
More information about the Python-list
mailing list