i have the following function
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
when ever this method get called it producing this error
cursor.execute('SELECT rowid FROM ' + tableName + ' WHERE ' + columnName + ' = ?', (text,))
InterfaceError: Error binding parameter 0 - probably unsupported type.
currently this error is producing when i am running this in django otherwise its working fine. what can be the reason ?
here the type of my parameter 0 (text) was a <type 'unicode'>
, and the column data-type in database was a text type
so the error
InterfaceError: Error binding parameter 0 - probably unsupported type.
is obvious, as parameter 0 is not meeting the type of database column
i did'nt get this earlier ,as i was getting this from another source.
But after getting it is not a text type i had to convert it in text type
something like str(text)
its working like a charm now