public inbox for [email protected]  
help / color / mirror / Atom feed
PATCH: Encoding issue with qtLiteral function (pgAdmin4)
16+ messages / 2 participants
[nested] [flat]

* PATCH: Encoding issue with qtLiteral function (pgAdmin4)
@ 2016-07-22 14:11 Murtuza Zabuawala <[email protected]>
  2016-07-22 15:50 ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  0 siblings, 1 reply; 16+ messages in thread

From: Murtuza Zabuawala @ 2016-07-22 14:11 UTC (permalink / raw)
  To: pgadmin-hackers

Hi,

PFA patch to fix the issue when we use qtLiteral function and user enters
special characters(like emojis) which it fails to handle.
RM#1307


--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers


Attachments:

  [application/octet-stream] RM_1307.patch (1.4K, 3-RM_1307.patch)
  download | inline diff:
diff --git a/requirements_py2.txt b/requirements_py2.txt
index b205323..83ac8d3 100644
--- a/requirements_py2.txt
+++ b/requirements_py2.txt
@@ -21,7 +21,7 @@ linecache2==1.0.0
 MarkupSafe==0.23
 passlib==1.6.2
 pbr==1.9.1
-psycopg2==2.5.2
+psycopg2==2.6.2
 pycrypto==2.6.1
 pyrsistent==0.11.13
 python-dateutil==2.5.0
diff --git a/requirements_py3.txt b/requirements_py3.txt
index 463f79e..ad6fa02 100644
--- a/requirements_py3.txt
+++ b/requirements_py3.txt
@@ -20,7 +20,7 @@ linecache2==1.0.0
 MarkupSafe==0.23
 passlib==1.6.2
 pbr==1.9.1
-psycopg2==2.5.2
+psycopg2==2.6.2
 pycrypto==2.6.1
 pyrsistent==0.11.13
 python-dateutil==2.5.0
diff --git a/web/pgadmin/utils/driver/psycopg2/__init__.py b/web/pgadmin/utils/driver/psycopg2/__init__.py
index 7b901d4..9c76959 100644
--- a/web/pgadmin/utils/driver/psycopg2/__init__.py
+++ b/web/pgadmin/utils/driver/psycopg2/__init__.py
@@ -1564,9 +1564,13 @@ class Driver(BaseDriver):
 
     @staticmethod
     def qtLiteral(value):
-
-        res = adapt(value).getquoted()
-
+        try:
+            res = adapt(value).getquoted()
+        except UnicodeEncodeError:
+            # We will handle special charcters with utf8 encoding
+            adapted = adapt(value)
+            adapted.encoding = 'utf8'
+            res = adapted.getquoted()
         # Returns in bytes, we need to convert it in string
         if isinstance(res, bytes):
             return res.decode()


^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4)
  2016-07-22 14:11 PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
@ 2016-07-22 15:50 ` Dave Page <[email protected]>
  2016-07-25 06:19   ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  0 siblings, 1 reply; 16+ messages in thread

From: Dave Page @ 2016-07-22 15:50 UTC (permalink / raw)
  To: Murtuza Zabuawala <[email protected]>; +Cc: pgadmin-hackers

Hi

On Fri, Jul 22, 2016 at 3:11 PM, Murtuza Zabuawala
<[email protected]> wrote:
> Hi,
>
> PFA patch to fix the issue when we use qtLiteral function and user enters
> special characters(like emojis) which it fails to handle.
> RM#1307

It still seems to be broken to me. For example, if I try to set a
comment on a table to 😬, I get the following error:

2016-07-22 16:47:49,526: INFO werkzeug: 127.0.0.1 - - [22/Jul/2016
16:47:49] "GET /browser/table/msql/1/1/17251/2200/17267?id=17267&description=%F0%9F%98%AC+&columns=%7B%22changed%22%3A%5B%7B%22attlen%22%3Anull%7D%2C%7B%22attlen%22%3Anull%7D%2C%7B%22attlen%22%3Anull%7D%2C%7B%22attlen%22%3Anull%7D%2C%7B%22attlen%22%3Anull%7D%5D%7D&_=1469202363116
HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
line 2000, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
line 1991, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
line 1567, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/views.py",
line 84, in view
    return self.dispatch_request(*args, **kwargs)
  File "/Users/dpage/git/pgadmin4/web/pgadmin/browser/utils.py", line
235, in dispatch_request
    return method(*args, **kwargs)
  File "/Users/dpage/git/pgadmin4/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py",
line 276, in wrap
    self.conn = self.manager.connection(did=kwargs['did'])
  File "/Users/dpage/git/pgadmin4/web/pgadmin/utils/driver/psycopg2/__init__.py",
line 1278, in connection
    raise Exception(msg_active_conn)
Exception: Server has no active connection. Please connect to the server.


-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4)
  2016-07-22 14:11 PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-22 15:50 ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
@ 2016-07-25 06:19   ` Murtuza Zabuawala <[email protected]>
  2016-07-25 11:31     ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  0 siblings, 1 reply; 16+ messages in thread

From: Murtuza Zabuawala @ 2016-07-25 06:19 UTC (permalink / raw)
  To: Dave Page <[email protected]>; +Cc: pgadmin-hackers

Hi Dave,

I'm not able to re-produce the issue on my side (PFA screenshot), and from
exception log you mentioned it looks like connection to database issue
rather than encoding.
Would you please try & test one more time?


Regards,
Murtuza

--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

On Fri, Jul 22, 2016 at 9:20 PM, Dave Page <[email protected]> wrote:

> Hi
>
> On Fri, Jul 22, 2016 at 3:11 PM, Murtuza Zabuawala
> <[email protected]> wrote:
> > Hi,
> >
> > PFA patch to fix the issue when we use qtLiteral function and user enters
> > special characters(like emojis) which it fails to handle.
> > RM#1307
>
> It still seems to be broken to me. For example, if I try to set a
> comment on a table to 😬, I get the following error:
>
> 2016-07-22 16:47:49,526: INFO werkzeug: 127.0.0.1 - - [22/Jul/2016
> 16:47:49] "GET
> /browser/table/msql/1/1/17251/2200/17267?id=17267&description=%F0%9F%98%AC+&columns=%7B%22changed%22%3A%5B%7B%22attlen%22%3Anull%7D%2C%7B%22attlen%22%3Anull%7D%2C%7B%22attlen%22%3Anull%7D%2C%7B%22attlen%22%3Anull%7D%2C%7B%22attlen%22%3Anull%7D%5D%7D&_=1469202363116
> HTTP/1.1" 500 -
> Traceback (most recent call last):
>   File
> "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
> line 2000, in __call__
>     return self.wsgi_app(environ, start_response)
>   File
> "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
> line 1991, in wsgi_app
>     response = self.make_response(self.handle_exception(e))
>   File
> "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
> line 1567, in handle_exception
>     reraise(exc_type, exc_value, tb)
>   File
> "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
> line 1988, in wsgi_app
>     response = self.full_dispatch_request()
>   File
> "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
> line 1641, in full_dispatch_request
>     rv = self.handle_user_exception(e)
>   File
> "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
> line 1544, in handle_user_exception
>     reraise(exc_type, exc_value, tb)
>   File
> "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
> line 1639, in full_dispatch_request
>     rv = self.dispatch_request()
>   File
> "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
> line 1625, in dispatch_request
>     return self.view_functions[rule.endpoint](**req.view_args)
>   File
> "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/views.py",
> line 84, in view
>     return self.dispatch_request(*args, **kwargs)
>   File "/Users/dpage/git/pgadmin4/web/pgadmin/browser/utils.py", line
> 235, in dispatch_request
>     return method(*args, **kwargs)
>   File
> "/Users/dpage/git/pgadmin4/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py",
> line 276, in wrap
>     self.conn = self.manager.connection(did=kwargs['did'])
>   File
> "/Users/dpage/git/pgadmin4/web/pgadmin/utils/driver/psycopg2/__init__.py",
> line 1278, in connection
>     raise Exception(msg_active_conn)
> Exception: Server has no active connection. Please connect to the server.
>
>
> --
> Dave Page
> Blog: http://pgsnake.blogspot.com
> Twitter: @pgsnake
>
> EnterpriseDB UK: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers


Attachments:

  [image/jpeg] test_emoji.jpg (118.3K, 3-test_emoji.jpg)
  download | view image

^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4)
  2016-07-22 14:11 PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-22 15:50 ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-25 06:19   ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
@ 2016-07-25 11:31     ` Dave Page <[email protected]>
  2016-07-26 13:34       ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  0 siblings, 1 reply; 16+ messages in thread

From: Dave Page @ 2016-07-25 11:31 UTC (permalink / raw)
  To: Murtuza Zabuawala <[email protected]>; +Cc: pgadmin-hackers

Hi

Whenever I connect to my primary test server I get the following in the
console, and see the attached error:

2016-07-25 12:22:56,684: INFO pgadmin: Connection Request for server#1
2016-07-25 12:22:56,688: ERROR pgadmin: 'ascii' codec can't decode byte
0x8f in position 0: ordinal not in range(128)
Traceback (most recent call last):
  File
"/Users/dpage/git/pgadmin4/web/pgadmin/browser/server_groups/servers/__init__.py",
line 785, in connect
    server_types=ServerType.types()
  File
"/Users/dpage/git/pgadmin4/web/pgadmin/utils/driver/psycopg2/__init__.py",
line 250, in connect
    password = password.decode()
UnicodeDecodeError: 'ascii' codec can't decode byte 0x8f in position 0:
ordinal not in range(128)

I can no longer connect to that server even without the patch, following
the testing I did on your patch last week.

To make everythign work again, I had to drop the SQLite database. If I then
try to add an emojii to the comment for the server (with your patch), I get:

2016-07-25 12:29:36,930: INFO werkzeug: 127.0.0.1 - - [25/Jul/2016
12:29:36] "PUT /browser/server/obj/1/1 HTTP/1.1" 500 -
Traceback (most recent call last):
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
line 2000, in __call__
    return self.wsgi_app(environ, start_response)
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
line 1991, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
line 1567, in handle_exception
    reraise(exc_type, exc_value, tb)
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/views.py",
line 84, in view
    return self.dispatch_request(*args, **kwargs)
  File "/Users/dpage/git/pgadmin4/web/pgadmin/browser/utils.py", line 235,
in dispatch_request
    return method(*args, **kwargs)
  File
"/Users/dpage/git/pgadmin4/web/pgadmin/browser/server_groups/servers/__init__.py",
line 403, in update
    data = request.form if request.form else
json.loads(request.data.decode())
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf0 in position 119:
ordinal not in range(128)


On Mon, Jul 25, 2016 at 7:19 AM, Murtuza Zabuawala <
[email protected]> wrote:

> Hi Dave,
>
> I'm not able to re-produce the issue on my side (PFA screenshot), and from
> exception log you mentioned it looks like connection to database issue
> rather than encoding.
> Would you please try & test one more time?
>
>
> Regards,
> Murtuza
>
> --
> Regards,
> Murtuza Zabuawala
> EnterpriseDB: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>
> On Fri, Jul 22, 2016 at 9:20 PM, Dave Page <[email protected]> wrote:
>
>> Hi
>>
>> On Fri, Jul 22, 2016 at 3:11 PM, Murtuza Zabuawala
>> <[email protected]> wrote:
>> > Hi,
>> >
>> > PFA patch to fix the issue when we use qtLiteral function and user
>> enters
>> > special characters(like emojis) which it fails to handle.
>> > RM#1307
>>
>> It still seems to be broken to me. For example, if I try to set a
>> comment on a table to 😬, I get the following error:
>>
>> 2016-07-22 16:47:49,526: INFO werkzeug: 127.0.0.1 - - [22/Jul/2016
>> 16:47:49] "GET
>> /browser/table/msql/1/1/17251/2200/17267?id=17267&description=%F0%9F%98%AC+&columns=%7B%22changed%22%3A%5B%7B%22attlen%22%3Anull%7D%2C%7B%22attlen%22%3Anull%7D%2C%7B%22attlen%22%3Anull%7D%2C%7B%22attlen%22%3Anull%7D%2C%7B%22attlen%22%3Anull%7D%5D%7D&_=1469202363116
>> HTTP/1.1" 500 -
>> Traceback (most recent call last):
>>   File
>> "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
>> line 2000, in __call__
>>     return self.wsgi_app(environ, start_response)
>>   File
>> "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
>> line 1991, in wsgi_app
>>     response = self.make_response(self.handle_exception(e))
>>   File
>> "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
>> line 1567, in handle_exception
>>     reraise(exc_type, exc_value, tb)
>>   File
>> "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
>> line 1988, in wsgi_app
>>     response = self.full_dispatch_request()
>>   File
>> "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
>> line 1641, in full_dispatch_request
>>     rv = self.handle_user_exception(e)
>>   File
>> "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
>> line 1544, in handle_user_exception
>>     reraise(exc_type, exc_value, tb)
>>   File
>> "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
>> line 1639, in full_dispatch_request
>>     rv = self.dispatch_request()
>>   File
>> "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/app.py",
>> line 1625, in dispatch_request
>>     return self.view_functions[rule.endpoint](**req.view_args)
>>   File
>> "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/flask/views.py",
>> line 84, in view
>>     return self.dispatch_request(*args, **kwargs)
>>   File "/Users/dpage/git/pgadmin4/web/pgadmin/browser/utils.py", line
>> 235, in dispatch_request
>>     return method(*args, **kwargs)
>>   File
>> "/Users/dpage/git/pgadmin4/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py",
>> line 276, in wrap
>>     self.conn = self.manager.connection(did=kwargs['did'])
>>   File
>> "/Users/dpage/git/pgadmin4/web/pgadmin/utils/driver/psycopg2/__init__.py",
>> line 1278, in connection
>>     raise Exception(msg_active_conn)
>> Exception: Server has no active connection. Please connect to the server.
>>
>>
>> --
>> Dave Page
>> Blog: http://pgsnake.blogspot.com
>> Twitter: @pgsnake
>>
>> EnterpriseDB UK: http://www.enterprisedb.com
>> The Enterprise PostgreSQL Company
>>
>
>


-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers


Attachments:

  [image/png] Screen Shot 2016-07-25 at 12.23.47.png (622.0K, 3-Screen%20Shot%202016-07-25%20at%2012.23.47.png)
  download | view image

^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4)
  2016-07-22 14:11 PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-22 15:50 ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-25 06:19   ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-25 11:31     ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
@ 2016-07-26 13:34       ` Murtuza Zabuawala <[email protected]>
  2016-07-26 14:06         ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  0 siblings, 1 reply; 16+ messages in thread

From: Murtuza Zabuawala @ 2016-07-26 13:34 UTC (permalink / raw)
  To: Dave Page <[email protected]>; +Cc: pgadmin-hackers

Hi Dave,

PFA updated patch to fix encoding issue, I have tested in Python2/3 and
looks like working in both environment.

Almost all nodes are affected with this change, I tried to test & cover all
basic operations on nodes but still it requires some testing.

This patch will cover below tickets,
RM#1307
RM#1479

Please review.

--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers


Attachments:

  [application/octet-stream] Fix_encoding_all_nodes.patch (103.3K, 3-Fix_encoding_all_nodes.patch)
  download | inline diff:
diff --git a/requirements_py2.txt b/requirements_py2.txt
index 3d0d700..4d6c03a 100644
--- a/requirements_py2.txt
+++ b/requirements_py2.txt
@@ -21,7 +21,7 @@ linecache2==1.0.0
 MarkupSafe==0.23
 passlib==1.6.2
 pbr==1.9.1
-psycopg2==2.5.2
+psycopg2==2.6.2
 pycrypto==2.6.1
 pyrsistent==0.11.13
 python-dateutil==2.5.0
diff --git a/requirements_py3.txt b/requirements_py3.txt
index 1f3ab95..462ed19 100644
--- a/requirements_py3.txt
+++ b/requirements_py3.txt
@@ -20,7 +20,7 @@ linecache2==1.0.0
 MarkupSafe==0.23
 passlib==1.6.2
 pbr==1.9.1
-psycopg2==2.5.2
+psycopg2==2.6.2
 pycrypto==2.6.1
 pyrsistent==0.11.13
 python-dateutil==2.5.0
diff --git a/web/pgadmin/__init__.py b/web/pgadmin/__init__.py
index fe9e69c..d4c174a 100644
--- a/web/pgadmin/__init__.py
+++ b/web/pgadmin/__init__.py
@@ -147,7 +147,7 @@ def create_app(app_name=config.APP_NAME):
     logger.setLevel(logging.INFO)
 
     # File logging
-    fh = logging.FileHandler(config.LOG_FILE)
+    fh = logging.FileHandler(config.LOG_FILE, encoding='utf-8')
     fh.setLevel(config.FILE_LOG_LEVEL)
     fh.setFormatter(logging.Formatter(config.FILE_LOG_FORMAT))
     app.logger.addHandler(fh)
diff --git a/web/pgadmin/browser/server_groups/__init__.py b/web/pgadmin/browser/server_groups/__init__.py
index 97d261f..faff488 100644
--- a/web/pgadmin/browser/server_groups/__init__.py
+++ b/web/pgadmin/browser/server_groups/__init__.py
@@ -8,7 +8,7 @@
 ##########################################################################
 """Defines views for management of server groups"""
 
-import json
+import simplejson as json
 from abc import ABCMeta, abstractmethod
 
 import six
@@ -156,7 +156,9 @@ class ServerGroupView(NodeView):
             user_id=current_user.id,
             id=gid).first()
 
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
 
         if servergroup is None:
             return make_json_response(
@@ -201,7 +203,10 @@ class ServerGroupView(NodeView):
             )
 
     def create(self):
-        data = request.form if request.form else json.loads(request.data.decode())
+        """Creates new server-group """
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
         if data[u'name'] != '':
             try:
                 check_sg = ServerGroup.query.filter_by(
diff --git a/web/pgadmin/browser/server_groups/servers/__init__.py b/web/pgadmin/browser/server_groups/servers/__init__.py
index 6290158..5128e74 100644
--- a/web/pgadmin/browser/server_groups/servers/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/__init__.py
@@ -7,7 +7,7 @@
 #
 ##########################################################################
 
-import json
+import simplejson as json
 import traceback
 
 import pgadmin.browser.server_groups as sg
@@ -400,7 +400,9 @@ class ServerNode(PGChildNodeView):
         }
 
         idx = 0
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
 
         from pgadmin.utils.driver import get_driver
         manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
@@ -554,7 +556,9 @@ class ServerNode(PGChildNodeView):
             u'role'
         ]
 
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
 
         for arg in required_args:
             if arg not in data:
@@ -740,8 +744,9 @@ class ServerNode(PGChildNodeView):
         if user is None:
             return unauthorized(gettext("Unauthorized request."))
 
-        data = request.form if request.form else json.loads(request.data) if \
-            request.data else {}
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        ) if request.data else {}
 
         password = None
         save_password = False
@@ -969,7 +974,7 @@ class ServerNode(PGChildNodeView):
             sid: Server id
         """
         try:
-            data = json.loads(request.form['data'])
+            data = json.loads(request.form['data'], encoding='utf-8')
             if data and ('password' not in data or
                                  data['password'] == '' or
                                  'newPassword' not in data or
diff --git a/web/pgadmin/browser/server_groups/servers/databases/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/__init__.py
index 1b7882d..a7100c5 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/__init__.py
@@ -9,7 +9,7 @@
 
 """Implements the Database Node"""
 
-import json
+import simplejson as json
 import re
 from functools import wraps
 
@@ -186,11 +186,12 @@ class DatabaseView(PGChildNodeView):
             return internal_server_error(errormsg=rset)
 
         for row in rset['rows']:
-            if self.manager.db == row['name']:
+            dbname = row['name']
+            if self.manager.db == dbname:
                 connected = True
                 canDrop = canDisConn = False
             else:
-                conn = self.manager.connection(row['name'])
+                conn = self.manager.connection(dbname)
                 connected = conn.connected()
                 canDrop = canDisConn = True
 
@@ -441,7 +442,9 @@ class DatabaseView(PGChildNodeView):
             u'name'
         ]
 
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
 
         for arg in required_args:
             if arg not in data:
@@ -516,7 +519,7 @@ class DatabaseView(PGChildNodeView):
         """Update the database."""
 
         data = request.form if request.form else json.loads(
-            request.data.decode()
+            request.data, encoding='utf-8'
         )
         info = "nothing to update."
 
@@ -633,7 +636,7 @@ class DatabaseView(PGChildNodeView):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
         try:
@@ -705,7 +708,7 @@ class DatabaseView(PGChildNodeView):
             acls = render_template(
                 "/".join([self.template_path, 'allowed_privs.json'])
             )
-            acls = json.loads(acls)
+            acls = json.loads(acls, encoding='utf-8')
         except Exception as e:
             current_app.logger.exception(e)
 
@@ -738,7 +741,7 @@ class DatabaseView(PGChildNodeView):
             acls = render_template(
                 "/".join([self.template_path, 'allowed_privs.json'])
             )
-            acls = json.loads(acls)
+            acls = json.loads(acls, encoding='utf-8')
         except Exception as e:
             current_app.logger.exception(e)
 
@@ -861,17 +864,20 @@ class DatabaseView(PGChildNodeView):
         frmtd_variables = parse_variables_from_db(res1['rows'])
         result.update(frmtd_variables)
 
-        sql_header = """
--- Database: {0}
+        sql_header = "-- Database: {0}\n\n-- ".format(result['name'])
+        if hasattr(str, 'decode'):
+            sql_header = sql_header.decode('utf-8')
 
