'''
简介
PyQt5中 处理database 例子
'''
import sys
from PyQt5QtCore import
from PyQt5QtGui import
from PyQt5QtWidgets import
from PyQt5QtSql import QSqlDatabase , QSqlQuery
def createDB():
db = QSqlDatabaseaddDatabase('QSQLITE')
dbsetDatabaseName('/db/databasedb')
if name == ' main ':
app = QApplication(sysargv)
createDB()
sysexit(appexec_())
'''
简介
PyQt5中 处理database 例子
'''
import sys
from PyQt5QtCore import
from PyQt5QtGui import
from PyQt5QtWidgets import
from PyQt5QtSql import QSqlDatabase, QSqlTableModel
from PyQt5QtCore import Qt
def initializeModel(model):
modelsetTable('people')
modelsetEditStrategy(QSqlTableModelOnFieldChange)
modelselect()
modelsetHeaderData(0, QtHorizontal, "ID")
modelsetHeaderData(1, QtHorizontal, "name")
modelsetHeaderData(2, QtHorizontal, "address")
def createView(title, model):
view = QTableView()
viewsetModel(model)
viewsetWindowTitle(title)
return view
def addrow():
ret = modelinsertRows(modelrowCount(), 1)
print('insertRows=%s' % str(ret))
def findrow(i):
delrow = irow()
print('del row=%s' % str(delrow))
if name == ' main ':
app = QApplication(sysargv)
db = QSqlDatabaseaddDatabase('QSQLITE')
dbsetDatabaseName('/db/databasedb')
model = QSqlTableModel()
delrow = -1
initializeModel(model)
view1 = createView("Table Model (View 1)", model)
view1clickedconnect(findrow)
select COLUMN_NAME from information_schemaCOLUMNS where table_name = 'your_table_name' and table_schema = 'your_db_name';
这条语句可以查看指定数据库中指定表的所有字段名字,你可以看看查到的字符串在第几个位置上,那么对应起来就是那个字段了
以上就是关于python pyqt5 *** 作sqlite全部的内容,包括:python pyqt5 *** 作sqlite、请教:如果SQL表某一列的记录中包含某个字符串,怎么返回这列的列名、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)