-1

I am getting into SQL, trying to insert a value into a specific table column but it seems it only wants to take one character compared to the entire string I am attempting to supply it.

import sqlite3
import random

conn = sqlite3.connect(r"test.db")
cursor = conn.cursor()
profile_ID = str(random.randint(100,999))

'''
insert into one column
'''
cursor.execute("INSERT INTO Webstore(Running) VALUES(?)", (profile_ID))

this is the error that appears:

sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 3 supplied.

It seems the insert with the query above only wants to accept one character versus the three in profile_ID, I attempt to send a string such as "string 6" and it would pass me the same error but "8 supplied" in this case (8 characters in "string 6").

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Shaneless
  • 11
  • 3

2 Answers2

0

inserting one value:

cursor.execute("insert into Webstore (Running) values (%s)" % profile_ID)

inserting multiple values (? works here without error):

cursor.execute("insert into Webstore (Running, Status) values (?, ?)", (profile_ID, status))
Shaneless
  • 11
  • 3
0

I am no expert in using sqlite, but I firmly believe the problem you are sticking with is not related to this module; rather, it's a tuple issue. I believe you need to change this line:

cursor.execute("INSERT INTO Webstore(Running) VALUES(?)", (profile_ID))

to this line:

cursor.execute("INSERT INTO Webstore(Running) VALUES(?)", (profile_ID,))

There is a slight difference between these two lines. (profile_ID) has been changed to (profile_ID,). The former could be anything based on the value of profile_ID: a string, an integer, or even a float. But the latter is absolutely a tuple which I believe you will need for the second variable in cursor.execute.

TheFaultInOurStars
  • 3,464
  • 1
  • 8
  • 29