mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fixed an issue where adding/updating records fails if the table name contains percent sign.
refs #4438
This commit is contained in:
parent
408df750be
commit
68132e2a8f
@ -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 %}
|
({% 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 ###}
|
{### 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 %}
|
({% for each_label in primary_key_labels %}{{ obj[each_label]|qtLiteral }}{% if not loop.last %}, {% endif %}{% endfor %}){% endif %}{% if not loop.last %}, {% endif %}
|
||||||
{% endfor %});
|
{% endfor %});
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
{# Insert the new row with primary keys (specified in primary_keys) #}
|
{# 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 %}
|
{% 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 (
|
) VALUES (
|
||||||
{% for col in data_to_be_saved %}
|
{% 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 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 %};
|
{% if has_oids %} returning oid{% endif %};
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
{# Select table rows #}
|
{# 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
|
WHERE
|
||||||
{% if has_oids %}
|
{% if has_oids %}
|
||||||
oid = %(oid)s
|
oid = %(oid)s
|
||||||
{% elif primary_keys|length > 0 %}
|
{% elif primary_keys|length > 0 %}
|
||||||
{% for pk in primary_keys %}
|
{% 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 %};
|
{% endif %};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{# Update the row with primary keys (specified in primary_keys) #}
|
{# 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 %}
|
{% 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
|
WHERE
|
||||||
{% for pk in primary_keys %}
|
{% 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 %};
|
||||||
|
@ -36,8 +36,6 @@ def save_changed_data(changed_data, columns_info, conn, command_obj,
|
|||||||
operations = ('added', 'updated', 'deleted')
|
operations = ('added', 'updated', 'deleted')
|
||||||
list_of_sql = {}
|
list_of_sql = {}
|
||||||
_rowid = None
|
_rowid = None
|
||||||
# Replace '%' with '%%' as python use '%' as string formatting.
|
|
||||||
command_obj.object_name = command_obj.object_name.replace('%', '%%')
|
|
||||||
|
|
||||||
pgadmin_alias = {
|
pgadmin_alias = {
|
||||||
col_name: col_info['pgadmin_alias']
|
col_name: col_info['pgadmin_alias']
|
||||||
|
@ -1970,5 +1970,9 @@ Failed to reset the connection to the server due to following error:
|
|||||||
if not status:
|
if not status:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
mogrified_sql = cursor.mogrify(query, parameters)
|
|
||||||
return mogrified_sql
|
if parameters:
|
||||||
|
mogrified_sql = cursor.mogrify(query, parameters)
|
||||||
|
return mogrified_sql
|
||||||
|
else:
|
||||||
|
return query
|
||||||
|
Loading…
Reference in New Issue
Block a user