mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement
Hi There,
I am just starting to investigate how to use python and mysql with blob data and I created a very simple script that creates a table and then opens an image file before saving the resulting data to the database.
I first tried it in SQLite3 (which is what I am used to) and it works fine:
import sqlite3
import mysql.connector as conn
db = con.connect(
cursor = db.cursor()
sql = """create table blob_store
(blob_id integer,
blob_file text,
blob_data blob,
primary key(blob_id))"""
cursor.execute(sql)
db.commit()
image = open("adam.
image_data = image.read()
image.close()
test_data = [["hello"
sql = "insert into blob_store (blob_file, blob_data) values (?,?)"
for each in test_data:
cursor.
db.commit()
cursor.close()
I changed the above code to use mysql instead:
import mysql.connector as conn
db = conn.connect(
cursor = db.cursor()
sql = """create table blob_store
(blob_id integer auto_increment,
blob_file text,
blob_data blob,
primary key(blob_id))"""
cursor.execute(sql)
db.commit()
image = open("adam.
image_data = image.read()
image.close()
test_data = [["hello"
sql = "insert into blob_store (blob_file, blob_data) values (?,?)"
for each in test_data:
cursor.
db.commit()
cursor.close()
How when I run it this way I get the following error:
Traceback (most recent call last):
File "/Users/
cursor.
File "/Library/
"Not all parameters were used in the SQL statement")
mysql.connector
However, if I change it to use tokens it works fine:
import mysql.connector as conn
db = conn.connect(
cursor = db.cursor()
sql = """create table blob_store
(blob_id integer auto_increment,
blob_file text,
blob_data blob,
primary key(blob_id))"""
cursor.execute(sql)
db.commit()
image = open("adam.
image_data = image.read()
image.close()
test_data = [["hello"
sql = "insert into blob_store (blob_file, blob_data) values (%s,%s)"
for each in test_data:
print(each)
cursor.
db.commit()
cursor.close()
Is this the preferred method of adding data or am I doing something wrong with the questions marks?
Thanks for any assistance,
Kind Regards,
Adam.
Question information
- Language:
- English Edit question
- Status:
- Solved
- Assignee:
- No assignee Edit question
- Solved by:
- Geert JM Vanderkelen
- Solved:
- Last query:
- Last reply: