Hi,
Please find updated patch for RM2244.
Changes: View Data was broken in last patch when table contains more that 1
column.
--
*Harshal Dhumal*
*Software Engineer*
EnterpriseDB India: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
On Mon, Mar 20, 2017 at 4:10 PM, Dave Page <[email protected]> wrote:
> Hi
>
> On Sat, Mar 18, 2017 at 2:57 PM, Harshal Dhumal
> <[email protected]> wrote:
> >
> > Please find attached patch for RM2244.
>
> If I run View Data on the table below, I see the following exception
> and no grid is rendered:
>
> CREATE TABLE public.varchar_test
> (
> id integer NOT NULL DEFAULT nextval('varchar_test_id_seq'::regclass),
> data character varying(10) COLLATE pg_catalog."default",
> CONSTRAINT varchar_test_pkey PRIMARY KEY (id)
> )
> WITH (
> OIDS = FALSE
> )
> TABLESPACE pg_default;
>
> ALTER TABLE public.varchar_test
> OWNER to postgres;
>
>
>
>
> 2017-03-20 10:37:49,711: SQL pgadmin: Execute (async) for server #1 -
> CONN:1470698 (Query-id: 4557394):
> SELECT * FROM public.varchar_test
> ORDER BY id ASC
> 2017-03-20 10:37:49,714: INFO werkzeug: 127.0.0.1 - - [20/Mar/2017
> 10:37:49] "GET /sqleditor/view_data/start/2408862 HTTP/1.1" 200 -
> 2017-03-20 10:37:49,749: SQL pgadmin: Polling result for (Query-id:
> 4557394)
> 2017-03-20 10:37:49,749: SQL pgadmin: Status message for (Query-id:
> 4557394)
> 2017-03-20 10:37:49,750: INFO werkzeug: 127.0.0.1 - - [20/Mar/2017
> 10:37:49] "GET /sqleditor/poll/2408862 HTTP/1.1" 200 -
> 2017-03-20 10:37:49,779: INFO werkzeug: 127.0.0.1 - - [20/Mar/2017
> 10:37:49] "GET /sqleditor/columns/2408862 HTTP/1.1" 200 -
> 2017-03-20 10:37:49,808: SQL pgadmin: Execute (dict) for server #1 -
> CONN:1470698 (Query-id: 9451779):
> SELECT oid, format_type(oid,null) as typname FROM pg_type WHERE oid IN
> (%s) ORDER BY oid;
>
> 2017-03-20 10:37:49,814: INFO werkzeug: 127.0.0.1 - - [20/Mar/2017
> 10:37:49] "GET /sqleditor/fetch/types/2408862 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_login.py",
> line 792, in decorated_view
> return func(*args, **kwargs)
> File "/Users/dpage/git/pgadmin4/web/pgadmin/tools/sqleditor/__
> init__.py",
> line 558, in fetch_pg_types
> """, tuple(oid))
> File "/Users/dpage/git/pgadmin4/web/pgadmin/utils/driver/
> psycopg2/__init__.py",
> line 938, in execute_dict
> self.__internal_blocking_execute(cur, query, params)
> File "/Users/dpage/git/pgadmin4/web/pgadmin/utils/driver/
> psycopg2/__init__.py",
> line 595, in __internal_blocking_execute
> cur.execute(query, params)
> File "/Users/dpage/git/pgadmin4/web/pgadmin/utils/driver/
> psycopg2/cursor.py",
> line 176, in execute
> return _cursor.execute(self, query, params)
> TypeError: not all arguments converted during string formatting
>
>
>
> --
> Dave Page
> Blog: http://pgsnake.blogspot.com
> Twitter: @pgsnake
>
> EnterpriseDB UK: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>
diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py
index 3f87cac..70750c9 100644
--- a/web/pgadmin/tools/sqleditor/__init__.py
+++ b/web/pgadmin/tools/sqleditor/__init__.py
@@ -26,14 +26,14 @@ from pgadmin.utils.sqlautocomplete.autocomplete import SQLAutoComplete
from pgadmin.misc.file_manager import Filemanager
-from config import PG_DEFAULT_DRIVER, SERVER_MODE
+from config import PG_DEFAULT_DRIVER
MODULE_NAME = 'sqleditor'
-# import unquote from urlib for python2.x and python3.x
+# import unquote from urllib for python2.x and python3.x
try:
from urllib import unquote
-except Exception as e:
+except ImportError:
from urllib.parse import unquote
# Async Constants
@@ -476,8 +476,6 @@ def poll(trans_id):
status, result = conn.poll()
if status == ASYNC_OK:
status = 'Success'
- if 'primary_keys' in session_obj:
- primary_keys = session_obj['primary_keys']
rows_affected = conn.rows_affected()
# if transaction object is instance of QueryToolCommand
@@ -500,11 +498,10 @@ def poll(trans_id):
status = 'NotConnected'
result = error_msg
- """
- Procedure/Function output may comes in the form of Notices from the
- database server, so we need to append those outputs with the
- original result.
- """
+ # Procedure/Function output may comes in the form of Notices from the
+ # database server, so we need to append those outputs with the
+ # original result.
+
if status == 'Success' and result is None:
result = conn.status_message()
messages = conn.messages()
@@ -549,31 +546,26 @@ def fetch_pg_types(trans_id):
status, error_msg, conn, trans_obj, session_obj = check_transaction_status(trans_id)
if status and conn is not None \
and trans_obj is not None and session_obj is not None:
-
- # List of oid for which we need type name from pg_type
- oid = ''
res = {}
if 'columns_info' in session_obj \
and session_obj['columns_info'] is not None:
- for col in session_obj['columns_info']:
- type_obj = session_obj['columns_info'][col]
- oid += str(type_obj['type_code']) + ','
-
- # Remove extra comma
- oid = oid[:-1]
- status, res = conn.execute_dict(
- """SELECT oid, format_type(oid,null) as typname FROM pg_type WHERE oid IN ({0}) ORDER BY oid;
-""".format(oid))
-
- if status:
- # iterate through pg_types and update the type name in session object
- for record in res['rows']:
- for col in session_obj['columns_info']:
- type_obj = session_obj['columns_info'][col]
- if type_obj['type_code'] == record['oid']:
- type_obj['type_name'] = record['typname']
-
- update_session_grid_transaction(trans_id, session_obj)
+
+ oids = [session_obj['columns_info'][col]['type_code'] for col in session_obj['columns_info']]
+
+ if oids:
+ status, res = conn.execute_dict(
+ u"""SELECT oid, format_type(oid,null) as typname FROM pg_type WHERE oid IN %s ORDER BY oid;
+""", [tuple(oids)])
+
+ if status:
+ # iterate through pg_types and update the type name in session object
+ for record in res['rows']:
+ for col in session_obj['columns_info']:
+ type_obj = session_obj['columns_info'][col]
+ if type_obj['type_code'] == record['oid']:
+ type_obj['type_name'] = record['typname']
+
+ update_session_grid_transaction(trans_id, session_obj)
else:
status = False
res = error_msg
@@ -604,8 +596,10 @@ def save(trans_id):
# If there is no primary key found then return from the function.
if len(session_obj['primary_keys']) <= 0 or len(changed_data) <= 0:
return make_json_response(
- data={'status': False,
- 'result': gettext('No primary key found for this object, so unable to save records.')}
+ data={
+ 'status': False,
+ 'result': gettext('No primary key found for this object, so unable to save records.')
+ }
)
status, res, query_res, _rowid = trans_obj.save(changed_data)
@@ -615,11 +609,13 @@ def save(trans_id):
query_res = None
return make_json_response(
- data={ 'status': status,
- 'result': res,
- 'query_result': query_res,
- '_rowid': _rowid }
- )
+ data={
+ 'status': status,
+ 'result': res,
+ 'query_result': query_res,
+ '_rowid': _rowid
+ }
+ )
@blueprint.route('/filter/get/<int:trans_id>', methods=["GET"])
--
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers