本文整理匯總了Python中db.DB.queryInsert方法的典型用法代碼示例。如果您正苦於以下問題:Python DB.queryInsert方法的具體用法?Python DB.queryInsert怎麽用?Python DB.queryInsert使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類db.DB
的用法示例。
在下文中一共展示了DB.queryInsert方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: addMissingParts
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import queryInsert [as 別名]
def addMissingParts(self, numbers, groupID):
mdb = DB()
insertStr = 'INSERT INTO partrepair (numberID, groupID) VALUES '
for number in numbers:
insertStr += '(%s, %s), ' % (number, groupID)
insertStr = insertStr[0:-2]
insertStr += ' ON DUPLICATE KEY UPDATE attempts=attampts+1'
return mdb.queryInsert(insertStr, False)
示例2: addBlacklist
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import queryInsert [as 別名]
def addBlacklist(self, regex):
mdb = DB()
groupname = regex['groupname']
if groupname == '':
groupname = 'null'
else:
groupname = re.sub('a\.b\.' 'alt.binaries.', groupname, re.IGNORECASE)
groupname = mdb.escapeString(groupname)
return mdb.queryInsert("insert into binaryblacklist (groupname, regex, status, description, optype, msgcol) values (%s, %s, %d, %s, %d, %d) ",
(regex['regex'], regex['status'], regex['description'], regex['optype'], regex['msgcol']))
示例3: scan
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import queryInsert [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