Exemple #1
0
    def sql(self, gid, sid, did, scid, tid, ptid):
        """
        This function will creates reverse engineered sql for
        the table object

         Args:
           gid: Server Group ID
           sid: Server ID
           did: Database ID
           scid: Schema ID
           tid: Table ID
           ptid: Partition Table ID
        """
        main_sql = []

        SQL = render_template("/".join(
            [self.partition_template_path, 'properties.sql']),
                              did=did,
                              scid=scid,
                              tid=tid,
                              ptid=ptid,
                              datlastsysoid=self.datlastsysoid)
        status, res = self.conn.execute_dict(SQL)
        if not status:
            return internal_server_error(errormsg=res)

        if len(res['rows']) == 0:
            return gone(
                gettext("The specified partitioned table could not be found."))

        data = res['rows'][0]

        return BaseTableView.get_reverse_engineered_sql(
            self, did, scid, ptid, main_sql, data)
Exemple #2
0
    def sql(self, gid, sid, did, scid, tid, ptid):
        """
        This function will creates reverse engineered sql for
        the table object

         Args:
           gid: Server Group ID
           sid: Server ID
           did: Database ID
           scid: Schema ID
           tid: Table ID
           ptid: Partition Table ID
        """
        main_sql = []

        status, res = self._fetch_properties(did, scid, tid, ptid)

        if not status:
            return res

        if len(res['rows']) == 0:
            return gone(self.not_found_error_msg())

        data = res['rows'][0]

        return BaseTableView.get_reverse_engineered_sql(self,
                                                        did=did,
                                                        scid=scid,
                                                        tid=ptid,
                                                        main_sql=main_sql,
                                                        data=data)
Exemple #3
0
    def sql(self, gid, sid, did, scid, tid, ptid):
        """
        This function will creates reverse engineered sql for
        the table object

         Args:
           gid: Server Group ID
           sid: Server ID
           did: Database ID
           scid: Schema ID
           tid: Table ID
           ptid: Partition Table ID
        """
        main_sql = []

        SQL = render_template("/".join([self.partition_template_path,
                                        'properties.sql']),
                              did=did, scid=scid, tid=tid,
                              ptid=ptid, datlastsysoid=self.datlastsysoid)
        status, res = self.conn.execute_dict(SQL)
        if not status:
            return internal_server_error(errormsg=res)

        if len(res['rows']) == 0:
                return gone(gettext(
                    "The specified partitioned table could not be found."))

        data = res['rows'][0]

        return BaseTableView.get_reverse_engineered_sql(self, did, scid, ptid,
                                                        main_sql, data)
Exemple #4
0
    def get_sql_from_diff(self, **kwargs):
        """
        This function will create sql on the basis the difference of 2 tables
        """
        data = dict()
        res = None
        sid = kwargs['sid']
        did = kwargs['did']
        scid = kwargs['scid']
        tid = kwargs['tid']
        ptid = kwargs['ptid']
        diff_data = kwargs['diff_data'] if 'diff_data' in kwargs else None
        json_resp = kwargs['json_resp'] if 'json_resp' in kwargs else True
        diff_schema = kwargs['diff_schema'] if 'diff_schema' in kwargs else\
            None

        if diff_data:
            SQL = render_template("/".join(
                [self.partition_template_path, 'properties.sql']),
                                  did=did,
                                  scid=scid,
                                  tid=tid,
                                  ptid=ptid,
                                  datlastsysoid=self.datlastsysoid)
            status, res = self.conn.execute_dict(SQL)
            if not status:
                return internal_server_error(errormsg=res)

            SQL, name = self.get_sql(did, scid, ptid, diff_data, res)
            SQL = re.sub('\n{2,}', '\n\n', SQL)
            SQL = SQL.strip('\n')
            return SQL
        else:
            main_sql = []

            SQL = render_template("/".join(
                [self.partition_template_path, 'properties.sql']),
                                  did=did,
                                  scid=scid,
                                  tid=tid,
                                  ptid=ptid,
                                  datlastsysoid=self.datlastsysoid)
            status, res = self.conn.execute_dict(SQL)
            if not status:
                return internal_server_error(errormsg=res)

            if len(res['rows']) == 0:
                return gone(
                    gettext(
                        "The specified partitioned table could not be found."))

            data = res['rows'][0]

            if diff_schema:
                data['schema'] = diff_schema
                data['parent_schema'] = diff_schema

            return BaseTableView.get_reverse_engineered_sql(
                self, did, scid, ptid, main_sql, data, False)
Exemple #5
0
 def sql(self, conn_id=None, did=None, sid=None, data={}):
     return BaseTableView.get_sql(self,
                                  did,
                                  None,
                                  None,
                                  data,
                                  None,
                                  add_not_exists_clause=True)
Exemple #6
0
    def fetch_all_tables(self, conn_id=None, did=None, sid=None):
        status, schemas = get_schemas(self.conn, show_system_objects=False)
        if not status:
            return status, schemas

        all_tables = []
        for row in schemas['rows']:
            status, res = \
                BaseTableView.fetch_tables(self, sid, did, row['oid'])
            if not status:
                return status, res

            all_tables.extend(res.values())

        return True, all_tables
Exemple #7
0
 def sql(self, conn_id=None, did=None, sid=None, data={}):
     return BaseTableView.get_sql(self, did, None, None, data, None)