SQLite Forum

Error in SQLite 'all VALUES must have the same number of terms'

Error in SQLite 'all VALUES must have the same number of terms'

(1) By Aneesh Mehta (Mehta_aneesh) on 2021-01-18 10:30:54 [link] [source]

Glad to be a part of this platform among you, highly experienced programmers, Nowadays I am working on a POS system project in python, using tkinter for frontend & Sqlite as the database. While putting data into it, I am facing this issue.

def proceed_raise_invoice(): execute_query(connection, create_invoices)

ttk.Label(tab1, text="Raise Invoice", font=('', 20)).grid(column=0, row=0) ttk.Label(tab1, text="General Details:", font=('', 15)).grid(column=0, row=4) invoice_number = tk.StringVar() ttk.Label(tab1, text="Invoice Number:", font=('', 12)).grid(column=0, row=5) ttk.Entry(tab1, width=22, font=('', 12), textvariable=invoice_number).grid(column=3, row=5) invoice = invoice_number.get() invoice_date = date.today() ttk.Label(tab1, text="Date:", font=('', 12)).grid(column=0, row=6) ttk.Entry(tab1, width=22, font=('', 12), textvariable=invoice_date).grid(column=3, row=6) ttk.Label(tab1, text="Details of receiver/billed to:", font=('', 15)).grid(column=0, row=7) name = "" ttk.Label(tab1, text="Name:", font=('', 12)).grid(column=0, row=8) ttk.Combobox(tab1, width=30, textvariable=name).grid(column=3, row=8) customer_gstin = "07" ttk.Label(tab1, text="GSTIN:", font=('', 12)).grid(column=0, row=9) ttk.Label(tab1, text="", font=('', 12), textvariable=customer_gstin).grid(column=3, row=9) ttk.Label(tab1, text="Purchasing:", font=('', 15)).grid(column=0, row=10) product = "" ttk.Label(tab1, text="Name of product:", font=('', 12)).grid(column=0, row=11) ttk.Entry(tab1, width=22, font=('', 12), textvariable=product).grid(column=3, row=11) hsn = "" ttk.Label(tab1, text="HSN ACS:", font=('', 12)).grid(column=0, row=12) ttk.Combobox(tab1, width=30, textvariable=hsn).grid(column=3, row=12) uom = "" ttk.Label(tab1, text="Units of Measure:", font=('', 12)).grid(column=0, row=13) ttk.Entry(tab1, width=33, textvariable=uom).grid(column=3, row=13) quantity = int(1) ttk.Label(tab1, text="Quantity:", font=('', 12)).grid(column=0, row=14) ttk.Entry(tab1, width=22, font=('', 12), textvariable=quantity).grid(column=3, row=14) rate = int(0) ttk.Label(tab1, text="Rate:", font=('', 12)).grid(column=0, row=15) ttk.Entry(tab1, width=22, font=('', 12), textvariable=rate).grid(column=3, row=15) supplier = "" ttk.Label(tab1, text="Supplier:", textvariable=supplier, font=('', 15)).grid(column=0, row=18) ttk.Combobox(tab1, width=20, font=('', 12)).grid(column=3, row=18) ttk.Button(tab1, text='Proceed', command=proceed_raise_invoice).grid(column=3, row=19)

amount = quantity * rate

list = ['invoice_number', 'invoice_date', 'name', 'customer_gstin', 'product', 'hsn', 'uom', 'quantity', 'rate', 'amount', 'supplier']'invoice_number', 'invoice_date', 'name', 'customer_gstin', 'product', 'hsn', 'uom', 'quantity', 'rate', 'amount', 'supplier'

create_invoices_table = """ CREATE TABLE IF NOT EXISTS invoices ( invoice_no TEXT PRIMARY KEY NOT NULL, date TEXT NOT NULL, customer_name TEXT NOT NULL , gstin TEXT NOT NULL, product TEXT NOT NULL, hsn INTEGER NOT NULL, uom TEXT NOT NULL, quantity INTEGER NOT NULL, rate INTEGER NOT NULL, amount INTEGER NOT NULL, supplier TEXT NOT NULL ); """ execute_query(connection, create_invoices_table)

create_invoices = """ INSERT INTO invoices (invoice_no, date, customer_name, gstin, product, hsn, uom, quantity, rate, amount, supplier) VALUES (?,?),('list') """

What I am trying to do here is retrieving data from the tkinter widget and then uploading it to the database. I would be grateful if you could point out where am going wrong, also if you could tell me if I am using the correct method to retrieve data from the tkinter widget. Thanks Aneesh Mehta

(2) By Larry Brasfield (LarryBrasfield) on 2021-01-18 15:45:12 in reply to 1 [source]

create_invoices = """ INSERT INTO invoices (invoice_no, date, customer_name, gstin, product, hsn, uom, quantity, rate, amount, supplier) VALUES (?,?),('list') """

Ignoring quite a bit of information not relevant to the error shown in your thread title, I say: Your INSERT statement claims that 11 columns are to given values, (by naming them in the first parenthesized list), then provide only a set of 2 values ((?,?)) and set of 1 value (('list')). For that INSERT statement to be semantically valid, the value lists would each need to have 11 members. Because it is not semantically valid, the statement preparation phase rejects that SQL with the error you see.