user1119429
user1119429

Reputation: 685

Insert variable into sqlite data base table

I can't insert data into sqlite table. Here is my code:

import sqlite3
connection = sqlite3.connect('mydata.db')
cursor = connection.cursor()
a=raw_input('name')
a=str(a)
b=raw_input('theme')
b=str(b)
c=raw_input('language')
c=str(c)
sql="INSERT INTO Website (Website, Theme, Language) VALUES (%, %, %)",(a,b,c)
cursor.execute(sql)
connection.commit()
connection.close()

For some reason it doesn't work.

Upvotes: 0

Views: 4717

Answers (1)

jfs
jfs

Reputation: 414129

  • the extended call syntax is f(*args):

    cursor.execute(*sql)
    
  • sqlite uses '?' placeholder:

    conn.execute('insert into sometable values (?,?,?)', (a,b,c))
    
  • raw_input() already returns a string. a = str(a) is unnecessary

Upvotes: 1

Related Questions