SQLite3 Python 2.7 SQLite3。OperationalError语法错误

时间:2021-05-01 15:26:44
import sqlite3
import codecs

sqlite3.connect("test.db")
db.execute("""CREATE TABLE IF NOT EXISTS STATIONS
       (StationUID INT PRIMARY KEY     NOT NULL,
       StationNumber           TEXT    NOT NULL,
       StationName             TEXT    NOT NULL,
       StationLongitude        REAL    NOT NULL,
       StationAltitude         REAL    NOT NULL);""")

print "Created Table STATIONS successfully"
cr = db.cursor()
name = "b"
station_number = "0123"
longitude = 13.4
altitude = 34.4
cr.execute("INSERT INTO STATIONS VALUES", (None, station_number, name, longitude, altitude))
db.commit()

It throws sqlite3.OperationalError: near "VALUES": syntax error, but I don't understand why, because it is the same syntax I found in the example.

它把sqlite3。OperationalError: near“VALUES”:语法错误,但我不理解为什么,因为它与我在示例中发现的语法相同。

2 个解决方案

#1


2  

You need to specify what values to insert:

您需要指定要插入的值:

INSERT INTO STATIONS VALUES (value1, value2, ...)

You cannot omit that part. Use SQL parameters to map Python values to those locations in the SQL syntax:

你不能省略那部分。使用SQL参数将Python值映射到SQL语法中的那些位置:

cr.execute(
    "INSERT INTO STATIONS VALUES (?, ?, ?, ?, ?)",
    (None, station_number, name, longitude, altitude))

#2


1  

The INSERT command is not complete. You need to insert the values into the INSERT by writing:

插入命令不完整。您需要通过写入将值插入到insert中:

cr.execute("INSERT INTO STATIONS VALUES (?, ?, ?, ?, ?)", (None, station_number, name, longitude, altitude))

#1


2  

You need to specify what values to insert:

您需要指定要插入的值:

INSERT INTO STATIONS VALUES (value1, value2, ...)

You cannot omit that part. Use SQL parameters to map Python values to those locations in the SQL syntax:

你不能省略那部分。使用SQL参数将Python值映射到SQL语法中的那些位置:

cr.execute(
    "INSERT INTO STATIONS VALUES (?, ?, ?, ?, ?)",
    (None, station_number, name, longitude, altitude))

#2


1  

The INSERT command is not complete. You need to insert the values into the INSERT by writing:

插入命令不完整。您需要通过写入将值插入到insert中:

cr.execute("INSERT INTO STATIONS VALUES (?, ?, ?, ?, ?)", (None, station_number, name, longitude, altitude))