troubleshooting Question

sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.

Avatar of Dolamite Jenkins
Dolamite JenkinsFlag for United States of America asked on
* sqlite3SQLPythonDatabases
4 Comments1 Solution18 ViewsLast Modified:
Storing images in Sqlite ...I have no choice I have to use sqlite .... every thing works except when I try to execute the Insert query

line 36, in <module>
    cursor.execute(""" INSERT INTO my_table (name, image) VALUES (?,?)""",(name,image))
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.

my code snippet

import sqlite3
import os
import sys


#=============Create DataBase========================

conn = sqlite3.connect("my_db_example.db")
cursor = conn.cursor()

cursor.execute("""CREATE TABLE IF NOT EXISTS my_table (name TEXT,image BLOB)""")

conn.commit()
cursor.close()
conn.close()

#==============get & convert Data ================================================
image_name =[]
conn = sqlite3.connect("my_db_example.db")
cursor = conn.cursor()

arr = os.listdir('Images')
#print(arr)
for item in arr:
    image_name.append(item)
    name = image_name
    if ".jpg" in item:
        with open(item, "rb") as f:
            data = f.read()
            name = image_name
            image = data
            print("{} File Name ".format(name))
            print("{} File RB ".format(image))
            cursor.execute(""" INSERT INTO my_table (name, image) VALUES (?,?)""",(name,image))
            #print("{} Added to database ".format(image_name))

conn.commit()
cursor.close()
conn.close()
"Images" directory
Image 1.jpg
image 2.jpg
image3.jpg

when I print the output it is correct ...see sample output snippet

\xe6\x8dK\xbd\xbb~:\xdb\xe5:\xc5\nA\xb6u\x15`\x18\x04MFGt\xe5\x97\x90\x9c\x9ek\xe3<r\xfa\x7f\xf4p\xdd\xa3\x96\xe0\xf6mJ\xa7\xb8\xa6\xdfh\xe4\xbe\xb3A\x82\xec\xda.nw\xcf-\x17\xf5\x9a\x11kd\x00\xe9\t\xa7S\x9b`\xa2D\x14\x80\x16\x02\xc0r\x8d\xde\xd2[\t\x1a\xb1\xb1\x03\x9f\xba \x14\x1f\xc6\xde\xe8#_G\x04`\x7f\xff\xd9' File Read Binary
['maid5.jpg', 'Unknown.jpg', 'big5.jpg'] File Name 
If I just enter the Binary data into my BLOB it works, but I can't, get it to accept the the name & data(RB) with out throwing an error .... any help or suggestions 
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros