Commit 596e87cf authored by Francois Mares's avatar Francois Mares
Browse files

Replace SQL.py

parent 67a288df
import psycopg2
"""
Classe d'interface avec une base de données
"""
class SQL():
HOST = 'tuxa.sme.utc'
DATABASE = 'dbnf18p103'
PASSWORD = 'RdhPbg7H'
USER = 'nf18p103'
_HOST = 'tuxa.sme.utc'
_DATABASE = 'dbnf18p103'
_PASSWORD = 'RdhPbg7H'
_USER = 'nf18p103'
def __init__(self,HOST=None, DATABASE=None, PASSWORD=None, USER=None):
if(HOST):
self._HOST=HOST
if(DATABASE):
self._DATABASE=DATABASE
if(PASSWORD):
self._PASSWORD=PASSWORD
if(USER):
self._USER=USER
def _connexion(self):
try:
return psycopg2.connect(f"dbname='{self._DATABASE}' user ='{self._USER}' host='{self._HOST}' password='{self._PASSWORD}'")
except psycopg2.DatabaseError as e:
connexion.rollback()
print("Message système :", e)
# PUBLIC:
def requete_sql(self,sql):
connexion = self._connexion()
try:
connexion = psycopg2.connect(f"dbname='{DATABASE}' user ='{USER}' host='{HOST}' password='{PASSWORD}'")
cur = connexion.cursor()
cur.execute(sql)
rows=cur.fetchall()
connexion.close()
return rows
except psycopg2.IntegrityError as e:
except psycopg2.Error as e:
connexion.rollback()
print("Message système :", e)
def insert_into(self,classe,values):
sql="INSERT INTO "+classe+" VALUES("+values+")"
def insert_into(self,class_name,values):
sql="INSERT INTO "+class_name+" VALUES("
for value in values:
sql+="'"+value+"',"
sql=sql[:-1]
sql+=")"
connexion = self._connexion()
try:
connexion = psycopg2.connect(f"dbname='{DATABASE}' user ='{USER}' host='{HOST}' password='{PASSWORD}'")
cur = connexion.cursor()
cur.execute(sql)
connexion.close()
......
Supports Markdown
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