Пример #1
0
    def dependencies(self, gid, sid, did, scid, coid, clid):
        """
        This function get the dependencies and return ajax response
        for the column node.

        Args:
            gid: Server Group ID
            sid: Server ID
            did: Database ID
            scid: Schema ID
            coid: Catalog objects ID
            clid: Column ID

        """
        # Specific condition for column which we need to append
        where = "WHERE dep.objid={0}::OID AND dep.objsubid={1}".format(
            coid, clid
        )

        dependencies_result = self.get_dependencies(
            self.conn, clid, where=where
        )

        return ajax_response(
            response=dependencies_result,
            status=200
        )
Пример #2
0
    def sql(self, gid, sid, did, eid):
        """
        This function will generate sql for the sql panel
        """
        SQL = render_template("/".join(
            [self.template_path, 'properties.sql']
        ), eid=eid)
        status, res = self.conn.execute_dict(SQL)
        if not status:
            return internal_server_error(errormsg=res)
        if len(res['rows']) == 0:
            return gone(
                _("Could not find the extension on the server.")
            )

        result = res['rows'][0]

        SQL = render_template("/".join(
            [self.template_path, 'create.sql']
        ),
            data=result,
            conn=self.conn,
            display_comments=True
        )

        return ajax_response(response=SQL)
Пример #3
0
    def properties(self, gid, sid, did, scid, coid):
        """
        This function will show the properties of the selected collation node.

        Args:
            gid: Server Group ID
            sid: Server ID
            did:  Database ID
            scid: Schema ID
            scid: Schema ID
            coid: Collation ID

        Returns:
            JSON of selected collation node
        """

        try:
            SQL = render_template("/".join([self.template_path,
                                            'properties.sql']),
                                  scid=scid, coid=coid)
            status, res = self.conn.execute_dict(SQL)

            if not status:
                return internal_server_error(errormsg=res)

            return ajax_response(
                response=res['rows'][0],
                status=200
            )

        except Exception as e:
            return internal_server_error(errormsg=str(e))
Пример #4
0
    def properties(self, gid, sid, did, etid):
        """
        This function is used to list all the event trigger
        nodes within that collection.

        Args:
          gid: Server Group ID
          sid: Server ID
          did: Database ID
          etid: Event trigger ID

        Returns:

        """
        sql = render_template(
            "/".join([self.template_path, 'properties.sql']),
            etid=etid, conn=self.conn
        )
        status, res = self.conn.execute_dict(sql)
        if not status:
            return internal_server_error(errormsg=res)

        if len(res['rows']) == 0:
            return gone(
                gettext("Could not find the event trigger information.")
            )

        result = res['rows'][0]
        result = self._formatter(result)

        return ajax_response(
            response=result,
            status=200
        )
Пример #5
0
    def sql(self, gid, sid, did, scid, coid):
        """
        This function will generates reverse engineered sql for collation object

         Args:
           gid: Server Group ID
           sid: Server ID
           did: Database ID
           scid: Schema ID
           coid: Collation ID
        """
        SQL = render_template("/".join([self.template_path,
                                        'properties.sql']),
                              scid=scid, coid=coid)
        status, res = self.conn.execute_dict(SQL)
        if not status:
            return internal_server_error(errormsg=res)

        data = res['rows'][0]

        SQL = render_template("/".join([self.template_path,
                                        'create.sql']),
                              data=data, conn=self.conn)

        sql_header = "-- Collation: {0};\n\n-- ".format(data['name'])
        sql_header += render_template("/".join([self.template_path,
                                                'delete.sql']),
                                      name=data['name'])
        SQL = sql_header + '\n\n' + SQL.strip('\n')

        return ajax_response(response=SQL)
Пример #6
0
    def properties(self, gid, sid, did, scid, pkgid, edbfnid=None):
        """
        Returns the Function properties.

        Args:
            gid: Server Group Id
            sid: Server Id
            did: Database Id
            scid: Schema Id
            pkgid: Package Id
            edbfnid: Function Id
        """
        SQL = render_template("/".join([self.sql_template_path,
                                        'properties.sql']),
                              pkgid=pkgid, edbfnid=edbfnid)
        status, res = self.conn.execute_dict(SQL)
        if not status:
            return internal_server_error(errormsg=res)

        if len(res['rows']) == 0:
            return gone(
                gettext("Could not find the function in the database.")
            )

        resp_data = res['rows'][0]

        # Get formatted Arguments
        frmtd_params, frmtd_proargs = self._format_arguments_from_db(resp_data)
        resp_data.update(frmtd_params)
        resp_data.update(frmtd_proargs)

        return ajax_response(
            response=resp_data,
            status=200
        )
Пример #7
0
    def list(self, gid, sid):
        last_system_oid = self.retrieve_last_system_oid()

        db_disp_res = None
        params = None
        if self.manager and self.manager.db_res:
            db_disp_res = ", ".join(
                ['%s'] * len(self.manager.db_res.split(','))
            )
            params = tuple(self.manager.db_res.split(','))

        SQL = render_template(
            "/".join([self.template_path, 'properties.sql']),
            conn=self.conn,
            last_system_oid=last_system_oid,
            db_restrictions=db_disp_res
        )
        status, res = self.conn.execute_dict(SQL, params)

        if not status:
            return internal_server_error(errormsg=res)

        return ajax_response(
            response=res['rows'],
            status=200
        )