--- DROP DATABASE {0};
-
-""".format(result['name'])
+        sql_header += render_template(
+            "/".join([self.template_path, 'delete.sql']),
+            datname=result['name'], conn=self.conn
+        )
 
         SQL = self.get_new_sql(gid, sid, result, did)
         SQL = re.sub('\n{2,}', '\n\n', SQL)
-        SQL = sql_header + SQL
+        SQL = sql_header + '\n' + SQL
         SQL = SQL.strip('\n')
+
         return ajax_response(response=SQL)
 
     @check_precondition()
diff --git a/web/pgadmin/browser/server_groups/servers/databases/casts/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/casts/__init__.py
index f159a05..92ccaab 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/casts/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/casts/__init__.py
@@ -9,7 +9,7 @@
 
 """Implements Cast Node"""
 
-import json
+import simplejson as json
 from functools import wraps
 
 import pgadmin.browser.server_groups.servers.databases as databases
@@ -345,7 +345,9 @@ class CastView(PGChildNodeView):
             'trgtyp'
         ]
 
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
         for arg in required_args:
             if arg not in data:
                 return make_json_response(
@@ -396,7 +398,9 @@ class CastView(PGChildNodeView):
         :param gid: group id
         :return:
         """
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
         sql = self.get_sql(gid, sid, did, data, cid)
         try:
             if sql and sql.strip('\n') and sql.strip(' '):
@@ -549,7 +553,10 @@ class CastView(PGChildNodeView):
         :return:
         """
         res = []
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
+
         sql = render_template("/".join([self.template_path, 'functions.sql']),
                               srctyp=data['srctyp'],
                               trgtyp=data['trgtyp'])
diff --git a/web/pgadmin/browser/server_groups/servers/databases/event_triggers/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/event_triggers/__init__.py
index f429356..6e39c93 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/event_triggers/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/event_triggers/__init__.py
@@ -7,7 +7,7 @@
 #
 ##########################################################################
 
-import json
+import simplejson as json
 import re
 from functools import wraps
 
@@ -327,7 +327,10 @@ class EventTriggerView(PGChildNodeView):
         Returns:
 
         """
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
+
         required_args = {
             'name': 'Name',
             'eventowner': 'Owner',
@@ -390,7 +393,9 @@ class EventTriggerView(PGChildNodeView):
         Returns:
 
         """
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
 
         try:
             sql = self.get_sql(data, etid)
@@ -489,7 +494,7 @@ class EventTriggerView(PGChildNodeView):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
         try:
@@ -590,6 +595,8 @@ class EventTriggerView(PGChildNodeView):
                 return internal_server_error(errormsg=db_name)
 
             sql_header = "-- Event Trigger: {0} on database {1}\n\n-- ".format(result['name'], db_name)
+            if hasattr(str, 'decode'):
+                sql_header = sql_header.decode('utf-8')
 
             sql_header += render_template(
                 "/".join([self.template_path, 'delete.sql']),
diff --git a/web/pgadmin/browser/server_groups/servers/databases/extensions/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/extensions/__init__.py
index f4c1e9e..b7c5a78 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/extensions/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/extensions/__init__.py
@@ -9,7 +9,7 @@
 
 """ Implements Extension Node """
 
-import json
+import simplejson as json
 from functools import wraps
 
 import pgadmin.browser.server_groups.servers.databases as databases
@@ -216,8 +216,10 @@ class ExtensionView(PGChildNodeView):
             'name'
         ]
 
-        data = request.form if request.form else \
-            json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
+
         for arg in required_args:
             if arg not in data:
                 return make_json_response(
@@ -263,8 +265,9 @@ class ExtensionView(PGChildNodeView):
         """
         This function will update an extension object
         """
-        data = request.form if request.form else \
-            json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
         SQL = self.getSQL(gid, sid, data, did, eid)
 
         try:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/__init__.py
index d8481eb..e2fac1e 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/__init__.py
@@ -9,7 +9,7 @@
 
 """Implements Foreign Data Wrapper Node"""
 
-import json
+import simplejson as json
 from functools import wraps
 
 import pgadmin.browser.server_groups.servers as servers
@@ -355,7 +355,9 @@ class ForeignDataWrapperView(PGChildNodeView):
             'name'
         ]
 
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
         for arg in required_args:
             if arg not in data:
                 return make_json_response(
@@ -422,7 +424,9 @@ class ForeignDataWrapperView(PGChildNodeView):
             did: Database ID
             fid: foreign data wrapper ID
         """
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
         sql = self.get_sql(gid, sid, data, did, fid)
         try:
             if sql and sql.strip('\n') and sql.strip(' '):
@@ -513,7 +517,7 @@ class ForeignDataWrapperView(PGChildNodeView):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
@@ -666,6 +670,9 @@ class ForeignDataWrapperView(PGChildNodeView):
 
 """.format(res['rows'][0]['name'])
 
+        if hasattr(str, 'decode'):
+            sql_header = sql_header.decode('utf-8')
+
         sql = sql_header + sql
 
         return ajax_response(response=sql)
diff --git a/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/__init__.py
index e4c71df..00d5242 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/__init__.py
@@ -9,7 +9,7 @@
 
 """Implements Foreign Server Node"""
 
-import json
+import simplejson as json
 from functools import wraps
 
 import pgadmin.browser.server_groups.servers.databases as databases
@@ -356,7 +356,9 @@ class ForeignServerView(PGChildNodeView):
             'name'
         ]
 
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
         for arg in required_args:
             if arg not in data:
                 return make_json_response(
@@ -428,7 +430,9 @@ class ForeignServerView(PGChildNodeView):
             fsid: foreign server ID
         """
 
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
         sql = self.get_sql(gid, sid, data, did, fid, fsid)
         try:
             if sql and sql.strip('\n') and sql.strip(' '):
@@ -526,7 +530,7 @@ class ForeignServerView(PGChildNodeView):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
@@ -703,6 +707,8 @@ class ForeignServerView(PGChildNodeView):
 -- DROP SERVER {0}
 
 """.format(res['rows'][0]['name'])
+        if hasattr(str, 'decode'):
+            sql_header = sql_header.decode('utf-8')
 
         sql = sql_header + sql
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/user_mapping/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/user_mapping/__init__.py
index eac0659..b0d4f3c 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/user_mapping/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/user_mapping/__init__.py
@@ -9,7 +9,7 @@
 
 """Implements User Mapping Node"""
 
-import json
+import simplejson as json
 from functools import wraps
 
 import pgadmin.browser.server_groups.servers as servers
@@ -361,7 +361,9 @@ class UserMappingView(PGChildNodeView):
             'name'
         ]
 
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
         for arg in required_args:
             if arg not in data:
                 return make_json_response(
@@ -435,7 +437,9 @@ class UserMappingView(PGChildNodeView):
             umid: User mapping ID
         """
 
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
         sql = self.get_sql(gid, sid, data, did, fid, fsid, umid)
         try:
             if sql and sql.strip('\n') and sql.strip(' '):
@@ -546,7 +550,7 @@ class UserMappingView(PGChildNodeView):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
@@ -706,6 +710,8 @@ class UserMappingView(PGChildNodeView):
 -- DROP USER MAPPING FOR {0} SERVER {1}
 
 """.format(res['rows'][0]['name'], fdw_data['name'])
+        if hasattr(str, 'decode'):
+            sql_header = sql_header.decode('utf-8')
 
         sql = sql_header + sql
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/languages/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/languages/__init__.py
index 47ef5fe..07c04e9 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/languages/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/languages/__init__.py
@@ -9,7 +9,7 @@
 
 """Implements Language Node"""
 
-import json
+import simplejson as json
 from functools import wraps
 
 import pgadmin.browser.server_groups.servers.databases as databases
@@ -354,7 +354,9 @@ class LanguageView(PGChildNodeView):
             did: Database ID
             lid: Language ID
         """
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
         sql = self.get_sql(data, lid)
 
         try:
@@ -402,7 +404,7 @@ class LanguageView(PGChildNodeView):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/__init__.py
index 7b99024..f0cdacb 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/__init__.py
@@ -7,7 +7,7 @@
 #
 ##########################################################################
 
-import json
+import simplejson as json
 import re
 from functools import wraps
 
@@ -262,7 +262,7 @@ class SchemaView(PGChildNodeView):
             acls = render_template(
                 "/".join([self.template_path, 'allowed_privs.json'])
             )
-            acls = json.loads(acls)
+            acls = json.loads(acls, encoding='utf-8')
         except Exception as e:
             current_app.logger.exception(e)
 
@@ -490,8 +490,9 @@ It may have been removed by another user.
            sid: Server ID
            did: Database ID
         """
-        data = request.form if request.form else \
-            json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
 
         required_args = {
             'name': 'Name'
@@ -559,7 +560,7 @@ It may have been removed by another user.
            scid: Schema ID
         """
         data = request.form if request.form else json.loads(
-            request.data.decode()
+            request.data, encoding='utf-8'
         )
         try:
             SQL = self.get_sql(gid, sid, data, scid)
@@ -657,7 +658,7 @@ It may have been removed by another user.
         data = dict()
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
@@ -757,14 +758,16 @@ It may have been removed by another user.
             _=gettext, data=data, conn=self.conn
         )
 
-        sql_header = """
--- SCHEMA: {0}
-
--- DROP SCHEMA {0};
+        sql_header = "-- SCHEMA: {0}\n\n-- ".format(data['name'])
+        if hasattr(str, 'decode'):
+            sql_header = sql_header.decode('utf-8')
 
-""".format(data['name'])
+        # drop schema
+        sql_header += render_template(
+            "/".join([self.template_path, 'sql/delete.sql']),
+            _=gettext, name=data['name'], conn=self.conn, cascade=False)
 
-        SQL = sql_header + SQL
+        SQL = sql_header + '\n\n' + SQL
 
         return ajax_response(response=SQL.strip("\n"))
 
@@ -947,6 +950,8 @@ It may have been removed by another user.
 -- DROP SCHEMA {0};
 
 """.format(old_data['name'])
+        if hasattr(str, 'decode'):
+            sql_header = sql_header.decode('utf-8')
 
         SQL = sql_header + SQL
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/__init__.py
index 4492a79..6c15b97 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/__init__.py
@@ -9,7 +9,7 @@
 
 """ Implements Collation Node """
 
-import json
+import simplejson as json
 from functools import wraps
 
 import pgadmin.browser.server_groups.servers.databases as database
@@ -378,7 +378,7 @@ class CollationView(PGChildNodeView):
         """
 
         data = request.form if request.form else json.loads(
-            request.data.decode()
+            request.data, encoding='utf-8'
         )
 
         required_args = [
@@ -491,7 +491,7 @@ class CollationView(PGChildNodeView):
            coid: Collation ID
         """
         data = request.form if request.form else json.loads(
-            request.data.decode()
+            request.data, encoding='utf-8'
         )
         SQL = self.get_sql(gid, sid, data, scid, coid)
         try:
@@ -538,7 +538,7 @@ class CollationView(PGChildNodeView):
         data = dict()
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
@@ -611,6 +611,8 @@ class CollationView(PGChildNodeView):
                               data=data, conn=self.conn)
 
         sql_header = "-- Collation: {0};\n\n-- ".format(data['name'])
+        if hasattr(str, 'decode'):
+            sql_header = sql_header.decode('utf-8')
         sql_header += render_template("/".join([self.template_path,
                                                 'delete.sql']),
                                       name=data['name'])
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/__init__.py
index f9a2d82..a7700f0 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/__init__.py
@@ -9,7 +9,7 @@
 
 """Implements the Domain Node."""
 
-import json
+import simplejson as json
 from functools import wraps
 
 import pgadmin.browser.server_groups.servers.databases as databases
@@ -189,7 +189,7 @@ class DomainView(PGChildNodeView, DataTypeReader):
 
             data = {}
             if request.data:
-                req = json.loads(request.data.decode())
+                req = json.loads(request.data, encoding='utf-8')
             else:
                 req = request.args or request.form
 
@@ -218,7 +218,7 @@ class DomainView(PGChildNodeView, DataTypeReader):
                     if key in list_params and req[key] != '' \
                             and req[key] is not None:
                         # Coverts string into python list as expected.
-                        data[key] = json.loads(req[key])
+                        data[key] = json.loads(req[key], encoding='utf-8')
                     elif key == 'typnotnull':
                         data[key] = True if req[key] == 'true' or req[key] is \
                                                                   True else \
@@ -695,6 +695,8 @@ AND relkind != 'c'))"""
 -- DROP DOMAIN {0};
 
 """.format(data['basensp'] + '.' + data['name'])
+        if hasattr(str, 'decode'):
+            sql_header = sql_header.decode('utf-8')
 
         SQL = sql_header + SQL
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/domain_constraints/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/domain_constraints/__init__.py
index 8db6b04..ba883ec 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/domain_constraints/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/domain_constraints/__init__.py
@@ -9,7 +9,7 @@
 
 """Implements the Domain Constraint Module."""
 
-import json
+import simplejson as json
 from functools import wraps
 
 import pgadmin.browser.server_groups.servers.databases.schemas.domains \
@@ -193,7 +193,7 @@ class DomainConstraintView(PGChildNodeView):
 
             data = {}
             if request.data:
-                req = json.loads(request.data.decode())
+                req = json.loads(request.data, encoding='utf-8')
             else:
                 req = request.args or request.form
 
@@ -560,6 +560,8 @@ class DomainConstraintView(PGChildNodeView):
 -- ALTER DOMAIN {1} DROP CONSTRAINT {0};
 
 """.format(data['name'], schema + '.' + domain)
+        if hasattr(str, 'decode'):
+            sql_header = sql_header.decode('utf-8')
 
         SQL = sql_header + SQL
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py
index 7b698c0..32a5f65 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py
@@ -9,7 +9,7 @@
 
 """Implements the Foreign Table Module."""
 
-import json
+import simplejson as json
 import sys
 import traceback
 from functools import wraps
@@ -232,7 +232,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
             data = {}
 
             if request.data:
-                req = json.loads(request.data.decode())
+                req = json.loads(request.data, encoding='utf-8')
             else:
                 req = request.args or request.form
 
@@ -267,7 +267,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
                         # Coverts string into python list as expected.
                         data[key] = [] if \
                             type(req[key]) == list and len(req[key]) == 0 else \
-                            json.loads(req[key])
+                            json.loads(req[key], encoding='utf-8')
 
                         if key == 'inherits':
                             # Convert Table ids from unicode/string to int
@@ -822,6 +822,8 @@ AND relkind != 'c'))"""
 -- DROP {0} {1};
 
 """.format('FOREIGN TABLE', data['basensp'] + "." + data['name'])
+        if hasattr(str, 'decode'):
+            sql_header = sql_header.decode('utf-8')
 
         SQL = sql_header + SQL
 
@@ -1194,7 +1196,7 @@ AND relkind != 'c'))"""
         else:
             columns = '*'
 
-        sql = "SELECT {0}\n\tFROM {1};".format(
+        sql = u"SELECT {0}\n\tFROM {1};".format(
             columns,
             self.qtIdent(self.conn, data['basensp'], data['name'])
         )
@@ -1230,7 +1232,7 @@ AND relkind != 'c'))"""
         if len(columns) > 0:
             columns = ", ".join(columns)
             values = ", ".join(values)
-            sql = "INSERT INTO {0}(\n\t{1})\n\tVALUES ({2});".format(
+            sql = u"INSERT INTO {0}(\n\t{1})\n\tVALUES ({2});".format(
                 self.qtIdent(self.conn, data['basensp'], data['name']),
                 columns, values
             )
@@ -1271,7 +1273,7 @@ AND relkind != 'c'))"""
                 columns = "=?, ".join(columns)
                 columns += "=?"
 
-            sql = "UPDATE {0}\n\tSET {1}\n\tWHERE <condition>;".format(
+            sql = u"UPDATE {0}\n\tSET {1}\n\tWHERE <condition>;".format(
                 self.qtIdent(self.conn, data['basensp'], data['name']),
                 columns
             )
@@ -1297,7 +1299,7 @@ AND relkind != 'c'))"""
         """
         data = self._fetch_properties(gid, sid, did, scid, foid)
 
-        sql = "DELETE FROM {0}\n\tWHERE <condition>;".format(
+        sql = u"DELETE FROM {0}\n\tWHERE <condition>;".format(
             self.qtIdent(self.conn, data['basensp'], data['name'])
         )
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/__init__.py
index 69f0348..80e900e 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/__init__.py
@@ -9,7 +9,7 @@
 
 """Defines views for management of Fts Configuration node"""
 
-import json
+import simplejson as json
 from functools import wraps
 
 import pgadmin.browser.server_groups.servers.databases as databases
@@ -404,7 +404,8 @@ class FtsConfigurationView(PGChildNodeView):
         ]
 
         data = request.form if request.form else json.loads(
-            request.data.decode())
+            request.data, encoding='utf-8'
+        )
         for arg in required_args:
             if arg not in data:
                 return make_json_response(
@@ -484,7 +485,8 @@ class FtsConfigurationView(PGChildNodeView):
         :param cfgid: fts Configuration id
         """
         data = request.form if request.form else json.loads(
-            request.data.decode())
+            request.data, encoding='utf-8'
+        )
 
         # Fetch sql query to update fts Configuration
         sql = self.get_sql(gid, sid, did, scid, data, cfgid)
@@ -614,7 +616,7 @@ class FtsConfigurationView(PGChildNodeView):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/__init__.py
index 987cd6d..bb90dc6 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/__init__.py
@@ -9,7 +9,7 @@
 
 """Defines views for management of Fts Dictionary node"""
 
-import json
+import simplejson as json
 from functools import wraps
 
 import pgadmin.browser.server_groups.servers.databases as databases
@@ -409,7 +409,8 @@ class FtsDictionaryView(PGChildNodeView):
         ]
 
         data = request.form if request.form else json.loads(
-            request.data.decode())
+            request.data, encoding='utf-8'
+        )
         for arg in required_args:
             if arg not in data:
                 return make_json_response(
@@ -475,7 +476,8 @@ class FtsDictionaryView(PGChildNodeView):
         :param dcid: fts dictionary id
         """
         data = request.form if request.form else json.loads(
-            request.data.decode())
+            request.data, encoding='utf-8'
+        )
 
         # Fetch sql query to update fts dictionary
         sql = self.get_sql(gid, sid, did, scid, data, dcid)
@@ -600,7 +602,7 @@ class FtsDictionaryView(PGChildNodeView):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/__init__.py
index d6aae60..956604d 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/__init__.py
@@ -9,7 +9,7 @@
 
 """Defines views for management of FTS Parser node"""
 
-import json
+import simplejson as json
 from functools import wraps
 
 from flask import render_template, request, jsonify, current_app
@@ -345,7 +345,8 @@ class FtsParserView(PGChildNodeView):
         ]
 
         data = request.form if request.form else json.loads(
-            request.data.decode())
+            request.data, encoding='utf-8'
+        )
         for arg in required_args:
             if arg not in data:
                 return make_json_response(
@@ -413,7 +414,8 @@ class FtsParserView(PGChildNodeView):
         :param pid: fts parser id
         """
         data = request.form if request.form else json.loads(
-            request.data.decode())
+            request.data, encoding='utf-8'
+        )
 
         # Fetch sql query to update fts parser
         sql = self.get_sql(gid, sid, did, scid, data, pid)
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/__init__.py
index 6612998..4a6d661 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/__init__.py
@@ -9,7 +9,7 @@
 
 """Defines views for management of Fts Template node"""
 
-import json
+import simplejson as json
 from functools import wraps
 
 from flask import render_template, make_response, request, jsonify
@@ -322,7 +322,8 @@ class FtsTemplateView(PGChildNodeView):
         ]
 
         data = request.form if request.form else json.loads(
-            request.data.decode())
+            request.data, encoding='utf-8'
+        )
         for arg in required_args:
             if arg not in data:
                 return make_json_response(
@@ -387,7 +388,8 @@ class FtsTemplateView(PGChildNodeView):
         :param tid: fts tempate id
         """
         data = request.form if request.form else json.loads(
-            request.data.decode())
+            request.data, encoding='utf-8'
+        )
 
         # Fetch sql query to update fts template
         sql = self.get_sql(gid, sid, did, scid, data, tid)
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py
index 9873ba3..d45dc32 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py
@@ -10,7 +10,7 @@
 """Implements Functions/Procedures Node."""
 
 import copy
-import json
+import simplejson as json
 import re
 import sys
 import traceback
@@ -252,7 +252,7 @@ class FunctionView(PGChildNodeView, DataTypeReader):
 
             data = {}
             if request.data:
-                req = json.loads(request.data.decode())
+                req = json.loads(request.data, encoding='utf-8')
             else:
                 req = request.args or request.form
 
@@ -280,7 +280,7 @@ class FunctionView(PGChildNodeView, DataTypeReader):
                     if key in list_params and req[key] != '' \
                             and req[key] is not None:
                         # Coverts string into python list as expected.
-                        data[key] = json.loads(req[key])
+                        data[key] = json.loads(req[key], encoding='utf-8')
                     elif (
                                                 key == 'proretset' or key == 'proisstrict' or
                                             key == 'prosecdef' or key == 'proiswindow' or
@@ -960,6 +960,8 @@ class FunctionView(PGChildNodeView, DataTypeReader):
 -- DROP {0} {1};
 
 """.format(object_type.upper(), name)
+        if hasattr(str, 'decode'):
+            sql_header = sql_header.decode('utf-8')
 
         SQL = sql_header + func_def
         SQL = re.sub('\n{2,}', '\n\n', SQL)
@@ -1124,7 +1126,7 @@ class FunctionView(PGChildNodeView, DataTypeReader):
                 if 'acl' in data:
                     data['acl'] = parse_priv_to_db(data['acl'], ["X"])
 
-                args = ''
+                args = u''
                 cnt = 1
                 if 'arguments' in data:
                     for a in data['arguments']:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/__init__.py
index 5f55e97..048046a 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/__init__.py
@@ -9,7 +9,7 @@
 
 """Implements Sequence Node"""
 
-import json
+import simplejson as json
 from functools import wraps
 
 import pgadmin.browser.server_groups.servers.databases as database
@@ -302,7 +302,9 @@ class SequenceView(PGChildNodeView):
             u'seqowner',
         ]
 
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
 
         for arg in required_args:
             if arg not in data:
