+

Add doSQL and close methods

Benjamin Renard [2015-04-01 15:52:32]
Add doSQL and close methods
Filename
PgDB.py
diff --git a/PgDB.py b/PgDB.py
index f017ba5..f86f4b8 100644
--- a/PgDB.py
+++ b/PgDB.py
@@ -28,6 +28,10 @@ class PgDB(object):
 				logging.fatal(e)
 				sys.exit(1)

+	def close(self):
+		if self.con:
+			self.con.close()
+
 	def setEncoding(self,enc):
 		if self.con:
 			try:
@@ -37,6 +41,20 @@ class PgDB(object):
 				logging.error(e)
 		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):
 		cursor = self.con.cursor()
 		try:
ViewGit