Пример #8
0
    def list(self, gid, sid, did, scid):
        """
        This function is used to list all the catalog objects
        nodes within that collection.

        Args:
            gid: Server group ID
            sid: Server ID
            did: Database ID
            scid: Schema ID

        Returns:
            JSON of available catalog objects nodes
        """

        SQL = render_template("/".join([
            self.template_path, 'properties.sql'
        ]), scid=scid
        )

        status, res = self.conn.execute_dict(SQL)

        if not status:
            return internal_server_error(errormsg=res)
        return ajax_response(
            response=res['rows'],
            status=200
        )
Пример #9
0
def role(rid):
    """

    Args:
      rid: Role id

    Returns: List of pgAdmin4 users roles or single role if rid is provided.

    """

    if rid:
        r = Role.query.get(rid)

        res = {'id': r.id, 'name': r.name}
    else:
        roles = Role.query.all()

        roles_data = []
        for r in roles:
            roles_data.append({'id': r.id,
                               'name': r.name})

        res = roles_data

    return ajax_response(
        response=res,
        status=200
    )
Пример #10
0
    def properties(self, gid, sid, did, scid, coid):
        """
        This function will show the properties of the selected
        catalog objects node.

        Args:
            gid: Server Group ID
            sid: Server ID
            did:  Database ID
            scid: Schema ID
            scid: Schema ID
            coid: Catalog object ID

        Returns:
            JSON of selected catalog objects node
        """
        SQL = render_template(
            "/".join([self.template_path, 'properties.sql']),
            scid=scid, coid=coid
        )
        status, res = self.conn.execute_dict(SQL)

        if not status:
            return internal_server_error(errormsg=res)

        if len(res['rows']) == 0:
            return gone(
                gettext("""Could not find the specified catalog object."""))

        return ajax_response(
            response=res['rows'][0],
            status=200
        )
Пример #11
0
    def sql(self, gid, sid, did, scid, seid):
        """
        This function will generate sql for sql panel

        Args:
            gid: Server Group ID
            sid: Server ID
            did: Database ID
            scid: Schema ID
            seid: Sequence ID
        """

        SQL = render_template("/".join([self.template_path, 'properties.sql']), scid=scid, seid=seid)
        status, res = self.conn.execute_dict(SQL)
        if not status:
            return internal_server_error(errormsg=res)

        for row in res['rows']:
            SQL = render_template("/".join([self.template_path, 'get_def.sql']), data=row)
            status, rset1 = self.conn.execute_dict(SQL)
            if not status:
                return internal_server_error(errormsg=rset1)

            row['current_value'] = rset1['rows'][0]['last_value']
            row['minimum'] = rset1['rows'][0]['min_value']
            row['maximum'] = rset1['rows'][0]['max_value']
            row['increment'] = rset1['rows'][0]['increment_by']
            row['cache'] = rset1['rows'][0]['cache_value']
            row['cycled'] = rset1['rows'][0]['is_cycled']

        result = res['rows'][0]
        result = self._formatter(result, scid, seid)
        SQL = self.getSQL(gid, sid, did, result, scid)
        SQL = SQL.strip('\n').strip(' ')
        return ajax_response(response=SQL)
Пример #12
0
    def properties(self, gid, sid):
        """Return list of attributes of a server"""
        server = Server.query.filter_by(
            user_id=current_user.id,
            id=sid).first()

        if server is None:
            return make_json_response(
                success=0,
                errormsg=gettext("Couldn't find the given server")
            )

        sg = ServerGroup.query.filter_by(
            user_id=current_user.id,
            id=server.servergroup_id
        ).first()

        return ajax_response(
            response={
                'id': server.id,
                'name': server.name,
                'host': server.host,
                'port': server.port,
                'db': server.maintenance_db,
                'username': server.username,
                'gid': server.servergroup_id,
                'group-name': sg.name,
                'comment': server.comment,
                # TODO:: Make sure - we do have correct values here
                'connected': True,
                'version': 'PostgreSQL 9.3 (linux-x64)'
            }
        )
Пример #13
0
    def list(self, gid, sid, did):
        """
        This function is used to list all the foreign data wrapper
        nodes within that collection.

        Args:
            gid: Server Group ID
            sid: Server ID
            did: Database ID
        """
        sql = render_template("/".join([self.template_path, 'properties.sql']),
                              conn=self.conn)
        status, res = self.conn.execute_dict(sql)

        if not status:
            return internal_server_error(errormsg=res)

        for row in res['rows']:
            if row['fdwoptions'] is not None:
                row['fdwoptions'] = tokenize_options(
                    row['fdwoptions'], 'fdwoption', 'fdwvalue'
                )

        return ajax_response(
            response=res['rows'],
            status=200
        )
