Marin/definitions.py

21 lines
581 B
Python

### Fonctions communes
import sqlite3
def ex_sql(db_name,request,replace=""):
conn = sqlite3.connect(db_name)
conn.row_factory=sqlite3.Row # La fonction retourne des dicos et pas des listes
cur = conn.cursor()
if not replace=="":
cur.execute(request,replace)
else:
cur.execute(request)
conn.commit()
a = None
if "SELECT" in request.upper():
a = cur.fetchall()
for i in range(len(a)):
a[i] = dict(a[i]) # Convertir les dicos sqlite3 en dico classiques python
cur.close()
conn.close()
return a