public inbox for [email protected]
help / color / mirror / Atom feedFrom: Nikhil Mohite <[email protected]>
To: Akshay Joshi <[email protected]>
Cc: pgadmin-hackers <[email protected]>
Subject: Re: [pgAdmin][PM-4438]: Adding new entries fails when primary key is on any data type and name contains special characters.
Date: Thu, 11 Mar 2021 13:13:05 +0530
Message-ID: <CAOBg0ANExhGv_dNJrP2MpN9DTgrqkTe18v7Lr_pyEb8bHyGR_Q@mail.gmail.com> (raw)
In-Reply-To: <CANxoLDcoHex7D0HxqH2FfG9MfEu_91c0taiockFGYRFTOkBe-Q@mail.gmail.com>
References: <CAOBg0AOPctXQiwRZ3O0rAKgymh-Kn50+RccYSucPxANBiAu_YA@mail.gmail.com>
<CANxoLDcoHex7D0HxqH2FfG9MfEu_91c0taiockFGYRFTOkBe-Q@mail.gmail.com>
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
view thread (4+ 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: [pgAdmin][PM-4438]: Adding new entries fails when primary key is on any data type and name contains special characters.
In-Reply-To: <CAOBg0ANExhGv_dNJrP2MpN9DTgrqkTe18v7Lr_pyEb8bHyGR_Q@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