Esempio n. 1
0
 def createTable(self, tableName):
     assert Strings.notEmpty(tableName), "table Name Cannot be Empty"
     connection = self.m_databaseConnection.getConnection()
     for env in EnvironmentTypeEnum:
         try:
             query = self.getCreateTableQuery(table=Strings.concatinateWithUnderScore(str1=tableName, str2=env.name))
             print(query)
             connection.cursor().execute(query)
             connection.commit()
             query = self.insertQuery(table=Strings.concatinateWithUnderScore(str1=tableName, str2=env.name))
             print(query)
             connection.cursor().execute(query)
             connection.commit()
         except (Exception, psycopg2.Error) as error:
             print(error)
     self.m_databaseConnection.closeConnection(connection=connection);
 def get(self):
     try:
         query = self.m_helper.getEntityQuery(
             data=Strings.concatinateWithUnderScore(
                 self.m_table.tableName(),
                 self.m_serverEnvironment.getServerEnvironment().name))
         print(query)
         conn = self.m_dbConnection.getConnection()
         cursor = conn.cursor()
         cursor.execute(query)
         row = cursor.fetchall()[0]
         self.id = row[1]
         conn.close()
         return self.m_encoder.convert(id=int(row[1]))
     except (Exception, psycopg2.Error) as error:
         print("Error in update operation", error)
    def update(self):

        try:
            query = self.m_helper.updateEntityQuery(
                data=Strings.concatinateWithUnderScore(
                    self.m_table.tableName(),
                    self.m_serverEnvironment.getServerEnvironment().name),
                value=self.getIdNumber(self.id))
            print(query)
            conn = self.m_dbConnection.getConnection()
            cursor = conn.cursor()
            cursor.execute(query)
            conn.commit()
            count = cursor.rowcount
            conn.close()
        except (Exception, psycopg2.Error) as error:
            print("Error in update operation", error)
Esempio n. 4
0
 def update(self, id, json, table):
     try:
         query = self.getUpdateQuery(id=id, json=json, table=Strings.concatinateWithUnderScore(str1=table,
                                                                                               str2=self.m_serverListner.getServerEnvironment().name))
         print(query)
         conn = self.m_dbConnection.getConnection()
         cursor = conn.cursor()
         cursor.execute(str(query))
         if (cursor.rowcount > 0):
             conn.commit()
             conn.close()
             cursor.close()
             return json
         else:
             conn.commit()
             conn.close()
             cursor.close()
             return None
     except (Exception, psycopg2.Error) as error:
         print("Error in update operation", error)
 def checkTable(self, tableName):
     assert Strings.notEmpty(tableName), "table Name Cannot be Empty"
     connection = self.m_databaseConnection.getConnection()
     cursor = connection.cursor()
     check = False
     for env in EnvironmentTypeEnum:
         try:
             query = self.ckeckTableQuery(
                 tableName=Strings.concatinateWithUnderScore(str1=tableName,
                                                             str2=env.name))
             print(query)
             cursor.execute(query)
             val = cursor.fetchall()[0]
             check = val[0]
             connection.commit()
         except:
             pass
     self.m_databaseConnection.closeConnection(connection=connection)
     if (check):
         return check
 def get(self, id, table):
     try:
         query = self.getQuery(table=Strings.concatinateWithUnderScore(str1=table,
                                                                       str2=self.m_serverListner.getServerEnvironment().name),
                               id=id)
         print(query)
         conn = self.m_dbConnection.getConnection()
         cursor = conn.cursor()
         cursor.execute(query)
         if (cursor.rowcount == 1):
             row = cursor.fetchall()
             data = row[0]
             conn.commit()
             conn.close()
             cursor.close()
             return data[0]
         else:
             conn.commit()
             conn.close()
             cursor.close()
             return None
     except (Exception, psycopg2.Error) as error:
         print("Error in update operation", error)