Пример #14
0
def user(uid):
    """

    Args:
      uid: User id

    Returns: List of pgAdmin4 users or single user if uid is provided.

    """

    if uid:
        u = User.query.get(uid)

        res = {'id': u.id,
               'email': u.email,
               'active': u.active,
               'role': u.roles[0].id
               }
    else:
        users = User.query.all()

        users_data = []
        for u in users:
            users_data.append({'id': u.id,
                               'email': u.email,
                               'active': u.active,
                               'role': u.roles[0].id
                               })

        res = users_data

    return ajax_response(
        response=res,
        status=200
    )
Пример #15
0
    def sql(self, gid, sid, did, scid, syid):
        """
        This function will generates reverse engineered sql for synonym object

         Args:
           gid: Server Group ID
           sid: Server ID
           did: Database ID
           scid: Schema ID
           syid: Synonym ID
        """
        SQL = render_template("/".join([self.template_path,
                                        'properties.sql']),
                              scid=scid, syid=syid)
        status, res = self.conn.execute_dict(SQL)
        if not status:
            return internal_server_error(errormsg=res)

        if len(res['rows']) > 0:
            data = res['rows'][0]
        else:
            return gone(
                gettext('The specified synonym could not be found.')
            )

        SQL = render_template("/".join([self.template_path,
                                        'create.sql']),
                              data=data, conn=self.conn, comment=True)

        return ajax_response(response=SQL)
Пример #16
0
    def properties(self, gid, sid, did, fid, fsid, umid):
        """
        This function will show the properties of the selected user mapping node.

        Args:
            gid: Server Group ID
            sid: Server ID
            did: Database ID
            fid: Foreign data wrapper ID
            fsid: Foreign server ID
            umid: User mapping ID
        """

        sql = render_template("/".join([self.template_path, 'properties.sql']), umid=umid, conn=self.conn)
        status, res = self.conn.execute_dict(sql)

        if not status:
            return internal_server_error(errormsg=res)

        if res['rows'][0]['umoptions'] is not None:
            res['rows'][0]['umoptions'] = self.tokenizeOptions(res['rows'][0]['umoptions'])

        return ajax_response(
            response=res['rows'][0],
            status=200
        )
Пример #17
0
    def select_sql(self, gid, sid, did, scid, foid):
        """
        SELECT script sql for the object

        Args:
            gid: Server Group Id
            sid: Server Id
            did: Database Id
            scid: Schema Id
            foid: Foreign Table Id

        Returns:
            SELECT Script sql for the object
        """
        data = self._fetch_properties(gid, sid, did, scid, foid)
        if data is False:
            return gone(
                gettext("Could not find the foreign table on the server.")
            )

        columns = []
        for c in data['columns']:
            columns.append(self.qtIdent(self.conn, c['attname']))

        if len(columns) > 0:
            columns = ", ".join(columns)
        else:
            columns = '*'

        sql = u"SELECT {0}\n\tFROM {1};".format(
            columns,
            self.qtIdent(self.conn, data['basensp'], data['name'])
        )

        return ajax_response(response=sql)
Пример #18
0
def get_data(sid, did, template):
    """
    Generic function to get server stats based on an SQL template
    Args:
        sid: The server ID
        did: The database ID
        template: The SQL template name

    Returns:

    """
    # Allow no server ID to be specified (so we can generate a route in JS)
    # but throw an error if it's actually called.
    if not sid:
        return internal_server_error(errormsg='Server ID not specified.')

    sql = render_template(
        "/".join([g.template_path, template]), did=did
    )
    status, res = g.conn.execute_dict(sql)

    if not status:
        return internal_server_error(errormsg=res)

    return ajax_response(
        response=res['rows'],
        status=200
    )
Пример #19
0
    def delete_sql(self, gid, sid, did, scid, foid):
        """
        DELETE script sql for the object

        Args:
            gid: Server Group Id
            sid: Server Id
            did: Database Id
            scid: Schema Id
            foid: Foreign Table Id

        Returns:
            DELETE Script sql for the object
        """
        data = self._fetch_properties(gid, sid, did, scid, foid)
        if data is False:
            return gone(
                gettext("Could not find the foreign table on the server.")
            )

        sql = u"DELETE FROM {0}\n\tWHERE <condition>;".format(
            self.qtIdent(self.conn, data['basensp'], data['name'])
        )

        return ajax_response(response=sql)
Пример #20
0
    def properties(self, gid, sid, jid, jscid):
        """
        This function will show the properties of the selected language node.

        Args:
            gid: Server Group ID
            sid: Server ID
            jid: Job ID
            jscid: JobSchedule ID
        """
        sql = render_template(
            "/".join([self.template_path, 'properties.sql']),
            jscid=jscid, jid=jid
        )
        status, res = self.conn.execute_dict(sql)

        if not status:
            return internal_server_error(errormsg=res)

        if len(res['rows']) == 0:
            return gone(
                errormsg=gettext("Could not find the specified job step.")
            )

        return ajax_response(
            response=res['rows'][0],
            status=200
        )
