Hi, Please find attached patch to handle bytea and bytea[] data in datagrid.
Now instead of showing actual data we can show placeholders like <binary data> and <binary data[]>. Also placeholders will only appear if data actually exists otherwise null will be shown. -- *Harshal Dhumal* *Sr. Software Engineer* EnterpriseDB India: http://www.enterprisedb.com The Enterprise PostgreSQL Company
diff --git a/web/pgadmin/feature_tests/pg_datatype_validation_test.py b/web/pgadmin/feature_tests/pg_datatype_validation_test.py index 26c787b..7bedde8 100644 --- a/web/pgadmin/feature_tests/pg_datatype_validation_test.py +++ b/web/pgadmin/feature_tests/pg_datatype_validation_test.py @@ -101,7 +101,7 @@ class PGDataypeFeatureTest(BaseFeatureTest): '922337203685.922337203685', '-92233720368547758.08', '{1,2,3}', '{NaN,NaN,NaN}', 'Infinity', '{Infinity}', - r'\336\255\276\357', r'{"\\336\\255\\276\\357","\\336\\255\\276\\357"}' + r'<binary data>', r'<binary data[]>' ] self.page.open_query_tool() diff --git a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js index 8a797ab..bf29a39 100644 --- a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js +++ b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js @@ -578,6 +578,7 @@ define([ name: c.label, display_name: c.display_name, column_type: c.column_type, + column_type_internal: c.column_type_internal, not_null: c.not_null, has_default_val: c.has_default_val }; @@ -744,6 +745,11 @@ define([ // Listener function which will be called before user updates existing cell // This will be used to collect primary key for that row grid.onBeforeEditCell.subscribe(function (e, args) { + if (args.column.column_type_internal == 'bytea' || + args.column.column_type_internal == 'bytea[]') { + return false; + } + var before_data = args.item; // If newly added row is saved but grid is not refreshed, @@ -2000,9 +2006,9 @@ define([ pg_types[pg_types.length - 1][0] : 'unknown'; if (!is_primary_key) - col_type += ' ' + type; + col_type += type; else - col_type += ' [PK] ' + type; + col_type += '[PK] ' + type; if (c.precision && c.precision >= 0 && c.precision != 65535) { col_type += ' (' + c.precision; @@ -2051,6 +2057,7 @@ define([ 'name': c.name, 'display_name': c.display_name, 'column_type': col_type, + 'column_type_internal': type, 'pos': c.pos, 'label': column_label, 'cell': col_cell, diff --git a/web/pgadmin/utils/driver/psycopg2/__init__.py b/web/pgadmin/utils/driver/psycopg2/__init__.py index 8a20521..7510f80 100644 --- a/web/pgadmin/utils/driver/psycopg2/__init__.py +++ b/web/pgadmin/utils/driver/psycopg2/__init__.py @@ -60,8 +60,8 @@ psycopg2.extensions.register_type( psycopg2.extensions.register_type( psycopg2.extensions.new_type( ( - # To cast bytea, bytea[] and interval type - 17, 1001, 1186, + # To cast interval type + 1186, # to cast int4range, int8range, numrange tsrange, tstzrange, # daterange @@ -76,6 +76,28 @@ psycopg2.extensions.register_type( 'TYPECAST_TO_STRING', psycopg2.STRING) ) +psycopg2.extensions.register_type( + psycopg2.extensions.new_type( + ( + # To cast bytea type + 17, + ), + 'BYTEA_PLACEHOLDER', + # Only show placeholder if data actually exists. + lambda value, cursor: '<binary data>' if value is not None else None) +) + +psycopg2.extensions.register_type( + psycopg2.extensions.new_type( + ( + # To cast bytea[] type + 1001, + ), + 'BYTEA_ARRAY_PLACEHOLDER', + # Only show placeholder if data actually exists. + lambda value, cursor: '<binary data[]>' if value is not None else None) +) + def register_string_typecasters(connection): if connection.encoding != 'UTF8':