[英]python sqlite creation of a table syntax error
我正在數據庫中創建一個新表。 在創建其他表之前,我已經完成了此操作,但是這次我遇到語法錯誤。 據我所見,語法是正確的。 因此,我無法弄清楚。
下面是引發錯誤的語句的代碼片段:
cursor.execute('''
CREATE TABLE IF NOT EXISTS order(
orderID INTEGER PRIMARY KEY,
productname STRING,
productprice FLOAT,
productquanitity INTEGER,
producttotal INTEGER;''')
這是錯誤:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1533, in __call__
return self.func(*args)
File "N:/NEW/cashregister.py", line 42, in okitem
producttotal INTEGER;''')
sqlite3.OperationalError: near "order": syntax error
我將對為什么出現這種情況提出一些建議,不勝感激。
order
是SQL中的保留關鍵字; 有關SQLite使用的保留關鍵字的完整列表,請參見文檔 。
使用"order"
使SQLite理解它將被解釋為表名。 您也忘記了結帳)
:
CREATE TABLE IF NOT EXISTS "order" (
orderID INTEGER PRIMARY KEY,
productname STRING,
productprice FLOAT,
productquanitity INTEGER,
producttotal INTEGER
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.