Writing to Database

This is the place for queries that don't fit in any of the other categories.

Writing to Database

Postby jogl8 » Thu Aug 08, 2013 12:49 pm

I decided to try switching from sqlite3 to mySQL.

This:
Code: Select all
with conn:
            cur = conn.cursor()

            cur.execute("INSERT INTO t3d VALUES(?, ?, ?, ?, ?, ?, ?, ?)", (iyear, imonth, iday, ihour, iminute, isecond, inode, irawdata))

            conn.commit()

worked in sqlite3 but I get this error from mySQL:

Code: Select all
Traceback (most recent call last):
  File "test3m.py", line 68, in <module>
    cur.execute("INSERT INTO t3d VALUES(?, ?, ?, ?, ?, ?, ?, ?)", (iyear, imonth, iday, ihour, iminute, isecond, inode, irawdata))
  File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 159, in execute
    query = query % db.literal(args)
TypeError: not all arguments converted during string formatting

It almost looks like something is wrong with the cursors.py program. Any ideas?

Thanks,
JP.
jogl8
 
Posts: 33
Joined: Fri Feb 08, 2013 4:46 pm
Location: SW Ontario, Canada

Re: Writing to Database

Postby stranac » Thu Aug 08, 2013 1:02 pm

MySQLdb uses %s for parameter substitution placeholder, not ?.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1212
Joined: Thu Feb 07, 2013 3:42 pm

Re: Writing to Database

Postby jogl8 » Thu Aug 08, 2013 2:02 pm

Thank you Stranac.
jogl8
 
Posts: 33
Joined: Fri Feb 08, 2013 4:46 pm
Location: SW Ontario, Canada


Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot] and 6 guests