简体   繁体   English

查看Function 以前可以用现在不行了

[英]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.

相关问题 为什么这个功能在用作装饰器时不起作用? - Why does this function not work when used as a decorator? 如果在'for'循环中使用'for'函数,它是如何工作的? - How does the 'for' function work if it is used in a 'for' loop? SELECT date('now')在Python + SQLite中不起作用 - SELECT date('now') does not work in Python + SQLite Tkinter GUI曾经可以工作,但是现在我有一个空窗口 - Tkinter GUI used to work, but now I have a empty window PyInstaller断言错误-过去工作正常,现在不起作用 - PyInstaller Assertion Error - used to work fine, now it doesn't 脚本不再起作用,.group()曾经起作用,但现在抛出错误 - Script not working anymore, .group() used to work but now is throwing an error discord.py 音乐曾经可以工作,但现在我遇到了错误 - discord.py music used to work but now im getting an error Cqlsh现在可以在Ubuntu 16.04上新安装的Cassandra上运行 - Cqlsh does now work on newly installed Cassandra on Ubuntu 16.04 IPython(jupyter)中的完成现在可以工作(意外的关键字参数'column') - Completion in IPython (jupyter) does now work (unexpected keyword argument 'column') 使用 python 安装程序构建的 Exe 文件现在不起作用 - The Exe file that was build with python installer does not work now
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM