Compare commits
3 commits
Author | SHA1 | Date | |
---|---|---|---|
3c2da7f85e | |||
8dbb067996 | |||
198d6021b4 |
18
PgDB.py
18
PgDB.py
|
@ -28,11 +28,20 @@ class PgDB(object):
|
||||||
def connect(self):
|
def connect(self):
|
||||||
if self.con == 0:
|
if self.con == 0:
|
||||||
try:
|
try:
|
||||||
con = psycopg2.connect("dbname='%s' user='%s' host='%s' password='%s'" % (self.db,self.user,self.host,self.pwd))
|
con = psycopg2.connect(
|
||||||
|
dbname=self.db,
|
||||||
|
user=self.user,
|
||||||
|
host=self.host,
|
||||||
|
password=self.pwd
|
||||||
|
)
|
||||||
self.con = con
|
self.con = con
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.fatal('An error occured during Postgresql database connection.', exc_info=1)
|
logging.fatal(
|
||||||
|
'An error occured during Postgresql database connection (%s@%s, database=%s).',
|
||||||
|
self.user, self.host, self.db, exc_info=1
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
return True
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
if self.con:
|
if self.con:
|
||||||
|
@ -61,10 +70,13 @@ class PgDB(object):
|
||||||
self.con.rollback()
|
self.con.rollback()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def doSelect(self,sql):
|
def doSelect(self,sql,params):
|
||||||
cursor = self.con.cursor()
|
cursor = self.con.cursor()
|
||||||
try:
|
try:
|
||||||
|
if params is None:
|
||||||
cursor.execute(sql)
|
cursor.execute(sql)
|
||||||
|
else:
|
||||||
|
cursor.execute(sql,params)
|
||||||
results = cursor.fetchall()
|
results = cursor.fetchall()
|
||||||
return results
|
return results
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
Loading…
Reference in a new issue