From e3dfe03a2a6839e510137960bea69b684f4f4b9d Mon Sep 17 00:00:00 2001 From: Yogesh Mahajan Date: Thu, 6 Aug 2020 12:30:10 +0530 Subject: [PATCH] Fixed an issue where the user is not able to insert the data if the table and columns name contains special characters. Fixes #4387 --- docs/en_US/release_notes_4_25.rst | 1 + web/pgadmin/tools/sqleditor/static/js/sqleditor.js | 2 +- .../sqleditor/templates/sqleditor/sql/default/select.sql | 2 +- .../tools/sqleditor/tests/test_view_data_templates.py | 2 ++ web/pgadmin/tools/sqleditor/utils/save_changed_data.py | 7 ++++++- 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/en_US/release_notes_4_25.rst b/docs/en_US/release_notes_4_25.rst index f41e554a7..640a9e17e 100644 --- a/docs/en_US/release_notes_4_25.rst +++ b/docs/en_US/release_notes_4_25.rst @@ -24,6 +24,7 @@ Bug fixes ********* | `Issue #3767 `_ - Ensure that the original file format should be retained when saving the same file in SQL editor. +| `Issue #4387 `_ - Fixed an issue where the user is not able to insert the data if the table and columns name contains special characters. | `Issue #4810 `_ - Fixed an issue where the user is not able to save the new row if the table is empty. | `Issue #5429 `_ - Ensure that the Dictionaries drop-down shows all the dictionaries in the FTS configuration dialog. | `Issue #5490 `_ - Make the runtime configuration dialog non-modal. diff --git a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js index 61e1f9cf4..b2081b97e 100644 --- a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js +++ b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js @@ -786,7 +786,7 @@ define('tools.querytool', [ c.column_type = _.escape(c.column_type); var options = { - id: c.name, + id: _.escape(c.name), pos: c.pos, field: c.name, name: c.label, 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 97329cd32..1bf7428b6 100644 --- a/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/default/select.sql +++ b/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/default/select.sql @@ -5,5 +5,5 @@ WHERE oid = %(oid)s {% elif primary_keys|length > 0 %} {% for pk in primary_keys %} - {% if not loop.first %} AND {% endif %}{{ conn|qtIdent(pk) }} = %({{ pk }})s{% endfor %} + {% if not loop.first %} AND {% endif %}{{ conn|qtIdent(pk) }} = %({{ pgadmin_alias[pk] }})s{% endfor %} {% endif %}; diff --git a/web/pgadmin/tools/sqleditor/tests/test_view_data_templates.py b/web/pgadmin/tools/sqleditor/tests/test_view_data_templates.py index 1e927593a..217079d9c 100644 --- a/web/pgadmin/tools/sqleditor/tests/test_view_data_templates.py +++ b/web/pgadmin/tools/sqleditor/tests/test_view_data_templates.py @@ -54,6 +54,7 @@ class TestViewDataTemplates(BaseTestGenerator): select_template_path='sqleditor/sql/default/select.sql', select_parameters=dict( object_name='test_table', + pgadmin_alias=pgadmin_alias, nsp_name='test_schema', primary_keys=OrderedDict([('id', 'int4')]), has_oids=False @@ -87,6 +88,7 @@ class TestViewDataTemplates(BaseTestGenerator): select_parameters=dict( object_name='test_table', nsp_name='test_schema', + pgadmin_alias=pgadmin_alias, primary_keys=OrderedDict([('id', 'int4'), ('text', 'text')]), has_oids=False diff --git a/web/pgadmin/tools/sqleditor/utils/save_changed_data.py b/web/pgadmin/tools/sqleditor/utils/save_changed_data.py index bc30b1395..525095997 100644 --- a/web/pgadmin/tools/sqleditor/utils/save_changed_data.py +++ b/web/pgadmin/tools/sqleditor/utils/save_changed_data.py @@ -138,6 +138,7 @@ def save_changed_data(changed_data, columns_info, conn, command_obj, "/".join([command_obj.sql_path, 'select.sql']), object_name=command_obj.object_name, nsp_name=command_obj.nsp_name, + pgadmin_alias=pgadmin_alias, primary_keys=primary_keys, has_oids=command_obj.has_oids() ) @@ -279,8 +280,12 @@ def save_changed_data(changed_data, columns_info, conn, command_obj, # Select added row from the table if 'select_sql' in item: + params = { + pgadmin_alias[k] if k in pgadmin_alias else k: v + for k, v in res['rows'][0].items() + } status, sel_res = conn.execute_dict( - item['select_sql'], res['rows'][0]) + item['select_sql'], params) if not status: return failure_handle(sel_res, item.get('row_id', 0))