This repository has been archived on 2021-09-15. You can view files and clone it, but cannot push or open issues or pull requests.
L3GestionParking/src/m/connexionBDD.py

53 lines
1.3 KiB
Python
Raw Normal View History

2015-02-04 13:20:39 +00:00
from shutil import copyfile
2015-01-13 23:39:12 +00:00
__author__ = 'sidya'
2015-01-12 15:49:41 +00:00
2015-01-13 23:39:12 +00:00
import sqlite3
2015-01-12 15:49:41 +00:00
2015-01-10 15:11:11 +00:00
class connexionBDD:
2015-02-04 13:20:39 +00:00
__chemin = "m/BDDprojetPython.sq3"
__sql = "m/table.sql"
2015-01-08 09:31:14 +00:00
def __init__(self):
2015-02-04 13:20:39 +00:00
try:
with open(self.__chemin):
pass
except IOError:
self.__conn = sqlite3.connect(connexionBDD.__chemin)
self.__conn.row_factory = sqlite3.Row
self.__cur = self.__conn.cursor()
self.initialisationBDD()
self.__conn = sqlite3.connect(connexionBDD.__chemin)
2015-01-13 23:39:12 +00:00
self.__conn.row_factory = sqlite3.Row
self.__cur = self.__conn.cursor()
2015-02-04 13:20:39 +00:00
2015-01-13 23:39:12 +00:00
def execute(self, req, param = ()):
r = None
#try:
r = self.__cur.execute(req, param)
self.__conn.commit()
"""except Exception as e:
print (e)"""
return r
def lastId(self):
return self.__cur.lastrowid
2015-01-12 15:49:41 +00:00
2015-01-08 09:31:14 +00:00
def seDeconnecter(self):
2015-01-13 23:39:12 +00:00
self.__cur.close()
self.__conn.close()
def initialisationBDD(self):
2015-02-04 13:20:39 +00:00
with open(self.__sql) as f:
2015-01-13 23:39:12 +00:00
sql = f.read()
self.__conn.executescript(sql)
self.__conn.commit()
2015-02-04 13:20:39 +00:00
@staticmethod
def sauver(path):
copyfile(connexionBDD.chemin, path)
@staticmethod
def charger(path):
copyfile(path, connexionBDD.chemin)