Fixed an issue where adding/updating records fails if the table name contains percent sign.

refs #4438
This commit is contained in:
Nikhil Mohite 2021-03-12 11:59:45 +05:30 committed by Akshay Joshi
parent 408df750be
commit 68132e2a8f
6 changed files with 15 additions and 13 deletions

View File

@ -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 %};

View File

@ -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 %};

View File

@ -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 %};

View File

@ -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']

View File

@ -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