當前位置: 首頁>>代碼示例>>Python>>正文


Python DB.queryOneRow方法代碼示例

本文整理匯總了Python中db.DB.queryOneRow方法的典型用法代碼示例。如果您正苦於以下問題:Python DB.queryOneRow方法的具體用法?Python DB.queryOneRow怎麽用?Python DB.queryOneRow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在db.DB的用法示例。


在下文中一共展示了DB.queryOneRow方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: getCountInactive

# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import queryOneRow [as 別名]
def getCountInactive(gropuname=''):
	mdb = DB()

	grpsql = ''
	if groupname != '':
		grpsql += "and groups.name like %s " % mdb.escapeString("%"+groupname+"%")

	res = mdb.queryOneRow('SELECT count(ID) as num from groups where 1=1 %s and active = 0', (grpsql,))
	return res['num']
開發者ID:rcconvict,項目名稱:usepy,代碼行數:11,代碼來源:groups.py

示例2: safebackfill

# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import queryOneRow [as 別名]
	def safebackfill(self, articles=''):
		mdb = DB()
		n = self.n

		targetdate = '2012-06-04'
		groupname = mdb.queryOneRow('select name from groups where (first_record_date between %s and now()) and (active = 1) order by name asc', (targetdate,))

		if groupname == None:
			print 'No groups to backfill. They are all at the target date %s.' % targetdate
			sys.exit()
		else:
			self.backfillPostAllGroups(groupname['name'], articles)
開發者ID:jonnyboy,項目名稱:usepy,代碼行數:14,代碼來源:backfill.py

示例3: getBlacklistByID

# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import queryOneRow [as 別名]
	def getBlacklistByID(self, id):
		mdb = DB()
		return mdb.queryOneRow('select * from binaryblacklist where ID = %s', (id,))
開發者ID:jonnyboy,項目名稱:usepy,代碼行數:5,代碼來源:binaries.py

示例4: getById

# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import queryOneRow [as 別名]
	def getById(self, id):
		mdb = DB()
		return mdb.queryOneRow('select binaries.*, collections.groupID, groups.name as groupname from binaries, collections left outer join groups on collections.groupID = groups.ID where binaries.ID = %d', (id,))
開發者ID:jonnyboy,項目名稱:usepy,代碼行數:5,代碼來源:binaries.py

示例5: scan

# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import queryOneRow [as 別名]

