我有以下功能
def get_id(entityName, text):
"""Retrieve an entity's unique ID from the database, given its associated text.
If the row is not already present, it is inserted.
The entity can either be a sentence or a word."""
tableName = entityName + 's'
columnName = entityName
cursor.execute('SELECT rowid FROM ' + tableName + ' WHERE ' + columnName + ' = %s', (text,))
row = cursor.fetchone()
if row:
return row[0]
else:
cursor.execute('INSERT INTO ' + tableName + ' (' + columnName + ') VALUES (?)', (text,))
return cursor.lastrowid
每当调用此方法时,都会产生此错误
cursor.execute('SELECT rowid FROM ' + tableName + ' WHERE ' + columnName + ' = ?', (text,))
InterfaceError: Error binding parameter 0 - probably unsupported type.
目前,当我在 django 中运行此错误时,会产生此错误 否则它工作正常。 可能是什么原因?
最佳答案
这里我的参数 0(文本)的类型是 <type 'unicode'>
,数据库中的列数据类型为 text type
所以错误
InterfaceError: Error binding parameter 0 - probably unsupported type.
很明显,因为参数0不符合数据库列的类型
我之前没有得到这个,因为我是从另一个来源得到的。
但得到它不是文本类型后我必须将其转换为文本类型
类似 str(text)
它现在就像一个魅力
关于python - 接口(interface)错误: Error binding parameter 0 - probably unsupported type when runing my django script,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49835272/