Пример #21
0
    def properties(self, gid, sid, did, fid):
        """
        This function will show the properties of the selected foreign data wrapper node.

        Args:
            gid: Server Group ID
            sid: Server ID
            did: Database ID
            fid: foreign data wrapper ID
        """
        sql = render_template("/".join([self.template_path, 'properties.sql']), fid=fid, conn=self.conn)
        status, res = self.conn.execute_dict(sql)

        if not status:
            return internal_server_error(errormsg=res)

        if res['rows'][0]['fdwoptions'] is not None:
            res['rows'][0]['fdwoptions'] = self.tokenize_options(res['rows'][0]['fdwoptions'])

        sql = render_template("/".join([self.template_path, 'acl.sql']), fid=fid)
        status, fdw_acl_res = self.conn.execute_dict(sql)
        if not status:
            return internal_server_error(errormsg=fdw_acl_res)

        for row in fdw_acl_res['rows']:
            privilege = parse_priv_from_db(row)
            if row['deftype'] in res['rows'][0]:
                res['rows'][0][row['deftype']].append(privilege)
            else:
                res['rows'][0][row['deftype']] = [privilege]

        return ajax_response(
            response=res['rows'][0],
            status=200
        )
Пример #22
0
    def sql(self, gid, sid, did, cid):
        """
        This function will generate sql for sql panel
        :param gid: group id
        :param sid: server id
        :param did: database id
        :param cid: cast id
        :return:
        """
        try:
            sql = render_template(
                "/".join([self.template_path, 'sql.sql']),
                cid=cid,
                conn=self.conn
            )
            status, res = self.conn.execute_scalar(sql)
            if not status:
                return internal_server_error(
                    _("Could not generate reversed engineered SQL for the cast.\n\n{0}").format(
                        res
                    )
                )

            if res is None:
                return gone(
                    _("Could not generate reversed engineered SQL for the cast node.\n")
                )

            return ajax_response(response=res)

        except Exception as e:
            return internal_server_error(errormsg=str(e))
Пример #23
0
    def properties(self, gid, sid, did, cid):
        """
        This function will show the properties of the selected cast node
        :param gid: group id
        :param sid: server id
        :param did: database id
        :param cid: cast id
        :return:
        """
        sql = render_template(
            "/".join([self.template_path, 'properties.sql']),
            cid=cid,
            datlastsysoid=self.manager.db_info[did]['datlastsysoid'],
            showsysobj=self.blueprint.show_system_objects
        )
        status, res = self.conn.execute_dict(sql)

        if not status:
            return internal_server_error(errormsg=res)
        result = res['rows'][0]

        return ajax_response(
            response=res['rows'][0],
            status=200
        )
Пример #24
0
    def list(self, gid, sid, did):
        """
        This function is used to list all the schema nodes within the collection.

        Args:
            gid: Server group ID
            sid: Server ID
            did: Database ID

        Returns:
            JSON of available schema nodes
        """
        SQL = render_template(
            "/".join([self.template_path, 'sql/properties.sql']),
            _=gettext,
            show_sysobj=self.blueprint.show_system_objects
        )
        status, res = self.conn.execute_dict(SQL)

        if not status:
            return internal_server_error(errormsg=res)
        return ajax_response(
            response=res['rows'],
            status=200
        )
Пример #25
0
    def dependents(self, gid, sid, did, fid, fsid):
        """
        This function get the dependents and return ajax response
        for the foreign server node.

        Args:
            gid: Server Group ID
            sid: Server ID
            did: Database ID
            fid: foreign data wrapper ID
            fsid: Foreign server ID
        """
        dependents_result = self.get_dependents(self.conn, fsid)

        # Fetching dependents of foreign servers
        query = render_template("/".join([self.template_path, 'dependents.sql']), fsid=fsid)
        status, result = self.conn.execute_dict(query)
        if not status:
            internal_server_error(errormsg=result)

        for row in result['rows']:
            dependents_result.append(
                {'type': 'user_mapping', 'name': row['name'], 'field': 'normal' if (row['deptype'] == 'n') else ''})

        return ajax_response(
            response=dependents_result,
            status=200
        )
Пример #26
0
    def list(self, gid, sid, did):
        """
        This function is used to list all the cast nodes within the collection.
        :param gid: group id
        :param sid: server id
        :param did: database id
        :return:
        """
        sql = render_template(
            "/".join([self.template_path, 'properties.sql']),
            datlastsysoid=self.manager.db_info[did]['datlastsysoid'],
            showsysobj=self.blueprint.show_system_objects
        )
        status, res = self.conn.execute_dict(sql)

        if not status:
            return internal_server_error(errormsg=res)

        for row in res['rows']:
            row['castcontext'] = True if row['castcontext'] == 'IMPLICIT' else False

        return ajax_response(
            response=res['rows'],
            status=200
        )
