Example #1
0
 def getBlobIdCount(self):
     sqlStr = "select count(1) from " + re.split(
         'from', self.blobIdSQLStr, flags=re.I)[1]
     with DBConnection(self.sourceDBConnStr) as dbConnection:
         cursor = dbConnection.openConnection()
         cursor.execute(sqlStr)
         self.blobIdCount = cursor.fetchone()[0]
     return self.blobIdCount
Example #2
0
    def master(self, imgQueue):
        """获取所有图片记录的ROWID及图片名称,放入队列"""

        with DBConnection(self.sourceDBConnStr) as dbConnection:
            cursor = dbConnection.openConnection()
            cursor.execute(self.blobIdSQLStr)
            for res in cursor:
                imgQueue.put(res)
            imgQueue.put(["gameover", 0])
Example #3
0
	def getTargetTableColumn(self, tableName):
		self.targetTable = tableName
		tableColumn = []
		with DBConnection(self.targetDBConnStr) as db:
			cursor = db.openConnection()
			if cursor:
				cursor.execute("select * from " + tableName)
				tableColumn = [i[0] + ' ' + str(i[1]).replace("type 'cx_Oracle.", "")\
				               .replace("'", "") for i in cursor.description]
		return tableColumn
Example #4
0
 def master(self, imgQueue):
     """获取所有图片记录的ROWID及图片名称,放入队列"""
     with DBConnection(self.sourceDBConnStr) as dbConnection:
         cursor = dbConnection.openConnection()
         cursor.execute(self.blobIdSQLStr)
         fileNo = ToolBox.getFileCount(self.filePath, self.logFileName)
         for res in cursor:
             fileNo += 1
             data = res + (fileNo, )
             imgQueue.put(data)
         imgQueue.put(["gameover", 0])
Example #5
0
	def getDBConnStatus(self, dbConnStr, t = 'sourceDB'):
		result = ''
		with DBConnection(dbConnStr) as db:
			result = db.openConnection()
		
		if  t == 'sourceDB':
			self.sourceDBConnStr = dbConnStr
		else:
			self.targetDBConnStr = dbConnStr
			
		return result
Example #6
0
 def slave(self, imgQueue):
     """从队列中取出ROWID,再到图片表获取图片数据并再OS上生成图片文件"""
     self.targetDB = DBWriter(self.targetDBConnStr)
     print(self.targetDB)
     with DBConnection(self.sourceDBConnStr) as dbConnection:
         cursor = dbConnection.openConnection()
         while True:
             imageIdInfo = imgQueue.get()
             imageId = imageIdInfo[0]
             if imageId == "gameover":
                 imgQueue.put(["gameover", 0])
                 break
             sqlStr = self.blobSQLStr % (str(imageId))
             cursor.execute(sqlStr)
             res = cursor.fetchone()
             if res and res[0]:
                 blobNameColumnList = imageIdInfo + res[:]
                 columnValueStr = ToolBox.genColumnValueStr(
                     blobNameColumnList, self.columnPositionList)
                 blobInsertSQLStr = self.blobInsertSQLStr + ' ( ' + columnValueStr + ' )'
                 self.targetDB.run(blobInsertSQLStr, res[0].read())
     self.targetDB.close()
Example #7
0
    def slave(self, imgQueue, recQueue):
        """从队列中取出ROWID,再到图片表获取图片数据并再OS上生成图片文件"""
        with DBConnection(self.sourceDBConnStr) as dbConnection:
            cursor = dbConnection.openConnection()

            while True:
                imageIdInfo = imgQueue.get()
                imageId = imageIdInfo[0]
                fileNo = imageIdInfo[-1]
                if imageId == "gameover":
                    imgQueue.put(["gameover", 0])
                    recQueue.put("gameover")
                    break
                sqlStr = self.blobSQLStr % (str(imageId))
                cursor.execute(sqlStr)
                res = cursor.fetchone()
                if res and res[0]:
                    blobNameColumnList = imageIdInfo[:-1] + res[:]
                    print(imageIdInfo)
                    imageName = ToolBox.genImageName(
                        blobNameColumnList, self.blobNameColumnIndexList,
                        self.blobNameSpliter)

                    fileName = os.path.join(
                        self.filePath, str(fileNo % self.subDirCount + 1),
                        imageName + self.blobNameSpliter + str(fileNo) +
                        '.jpg')

                    try:
                        with open(fileName, 'wb') as f:
                            f.write(res[0].read())
                    except Exception as e:
                        print(e.args)
                        with open(ToolBox.formartImageName(fileName),
                                  'wb') as f:
                            f.write(res[0].read())
                        print("imageId: " + str(imageId) + " has settled")

                recQueue.put(imageId)
Example #8
0
class DBWriter(object):
    def __new__(cls, *args, **kw):
        if not hasattr(cls, '_instance'):
            cls._instance = object.__new__(cls, *args, **kw)
        return cls._instance

    def __init__(self, dbConnStr):
        self.db = DBConnection(dbConnStr)
        self.cursor = self.db.openConnection()
        self.count = 0
        self.commitCount = 1000

    def run(self, insertSQLStr, blob):
        self.count += 1
        self.cursor.setinputsizes(blobData=cx_Oracle.BLOB)
        self.cursor.execute(insertSQLStr, {'blobData': blob})
        if self.count % self.commitCount == 0:
            self.db.connection.commit()

    def close(self):
        self.db.connection.commit()
        self.cursor.close()
        self.db.connection.close()
Example #9
0
class DBWriter(object):
	def __new__(cls, *args, **kw):  
		if not hasattr(cls, '_instance'):  
			cls._instance = object.__new__(cls, *args, **kw)  
		return cls._instance  	
	
	def __init__(self, dbConnStr):
		self.db = DBConnection(dbConnStr)
		self.cursor = self.db.openConnection()
		self.count = 0
		self.commitCount = 1000
	
	def run(self, insertSQLStr, blob):
		self.count += 1
		self.cursor.setinputsizes(blobData=cx_Oracle.BLOB)
		self.cursor.execute(insertSQLStr, {'blobData':blob})
		if self.count % self.commitCount == 0:
			self.db.connection.commit()
			
	def close(self):
		self.db.connection.commit()
		self.cursor.close()
		self.db.connection.close()
Example #10
0
 def __init__(self, dbConnStr):
     self.db = DBConnection(dbConnStr)
     self.cursor = self.db.openConnection()
     self.count = 0
     self.commitCount = 1000
Example #11
0
	def __init__(self, dbConnStr):
		self.db = DBConnection(dbConnStr)
		self.cursor = self.db.openConnection()
		self.count = 0
		self.commitCount = 1000