Commit 5ca4daf5 authored by Francois Mares's avatar Francois Mares
Browse files

Replace SQL.py

parent e70caf59
......@@ -23,35 +23,63 @@ class SQL():
# _PROTECTED
def _connexion(self):
return psycopg2.connect(f"dbname='{self._DATABASE}' user ='{self._USER}' host='{self._HOST}' password='{self._PASSWORD}'")
# PUBLIC:
def requete_sql(self,sql):
connexion=None
try:
connexion = self._connexion()
cur = connexion.cursor()
cur.execute(sql)
rows=cur.fetchall()
connexion.close()
return rows
return psycopg2.connect(f"dbname='{self._DATABASE}' user ='{self._USER}' host='{self._HOST}' password='{self._PASSWORD}'")
except psycopg2.Error as e:
print("Message système :", e)
return None
def _execute_sql(self, file_path, mode='r'):
connexion = self._connexion()
if connexion:
try :
cur = connexion.cursor()
cur.execute(open(file_path, mode).read())
connexion.commit()
connexion.close()
return
except psycopg2.Error as e:
connexion.rollback()
print("Message système :", e)
def insert_into(self,class_name,values):
def _requete_sql(self,sql):
connexion = self._connexion()
if connexion:
try:
cur = connexion.cursor()
cur.execute(sql)
rows=cur.fetchall()
connexion.close()
return rows
except psycopg2.Error as e:
connexion.rollback()
print("Message système :", e)
def _insert_into(self,class_name,values):
sql="INSERT INTO "+class_name+" VALUES("
for value in values:
sql+="'"+value+"',"
sql=sql[:-1]
sql+=")"
try:
connexion = self._connexion()
cur = connexion.cursor()
cur.execute(sql)
connexion.close()
except psycopg2.Error as e:
print("Message système :", e)
self.requete_sql(sql)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment