用pyqt5内的QtSql功能新建数据库(目前使用中会出现闪退异常,原因未知)
from PyQt5.QtSql import QSqlDatabase, QSqlQuery
db = QSqlDatabase.addDatabase('QSQLITE')
db.setDatabaseName('/DataSave.db')
db.open()
self.query = QSqlQuery()
#创建log表格
self.query.exec_("create table log(time varchar(1), topic varchar(100), projectname varchar(100)"
", projectver varchar(100), mdeviceid varchar(100), subdeviceid varchar(100)"
",cmdordata varchar(100),codemode varchar(100),payload varchar(500)"
",msgtype varchar(100),devicetype varchar(100),deviceid varchar(100),serviceid varchar(100))")
#写入数据
self.query.exec_(
"insert into log (time,topic,projectname,projectver,mdeviceid,subdeviceid,cmdordata,codemode,payload,msgtype,devicetype,deviceid,serviceid)values('%s', '%s','%s','%s','%s',&