Пример #27
0
    def exec_sql(self, gid, sid, did, scid, fnid):
        """
        This function returns sql for exec script call.

        Args:
            gid: Server Group Id
            sid: Server Id
            did: Database Id
            scid: Schema Id
            doid: Function Id
        """
        resp_data = self._fetch_properties(gid, sid, did, scid, fnid)

        # Fetch the schema name from OID
        if 'pronamespace' in resp_data:
            resp_data['pronamespace'] = self._get_schema(
                resp_data['pronamespace']
            )

        name = resp_data['pronamespace'] + "." + resp_data['name_with_args']

        # Fetch only arguments
        args = name[name.rfind('('):].strip('(').strip(')').split(',')
        # Remove unwanted spaces from arguments
        args = [arg.strip(' ') for arg in args]

        # Remove duplicate and then format arguments
        for arg in list(set(args)):
            formatted_arg = '\n\t<' + arg + '>'
            name = name.replace(arg, formatted_arg)

        name = name.replace(')', '\n)')
        sql = "EXEC {0}".format(name)

        return ajax_response(response=sql)
Пример #28
0
    def properties(self, gid, sid, did, scid, doid, coid):
        """
        Returns the Domain Constraints property.

        Args:
            gid: Server Group Id
            sid: Server Id
            did: Database Id
            scid: Schema Id
            doid: Domain Id
            coid: Domain Constraint Id
        """

        SQL = render_template("/".join([self.template_path,
                                        'properties.sql']),
                              doid=doid, coid=coid)
        status, res = self.conn.execute_dict(SQL)
        if not status:
            return internal_server_error(errormsg=res)

        data = res['rows'][0]
        return ajax_response(
            response=data,
            status=200
        )
Пример #29
0
    def sql(self, gid, sid, did, scid, tid):
        """
        This function will reverse generate sql for sql panel
        :param gid: group id
        :param sid: server id
        :param did: database id
        :param scid: schema id
        :param tid: fts tempate id
        """
        sql = render_template(
            "/".join([self.template_path, 'sql.sql']),
            tid=tid,
            scid=scid,
            conn=self.conn
        )
        status, res = self.conn.execute_scalar(sql)
        if not status:
            return internal_server_error(
                gettext(
                    "Could not generate reversed engineered query for the "
                    "FTS Template.\n{0}").format(res)
            )

        if res is None:
            return gone(
                gettext(
                    "Could not generate reversed engineered query for "
                    "FTS Template node.")
            )

        return ajax_response(response=res)
Пример #30
0
    def delete_sql(self, gid, sid, did, scid, tid):
        """
        DELETE script sql for the object

        Args:
            gid: Server Group Id
            sid: Server Id
            did: Database Id
            scid: Schema Id
            tid: Table Id

        Returns:
            DELETE Script sql for the object
        """
        SQL = render_template(
            "/".join([self.table_template_path, 'properties.sql']),
            did=did, scid=scid, tid=tid,
            datlastsysoid=self.datlastsysoid
        )
        status, res = self.conn.execute_dict(SQL)
        if not status:
            return internal_server_error(errormsg=res)

        data = res['rows'][0]

        sql = u"DELETE FROM {0}\n\tWHERE <condition>;".format(
            self.qtIdent(self.conn, data['schema'], data['name'])
        )

        return ajax_response(response=sql)
Пример #31
0
    def properties(self, gid, sid, jid, jstid):
        """
        This function will show the properties of the selected job step node.

        Args:
            gid: Server Group ID
            sid: Server ID
            jid: Job ID
            jstid: JobStep ID
        """
        sql = render_template(
            "/".join([self.template_path, 'properties.sql']),
            jstid=jstid,
            jid=jid,
            has_connstr=self.manager.db_info['pgAgent']['has_connstr'])
        status, res = self.conn.execute_dict(sql)

        if not status:
            return internal_server_error(errormsg=res)

        if len(res['rows']) == 0:
            return gone(errormsg="Could not find the specified job step.")

        return ajax_response(response=res['rows'][0], status=200)
Пример #32
0
    def list(self, gid, sid, did, scid, tid):
        """
        This function is used to list all the trigger nodes within that
        collection.

        Args:
            gid: Server group ID
            sid: Server ID
            did: Database ID
            scid: Schema ID
            tid: Table ID

        Returns:
            JSON of available trigger nodes
        """

        SQL = render_template("/".join(
            [self.template_path, self._PROPERTIES_SQL]),
                              tid=tid)
        status, res = self.conn.execute_dict(SQL)

        if not status:
            return internal_server_error(errormsg=res)
        return ajax_response(response=res['rows'], status=200)
Пример #33
0
    def sql(self, gid, sid, did, scid, pid):
        """
        This function will reverse generate sql for sql panel
        :param gid: group id
        :param sid: server id
        :param did: database id
        :param scid: schema id
        :param pid: fts tempate id
        """
        try:
            sql = render_template(
                "/".join([self.template_path, 'sql.sql']),
                pid=pid,
                scid=scid,
                conn=self.conn
            )
            status, res = self.conn.execute_scalar(sql)
            if not status:
                return internal_server_error(
                    _(
                        "Could not generate reversed engineered query for the FTS Parser.\n{0}"
                    ).format(res)
                )

            if res is None:
                return gone(
                    _(
                        "Could not generate reversed engineered query for FTS Parser node"
                    )
                )

            return ajax_response(response=res)

        except Exception as e:
            current_app.logger.exception(e)
            return internal_server_error(errormsg=str(e))
