summaryrefslogtreecommitdiff
path: root/test-cli/test/helpers/psqldb.py
diff options
context:
space:
mode:
authorManel Caro <mcaro@iatec.biz>2021-11-06 16:28:38 +0100
committerManel Caro <mcaro@iatec.biz>2021-11-06 16:28:38 +0100
commitcf19bfe18cbd283b188a858ee1629f9909c924f4 (patch)
tree1efb23519727130058401df090ab1b5f4cc8ba99 /test-cli/test/helpers/psqldb.py
parentb6932fbaf898724ae87c29f8965621610f377084 (diff)
parentd5b273a3b58a250742049df4ca0ef0ba54f53d33 (diff)
downloadboard-cf19bfe18cbd283b188a858ee1629f9909c924f4.zip
board-cf19bfe18cbd283b188a858ee1629f9909c924f4.tar.gz
board-cf19bfe18cbd283b188a858ee1629f9909c924f4.tar.bz2
Merge branch 'sopa-test'rel.0.1sopa-test
Diffstat (limited to 'test-cli/test/helpers/psqldb.py')
-rw-r--r--test-cli/test/helpers/psqldb.py44
1 files changed, 28 insertions, 16 deletions
diff --git a/test-cli/test/helpers/psqldb.py b/test-cli/test/helpers/psqldb.py
index 26dd03d..0141414 100644
--- a/test-cli/test/helpers/psqldb.py
+++ b/test-cli/test/helpers/psqldb.py
@@ -1,34 +1,40 @@
import psycopg2
+import psycopg2.extras
+
class PgSQLConnection(object):
- """aaaaaaa"""
+ """Postgres Connection Object"""
__conection_object = None
__db_config = {'dbname': 'testsrv', 'host': '192.168.2.171',
- 'password': 'Idkfa2009', 'port': 5432, 'user': 'admin'}
+ 'password': 'Idkfa2009', 'port': 5432, 'user': 'admin'}
- def __init__ (self):
-# self.__conection_object = None
-# if connect_str is not None:
-# self.__db_config = connect_str
-# else:
- self.__db_config = {'dbname': 'testsrv', 'host': '192.168.2.171',
- 'password': 'Idkfa2009', 'port': 5432, 'user': 'admin'}
+ def __init__(self, connect_str=None):
+ self.__conection_object = None
+ if connect_str is not None:
+ self.__db_config = connect_str
+ else:
+ self.__db_config = {'dbname': 'testsrv', 'host': '192.168.2.171',
+ 'password': 'Idkfa2009', 'port': 5432, 'user': 'admin'}
- def db_connect (self, connect_str):
+ def db_connect(self, connect_str=None):
result = False
try:
if connect_str == None:
self.__conection_object = psycopg2.connect(**self.__db_config)
else:
- self.__db_config = connect_str;
+ self.__db_config = connect_str
self.__conection_object = psycopg2.connect(**self.__db_config)
+
self.__conection_object.autocommit = True
result = True
except Exception as error:
print(error)
return result
+ def getConfig(self):
+ return self.__db_config
+
def db_execute_query(self, query):
cur = self.__conection_object.cursor()
cur.execute(query)
@@ -36,20 +42,26 @@ class PgSQLConnection(object):
cur.close()
return data
+ def db_upload_large_file(self, filepath):
+ # a new connection must be created to use large objects
+ __conn = psycopg2.connect(**self.__db_config)
+ lobj = __conn.lobject(oid=0, mode="rw", new_oid=0, new_file=filepath)
+ fileoid = lobj.oid
+ lobj.close()
+ __conn.commit()
+ __conn.close()
+ return fileoid
+
def commit(self):
self.__conection_object.commit()
-
def db_close(self):
if self.__conection_object is not None:
self.__conection_object.close()
del self.__conection_object
self.__conection_object = None
-
def __del__(self):
if self.__conection_object is not None:
self.__conection_object.close()
- #print("disconnected")
-
-
+ # print("disconnected")