我在尝试将一些数据插入mysql时遇到错误。这是代码
import oursql
db = oursql.connect('localhost','root','pass',db='schem')
curr = db.cursor()
sql = "INSERT INTO schem.comments (CreationDate,Text,UserId,Score,PostId,Id)\
VALUES (?,?,?,?,?,?)"
data = ('2009-06-28T08:23:41.833', "Text", '1', '3', '3', '2')
curr.execute(sql,data)
db.commit()
这是追溯
Traceback (most recent call last):
File "E:\...\test.py", line 9, in <module>
curr.execute(sql,data)
File "cursor.pyx", line 122, in oursql.Cursor.execute (oursqlx\oursql.c:15329)
File "statement.pyx", line 384, in oursql._Statement.execute (oursqlx\oursql.c:9606)
File "statement.pyx", line 126, in oursql._Statement._raise_error (oursqlx\oursql.c:6997)
oursql.InterfaceError: (2036, 'Using unsupported buffer type: 29127352 (parameter: 3)', None)
我在win 7(32位)上使用python 2.6.6,mysql 5.5和oursql 0.9.2。这可能是一个错误,还是我的代码有问题?
以下工作正常:
import MySQLdb
db = MySQLdb.connect('localhost','root','pass',db='schem')
curr = db.cursor()
sql = "INSERT INTO schem.comments (CreationDate,Text,UserId,Score,PostId,Id)\
VALUES (%s,%s,%s,%s,%s,%s)"
data = ('2009-06-28T08:23:41.833', "Text", '1', '3', '3', '2')
curr.execute(sql,data)
db.commit()