public inbox for [email protected]  
help / color / mirror / Atom feed
[pgAdmin4][Patch]: RM 4393 Edit users with parameters 'all' gives error while saving
2+ messages / 2 participants
[nested] [flat]

* [pgAdmin4][Patch]: RM 4393 Edit users with parameters 'all' gives error while saving
@ 2019-07-04 08:29  Akshay Joshi <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Akshay Joshi @ 2019-07-04 08:29 UTC (permalink / raw)
  To: pgadmin-hackers

Hi Hackers,

Attached is the patch to fix RM #4393 Edit users with parameters 'all'
gives error while saving. Apart from that I have modified the function
qtIdent, qtTypeIdent and qtLiteral to handle integer value.

Please review it

-- 
*Thanks & Regards*
*Akshay Joshi*

*Sr. Software Architect*
*EnterpriseDB Software India Private Limited*
*Mobile: +91 976-788-8246*


Attachments:

  [application/octet-stream] RM_4393.patch (4.0K, 3-RM_4393.patch)
  download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/default/get_position.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/default/get_position.sql
index cea57210..6a900faf 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/default/get_position.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/default/get_position.sql
@@ -1,4 +1,4 @@
 SELECT att.attnum
 FROM pg_attribute att
     WHERE att.attrelid = {{tid}}::oid
-    AND att.attname = {{data.name|qtLiteral}}
+    AND att.attname = {{data.name|qtLiteral(True)}}
diff --git a/web/pgadmin/browser/server_groups/servers/templates/macros/variable.macros b/web/pgadmin/browser/server_groups/servers/templates/macros/variable.macros
index 385f9727..173a0ca7 100644
--- a/web/pgadmin/browser/server_groups/servers/templates/macros/variable.macros
+++ b/web/pgadmin/browser/server_groups/servers/templates/macros/variable.macros
@@ -4,7 +4,7 @@
 {% macro APPLY(conn, database, role, param, value) -%}
 ALTER {% if role %}ROLE {{ self.conn|qtIdent(role) }}{% if database %} IN DATABASE {{ conn|qtIdent(database) }}{% endif %}{% else %}DATABASE {{ conn|qtIdent(database) }}{% endif %}
 
-    SET {{ conn|qtIdent(param) }} TO {{ value }};
+    SET {{ conn|qtIdent(param) }} TO {{ value|qtLiteral }};
 {%- endmacro %}
 {% macro RESET(conn, database, role, param) -%}
 ALTER {% if role %}ROLE {{ self.conn|qtIdent(role) }}{% if database %} IN DATABASE {{ conn|qtIdent(database) }}{% endif %}{% else %}DATABASE {{ conn|qtIdent(database) }}{% endif %}
diff --git a/web/pgadmin/utils/driver/psycopg2/__init__.py b/web/pgadmin/utils/driver/psycopg2/__init__.py
index 60a3bb2b..4b3e2204 100644
--- a/web/pgadmin/utils/driver/psycopg2/__init__.py
+++ b/web/pgadmin/utils/driver/psycopg2/__init__.py
@@ -228,7 +228,7 @@ class Driver(BaseDriver):
                 mgr.release()
 
     @staticmethod
-    def qtLiteral(value):
+    def qtLiteral(value, forceQuote=False):
         adapted = adapt(value)
 
         # Not all adapted objects have encoding
@@ -242,7 +242,14 @@ class Driver(BaseDriver):
         res = adapted.getquoted()
 
         if isinstance(res, bytes):
-            return res.decode('utf-8')
+            res = res.decode('utf-8')
+
+        if forceQuote is True:
+            # Convert the input to the string to use the startsWith(...)
+            res = str(res)
+            if not res.startswith("'"):
+                return "'" + res + "'"
+
         return res
 
     @staticmethod
@@ -343,6 +350,10 @@ class Driver(BaseDriver):
         value = None
 
         for val in args:
+            # DataType doesn't have len function then convert it to string
+            if not hasattr(val, '__len__'):
+                val = str(val)
+
             if len(val) == 0:
                 continue
             if hasattr(str, 'decode') and not isinstance(val, unicode):
@@ -354,7 +365,7 @@ class Driver(BaseDriver):
                     val = str(val).decode('utf-8')
             value = val
 
-            if (Driver.needsQuoting(val, True)):
+            if Driver.needsQuoting(val, True):
                 value = value.replace("\"", "\"\"")
                 value = "\"" + value + "\""
 
@@ -372,6 +383,11 @@ class Driver(BaseDriver):
         for val in args:
             if type(val) == list:
                 return map(lambda w: Driver.qtIdent(conn, w), val)
+
+            # DataType doesn't have len function then convert it to string
+            if not hasattr(val, '__len__'):
+                val = str(val)
+
             if hasattr(str, 'decode') and not isinstance(val, unicode):
                 # Handling for python2
                 try:
@@ -385,7 +401,7 @@ class Driver(BaseDriver):
 
             value = val
 
-            if (Driver.needsQuoting(val, False)):
+            if Driver.needsQuoting(val, False):
                 value = value.replace("\"", "\"\"")
                 value = "\"" + value + "\""
 


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: [pgAdmin4][Patch]: RM 4393 Edit users with parameters 'all' gives error while saving
@ 2019-07-04 14:00  Dave Page <[email protected]>
  parent: Akshay Joshi <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Dave Page @ 2019-07-04 14:00 UTC (permalink / raw)
  To: Akshay Joshi <[email protected]>; +Cc: pgadmin-hackers

Thanks, committed.

On Thu, Jul 4, 2019 at 9:29 AM Akshay Joshi <[email protected]>
wrote:

> Hi Hackers,
>
> Attached is the patch to fix RM #4393 Edit users with parameters 'all'
> gives error while saving. Apart from that I have modified the function
> qtIdent, qtTypeIdent and qtLiteral to handle integer value.
>
> Please review it
>
> --
> *Thanks & Regards*
> *Akshay Joshi*
>
> *Sr. Software Architect*
> *EnterpriseDB Software India Private Limited*
> *Mobile: +91 976-788-8246*
>


-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2019-07-04 14:00 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-07-04 08:29 [pgAdmin4][Patch]: RM 4393 Edit users with parameters 'all' gives error while saving Akshay Joshi <[email protected]>
2019-07-04 14:00 ` Dave Page <[email protected]>

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