def _handleNewColumns(self, tableName:str, existingSchema: QSqlRecord,
                             newSchema: QSqlRecord):
        """
        Compares the existing schema with the new schema to work out what
        changes need to be made.
        Note: To modify a table column or insert a new column between existing
        columns (as opposed to just appending at the end), a schema upgrade
        routine will need to be written.
        """
        i = 0
        while i < min(existingSchema.count(), newSchema.count()):
            if existingSchema.field(i) != newSchema.field(i):
                raise UpgradeException("New schema cannot modify field " +
                                       "properties or ordering without a schema" +
                                       " upgrade routine.")
            i += 1

        if newSchema.count() > existingSchema.count():
            while i < newSchema.count():
                self._query.AlterTableAddColumn(tableName, newSchema.field(i))
                i += 1

        elif newSchema.count() < existingSchema.count() and self._dangerousMode:
            while i < existingSchema.count():
                self._query.AlterTableDropColumn(tableName, existingSchema.field(i))
                i += 1
Esempio n. 2
0
 def _setDefaultColumn(self, model, db, record: QtSql.QSqlRecord):
     '''根据一个record对象设置默认ViewColumns'''
     self.__model = model
     for i in range(record.count()):
         fld = record.field(i)
         fn = fld.name()
         vc = ViewColumn(model, fn, fn)
         vc.parent = self
         self._list.append(vc)
         self._setViewColumnAlighAndFormatString(vc)