Пример #34
0
    def properties(self, gid, sid, did, scid):
        """
        This function will show the properties of the selected schema node.

        Args:
            gid: Server Group ID
            sid: Server ID
            did:  Database ID
            scid: Schema ID

        Returns:
            JSON of selected schema node
        """
        SQL = render_template("/".join(
            [self.template_path, self._SQL_PREFIX + self._PROPERTIES_SQL]),
                              scid=scid,
                              _=gettext,
                              show_sysobj=self.blueprint.show_system_objects)

        status, res = self.conn.execute_dict(SQL)

        if not status:
            return internal_server_error(errormsg=res)

        if len(res['rows']) == 0:
            return gone(
                gettext("Could not find the schema in the database. "
                        "It may have been removed by another user."))

        # Making copy of output for future use
        copy_data = dict(res['rows'][0])
        copy_data['is_sys_obj'] = (copy_data['oid'] <= self.datlastsysoid
                                   or self.datistemplate)
        copy_data = self._formatter(copy_data, scid)

        return ajax_response(response=copy_data, status=200)
Пример #35
0
    def properties(self, gid, sid, jid, jscid):
        """
        This function will show the properties of the selected language node.

        Args:
            gid: Server Group ID
            sid: Server ID
            jid: Job ID
            jscid: JobSchedule ID
        """
        sql = render_template("/".join(
            [self.template_path, self._PROPERTIES_SQL]),
                              jscid=jscid,
                              jid=jid)
        status, res = self.conn.execute_dict(sql)

        if not status:
            return internal_server_error(errormsg=res)

        if len(res['rows']) == 0:
            return gone(
                errormsg=gettext("Could not find the specified job step."))

        return ajax_response(response=res['rows'][0], status=200)
Пример #36
0
    def properties(self, gid, sid, did, scid, tid, idx):
        """
        This function will show the properties of the selected schema node.

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

        Returns:
            JSON of selected schema node
        """
        status, data = self._fetch_properties(did, tid, idx)
        if not status:
            return data

        return ajax_response(
            response=data,
            status=200
        )
Пример #37
0
    def sql(self, gid, sid, did, scid, foid=None):
        """
        Returns the SQL for the Foreign Table object.

        Args:
            gid: Server Group Id
            sid: Server Id
            did: Database Id
            scid: Schema Id
            foid: Foreign Table Id
        """
        data = self._fetch_properties(gid, sid, did, scid, foid, inherits=True)
        if data == False:
            return gone(
                gettext("Could not find the foreign table on the server."))

        col_data = []
        for c in data['columns']:
            if (not 'inheritedfrom' in c) or (c['inheritedfrom'] is None):
                col_data.append(c)

        data['columns'] = col_data

        SQL = render_template("/".join([self.template_path, 'create.sql']),
                              data=data,
                              is_sql=True)

        sql_header = u"""-- FOREIGN TABLE: {0}

-- DROP FOREIGN TABLE {0};

""".format(self.qtIdent(self.conn, data['basensp'], data['name']))

        SQL = sql_header + SQL

        return ajax_response(response=SQL.strip('\n'))
Пример #38
0
    def properties(self, gid, sid, did, scid, tid, exid=None):
        """
        This function is used to list all the Exclusion constraint
        nodes within that collection.

        Args:
          gid: Server Group ID
          sid: Server ID
          did: Database ID
          scid: Schema ID
          tid: Table ID
          exid: Exclusion constraint ID

        Returns:

        """
        status, res = exclusion_utils.get_exclusion_constraints(
            self.conn, did, tid, exid)
        if not status:
            return res

        if len(res) == 0:
            return gone(_(
                """Could not find the exclusion constraint in the table."""
            ))

        result = res
        if exid:
            result = res[0]
        result['is_sys_obj'] = (
            result['oid'] <= self.datlastsysoid)

        return ajax_response(
            response=result,
            status=200
        )
Пример #39
0
    def list(self, gid, sid, did, scid, tid, exid=None):
        """
        This function returns all exclusion constraints
        nodes within that collection as a http response.

        Args:
          gid: Server Group ID
          sid: Server ID
          did: Database ID
          scid: Schema ID
          tid: Table ID
          exid: Exclusion constraint ID

        Returns:

        """
        try:
            res = self.get_node_list(gid, sid, did, scid, tid, exid)
            return ajax_response(
                response=res,
                status=200
            )
        except Exception as e:
            return internal_server_error(errormsg=str(e))