@@ -418,7 +420,9 @@ class SequenceView(PGChildNodeView):
         Returns:
 
         """
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
         try:
             SQL = self.getSQL(gid, sid, did, data, scid, seid)
             SQL = SQL.strip('\n').strip(' ')
@@ -470,7 +474,7 @@ class SequenceView(PGChildNodeView):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
index e67add5..252b3e9 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
@@ -9,7 +9,7 @@
 
 """ Implements Table Node """
 
-import json
+import simplejson as json
 import re
 from functools import wraps
 
@@ -1348,11 +1348,13 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
            did: Database ID
            scid: Schema ID
         """
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
 
         for k, v in data.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except (ValueError, TypeError):
                 data[k] = v
 
@@ -1381,7 +1383,9 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
         # We will convert it again to list
         if 'coll_inherits' in data and \
                 isinstance(data['coll_inherits'], str):
-            data['coll_inherits'] = json.loads(data['coll_inherits'])
+            data['coll_inherits'] = json.loads(
+                data['coll_inherits'], encoding='utf-8'
+            )
 
         if 'foreign_key' in data:
             for c in data['foreign_key']:
@@ -1434,12 +1438,12 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
            tid: Table ID
         """
         data = request.form if request.form else json.loads(
-            request.data.decode()
+            request.data, encoding='utf-8'
         )
 
         for k, v in data.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except (ValueError, TypeError):
                 data[k] = v
 
@@ -1535,7 +1539,9 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
            tid: Table ID
         """
         # Below will decide if it's simple drop or drop with cascade call
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
         # Convert str 'true' to boolean type
         is_cascade = json.loads(data['cascade'])
 
@@ -1581,7 +1587,9 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
            tid: Table ID
         """
         # Below will decide if it's simple drop or drop with cascade call
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
         # Convert str 'true' to boolean type
         is_enable = json.loads(data['enable'])
 
@@ -1663,7 +1671,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
         data = dict()
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except (ValueError, TypeError):
                 data[k] = v
 
@@ -2385,9 +2393,10 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
                 c['cltype'] = self._cltype_formatter(c['cltype'])
                 c['hasSqrBracket'] = self.hasSqrBracket
 
-        sql_header = "-- Table: {0}\n\n-- ".format(self.qtIdent(self.conn,
+        sql_header = u"-- Table: {0}\n\n-- ".format(self.qtIdent(self.conn,
                                                                 data['schema'],
                                                                 data['name']))
+
         sql_header += render_template("/".join([self.template_path,
                                                 'delete.sql']),
                                       data=data, conn=self.conn)
@@ -2478,6 +2487,9 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
             data['cols'] = ', '.join(cols)
 
             sql_header = "\n-- Index: {0}\n\n-- ".format(data['name'])
+            if hasattr(str, 'decode'):
+                sql_header = sql_header.decode('utf-8')
+
             sql_header += render_template("/".join([self.index_template_path,
                                                     'delete.sql']),
                                           data=data, conn=self.conn)
@@ -2547,6 +2559,9 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
             data = trigger_definition(data)
 
             sql_header = "\n-- Trigger: {0}\n\n-- ".format(data['name'])
+            if hasattr(str, 'decode'):
+                sql_header = sql_header.decode('utf-8')
+
             sql_header += render_template("/".join([self.trigger_template_path,
                                                     'delete.sql']),
                                           data=data, conn=self.conn)
@@ -2644,7 +2659,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
         else:
             columns = '*'
 
-        sql = "SELECT {0}\n\tFROM {1};".format(
+        sql = u"SELECT {0}\n\tFROM {1};".format(
             columns,
             self.qtIdent(self.conn, data['schema'], data['name'])
         )
@@ -2688,7 +2703,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
         if len(columns) > 0:
             columns = ", ".join(columns)
             values = ", ".join(values)
-            sql = "INSERT INTO {0}(\n\t{1})\n\tVALUES ({2});".format(
+            sql = u"INSERT INTO {0}(\n\t{1})\n\tVALUES ({2});".format(
                 self.qtIdent(self.conn, data['schema'], data['name']),
                 columns, values
             )
@@ -2737,7 +2752,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
             else:
                 columns = "=?, ".join(columns)
 
-            sql = "UPDATE {0}\n\tSET {1}\n\tWHERE <condition>;".format(
+            sql = u"UPDATE {0}\n\tSET {1}\n\tWHERE <condition>;".format(
                 self.qtIdent(self.conn, data['schema'], data['name']),
                 columns
             )
@@ -2771,7 +2786,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
 
         data = res['rows'][0]
 
-        sql = "DELETE FROM {0}\n\tWHERE <condition>;".format(
+        sql = u"DELETE FROM {0}\n\tWHERE <condition>;".format(
             self.qtIdent(self.conn, data['schema'], data['name'])
         )
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/__init__.py
index c860316..cc64d7a 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/__init__.py
@@ -9,7 +9,7 @@
 
 """ Implements Column Node """
 
-import json
+import simplejson as json
 from functools import wraps
 
 import pgadmin.browser.server_groups.servers.databases as database
@@ -505,12 +505,12 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
            tid: Table ID
         """
         data = request.form if request.form else json.loads(
-            request.data.decode()
+            request.data, encoding='utf-8'
         )
 
         for k, v in data.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except (ValueError, TypeError):
                 data[k] = v
 
@@ -631,7 +631,9 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
            tid: Table ID
            clid: Column ID
         """
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
 
         # Adding parent into data dict, will be using it while creating sql
         data['schema'] = self.schema
@@ -688,7 +690,7 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
         data = dict()
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
@@ -813,10 +815,11 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
 
             SQL = self.get_sql(scid, tid, None, data)
 
-            sql_header = "-- Column: {0}\n\n-- ".format(self.qtIdent(self.conn,
+            sql_header = u"-- Column: {0}\n\n-- ".format(self.qtIdent(self.conn,
                                                                      data['schema'],
                                                                      data['table'],
                                                                      data['name']))
+
             sql_header += render_template("/".join([self.template_path,
                                                     'delete.sql']),
                                           data=data, conn=self.conn)
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/__init__.py
index 4aa9552..0fe7e1b 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/__init__.py
@@ -9,7 +9,7 @@
 
 """Implements the Check Constraint Module."""
 
-import json
+import simplejson as json
 from functools import wraps
 
 import pgadmin.browser.server_groups.servers.databases as database
@@ -396,11 +396,13 @@ class CheckConstraintView(PGChildNodeView):
         """
         required_args = ['consrc']
 
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
 
         for k, v in data.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except (ValueError, TypeError):
                 data[k] = v
 
@@ -545,7 +547,9 @@ class CheckConstraintView(PGChildNodeView):
             tid: Table Id
             cid: Check Constraint Id
         """
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
 
         try:
             data['schema'] = self.schema
@@ -632,6 +636,8 @@ class CheckConstraintView(PGChildNodeView):
                               data=data)
 
         sql_header = "-- Constraint: {0}\n\n-- ".format(data['name'])
+        if hasattr(str, 'decode'):
+            sql_header = sql_header.decode('utf-8')
 
         sql_header += render_template(
             "/".join([self.template_path, 'delete.sql']),
@@ -661,7 +667,7 @@ class CheckConstraintView(PGChildNodeView):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/__init__.py
index bb9c7ea..97e1e2f 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/__init__.py
@@ -9,7 +9,7 @@
 
 """Implements Exclusion constraint Node"""
 
-import json
+import simplejson as json
 from functools import wraps
 
 import pgadmin.browser.server_groups.servers.databases as database
@@ -441,11 +441,13 @@ class ExclusionConstraintView(PGChildNodeView):
         """
         required_args = ['columns']
 
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
 
         for k, v in data.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except (ValueError, TypeError):
                 data[k] = v
 
@@ -546,7 +548,9 @@ class ExclusionConstraintView(PGChildNodeView):
         Returns:
 
         """
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
 
         try:
             data['schema'] = self.schema
@@ -666,7 +670,7 @@ class ExclusionConstraintView(PGChildNodeView):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
@@ -789,6 +793,8 @@ class ExclusionConstraintView(PGChildNodeView):
                 "/".join([self.template_path, 'create.sql']), data=data)
 
             sql_header = "-- Constraint: {0}\n\n-- ".format(data['name'])
+            if hasattr(str, 'decode'):
+                sql_header = sql_header.decode('utf-8')
 
             sql_header += render_template(
                 "/".join([self.template_path, 'delete.sql']),
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/__init__.py
index 5a05a91..d02c93f 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/__init__.py
@@ -9,7 +9,7 @@
 
 """Implements Foreign key constraint Node"""
 
-import json
+import simplejson as json
 from functools import wraps
 
 import pgadmin.browser.server_groups.servers.databases as database
@@ -464,11 +464,13 @@ class ForeignKeyConstraintView(PGChildNodeView):
         """
         required_args = ['columns']
 
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
 
         for k, v in data.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except (ValueError, TypeError):
                 data[k] = v
 
@@ -598,7 +600,9 @@ class ForeignKeyConstraintView(PGChildNodeView):
         Returns:
 
         """
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
 
         try:
             data['schema'] = self.schema
@@ -726,7 +730,7 @@ class ForeignKeyConstraintView(PGChildNodeView):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
@@ -892,6 +896,8 @@ class ForeignKeyConstraintView(PGChildNodeView):
                 "/".join([self.template_path, 'create.sql']), data=data)
 
             sql_header = "-- Constraint: {0}\n\n-- ".format(data['name'])
+            if hasattr(str, 'decode'):
+                sql_header = sql_header.decode('utf-8')
 
             sql_header += render_template(
                 "/".join([self.template_path, 'delete.sql']),
@@ -1044,7 +1050,7 @@ class ForeignKeyConstraintView(PGChildNodeView):
         index = None
         try:
             if data and 'cols' in data:
-                cols = set(json.loads(data['cols']))
+                cols = set(json.loads(data['cols'], encoding='utf-8'))
                 index = self.search_coveringindex(tid, cols)
 
             return make_json_response(
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/__init__.py
index a5ee551..bf1be94 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/__init__.py
@@ -9,7 +9,7 @@
 
 """Implements Primary key constraint Node"""
 
-import json
+import simplejson as json
 from functools import wraps
 
 import pgadmin.browser.server_groups.servers.databases as database
@@ -444,11 +444,13 @@ class IndexConstraintView(PGChildNodeView):
             [u'columns', u'index']  # Either of one should be there.
         ]
 
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
 
         for k, v in data.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except (ValueError, TypeError):
                 data[k] = v
 
@@ -563,7 +565,9 @@ class IndexConstraintView(PGChildNodeView):
         Returns:
 
         """
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
 
         try:
             data['schema'] = self.schema
@@ -688,7 +692,7 @@ class IndexConstraintView(PGChildNodeView):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
@@ -816,6 +820,8 @@ class IndexConstraintView(PGChildNodeView):
                 constraint_name=self.constraint_name)
 
             sql_header = "-- Constraint: {0}\n\n-- ".format(data['name'])
+            if hasattr(str, 'decode'):
+                sql_header = sql_header.decode('utf-8')
 
             sql_header += render_template(
                 "/".join([self.template_path, 'delete.sql']),
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py
index e2cce0b..8f743fb 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py
@@ -9,7 +9,7 @@
 
 """ Implements Index Node """
 
-import json
+import simplejson as json
 from functools import wraps
 
 import pgadmin.browser.server_groups.servers.databases as database
@@ -522,12 +522,12 @@ class IndexesView(PGChildNodeView):
            tid: Table ID
         """
         data = request.form if request.form else json.loads(
-            request.data.decode()
+            request.data, encoding='utf-8'
         )
 
         for k, v in data.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except (ValueError, TypeError):
                 data[k] = v
 
@@ -672,7 +672,9 @@ class IndexesView(PGChildNodeView):
            tid: Table ID
            idx: Index ID
         """
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
         data['schema'] = self.schema
         data['table'] = self.table
         try:
@@ -721,7 +723,7 @@ class IndexesView(PGChildNodeView):
         data = dict()
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
@@ -824,6 +826,9 @@ class IndexesView(PGChildNodeView):
             SQL = self.get_sql(scid, tid, None, data)
 
             sql_header = "-- Index: {0}\n\n-- ".format(data['name'])
+            if hasattr(str, 'decode'):
+                sql_header = sql_header.decode('utf-8')
+
             sql_header += render_template("/".join([self.template_path,
                                                     'delete.sql']),
                                           data=data, conn=self.conn)
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/rules/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/rules/__init__.py
index c256e40..4f40f52 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/rules/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/rules/__init__.py
@@ -9,7 +9,7 @@
 
 """Implements Rule Node"""
 
-import json
+import simplejson as json
 from functools import wraps
 
 import pgadmin.browser.server_groups.servers.databases.schemas as schemas
@@ -290,8 +290,9 @@ class RuleView(PGChildNodeView):
             'name',
         ]
 
