diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py index 013e4dc..a9460dd 100644 --- a/web/pgadmin/tools/sqleditor/__init__.py +++ b/web/pgadmin/tools/sqleditor/__init__.py @@ -1480,19 +1480,24 @@ def query_tool_status(trans_id): if conn and trans_obj and session_obj: status = conn.transaction_status() - # Check for the asynchronous notifies statements. - conn.check_notifies(True) - notifies = conn.get_notifies() + if status is not None: + # Check for the asynchronous notifies statements. + conn.check_notifies(True) + notifies = conn.get_notifies() - return make_json_response( - data={ - 'status': status, - 'message': gettext( - CONNECTION_STATUS_MESSAGE_MAPPING.get(status), - ), - 'notifies': notifies - } - ) + return make_json_response( + data={ + 'status': status, + 'message': gettext( + CONNECTION_STATUS_MESSAGE_MAPPING.get(status), + ), + 'notifies': notifies + } + ) + else: + return internal_server_error( + errormsg=gettext("Transaction status check failed.") + ) else: return internal_server_error( errormsg=gettext("Transaction status check failed.") diff --git a/web/pgadmin/utils/driver/psycopg2/connection.py b/web/pgadmin/utils/driver/psycopg2/connection.py index cfd161a..e8ca886 100644 --- a/web/pgadmin/utils/driver/psycopg2/connection.py +++ b/web/pgadmin/utils/driver/psycopg2/connection.py @@ -51,6 +51,12 @@ else: _ = gettext +# Replace default ascii encoder with unicode-escape +# which translates characters to unicode format. +# Escape special characters to ASCII based on unicode +encodings['SQL_ASCII'] = 'unicode-escape' +encodings['SQLASCII'] = 'unicode-escape' + # Register global type caster which will be applicable to all connections. register_global_typecasters() diff --git a/web/pgadmin/utils/driver/psycopg2/typecast.py b/web/pgadmin/utils/driver/psycopg2/typecast.py index f136604..ccebb2f 100644 --- a/web/pgadmin/utils/driver/psycopg2/typecast.py +++ b/web/pgadmin/utils/driver/psycopg2/typecast.py @@ -164,7 +164,7 @@ def register_global_typecasters(): def register_string_typecasters(connection): - if connection.encoding != 'UTF8': + if connection.encoding not in ('UTF8', 'SQLASCII', 'SQL_ASCII'): # In python3 when database encoding is other than utf-8 and client # encoding is set to UNICODE then we need to map data from database # encoding to utf-8. diff --git a/web/regression/python_test_utils/test_utils.py b/web/regression/python_test_utils/test_utils.py index 3e517b6..163af10 100644 --- a/web/regression/python_test_utils/test_utils.py +++ b/web/regression/python_test_utils/test_utils.py @@ -116,7 +116,7 @@ def clear_node_info_dict(): del node_info_dict[node][:] -def create_database(server, db_name): +def create_database(server, db_name, encoding=None): """This function used to create database and returns the database id""" try: connection = get_db_connection( @@ -130,8 +130,14 @@ def create_database(server, db_name): old_isolation_level = connection.isolation_level connection.set_isolation_level(0) pg_cursor = connection.cursor() - pg_cursor.execute( - '''CREATE DATABASE "%s" TEMPLATE template0''' % db_name) + if encoding is None: + pg_cursor.execute( + '''CREATE DATABASE "%s" TEMPLATE template0''' % db_name) + else: + pg_cursor.execute( + '''CREATE DATABASE "%s" TEMPLATE template0 + ENCODING='%s' LC_COLLATE='%s' LC_CTYPE='%s' ''' % + (db_name, encoding[0], encoding[1], encoding[1])) connection.set_isolation_level(old_isolation_level) connection.commit()