Пример #40
0
    def sql(self, gid, sid, did, scid, coid):
        """
        This function will generates reverse engineered sql for collation object

         Args:
           gid: Server Group ID
           sid: Server ID
           did: Database ID
           scid: Schema ID
           coid: Collation ID
        """
        SQL = render_template("/".join([self.template_path, 'properties.sql']),
                              scid=scid,
                              coid=coid)
        status, res = self.conn.execute_dict(SQL)
        if not status:
            return internal_server_error(errormsg=res)
        if len(res['rows']) == 0:
            return gone(
                gettext(
                    "Could not find the collation object in the database."))

        data = res['rows'][0]

        SQL = render_template("/".join([self.template_path, 'create.sql']),
                              data=data,
                              conn=self.conn)

        sql_header = u"-- Collation: {0};\n\n-- ".format(data['name'])

        sql_header += render_template("/".join(
            [self.template_path, 'delete.sql']),
                                      name=data['name'])
        SQL = sql_header + '\n\n' + SQL.strip('\n')

        return ajax_response(response=SQL)
Пример #41
0
    def list(self, gid, sid, did, scid):
        """
        This function is used to list all the sequence nodes within the
        collection.

        Args:
          gid: Server Group ID
          sid: Server ID
          did: Database ID
          scid: Schema ID

        Returns:

        """
        SQL = render_template("/".join(
            [self.template_path, self._PROPERTIES_SQL]),
                              scid=scid)
        status, res = self.conn.execute_dict(SQL)

        if not status:
            return internal_server_error(errormsg=res)

        sequence_nodes = self._get_sequence_nodes(res['rows'])
        return ajax_response(response=sequence_nodes, status=200)
Пример #42
0
    def list(self, gid, sid, did, scid):
        """
        This function is used to list all the package nodes within the
        collection.

        Args:
          gid: Server Group ID
          sid: Server ID
          did: Database ID
          scid: Schema ID

        Returns:

        """
        SQL = render_template("/".join([self.template_path, 'properties.sql']),
                              scid=scid)
        status, res = self.conn.execute_dict(SQL)

        if not status:
            return internal_server_error(errormsg=res)
        return ajax_response(
            response=res['rows'],
            status=200
        )
Пример #43
0
    def properties(self, gid, sid, did, scid, coid):
        """
        This function will show the properties of the selected
        catalog objects node.

        Args:
            gid: Server Group ID
            sid: Server ID
            did:  Database ID
            scid: Schema ID
            scid: Schema ID
            coid: Catalog object ID

        Returns:
            JSON of selected catalog objects node
        """
        SQL = render_template(
            "/".join([self.template_path, self._PROPERTIES_SQL]),
            scid=scid, coid=coid
        )
        status, res = self.conn.execute_dict(SQL)

        if not status:
            return internal_server_error(errormsg=res)

        if len(res['rows']) == 0:
            return gone(
                gettext("""Could not find the specified catalog object."""))

        res['rows'][0]['is_sys_obj'] = (
            res['rows'][0]['oid'] <= self.datlastsysoid)

        return ajax_response(
            response=res['rows'][0],
            status=200
        )
Пример #44
0
    def properties(self, gid, sid, rid):

        status, res = self.conn.execute_dict(
            render_template(
                self.sql_path + 'properties.sql',
                rid=rid
            )
        )

        if not status:
            return internal_server_error(
                _(
                    "Error retrieving roles from the database server.\n{0}"
                ).format(res)
            )

        self.transform(res)
        if len(res['rows']) == 0:
            return gone(_("Could not find the role information."))

        return ajax_response(
            response=res['rows'][0],
            status=200
        )
Пример #45
0
    def sql(self, gid, sid, did, eid, json_resp=True):
        """
        This function will generate sql for the sql panel
        """
        SQL = render_template("/".join(
            [self.template_path, self._PROPERTIES_SQL]),
                              eid=eid)
        status, res = self.conn.execute_dict(SQL)
        if not status:
            return internal_server_error(errormsg=res)
        if len(res['rows']) == 0:
            return gone(gettext("Could not find the extension on the server."))

        result = res['rows'][0]

        SQL = render_template("/".join([self.template_path, self._CREATE_SQL]),
                              data=result,
                              conn=self.conn,
                              display_comments=True)

        if not json_resp:
            return SQL

        return ajax_response(response=SQL)
Пример #46
0
    def list(self, gid, sid, did, scid):
        """
        List all FTS Dictionary nodes.

        Args:
            gid: Server Group Id
            sid: Server Id
            did: Database Id
            scid: Schema Id
        """

        sql = render_template("/".join(
            [self.template_path, self._PROPERTIES_SQL]),
                              scid=scid)
        status, res = self.conn.execute_dict(sql)

        if not status:
            return internal_server_error(errormsg=res)

        for row in res['rows']:
            if row['options'] is not None:
                row['options'] = self.tokenize_options(row['options'])

        return ajax_response(response=res['rows'], status=200)
Пример #47
0
    def sql(self, gid, sid, did, cid, json_resp=True):
        """
        This function will generate sql for sql panel
        :param gid: group id
        :param sid: server id
        :param did: database id
        :param cid: cast id
        :param json_resp:
        :return:
        """
        try:
            sql = render_template(
                "/".join([self.template_path, 'sql.sql']),
                cid=cid,
                conn=self.conn
            )

            status, res = self.conn.execute_scalar(sql)
            if not status:
                return internal_server_error(gettext(
                    "Could not generate reversed engineered SQL for the cast."
                ) + "\n\n{0}".format(res))

            if res is None:
                return gone(gettext(
                    "Could not generate reversed engineered SQL for the "
                    "cast node."
                ))

            if not json_resp:
                return res

            return ajax_response(response=res)

        except Exception as e:
            return internal_server_error(errormsg=str(e))
