[英]View Function used to work now it does not
import sqlite3
def create_table():
connection = sqlite3.connect('lite.db')
cursor = connection.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS shop (item TEXT, quantity INTEGER, price REAL)') #you write the SQL code in between brackets
connection.commit()
connection.close()
create_table()
def insert(item,quantity,price):
connection = sqlite3.connect('lite.db')
cursor = connection.cursor()
cursor.execute("INSERT INTO shop VALUES (?,?,?)", (item,quantity,price)) # inserting data
connection.commit()
connection.close()
insert('Wine Glass', 10, 5)
insert('Coffe Cup', 5, 2)
insert('Plate', 20, 10)
def view():
connection = sqlite3.connect('lite.db')
cursor = connection.cursor()
cursor.execute('SELECT ALL FROM shop ')
rows = cursor.fetchall()
connection.close()
return rows
def delete_item(item):
connection = sqlite3.connect('lite.db')
cursor = connection.cursor()
cursor.execute("DELETE * FROM shop WHERE item = ?", (item,)) # inserting data
connection.commit()
connection.close()
print(view())
delete_item('Wine Glass')
print(view())
Error Message:错误信息:
cursor.execute('SELECT ALL FROM shop ')
sqlite3.OperationalError: near "FROM": syntax error
It used to work and then I added the delete function and now it gives me this syntax error, I didn't even make any changes on that function. The code is based on a Udemy tutorial, and with the same changes applied on the video I got this error message but the tutor did not.它曾经有效,然后我添加了删除 function,现在它给了我这个语法错误,我什至没有对该 function 进行任何更改。该代码基于 Udemy 教程,并且对视频应用了相同的更改我收到此错误消息,但导师没有。 As you can guess I am pretty new to this stuff and I cant decipher the error message, or at least if it means any more than the obvious.
正如您所猜到的,我对这些东西很陌生,我无法破译错误消息,或者至少如果它的含义不那么明显的话。 So yeah thanks in advance
所以是的,提前谢谢
SELECT ALL
should be SELECT ALL *
or just SELECT *
to select all columns in all rows. SELECT ALL
应该是SELECT ALL *
或者只是SELECT *
到 select 所有行中的所有列。 See the syntax here .请参阅此处的语法。
DELETE * FROM shop
should be DELETE FROM shop
. DELETE * FROM shop
应该是DELETE FROM shop
。 DELETE
deletes whole rows, it doesn't need a list of columns. DELETE
删除整行,不需要列列表。 See the syntax here .请参阅此处的语法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.