#.........這裏部分代碼省略.........

			timeCleaning = int(time.time() - self.startCleaning)
			del msg
			maxnum = last
			rangenotreceived = list(set(rangerequested) - set(msgsreceived))

			if stype != 'partrepair':
				print 'Received ', len(msgsreceived), 'articles of', last-first+1, 'requested,', len(msgsblacklisted), 'blacklisted,', len(msgsignored), 'not binary.'					

			if len(rangenotreceived) > 0:
				if stype == 'backfill':
					''' dont add missing articles'''
				else:
					if self.DoPartRepair:
						self.addMissingParts(rangenotreceived, groupArr['ID'])

				if stype != 'partrepair':
					print 'Server did not return %d articles.' % (len(rangenotreceived))

			self.startUpdate = time.time()
			try:
				len(self.message)
			except NameError:
				pass
			else:
				maxnum = first
				# insert binaries and parts into database. When binaries already exists; only insert new parts
				insPartsStmt = "INSERT IGNORE INTO parts (binaryID, number, messageID, partnumber, size) VALUES (%s, %s, %s, %s, %s)"

				lastCollectionHash = ''
				lastCollectionID = -1
				lastBinaryHash = ''
				lastBinaryID = -1

				mdb.setAutoCommit(False)

				for subject, data in self.message.iteritems():
					collectionHash = data['CollectionHash']
					subject = namecleaning.unfuckString(subject)

					if lastCollectionHash == collectionHash:
						collectionID = lastCollectionID
					else:
						lastCollectionHash = collectionHash
						lastBinaryHash = ''
						lastBinaryID = -1

						cres = mdb.queryOneRow("SELECT ID FROM collections WHERE collectionhash = %s", (collectionHash,))
						if cres is None:
							cleanerName = namecleaning.releaseCleaner(subject)
							csql = "INSERT INTO collections (name, subject, fromname, date, xref, groupID, totalFiles, collectionhash, dateadded) VALUES (%s, %s, %s, FROM_UNIXTIME(%s), %s, %s, %s, %s, now())"
							collectionID = mdb.queryInsert(csql, (cleanerName, subject, data['from'], data['Date'], data['xref'], groupArr['ID'], data['MaxFiles'], collectionHash))
						else:
							collectionID = int(cres['ID'])
							cusql = 'UPDATE collections SET dateadded = now() where ID = %s'
							mdb.queryDirect(cusql, (collectionID,))

						lastCollectionID = collectionID
					binaryHash = hashlib.md5(subject+data['from']+str(groupArr['ID'])).hexdigest()

					if lastBinaryHash == binaryHash:
						binaryID = lastBinaryID
					else:
						lastBinaryHash = binaryHash

						bres = mdb.queryOneRow('SELECT ID FROM binaries WHERE binaryhash = %s', (binaryHash,))
						if bres is None:
							bsql = "INSERT INTO binaries (binaryhash, name, collectionID, totalParts, filenumber) VALUES (%s, %s, %s, %s, %s)"
							binaryID = mdb.queryInsert(bsql, (binaryHash, subject, collectionID, data['MaxParts'], round(data['File'])))
						else:
							binaryID = bres['ID']
						lastBinaryID = binaryID

					for partdata in data['Parts'].values():
						pBinaryID = binaryID
						pMessageID = partdata['Message-ID']
						pNumber = partdata['number']
						pPartNumber = round(partdata['part'])
						pSize = partdata['size']
						maxnum = partdata['number'] if (partdata['number'] > maxnum) else maxnum
						params = (pBinaryID, pNumber, pMessageID, pPartNumber, pSize)
						
						try:
							mdb.query(insPartsStmt, params)
						except MySQLdb.Error, e:
							msgsnotinserted.append(partdata['number'])

				if len(msgsnotinserted) > 0:
					print 'WARNING: %d parts failed to insert.' % len(msgsnotinserted)
					if self.DoPartRepair:
						self.addMissingParts(msgsnotinserted, groupArr['ID'])
				mdb.commit()
				mdb.setAutoCommit(True)
			timeUpdate = int(time.time() - self.startUpdate)
			timeLoop = int(time.time() - self.startLoop)

			if stype != 'partrepair':
				print '%ds to download articles, %ds to clean articles, %d to insert articles, %ds total.\n\n' % (timeHeaders, timeCleaning, timeUpdate, timeLoop)
			data, self.message = None, {}
			return maxnum
開發者ID:jonnyboy,項目名稱:usepy,代碼行數:104,代碼來源:binaries.py

示例6: getByID

# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import queryOneRow [as 別名]
def getByID(id):
	mdb = DB()
	return mdb.queryOneRow('SELECT * FROM groups WHERE ID = %s', (id,))
開發者ID:rcconvict,項目名稱:usepy,代碼行數:5,代碼來源:groups.py

示例7: disableForPost

# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import queryOneRow [as 別名]
def disableForPost(name):
	mdb = DB()
	mdb.queryOneRow("update groups set first_record_postdate = %s where name = %s", ('2000-00-00 00:00:00', mdb.escapeString(name)))
開發者ID:rcconvict,項目名稱:usepy,代碼行數:5,代碼來源:groups.py

示例8: getIDByName

# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import queryOneRow [as 別名]
def getIDByName(name):
	mdb = DB()
	res = mdb.queryOneRow('SELECT * FROM groups WHERE name = %s', (name,))
	return res['ID']
開發者ID:rcconvict,項目名稱:usepy,代碼行數:6,代碼來源:groups.py

示例9: getNameByID

# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import queryOneRow [as 別名]
def getNameByID(id):
	mdb = DB()
	res = mdb.queryOneRow('SELECT * FROM groups WHERE ID = %d', (id,))
	return res['name']
開發者ID:rcconvict,項目名稱:usepy,代碼行數:6,代碼來源:groups.py

示例10: getByName

# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import queryOneRow [as 別名]
def getByName(grp):
	mdb = DB()
	return mdb.queryOneRow('SELECT * FROM groups WHERE name = %s', (grp,))
開發者ID:rcconvict,項目名稱:usepy,代碼行數:5,代碼來源:groups.py


注:本文中的db.DB.queryOneRow方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。