Beispiel #1
0
 def createDstTable(self):
     fields = self.convertHash(sql_helpers.selectHashIterator(self.sq_connection.execute("select * from {0}".format(self.src))).next())
     for key in fields:
         fields[key] = "varchar"
     fields["ref_id"] = "integer"
         
     sql_helpers.makeTableIfNotExists(self.sq_connection, self.dst, fields, ["foreign key (ref_id) references {0}(id) on delete cascade".format(self.src), "unique(ref_id)"])
Beispiel #2
0
 def next(self):
     ret = self.xmlmk_class()
     ret._local_init(self.transformer)
     iterator = sql_helpers.selectHashIterator(self.cursor).__iter__()
     got = 0
     while True:
            record = iterator.next()
            ret.insertRecord(record)
            got += 1
            if got >= self.max_count:
                break
     return ret
Beispiel #3
0
 def convertTable(self):
     self._checkForNecessaryFields()
     if sql_helpers.isTableAre(self.sq_connection, self.dst):
         dst_id = sql_helpers.getIdForTable(self.sq_connection, self.dst)
     else:
         dst_id = 1
         self.createDstTable()
         
     try:
         for rec in sql_helpers.selectHashIterator(self.sq_connection.execute("select * from {0}".format(self.src))):
             try:
                 sql_helpers.insertInto(self.sq_connection, self.dst, self._processAndAddIDReferences(dst_id, rec))
             except:
                 self.sq_connection.execute("delete from {0} where ref_id = ?".format(self.dst), (rec["id"],))
                 sql_helpers.insertInto(self.sq_connection, self.dst, self._processAndAddIDReferences(dst_id, rec))
                 
             dst_id += 1
     except:
         self.sq_connection.rollback()
         raise
     else:
         self.sq_connection.commit()
Beispiel #4
0
 def fetchTable(self):
     if not sql_helpers.isTableAre(self.sq_connection, self.table):
         raise Exception("{0}.{1}: table {2} does not exists in the database".format(self.__class__.__name__, __name__, self.table))
     self.tag = self.table
     for rec in sql_helpers.selectHashIterator(self.sq_connection.execute('select * from {0}'.format(self.table))):
         self.insertRecord(rec)