1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| def envoyer(self, instance_glob):
try:
cursor = instance_glob.connection.cursor()
sql = """SELECT Num_DT FROM Data_LEIT ORDER BY Num_DT DESC LIMIT 1"""
cursor.execute(sql)
liste = cursor.fetchall()
val = liste[-1][0]
#ici je récupère la valeur de la dernière ligne de ma bdd (1ere colonne)
suffixe_annee = int(str(datetime.datetime.today().year)[2:])
suffixe_annee_last_dt = int(val[2:4])
partie_chiffree = int(val[-4:])
if suffixe_annee_last_dt == suffixe_annee:
partie_chiffree = partie_chiffree + 1
else:
partie_chiffree = 1
if partie_chiffree < 10:
partie_chiffree = str("000") + str(partie_chiffree)
elif partie_chiffree < 100:
partie_chiffree = str("00") + str(partie_chiffree)
elif partie_chiffree < 1000:
partie_chiffree = str("0") + str(partie_chiffree)
else:
partie_chiffree = str(partie_chiffree)
new_number = "DT" + str(suffixe_annee) + "-" + str(partie_chiffree)
base = tuple(["%s" for i in range(0, len(self.instance_glob.df.columns), 1)])
colonnes_requette = "(Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13, Col14, Col15, Col16, Col17, Col18, Col19, Col20, Col21, Col22, Col23, Col24, Col25, Col26, Col27, Col28, Col29, Col30, Col31, Col32, Col33, Col34, Col35, Col36, Col37, Col38, Col39, Col40, Col41)"
new_val_saisies = (Val1, Val2, Val3, Val4, Val5, Val6, Val7, Val8, Val9, Val10, Val11, Val12, Val13, Val14, Val15, Val16)
new_val_non_saisies = ("","","","","","","","","","","","","","","","","","","","","","","","","")
new_val = new_val_saisies + new_val_non_saisies
new_base = str(base).replace("'","")
sql = "INSERT INTO Ma_Table " + colonnes_requette + " VALUES " + new_base
cursor.execute(sql, new_val)
instance_glob.connection.commit()
cursor.close()
Except Exception as error:
print(error) |
Partager