Пример #48
0
    def properties(self, gid, sid, did, scid, tid, cid):
        """
        Returns the Check Constraints property.

        Args:
            gid: Server Group Id
            sid: Server Id
            did: Database Id
            scid: Schema Id
            tid: Check Id
            cid: Check Constraint Id
        """

        SQL = render_template("/".join([self.template_path, 'properties.sql']),
                              tid=tid,
                              cid=cid)
        status, res = self.conn.execute_dict(SQL)
        if not status:
            return internal_server_error(errormsg=res)
        if len(res['rows']) == 0:
            return gone(_("Could not find the object on the server."))

        data = res['rows'][0]
        return ajax_response(response=data, status=200)
Пример #49
0
    def sql(self, gid, sid, did, scid, syid, diff_schema=None, json_resp=True):
        """
        This function will generates reverse engineered sql for synonym object

         Args:
           gid: Server Group ID
           sid: Server ID
           did: Database ID
           scid: Schema ID
           syid: Synonym ID
           diff_schema:
           json_resp:
        """
        SQL = render_template("/".join([self.template_path, 'properties.sql']),
                              scid=scid,
                              syid=syid)
        status, res = self.conn.execute_dict(SQL)
        if not status:
            return internal_server_error(errormsg=res)

        if len(res['rows']) > 0:
            data = res['rows'][0]
        else:
            return gone(gettext('The specified synonym could not be found.'))

        if diff_schema:
            data['schema'] = diff_schema

        SQL = render_template("/".join([self.template_path, 'create.sql']),
                              data=data,
                              conn=self.conn,
                              comment=True)
        if not json_resp:
            return SQL

        return ajax_response(response=SQL)
Пример #50
0
    def properties(self, gid, sid, tsid):
        SQL = render_template(
            "/".join([self.template_path, self._PROPERTIES_SQL]),
            tsid=tsid, conn=self.conn
        )
        status, res = self.conn.execute_dict(SQL)
        if not status:
            return internal_server_error(errormsg=res)

        if len(res['rows']) == 0:
            return gone(
                gettext("""Could not find the tablespace information.""")
            )

        # Making copy of output for future use
        copy_data = dict(res['rows'][0])
        copy_data['is_sys_obj'] = (
            copy_data['oid'] <= self.datlastsysoid or self.datistemplate)
        copy_data = self._formatter(copy_data, tsid)

        return ajax_response(
            response=copy_data,
            status=200
        )
Пример #51
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.datlastsysoid,
            add_not_exists_clause=True)

        return ajax_response(response=SQL)
Пример #52
0
    def properties(self, gid, sid, jid=None):
        SQL = render_template("/".join(
            [self.template_path, self._PROPERTIES_SQL]),
                              jid=jid,
                              conn=self.conn)
        status, rset = self.conn.execute_dict(SQL)

        if not status:
            return internal_server_error(errormsg=rset)

        if jid is not None:
            if len(rset['rows']) != 1:
                return gone(errormsg=_(
                    "Could not find the pgAgent job on the server."))
            res = rset['rows'][0]
            status, rset = self.conn.execute_dict(
                render_template("/".join([self.template_path, 'steps.sql']),
                                jid=jid,
                                conn=self.conn,
                                has_connstr=self.manager.db_info['pgAgent']
                                ['has_connstr']))
            if not status:
                return internal_server_error(errormsg=rset)
            res['jsteps'] = rset['rows']
            status, rset = self.conn.execute_dict(
                render_template("/".join([self.template_path,
                                          'schedules.sql']),
                                jid=jid,
                                conn=self.conn))
            if not status:
                return internal_server_error(errormsg=rset)
            res['jschedules'] = rset['rows']
        else:
            res = rset['rows']

        return ajax_response(response=res, status=200)
Пример #53
0
    def properties(self, gid, sid, did, scid, pkgid, edbfnid=None):
        """
        Returns the Function properties.

        Args:
            gid: Server Group Id
            sid: Server Id
            did: Database Id
            scid: Schema Id
            pkgid: Package Id
            edbfnid: Function Id
        """
        SQL = render_template("/".join([self.sql_template_path,
                                        'properties.sql']),
                              pkgid=pkgid, edbfnid=edbfnid)
        status, res = self.conn.execute_dict(SQL)
        if not status:
            return internal_server_error(errormsg=res)

        if len(res['rows']) == 0:
            return gone(gettext("""
Could not find the function in the database.\n
It may have been removed by another user or moved to another schema.
"""))

        resp_data = res['rows'][0]

        # Get formatted Arguments
        frmtd_params, frmtd_proargs = self._format_arguments_from_db(resp_data)
        resp_data.update(frmtd_params)
        resp_data.update(frmtd_proargs)

        return ajax_response(
            response=resp_data,
            status=200
        )