triunenature
triunenature

Reputation: 671

Python SQLITE insert into not working

So I am trying to get a simple program to insert information into a sqlite db.

The line that is breaking is the cur.execute

sitename = "TEST sitename2"
siteusername = "TEST siteusername2"
sitepasswd = "TEST sitepassword2"
cur.execute("INSERT INTO mytable(sitename, siteusername, sitepasswd) VALUES(%s, %s, %s)", (sitename, siteusername, sitepasswd))

Error that I receive from Python:
sqlite3.OperationalError: near "%": syntax error

Upvotes: 1

Views: 1682

Answers (1)

mechanical_meat
mechanical_meat

Reputation: 169524

You simply have the wrong parameter style.

>>> import sqlite3
>>> sqlite3.paramstyle
'qmark'

Change your code to:

cur.execute("""INSERT INTO mytable(sitename, siteusername, sitepasswd) 
               VALUES (?, ?, ?)""", (sitename, siteusername, sitepasswd))

Upvotes: 1

Related Questions