import os

class ExecuteSQL:
    def __init__(self,pgconn):
        self._pgconn = pgconn
        self._cursor = pgconn.cursor

    def createProcedures(self):
        dir_path = os.path.dirname(os.path.realpath(__file__))
        dir_file = os.path.join(dir_path, "sql/Procedures.sql")
        with open(dir_file, 'r') as myfile:
            data = myfile.read()

        self._cursor.execute(data)
        self._pgconn.connection.commit()
        count = self._cursor.rowcount
        print (count, "Record inserted successfully into the table")

    def createTriggers(self):
        dir_path = os.path.dirname(os.path.realpath(__file__))
        dir_file = os.path.join(dir_path, "sql/functions_g.sql")
        with open(dir_file, 'r') as myfile:
            data = myfile.read()

        self._cursor.execute(data)
        self._pgconn.connection.commit()
        count = self._cursor.rowcount
        print (count, "Created functions for triggers")

        dir_path = os.path.dirname(os.path.realpath(__file__))
        dir_file = os.path.join(dir_path, "sql/triggers_g_sentences.sql")
        with open(dir_file, 'r') as myfile:
            data = myfile.read()

        self._cursor.execute(data)
        self._pgconn.connection.commit()
        count = self._cursor.rowcount
        print (count, "Created functions for triggers")