0

I am trying to add two values in a table by calling functions of a file. The file has following code:

import sqlite3
con = sqlite3.Connection('rdb')
cur = con.cursor()
def insert(s):
    cur.execute("create table if not exists customerorder(no number primary 
    key,menuitems varchar(40))")
    c=1
    for i in s:
        print c
        print i
        cur.execute("insert into customerorder(?,?)",(int(c),i))
        c += 1 

def fetch():
    cur.execute("select * from customerorder")
    print cur.fetchall()

Here 's' is a list. Having s[0]='simple book' and s[1] = 'advance book'.

1 Answer 1

1
insert into customerorder(?,?)

You need to change this to something like

insert into customerorder values(?,?)

The first list in parens after a table name is a list of columns, and you cannot have ? variables for column names.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.