Add doSQL and close methods

This commit is contained in:
Benjamin Renard 2015-04-01 17:52:32 +02:00
parent de9472a08a
commit a3cca712c2

18
PgDB.py
View file

@ -28,6 +28,10 @@ class PgDB(object):
logging.fatal(e) logging.fatal(e)
sys.exit(1) sys.exit(1)
def close(self):
if self.con:
self.con.close()
def setEncoding(self,enc): def setEncoding(self,enc):
if self.con: if self.con:
try: try:
@ -37,6 +41,20 @@ class PgDB(object):
logging.error(e) logging.error(e)
return False return False
def doSQL(self,sql,params=None):
cursor = self.con.cursor()
try:
if params is None:
cursor.execute(sql)
else:
cursor.execute(sql,params)
self.con.commit()
return True
except Exception, e:
logging.error('Erreur durant la requete sql %s : %s' % (sql,e))
self.con.rollback()
return False
def doSelect(self,sql): def doSelect(self,sql):
cursor = self.con.cursor() cursor = self.con.cursor()
try: try: