本文整理汇总了Python中DatabaseHandler.DatabaseHandler.processQueries方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseHandler.processQueries方法的具体用法?Python DatabaseHandler.processQueries怎么用?Python DatabaseHandler.processQueries使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseHandler.DatabaseHandler
的用法示例。
在下文中一共展示了DatabaseHandler.processQueries方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initDb
# 需要导入模块: from DatabaseHandler import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler.DatabaseHandler import processQueries [as 别名]
def initDb(pathDb):
db = DatabaseHandler(u'qt_sql_default_connection', pathDb)
queries = [
('CREATE TABLE folders (name TEXT PRIMARY KEY, os TEXT, computerName TEXT)', None),
('CREATE TABLE files (hash TEXT, absPath TEXT, name TEXT, path TEXT, size NUM, searchTag NUM)', None),
('CREATE TABLE tags (searchTag NUM UNIQUE, timestamp NUM, computerName TEXT)', None),
('CREATE TABLE lastSearch (searchTag UNIQUE, lastPercent NUM, lastPath TEXT)', None)
]
db.processQueries(queries)
return
示例2: DAThread
# 需要导入模块: from DatabaseHandler import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler.DatabaseHandler import processQueries [as 别名]
class DAThread(QtCore.QObject):
onFolderUpdate = QtCore.pyqtSignal()
onDoubleUpdate = QtCore.pyqtSignal()
onProgressChange = QtCore.pyqtSignal(float)
def __init__(self, dbPath):
QtCore.QObject.__init__(self)
self.db = DatabaseHandler('DAThread', dbPath)
self.merger = Merger()
self.sha = QtCore.QCryptographicHash(QtCore.QCryptographicHash.Sha1)
return
def __del__(self):
return
@QtCore.pyqtSlot()
def closeEvent(self):
self.db = None
self.thread().exit()
return
@QtCore.pyqtSlot(QtCore.QString)
def onFolderAdded(self, path):
queries = [
('INSERT INTO folders (name, os, computerName) VALUES (:name, :os, :computerName)', {
':name': path,
':os': platform.system(),
':computerName': platform.node()
}
)
]
self.db.processQueries(queries)
self.onFolderUpdate.emit()
return
def sha1(self, path):
s = QtCore.QFile(path)
s.open(QtCore.QIODevice.ReadOnly)
self.sha.addData(s.readAll())
s.close()
res = self.sha.result().toHex()
self.sha.reset()
return res
def processFile(self, t):
absPath, path, fileName, size = t
query = 'INSERT INTO files (hash, absPath, name, path, size, searchTag) VALUES (:hash, :absPath, :name, :path, :size, :searchTag)'
dic = { ':hash': self.sha1(absPath), ':absPath': absPath, ':name': fileName, ':path': path, ':size': QtCore.QString(unicode(size)), ':searchTag': self.currentTag }
self.queries.append((query, dic))
return
def progressFun(self, percent):
if percent == 0:
return
elif percent != -1:
self.progress += percent
self.onProgressChange.emit(self.progress)
else:
self.onProgressChange.emit(-1)
return
def createSession(self):
timestamp = QtCore.QString(unicode(int(time.time())))
computerName = QtCore.QString(platform.node())
h = QtCore.QCryptographicHash(QtCore.QCryptographicHash.Sha1)
h.addData(computerName)
h.addData(timestamp)
currentTag = h.result().toHex()
query = 'INSERT INTO tags (searchTag, timestamp, computerName) VALUES (:searchTag, :timestamp, :computerName)'
dic = { ':searchTag': currentTag, ':timestamp': timestamp, ':computerName': computerName }
self.db.processQueries([(query, dic)])
self.queries = []
self.progress = 0.0
self.currentTag = currentTag
return
def saveProgress(self, d):
queries = self.queries
self.queries = []
query = 'REPLACE INTO lastSearch (searchTag, lastPercent, lastPath) VALUES (:searchTag, :lastPercent, :lastPath)'
dic = { ':searchTag': self.currentTag, ':lastPercent': self.progress, ':lastPath': d }
queries.append((query, dic))
self.db.processQueries(queries)
self.onDoubleUpdate.emit()
return
@QtCore.pyqtSlot(list, float)
def onSearchAsked(self, cl, percent):
self.createSession()
for d in cl:
walk(d, self.processFile, percent, self.progressFun)
self.saveProgress(d)
self.onDoubleUpdate.emit()
self.onProgressChange.emit(-1)
self.onDoubleUpdate.emit()
return
@QtCore.pyqtSlot(QtCore.QString)
#.........这里部分代码省略.........