Update driver_execute.py

This commit is contained in:
Eukanj827 2022-08-15 09:58:17 +08:00
parent 4c345b1d31
commit eb4c1bd953
1 changed files with 7 additions and 4 deletions

View File

@ -18,19 +18,19 @@ import psycopg2
from .execute_factory import ExecuteFactory
from .execute_factory import IndexInfo
#class name:
#description:
#methods:
#note
#class name: DriverExecute Inherits from the parent class ExecuteFactory
#description: The SQL statement performs the operations associated with the call
#date: 2022/8/10
#contact: 1865997821
class DriverExecute(ExecuteFactory):
def __init__(self, *arg):
#Call the arguments of the parent class __init__ method
super(DriverExecute, self).__init__(*arg)
self.conn = None
self.cur = None
#Connecting to the database
def init_conn_handle(self):
self.conn = psycopg2.connect(dbname=self.dbname,
user=self.user,
@ -39,6 +39,7 @@ class DriverExecute(ExecuteFactory):
port=self.port)
self.cur = self.conn.cursor()
#If an error occurs after the SQL statement is executed, the error information is reported to the user
def execute(self, sql):
try:
self.cur.execute(sql)
@ -47,11 +48,13 @@ class DriverExecute(ExecuteFactory):
except Exception:
self.conn.commit()
#Disconnecting from the database
def close_conn(self):
if self.conn and self.cur:
self.cur.close()
self.conn.close()
#Check whether multiple nodes exist
def is_multi_node(self):
self.init_conn_handle()
try: