mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fixed an issue where a decimal number is appended for character varying fields while downloading the data in CSV format. Fixes #6520
This commit is contained in:
parent
b9b0a573e5
commit
e3190b86ab
@ -35,3 +35,4 @@ Bug fixes
|
|||||||
| `Issue #6478 <https://redmine.postgresql.org/issues/6478>`_ - Fixed duplicate SQL issue for tables with more than one partition.
|
| `Issue #6478 <https://redmine.postgresql.org/issues/6478>`_ - Fixed duplicate SQL issue for tables with more than one partition.
|
||||||
| `Issue #6482 <https://redmine.postgresql.org/issues/6482>`_ - Fixed an issue where the Foreground Color property of server dialog does not work.
|
| `Issue #6482 <https://redmine.postgresql.org/issues/6482>`_ - Fixed an issue where the Foreground Color property of server dialog does not work.
|
||||||
| `Issue #6513 <https://redmine.postgresql.org/issues/6513>`_ - Fixed an issue where pgAdmin does not open after password reset in server mode.
|
| `Issue #6513 <https://redmine.postgresql.org/issues/6513>`_ - Fixed an issue where pgAdmin does not open after password reset in server mode.
|
||||||
|
| `Issue #6520 <https://redmine.postgresql.org/issues/6520>`_ - Fixed an issue where a decimal number is appended for character varying fields while downloading the data in CSV format.
|
||||||
|
@ -1357,7 +1357,8 @@ def start_query_download_tool(trans_id):
|
|||||||
try:
|
try:
|
||||||
|
|
||||||
# This returns generator of records.
|
# This returns generator of records.
|
||||||
status, gen = sync_conn.execute_on_server_as_csv(records=2000)
|
status, gen, conn_obj = \
|
||||||
|
sync_conn.execute_on_server_as_csv(records=2000)
|
||||||
|
|
||||||
if not status:
|
if not status:
|
||||||
return make_json_response(
|
return make_json_response(
|
||||||
@ -1367,13 +1368,13 @@ def start_query_download_tool(trans_id):
|
|||||||
)
|
)
|
||||||
|
|
||||||
r = Response(
|
r = Response(
|
||||||
gen(
|
gen(conn_obj,
|
||||||
trans_obj,
|
trans_obj,
|
||||||
quote=blueprint.csv_quoting.get(),
|
quote=blueprint.csv_quoting.get(),
|
||||||
quote_char=blueprint.csv_quote_char.get(),
|
quote_char=blueprint.csv_quote_char.get(),
|
||||||
field_separator=blueprint.csv_field_separator.get(),
|
field_separator=blueprint.csv_field_separator.get(),
|
||||||
replace_nulls_with=blueprint.replace_nulls_with.get()
|
replace_nulls_with=blueprint.replace_nulls_with.get()
|
||||||
),
|
),
|
||||||
mimetype='text/csv' if
|
mimetype='text/csv' if
|
||||||
blueprint.csv_field_separator.get() == ','
|
blueprint.csv_field_separator.get() == ','
|
||||||
else 'text/plain'
|
else 'text/plain'
|
||||||
|
@ -879,7 +879,7 @@ WHERE db.datname = current_database()""")
|
|||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def gen(trans_obj, quote='strings', quote_char="'",
|
def gen(conn_obj, trans_obj, quote='strings', quote_char="'",
|
||||||
field_separator=',', replace_nulls_with=None):
|
field_separator=',', replace_nulls_with=None):
|
||||||
|
|
||||||
cur.scroll(0, mode='absolute')
|
cur.scroll(0, mode='absolute')
|
||||||
@ -889,7 +889,7 @@ WHERE db.datname = current_database()""")
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Type cast the numeric values
|
# Type cast the numeric values
|
||||||
results = numeric_typecasters(results)
|
results = numeric_typecasters(results, conn_obj)
|
||||||
|
|
||||||
header = []
|
header = []
|
||||||
json_columns = []
|
json_columns = []
|
||||||
@ -958,7 +958,7 @@ WHERE db.datname = current_database()""")
|
|||||||
# Registering back type caster for large size data types to string
|
# Registering back type caster for large size data types to string
|
||||||
# which was unregistered at starting
|
# which was unregistered at starting
|
||||||
register_string_typecasters(self.conn)
|
register_string_typecasters(self.conn)
|
||||||
return True, gen
|
return True, gen, self
|
||||||
|
|
||||||
def execute_scalar(self, query, params=None,
|
def execute_scalar(self, query, params=None,
|
||||||
formatted_exception_msg=False):
|
formatted_exception_msg=False):
|
||||||
|
@ -198,25 +198,21 @@ def register_string_typecasters(connection):
|
|||||||
psycopg2.extensions.register_type(unicode_array_type, connection)
|
psycopg2.extensions.register_type(unicode_array_type, connection)
|
||||||
|
|
||||||
|
|
||||||
def is_numeric(val):
|
def numeric_typecasters(results, conn_obj):
|
||||||
"""Check if value is numeric or not"""
|
|
||||||
try:
|
|
||||||
if '.' in val:
|
|
||||||
float(val)
|
|
||||||
else:
|
|
||||||
int(val)
|
|
||||||
except ValueError:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def numeric_typecasters(results):
|
|
||||||
# This function is to convert pg types to numeic type caster
|
# This function is to convert pg types to numeic type caster
|
||||||
|
|
||||||
|
data = []
|
||||||
|
for obj_type in conn_obj.column_info:
|
||||||
|
if obj_type['type_code'] in TO_STRING_NUMERIC_DATATYPES:
|
||||||
|
data.append(obj_type['name'])
|
||||||
|
|
||||||
for result in results:
|
for result in results:
|
||||||
for key, value in result.items():
|
for key, value in result.items():
|
||||||
if isinstance(result[key], str) and is_numeric(result[key]):
|
if isinstance(result[key],
|
||||||
|
str) and key in data and not value.isdigit():
|
||||||
result[key] = float(result[key])
|
result[key] = float(result[key])
|
||||||
|
elif isinstance(result[key], str) and key in data:
|
||||||
|
result[key] = int(result[key])
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user