adding custom values to request method
This commit is contained in:
parent
fc805d9b8e
commit
5577493782
1 changed files with 10 additions and 5 deletions
|
@ -2,7 +2,8 @@ import sqlite3
|
||||||
|
|
||||||
class Database:
|
class Database:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.curseur = self.createConnection("src/db/bot.sqlite3").cursor()
|
self.connexion = self.createConnection(r"src/db/bot.sqlite3")
|
||||||
|
self.curseur = self.connexion.cursor()
|
||||||
|
|
||||||
def createConnection(self, path):
|
def createConnection(self, path):
|
||||||
"""Connexion à une base de donnée SQLite"""
|
"""Connexion à une base de donnée SQLite"""
|
||||||
|
@ -11,7 +12,6 @@ class Database:
|
||||||
connnexion = None
|
connnexion = None
|
||||||
try:
|
try:
|
||||||
connnexion = sqlite3.connect(path)
|
connnexion = sqlite3.connect(path)
|
||||||
print(f"Database connected with SQLite v{sqlite3.version}")
|
|
||||||
except sqlite3.Error as e:
|
except sqlite3.Error as e:
|
||||||
print(e)
|
print(e)
|
||||||
return connnexion
|
return connnexion
|
||||||
|
@ -25,9 +25,14 @@ class Database:
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def requete(self, requete):
|
def requete(self, requete, valeurs = None):
|
||||||
"""Reqête vers la base de données"""
|
"""Envois une requête vers la base de données"""
|
||||||
try:
|
try:
|
||||||
self.curseur.execute(requete)
|
if valeurs:
|
||||||
|
self.curseur.execute(requete, valeurs)
|
||||||
|
else:
|
||||||
|
self.curseur.execute(requete)
|
||||||
|
self.connexion.commit()
|
||||||
|
return self.curseur.lastrowid
|
||||||
except sqlite3.Error as e:
|
except sqlite3.Error as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
Reference in a new issue