From 88cae263b2e35954bc3a5358b85c279d4b891818 Mon Sep 17 00:00:00 2001 From: Surinder Kumar Date: Fri, 24 Feb 2017 13:39:40 +0000 Subject: [PATCH] Fix display of long integers and decimals. Fixes #2039. Fixes #2119. Fixes #2154 --- .../js/slickgrid/slick.pgadmin.editors.js | 2 +- web/pgadmin/utils/driver/psycopg2/__init__.py | 51 ++++--------------- 2 files changed, 11 insertions(+), 42 deletions(-) diff --git a/web/pgadmin/static/js/slickgrid/slick.pgadmin.editors.js b/web/pgadmin/static/js/slickgrid/slick.pgadmin.editors.js index d1b92cc64..7522c4950 100644 --- a/web/pgadmin/static/js/slickgrid/slick.pgadmin.editors.js +++ b/web/pgadmin/static/js/slickgrid/slick.pgadmin.editors.js @@ -791,7 +791,7 @@ if ($input.val() === "") { return null; } - return parseInt($input.val(), 10) || 0; + return $input.val(); }; this.applyValue = function (item, state) { diff --git a/web/pgadmin/utils/driver/psycopg2/__init__.py b/web/pgadmin/utils/driver/psycopg2/__init__.py index 3390cfe3e..d63a0e11d 100644 --- a/web/pgadmin/utils/driver/psycopg2/__init__.py +++ b/web/pgadmin/utils/driver/psycopg2/__init__.py @@ -50,50 +50,20 @@ psycopg2.extensions.register_type( psycopg2.extensions.UNICODE) ) -# Cast bytea fields to text. By default, this will render as hex strings with -# Postgres 9+ and as escaped binary in earlier versions. -psycopg2.extensions.register_type( - psycopg2.extensions.new_type((17,), 'BYTEA_TEXT', psycopg2.STRING) -) - -# This registers a type caster for datatype 'NaN'. -psycopg2.extensions.register_type( - psycopg2.extensions.new_type((701,), 'NaN_TEXT', psycopg2.STRING) -) - -# This registers a type caster for datatype 'interval'. -psycopg2.extensions.register_type( - psycopg2.extensions.new_type((1186,), 'INTERVAL_TEXT', psycopg2.STRING) -) - -# This registers a type caster for int4range, int8range, numrange -# tsrange, tstzrange, daterange +# This registers a type caster to convert various pg types into string type psycopg2.extensions.register_type( psycopg2.extensions.new_type( - (3904, 3926, 3906, 3908, 3910, 3912), - 'NUMERIC_RANGE_TEXT', psycopg2.STRING) + ( + # To cast bytea and interval type + 17, 1186, + # to cast int4range, int8range, numrange tsrange, tstzrange + 3904,3926, 3906, 3908, 3910, 3912, + # date, timestamp, timestamptz, bigint, double precision + 1700, 1082, 1114, 1184, 20, 701 + ), + 'TYPECAST_TO_STRING', psycopg2.STRING) ) -def register_string_typecasters(connection): - """ - Casts various types to string, resolving issues with out of - range dates (e.g. BC) and rounded numbers which psycopg2 can't - handle - """ - - def return_as_string(value, cursor): - return value - - cursor = connection.cursor() - cursor.execute('SELECT NULL::date, NULL::timestamp, NULL::timestamptz, NULL::bigint') - # Oid(s): Date, timestamp, timestamptz, bigint, double precision - oids = ( - cursor.description[0][1], cursor.description[1][1], - cursor.description[2][1], cursor.description[3][1] - ) - new_type = psycopg2.extensions.new_type(oids, 'RETURN_STRING', return_as_string) - psycopg2.extensions.register_type(new_type) - class Connection(BaseConnection): """ class Connection(object) @@ -367,7 +337,6 @@ Failed to connect to the database server(#{server_id}) for connection ({conn_id} self.conn.autocommit = False else: self.conn.autocommit = True - register_string_typecasters(self.conn) status = _execute(cur, """ SET DateStyle=ISO;