Home > database >  sqlite3.DatabaseError: malformed database schema (?)
sqlite3.DatabaseError: malformed database schema (?)

Time:01-29

I executed the python file in the first try & it worked. But when I included the code "IF NOT EXISTS" in the line cur.execute("CREATE TABLE IF NOT EXISTS store (item TEXT, quantity INTEGER, price REAL)")& cur.execute("INSERT INTO store VALUES ('Wine Glass,8,10.5')") I am getting an error.

here is my code:

import sqlite3

conn=sqlite3.connect("lite.db")
cur=conn.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS store (item TEXT, quantity INTEGER, price REAL)")
cur.execute("INSERT INTO store VALUES ('Wine Glass,8,10.5')")
conn.commit()
conn.close()

here is the error:

PS D:\mysite\Interacting with Databases> python 1.py
Traceback (most recent call last):
  File "D:\mysite\Interacting with Databases\1.py", line 5, in <module>
    cur.execute("CREATE TABLE IF NOT EXISTS store (item TEXT, quantity INTEGER, price REAL)")
sqlite3.DatabaseError: malformed database schema (?)

CodePudding user response:

You have an error in the code:

cur.execute("INSERT INTO store VALUES ('Wine Glass,8,10.5')")

you are prividing only single value to three-column table. Replace it with

cur.execute("INSERT INTO store VALUES ('Wine Glass','8','10.5')")

and your code should work fine.

  •  Tags:  
  • Related