示例#1
0
    def get_sql_from_index_diff(self, **kwargs):
        """
        This function get the sql from index diff.
        :param kwargs:
        :return:
        """
        sid = kwargs.get('sid')
        did = kwargs.get('did')
        scid = kwargs.get('scid')
        tid = kwargs.get('tid')
        idx = kwargs.get('idx')
        data = kwargs.get('data', None)
        target_schema = kwargs.get('target_schema', None)
        drop_req = kwargs.get('drop_req', False)

        sql = ''

        if data:
            data['schema'] = self.schema
            data['nspname'] = self.schema
            data['table'] = self.table

            sql, name = index_utils.get_sql(
                self.conn,
                data=data,
                did=did,
                tid=tid,
                idx=idx,
                datlastsysoid=self._DATABASE_LAST_SYSTEM_OID,
                mode='create')

            sql = sql.strip('\n').strip(' ')

        elif target_schema:
            sql = index_utils.get_reverse_engineered_sql(
                self.conn,
                schema=target_schema,
                table=self.table,
                did=did,
                tid=tid,
                idx=idx,
                datlastsysoid=self._DATABASE_LAST_SYSTEM_OID,
                template_path=None,
                with_header=False,
                add_not_exists_clause=True)

        drop_sql = ''
        if drop_req:
            drop_sql = '\n' + self.delete(gid=1,
                                          sid=sid,
                                          did=did,
                                          scid=scid,
                                          tid=tid,
                                          idx=idx,
                                          only_sql=True)

        if drop_sql != '':
            sql = drop_sql + '\n\n' + sql
        return sql
示例#2
0
    def get_sql_from_index_diff(self,
                                sid,
                                did,
                                scid,
                                tid,
                                idx,
                                data=None,
                                diff_schema=None,
                                drop_req=False):

        tmp_idx = idx
        schema = ''
        if data:
            schema = self.schema

            data['schema'] = self.schema
            data['nspname'] = self.schema
            data['table'] = self.table

            sql, name = index_utils.get_sql(self.conn,
                                            data,
                                            did,
                                            tid,
                                            idx,
                                            self.datlastsysoid,
                                            mode='create')

            sql = sql.strip('\n').strip(' ')

        elif diff_schema:
            schema = diff_schema

            sql = index_utils.get_reverse_engineered_sql(self.conn,
                                                         schema,
                                                         self.table,
                                                         did,
                                                         tid,
                                                         idx,
                                                         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,
                                          idx=idx,
                                          only_sql=True)

        if drop_sql != '':
            sql = drop_sql + '\n\n' + sql
        return sql
示例#3
0
    def sql(self, gid, sid, did, scid, tid, idx):
        """
        This function will generates reverse engineered sql for schema object

         Args:
           gid: Server Group ID
           sid: Server ID
           did: Database ID
           scid: Schema ID
           tid: Table ID
           idx: Index ID
        """

        SQL = index_utils.get_reverse_engineered_sql(self.conn, self.schema,
                                                     self.table, did, tid, idx,
                                                     self.datlastsysoid)

        return ajax_response(response=SQL)
示例#4
0
    def sql(self, gid, sid, did, scid, tid, idx):
        """
        This function will generates reverse engineered sql for schema object

         Args:
           gid: Server Group ID
           sid: Server ID
           did: Database ID
           scid: Schema ID
           tid: Table ID
           idx: Index ID
        """

        SQL = index_utils.get_reverse_engineered_sql(
            self.conn,
            schema=self.schema,
            table=self.table,
            did=did,
            tid=tid,
            idx=idx,
            datlastsysoid=self._DATABASE_LAST_SYSTEM_OID,
            add_not_exists_clause=True)

        return ajax_response(response=SQL)
示例#5
0
    def get_sql_from_index_diff(self, sid, did, scid, tid, idx, data=None,
                                diff_schema=None, drop_req=False):

        tmp_idx = idx
        schema = ''
        if data:
            schema = self.schema
        elif diff_schema:
            schema = diff_schema

        sql = index_utils.get_reverse_engineered_sql(
            self.conn, schema,
            self.table, did, tid, idx,
            self.datlastsysoid,
            template_path=None, with_header=False)

        drop_sql = ''
        if drop_req:
            drop_sql = '\n' + render_template(
                "/".join([self.template_path, 'delete.sql']),
                data=data, conn=self.conn
            )

        return drop_sql + '\n\n' + sql