def get_sql_from_diff(self, **kwargs): """ This function is used to get the DDL/DML statements. :param kwargs :return: """ sid = kwargs.get('sid') did = kwargs.get('did') scid = kwargs.get('scid') tid = kwargs.get('tid') oid = kwargs.get('plid') data = kwargs.get('data', None) drop_req = kwargs.get('drop_req', False) target_schema = kwargs.get('target_schema', None) if data: data['schema'] = self.schema data['table'] = self.table sql, name = row_security_policies_utils.get_sql( self.conn, data=data, scid=scid, plid=oid, policy_table_id=tid, schema=self.schema, table=self.table) sql = sql.strip('\n').strip(' ') else: schema = self.schema if target_schema: schema = target_schema sql = row_security_policies_utils.get_reverse_engineered_sql( self.conn, schema=schema, table=self.table, scid=scid, plid=oid, policy_table_id=tid, datlastsysoid=self._DATABASE_LAST_SYSTEM_OID, with_header=False) drop_sql = '' if drop_req: drop_sql = '\n' + self.delete(gid=1, sid=sid, did=did, scid=scid, tid=tid, plid=oid, only_sql=True) if drop_sql != '': sql = drop_sql + '\n\n' + sql return sql
def get_sql_from_diff(self, gid, sid, did, scid, tid, plid, data=None, diff_schema=None, drop_req=False): sql = '' if data: data['schema'] = self.schema data['table'] = self.table sql, name = row_security_policies_utils.get_sql( self.conn, data, did, scid, tid, plid, self.datlastsysoid, self.schema, self.table) sql = sql.strip('\n').strip(' ') elif diff_schema: schema = diff_schema sql = row_security_policies_utils.get_reverse_engineered_sql( self.conn, schema, self.table, did, scid, tid, plid, self.datlastsysoid, template_path=None, with_header=False) drop_sql = '' if drop_req: drop_sql = '\n' + self.delete(gid=1, sid=sid, did=did, scid=scid, tid=tid, plid=plid, only_sql=True) if drop_sql != '': sql = drop_sql + '\n\n' + sql return sql
def sql(self, gid, sid, did, scid, tid, plid): """ This function will generate sql to render into the sql panel Args: gid: Server Group ID sid: Server ID did: Database ID scid: Schema ID tid: Table ID plid: policy ID """ SQL = row_security_policies_utils.get_reverse_engineered_sql( self.conn, self.schema, self.table, did, scid, tid, plid, self.datlastsysoid) return ajax_response(response=SQL)