def __init__(self,dbConnection): BaseDb.__init__(self) self._entFields={ 'pycad_id':'INTEGER PRIMARY KEY', 'pycad_entity_id':'INTEGER', 'pycad_object_type':'TEXT', 'pycad_object_definition':'TEXT', 'pycad_object_style':'TEXT', 'pycad_security_id':'INTEGER', 'pycad_undo_id':'INTEGER', 'pycad_entity_state':'TEXT', 'pycad_index':'NUMERIC', 'pycad_visible':'INTEGER', 'pycad_undo_visible':'INTEGER', 'pycad_locked':'INTEGER', 'pycad_bbox_xmin':'REAL', 'pycad_bbox_ymin':'REAL', 'pycad_bbox_xmax':'REAL', 'pycad_bbox_ymax':'REAL', 'pycad_property':'TEXT' } def creationFieldsStr(): outStr='' for fieldName,fieldValue in list(self._entFields.items()): outStr+='%s %s,'%(str(fieldName),str(fieldValue)) return outStr[:-1] def addTableField(fieldName,fieldType): sql="ALTER TABLE pycadent ADD COLUMN %s %s "%(str(fieldName),str(fieldType)) self.makeUpdateInsert(sql) if dbConnection is None: self.createConnection() else: self.setConnection(dbConnection) _sqlCheck="""select * from sqlite_master where name like 'pycadent'""" _table=self.makeSelect(_sqlCheck).fetchone() if _table is None: _sqlCreation="""CREATE TABLE pycadent( %s)"""%creationFieldsStr() self.__revisionIndex=0 self.makeUpdateInsert(_sqlCreation) else: rows=self.makeSelect("pragma table_info('pycadent')") dbColumns=dict([(row[1],row[2]) for row in rows]) for classColumn in list(self._entFields.keys()): if not classColumn in dbColumns: addTableField(classColumn,self._entFields[classColumn]) self.__revisionIndex=self.getRevisionIndex()
def __init__(self, dbConnection=None): BaseDb.__init__(self) if dbConnection is None: self.createConnection() else: self.setConnection(dbConnection) _sqlCheck = """select * from sqlite_master where name like 'pycadrel'""" _table = self.makeSelect(_sqlCheck).fetchone() if _table is None: _sqlCreation = """CREATE TABLE pycadrel( "pycad_id" INTEGER PRIMARY KEY, "pycad_parent_id" INTEGER, "pycad_child_id" INTEGER )""" self.makeUpdateInsert(_sqlCreation)
def __init__(self,dbConnection=None): BaseDb.__init__(self) if dbConnection is None: self.createConnection() else: self.setConnection(dbConnection) _sqlCheck="""select * from sqlite_master where name like 'pycadrel'""" _table=self.makeSelect(_sqlCheck).fetchone() if _table is None: _sqlCreation="""CREATE TABLE pycadrel( "pycad_id" INTEGER PRIMARY KEY, "pycad_parent_id" INTEGER, "pycad_child_id" INTEGER )""" self.makeUpdateInsert(_sqlCreation)
def __init__(self,dbConnection): BaseDb.__init__(self) if dbConnection is None: self.createConnection() else: self.setConnection(dbConnection) _sqlCheck="""select * from sqlite_master where name like 'pycadundo'""" _pycadundoTableRow=self.fetchOneRow(_sqlCheck) if _pycadundoTableRow is None: _sqlCreation="""CREATE TABLE "pycadundo" ( "pycad_id" INTEGER PRIMARY KEY, "pycad_incremental_id" INTEGER ) """ self.makeUpdateInsert(_sqlCreation) self.__lastUndo=1 else: self.__lastUndo=self.getMaxUndoIndex() self.__activeUndo=self.getLastUndoIndex()
def __init__(self, dbConnection): BaseDb.__init__(self) if dbConnection is None: self.createConnection() else: self.setConnection(dbConnection) _sqlCheck = """select * from sqlite_master where name like 'pycadundo'""" _pycadundoTableRow = self.fetchOneRow(_sqlCheck) if _pycadundoTableRow is None: _sqlCreation = """CREATE TABLE "pycadundo" ( "pycad_id" INTEGER PRIMARY KEY, "pycad_incremental_id" INTEGER ) """ self.makeUpdateInsert(_sqlCreation) self.__lastUndo = 1 else: self.__lastUndo = self.getMaxUndoIndex() self.__activeUndo = self.getLastUndoIndex()
def __init__(self, dbPath=None): """ init of the kernel """ self.__logger = logging.getLogger('DbKernel') self.__logger.debug('__init__') BaseDb.__init__(self) # set the events self.__logger.debug('set events') self.saveEntityEvent = PyCadEvent() self.deleteEntityEvent = PyCadEvent() self.massiveDeleteEvent = PyCadEvent() self.showEntEvent = PyCadEvent() self.hideEntEvent = PyCadEvent() self.updateShowEntEvent = PyCadEvent() self.undoRedoEvent = PyCadEvent() self.handledErrorEvent = PyCadEvent() #create Connection self.createConnection(dbPath) # inizialize extentionObject self.__UndoDb = UndoDb(self.getConnection()) self.__EntityDb = EntityDb(self.getConnection()) self.__RelationDb = RelationDb(self.getConnection()) # Some inizialization parameter self.__bulkCommit = False self.__bulkUndoIndex = -1 # undo index are always positive so we do not brake in case missing entity id self.__entId = self.__EntityDb.getNewEntId() # set the default style self.__logger.debug('Set Style') self.__activeStyleObj = None self.__activeStyleObj = self.getMainStyle() self.__settings = self.getDbSettingsObject() self.__property = {} #************************ #Inizialize Layer structure #************************ self.__logger.debug('Inizialize layer structure') try: self.__LayerTree = LayerTree(self) except StructuralError: raise StructuralError('Unable to create LayerTree structure') self.__logger.debug('Done inizialization')
def __init__(self,dbPath=None): """ init of the kernel """ self.__logger=logging.getLogger('DbKernel') self.__logger.debug('__init__') BaseDb.__init__(self) # set the events self.__logger.debug('set events') self.saveEntityEvent=PyCadEvent() self.deleteEntityEvent=PyCadEvent() self.massiveDeleteEvent=PyCadEvent() self.showEntEvent=PyCadEvent() self.hideEntEvent=PyCadEvent() self.updateShowEntEvent=PyCadEvent() self.undoRedoEvent=PyCadEvent() self.handledErrorEvent=PyCadEvent() #create Connection self.createConnection(dbPath) # inizialize extentionObject self.__UndoDb=UndoDb(self.getConnection()) self.__EntityDb=EntityDb(self.getConnection()) self.__RelationDb=RelationDb(self.getConnection()) # Some inizialization parameter self.__bulkCommit=False self.__bulkUndoIndex=-1 # undo index are always positive so we do not brake in case missing entity id self.__entId=self.__EntityDb.getNewEntId() # set the default style self.__logger.debug('Set Style') self.__activeStyleObj=None self.__activeStyleObj=self.getMainStyle() self.__settings=self.getDbSettingsObject() self.__property={} #************************ #Inizialize Layer structure #************************ self.__logger.debug('Inizialize layer structure') try: self.__LayerTable = LayerTable(self) except StructuralError: raise StructuralError, 'Unable to create LayerTree structure' self.__logger.debug('Done inizialization')