1

Given a SQLite table I've created, with the field in question being type TEXT, the following fails:
hsh = hashlib.sha1("".join(some_list)).hexdigest()
db_setup(hsh)

I receive the error:
InterfaceError: Error binding parameter 2 - probably unsupported type.

def db_setup(my_hash, oavals)
    to_insert = (my_hash,)
    ('INSERT INTO position VALUES \
    (null, ?, ?, null, ?, ?, ?, ?, ?)',(0, 0, to_insert,
    oavals["a"], oavals["b"],
    oavals["c"], oavals["d"]))

If I substitute a manual int or string (e.g. 57, or "hello" for to_insert in the db_setup def, it works fine, which leads me to believe that it's tripping over the hash, for some reason. I feel as if I'm missing something obvious here.


Table schema:
'CREATE TABLE position \
(id INTEGER PRIMARY KEY, position INTEGER, displayline INTEGER, \
header TEXT, digest TEXT, conkey TEXT, consecret TEXT, \
acckey TEXT, accsecret TEXT)'

1
  • What is the schema for the table? Commented Jan 22, 2011 at 1:45

1 Answer 1

2

It is failing because to_insert is a tuple, not the value you wish to insert.

Try changing that first line to:

to_insert = my_hash

Or better yet, just put my_hash into your parameter list.

Here's an example:

>>> hsh = '49cb6536afc7e4a4b3a94eb493aae4d52b8f6a60'
>>> conn = sqlite3.connect(':memory:')
>>> c = conn.cursor()
>>> c.execute("CREATE TABLE t (i TEXT);")
>>> c.execute("INSERT INTO t VALUES (?)", (hsh,)) # tuple works
<sqlite3.Cursor object at 0x011A35E0>
>>> c.execute("INSERT INTO t VALUES (?)", ((123,),)) # tuple within tuple doesn't
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.
Sign up to request clarification or add additional context in comments.

1 Comment

Yep, that was it. The tuple-within-tuple was the problem. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.