当前位置: 首页>>代码示例>>Python>>正文


Python DatabaseHandler.processQueries方法代码示例

本文整理汇总了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
开发者ID:mower,项目名称:mower-apps,代码行数:12,代码来源:doubleAssassination.py

示例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)
#.........这里部分代码省略.........
开发者ID:mower,项目名称:mower-apps,代码行数:103,代码来源:doubleAssassination.py


注:本文中的DatabaseHandler.DatabaseHandler.processQueries方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。