summaryrefslogtreecommitdiff
path: root/test-cli/test/helpers/psqldb.py
diff options
context:
space:
mode:
authorManel Caro <mcaro@iseebcn.com>2019-03-09 21:25:56 +0100
committerManel Caro <mcaro@iseebcn.com>2019-03-09 21:25:56 +0100
commit9332c933fc05f42882640c9a4e35fab09854af84 (patch)
tree2b9b00b5a411b27f9705603c0d93b8925afd4677 /test-cli/test/helpers/psqldb.py
downloadboard-9332c933fc05f42882640c9a4e35fab09854af84.zip
board-9332c933fc05f42882640c9a4e35fab09854af84.tar.gz
board-9332c933fc05f42882640c9a4e35fab09854af84.tar.bz2
Board: Client Test Suite Initial Commit
Diffstat (limited to 'test-cli/test/helpers/psqldb.py')
-rw-r--r--test-cli/test/helpers/psqldb.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/test-cli/test/helpers/psqldb.py b/test-cli/test/helpers/psqldb.py
new file mode 100644
index 0000000..af08579
--- /dev/null
+++ b/test-cli/test/helpers/psqldb.py
@@ -0,0 +1,55 @@
+import psycopg2
+
+class PgSQLConnection(object):
+ """aaaaaaa"""
+
+ __conection_object = None
+ __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 = None):
+ result = False
+ try:
+ if connect_str == None:
+ self.__conection_object = psycopg2.connect(**self.__db_config)
+ else:
+ __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 db_execute_query(self, query):
+ cur = self.__conection_object.cursor()
+ cur.execute(query)
+ data = cur.fetchall()
+ cur.close()
+ return data
+
+ 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")
+
+