-        data = request.form if request.form else \
-            json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
         for arg in required_args:
             if arg not in data:
                 return make_json_response(
@@ -331,8 +332,9 @@ class RuleView(PGChildNodeView):
         """
         This function will update a rule object
         """
-        data = request.form if request.form else \
-            json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
         SQL = self.getSQL(gid, sid, data, tid, rid)
         try:
             if SQL and SQL.strip('\n') and SQL.strip(' '):
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/__init__.py
index 35559ea..46f2645 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/__init__.py
@@ -9,7 +9,7 @@
 
 """ Implements Trigger Node """
 
-import json
+import simplejson as json
 from functools import wraps
 
 import pgadmin.browser.server_groups.servers.databases as database
@@ -537,12 +537,12 @@ class TriggerView(PGChildNodeView):
            tid: Table ID
         """
         data = request.form if request.form else json.loads(
-            request.data.decode()
+            request.data, encoding='utf-8'
         )
 
         for k, v in data.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except (ValueError, TypeError):
                 data[k] = v
 
@@ -657,7 +657,9 @@ class TriggerView(PGChildNodeView):
            tid: Table ID
            trid: Trigger ID
         """
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
 
         try:
             SQL = self.get_sql(scid, tid, trid, data)
@@ -705,7 +707,7 @@ class TriggerView(PGChildNodeView):
         data = dict()
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
@@ -815,6 +817,9 @@ class TriggerView(PGChildNodeView):
             SQL = self.get_sql(scid, tid, None, data)
 
             sql_header = "-- Trigger: {0}\n\n-- ".format(data['name'])
+            if hasattr(str, 'decode'):
+                sql_header = sql_header.decode('utf-8')
+
             sql_header += render_template("/".join([self.template_path,
                                                     'delete.sql']),
                                           data=data, conn=self.conn)
@@ -847,7 +852,9 @@ class TriggerView(PGChildNodeView):
            trid: Trigger ID
         """
 
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
 
         # Convert str 'true' to boolean type
         is_enable_flag = json.loads(data['enable'])
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py
index dc790ce..39c31e9 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py
@@ -9,7 +9,7 @@
 
 """ Implements Type Node """
 
-import json
+import simplejson as json
 from functools import wraps
 
 import pgadmin.browser.server_groups.servers.databases as database
@@ -793,7 +793,9 @@ class TypeView(PGChildNodeView, DataTypeReader):
            scid: Schema ID
            tid: Type ID
         """
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
         required_args = {
             'name': 'Name',
             'typtype': 'Type'
@@ -898,7 +900,9 @@ class TypeView(PGChildNodeView, DataTypeReader):
            tid: Type ID
         """
 
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
         try:
             SQL = self.get_sql(gid, sid, data, scid, tid)
             if SQL and SQL.strip('\n') and SQL.strip(' '):
@@ -1004,7 +1008,7 @@ class TypeView(PGChildNodeView, DataTypeReader):
         # converting nested request data in proper json format
         for key, val in req.items():
             if key in ['composite', 'enum', 'seclabels', 'typacl']:
-                data[key] = json.loads(val)
+                data[key] = json.loads(val, encoding='utf-8')
             else:
                 data[key] = val
 
@@ -1180,6 +1184,9 @@ class TypeView(PGChildNodeView, DataTypeReader):
 
         # We are appending headers here for sql panel
         sql_header = "-- Type: {0}\n\n-- ".format(data['name'])
+        if hasattr(str, 'decode'):
+            sql_header = sql_header.decode('utf-8')
+
         sql_header += render_template("/".join([self.template_path,
                                                 'delete.sql']),
                                       data=data, conn=self.conn)
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/__init__.py
index efd1247..a2ef587 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/__init__.py
@@ -466,8 +466,9 @@ class ViewNode(PGChildNodeView, VacuumSettings):
             'definition'
         ]
 
-        data = request.form if request.form else \
-            json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
         for arg in required_args:
             if arg not in data:
                 return make_json_response(
@@ -511,8 +512,9 @@ class ViewNode(PGChildNodeView, VacuumSettings):
         """
         This function will update a view object
         """
-        data = request.form if request.form else \
-            json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
         SQL = self.getSQL(gid, sid, data, vid)
         try:
             if SQL and SQL.strip('\n') and SQL.strip(' '):
@@ -626,7 +628,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
         data = {}
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
@@ -1128,7 +1130,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
         else:
             columns = '*'
 
-        sql = "SELECT {0}\n\tFROM {1};".format(
+        sql = u"SELECT {0}\n\tFROM {1};".format(
             columns,
             self.qtIdent(self.conn, data_view['schema'], data_view['name'])
         )
@@ -1185,7 +1187,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
         if len(columns) > 0:
             columns = ", ".join(columns)
             values = ", ".join(values)
-            sql = "INSERT INTO {0}(\n\t{1})\n\tVALUES ({2});".format(
+            sql = u"INSERT INTO {0}(\n\t{1})\n\tVALUES ({2});".format(
                 self.qtIdent(
                     self.conn, data_view['schema'], data_view['name']
                 ),
@@ -1596,8 +1598,9 @@ class MViewNode(ViewNode, VacuumSettings):
         """
 
         # Below will decide if it's refresh data or refresh concurrently
-        data = request.form if request.form else \
-            json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
 
         is_concurrent = json.loads(data['concurrent'])
         with_data = json.loads(data['with_data'])
diff --git a/web/pgadmin/browser/server_groups/servers/resource_groups/__init__.py b/web/pgadmin/browser/server_groups/servers/resource_groups/__init__.py
index 16c617a..df62ab3 100644
--- a/web/pgadmin/browser/server_groups/servers/resource_groups/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/resource_groups/__init__.py
@@ -9,7 +9,7 @@
 
 """Implements Resource Groups for PPAS 9.4 and above"""
 
-import json
+import simplejson as json
 from functools import wraps
 
 import pgadmin.browser.server_groups.servers as servers
@@ -312,7 +312,9 @@ class ResourceGroupView(NodeView):
             'name'
         ]
 
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
         for arg in required_args:
             if arg not in data:
                 return make_json_response(
@@ -370,7 +372,9 @@ class ResourceGroupView(NodeView):
         required_args = [
             'name', 'cpu_rate_limit', 'dirty_rate_limit'
         ]
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
 
         try:
             sql = render_template("/".join([self.template_path, 'properties.sql']), rgid=rg_id)
@@ -462,7 +466,7 @@ class ResourceGroupView(NodeView):
         data = dict()
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except ValueError:
                 data[k] = v
 
diff --git a/web/pgadmin/browser/server_groups/servers/roles/__init__.py b/web/pgadmin/browser/server_groups/servers/roles/__init__.py
index 8becc4e..bee3d02 100644
--- a/web/pgadmin/browser/server_groups/servers/roles/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/roles/__init__.py
@@ -111,7 +111,7 @@ class RoleView(PGChildNodeView):
 
             data = None
             if request.data:
-                data = json.loads(request.data)
+                data = json.loads(request.data, encoding='utf-8')
             else:
                 data = dict()
                 req = request.args or request.form
@@ -125,7 +125,7 @@ class RoleView(PGChildNodeView):
                         u'rolcatupdate', u'variables', u'rolmembership',
                         u'seclabels'
                     ]:
-                        data[key] = json.loads(val)
+                        data[key] = json.loads(val, encoding='utf-8')
                     else:
                         data[key] = val
 
@@ -685,7 +685,7 @@ rolmembership:{
     def drop(self, gid, sid, rid):
 
         status, res = self.conn.execute_2darray(
-            "DROP ROLE {0};".format(self.qtIdent(self.conn, self.role))
+            u"DROP ROLE {0};".format(self.qtIdent(self.conn, self.role))
         )
         if not status:
             return internal_server_error(
diff --git a/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py b/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py
index 6137a69..bd5de07 100644
--- a/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py
@@ -6,7 +6,7 @@
 # This software is released under the PostgreSQL Licence
 #
 ##########################################################################
-import json
+import simplejson as json
 import re
 from functools import wraps
 
@@ -252,7 +252,9 @@ class TablespaceView(PGChildNodeView):
             'spclocation': 'Location'
         }
 
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
 
         for arg in required_args:
             if arg not in data:
@@ -318,7 +320,9 @@ class TablespaceView(PGChildNodeView):
         """
         This function will update tablespace object
         """
-        data = request.form if request.form else json.loads(request.data.decode())
+        data = request.form if request.form else json.loads(
+            request.data, encoding='utf-8'
+        )
 
         try:
             SQL = self.get_sql(gid, sid, data, tsid)
@@ -405,7 +409,7 @@ class TablespaceView(PGChildNodeView):
         data = dict()
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except ValueError as ve:
                 current_app.logger.exception(ve)
                 data[k] = v
@@ -521,6 +525,9 @@ class TablespaceView(PGChildNodeView):
 
 """.format(old_data['name'])
 
+        if hasattr(str, 'decode'):
+            sql_header = sql_header.decode('utf-8')
+
         SQL = sql_header + SQL
         SQL = re.sub('\n{2,}', '\n\n', SQL)
         return ajax_response(response=SQL.strip('\n'))
@@ -723,7 +730,7 @@ class TablespaceView(PGChildNodeView):
             sid: Server ID
             tsid: Tablespace ID
         """
-        data = json.loads(request.form['data'])
+        data = json.loads(request.form['data'], encoding='utf-8')
 
         try:
             SQL = render_template("/".join(
@@ -762,7 +769,7 @@ class TablespaceView(PGChildNodeView):
         data = dict()
         for k, v in request.args.items():
             try:
-                data[k] = json.loads(v)
+                data[k] = json.loads(v, encoding='utf-8')
             except ValueError as ve:
                 current_app.logger.exception(ve)
                 data[k] = v
diff --git a/web/pgadmin/tools/backup/__init__.py b/web/pgadmin/tools/backup/__init__.py
index ece5d97..771b3ff 100644
--- a/web/pgadmin/tools/backup/__init__.py
+++ b/web/pgadmin/tools/backup/__init__.py
@@ -9,7 +9,7 @@
 
 """Implements Backup Utility"""
 
-import json
+import simplejson as json
 import os
 
 from flask import render_template, request, current_app, \
@@ -233,9 +233,9 @@ def create_backup_job(sid):
     if request.form:
         # Convert ImmutableDict to dict
         data = dict(request.form)
-        data = json.loads(data['data'][0])
+        data = json.loads(data['data'][0], encoding='utf-8')
     else:
-        data = json.loads(request.data.decode())
+        data = json.loads(request.data, encoding='utf-8')
 
     backup_file = filename_with_file_manager_path(data['file'])
 
@@ -327,9 +327,9 @@ def create_backup_objects_job(sid):
     if request.form:
         # Convert ImmutableDict to dict
         data = dict(request.form)
-        data = json.loads(data['data'][0])
+        data = json.loads(data['data'][0], encoding='utf-8')
     else:
-        data = json.loads(request.data.decode())
+        data = json.loads(request.data, encoding='utf-8')
 
     backup_file = filename_with_file_manager_path(data['file'])
 
diff --git a/web/pgadmin/tools/datagrid/__init__.py b/web/pgadmin/tools/datagrid/__init__.py
index aaaefda..b607143 100644
--- a/web/pgadmin/tools/datagrid/__init__.py
+++ b/web/pgadmin/tools/datagrid/__init__.py
@@ -10,7 +10,7 @@
 """A blueprint module implementing the datagrid frame."""
 MODULE_NAME = 'datagrid'
 
-import json
+import simplejson as json
 import pickle
 import random
 
@@ -93,7 +93,7 @@ def initialize_datagrid(cmd_type, obj_type, sid, did, obj_id):
     """
 
     if request.data:
-        filter_sql = json.loads(request.data.decode())
+        filter_sql = json.loads(request.data, encoding='utf-8')
     else:
         filter_sql = request.args or request.form
 
@@ -289,7 +289,7 @@ def validate_filter(sid, did, obj_id):
         obj_id: Id of currently selected object
     """
     if request.data:
-        filter_sql = json.loads(request.data.decode())
+        filter_sql = json.loads(request.data, encoding='utf-8')
     else:
         filter_sql = request.args or request.form
 
diff --git a/web/pgadmin/tools/debugger/__init__.py b/web/pgadmin/tools/debugger/__init__.py
index 4b9f0bc..18393c3 100644
--- a/web/pgadmin/tools/debugger/__init__.py
+++ b/web/pgadmin/tools/debugger/__init__.py
@@ -11,7 +11,7 @@
 
 MODULE_NAME = 'debugger'
 
-import json
+import simplejson as json
 import random
 
 from flask import url_for, Response, render_template, request, session, current_app
@@ -373,7 +373,7 @@ def initialize_target(debug_type, sid, did, scid, func_id):
     # Here we get the value in case of direct debugging so update the session variables accordingly
     # For indirect debugging user will provide the data from another session so below condition will be be required
     if request.method == 'POST':
-        data = json.loads(request.values['data'])
+        data = json.loads(request.values['data'], encoding='utf-8')
         if data:
             d = session['funcData']
             d['args_value'] = data
@@ -582,7 +582,7 @@ def start_debugger_listener(trans_id):
     # If user again start the same debug function with different arguments then we need to save that values to session
     # variable and database.
     if request.method == 'POST':
-        data = json.loads(request.values['data'])
+        data = json.loads(request.values['data'], encoding='utf-8')
         if data:
             function_data = session['functionData']
             session_obj = function_data[str(trans_id)]
@@ -1080,7 +1080,7 @@ def deposit_parameter_value(trans_id):
 
     if conn.connected():
         # get the data sent through post from client
-        data = json.loads(request.values['data'])
+        data = json.loads(request.values['data'], encoding='utf-8')
 
         if data:
             sql = render_template("/".join([template_path, "deposit_value.sql"]), session_id=obj['session_id'],
@@ -1223,7 +1223,7 @@ def set_arguments_sqlite(sid, did, scid, func_id):
     """
 
     if request.values['data']:
-        data = json.loads(request.values['data'])
+        data = json.loads(request.values['data'], encoding='utf-8')
 
     try:
         for i in range(0, len(data)):
diff --git a/web/pgadmin/tools/import_export/__init__.py b/web/pgadmin/tools/import_export/__init__.py
index f04f562..e1dc061 100644
--- a/web/pgadmin/tools/import_export/__init__.py
+++ b/web/pgadmin/tools/import_export/__init__.py
@@ -9,7 +9,7 @@
 
 """A blueprint module implementing the import and export functionality"""
 
-import json
+import simplejson as json
 import os
 
 from flask import url_for, Response, render_template, request, current_app
@@ -166,9 +166,9 @@ def create_import_export_job(sid):
     if request.form:
         # Convert ImmutableDict to dict
         data = dict(request.form)
-        data = json.loads(data['data'][0])
+        data = json.loads(data['data'][0], encoding='utf-8')
     else:
-        data = json.loads(request.data.decode())
+        data = json.loads(request.data, encoding='utf-8')
 
     # Fetch the server details like hostname, port, roles etc
     server = Server.query.filter_by(
diff --git a/web/pgadmin/tools/maintenance/__init__.py b/web/pgadmin/tools/maintenance/__init__.py
index b116bf9..8853c8b 100644
--- a/web/pgadmin/tools/maintenance/__init__.py
+++ b/web/pgadmin/tools/maintenance/__init__.py
@@ -9,7 +9,7 @@
 
 """A blueprint module implementing the maintenance tool for vacuum"""
 
-import json
+import simplejson as json
 
 from flask import url_for, Response, render_template, request, current_app
 from flask_babel import gettext as _
@@ -171,9 +171,9 @@ def create_maintenance_job(sid, did):
     if request.form:
         # Convert ImmutableDict to dict
         data = dict(request.form)
-        data = json.loads(data['data'][0])
+        data = json.loads(data['data'][0], encoding='utf-8')
     else:
-        data = json.loads(request.data.decode())
+        data = json.loads(request.data, encoding='utf-8')
 
     index_name = None
 
diff --git a/web/pgadmin/tools/restore/__init__.py b/web/pgadmin/tools/restore/__init__.py
index 5cec8da..0fa8bb8 100644
--- a/web/pgadmin/tools/restore/__init__.py
+++ b/web/pgadmin/tools/restore/__init__.py
@@ -9,7 +9,7 @@
 
 """Implements Restore Utility"""
 
-import json
+import simplejson as json
 import os
 
 from flask import render_template, request, current_app, \
@@ -175,9 +175,9 @@ def create_restore_job(sid):
     if request.form:
         # Convert ImmutableDict to dict
         data = dict(request.form)
-        data = json.loads(data['data'][0])
+        data = json.loads(data['data'][0], encoding='utf-8')
     else:
-        data = json.loads(request.data.decode())
+        data = json.loads(request.data, encoding='utf-8')
 
     backup_file = filename_with_file_manager_path(data['file'])
 
diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py
index 21b7e93..215edb5 100644
--- a/web/pgadmin/tools/sqleditor/__init__.py
+++ b/web/pgadmin/tools/sqleditor/__init__.py
@@ -10,7 +10,7 @@
 """A blueprint module implementing the sqleditor frame."""
 MODULE_NAME = 'sqleditor'
 
-import json
+import simplejson as json
 import os
 import pickle
 import random
@@ -238,7 +238,7 @@ def start_query_tool(trans_id):
     """
 
     if request.data:
-        sql = json.loads(request.data.decode())
+        sql = json.loads(request.data, encoding='utf-8')
     else:
         sql = request.args or request.form
 
@@ -366,7 +366,7 @@ def preferences(trans_id):
     else:
         data = None
         if request.data:
-            data = json.loads(request.data.decode())
+            data = json.loads(request.data, encoding='utf-8')
         else:
             data = request.args or request.form
         for k, v in data.items():
@@ -516,7 +516,7 @@ def save(trans_id):
     """
 
     if request.data:
-        changed_data = json.loads(request.data.decode())
+        changed_data = json.loads(request.data, encoding='utf-8')
     else:
         changed_data = request.args or request.form
 
@@ -574,7 +574,7 @@ def apply_filter(trans_id):
         trans_id: unique transaction id
     """
     if request.data:
-        filter_sql = json.loads(request.data.decode())
+        filter_sql = json.loads(request.data, encoding='utf-8')
     else:
         filter_sql = request.args or request.form
 
@@ -606,7 +606,7 @@ def append_filter_inclusive(trans_id):
         trans_id: unique transaction id
     """
     if request.data:
-        filter_data = json.loads(request.data.decode())
+        filter_data = json.loads(request.data, encoding='utf-8')
     else:
         filter_data = request.args or request.form
 
@@ -649,7 +649,7 @@ def append_filter_exclusive(trans_id):
         trans_id: unique transaction id
     """
     if request.data:
-        filter_data = json.loads(request.data.decode())
+        filter_data = json.loads(request.data, encoding='utf-8')
     else:
         filter_data = request.args or request.form
 
@@ -724,7 +724,7 @@ def set_limit(trans_id):
         trans_id: unique transaction id
     """
     if request.data:
-        limit = json.loads(request.data.decode())
+        limit = json.loads(request.data, encoding='utf-8')
     else:
         limit = request.args or request.form
 
@@ -847,7 +847,7 @@ def set_auto_commit(trans_id):
         trans_id: unique transaction id
     """
     if request.data:
-        auto_commit = json.loads(request.data.decode())
+        auto_commit = json.loads(request.data, encoding='utf-8')
     else:
         auto_commit = request.args or request.form
 
@@ -885,7 +885,7 @@ def set_auto_rollback(trans_id):
         trans_id: unique transaction id
     """
     if request.data:
-        auto_rollback = json.loads(request.data.decode())
+        auto_rollback = json.loads(request.data, encoding='utf-8')
     else:
         auto_rollback = request.args or request.form
 
@@ -926,7 +926,7 @@ def auto_complete(trans_id):
     text_before_cursor = ''
 
     if request.data:
-        data = json.loads(request.data.decode())
+        data = json.loads(request.data, encoding='utf-8')
     else:
         data = request.args or request.form
 
@@ -1125,7 +1125,7 @@ def load_file():
     reads the data and sends back in reponse
     """
     if request.data:
-        file_data = json.loads(request.data.decode())
+        file_data = json.loads(request.data, encoding='utf-8')
 
     file_path = unquote(file_data['file_name'])
     # retrieve storage directory path
@@ -1182,7 +1182,7 @@ def save_file():
     and then save the data to the file
     """
     if request.data:
-        file_data = json.loads(request.data.decode())
+        file_data = json.loads(request.data, encoding='utf-8')
 
     # retrieve storage directory path
     storage_manager_path = get_storage_directory()
diff --git a/web/pgadmin/tools/user_management/__init__.py b/web/pgadmin/tools/user_management/__init__.py
index b7096c2..dbf010b 100644
--- a/web/pgadmin/tools/user_management/__init__.py
+++ b/web/pgadmin/tools/user_management/__init__.py
@@ -9,7 +9,7 @@
 
 """Implements pgAdmin4 User Management Utility"""
 
-import json
+import simplejson as json
 import re
 
 from flask import render_template, request, \
@@ -163,7 +163,9 @@ def create():
     Returns:
 
     """
-    data = request.form if request.form else json.loads(request.data.decode())
+    data = request.form if request.form else json.loads(
+        request.data, encoding='utf-8'
+    )
 
     for f in ('email', 'role', 'active', 'newPassword', 'confirmPassword'):
         if f in data and data[f] != '':
@@ -265,7 +267,9 @@ def update(uid):
     if not usr:
         abort(404)
 
-    data = request.form if request.form else json.loads(request.data.decode())
+    data = request.form if request.form else json.loads(
+        request.data, encoding='utf-8'
+    )
 
     try:
         new_data = validate_user(data)
diff --git a/web/pgadmin/utils/driver/psycopg2/__init__.py b/web/pgadmin/utils/driver/psycopg2/__init__.py
index 4bf7506..41a7e62 100644
--- a/web/pgadmin/utils/driver/psycopg2/__init__.py
+++ b/web/pgadmin/utils/driver/psycopg2/__init__.py
@@ -250,13 +250,23 @@ class Connection(BaseConnection):
                 password = password.decode()
 
         try:
+            if hasattr(str, 'decode'):
+                database = self.db.encode('utf-8')
+                user = mgr.user.encode('utf-8')
+                conn_id = self.conn_id.encode('utf-8')
+            else:
+                database = self.db
+                user = mgr.user
+                conn_id = self.conn_id
+
             import os
-            os.environ['PGAPPNAME'] = '{0} - {1}'.format(config.APP_NAME, self.conn_id)
+            os.environ['PGAPPNAME'] = '{0} - {1}'.format(config.APP_NAME, conn_id)
+
             pg_conn = psycopg2.connect(
                 host=mgr.host,
                 port=mgr.port,
-                database=self.db,
-                user=mgr.user,
+                database=database,
+                user=user,
                 password=password,
                 async=self.async
             )
@@ -277,7 +287,7 @@ class Connection(BaseConnection):
 Failed to connect to the database server(#{server_id}) for connection ({conn_id}) with error message as below:
 {msg}""".format(
                 server_id=self.manager.sid,
-                conn_id=self.conn_id,
+                conn_id=conn_id,
                 msg=msg
             )
             )
@@ -310,7 +320,7 @@ SET client_encoding='UNICODE';""")
             return False, res
 
         if mgr.role:
-            status, res = self.execute_scalar("SET ROLE TO %s", [mgr.role])
+            status, res = self.execute_scalar(u"SET ROLE TO %s", [mgr.role])
 
             if not status:
                 self.conn.close()
@@ -320,7 +330,7 @@ Connect to the database server (#{server_id}) for connection ({conn_id}), but -
 {msg}
 """.format(
                     server_id=self.manager.sid,
-                    conn_id=self.conn_id,
+                    conn_id=conn_id,
                     msg=res
                 )
                 )
@@ -343,7 +353,7 @@ Failed to fetch the version information on the established connection to the dat
 {msg}
 """.format(
                     server_id=self.manager.sid,
-                    conn_id=self.conn_id,
+                    conn_id=conn_id,
                     msg=res
                 )
                 )
@@ -395,7 +405,10 @@ WHERE
         return True, None
 
     def __cursor(self, server_cursor=False):
-        cur = getattr(g, str(self.manager.sid) + '#' + self.conn_id, None)
+        cur = getattr(g, "{0}#{1}".format(
+            self.manager.sid,
+            self.conn_id.encode('utf-8')
+        ), None)
 
         if self.connected() and cur and not cur.closed:
             if not server_cursor or (server_cursor and cur.name):
@@ -457,7 +470,7 @@ Attempting to reconnect to the database server (#{server_id}) for the connection
                 status, cur = self.connect()
                 if not status:
                     msg = gettext(
-                        """
+                        u"""
 Connection for server#{0} with database "{1}" was lost.
 Attempt to reconnect it failed with the error:
 {2}"""
@@ -468,7 +481,7 @@ Attempt to reconnect it failed with the error:
             else:
                 return False, errmsg
 
-        setattr(g, str(self.manager.sid) + '#' + self.conn_id, cur)
+        setattr(g, "{0}#{1}".format(self.manager.sid, self.conn_id.encode('utf-8')), cur)
 
         return True, cur
 
@@ -498,7 +511,7 @@ Attempt to reconnect it failed with the error:
         query_id = random.randint(1, 9999999)
 
         current_app.logger.log(25,
-                               "Execute (with server cursor) for server #{server_id} - {conn_id} (Query-id: {query_id}):\n{query}".format(
+                               u"Execute (with server cursor) for server #{server_id} - {conn_id} (Query-id: {query_id}):\n{query}".format(
                                    server_id=self.manager.sid,
                                    conn_id=self.conn_id,
                                    query=query,
@@ -511,7 +524,7 @@ Attempt to reconnect it failed with the error:
             cur.close()
             errmsg = self._formatted_exception_msg(pe, formatted_exception_msg)
             current_app.logger.error(
-                "Failed to execute query ((with server cursor) for the server #{server_id} - {conn_id} (Query-id: {query_id}):\nError Message:{errmsg}".format(
+                u"Failed to execute query ((with server cursor) for the server #{server_id} - {conn_id} (Query-id: {query_id}):\nError Message:{errmsg}".format(
                     server_id=self.manager.sid,
                     conn_id=self.conn_id,
                     query=query,
@@ -568,7 +581,7 @@ Attempt to reconnect it failed with the error:
 
         current_app.logger.log(
             25,
-            "Execute (scalar) for server #{server_id} - {conn_id} (Query-id: {query_id}):\n{query}".format(
+            u"Execute (scalar) for server #{server_id} - {conn_id} (Query-id: {query_id}):\n{query}".format(
                 server_id=self.manager.sid,
                 conn_id=self.conn_id,
                 query=query,
@@ -582,7 +595,7 @@ Attempt to reconnect it failed with the error:
             cur.close()
             errmsg = self._formatted_exception_msg(pe, formatted_exception_msg)
             current_app.logger.error(
-                "Failed to execute query (execute_scalar) for the server #{server_id} - {conn_id} (Query-id: {query_id}):\nError Message:{errmsg}".format(
+                u"Failed to execute query (execute_scalar) for the server #{server_id} - {conn_id} (Query-id: {query_id}):\nError Message:{errmsg}".format(
                     server_id=self.manager.sid,
                     conn_id=self.conn_id,
                     query=query,
@@ -618,7 +631,7 @@ Attempt to reconnect it failed with the error:
 
         current_app.logger.log(
             25,
-            "Execute (async) for server #{server_id} - {conn_id} (Query-id: {query_id}):\n{query}".format(
+            u"Execute (async) for server #{server_id} - {conn_id} (Query-id: {query_id}):\n{query}".format(
                 server_id=self.manager.sid,
                 conn_id=self.conn_id,
                 query=query,
@@ -632,7 +645,7 @@ Attempt to reconnect it failed with the error:
             res = self._wait_timeout(cur.connection, ASYNC_WAIT_TIMEOUT)
         except psycopg2.Error as pe:
             errmsg = self._formatted_exception_msg(pe, formatted_exception_msg)
-            current_app.logger.error("""
+            current_app.logger.error(u"""
 Failed to execute query (execute_async) for the server #{server_id} - {conn_id}
 (Query-id: {query_id}):\nError Message:{errmsg}
 """.format(
@@ -668,7 +681,7 @@ Failed to execute query (execute_async) for the server #{server_id} - {conn_id}
 
         current_app.logger.log(
             25,
-            "Execute (void) for server #{server_id} - {conn_id} (Query-id: {query_id}):\n{query}".format(
+            u"Execute (void) for server #{server_id} - {conn_id} (Query-id: {query_id}):\n{query}".format(
                 server_id=self.manager.sid,
                 conn_id=self.conn_id,
                 query=query,
@@ -681,7 +694,7 @@ Failed to execute query (execute_async) for the server #{server_id} - {conn_id}
         except psycopg2.Error as pe:
             cur.close()
             errmsg = self._formatted_exception_msg(pe, formatted_exception_msg)
-            current_app.logger.error("""
+            current_app.logger.error(u"""
 Failed to execute query (execute_void) for the server #{server_id} - {conn_id}
 (Query-id: {query_id}):\nError Message:{errmsg}
 """.format(
@@ -708,7 +721,7 @@ Failed to execute query (execute_void) for the server #{server_id} - {conn_id}
         query_id = random.randint(1, 9999999)
         current_app.logger.log(
             25,
-            "Execute (2darray) for server #{server_id} - {conn_id} (Query-id: {query_id}):\n{query}".format(
+            u"Execute (2darray) for server #{server_id} - {conn_id} (Query-id: {query_id}):\n{query}".format(
                 server_id=self.manager.sid,
                 conn_id=self.conn_id,
                 query=query,
@@ -721,7 +734,7 @@ Failed to execute query (execute_void) for the server #{server_id} - {conn_id}
             cur.close()
             errmsg = self._formatted_exception_msg(pe, formatted_exception_msg)
             current_app.logger.error(
-                "Failed to execute query (execute_2darray) for the server #{server_id} - {conn_id} (Query-id: {query_id}):\nError Message:{errmsg}".format(
+                u"Failed to execute query (execute_2darray) for the server #{server_id} - {conn_id} (Query-id: {query_id}):\nError Message:{errmsg}".format(
                     server_id=self.manager.sid,
                     conn_id=self.conn_id,
                     query=query,
@@ -753,7 +766,7 @@ Failed to execute query (execute_void) for the server #{server_id} - {conn_id}
         query_id = random.randint(1, 9999999)
         current_app.logger.log(
             25,
-            "Execute (dict) for server #{server_id} - {conn_id} (Query-id: {query_id}):\n{query}".format(
+            u"Execute (dict) for server #{server_id} - {conn_id} (Query-id: {query_id}):\n{query}".format(
                 server_id=self.manager.sid,
                 conn_id=self.conn_id,
                 query=query,
@@ -766,7 +779,7 @@ Failed to execute query (execute_void) for the server #{server_id} - {conn_id}
             cur.close()
             errmsg = self._formatted_exception_msg(pe, formatted_exception_msg)
             current_app.logger.error(
-                "Failed to execute query (execute_dict) for the server #{server_id}- {conn_id} (Query-id: {query_id}):\nError Message:{errmsg}".format(
+                u"Failed to execute query (execute_dict) for the server #{server_id}- {conn_id} (Query-id: {query_id}):\nError Message:{errmsg}".format(
                     server_id=self.manager.sid,
                     conn_id=self.conn_id,
                     query_id=query_id,
@@ -1245,17 +1258,23 @@ class ServerManager(object):
             "Server has no active connection. Please connect to the server."
         )
 
-        if database is None:
+        if database is not None:
+            if hasattr(str, 'decode') and \
+                    not isinstance(database, unicode):
+                database = database.decode('utf-8')
+        else:
             if did is None:
                 database = self.db
             elif did in self.db_info:
                 database = self.db_info[did]['datname']
+                if hasattr(str, 'decode'):
+                    database = database.decode('utf-8')
             else:
-                maintenance_db_id = 'DB:' + self.db
+                maintenance_db_id = u'DB:{0}'.format(self.db)
                 if maintenance_db_id in self.connections:
                     conn = self.connections[maintenance_db_id]
                     if conn.connected():
-                        status, res = conn.execute_dict("""
+                        status, res = conn.execute_dict(u"""
 SELECT
     db.oid as did, db.datname, db.datallowconn,
     pg_encoding_to_char(db.encoding) AS serverencoding,
@@ -1267,6 +1286,9 @@ WHERE db.oid = {0}""".format(did))
                         if status and len(res['rows']) > 0:
                             for row in res['rows']:
                                 self.db_info[did] = row
+                                if hasattr(str, 'decode'):
+                                    self.db_info[did]['datname'] = \
+                                        self.db_info[did]['datname'].decode('utf-8')
                                 database = self.db_info[did]['datname']
 
                         if did not in self.db_info:
@@ -1277,8 +1299,8 @@ WHERE db.oid = {0}""".format(did))
         if database is None:
             raise Exception(msg_active_conn)
 
-        my_id = ('CONN:' + str(conn_id)) if conn_id is not None else \
-            ('DB:' + str(database))
+        my_id = (u'CONN:{0}'.format(conn_id)) if conn_id is not None else \
+            (u'DB:{0}'.format(database))
 
         self.pinged = datetime.datetime.now()
 
@@ -1335,13 +1357,15 @@ WHERE db.oid = {0}""".format(did))
         if did is not None:
             if did in self.db_info and 'datname' in self.db_info[did]:
                 database = self.db_info[did]['datname']
+                if hasattr(str, 'decode'):
+                    database = database.decode('utf-8')
                 if database is None:
                     return False
             else:
                 return False
 
-        my_id = ('CONN:' + str(conn_id)) if conn_id is not None else \
-            ('DB:' + str(database)) if database is not None else None
+        my_id = (u'CONN:{0}'.format(conn_id)) if conn_id is not None else \
+            (u'DB:{0}'.format(database)) if database is not None else None
 
         if my_id is not None:
             if my_id in self.connections:
@@ -1564,14 +1588,22 @@ class Driver(BaseDriver):
 
     @staticmethod
     def qtLiteral(value):
-
-        res = adapt(value).getquoted()
+        try:
+            res = adapt(value).getquoted()
+        except UnicodeEncodeError:
+            # We will handle special characters with utf8 encoding
+            adapted = adapt(value)
+            adapted.encoding = 'utf8'
+            res = adapted.getquoted()
 
         # Returns in bytes, we need to convert it in string
         if isinstance(res, bytes):
-            return res.decode()
-        else:
-            return res
+            try:
+                res = res.decode()
+            except UnicodeDecodeError:
+                res = res.decode('utf-8')
+
+        return res
 
     @staticmethod
     def ScanKeywordExtraLookup(key):
@@ -1607,17 +1639,12 @@ class Driver(BaseDriver):
 
     @staticmethod
     def needsQuoting(key, forTypes):
-
-        # Python 3 does not require the decoding of value
-        if hasattr(str, 'decode'):
-            value = key.decode()
-        else:
-            value = key
+        value = key
         valNoArray = value
 
         # check if the string is number or not
-        if (isinstance(value, int)):
-            return True;
+        if isinstance(value, int):
+            return True
         # certain types should not be quoted even though it contains a space. Evilness.
         elif forTypes and value[-2:] == u"[]":
             valNoArray = value[:-2]
@@ -1691,8 +1718,14 @@ class Driver(BaseDriver):
         for val in args:
             if type(val) == list:
                 return map(lambda w: Driver.qtIdent(conn, w), val)
+            if hasattr(str, 'decode') and not isinstance(val, unicode):
+                # Handling for python2
+                try:
+                    val = str(val).encode('utf-8')
+                except UnicodeDecodeError:
+                    # If already unicode, most likely coming from db
+                    val = str(val).decode('utf-8')
 
-            val = str(val)
             if len(val) == 0:
                 continue
 


^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4)
  2016-07-22 14:11 PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-22 15:50 ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-25 06:19   ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-25 11:31     ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-26 13:34       ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
@ 2016-07-26 14:06         ` Dave Page <[email protected]>
  2016-07-26 16:02           ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  0 siblings, 1 reply; 16+ messages in thread

From: Dave Page @ 2016-07-26 14:06 UTC (permalink / raw)
  To: Murtuza Zabuawala <[email protected]>; +Cc: pgadmin-hackers

Hi

On Tue, Jul 26, 2016 at 2:34 PM, Murtuza Zabuawala
<[email protected]> wrote:
> Hi Dave,
>
> PFA updated patch to fix encoding issue, I have tested in Python2/3 and
> looks like working in both environment.
>
> Almost all nodes are affected with this change, I tried to test & cover all
> basic operations on nodes but still it requires some testing.
>
> This patch will cover below tickets,
> RM#1307
> RM#1479

I've committed this as-is, as it fixes things nicely as far as I can
see... with one exception: I couldn't create Functions with utf-8
names. Can you fix that please?

Thanks.

-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4)
  2016-07-22 14:11 PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-22 15:50 ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-25 06:19   ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-25 11:31     ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-26 13:34       ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-26 14:06         ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
@ 2016-07-26 16:02           ` Dave Page <[email protected]>
  2016-07-27 11:18             ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  0 siblings, 1 reply; 16+ messages in thread

From: Dave Page @ 2016-07-26 16:02 UTC (permalink / raw)
  To: Murtuza Zabuawala <[email protected]>; +Cc: pgadmin-hackers

On Tue, Jul 26, 2016 at 3:06 PM, Dave Page <[email protected]> wrote:
> Hi
>
> On Tue, Jul 26, 2016 at 2:34 PM, Murtuza Zabuawala
> <[email protected]> wrote:
>> Hi Dave,
>>
>> PFA updated patch to fix encoding issue, I have tested in Python2/3 and
>> looks like working in both environment.
>>
>> Almost all nodes are affected with this change, I tried to test & cover all
>> basic operations on nodes but still it requires some testing.
>>
>> This patch will cover below tickets,
>> RM#1307
>> RM#1479
>
> I've committed this as-is, as it fixes things nicely as far as I can
> see... with one exception: I couldn't create Functions with utf-8
> names. Can you fix that please?

I spoke too soon - Types don't play nicely either - try creating the
following in the UI.

CREATE TYPE public."🍺" AS ENUM
    ('a', 'b');

ALTER TYPE public."🍺"
    OWNER TO postgres;


Isn't there a way we can force everything to UTF-8 without having to
modify individual nodes? That's what we did in pgAdmin 3, then never
worried about the problem again.

-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4)
  2016-07-22 14:11 PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-22 15:50 ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-25 06:19   ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-25 11:31     ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-26 13:34       ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-26 14:06         ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-26 16:02           ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
@ 2016-07-27 11:18             ` Murtuza Zabuawala <[email protected]>
  2016-07-27 11:34               ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  0 siblings, 1 reply; 16+ messages in thread

From: Murtuza Zabuawala @ 2016-07-27 11:18 UTC (permalink / raw)
  To: Dave Page <[email protected]>; +Cc: pgadmin-hackers

Hi Dave,

1) Unicode conversion was working properly for function node, It was
failing due to wrong sql templates.
- I've fixed them.
2) Type is also working fine with encoding for me(PFA screenshots), Can you
please provide error you got?


This patch also makes Provider optional in security label control &
templates.

-------
Regarding enforcing to utf-8, In my opinion we can enforce everything to
utf-8 if we use any of one python version but to make it compatible with
both python2 and python3 version by forcing utf-8 encoding it will be
difficult to handle its side effects.

For example,

*Python2,*

>>> txt_sample = 'Hello'
>>> isinstance(txt_sample, str)
True
>>> isinstance(txt_sample, bytes)
True
>>> isinstance(txt_sample, unicode)
False
>>> txt_sample.encode('utf-8')
'Hello'
>>> txt_sample.decode('utf-8')
u'Hello'

Forcing to unicode in Python2,

>>> txt_sample = u'Hello'
>>> isinstance(txt_sample, str)
False
>>> isinstance(txt_sample, bytes)
False
>>> isinstance(txt_sample, unicode)
True

*Python3,*

>>> txt_sample = 'Hello'
>>> isinstance(txt_sample, str)
True
>>> isinstance(txt_sample, bytes)
False
>>> txt_sample.encode('utf-8')
b'Hello'
>>> txt_sample.decode('utf-8')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'decode'


And also psycopg2 driver returns text as string in Python2 even if that
text contains unicode characters, In python3 that just works fine because
string is Unicode by default.


Regards,
Murtuza

--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers


Attachments:

  [image/png] python2.png (29.6K, 3-python2.png)
  download | view image

  [image/png] python-2.png (69.8K, 4-python-2.png)
  download | view image

  [image/png] python-3.png (70.6K, 5-python-3.png)
  download | view image

  [application/octet-stream] fix_func_templates_and_SecLabls.patch (40.5K, 6-fix_func_templates_and_SecLabls.patch)
  download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/__init__.py
index 33f1d15..3b7c57b 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/__init__.py
@@ -187,6 +187,8 @@ class DatabaseView(PGChildNodeView):
 
         for row in rset['rows']:
             dbname = row['name']
+            if hasattr(str, 'decode'):
+                dbname = dbname.decode('utf-8')
             if self.manager.db == dbname:
                 connected = True
                 canDrop = canDisConn = False
@@ -228,7 +230,10 @@ class DatabaseView(PGChildNodeView):
             return internal_server_error(errormsg=rset)
 
         for row in rset['rows']:
-            if self.manager.db == row['name']:
+            db = row['name']
+            if hasattr(str, 'decode'):
+                db = db.decode('utf-8')
+            if self.manager.db == db:
                 connected = True
             else:
                 conn = self.manager.connection(row['name'])
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py
index aadd466..810bb49 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py
@@ -902,26 +902,35 @@ class FunctionView(PGChildNodeView, DataTypeReader):
         """
         resp_data = self._fetch_properties(gid, sid, did, scid, fnid)
         # Fetch the function definition.
-        args = ''
+        args = u''
+        args_without_name = u''
         cnt = 1
-        if 'arguments' in resp_data:
-            for a in resp_data['arguments']:
-                if (('argmode' in a and a['argmode'] != 'OUT' and
-                    a['argmode'] is not None
-                      ) or 'argnode' not in a):
-                    if 'argmode' in a:
-                        args += a['argmode'] + " "
-                    if 'argname' in a and a['argname'] != ''\
-                            and a['argname'] is not None:
-                        args += self.qtIdent(
-                            self.conn, a['argname']) + " "
-                    if 'argtype' in a:
-                        args += a['argtype']
-                    if cnt < len(resp_data['arguments']):
-                        args += ', '
-                cnt += 1
+        args_list = []
+        if 'arguments' in resp_data and len(resp_data['arguments']) > 0:
+            args_list = resp_data['arguments']
+            resp_data['args'] = resp_data['arguments']
+
+        for a in args_list:
+            if (('argmode' in a and a['argmode'] != 'OUT' and
+                         a['argmode'] is not None
+                 ) or 'argmode' not in a):
+                if 'argmode' in a:
+                    args += a['argmode'] + " "
+                    args_without_name += a['argmode'] + " "
+                if 'argname' in a and a['argname'] != '' \
+                        and a['argname'] is not None:
+                    args += self.qtIdent(
+                        self.conn, a['argname']) + " "
+                if 'argtype' in a:
+                    args += a['argtype']
+                    args_without_name += a['argtype']
+                if cnt < len(args_list):
+                    args += ', '
+                    args_without_name += ', '
+            cnt += 1
 
         resp_data['func_args'] = args.strip(' ')
+        resp_data['func_args_without'] = args_without_name.strip(' ')
 
         if self.node_type == 'procedure':
             object_type = 'procedure'
@@ -960,8 +969,17 @@ class FunctionView(PGChildNodeView, DataTypeReader):
             if not status:
                 return internal_server_error(errormsg=res)
 
-            func_def, name = res['rows'][0]
+            name = res['rows'][0]['name']
             # Create mode
+            if hasattr(str, 'decode'):
+                if resp_data['prosrc']:
+                    resp_data['prosrc'] = resp_data['prosrc'].decode(
+                        'utf-8'
+                    )
+                if resp_data['prosrc_c']:
+                    resp_data['prosrc_c'] = resp_data['prosrc_c'].decode(
+                        'utf-8'
+                    )
             func_def = render_template("/".join([self.sql_template_path,
                                                  'create.sql']),
                                        data=resp_data, query_type="create")
@@ -1138,25 +1156,34 @@ class FunctionView(PGChildNodeView, DataTypeReader):
                     data['acl'] = parse_priv_to_db(data['acl'], ["X"])
 
                 args = u''
+                args_without_name = u''
                 cnt = 1
-                if 'arguments' in data:
-                    for a in data['arguments']:
-                        if (('argmode' in a and a['argmode'] != 'OUT' and
-                                     a['argmode'] is not None
-                             ) or 'argnode' not in a):
-                            if 'argmode' in a:
-                                args += a['argmode'] + " "
-                            if 'argname' in a and a['argname'] != '' \
-                                    and a['argname'] is not None:
-                                args += self.qtIdent(
-                                    self.conn, a['argname']) + " "
-                            if 'argtype' in a:
-                                args += a['argtype']
-                            if cnt < len(data['arguments']):
-                                args += ', '
-                        cnt += 1
+                args_list = []
+                if 'arguments' in data and len(data['arguments']) > 0:
+                    args_list = data['arguments']
+                elif 'args' in data and len(data['args']) > 0:
+                    args_list = data['args']
+                for a in args_list:
+                    if (('argmode' in a and a['argmode'] != 'OUT' and
+                                 a['argmode'] is not None
+                         ) or 'argmode' not in a):
+                        if 'argmode' in a:
+                            args += a['argmode'] + " "
+                            args_without_name += a['argmode'] + " "
+                        if 'argname' in a and a['argname'] != '' \
+                                and a['argname'] is not None:
+                            args += self.qtIdent(
+                                self.conn, a['argname']) + " "
+                        if 'argtype' in a:
+                            args += a['argtype']
+                            args_without_name += a['argtype']
+                        if cnt < len(args_list):
+                            args += ', '
+                            args_without_name += ', '
+                    cnt += 1
 
                 data['func_args'] = args.strip(' ')
+                data['func_args_without'] = args_without_name.strip(' ')
                 # Create mode
                 SQL = render_template("/".join([self.sql_template_path,
                                                 'create.sql']),
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.1_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.1_plus/create.sql
index efd7775..4566d06 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.1_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.1_plus/create.sql
@@ -4,19 +4,10 @@
 {% set is_columns = [] %}
 {% if data %}
 CREATE{% if query_type is defined %}{{' OR REPLACE'}}{% endif %} FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({% if data.args %}
-{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}}{% endif %}{% if p.argtype %}{{ conn|qtIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
+{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}}{% endif %}{% if p.argtype %}{{ conn|qtTypeIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
 {% if not loop.last %},{% endif %}
 {% endfor %}
 {% endif -%}
-{% if data.func_args %}
-{% set func_args = data.func_args.split(',') %}
-
-{% for f in func_args %}
-    {{ f|trim }}{% if not loop.last %},
-{% endif %}
-{% endfor %}
-
-{% endif %}
 )
     RETURNS{% if data.proretset %} SETOF{% endif %} {{ conn|qtTypeIdent(data.prorettypename) }}
     LANGUAGE {{ data.lanname|qtLiteral }}
@@ -39,24 +30,24 @@ $function$
 $function${% endif %};
 {% if data.funcowner %}
 
-ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
+ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
     OWNER TO {{ data.funcowner }};
 {% endif %}
 {% if data.acl %}
 {% for p in data.acl %}
 
-{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
+{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
 {% endfor %}{% endif %}
 {% if data.description %}
 
-COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
 {% if r.label and r.provider %}
 
-{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
+{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
 {% endif %}
 {% endfor %}
 {% endif -%}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.2_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.2_plus/create.sql
index 63585ad..dda39cf 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.2_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.2_plus/create.sql
@@ -4,19 +4,10 @@
 {% set is_columns = [] %}
 {% if data %}
 CREATE{% if query_type is defined %}{{' OR REPLACE'}}{% endif %} FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({% if data.args %}
-{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}}{% endif %}{% if p.argtype %}{{ conn|qtIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
+{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtTypeIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
 {% if not loop.last %},{% endif %}
 {% endfor %}
 {% endif -%}
-{% if data.func_args %}
-{% set func_args = data.func_args.split(',') %}
-
-{% for f in func_args %}
-    {{ f|trim }}{% if not loop.last %},
-{% endif %}
-{% endfor %}
-
-{% endif %}
 )
     RETURNS{% if data.proretset %} SETOF{% endif %} {{ conn|qtTypeIdent(data.prorettypename) }}
     LANGUAGE {{ data.lanname|qtLiteral }}
@@ -43,25 +34,25 @@ $function$
 $function${% endif -%};
 {% if data.funcowner %}
 
-ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
+ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
     OWNER TO {{ data.funcowner }};
 {% endif -%}
 {% if data.acl %}
 {% for p in data.acl %}
 
-{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
+{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
 {% endfor -%}
 {% endif -%}
 {% if data.description %}
 
-COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
 {% if r.label and r.provider %}
 
-{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
+{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
 {% endif %}
 {% endfor %}
 {% endif -%}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.5_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.5_plus/create.sql
index 45a9c61..0668313 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.5_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.5_plus/create.sql
@@ -8,15 +8,6 @@ CREATE{% if query_type is defined %}{{' OR REPLACE'}}{% endif %} FUNCTION {{ con
 {% if not loop.last %},{% endif %}
 {% endfor %}
 {% endif -%}
-{% if data.func_args %}
-{% set func_args = data.func_args.split(',') %}
-
-{% for f in func_args %}
-    {{ f|trim }}{% if not loop.last %},
-{% endif %}
-{% endfor %}
-
-{% endif %}
 )
     RETURNS{% if data.proretset %} SETOF{% endif %} {{ conn|qtTypeIdent(data.prorettypename) }}
     LANGUAGE {{ data.lanname|qtLiteral }}
@@ -43,24 +34,24 @@ $function$
 $function${% endif -%};
 {% if data.funcowner %}
 
-ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
+ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
     OWNER TO {{ data.funcowner }};
 {% endif -%}
 {% if data.acl %}
 {% for p in data.acl %}
 
-{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
+{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
 {% endfor %}{% endif %}
 {% if data.description %}
 
-COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
 {% if r.label and r.provider %}
 
-{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
+{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
 {% endif %}
 {% endfor %}
 {% endif -%}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.1_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.1_plus/create.sql
index efd7775..10589ce 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.1_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.1_plus/create.sql
@@ -4,19 +4,10 @@
 {% set is_columns = [] %}
 {% if data %}
 CREATE{% if query_type is defined %}{{' OR REPLACE'}}{% endif %} FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({% if data.args %}
-{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}}{% endif %}{% if p.argtype %}{{ conn|qtIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
+{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtTypeIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
 {% if not loop.last %},{% endif %}
 {% endfor %}
 {% endif -%}
-{% if data.func_args %}
-{% set func_args = data.func_args.split(',') %}
-
-{% for f in func_args %}
-    {{ f|trim }}{% if not loop.last %},
-{% endif %}
-{% endfor %}
-
-{% endif %}
 )
     RETURNS{% if data.proretset %} SETOF{% endif %} {{ conn|qtTypeIdent(data.prorettypename) }}
     LANGUAGE {{ data.lanname|qtLiteral }}
@@ -39,24 +30,24 @@ $function$
 $function${% endif %};
 {% if data.funcowner %}
 
-ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
+ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
     OWNER TO {{ data.funcowner }};
 {% endif %}
 {% if data.acl %}
 {% for p in data.acl %}
 
-{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
+{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
 {% endfor %}{% endif %}
 {% if data.description %}
 
-COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
 {% if r.label and r.provider %}
 
-{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
+{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
 {% endif %}
 {% endfor %}
 {% endif -%}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.2_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.2_plus/create.sql
index 516e6d4..77ed284 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.2_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.2_plus/create.sql
@@ -4,19 +4,10 @@
 {% set is_columns = [] %}
 {% if data %}
 CREATE{% if query_type is defined %}{{' OR REPLACE'}}{% endif %} FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({% if data.args %}
-{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}}{% endif %}{% if p.argtype %}{{ conn|qtIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
+{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtTypeIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
 {% if not loop.last %},{% endif %}
 {% endfor %}
 {% endif -%}
-{% if data.func_args %}
-{% set func_args = data.func_args.split(',') %}
-
-{% for f in func_args %}
-    {{ f|trim }}{% if not loop.last %},
-{% endif %}
-{% endfor %}
-
-{% endif %}
 )
     RETURNS{% if data.proretset %} SETOF{% endif %} {{ conn|qtTypeIdent(data.prorettypename) }}
     LANGUAGE {{ data.lanname|qtLiteral }}
@@ -43,25 +34,25 @@ $function$
 $function${% endif -%};
 {% if data.funcowner %}
 
-ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
+ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
     OWNER TO {{ data.funcowner }};
 {% endif -%}
 {% if data.acl %}
 {% for p in data.acl %}
 
-{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
+{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_withouts)}}
 {% endfor -%}
 {% endif -%}
 {% if data.description %}
 
-COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
 {% if r.label and r.provider %}
 
-{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
+{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args_withouts) }}
 {% endif %}
 {% endfor %}
 {% endif -%}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.5_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.5_plus/create.sql
index b5b7176..77034be 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.5_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.5_plus/create.sql
@@ -31,24 +31,24 @@ $function$
 $function${% endif -%};
 {% if data.funcowner %}
 
-ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
+ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
     OWNER TO {{ data.funcowner }};
 {% endif -%}
 {% if data.acl %}
 {% for p in data.acl %}
 
-{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
+{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
 {% endfor %}{% endif %}
 {% if data.description %}
 
-COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
 {% if r.label and r.provider %}
 
-{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
+{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
 {% endif %}
 {% endfor %}
 {% endif -%}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.1_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.1_plus/create.sql
index 0a8cb20..235f9c6 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.1_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.1_plus/create.sql
@@ -3,11 +3,10 @@
 {% import 'macros/functions/variable.macros' as VARIABLE %}
 {% set is_columns = [] %}
 {% if data %}
-CREATE OR REPLACE PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}{% if data.args is defined or data.func_args is defined %}
-({% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
+CREATE OR REPLACE PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}{% if data.args is defined %}
+({% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtTypeIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
 {% if not loop.last %}, {% endif %}
 {% endfor -%}
-{% if data.func_args %}{{ data.func_args }}{% endif %}
 ){% endif %}
 
 AS
@@ -15,18 +14,18 @@ AS
 {% if data.acl and not is_sql %}
 {% for p in data.acl %}
 
-{{ PRIVILEGE.SET(conn, "PROCEDURE", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
+{{ PRIVILEGE.SET(conn, "PROCEDURE", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
 {% endfor %}{% endif %}
 {% if data.description %}
 
 COMMENT ON PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}
-    IS '{{ data.description }}';
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
 {% if r.label and r.provider %}
 
-{{ SECLABEL.SET(conn, 'PROCEDURE', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
+{{ SECLABEL.SET(conn, 'PROCEDURE', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
 {% endif %}
 {% endfor %}
 {% endif -%}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.2_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.2_plus/create.sql
index 073ce1d..3a211f2 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.2_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.2_plus/create.sql
@@ -3,11 +3,10 @@
 {% import 'macros/functions/variable.macros' as VARIABLE %}
 {% set is_columns = [] %}
 {% if data %}
-CREATE OR REPLACE PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}{% if data.args is defined or data.func_args is defined %}
-({% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
+CREATE OR REPLACE PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}{% if data.args is defined %}
+({% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtTypeIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
  {% if not loop.last %}, {% endif %}
 {% endfor -%}
-{% if data.func_args %}{{ data.func_args }}{% endif %}
 ){% endif %}
 
 AS
@@ -15,18 +14,18 @@ AS
 {% if data.acl and not is_sql %}
 {% for p in data.acl %}
 
-{{ PRIVILEGE.SET(conn, "PROCEDURE", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
+{{ PRIVILEGE.SET(conn, "PROCEDURE", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
 {% endfor %}{% endif %}
 {% if data.description %}
 
 COMMENT ON PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}
-    IS '{{ data.description }}';
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
 {% if r.label and r.provider %}
 
-{{ SECLABEL.SET(conn, 'PROCEDURE', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
+{{ SECLABEL.SET(conn, 'PROCEDURE', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
 {% endif %}
 {% endfor %}
 {% endif -%}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.5_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.5_plus/create.sql
index f1a40af..d0682aa 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.5_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.5_plus/create.sql
@@ -3,11 +3,10 @@
 {% import 'macros/functions/variable.macros' as VARIABLE %}
 {% set is_columns = [] %}
 {% if data %}
-CREATE OR REPLACE PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}{% if data.args is defined or data.func_args is defined %}
+CREATE OR REPLACE PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}{% if data.args is defined %}
 ({% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtTypeIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
 {% if not loop.last %}, {% endif %}
 {% endfor -%}
-{% if data.func_args %}{{ data.func_args }}{% endif %}
 ){% endif %}
 {% if query_type != 'create' %}
 
@@ -27,18 +26,18 @@ AS
 {% if data.acl and not is_sql %}
 {% for p in data.acl %}
 
-{{ PRIVILEGE.SET(conn, "PROCEDURE", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
+{{ PRIVILEGE.SET(conn, "PROCEDURE", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
 {% endfor %}{% endif %}
 {% if data.description %}
 
 COMMENT ON PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}
-    IS '{{ data.description }}';
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
 {% if r.label and r.provider %}
 
-{{ SECLABEL.SET(conn, 'PROCEDURE', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
+{{ SECLABEL.SET(conn, 'PROCEDURE', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
 {% endif %}
 {% endfor %}
 {% endif -%}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.1_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.1_plus/create.sql
index 6e9fd78..0a776f3 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.1_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.1_plus/create.sql
@@ -37,7 +37,7 @@ ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args
 {% if data.description %}
 
 COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.2_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.2_plus/create.sql
index 7ca4bf1..412b02e 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.2_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.2_plus/create.sql
@@ -42,7 +42,7 @@ ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args
 {% if data.description %}
 
 COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.5_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.5_plus/create.sql
index 5445855..aaa31e0 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.5_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.5_plus/create.sql
@@ -40,7 +40,7 @@ ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args
 {% if data.description %}
 
 COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.1_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.1_plus/create.sql
index 6e9fd78..0a776f3 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.1_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.1_plus/create.sql
@@ -37,7 +37,7 @@ ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args
 {% if data.description %}
 
 COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.2_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.2_plus/create.sql
index 210cf3a..ef64d20 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.2_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.2_plus/create.sql
@@ -41,7 +41,7 @@ ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args
 {% if data.description %}
 
 COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.5_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.5_plus/create.sql
index 5c7c568..91f1de6 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.5_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.5_plus/create.sql
@@ -21,7 +21,7 @@ CREATE FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}()
     SET {{ conn|qtIdent(v.name) }}={{ v.value|qtLiteral }}{% endfor %}
 {% endif %}
 
-+AS {% endif %}{% if data.lanname == 'c' %}
+AS {% endif %}{% if data.lanname == 'c' %}
 {{ data.probin|qtLiteral }}, {{ data.prosrc_c|qtLiteral }}
 {% else %}
 $BODY$
@@ -40,7 +40,7 @@ ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args
 {% if data.description %}
 
 COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/macros/security.macros b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/macros/security.macros
index 39587c3..1beb259 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/macros/security.macros
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/macros/security.macros
@@ -1,6 +1,6 @@
 {% macro APPLY(conn, type, schema_name, parent_object, child_object, provider, label) -%}
-SECURITY LABEL FOR {{ conn|qtIdent(provider) }} ON {{ type }} {{ conn|qtIdent(schema_name, parent_object, child_object) }} IS {{ label|qtLiteral }};
+SECURITY LABEL{% if provider and provider != '' %} FOR {{ conn|qtIdent(provider) }}{% endif %} ON {{ type }} {{ conn|qtIdent(schema_name, parent_object, child_object) }} IS {{ label|qtLiteral }};
 {%- endmacro %}
 {% macro DROP(conn, type, schema_name, parent_object, child_object, provider) -%}
-SECURITY LABEL FOR {{ conn|qtIdent(provider) }} ON {{ type }} {{ conn|qtIdent(schema_name, parent_object, child_object) }} IS NULL;
+SECURITY LABEL{% if provider and provider != '' %} FOR {{ conn|qtIdent(provider) }}{% endif %} ON {{ type }} {{ conn|qtIdent(schema_name, parent_object, child_object) }} IS NULL;
 {%- endmacro %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/functions/security.macros b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/functions/security.macros
index dd2a086..5d9e2a6 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/functions/security.macros
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/functions/security.macros
@@ -2,7 +2,7 @@
 {# Macros for Security Labels (functions module) #}
 {#################################################}
 {% macro SET(conn, type, name, provider, label, schema, func_args) -%}
-SECURITY LABEL FOR {{ provider }} ON {{ type }} {{ conn|qtIdent(schema, name) }}({{func_args}}) IS {{ label|qtLiteral }};
+SECURITY LABEL{% if provider and provider != '' %} FOR {{ conn|qtIdent(provider) }}{% endif %} ON {{ type }} {{ conn|qtIdent(schema, name) }}({{func_args}}) IS {{ label|qtLiteral }};
 {%- endmacro %}
 {% macro UNSET(conn, type, name, provider, schema, func_args) -%}
 SECURITY LABEL FOR {{ provider }} ON {{ type }} {{ conn|qtIdent(schema, name) }}({{func_args}}) IS NULL;
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/schemas/security.macros b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/schemas/security.macros
index e1126b1..7d764c5 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/schemas/security.macros
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/schemas/security.macros
@@ -2,7 +2,7 @@
 {# Macros for schema and its child nodes  #}
 {##########################################}
 {% macro SET(conn, type, name, provider, label, schema) -%}
-SECURITY LABEL FOR {{ provider }} ON {{ type }} {{ conn|qtIdent(schema, name) }} IS {{ label|qtLiteral }};
+SECURITY LABEL FOR{% if provider and provider != '' %} FOR {{ conn|qtIdent(provider) }}{% endif %} ON {{ type }} {{ conn|qtIdent(schema, name) }} IS {{ label|qtLiteral }};
 {%- endmacro %}
 {% macro UNSET(conn, type, name, provider, schema) -%}
 SECURITY LABEL FOR {{ provider }} ON {{ type }} {{ conn|qtIdent(schema, name) }} IS NULL;
diff --git a/web/pgadmin/browser/server_groups/servers/templates/macros/security.macros b/web/pgadmin/browser/server_groups/servers/templates/macros/security.macros
index 83fb9d2..4350f9a 100644
--- a/web/pgadmin/browser/server_groups/servers/templates/macros/security.macros
+++ b/web/pgadmin/browser/server_groups/servers/templates/macros/security.macros
@@ -1,5 +1,5 @@
 {% macro APPLY(conn, type, name, provider, label) -%}
-SECURITY LABEL FOR {{ conn|qtIdent(provider) }} ON {{ type }} {{ conn|qtIdent(name) }} IS {{ label|qtLiteral }};
+SECURITY LABEL{% if provider and provider != '' %} FOR {{ conn|qtIdent(provider) }}{% endif %} ON {{ type }} {{ conn|qtIdent(name) }} IS {{ label|qtLiteral }};
 {%- endmacro %}
 {% macro DROP(conn, type, name, provider) -%}
 SECURITY LABEL FOR {{ conn|qtIdent(provider) }} ON {{ type }} {{ conn|qtIdent(name) }} IS NULL;
diff --git a/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js b/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js
index 1c8bff8..0a64143 100644
--- a/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js
+++ b/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js
@@ -23,14 +23,6 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
           errmsg = null;
         this.errorModel.clear();
 
-        if (_.isUndefined(this.get('provider')) ||
-          _.isNull(this.get('provider')) ||
-          String(this.get('provider')).replace(/^\s+|\s+$/g, '') == '') {
-            errmsg = '{{ _('Provider must be specified.') }}';
-            this.errorModel.set('provider', errmsg);
-            return errmsg;
-        }
-
         if (_.isUndefined(this.get('label')) ||
           _.isNull(this.get('label')) ||
           String(this.get('label')).replace(/^\s+|\s+$/g, '') == '') {


^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4)
  2016-07-22 14:11 PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-22 15:50 ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-25 06:19   ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-25 11:31     ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-26 13:34       ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-26 14:06         ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-26 16:02           ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-27 11:18             ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
@ 2016-07-27 11:34               ` Dave Page <[email protected]>
  2016-07-27 12:37                 ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  0 siblings, 1 reply; 16+ messages in thread

From: Dave Page @ 2016-07-27 11:34 UTC (permalink / raw)
  To: Murtuza Zabuawala <[email protected]>; +Cc: pgadmin-hackers

Hi

On Wed, Jul 27, 2016 at 12:18 PM, Murtuza Zabuawala
<[email protected]> wrote:
> Hi Dave,
>
> 1) Unicode conversion was working properly for function node, It was failing
> due to wrong sql templates.
> - I've fixed them.

I just did a test, and it's still failing - see the attached
screenshot. Aside from the encoding issue, it looks like it's adding
extra quotes around the parameter data type - double-double quoting
the schema and type, and then quoting the whole lot again in the
CREATE part. The ALTER part looks fine.

> 2) Type is also working fine with encoding for me(PFA screenshots), Can you
> please provide error you got?

Hmm, I can't reproduce that now. Weird.

> This patch also makes Provider optional in security label control &
> templates.
>
> -------
> Regarding enforcing to utf-8, In my opinion we can enforce everything to
> utf-8 if we use any of one python version but to make it compatible with
> both python2 and python3 version by forcing utf-8 encoding it will be
> difficult to handle its side effects.

Urgh. Ok, thanks.

> Python2,
>
>>>> txt_sample = 'Hello'
>>>> isinstance(txt_sample, str)
> True
>>>> isinstance(txt_sample, bytes)
> True
>>>> isinstance(txt_sample, unicode)
> False
>>>> txt_sample.encode('utf-8')
> 'Hello'
>>>> txt_sample.decode('utf-8')
> u'Hello'
>
> Forcing to unicode in Python2,
>
>>>> txt_sample = u'Hello'
>>>> isinstance(txt_sample, str)
> False
>>>> isinstance(txt_sample, bytes)
> False
>>>> isinstance(txt_sample, unicode)
> True
>
> Python3,
>
>>>> txt_sample = 'Hello'
>>>> isinstance(txt_sample, str)
> True
>>>> isinstance(txt_sample, bytes)
> False
>>>> txt_sample.encode('utf-8')
> b'Hello'
>>>> txt_sample.decode('utf-8')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> AttributeError: 'str' object has no attribute 'decode'
>
>
> And also psycopg2 driver returns text as string in Python2 even if that text
> contains unicode characters, In python3 that just works fine because string
> is Unicode by default.
>
>
> Regards,
> Murtuza
>
> --
> Regards,
> Murtuza Zabuawala
> EnterpriseDB: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company



-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers


Attachments:

  [image/png] Screen Shot 2016-07-27 at 12.31.21.png (83.5K, 2-Screen%20Shot%202016-07-27%20at%2012.31.21.png)
  download | view image

^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4)
  2016-07-22 14:11 PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-22 15:50 ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-25 06:19   ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-25 11:31     ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-26 13:34       ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-26 14:06         ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-26 16:02           ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-27 11:18             ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-27 11:34               ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
@ 2016-07-27 12:37                 ` Murtuza Zabuawala <[email protected]>
  2016-07-27 14:01                   ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-28 09:56                   ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  0 siblings, 2 replies; 16+ messages in thread

From: Murtuza Zabuawala @ 2016-07-27 12:37 UTC (permalink / raw)
  To: Dave Page <[email protected]>; +Cc: pgadmin-hackers

Okay, Let me check on that.

Meanwhile I'm attaching patch for making Provider optional in security
labels control.

Regards,
Murtuza

--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

On Wed, Jul 27, 2016 at 5:04 PM, Dave Page <[email protected]> wrote:

> Hi
>
> On Wed, Jul 27, 2016 at 12:18 PM, Murtuza Zabuawala
> <[email protected]> wrote:
> > Hi Dave,
> >
> > 1) Unicode conversion was working properly for function node, It was
> failing
> > due to wrong sql templates.
> > - I've fixed them.
>
> I just did a test, and it's still failing - see the attached
> screenshot. Aside from the encoding issue, it looks like it's adding
> extra quotes around the parameter data type - double-double quoting
> the schema and type, and then quoting the whole lot again in the
> CREATE part. The ALTER part looks fine.
>
> > 2) Type is also working fine with encoding for me(PFA screenshots), Can
> you
> > please provide error you got?
>
> Hmm, I can't reproduce that now. Weird.
>
> > This patch also makes Provider optional in security label control &
> > templates.
> >
> > -------
> > Regarding enforcing to utf-8, In my opinion we can enforce everything to
> > utf-8 if we use any of one python version but to make it compatible with
> > both python2 and python3 version by forcing utf-8 encoding it will be
> > difficult to handle its side effects.
>
> Urgh. Ok, thanks.
>
> > Python2,
> >
> >>>> txt_sample = 'Hello'
> >>>> isinstance(txt_sample, str)
> > True
> >>>> isinstance(txt_sample, bytes)
> > True
> >>>> isinstance(txt_sample, unicode)
> > False
> >>>> txt_sample.encode('utf-8')
> > 'Hello'
> >>>> txt_sample.decode('utf-8')
> > u'Hello'
> >
> > Forcing to unicode in Python2,
> >
> >>>> txt_sample = u'Hello'
> >>>> isinstance(txt_sample, str)
> > False
> >>>> isinstance(txt_sample, bytes)
> > False
> >>>> isinstance(txt_sample, unicode)
> > True
> >
> > Python3,
> >
> >>>> txt_sample = 'Hello'
> >>>> isinstance(txt_sample, str)
> > True
> >>>> isinstance(txt_sample, bytes)
> > False
> >>>> txt_sample.encode('utf-8')
> > b'Hello'
> >>>> txt_sample.decode('utf-8')
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in <module>
> > AttributeError: 'str' object has no attribute 'decode'
> >
> >
> > And also psycopg2 driver returns text as string in Python2 even if that
> text
> > contains unicode characters, In python3 that just works fine because
> string
> > is Unicode by default.
> >
> >
> > Regards,
> > Murtuza
> >
> > --
> > Regards,
> > Murtuza Zabuawala
> > EnterpriseDB: http://www.enterprisedb.com
> > The Enterprise PostgreSQL Company
>
>
>
> --
> Dave Page
> Blog: http://pgsnake.blogspot.com
> Twitter: @pgsnake
>
> EnterpriseDB UK: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers


Attachments:

  [application/octet-stream] Fix_SecLabls.patch (5.3K, 3-Fix_SecLabls.patch)
  download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/macros/security.macros b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/macros/security.macros
index 39587c3..1beb259 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/macros/security.macros
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/macros/security.macros
@@ -1,6 +1,6 @@
 {% macro APPLY(conn, type, schema_name, parent_object, child_object, provider, label) -%}
-SECURITY LABEL FOR {{ conn|qtIdent(provider) }} ON {{ type }} {{ conn|qtIdent(schema_name, parent_object, child_object) }} IS {{ label|qtLiteral }};
+SECURITY LABEL{% if provider and provider != '' %} FOR {{ conn|qtIdent(provider) }}{% endif %} ON {{ type }} {{ conn|qtIdent(schema_name, parent_object, child_object) }} IS {{ label|qtLiteral }};
 {%- endmacro %}
 {% macro DROP(conn, type, schema_name, parent_object, child_object, provider) -%}
-SECURITY LABEL FOR {{ conn|qtIdent(provider) }} ON {{ type }} {{ conn|qtIdent(schema_name, parent_object, child_object) }} IS NULL;
+SECURITY LABEL{% if provider and provider != '' %} FOR {{ conn|qtIdent(provider) }}{% endif %} ON {{ type }} {{ conn|qtIdent(schema_name, parent_object, child_object) }} IS NULL;
 {%- endmacro %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/functions/security.macros b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/functions/security.macros
index dd2a086..5d9e2a6 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/functions/security.macros
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/functions/security.macros
@@ -2,7 +2,7 @@
 {# Macros for Security Labels (functions module) #}
 {#################################################}
 {% macro SET(conn, type, name, provider, label, schema, func_args) -%}
-SECURITY LABEL FOR {{ provider }} ON {{ type }} {{ conn|qtIdent(schema, name) }}({{func_args}}) IS {{ label|qtLiteral }};
+SECURITY LABEL{% if provider and provider != '' %} FOR {{ conn|qtIdent(provider) }}{% endif %} ON {{ type }} {{ conn|qtIdent(schema, name) }}({{func_args}}) IS {{ label|qtLiteral }};
 {%- endmacro %}
 {% macro UNSET(conn, type, name, provider, schema, func_args) -%}
 SECURITY LABEL FOR {{ provider }} ON {{ type }} {{ conn|qtIdent(schema, name) }}({{func_args}}) IS NULL;
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/schemas/security.macros b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/schemas/security.macros
index e1126b1..7d764c5 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/schemas/security.macros
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/schemas/security.macros
@@ -2,7 +2,7 @@
 {# Macros for schema and its child nodes  #}
 {##########################################}
 {% macro SET(conn, type, name, provider, label, schema) -%}
-SECURITY LABEL FOR {{ provider }} ON {{ type }} {{ conn|qtIdent(schema, name) }} IS {{ label|qtLiteral }};
+SECURITY LABEL FOR{% if provider and provider != '' %} FOR {{ conn|qtIdent(provider) }}{% endif %} ON {{ type }} {{ conn|qtIdent(schema, name) }} IS {{ label|qtLiteral }};
 {%- endmacro %}
 {% macro UNSET(conn, type, name, provider, schema) -%}
 SECURITY LABEL FOR {{ provider }} ON {{ type }} {{ conn|qtIdent(schema, name) }} IS NULL;
diff --git a/web/pgadmin/browser/server_groups/servers/templates/macros/security.macros b/web/pgadmin/browser/server_groups/servers/templates/macros/security.macros
index 83fb9d2..4350f9a 100644
--- a/web/pgadmin/browser/server_groups/servers/templates/macros/security.macros
+++ b/web/pgadmin/browser/server_groups/servers/templates/macros/security.macros
@@ -1,5 +1,5 @@
 {% macro APPLY(conn, type, name, provider, label) -%}
-SECURITY LABEL FOR {{ conn|qtIdent(provider) }} ON {{ type }} {{ conn|qtIdent(name) }} IS {{ label|qtLiteral }};
+SECURITY LABEL{% if provider and provider != '' %} FOR {{ conn|qtIdent(provider) }}{% endif %} ON {{ type }} {{ conn|qtIdent(name) }} IS {{ label|qtLiteral }};
 {%- endmacro %}
 {% macro DROP(conn, type, name, provider) -%}
 SECURITY LABEL FOR {{ conn|qtIdent(provider) }} ON {{ type }} {{ conn|qtIdent(name) }} IS NULL;
diff --git a/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js b/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js
index 1c8bff8..0a64143 100644
--- a/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js
+++ b/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js
@@ -23,14 +23,6 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
           errmsg = null;
         this.errorModel.clear();
 
-        if (_.isUndefined(this.get('provider')) ||
-          _.isNull(this.get('provider')) ||
-          String(this.get('provider')).replace(/^\s+|\s+$/g, '') == '') {
-            errmsg = '{{ _('Provider must be specified.') }}';
-            this.errorModel.set('provider', errmsg);
-            return errmsg;
-        }
-
         if (_.isUndefined(this.get('label')) ||
           _.isNull(this.get('label')) ||
           String(this.get('label')).replace(/^\s+|\s+$/g, '') == '') {


^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4)
  2016-07-22 14:11 PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-22 15:50 ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-25 06:19   ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-25 11:31     ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-26 13:34       ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-26 14:06         ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-26 16:02           ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-27 11:18             ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-27 11:34               ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-27 12:37                 ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
@ 2016-07-27 14:01                   ` Dave Page <[email protected]>
  1 sibling, 0 replies; 16+ messages in thread

From: Dave Page @ 2016-07-27 14:01 UTC (permalink / raw)
  To: Murtuza Zabuawala <[email protected]>; +Cc: pgadmin-hackers

Thanks - applied!

On Wed, Jul 27, 2016 at 1:37 PM, Murtuza Zabuawala
<[email protected]> wrote:
> Okay, Let me check on that.
>
> Meanwhile I'm attaching patch for making Provider optional in security
> labels control.
>
> Regards,
> Murtuza
>
> --
> Regards,
> Murtuza Zabuawala
> EnterpriseDB: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>
> On Wed, Jul 27, 2016 at 5:04 PM, Dave Page <[email protected]> wrote:
>>
>> Hi
>>
>> On Wed, Jul 27, 2016 at 12:18 PM, Murtuza Zabuawala
>> <[email protected]> wrote:
>> > Hi Dave,
>> >
>> > 1) Unicode conversion was working properly for function node, It was
>> > failing
>> > due to wrong sql templates.
>> > - I've fixed them.
>>
>> I just did a test, and it's still failing - see the attached
>> screenshot. Aside from the encoding issue, it looks like it's adding
>> extra quotes around the parameter data type - double-double quoting
>> the schema and type, and then quoting the whole lot again in the
>> CREATE part. The ALTER part looks fine.
>>
>> > 2) Type is also working fine with encoding for me(PFA screenshots), Can
>> > you
>> > please provide error you got?
>>
>> Hmm, I can't reproduce that now. Weird.
>>
>> > This patch also makes Provider optional in security label control &
>> > templates.
>> >
>> > -------
>> > Regarding enforcing to utf-8, In my opinion we can enforce everything to
>> > utf-8 if we use any of one python version but to make it compatible with
>> > both python2 and python3 version by forcing utf-8 encoding it will be
>> > difficult to handle its side effects.
>>
>> Urgh. Ok, thanks.
>>
>> > Python2,
>> >
>> >>>> txt_sample = 'Hello'
>> >>>> isinstance(txt_sample, str)
>> > True
>> >>>> isinstance(txt_sample, bytes)
>> > True
>> >>>> isinstance(txt_sample, unicode)
>> > False
>> >>>> txt_sample.encode('utf-8')
>> > 'Hello'
>> >>>> txt_sample.decode('utf-8')
>> > u'Hello'
>> >
>> > Forcing to unicode in Python2,
>> >
>> >>>> txt_sample = u'Hello'
>> >>>> isinstance(txt_sample, str)
>> > False
>> >>>> isinstance(txt_sample, bytes)
>> > False
>> >>>> isinstance(txt_sample, unicode)
>> > True
>> >
>> > Python3,
>> >
>> >>>> txt_sample = 'Hello'
>> >>>> isinstance(txt_sample, str)
>> > True
>> >>>> isinstance(txt_sample, bytes)
>> > False
>> >>>> txt_sample.encode('utf-8')
>> > b'Hello'
>> >>>> txt_sample.decode('utf-8')
>> > Traceback (most recent call last):
>> >   File "<stdin>", line 1, in <module>
>> > AttributeError: 'str' object has no attribute 'decode'
>> >
>> >
>> > And also psycopg2 driver returns text as string in Python2 even if that
>> > text
>> > contains unicode characters, In python3 that just works fine because
>> > string
>> > is Unicode by default.
>> >
>> >
>> > Regards,
>> > Murtuza
>> >
>> > --
>> > Regards,
>> > Murtuza Zabuawala
>> > EnterpriseDB: http://www.enterprisedb.com
>> > The Enterprise PostgreSQL Company
>>
>>
>>
>> --
>> Dave Page
>> Blog: http://pgsnake.blogspot.com
>> Twitter: @pgsnake
>>
>> EnterpriseDB UK: http://www.enterprisedb.com
>> The Enterprise PostgreSQL Company
>
>



-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4)
  2016-07-22 14:11 PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-22 15:50 ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-25 06:19   ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-25 11:31     ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-26 13:34       ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-26 14:06         ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-26 16:02           ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-27 11:18             ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-27 11:34               ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-27 12:37                 ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
@ 2016-07-28 09:56                   ` Murtuza Zabuawala <[email protected]>
  2016-08-01 13:21                     ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  1 sibling, 1 reply; 16+ messages in thread

From: Murtuza Zabuawala @ 2016-07-28 09:56 UTC (permalink / raw)
  To: Dave Page <[email protected]>; +Cc: pgadmin-hackers

Hi Dave,

PFA updated patch to fix issue in functions which was due to improper
handing of nested quoting of types in templates.
I also fixed it in Table/Column node.

Please review.

Regards,
Murtuza


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers


Attachments:

  [application/octet-stream] misc_fixes_encoding_and_ident.patch (47.7K, 3-misc_fixes_encoding_and_ident.patch)
  download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/__init__.py
index 33f1d15..3b7c57b 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/__init__.py
@@ -187,6 +187,8 @@ class DatabaseView(PGChildNodeView):
 
         for row in rset['rows']:
             dbname = row['name']
+            if hasattr(str, 'decode'):
+                dbname = dbname.decode('utf-8')
             if self.manager.db == dbname:
                 connected = True
                 canDrop = canDisConn = False
@@ -228,7 +230,10 @@ class DatabaseView(PGChildNodeView):
             return internal_server_error(errormsg=rset)
 
         for row in rset['rows']:
-            if self.manager.db == row['name']:
+            db = row['name']
+            if hasattr(str, 'decode'):
+                db = db.decode('utf-8')
+            if self.manager.db == db:
                 connected = True
             else:
                 conn = self.manager.connection(row['name'])
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py
index aadd466..810bb49 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py
@@ -902,26 +902,35 @@ class FunctionView(PGChildNodeView, DataTypeReader):
         """
         resp_data = self._fetch_properties(gid, sid, did, scid, fnid)
         # Fetch the function definition.
-        args = ''
+        args = u''
+        args_without_name = u''
         cnt = 1
-        if 'arguments' in resp_data:
-            for a in resp_data['arguments']:
-                if (('argmode' in a and a['argmode'] != 'OUT' and
-                    a['argmode'] is not None
-                      ) or 'argnode' not in a):
-                    if 'argmode' in a:
-                        args += a['argmode'] + " "
-                    if 'argname' in a and a['argname'] != ''\
-                            and a['argname'] is not None:
-                        args += self.qtIdent(
-                            self.conn, a['argname']) + " "
-                    if 'argtype' in a:
-                        args += a['argtype']
-                    if cnt < len(resp_data['arguments']):
-                        args += ', '
-                cnt += 1
+        args_list = []
+        if 'arguments' in resp_data and len(resp_data['arguments']) > 0:
+            args_list = resp_data['arguments']
+            resp_data['args'] = resp_data['arguments']
+
+        for a in args_list:
+            if (('argmode' in a and a['argmode'] != 'OUT' and
+                         a['argmode'] is not None
+                 ) or 'argmode' not in a):
+                if 'argmode' in a:
+                    args += a['argmode'] + " "
+                    args_without_name += a['argmode'] + " "
+                if 'argname' in a and a['argname'] != '' \
+                        and a['argname'] is not None:
+                    args += self.qtIdent(
+                        self.conn, a['argname']) + " "
+                if 'argtype' in a:
+                    args += a['argtype']
+                    args_without_name += a['argtype']
+                if cnt < len(args_list):
+                    args += ', '
+                    args_without_name += ', '
+            cnt += 1
 
         resp_data['func_args'] = args.strip(' ')
+        resp_data['func_args_without'] = args_without_name.strip(' ')
 
         if self.node_type == 'procedure':
             object_type = 'procedure'
@@ -960,8 +969,17 @@ class FunctionView(PGChildNodeView, DataTypeReader):
             if not status:
                 return internal_server_error(errormsg=res)
 
-            func_def, name = res['rows'][0]
+            name = res['rows'][0]['name']
             # Create mode
+            if hasattr(str, 'decode'):
+                if resp_data['prosrc']:
+                    resp_data['prosrc'] = resp_data['prosrc'].decode(
+                        'utf-8'
+                    )
+                if resp_data['prosrc_c']:
+                    resp_data['prosrc_c'] = resp_data['prosrc_c'].decode(
+                        'utf-8'
+                    )
             func_def = render_template("/".join([self.sql_template_path,
                                                  'create.sql']),
                                        data=resp_data, query_type="create")
@@ -1138,25 +1156,34 @@ class FunctionView(PGChildNodeView, DataTypeReader):
                     data['acl'] = parse_priv_to_db(data['acl'], ["X"])
 
                 args = u''
+                args_without_name = u''
                 cnt = 1
-                if 'arguments' in data:
-                    for a in data['arguments']:
-                        if (('argmode' in a and a['argmode'] != 'OUT' and
-                                     a['argmode'] is not None
-                             ) or 'argnode' not in a):
-                            if 'argmode' in a:
-                                args += a['argmode'] + " "
-                            if 'argname' in a and a['argname'] != '' \
-                                    and a['argname'] is not None:
-                                args += self.qtIdent(
-                                    self.conn, a['argname']) + " "
-                            if 'argtype' in a:
-                                args += a['argtype']
-                            if cnt < len(data['arguments']):
-                                args += ', '
-                        cnt += 1
+                args_list = []
+                if 'arguments' in data and len(data['arguments']) > 0:
+                    args_list = data['arguments']
+                elif 'args' in data and len(data['args']) > 0:
+                    args_list = data['args']
+                for a in args_list:
+                    if (('argmode' in a and a['argmode'] != 'OUT' and
+                                 a['argmode'] is not None
+                         ) or 'argmode' not in a):
+                        if 'argmode' in a:
+                            args += a['argmode'] + " "
+                            args_without_name += a['argmode'] + " "
+                        if 'argname' in a and a['argname'] != '' \
+                                and a['argname'] is not None:
+                            args += self.qtIdent(
+                                self.conn, a['argname']) + " "
+                        if 'argtype' in a:
+                            args += a['argtype']
+                            args_without_name += a['argtype']
+                        if cnt < len(args_list):
+                            args += ', '
+                            args_without_name += ', '
+                    cnt += 1
 
                 data['func_args'] = args.strip(' ')
+                data['func_args_without'] = args_without_name.strip(' ')
                 # Create mode
                 SQL = render_template("/".join([self.sql_template_path,
                                                 'create.sql']),
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.1_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.1_plus/create.sql
index efd7775..4566d06 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.1_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.1_plus/create.sql
@@ -4,19 +4,10 @@
 {% set is_columns = [] %}
 {% if data %}
 CREATE{% if query_type is defined %}{{' OR REPLACE'}}{% endif %} FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({% if data.args %}
-{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}}{% endif %}{% if p.argtype %}{{ conn|qtIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
+{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}}{% endif %}{% if p.argtype %}{{ conn|qtTypeIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
 {% if not loop.last %},{% endif %}
 {% endfor %}
 {% endif -%}
-{% if data.func_args %}
-{% set func_args = data.func_args.split(',') %}
-
-{% for f in func_args %}
-    {{ f|trim }}{% if not loop.last %},
-{% endif %}
-{% endfor %}
-
-{% endif %}
 )
     RETURNS{% if data.proretset %} SETOF{% endif %} {{ conn|qtTypeIdent(data.prorettypename) }}
     LANGUAGE {{ data.lanname|qtLiteral }}
@@ -39,24 +30,24 @@ $function$
 $function${% endif %};
 {% if data.funcowner %}
 
-ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
+ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
     OWNER TO {{ data.funcowner }};
 {% endif %}
 {% if data.acl %}
 {% for p in data.acl %}
 
-{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
+{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
 {% endfor %}{% endif %}
 {% if data.description %}
 
-COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
 {% if r.label and r.provider %}
 
-{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
+{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
 {% endif %}
 {% endfor %}
 {% endif -%}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.2_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.2_plus/create.sql
index 63585ad..dda39cf 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.2_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.2_plus/create.sql
@@ -4,19 +4,10 @@
 {% set is_columns = [] %}
 {% if data %}
 CREATE{% if query_type is defined %}{{' OR REPLACE'}}{% endif %} FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({% if data.args %}
-{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}}{% endif %}{% if p.argtype %}{{ conn|qtIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
+{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtTypeIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
 {% if not loop.last %},{% endif %}
 {% endfor %}
 {% endif -%}
-{% if data.func_args %}
-{% set func_args = data.func_args.split(',') %}
-
-{% for f in func_args %}
-    {{ f|trim }}{% if not loop.last %},
-{% endif %}
-{% endfor %}
-
-{% endif %}
 )
     RETURNS{% if data.proretset %} SETOF{% endif %} {{ conn|qtTypeIdent(data.prorettypename) }}
     LANGUAGE {{ data.lanname|qtLiteral }}
@@ -43,25 +34,25 @@ $function$
 $function${% endif -%};
 {% if data.funcowner %}
 
-ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
+ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
     OWNER TO {{ data.funcowner }};
 {% endif -%}
 {% if data.acl %}
 {% for p in data.acl %}
 
-{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
+{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
 {% endfor -%}
 {% endif -%}
 {% if data.description %}
 
-COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
 {% if r.label and r.provider %}
 
-{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
+{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
 {% endif %}
 {% endfor %}
 {% endif -%}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.5_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.5_plus/create.sql
index 45a9c61..0668313 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.5_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.5_plus/create.sql
@@ -8,15 +8,6 @@ CREATE{% if query_type is defined %}{{' OR REPLACE'}}{% endif %} FUNCTION {{ con
 {% if not loop.last %},{% endif %}
 {% endfor %}
 {% endif -%}
-{% if data.func_args %}
-{% set func_args = data.func_args.split(',') %}
-
-{% for f in func_args %}
-    {{ f|trim }}{% if not loop.last %},
-{% endif %}
-{% endfor %}
-
-{% endif %}
 )
     RETURNS{% if data.proretset %} SETOF{% endif %} {{ conn|qtTypeIdent(data.prorettypename) }}
     LANGUAGE {{ data.lanname|qtLiteral }}
@@ -43,24 +34,24 @@ $function$
 $function${% endif -%};
 {% if data.funcowner %}
 
-ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
+ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
     OWNER TO {{ data.funcowner }};
 {% endif -%}
 {% if data.acl %}
 {% for p in data.acl %}
 
-{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
+{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
 {% endfor %}{% endif %}
 {% if data.description %}
 
-COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
 {% if r.label and r.provider %}
 
-{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
+{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
 {% endif %}
 {% endfor %}
 {% endif -%}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.1_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.1_plus/create.sql
index efd7775..10589ce 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.1_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.1_plus/create.sql
@@ -4,19 +4,10 @@
 {% set is_columns = [] %}
 {% if data %}
 CREATE{% if query_type is defined %}{{' OR REPLACE'}}{% endif %} FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({% if data.args %}
-{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}}{% endif %}{% if p.argtype %}{{ conn|qtIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
+{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtTypeIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
 {% if not loop.last %},{% endif %}
 {% endfor %}
 {% endif -%}
-{% if data.func_args %}
-{% set func_args = data.func_args.split(',') %}
-
-{% for f in func_args %}
-    {{ f|trim }}{% if not loop.last %},
-{% endif %}
-{% endfor %}
-
-{% endif %}
 )
     RETURNS{% if data.proretset %} SETOF{% endif %} {{ conn|qtTypeIdent(data.prorettypename) }}
     LANGUAGE {{ data.lanname|qtLiteral }}
@@ -39,24 +30,24 @@ $function$
 $function${% endif %};
 {% if data.funcowner %}
 
-ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
+ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
     OWNER TO {{ data.funcowner }};
 {% endif %}
 {% if data.acl %}
 {% for p in data.acl %}
 
-{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
+{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
 {% endfor %}{% endif %}
 {% if data.description %}
 
-COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
 {% if r.label and r.provider %}
 
-{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
+{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
 {% endif %}
 {% endfor %}
 {% endif -%}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.2_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.2_plus/create.sql
index 516e6d4..77ed284 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.2_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.2_plus/create.sql
@@ -4,19 +4,10 @@
 {% set is_columns = [] %}
 {% if data %}
 CREATE{% if query_type is defined %}{{' OR REPLACE'}}{% endif %} FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({% if data.args %}
-{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}}{% endif %}{% if p.argtype %}{{ conn|qtIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
+{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtTypeIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
 {% if not loop.last %},{% endif %}
 {% endfor %}
 {% endif -%}
-{% if data.func_args %}
-{% set func_args = data.func_args.split(',') %}
-
-{% for f in func_args %}
-    {{ f|trim }}{% if not loop.last %},
-{% endif %}
-{% endfor %}
-
-{% endif %}
 )
     RETURNS{% if data.proretset %} SETOF{% endif %} {{ conn|qtTypeIdent(data.prorettypename) }}
     LANGUAGE {{ data.lanname|qtLiteral }}
@@ -43,25 +34,25 @@ $function$
 $function${% endif -%};
 {% if data.funcowner %}
 
-ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
+ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
     OWNER TO {{ data.funcowner }};
 {% endif -%}
 {% if data.acl %}
 {% for p in data.acl %}
 
-{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
+{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_withouts)}}
 {% endfor -%}
 {% endif -%}
 {% if data.description %}
 
-COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
 {% if r.label and r.provider %}
 
-{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
+{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args_withouts) }}
 {% endif %}
 {% endfor %}
 {% endif -%}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.5_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.5_plus/create.sql
index b5b7176..77034be 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.5_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.5_plus/create.sql
@@ -31,24 +31,24 @@ $function$
 $function${% endif -%};
 {% if data.funcowner %}
 
-ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
+ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
     OWNER TO {{ data.funcowner }};
 {% endif -%}
 {% if data.acl %}
 {% for p in data.acl %}
 
-{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
+{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
 {% endfor %}{% endif %}
 {% if data.description %}
 
-COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
 {% if r.label and r.provider %}
 
-{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
+{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
 {% endif %}
 {% endfor %}
 {% endif -%}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.1_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.1_plus/create.sql
index 0a8cb20..235f9c6 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.1_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.1_plus/create.sql
@@ -3,11 +3,10 @@
 {% import 'macros/functions/variable.macros' as VARIABLE %}
 {% set is_columns = [] %}
 {% if data %}
-CREATE OR REPLACE PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}{% if data.args is defined or data.func_args is defined %}
-({% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
+CREATE OR REPLACE PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}{% if data.args is defined %}
+({% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtTypeIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
 {% if not loop.last %}, {% endif %}
 {% endfor -%}
-{% if data.func_args %}{{ data.func_args }}{% endif %}
 ){% endif %}
 
 AS
@@ -15,18 +14,18 @@ AS
 {% if data.acl and not is_sql %}
 {% for p in data.acl %}
 
-{{ PRIVILEGE.SET(conn, "PROCEDURE", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
+{{ PRIVILEGE.SET(conn, "PROCEDURE", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
 {% endfor %}{% endif %}
 {% if data.description %}
 
 COMMENT ON PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}
-    IS '{{ data.description }}';
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
 {% if r.label and r.provider %}
 
-{{ SECLABEL.SET(conn, 'PROCEDURE', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
+{{ SECLABEL.SET(conn, 'PROCEDURE', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
 {% endif %}
 {% endfor %}
 {% endif -%}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.2_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.2_plus/create.sql
index 073ce1d..3a211f2 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.2_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.2_plus/create.sql
@@ -3,11 +3,10 @@
 {% import 'macros/functions/variable.macros' as VARIABLE %}
 {% set is_columns = [] %}
 {% if data %}
-CREATE OR REPLACE PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}{% if data.args is defined or data.func_args is defined %}
-({% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
+CREATE OR REPLACE PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}{% if data.args is defined %}
+({% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtTypeIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
  {% if not loop.last %}, {% endif %}
 {% endfor -%}
-{% if data.func_args %}{{ data.func_args }}{% endif %}
 ){% endif %}
 
 AS
@@ -15,18 +14,18 @@ AS
 {% if data.acl and not is_sql %}
 {% for p in data.acl %}
 
-{{ PRIVILEGE.SET(conn, "PROCEDURE", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
+{{ PRIVILEGE.SET(conn, "PROCEDURE", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
 {% endfor %}{% endif %}
 {% if data.description %}
 
 COMMENT ON PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}
-    IS '{{ data.description }}';
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
 {% if r.label and r.provider %}
 
-{{ SECLABEL.SET(conn, 'PROCEDURE', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
+{{ SECLABEL.SET(conn, 'PROCEDURE', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
 {% endif %}
 {% endfor %}
 {% endif -%}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.5_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.5_plus/create.sql
index f1a40af..d0682aa 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.5_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.5_plus/create.sql
@@ -3,11 +3,10 @@
 {% import 'macros/functions/variable.macros' as VARIABLE %}
 {% set is_columns = [] %}
 {% if data %}
-CREATE OR REPLACE PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}{% if data.args is defined or data.func_args is defined %}
+CREATE OR REPLACE PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}{% if data.args is defined %}
 ({% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtTypeIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
 {% if not loop.last %}, {% endif %}
 {% endfor -%}
-{% if data.func_args %}{{ data.func_args }}{% endif %}
 ){% endif %}
 {% if query_type != 'create' %}
 
@@ -27,18 +26,18 @@ AS
 {% if data.acl and not is_sql %}
 {% for p in data.acl %}
 
-{{ PRIVILEGE.SET(conn, "PROCEDURE", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
+{{ PRIVILEGE.SET(conn, "PROCEDURE", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
 {% endfor %}{% endif %}
 {% if data.description %}
 
 COMMENT ON PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}
-    IS '{{ data.description }}';
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
 {% if r.label and r.provider %}
 
-{{ SECLABEL.SET(conn, 'PROCEDURE', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
+{{ SECLABEL.SET(conn, 'PROCEDURE', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
 {% endif %}
 {% endfor %}
 {% endif -%}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.1_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.1_plus/create.sql
index 6e9fd78..0a776f3 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.1_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.1_plus/create.sql
@@ -37,7 +37,7 @@ ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args
 {% if data.description %}
 
 COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.2_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.2_plus/create.sql
index 7ca4bf1..412b02e 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.2_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.2_plus/create.sql
@@ -42,7 +42,7 @@ ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args
 {% if data.description %}
 
 COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.5_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.5_plus/create.sql
index 5445855..aaa31e0 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.5_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.5_plus/create.sql
@@ -40,7 +40,7 @@ ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args
 {% if data.description %}
 
 COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.1_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.1_plus/create.sql
index 6e9fd78..0a776f3 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.1_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.1_plus/create.sql
@@ -37,7 +37,7 @@ ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args
 {% if data.description %}
 
 COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.2_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.2_plus/create.sql
index 210cf3a..ef64d20 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.2_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.2_plus/create.sql
@@ -41,7 +41,7 @@ ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args
 {% if data.description %}
 
 COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.5_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.5_plus/create.sql
index 5c7c568..91f1de6 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.5_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.5_plus/create.sql
@@ -21,7 +21,7 @@ CREATE FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}()
     SET {{ conn|qtIdent(v.name) }}={{ v.value|qtLiteral }}{% endfor %}
 {% endif %}
 
-+AS {% endif %}{% if data.lanname == 'c' %}
+AS {% endif %}{% if data.lanname == 'c' %}
 {{ data.probin|qtLiteral }}, {{ data.prosrc_c|qtLiteral }}
 {% else %}
 $BODY$
@@ -40,7 +40,7 @@ ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args
 {% if data.description %}
 
 COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
-    IS '{{ data.description }}';
+    IS {{ data.description|qtLiteral  }};
 {% endif -%}
 {% if data.seclabels %}
 {% for r in data.seclabels %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
index d4d1885..02057bf 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
@@ -681,6 +681,10 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
                 if isArray:
                     column['cltype'] += "[]"
 
+                if column['typnspname'] != 'pg_catalog':
+                    column['cltype'] = self.qtIdent(self.conn, column['typnspname']) \
+                                       + '.' + column['cltype']
+
                 if 'indkey' in column:
                     # Current column
                     attnum = str(column['attnum'])
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/__init__.py
index 78493b6..b67783c 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/__init__.py
@@ -435,6 +435,10 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
         if isArray:
             data['cltype'] += "[]"
 
+        if data['typnspname'] != 'pg_catalog':
+            data['cltype'] = self.qtIdent(self.conn, data['typnspname'])\
+                             + '.' + data['cltype']
+
         return data
 
     @check_precondition
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.1_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.1_plus/create.sql
index 5f04b6e..434858b 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.1_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.1_plus/create.sql
@@ -4,7 +4,7 @@
 {###  Add column ###}
 {% if data.name and  data.cltype %}
 ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
-    ADD COLUMN {{conn|qtIdent(data.name)}} {{data.cltype}}{% if data.attlen %}
+    ADD COLUMN {{conn|qtIdent(data.name)}} {{conn|qtTypeIdent(data.cltype)}}{% if data.attlen %}
 ({{data.attlen}}{% if data.attprecision%}, {{data.attprecision}}{% endif %}){% endif %}{% if data.hasSqrBracket %}
 []{% endif %}{% if data.collspcname %}
  COLLATE {{data.collspcname}}{% endif %}{% if data.attnotnull %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.1_plus/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.1_plus/update.sql
index 7b26dd7..500d534 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.1_plus/update.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.1_plus/update.sql
@@ -10,7 +10,7 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
 {###  Alter column type and collation ###}
 {% if (data.cltype and data.cltype != o_data.cltype) or (data.attlen and data.attlen != o_data.attlen) or (data.attprecision and data.attprecision != o_data.attprecision) %}
 ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
-    ALTER COLUMN {{conn|qtIdent(data.name)}} TYPE {% if data.cltype %}{{data.cltype}} {% else %}{{o_data.cltype}} {% endif %}{% if data.attlen %}
+    ALTER COLUMN {{conn|qtIdent(data.name)}} TYPE {% if data.cltype %}{{conn|qtTypeIdent(data.cltype)}} {% else %}{{o_data.cltype}} {% endif %}{% if data.attlen %}
 ({{data.attlen}}{% if data.attprecision%}, {{data.attprecision}}{% endif %}){% endif %}{% if data.hasSqrBracket %}
 []{% endif %}{% if data.collspcname and data.collspcname != o_data.collspcname %}
  COLLATE {{data.collspcname}}{% endif %};
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.2_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.2_plus/create.sql
index 5f04b6e..434858b 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.2_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.2_plus/create.sql
@@ -4,7 +4,7 @@
 {###  Add column ###}
 {% if data.name and  data.cltype %}
 ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
-    ADD COLUMN {{conn|qtIdent(data.name)}} {{data.cltype}}{% if data.attlen %}
+    ADD COLUMN {{conn|qtIdent(data.name)}} {{conn|qtTypeIdent(data.cltype)}}{% if data.attlen %}
 ({{data.attlen}}{% if data.attprecision%}, {{data.attprecision}}{% endif %}){% endif %}{% if data.hasSqrBracket %}
 []{% endif %}{% if data.collspcname %}
  COLLATE {{data.collspcname}}{% endif %}{% if data.attnotnull %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.2_plus/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.2_plus/update.sql
index 4d6a9fe..6d0b04b 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.2_plus/update.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.2_plus/update.sql
@@ -10,7 +10,7 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
 {###  Alter column type and collation ###}
 {% if (data.cltype and data.cltype != o_data.cltype) or (data.attlen and data.attlen != o_data.attlen) or (data.attprecision and data.attprecision != o_data.attprecision) %}
 ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
-    ALTER COLUMN {{conn|qtIdent(data.name)}} TYPE {% if data.cltype %}{{data.cltype}} {% else %}{{o_data.cltype}} {% endif %}{% if data.attlen %}
+    ALTER COLUMN {{conn|qtIdent(data.name)}} TYPE {% if data.cltype %}{{conn|qtTypeIdent(data.cltype)}} {% else %}{{o_data.cltype}} {% endif %}{% if data.attlen %}
 ({{data.attlen}}{% if data.attprecision%}, {{data.attprecision}}{% endif %}){% endif %}{% if data.hasSqrBracket %}
 []{% endif %}{% if data.collspcname and data.collspcname != o_data.collspcname %}
  COLLATE {{data.collspcname}}{% endif %};
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.1_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.1_plus/create.sql
index 71ac1c6..3805741 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.1_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.1_plus/create.sql
@@ -17,7 +17,7 @@
 {% endif %}
 CREATE {% if data.relpersistence %}UNLOGGED {% endif %}TABLE {{conn|qtIdent(data.schema, data.name)}}{{empty_bracket}}
 {% if data.typname %}
-    OF {{ data.typname }}
+    OF {{ conn|qtTypeIdent(data.typname) }}
 {% endif %}
 {% if data.like_relation or data.coll_inherits or data.columns|length > 0 or data.primary_key|length > 0 or data.unique_constraint|length > 0 or data.foreign_key|length > 0 or data.check_constraint|length > 0 or data.exclude_constraint|length > 0 %}
 (
@@ -43,7 +43,7 @@ CREATE {% if data.relpersistence %}UNLOGGED {% endif %}TABLE {{conn|qtIdent(data
 {% if c.name and c.cltype %}
 {% if loop.index != 1 %},
 {% endif %}
-    {{conn|qtIdent(c.name)}} {{c.cltype}}{% if c.attlen %}
+    {{conn|qtIdent(c.name)}} {{conn|qtTypeIdent(c.cltype)}}{% if c.attlen %}
 ({{c.attlen}}{% if c.attprecision%}, {{c.attprecision}}{% endif %}){% endif %}{% if c.hasSqrBracket %}
 []{% endif %}{% if c.collspcname %} COLLATE {{c.collspcname}}{% endif %}{% if c.attnotnull %} NOT NULL{% endif %}{% if c.defval %} DEFAULT {{c.defval}}{% endif %}
 {% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.5_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.5_plus/create.sql
index 71ac1c6..3805741 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.5_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.5_plus/create.sql
@@ -17,7 +17,7 @@
 {% endif %}
 CREATE {% if data.relpersistence %}UNLOGGED {% endif %}TABLE {{conn|qtIdent(data.schema, data.name)}}{{empty_bracket}}
 {% if data.typname %}
-    OF {{ data.typname }}
+    OF {{ conn|qtTypeIdent(data.typname) }}
 {% endif %}
 {% if data.like_relation or data.coll_inherits or data.columns|length > 0 or data.primary_key|length > 0 or data.unique_constraint|length > 0 or data.foreign_key|length > 0 or data.check_constraint|length > 0 or data.exclude_constraint|length > 0 %}
 (
@@ -43,7 +43,7 @@ CREATE {% if data.relpersistence %}UNLOGGED {% endif %}TABLE {{conn|qtIdent(data
 {% if c.name and c.cltype %}
 {% if loop.index != 1 %},
 {% endif %}
-    {{conn|qtIdent(c.name)}} {{c.cltype}}{% if c.attlen %}
+    {{conn|qtIdent(c.name)}} {{conn|qtTypeIdent(c.cltype)}}{% if c.attlen %}
 ({{c.attlen}}{% if c.attprecision%}, {{c.attprecision}}{% endif %}){% endif %}{% if c.hasSqrBracket %}
 []{% endif %}{% if c.collspcname %} COLLATE {{c.collspcname}}{% endif %}{% if c.attnotnull %} NOT NULL{% endif %}{% if c.defval %} DEFAULT {{c.defval}}{% endif %}
 {% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py
index e10cf98..2411638 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py
@@ -134,8 +134,15 @@ class DataTypeReader:
                     else:
                         max_val = 10
 
+                # If schema is not pg_catalog & then add schema
+                if row['nspname'] != 'pg_catalog' \
+                        and row['nspname'] == 'public':
+                    rtn_type = row['nspname'] + "." + row['typname']
+                else:
+                    rtn_type = row['typname']
+
                 res.append({
-                    'label': row['typname'], 'value': row['typname'],
+                    'label': rtn_type, 'value': rtn_type,
                     'typval': typeval, 'precision': precision,
                     'length': length, 'min_val': min_val, 'max_val': max_val,
                     'is_collatable': row['is_collatable']
diff --git a/web/pgadmin/utils/driver/psycopg2/__init__.py b/web/pgadmin/utils/driver/psycopg2/__init__.py
index 41a7e62..fbde603 100644
--- a/web/pgadmin/utils/driver/psycopg2/__init__.py
+++ b/web/pgadmin/utils/driver/psycopg2/__init__.py
@@ -591,7 +591,6 @@ Attempt to reconnect it failed with the error:
         try:
             self.__internal_blocking_execute(cur, query, params)
         except psycopg2.Error as pe:
-            current_app.logger.exception(pe)
             cur.close()
             errmsg = self._formatted_exception_msg(pe, formatted_exception_msg)
             current_app.logger.error(
@@ -1115,6 +1114,9 @@ Failed to reset the connection to the server due to following error:
             errmsg = exception_obj.diag.message_detail
         else:
             errmsg = str(exception_obj)
+        # errmsg might contains encoded value, lets decode it
+        if hasattr(str, 'decode'):
+            errmsg = errmsg.decode('utf-8')
 
         # if formatted_msg is false then return from the function
         if not formatted_msg:
@@ -1663,6 +1665,12 @@ class Driver(BaseDriver):
         ]:
             return False
 
+        # If already quoted?, If yes then do not quote again
+        if forTypes and valNoArray:
+            if valNoArray.startswith('"') \
+                    or valNoArray.endswith('"'):
+                return False
+
         if u'0' <= valNoArray[0] <= u'9':
             return True
 
@@ -1697,7 +1705,13 @@ class Driver(BaseDriver):
         for val in args:
             if len(val) == 0:
                 continue
-
+            if hasattr(str, 'decode') and not isinstance(val, unicode):
+                # Handling for python2
+                try:
+                    val = str(val).encode('utf-8')
+                except UnicodeDecodeError:
+                    # If already unicode, most likely coming from db
+                    val = str(val).decode('utf-8')
             value = val
 
             if (Driver.needsQuoting(val, True)):


^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4)
  2016-07-22 14:11 PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-22 15:50 ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-25 06:19   ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-25 11:31     ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-26 13:34       ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-26 14:06         ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-26 16:02           ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-27 11:18             ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-27 11:34               ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-27 12:37                 ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-28 09:56                   ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
@ 2016-08-01 13:21                     ` Dave Page <[email protected]>
  2016-08-01 13:33                       ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  0 siblings, 1 reply; 16+ messages in thread

From: Dave Page @ 2016-08-01 13:21 UTC (permalink / raw)
  To: Murtuza Zabuawala <[email protected]>; +Cc: pgadmin-hackers

Hi

On Thu, Jul 28, 2016 at 10:56 AM, Murtuza Zabuawala
<[email protected]> wrote:
> Hi Dave,
>
> PFA updated patch to fix issue in functions which was due to improper
> handing of nested quoting of types in templates.
> I also fixed it in Table/Column node.
>
> Please review.

This doesn't seem right to me:

                # If schema is not pg_catalog & then add schema
                if row['nspname'] != 'pg_catalog' \
                        and row['nspname'] == 'public':
                    rtn_type = row['nspname'] + "." + row['typname']
                else:
                    rtn_type = row['typname']

Shouldn't the "and row['nspname'] == 'public'" be removed?

-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4)
  2016-07-22 14:11 PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-22 15:50 ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-25 06:19   ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-25 11:31     ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-26 13:34       ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-26 14:06         ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-26 16:02           ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-27 11:18             ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-27 11:34               ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-27 12:37                 ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-28 09:56                   ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-08-01 13:21                     ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
@ 2016-08-01 13:33                       ` Murtuza Zabuawala <[email protected]>
  2016-08-01 13:46                         ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  0 siblings, 1 reply; 16+ messages in thread

From: Murtuza Zabuawala @ 2016-08-01 13:33 UTC (permalink / raw)
  To: Dave Page <[email protected]>; +Cc: pgadmin-hackers

Hi Dave,

We have to added it because postgres format_type() function do not provide
us type with 'public' schema prefix to it, due to which wrong SQL's are
getting generated.
Rest other types are pre fixed with their respective schema as required.


Thanks,
Murtuza


--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

On Mon, Aug 1, 2016 at 6:51 PM, Dave Page <[email protected]> wrote:

> Hi
>
> On Thu, Jul 28, 2016 at 10:56 AM, Murtuza Zabuawala
> <[email protected]> wrote:
> > Hi Dave,
> >
> > PFA updated patch to fix issue in functions which was due to improper
> > handing of nested quoting of types in templates.
> > I also fixed it in Table/Column node.
> >
> > Please review.
>
> This doesn't seem right to me:
>
>                 # If schema is not pg_catalog & then add schema
>                 if row['nspname'] != 'pg_catalog' \
>                         and row['nspname'] == 'public':
>                     rtn_type = row['nspname'] + "." + row['typname']
>                 else:
>                     rtn_type = row['typname']
>
> Shouldn't the "and row['nspname'] == 'public'" be removed?
>
> --
> Dave Page
> Blog: http://pgsnake.blogspot.com
> Twitter: @pgsnake
>
> EnterpriseDB UK: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>


^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4)
  2016-07-22 14:11 PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-22 15:50 ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-25 06:19   ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-25 11:31     ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-26 13:34       ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-26 14:06         ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-26 16:02           ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-27 11:18             ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-27 11:34               ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-27 12:37                 ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-28 09:56                   ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-08-01 13:21                     ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-08-01 13:33                       ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
@ 2016-08-01 13:46                         ` Dave Page <[email protected]>
  2016-08-01 14:24                           ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  0 siblings, 1 reply; 16+ messages in thread

From: Dave Page @ 2016-08-01 13:46 UTC (permalink / raw)
  To: Murtuza Zabuawala <[email protected]>; +Cc: pgadmin-hackers

On Mon, Aug 1, 2016 at 2:33 PM, Murtuza Zabuawala
<[email protected]> wrote:
> Hi Dave,
>
> We have to added it because postgres format_type() function do not provide
> us type with 'public' schema prefix to it, due to which wrong SQL's are
> getting generated.
> Rest other types are pre fixed with their respective schema as required.

OK, so:

                # If schema is not pg_catalog & then add schema
                if row['nspname'] == 'public':
                    rtn_type = row['nspname'] + "." + row['typname']
                else:
                    rtn_type = row['typname']

?

!= pg_catalog is redundant with == public.

-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4)
  2016-07-22 14:11 PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-22 15:50 ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-25 06:19   ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-25 11:31     ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-26 13:34       ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-26 14:06         ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-26 16:02           ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-27 11:18             ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-27 11:34               ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-07-27 12:37                 ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-07-28 09:56                   ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-08-01 13:21                     ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
  2016-08-01 13:33                       ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
  2016-08-01 13:46                         ` Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) Dave Page <[email protected]>
@ 2016-08-01 14:24                           ` Dave Page <[email protected]>
  0 siblings, 0 replies; 16+ messages in thread

From: Dave Page @ 2016-08-01 14:24 UTC (permalink / raw)
  To: Murtuza Zabuawala <[email protected]>; pgadmin-hackers

On Mon, Aug 1, 2016 at 2:53 PM, Murtuza Zabuawala
<[email protected]> wrote:
> Yes... :-)

OK, committed with the following:

                # If schema is public, prefix it. Otherwise, we should
already have it.
                if row['nspname'] == 'public':
                    rtn_type = "public." + row['typname']
                else:
                    rtn_type = row['typname']

> On Mon, Aug 1, 2016 at 7:16 PM, Dave Page <[email protected]> wrote:
>>
>> On Mon, Aug 1, 2016 at 2:33 PM, Murtuza Zabuawala
>> <[email protected]> wrote:
>> > Hi Dave,
>> >
>> > We have to added it because postgres format_type() function do not
>> > provide
>> > us type with 'public' schema prefix to it, due to which wrong SQL's are
>> > getting generated.
>> > Rest other types are pre fixed with their respective schema as required.
>>
>> OK, so:
>>
>>                 # If schema is not pg_catalog & then add schema
>>                 if row['nspname'] == 'public':
>>                     rtn_type = row['nspname'] + "." + row['typname']
>>                 else:
>>                     rtn_type = row['typname']
>>
>> ?
>>
>> != pg_catalog is redundant with == public.
>>
>> --
>> Dave Page
>> Blog: http://pgsnake.blogspot.com
>> Twitter: @pgsnake
>>
>> EnterpriseDB UK: http://www.enterprisedb.com
>> The Enterprise PostgreSQL Company
>
>



-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers




^ permalink  raw  reply  [nested|flat] 16+ messages in thread


end of thread, other threads:[~2016-08-01 14:24 UTC | newest]

Thread overview: 16+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-07-22 14:11 PATCH: Encoding issue with qtLiteral function (pgAdmin4) Murtuza Zabuawala <[email protected]>
2016-07-22 15:50 ` Dave Page <[email protected]>
2016-07-25 06:19   ` Murtuza Zabuawala <[email protected]>
2016-07-25 11:31     ` Dave Page <[email protected]>
2016-07-26 13:34       ` Murtuza Zabuawala <[email protected]>
2016-07-26 14:06         ` Dave Page <[email protected]>
2016-07-26 16:02           ` Dave Page <[email protected]>
2016-07-27 11:18             ` Murtuza Zabuawala <[email protected]>
2016-07-27 11:34               ` Dave Page <[email protected]>
2016-07-27 12:37                 ` Murtuza Zabuawala <[email protected]>
2016-07-27 14:01                   ` Dave Page <[email protected]>
2016-07-28 09:56                   ` Murtuza Zabuawala <[email protected]>
2016-08-01 13:21                     ` Dave Page <[email protected]>
2016-08-01 13:33                       ` Murtuza Zabuawala <[email protected]>
2016-08-01 13:46                         ` Dave Page <[email protected]>
2016-08-01 14:24                           ` Dave Page <[email protected]>

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