public inbox for [email protected]  
help / color / mirror / Atom feed
[pgAdmin][PM-4438]: Adding new entries fails when primary key is on any data type and name contains special characters.
4+ messages / 2 participants
[nested] [flat]

* [pgAdmin][PM-4438]: Adding new entries fails when primary key is on any data type and name contains special characters.
@ 2021-03-08 08:38 Nikhil Mohite <[email protected]>
  2021-03-09 08:37 ` Re: [pgAdmin][PM-4438]: Adding new entries fails when primary key is on any data type and name contains special characters. Akshay Joshi <[email protected]>
  0 siblings, 1 reply; 4+ messages in thread

From: Nikhil Mohite @ 2021-03-08 08:38 UTC (permalink / raw)
  To: pgadmin-hackers

Hi Hackers,

Please find the attached patch for RM-4438
<https://redmine.postgresql.org/issues/4438;: Adding new entries fails when
primary key is on any data type and name contains special characters.


-- 
*Thanks & Regards,*
*Nikhil Mohite*
*Software Engineer.*
*EDB Postgres* <https://www.enterprisedb.com/;
*Mob.No: +91-7798364578.*


Attachments:

  [application/octet-stream] RM-4438.patch (670B, 3-RM-4438.patch)
  download | inline diff:
diff --git a/web/pgadmin/tools/sqleditor/utils/save_changed_data.py b/web/pgadmin/tools/sqleditor/utils/save_changed_data.py
index 27d927a6..3997d93b 100644
--- a/web/pgadmin/tools/sqleditor/utils/save_changed_data.py
+++ b/web/pgadmin/tools/sqleditor/utils/save_changed_data.py
@@ -36,6 +36,8 @@ def save_changed_data(changed_data, columns_info, conn, command_obj,
     operations = ('added', 'updated', 'deleted')
     list_of_sql = {}
     _rowid = None
+    # Replace '%' with '%%' as python use '%' as string formatting.
+    command_obj.object_name = command_obj.object_name.replace('%', '%%')
 
     pgadmin_alias = {
         col_name: col_info['pgadmin_alias']


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

* Re: [pgAdmin][PM-4438]: Adding new entries fails when primary key is on any data type and name contains special characters.
  2021-03-08 08:38 [pgAdmin][PM-4438]: Adding new entries fails when primary key is on any data type and name contains special characters. Nikhil Mohite <[email protected]>
@ 2021-03-09 08:37 ` Akshay Joshi <[email protected]>
  2021-03-11 07:43   ` Re: [pgAdmin][PM-4438]: Adding new entries fails when primary key is on any data type and name contains special characters. Nikhil Mohite <[email protected]>
  0 siblings, 1 reply; 4+ messages in thread

From: Akshay Joshi @ 2021-03-09 08:37 UTC (permalink / raw)
  To: Nikhil Mohite <[email protected]>; +Cc: pgadmin-hackers

Thanks, patch applied.

On Mon, Mar 8, 2021 at 2:09 PM Nikhil Mohite <[email protected]>
wrote:

> Hi Hackers,
>
> Please find the attached patch for RM-4438
> <https://redmine.postgresql.org/issues/4438;: Adding new entries fails
> when primary key is on any data type and name contains special characters.
>
>
> --
> *Thanks & Regards,*
> *Nikhil Mohite*
> *Software Engineer.*
> *EDB Postgres* <https://www.enterprisedb.com/;
> *Mob.No: +91-7798364578.*
>


-- 
*Thanks & Regards*
*Akshay Joshi*
*pgAdmin Hacker | Principal Software Architect*
*EDB Postgres <http://edbpostgres.com>*

*Mobile: +91 976-788-8246*


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

* Re: [pgAdmin][PM-4438]: Adding new entries fails when primary key is on any data type and name contains special characters.
  2021-03-08 08:38 [pgAdmin][PM-4438]: Adding new entries fails when primary key is on any data type and name contains special characters. Nikhil Mohite <[email protected]>
  2021-03-09 08:37 ` Re: [pgAdmin][PM-4438]: Adding new entries fails when primary key is on any data type and name contains special characters. Akshay Joshi <[email protected]>
@ 2021-03-11 07:43   ` Nikhil Mohite <[email protected]>
  2021-03-12 08:05     ` Re: [pgAdmin][PM-4438]: Adding new entries fails when primary key is on any data type and name contains special characters. Akshay Joshi <[email protected]>
  0 siblings, 1 reply; 4+ messages in thread

From: Nikhil Mohite @ 2021-03-11 07:43 UTC (permalink / raw)
  To: Akshay Joshi <[email protected]>; +Cc: pgadmin-hackers

Hi Akshay/ Team,

Please find the updated patch for RM-4438.

Regards,
Nikhil Mohite.

On Tue, Mar 9, 2021 at 2:07 PM Akshay Joshi <[email protected]>
wrote:

