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:
|
||||
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):
|
||||
"""Connexion à une base de donnée SQLite"""
|
||||
|
@ -11,7 +12,6 @@ class Database:
|
|||
connnexion = None
|
||||
try:
|
||||
connnexion = sqlite3.connect(path)
|
||||
print(f"Database connected with SQLite v{sqlite3.version}")
|
||||
except sqlite3.Error as e:
|
||||
print(e)
|
||||
return connnexion
|
||||
|
@ -25,9 +25,14 @@ class Database:
|
|||
else:
|
||||
return True
|
||||
|
||||
def requete(self, requete):
|
||||
"""Reqête vers la base de données"""
|
||||
def requete(self, requete, valeurs = None):
|
||||
"""Envois une requête vers la base de données"""
|
||||
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:
|
||||
print(e)
|
||||
|
|
Reference in a new issue