public inbox for [email protected]  
help / color / mirror / Atom feed
From: Murtuza Zabuawala <[email protected]>
To: Dave Page <[email protected]>
Cc: pgadmin-hackers <[email protected]>
Subject: Re: PATCH: To fix issue in synonym node (pgAdmin4)
Date: Wed, 5 Oct 2016 17:58:11 +0530
Message-ID: <CAKKotZSayUMYQgQh-An0FnL7hA_U7ybhfDsJYr=nEMMKw03v5A@mail.gmail.com> (raw)
In-Reply-To: <CA+OCxoxyyyQkTPvGsg69U-MMrgZyaY+_e07ngF2DXe=9QFREEQ@mail.gmail.com>
References: <CAKKotZT8huV=9w7vy_8MWyUa1J6GCJ3-830HbB3LJeQVGJT3-A@mail.gmail.com>
	<CA+OCxoxyyyQkTPvGsg69U-MMrgZyaY+_e07ngF2DXe=9QFREEQ@mail.gmail.com>
List-Unsubscribe:  <mailto:[email protected]?body=unsub%20pgadmin-hackers>

Hi Dave,

PFA updated patch, Added schema filter in sql.
Please review.

--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

On Wed, Oct 5, 2016 at 5:38 PM, Dave Page <[email protected]> wrote:

> Hi
>
> On Wed, Oct 5, 2016 at 9:53 AM, Murtuza Zabuawala
> <[email protected]> wrote:
> > Hi,
> >
> > PFA patch to fix the issue in synonym node, where it was not horning
> parent
> > node while creating in different node, issue was that we were not sending
> > node properly.
> > RM#1611
>
> That doesn't seem like a reliable way to get the correct parent ID -
> what if there are multiple synonyms in different schemas but with the
> same name?
>
> --
> Dave Page
> Blog: http://pgsnake.blogspot.com
> Twitter: @pgsnake
>
> EnterpriseDB UK: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers


Attachments:

  [application/octet-stream] RM_1611_v1.patch (3.6K, 3-RM_1611_v1.patch)
  download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/__init__.py
index 95e58b6..97df5f5 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/__init__.py
@@ -391,10 +391,18 @@ class SynonymView(PGChildNodeView):
             if not status:
                 return internal_server_error(errormsg=res)
 
+            # Find parent oid to add properly in tree browser
+            SQL = render_template("/".join([self.template_path,
+                                            'get_parent_oid.sql']),
+                                  data=data, conn=self.conn)
+            status, parent_id = self.conn.execute_scalar(SQL)
+            if not status:
+                return internal_server_error(errormsg=res)
+
             return jsonify(
                 node=self.blueprint.generate_browser_node(
                     data['name'],
-                    scid,
+                    int(parent_id),
                     data['name'],
                     icon="icon-synonym"
                 )
@@ -483,25 +491,14 @@ class SynonymView(PGChildNodeView):
                 if not status:
                     return internal_server_error(errormsg=res)
 
-                return make_json_response(
-                    success=1,
-                    info="Synonym updated",
-                    data={
-                        'id': syid,
-                        'scid': scid,
-                        'did': did
-                    }
-                )
-            else:
-                return make_json_response(
-                    success=1,
-                    info="Nothing to update",
-                    data={
-                        'id': syid,
-                        'scid': scid,
-                        'did': did
-                    }
+            return jsonify(
+                node=self.blueprint.generate_browser_node(
+                    syid,
+                    scid,
+                    syid,
+                    icon="icon-synonym"
                 )
+            )
 
         except Exception as e:
             return internal_server_error(errormsg=str(e))
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/templates/synonym/sql/9.1_plus/get_parent_oid.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/templates/synonym/sql/9.1_plus/get_parent_oid.sql
new file mode 100644
index 0000000..08f07e0
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/templates/synonym/sql/9.1_plus/get_parent_oid.sql
@@ -0,0 +1,5 @@
+SELECT synnamespace as scid
+    FROM pg_synonym s
+WHERE synname = {{ data.name|qtLiteral }}
+AND synnamespace IN
+    ( SELECT oid FROM pg_namespace WHERE nspname = {{ data.schema|qtLiteral }} );
\ No newline at end of file
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/templates/synonym/sql/9.5_plus/get_parent_oid.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/templates/synonym/sql/9.5_plus/get_parent_oid.sql
new file mode 100644
index 0000000..08f07e0
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/templates/synonym/sql/9.5_plus/get_parent_oid.sql
@@ -0,0 +1,5 @@
+SELECT synnamespace as scid
+    FROM pg_synonym s
+WHERE synname = {{ data.name|qtLiteral }}
+AND synnamespace IN
+    ( SELECT oid FROM pg_namespace WHERE nspname = {{ data.schema|qtLiteral }} );
\ No newline at end of file


view thread (6+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: PATCH: To fix issue in synonym node (pgAdmin4)
  In-Reply-To: <CAKKotZSayUMYQgQh-An0FnL7hA_U7ybhfDsJYr=nEMMKw03v5A@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox