def _commandAnnotationEntity(self): if not tools.dataNotNull(self._actualLine): return False marqueur = "@ORM/" clfM = len(marqueur) + 2 if self.isLineContain("@ORM/", True): val = preFormatLineAnnotation(self._actualLine)[clfM:] lbca = len(baseCommandeAnnotation[1]) com = val[0:lbca] if com == baseCommandeAnnotation[1]: self._fieldEncours = FieldTable() stName = lbca + 1 self._fieldEncours.name = val[stName:] self._nameMysqlFieldEncours = val[stName:] return True lbca = len(baseCommandeAnnotation[2]) com = val[0:lbca] if com == baseCommandeAnnotation[2]: self._commandeColumn(val) return True lbca = len(baseCommandeAnnotation[3]) com = val[0:lbca] if com == baseCommandeAnnotation[3]: self._fieldEncours.extra = 'auto_increment' return True else: return False
def convertMysqlToEntityFile(self, tableToPut: Table): if tableToPut is not None: self._table = tableToPut if self._table is None: return False st = 'import datetime\nfrom database import Entity\n\n\n' nameEntity = convertNameToObjName( self._table.name).capitalize() + "Entity" st += shortComment + appelFonction + baseCommandeAnnotation[ 0] + "=" + self._table.name + "\n" st += "class " + nameEntity + "(Entity):\n" st += self._addAttributeFromTableFied() st += self._addSetterGetter() st = st[:-1] if tools.dataNotNull(self._filePath): filename = self._filePath + nameEntity + '.py' fileW = open(filename, 'w') fileW.write(st) fileW.close() filePacketEntityPath = self._filePath + "__init__.py" with open(filePacketEntityPath, "a") as fileAd: st = "from database.entity." + nameEntity + " import " + nameEntity + "\n" fileAd.write(st) fileAd.close() return st
def saveFileNonPresent(fieldsNonPresent: [FieldAbsent], raz: bool = False): brand = 'other' if tools.dataNotNull(fieldsNonPresent): brand = fieldsNonPresent[0].brand datasTopPut = [] existingDatas = loadFileNonPresent() if not raz: if tools.dataNotNull(existingDatas[brand]): datasTopPut.extend(existingDatas[brand]) for fa in fieldsNonPresent: objField = {"fieldName": fa.fieldName, 'exemple': []} if tools.dataNotNull(fa.exemple): for e in fa.exemple: objField['exemple'].append(e.values) datasTopPut.append(objField) existingDatas[brand] = datasTopPut with open(_fileAbsName, 'w') as outfile: json.dump(existingDatas, outfile)
def _prepareRequest(self): request = "" if self._request != "": self._request += "\n" primKey = self._entity.getPrimaryKey() primKeyValue = self._entity.__getattribute__(primKey) if not tools.dataNotNull(primKeyValue): if self._prevEntityClass != self._entity.getName(): self._request += "INSERT INTO " + self._table.name + " (" for a in range(len(self._entity.getAttributes())): attT = self._table.fieldsName[a] self._request += attT + "," self._request = self._request[:-1] + ") VALUES (" else: self._request = self._request[:-2] + ",\n(" self._request += "NULL," for a in range(len(self._entity.getAttributes())): attE = self._entity.getAttributes()[a] if attE != primKey: ft = self._table.fieldsName[a] val = self._entity.__getattribute__(attE) if (val is not None) | self._table.fields[ft].nullable: if isinstance(val, str): self._request += "'" + self._entity.__getattribute__( attE) + "'," elif val is None: self._request += "NULL," else: self._request += str( self._entity.__getattribute__(attE)) + "," else: tools.addMessage("Erreur : le champ" + attE + "ne peut pas être null") self._errors.append(attE) self._request = "" if len(self._errors) == 0: self._request = self._request[:-1] + ");"
def addAttributeToListAttributes(self, attributeName: str): if tools.dataNotNull(attributeName): if attributeName[0:1] != "_": attributeName = "_" + attributeName self._attributes.append(attributeName)
def fetchAll(self): if tools.dataNotNull(self.request): self.cursor = self.connection.cursor() self.cursor.execute(self.request) return self.cursor.fetchall() return None