public inbox for [email protected]
help / color / mirror / Atom feedFrom: Akshay Joshi <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin4][Patch]: RM 4393 Edit users with parameters 'all' gives error while saving
Date: Thu, 4 Jul 2019 13:59:22 +0530
Message-ID: <CANxoLDd2xz-H-KDaHq-S58n1P1c=mfq7i92shfcFdNfYtGD4Wg@mail.gmail.com> (raw)
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 + "\""
view thread (2+ 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]
Subject: Re: [pgAdmin4][Patch]: RM 4393 Edit users with parameters 'all' gives error while saving
In-Reply-To: <CANxoLDd2xz-H-KDaHq-S58n1P1c=mfq7i92shfcFdNfYtGD4Wg@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