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 941604d83..1e1f536d3 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 @@ -443,6 +443,13 @@ class CollationView(PGChildNodeView): if not status: return internal_server_error(errormsg=coid) + # Get updated schema oid + SQL = render_template("/".join([self.template_path, + 'get_oid.sql']), coid=coid) + status, scid = self.conn.execute_scalar(SQL) + if not status: + return internal_server_error(errormsg=coid) + return jsonify( node=self.blueprint.generate_browser_node( coid, 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 59d9a3dff..52b2079f0 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 @@ -546,6 +546,14 @@ AND relkind != 'c'))""" if not status: return internal_server_error(errormsg=res) + # Get updated schema oid + SQL = render_template("/".join([self.template_path, + 'get_oid.sql']), + doid=doid) + status, scid = self.conn.execute_scalar(SQL) + if not status: + return internal_server_error(errormsg=res) + return jsonify( node=self.blueprint.generate_browser_node( doid, @@ -640,12 +648,10 @@ AND relkind != 'c'))""" SQL = render_template("/".join([self.template_path, 'get_oid.sql']), doid=doid) - status, res = self.conn.execute_2darray(SQL) + status, scid = self.conn.execute_scalar(SQL) if not status: return internal_server_error(errormsg=res) - scid = res['rows'][0]['scid'] - return jsonify( node=self.blueprint.generate_browser_node( doid, 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 4dc9cf235..f9fca3a73 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 @@ -286,7 +286,7 @@ class FtsConfigurationView(PGChildNodeView): res.append( self.blueprint.generate_browser_node( row['oid'], - did, + scid, row['name'], icon="icon-fts_configuration" )) 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 b80f9eb1e..52cb2d875 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 @@ -256,7 +256,7 @@ class FtsParserView(PGChildNodeView): res.append( self.blueprint.generate_browser_node( row['oid'], - did, + scid, row['name'], icon="icon-fts_parser" )) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/templates/synonym/sql/9.5_plus/get_schema.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/templates/synonym/sql/9.5_plus/get_schema.sql new file mode 100644 index 000000000..c05ee0fcc --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/templates/synonym/sql/9.5_plus/get_schema.sql @@ -0,0 +1,7 @@ +{# ===== fetch new assigned schema id ===== #} +SELECT + c.relnamespace as scid +FROM + pg_class c +WHERE + c.oid = {{syid|qtLiteral}}::oid; 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 040afb8eb..daa6ef082 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 @@ -1442,9 +1442,17 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings): if not status: return internal_server_error(errormsg=res) + # Get updated schema oid + SQL = render_template("/".join([self.template_path, + 'get_schema_oid.sql']), tname=data['name']) + + status, scid = self.conn.execute_scalar(SQL) + if not status: + return internal_server_error(errormsg=scid) + # we need oid to to add object in tree at browser SQL = render_template("/".join([self.template_path, - 'get_oid.sql']), scid=scid, data=data) + 'get_oid.sql']), scid=scid, data=data) status, tid = self.conn.execute_scalar(SQL) if not status: return internal_server_error(errormsg=tid) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.1_plus/get_schema_oid.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.1_plus/get_schema_oid.sql index 99498f3c1..4d329d213 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.1_plus/get_schema_oid.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.1_plus/get_schema_oid.sql @@ -1,9 +1,11 @@ {# ===== fetch new assigned schema oid ===== #} -{% if tid %} SELECT c.relnamespace as scid FROM pg_class c WHERE +{% if tid %} c.oid = {{tid}}::oid; +{% else %} + c.relname = {{tname|qtLiteral}}::text; {% endif %} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.5_plus/get_schema_oid.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.5_plus/get_schema_oid.sql index 99498f3c1..4d329d213 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.5_plus/get_schema_oid.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.5_plus/get_schema_oid.sql @@ -1,9 +1,11 @@ {# ===== fetch new assigned schema oid ===== #} -{% if tid %} SELECT c.relnamespace as scid FROM pg_class c WHERE +{% if tid %} c.oid = {{tid}}::oid; +{% else %} + c.relname = {{tname|qtLiteral}}::text; {% endif %} 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 c67c47c38..e6b7f3c0d 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 @@ -902,10 +902,17 @@ class TypeView(PGChildNodeView, DataTypeReader): try: SQL = render_template("/".join([self.template_path, 'create.sql']), data=data, conn=self.conn) - status, res = self.conn.execute_scalar(SQL) + status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) + # we need scid to update in browser tree + SQL = render_template("/".join([self.template_path, + 'get_scid.sql']), tname=data['name']) + status, scid = self.conn.execute_scalar(SQL) + if not status: + return internal_server_error(errormsg=scid) + # we need oid to to add object in tree at browser SQL = render_template("/".join([self.template_path, 'get_oid.sql']), @@ -948,6 +955,14 @@ class TypeView(PGChildNodeView, DataTypeReader): if not status: return internal_server_error(errormsg=res) + SQL = render_template("/".join([self.template_path, + 'get_scid.sql']), tname=data['name']) + + # Get updated schema oid + status, scid = self.conn.execute_scalar(SQL) + if not status: + return internal_server_error(errormsg=res) + return jsonify( node=self.blueprint.generate_browser_node( tid, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/sql/9.1_plus/get_oid.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/sql/9.1_plus/get_oid.sql index 14f79502f..175149884 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/sql/9.1_plus/get_oid.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/sql/9.1_plus/get_oid.sql @@ -8,4 +8,4 @@ WHERE t.typtype != 'd' AND t.typname NOT LIKE E'\\_%' AND t.typnamespace = {{sci {% if data %} AND t.typname = {{data.name|qtLiteral}} {% endif %} -ORDER BY t.typname; \ No newline at end of file +ORDER BY t.typname; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/sql/9.1_plus/get_scid.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/sql/9.1_plus/get_scid.sql new file mode 100644 index 000000000..696a205a8 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/sql/9.1_plus/get_scid.sql @@ -0,0 +1,6 @@ +SELECT + t.typnamespace as scid +FROM + pg_type t +WHERE + t.typname = {{tname|qtLiteral}}::text; 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 1063c4ed2..73f818fac 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 @@ -487,12 +487,24 @@ class ViewNode(PGChildNodeView, VacuumSettings): SQL = render_template("/".join( [self.template_path, 'sql/view_id.sql']), data=data) status, view_id = self.conn.execute_scalar(SQL) + + if not status: + return internal_server_error(errormsg=res) + + # Get updated schema oid + SQL = render_template("/".join( + [self.template_path, 'sql/get_oid.sql']), vid=view_id) + status, scid = self.conn.execute_scalar(SQL) + + if not status: + return internal_server_error(errormsg=res) + return jsonify( node=self.blueprint.generate_browser_node( view_id, scid, data['name'], - icon="icon-%s" % self.node_type + icon="icon-view" ) ) except Exception as e: @@ -525,15 +537,13 @@ class ViewNode(PGChildNodeView, VacuumSettings): view_id = res_data['rows'][0]['oid'] new_view_name = res_data['rows'][0]['relname'] + # Get updated schema oid SQL = render_template("/".join( [self.template_path, 'sql/get_oid.sql']), vid=view_id) - status, res = self.conn.execute_2darray(SQL) + status, scid = self.conn.execute_scalar(SQL) if not status: return internal_server_error(errormsg=res) - # new schema id - scid = res['rows'][0]['scid'] - return jsonify( node=self.blueprint.generate_browser_node( view_id, diff --git a/web/pgadmin/browser/templates/browser/js/browser.js b/web/pgadmin/browser/templates/browser/js/browser.js index 46c49cfc9..3652ec502 100644 --- a/web/pgadmin/browser/templates/browser/js/browser.js +++ b/web/pgadmin/browser/templates/browser/js/browser.js @@ -1148,7 +1148,8 @@ function(require, $, _, S, Bootstrap, pgAdmin, Alertify, CodeMirror) { if ( this.i && this.d && this.new._type == this.d._type ) { - var _id = this.d._id; + var self = this, + _id = this.d._id; if (this.new._id != this.d._id) { // Found the new oid, update its node_id var node_data = this.t.itemData(ctx.i); @@ -1162,7 +1163,10 @@ function(require, $, _, S, Bootstrap, pgAdmin, Alertify, CodeMirror) { this.t.setId(ctx.id, {id: this.new.id}); this.t.openPath(this.i); this.t.deselect(this.i); - this.t.select(this.i); + // select tree item after few milliseconds + setTimeout(function() { + self.t.select(self.i); + }, 10); } } var success = this.o && this.o.success;