Beispiel #1
0
    def update(self, gid, sid, did, scid, tid, idx):
        """
        This function will updates existing the schema object

         Args:
           gid: Server Group ID
           sid: Server ID
           did: Database ID
           scid: Schema ID
           tid: Table ID
           idx: Index ID
        """
        data = request.form if request.form else json.loads(request.data,
                                                            encoding='utf-8')
        data['schema'] = self.schema
        data['table'] = self.table
        try:
            SQL, name = index_utils.get_sql(self.conn, data, did, tid, idx,
                                            self.datlastsysoid)
            if not isinstance(SQL, str):
                return SQL
            SQL = SQL.strip('\n').strip(' ')
            status, res = self.conn.execute_scalar(SQL)
            if not status:
                return internal_server_error(errormsg=res)

            return jsonify(node=self.blueprint.generate_browser_node(
                idx, tid, name, icon="icon-%s" % self.node_type))
        except Exception as e:
            return internal_server_error(errormsg=str(e))
Beispiel #2
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
Beispiel #3
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
Beispiel #4
0
    def msql(self, gid, sid, did, scid, tid, idx=None):
        """
        This function will generates modified sql for schema object

         Args:
           gid: Server Group ID
           sid: Server ID
           did: Database ID
           scid: Schema ID
           tid: Table ID
           idx: Index ID (When working with existing index)
        """
        data = dict()
        for k, v in request.args.items():
            try:
                # comments should be taken as is because if user enters a
                # json comment it is parsed by loads which should not happen
                if k in ('description', ):
                    data[k] = v
                else:
                    data[k] = json.loads(v, encoding='utf-8')
            except ValueError:
                data[k] = v

        # Adding parent into data dict, will be using it while creating sql
        data['schema'] = self.schema
        data['table'] = self.table

        try:
            sql, name = index_utils.get_sql(
                self.conn,
                data=data,
                did=did,
                tid=tid,
                idx=idx,
                datlastsysoid=self._DATABASE_LAST_SYSTEM_OID,
                mode='create')
            if not isinstance(sql, str):
                return sql
            sql = sql.strip('\n').strip(' ')
            if sql == '':
                sql = "--modified SQL"
            return make_json_response(data=sql, status=200)
        except Exception as e:
            return internal_server_error(errormsg=str(e))