> Thanks, patch applied.
>
> On Mon, Mar 8, 2021 at 2:09 PM Nikhil Mohite <
> [email protected]> wrote:
>
>> Hi Hackers,
>>
>> Please find the attached patch for RM-4438
>> <https://redmine.postgresql.org/issues/4438;: Adding new entries fails
>> when primary key is on any data type and name contains special characters.
>>
>>
>> --
>> *Thanks & Regards,*
>> *Nikhil Mohite*
>> *Software Engineer.*
>> *EDB Postgres* <https://www.enterprisedb.com/;
>> *Mob.No: +91-7798364578.*
>>
>
>
> --
> *Thanks & Regards*
> *Akshay Joshi*
> *pgAdmin Hacker | Principal Software Architect*
> *EDB Postgres <http://edbpostgres.com>*
>
> *Mobile: +91 976-788-8246*
>


Attachments:

  [application/octet-stream] RM-4438_v2.patch (5.4K, 3-RM-4438_v2.patch)
  download | inline diff:
diff --git a/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/default/delete.sql b/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/default/delete.sql
index a3ca72bb..953c4eeb 100644
--- a/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/default/delete.sql
+++ b/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/default/delete.sql
@@ -10,4 +10,4 @@ DELETE FROM {{ conn|qtIdent(nsp_name, object_name) }}
         ({% for obj in data %}{% if no_of_keys == 1 %}{{ obj[primary_key_labels[0]]|qtLiteral }}{% elif no_of_keys > 1 %}
 {### Here we need to make tuple for each row ###}
 ({% for each_label in primary_key_labels %}{{ obj[each_label]|qtLiteral }}{% if not loop.last %}, {% endif %}{% endfor %}){% endif %}{% if not loop.last %}, {% endif %}
-{% endfor %});
\ No newline at end of file
+{% endfor %});
diff --git a/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/default/insert.sql b/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/default/insert.sql
index a1b35ee8..63af3669 100644
--- a/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/default/insert.sql
+++ b/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/default/insert.sql
@@ -1,10 +1,10 @@
 {# Insert the new row with primary keys (specified in primary_keys) #}
-INSERT INTO {{ conn|qtIdent(nsp_name, object_name) }} (
+INSERT INTO {{ conn|qtIdent(nsp_name, object_name) | replace("%", "%%") }} (
 {% for col in data_to_be_saved %}
-{% if not loop.first %}, {% endif %}{{ conn|qtIdent(col) }}{% endfor %}
+{% if not loop.first %}, {% endif %}{{ conn|qtIdent(col) | replace("%", "%%") }}{% endfor %}
 ) VALUES (
 {% for col in data_to_be_saved %}
 {% if not loop.first %}, {% endif %}%({{ pgadmin_alias[col] }})s{% if type_cast_required[col] %}::{{ data_type[col] }}{% endif %}{% endfor %}
 )
-{% if pk_names and not has_oids %} returning {{pk_names}}{% endif %}
+{% if pk_names and not has_oids %} returning {{pk_names | replace("%", "%%")}}{% endif %}
 {% if has_oids %} returning oid{% endif %};
diff --git a/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/default/select.sql b/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/default/select.sql
index 1bf7428b..a509b4a4 100644
--- a/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/default/select.sql
+++ b/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/default/select.sql
@@ -1,9 +1,9 @@
 {# Select table rows #}
-SELECT {% if has_oids %}oid, {% endif %}* FROM {{ conn|qtIdent(nsp_name, object_name) }}
+SELECT {% if has_oids %}oid, {% endif %}* FROM {{ conn|qtIdent(nsp_name, object_name) | replace("%", "%%") }}
 WHERE
 {% if has_oids %}
   oid = %(oid)s
 {% elif primary_keys|length > 0 %}
   {% for pk in primary_keys %}
-    {% if not loop.first %} AND {% endif %}{{ conn|qtIdent(pk) }} = %({{ pgadmin_alias[pk] }})s{% endfor %}
+    {% if not loop.first %} AND {% endif %}{{ conn|qtIdent(pk) | replace("%", "%%") }} = %({{ pgadmin_alias[pk] }})s{% endfor %}
 {% endif %};
diff --git a/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/default/update.sql b/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/default/update.sql
index b2559fd8..43b0ee7a 100644
--- a/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/default/update.sql
+++ b/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/default/update.sql
@@ -1,7 +1,7 @@
 {# Update the row with primary keys (specified in primary_keys) #}
-UPDATE {{ conn|qtIdent(nsp_name, object_name) }} SET
+UPDATE {{ conn|qtIdent(nsp_name, object_name) | replace("%", "%%") }} SET
 {% for col in data_to_be_saved %}
-{% if not loop.first %}, {% endif %}{{ conn|qtIdent(col) }} = %({{ pgadmin_alias[col] }})s{% if type_cast_required[col] %}::{{ data_type[col] }}{% endif %}{% endfor %}
+{% if not loop.first %}, {% endif %}{{ conn|qtIdent(col) | replace("%", "%%") }} = %({{ pgadmin_alias[col] }})s{% if type_cast_required[col] %}::{{ data_type[col] }}{% endif %}{% endfor %}
  WHERE
 {% for pk in primary_keys %}
-{% if not loop.first %} AND {% endif %}{{ conn|qtIdent(pk) }} = {{ primary_keys[pk]|qtLiteral }}{% endfor %};
+{% if not loop.first %} AND {% endif %}{{ conn|qtIdent(pk) | replace("%", "%%") }} = {{ primary_keys[pk]|qtLiteral }}{% endfor %};
diff --git a/web/pgadmin/tools/sqleditor/utils/save_changed_data.py b/web/pgadmin/tools/sqleditor/utils/save_changed_data.py
index 3997d93b..27d927a6 100644
--- a/web/pgadmin/tools/sqleditor/utils/save_changed_data.py
+++ b/web/pgadmin/tools/sqleditor/utils/save_changed_data.py
@@ -36,8 +36,6 @@ def save_changed_data(changed_data, columns_info, conn, command_obj,
     operations = ('added', 'updated', 'deleted')
     list_of_sql = {}
     _rowid = None
-    # Replace '%' with '%%' as python use '%' as string formatting.
-    command_obj.object_name = command_obj.object_name.replace('%', '%%')
 
     pgadmin_alias = {
         col_name: col_info['pgadmin_alias']
diff --git a/web/pgadmin/utils/driver/psycopg2/connection.py b/web/pgadmin/utils/driver/psycopg2/connection.py
index c90d2439..3b7f3d5b 100644
--- a/web/pgadmin/utils/driver/psycopg2/connection.py
+++ b/web/pgadmin/utils/driver/psycopg2/connection.py
@@ -1970,5 +1970,9 @@ Failed to reset the connection to the server due to following error:
         if not status:
             return None
         else:
-            mogrified_sql = cursor.mogrify(query, parameters)
-            return mogrified_sql
+
+            if parameters:
+                mogrified_sql = cursor.mogrify(query, parameters)
+                return mogrified_sql
+            else:
+                return query


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

* Re: [pgAdmin][PM-4438]: Adding new entries fails when primary key is on any data type and name contains special characters.
  2021-03-08 08:38 [pgAdmin][PM-4438]: Adding new entries fails when primary key is on any data type and name contains special characters. Nikhil Mohite <[email protected]>
  2021-03-09 08:37 ` Re: [pgAdmin][PM-4438]: Adding new entries fails when primary key is on any data type and name contains special characters. Akshay Joshi <[email protected]>
  2021-03-11 07:43   ` Re: [pgAdmin][PM-4438]: Adding new entries fails when primary key is on any data type and name contains special characters. Nikhil Mohite <[email protected]>
@ 2021-03-12 08:05     ` Akshay Joshi <[email protected]>
  0 siblings, 0 replies; 4+ messages in thread

From: Akshay Joshi @ 2021-03-12 08:05 UTC (permalink / raw)
  To: Nikhil Mohite <[email protected]>; +Cc: pgadmin-hackers

Thanks, patch applied.

On Thu, Mar 11, 2021 at 1:13 PM Nikhil Mohite <
[email protected]> wrote:

> Hi Akshay/ Team,
>
> Please find the updated patch for RM-4438.
>
> Regards,
> Nikhil Mohite.
>
> On Tue, Mar 9, 2021 at 2:07 PM Akshay Joshi <[email protected]>
> wrote:
>
>> Thanks, patch applied.
>>
>> On Mon, Mar 8, 2021 at 2:09 PM Nikhil Mohite <
>> [email protected]> wrote:
>>
>>> Hi Hackers,
>>>
>>> Please find the attached patch for RM-4438
>>> <https://redmine.postgresql.org/issues/4438;: Adding new entries fails
>>> when primary key is on any data type and name contains special characters.
>>>
>>>
>>> --
>>> *Thanks & Regards,*
>>> *Nikhil Mohite*
>>> *Software Engineer.*
>>> *EDB Postgres* <https://www.enterprisedb.com/;
>>> *Mob.No: +91-7798364578.*
>>>
>>
>>
>> --
>> *Thanks & Regards*
>> *Akshay Joshi*
>> *pgAdmin Hacker | Principal Software Architect*
>> *EDB Postgres <http://edbpostgres.com>*
>>
>> *Mobile: +91 976-788-8246*
>>
>

-- 
*Thanks & Regards*
*Akshay Joshi*
*pgAdmin Hacker | Principal Software Architect*
*EDB Postgres <http://edbpostgres.com>*

*Mobile: +91 976-788-8246*


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


end of thread, other threads:[~2021-03-12 08:05 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-03-08 08:38 [pgAdmin][PM-4438]: Adding new entries fails when primary key is on any data type and name contains special characters. Nikhil Mohite <[email protected]>
2021-03-09 08:37 ` Akshay Joshi <[email protected]>
2021-03-11 07:43   ` Nikhil Mohite <[email protected]>
2021-03-12 08:05     ` Akshay Joshi <[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