Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SQL code not working
#1
Hi
Please can someone help me spot the problem with this code:

import sqlite3

conn = sqlite3.connect("Table example.db")
c = conn.cursor()

def createTable ():
    c.execute("CREATE TABLE Example(Language TEXT)")

def enterDynamicData (lang):
    c.execute ("INSERT INTO Example VALUES(?)",(lang))
    conn.commit ()

#createTable ()

lang=input("Lang: ") 
enterDynamicData (lang)
Error code
Error:
Traceback (most recent call last): File "C:/Users/Eitan/Dropbox/Python/Code/Table creation.py", line 15, in <module> enter_dynamic_data() File "C:/Users/Eitan/Dropbox/Python/Code/Table creation.py", line 11, in enter_dynamic_data c.execute("INSERT INTO example(Language) VALUES(?)",(lang)) sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 3 supplied.
Reply
#2
(Mar-08-2018, 04:05 PM)eml Wrote:
c.execute ("INSERT INTO Example VALUES(?)",(lang))
Something wrapped in parenthases does not make a tuple unless there's more than one element. Which means you're not passing a one-element tuple, you're passing a three-element string (...I'm guessing).

Normally, people just add a dangling comma to force a tuple:
>>> lang = "en1"
>>> (lang)
'en1'
>>> (lang, )
('en1',)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  New to Python - Not sure why this code isn't working - Any help appreciated TheGreatNinx 4 960 Jul-22-2023, 10:21 PM
Last Post: Pedroski55
  code not working when executed from flask app ThomasDC 1 891 Jul-18-2023, 07:16 AM
Last Post: ThomasDC
  I am new to python and Could someone please explain how this below code is working? kartheekdas 2 1,016 Dec-19-2022, 05:24 PM
Last Post: kartheekdas
Exclamation My code is not working as I expected and I don't know why! Marinho 4 1,081 Oct-13-2022, 08:09 PM
Last Post: deanhystad
  My Code isn't working... End3r 4 1,930 Mar-21-2022, 10:12 AM
Last Post: End3r
  I don't undestand why my code isn't working. RuyCab 2 1,990 Jun-17-2021, 03:06 PM
Last Post: RuyCab
  code is not working , can anybody help? RandomPerson69 4 2,910 Mar-22-2021, 04:24 PM
Last Post: deanhystad
  Short code for EventGhost not working Patricia 8 3,687 Feb-09-2021, 07:49 PM
Last Post: Patricia
  Code no longer working yk303 14 10,179 Dec-21-2020, 10:58 PM
Last Post: bowlofred
  autocomplete working code sample not working... aviper4u 0 1,640 Oct-24-2020, 03:04 AM
Last Post: aviper4u

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020