我与python 3.x和mariadb一起使用。
我尝试执行以下功能,但是它向我表明SQL命令存在问题。
此功能:
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 + '
= ?', (text,))**
row = cursor.fetchone()
if row:
return row[0]
else:
**cursor.execute('INSERT INTO ' + tableName + ' (' + columnName + ')
VALUES (?)', (text,))**
return cursor.lastrowid
,我收到以下错误:
mysql.connector.errors.ProgrammingError: Not all parameters were used in the
SQL statement
我试图将查询写到:
cursor.execute('SELECT rowid FROM words WHERE word = ?', (text,))
cursor.execute('INSERT INTO words (word) VALUES (?)', (text,))
,但错误仍然存在。
我很乐意帮助您了解我在做什么错吗?
谢谢