public inbox for [email protected]  
help / color / mirror / Atom feed
From: Aditya Toshniwal <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin4][RM#3289] Can't query SQL_ASCII database.
Date: Tue, 22 May 2018 11:35:32 +0530
Message-ID: <CAM9w-_ntCUguZp2rVJXPsDvWJbWneAz4-AHJoYB+nUTSYMXc9g@mail.gmail.com> (raw)

Hi Hackers,

PFA patch for RM#3289 where decode error was thrown on querying a SQL_ASCII
database table. Please note, this problem occurs only on windows.
Sample insert - insert into test_tab values ('é');

psycopg2 has a encodings dictionary where Postgres Database Encodings are
mapped to python equivalent. It uses 'ascii' decoder of python to decode
for SQL_ASCII encoding. If data has characters beyond the limit of ascii
then it failed. The solution would be to use utf_8 decoder instead of
ascii. I tried setting the client_encoding using
set_client_encoding('UTF8') method of a psycopg2 connection but no luck
(also its not allowed for async connection). I also tried executing "SET
CLIENT_ENCODING='UTF8'" but it didn't work too.
So, as in the patch, I had to set encodings dict value directly to 'utf_8'
and it seems to be working. Please note, the same is added to psycopg3
milestones
https://github.com/psycopg/psycopg2/milestone/4

Also fixed a small glitch for sql editor connection status check.

Kindly review.

Thanks and Regards,
Aditya Toshniwal
Software Engineer | EnterpriseDB Software Solutions | Pune
"Don't Complain about Heat, Plant a tree"


Attachments:

  [application/octet-stream] RM3289.patch (1.1K, 3-RM3289.patch)
  download | inline diff:
diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py
index c72505a4..aec3faba 100644
--- a/web/pgadmin/tools/sqleditor/__init__.py
+++ b/web/pgadmin/tools/sqleditor/__init__.py
@@ -1474,7 +1474,7 @@ def query_tool_status(trans_id):
             errormsg=error_msg
         )
 
-    if conn and trans_obj and session_obj:
+    if conn and trans_obj and session_obj and conn.transaction_status() is not None:
         status = conn.transaction_status()
         return make_json_response(
             data={
diff --git a/web/pgadmin/utils/driver/psycopg2/connection.py b/web/pgadmin/utils/driver/psycopg2/connection.py
index 315631c0..ea90e62f 100644
--- a/web/pgadmin/utils/driver/psycopg2/connection.py
+++ b/web/pgadmin/utils/driver/psycopg2/connection.py
@@ -49,6 +49,9 @@ else:
 
 _ = gettext
 
+# Use utf_8 decoder instead of ascii for SQL_ASCII database to avoid decode errors
+encodings['SQL_ASCII'] = 'utf_8'
+encodings['SQLASCII'] = 'utf_8'
 
 # Register global type caster which will be applicable to all connections.
 register_global_typecasters()


view thread (38+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: [pgAdmin4][RM#3289] Can't query SQL_ASCII database.
  In-Reply-To: <CAM9w-_ntCUguZp2rVJXPsDvWJbWneAz4-AHJoYB+nUTSYMXc9g@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox