def metadataRelation(self, relation): if not relation: return False fT = "" fF = "" rC = FLRelationMetaData.RELATION_M1 dC = False uC = False cI = True no = relation.firstChild() while not no.isNull(): e = no.toElement() if not e.isNull(): if e.tagName() == "table": fT = e.text() no = no.nextSibling() continue if e.tagName() == "field": fF = e.text() no = no.nextSibling() continue if e.tagName() == "card": if e.text() == "1M": rC = FLRelationMetaData.RELATION_1M no = no.nextSibling() continue if e.tagName() == "delC": dC = (e.text() == "true") no = no.nextSibling() continue if e.tagName() == "updC": uC = (e.text() == "true") no = no.nextSibling() continue if e.tagName() == "checkIn": cI = (e.text() == "true") no = no.nextSibling() continue no = no.nextSibling() return FLRelationMetaData(fT, fF, rC, dC, uC, cI)
def metadataRelation(self, relation): """ Crea un objeto FLRelationMetaData a partir de un elemento XML. Dado un elemento XML, que contiene la descripción de una relación entre tablas, construye y devuelve el objeto FLRelationMetaData correspondiente, que contiene dicha definición de la relación. NO SE HACEN CHEQUEOS DE ERRORES SINTÁCTICOS EN EL XML. @param relation Elemento XML con la descripción de la relación @return Objeto FLRelationMetaData que contiene la descripción de la relación """ if not relation: return False fT = "" fF = "" rC = FLRelationMetaData.RELATION_M1 dC = False uC = False cI = True no = relation.firstChild() while not no.isNull(): e = no.toElement() if not e.isNull(): if e.tagName() == "table": fT = e.text() no = no.nextSibling() continue if e.tagName() == "field": fF = e.text() no = no.nextSibling() continue if e.tagName() == "card": if e.text() == "1M": rC = FLRelationMetaData.RELATION_1M no = no.nextSibling() continue if e.tagName() == "delC": dC = (e.text() == "true") no = no.nextSibling() continue if e.tagName() == "updC": uC = (e.text() == "true") no = no.nextSibling() continue if e.tagName() == "checkIn": cI = (e.text() == "true") no = no.nextSibling() continue no = no.nextSibling() return FLRelationMetaData(fT, fF, rC, dC, uC, cI)
def getTableObj(tree, root): table = SchemaTableStruct() table.xmltree = tree table.xmlroot = root query_name = one(table.xmlroot.xpath("query/text()"), None) name = table.xmlroot.xpath("name/text()")[0] table.tablename = name if query_name: table.name = query_name table.query_table = name else: table.name = name table.query_table = None table.fields = [] table.pk = [] table.fields_idx = {} for xmlfield in table.xmlroot.xpath("field"): try: field = SchemaFieldStruct() field.name = None field.alias = None field.allowNull = False field.pk = False field.mtd_type = None field.length_ = 0 field.calculated = False field.visible = True field.editable = True field.pI = 4 field.pD = 0 field.iNX = False field.uNI = False field.coun = False field.defValue = None field.oT = False field.rX = None field.vG = True field.gene = False field.iCK = False fks = {} for fieldprop in xmlfield: if fieldprop.text: fks[fieldprop.tag] = fieldprop.text #else: fks[fieldprop.tag] = fieldprop #print("Field Prop: %r:%r" % (fieldprop.tag,fieldprop.text)) field.name = fks.get("name") field.alias = fks.get("alias") build_field_type(field, xmlfield, fks) field.length_ = fks.get("length", 0) field.allowNull = text2bool(fks.get("null", "true")) field.pk = text2bool(fks.get("pk", "false")) field.editable = text2bool(fks.get("editable", "true")) field.visible = text2bool(fks.get("visible", "true")) field.iCK = text2bool(fks.get("ck", "false")) field.defValue = fks.get("default") field.optionsList = fks.get("optionslist") field.vG = text2bool(fks.get("visiblegrid", "true")) field.rX = "" field.pI = fks.get("partI", 4) field.pD = fks.get("partD", 0) field.calculated = text2bool(fks.get("counter", "false")) # TODO: la lectura insistente con xpath parece ralentizar el parseo de las MTD if field.pk: table.pk.append(field.name) if field.name in table.fields_idx: raise ValueError("La tabla %s tiene el campo %s repetido" % (table.name, field.name)) field.number = len(table.fields) table.fields_idx[field.name] = field.number fieldMD = FLFieldMetaData(field.name, field.alias, field.allowNull, field.pk, field.mtd_type, field.length_, field.calculated, field.visible, field.editable, field.pI, field.pD, field.iNX, field.uNI, field.coun, field.defValue, field.oT, field.rX, field.vG, field.gene, field.iCK) relations = xmlfield.xpath("relation") for xmlRelation in relations: rks = {} for rel in xmlRelation: if rel.text: rks[rel.tag] = rel.text tableNameR = rks.get("table") fieldRelation = rks.get("field") cardR = rks.get("card") delC = text2bool(rks.get("delC", "false")) updC = text2bool(rks.get("updC", "false")) checkIn = rks.get("checkIn") relation = FLRelationMetaData(tableNameR, fieldRelation, cardR, delC, updC, checkIn) fieldMD.addRelationMD(relation) associateds = xmlfield.xpath("associated") for xmlAssoc in associateds: aks = {} for assoc in xmlAssoc: if assoc.text: aks[assoc.tag] = assoc.text aWith = aks.get("with") aBy = aks.get("by") fieldMD.setAssociatedField(aWith, aBy) if field.optionsList: fieldMD.setOptionsList(field.optionsList) table.fields.append(fieldMD) #table.fields.append(fieldMD) #fieldMD.addRelationMD(relation) #print(relationTableNameList_) """ fieldMD = FLFieldMetaData(field.name, field.alias, field.allowNull, field.pk, field.mtd_type, field.length_, field.calculated, field.visible, field.editable, field.pI, field.pD, field.iNX, field.uNI, field.coun, field.defValue, field.oT, field.rX, field.vG, field.gene, field.iCK) i = 0 l = len(relationTableNameList_) l1 = len(relationFieldRelationList_) l2 = len(relationCardList_) while i < l: print("%s.%s->%s de %s ojo (%s,%s) " % (table.name, field.name, i, l, l1, l2)) #print("%s.%s --(%s)--> %s.%s" % (table.name, field.name, relationCardList_[i],relationTableNameList_[i], relationFieldRelationList_[i])) if relationDelCList_[i] == "false": delC = False else: delC = True if relationupdCList_[i] == "false": updC = False else: updC = True if relationCIList_[i] == "false": cI = False else: cI = True relation = FLRelationMetaData(relationTableNameList_[i],relationFieldRelationList_[i], relationCardList_[i], delC, updC ,cI) fieldMD.addRelationMD(relation) i = i + 1 table.fields.append(fieldMD) """ except Exception as e: print("ERROR: procesando tabla %r:" % table.name, e) print(traceback.format_exc()) return table
def initCursor(self): # si no existe crea la tabla if not self._cursor: return False if not self._cursor._model: return False self._tMD = 0 if not self._sortField: self._tMD = self._cursor._model.name() if self._tMD: self.sortField_ = self._tMD.value(self._cursor._currentregister, self._tMD.primaryKey()) ownTMD = False if not self._tableName: #if not cursor_->db()->manager()->existsTable(tableName_)) { ownTMD = True #tMD = cursor_->db()->manager()->createTable(tableName_); else: ownTMD = True self._tMD = self._cursor._model._table.name if not self._tMD: return if not self._foreignField or not self._fieldRelation: if not self._cursor._model: if ownTMD and self._tMD and not self._tMD.inCache(): self._tMD = None return if not self._cursor._model.name() == self._tableName: ctxt = self._cursor.context() self._cursor = FLSqlCursor(self._tableName) if self._cursor: self._cursor.setContext(ctxt) cursorAux = 0 if ownTMD and self._tMD and not self._tMD.inCache(): self._tMD = None return else: cursorTopWidget = self.topWidget._cursor( ) # ::qt_cast<FLFormDB *>(topWidget)->cursor() if cursorTopWidget and not cursorTopWidget._model.name( ) == self._tableName: self._cursor = cursorTopWidget if not self._tableName or not self._foreignField or not self._fieldRelation or cursorAux: if ownTMD and self._tMD and not self._tMD.inCache(): tMD = None return cursorAux = self._cursor curName = self._cursor._model.name() rMD = self._cursor._model.relation(self._foreignField, self._fieldRelation, self._tableName) testM1 = self._tMD.relation(self._fieldRelation, self._foreignField, curName) checkIntegrity = bool(False) if not rMD: if testM1: checkIntegrity = ( testM1.cardinality() == FLRelationMetaData.RELATION_M1) fMD = FLTableMetaData(self._cursor._model.field( self._foreignField)) if (fMD): tmdAux = self._cursor._model(self._tableName) if not tmdAux or tmdAux.isQuery(): checkIntegrity = False if tmdAux and not tmdAux.inCache(): # mirar inCache() tmdAux = None rMD = FLRelationMetaData(self._tableName, self._fieldRelation, FLRelationMetaData.RELATION_1M, False, False, checkIntegrity) fMD.addRelationMD(rMD) print( "FLTableDB : La relación entre la tabla del formulario %r y esta tabla %r de este campo no existe, pero sin embargo se han indicado los campos de relación( %r, %r )" % (curName, self._tableName, self._fieldRelation, self._foreignField)) print( "FLTableDB : Creando automáticamente %r.%r --1M--> %r.%r" % (curName, self._foreignField, self._tableName, self._fieldRelation)) else: print( "FLTableDB : El campo ( %r ) indicado en la propiedad foreignField no se encuentra en la tabla ( %r )" % (self._foreignField, curName)) rMD = testM1 if not rMD: fMD = FLFieldMetaData(tMD.field(self._fieldRelation)) if (fMD): rMD = FLRelationMetaData(curName, self._foreignField, FLRelationMetaData.RELATION_1M, False, False, False) fMD.addRelationMD(rMD) print( "FLTableDB : Creando automáticamente %r.%r --1M--> %r.%r" % (self._tableName, self._fieldRelation, curName, self._foreignField)) else: print( "FLTableDB : El campo ( %r ) indicado en la propiedad fieldRelation no se encuentra en la tabla ( %r )" % (self._fieldRelation, self._tableName)) self._cursor = FLSqlCursor(self._tableName, True, self._cursor.db().connectionName(), cursorAux, rMD, self) if not self._cursor: self._cursor = cursorAux cursorAux = 0 else: self._cursor.setContext(cursorAux.context()) if self.showed: self.disconnect(cursorAux, QtCore.SIGNAL('newBuffer()'), self.refresh()) self.connect(cursorAux, QtCore.SIGNAL('newBuffer()'), self.refresh()) if cursorAux and self.topWidget.isA("FLFormSearchDB"): self.topWidget.setCaption(self._cursor._model.alias()) self.topWidget.setCursor( self._cursor ) #::qt_cast<FLFormSearchDB *>(topWidget)->setCursor(cursor_); if ownTMD and tMD and not tMD.inCache(): tMD = None
def initCursor(self): if not self.topWidget or not self.cursor_: return if not self.cursor_.metadata(): return tMD = self.cursor_.metadata() if not self.sortField_: if tMD: self.sortField_ = tMD.field(tMD.primaryKey()) ownTMD = None if self.tableName_: if DEBUG: print("**FLTableDB::name: %r tableName: %r" % (self.objectName(), self.tableName_)) if not self.cursor_.db().manager().existsTable(self.tableName_): ownTMD = True tMD = self.cursor_.db().manager().createTable(self.tableName_) else: ownTMD = True tMD = self.cursor_.db().manager().metadata(self.tableName_) if not tMD or isinstance(tMD,bool): return if not self.foreignField_ or not self.fieldRelation_: if not self.cursor_.metadata(): if ownTMD and tMD and not tMD.inCache(): del tMD return if not self.cursor_.metadata().name() == self.tableName_: ctxt = self.cursor_.context() self.cursor_ = FLSqlCursor(self.tableName_, True, self.cursor_.db().connectionName(), None, None , self) if self.cursor_: self.cursor_.setContext(ctxt) self.cursorAux = None if ownTMD and tMD and not tMD.inCache(): del tMD return else: cursorTopWidget = self.topWidget.cursor() if cursorTopWidget and not cursorTopWidget.metadata().name() == self.tableName_: self.cursor_ = cursorTopWidget if not self.tableName_ or not self.foreignField_ or not self.fieldRelation_ or self.cursorAux: if ownTMD and tMD and not tMD.inCache(): del tMD return self.cursorAux = self.cursor_ curName = self.cursor_.metadata().name() rMD = self.cursor_.metadata().relation(self.foreignField_, self.fieldRelation_, self.tableName_) testM1 = tMD.relation(self.fieldRelation_, self.foreignField_, curName) checkIntegrity = False if not rMD: if testM1: if testM1.cardinality() == FLRelationMetaData.RELATION_M1: checkIntegrity = True fMD = self.cursor_.metadata().field(self.foreignField_) if fMD: tmdAux = self.cursor_.db().manager().metadata(self.tableName_) if not tmdAux or tmdAux.isQuery(): checkIntegrity = False if tmdAux and not tmdAux.inCache(): del tmdAux rMD = FLRelationMetaData(self.tableName_, self.fieldRelation_, FLRelationMetaData.RELATION_1M, False, False, checkIntegrity) fMD.addRelationMD(rMD) #print("FLTableDB : La relación entre la tabla del formulario %s y esta tabla %s de este campo no existe, pero sin embargo se han indicado los campos de relación( %s, %s )" % ( curName, self.tableName_, self.fieldRelation_, self.foreignField_)) #print("FLTableDB : Creando automáticamente %s.%s --1M--> %s.%s" % (curName, self.foreignField_, self.tableName_, self.fieldRelation_)) else: #print("FLTableDB : El campo ( %s ) indicado en la propiedad foreignField no se encuentra en la tabla ( %s )" % (self.foreignField_, curName)) pass rMD = testM1 if not rMD: fMD = tMD.field(self.fieldRelation_) if fMD: rMD = FLRelationMetaData(curName, self.foreignField_, FLRelationMetaData.RELATION_1M, False, False, False) fMD.addRelationMD(rMD) if DEBUG: print("FLTableDB : Creando automáticamente %s.%s --1M--> %s.%s" % (self.tableName_, self.fieldRelation_, curName, self.foreignField_)) else: if DEBUG: print("FLTableDB : El campo ( %s ) indicado en la propiedad fieldRelation no se encuentra en la tabla ( %s )" % (self.fieldRelation_, self.tableName_)) self.cursor_ = FLSqlCursor(self.tableName_, True, self.cursor_.db().connectionName(), self.cursorAux, rMD, self) if not self.cursor_: self.cursor_ = self.cursorAux self.cursorAux = None else: self.cursor_.setContext(self.cursorAux.context()) if self.showed: try: self.cursorAux.newBuffer.disconnect(self.refresh) except: pass self.cursorAux.newBuffer.connect(self.refresh) if self.cursorAux and isinstance(self.topWidget, FLFormSearchDB): self.topWidget.setCaption(self.cursor_.metadata().alias()) self.topWidget_.setCursor(self.cursor_) if ownTMD or tMD and not tMD.inCache(): del tMD