1:sqlite3程序通过查找分号来决定一个SQL语句的结束。如果你省略分 号,sqlite3将给你一个连续的命令提示符并等你给当前的SQL命令添加更多的文字。
2: python 与sqlite3的连接:
from PyQt5 import QtSql
from PyQt5.QtSql import QSqlQuery
import sqlite3
conn = sqlite3.connect('agv_info.db')
cursor = conn.cursor()
cursor.execute(''' create table name(
time text,
AGV_ID int,
infomation text);''')
start_time=[1.0,2.1,3.4,4.4,5.5,6.6]
ID=[1,2,3,4,5,6]
infomation=['dsadada_use','physical prot (899.60, 1199.80)','physal prot (899.60, 1199.80)','physal prot (899.60, 11.80)','physal prot (9.60, 1199.80)','physal prot (899.60, 1199.80)']
# insert
for i in range(6):
cursor.execute("insert into test5 values('%s', '%s','%s' ) " %(start_time[i] ,ID[i] ,infomation[i]))
#cursor.execute("insert into exception values('%s', '%s','%s' ) " %(i ,i ,i))
# query sql table
sql = "select name from sqlite_master where type='table'"
result=cursor.execute(sql)
all_students = result.fetchall()
for student in all_students:
print(student)
# query test5 data
sql = "select * from test5"
results = cursor.execute(sql)
all_students = results.fetchall()
for student in all_students:
print(student)
conn.commit()
conn.close()
print('DONE!')
参考:
https://jingyan.baidu.com/article/375c8e199a2b2325f2a2293c.html