Hi,

Please find the attached patch to fix the RM 2069 - Wrong tablespace
displayed in table properties.

When the table is created without a tablespace, the "pg_default" tablespace
gets selected rather than the default tablespace (the current database
tablespace).
So, this issue has been fixed.

Thanks,
Khushboo
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 99fa00c..64657b1 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
@@ -134,7 +134,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
       - This function is used to return modified SQL for the selected
         Table node
 
-    * get_sql(data, scid, tid)
+    * get_sql(did, scid, tid, data)
       - This function will generate sql from model data
 
     * sql(gid, sid, did, scid, tid):
@@ -344,7 +344,8 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
         """
         SQL = render_template("/".join([self.template_path,
                                         'properties.sql']),
-                              scid=scid, datlastsysoid=self.datlastsysoid)
+                              did=did, scid=scid,
+                              datlastsysoid=self.datlastsysoid)
         status, res = self.conn.execute_dict(SQL)
 
         if not status:
@@ -1128,7 +1129,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
 
         SQL = render_template("/".join([self.template_path,
                                         'properties.sql']),
-                              scid=scid, tid=tid,
+                              did=did, scid=scid, tid=tid,
                               datlastsysoid=self.datlastsysoid)
         status, res = self.conn.execute_dict(SQL)
         if not status:
@@ -1498,7 +1499,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
                 data[k] = v
 
         try:
-            SQL, name = self.get_sql(scid, tid, data)
+            SQL, name = self.get_sql(did, scid, tid, data)
 
             SQL = SQL.strip('\n').strip(' ')
             status, res = self.conn.execute_scalar(SQL)
@@ -1547,7 +1548,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
         try:
             SQL = render_template("/".join([self.template_path,
                                             'properties.sql']),
-                                  scid=scid, tid=tid,
+                                  did=did, scid=scid, tid=tid,
                                   datlastsysoid=self.datlastsysoid)
             status, res = self.conn.execute_dict(SQL)
             if not status:
@@ -1608,7 +1609,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
         try:
             SQL = render_template("/".join([self.template_path,
                                             'properties.sql']),
-                                  scid=scid, tid=tid,
+                                  did=did, scid=scid, tid=tid,
                                   datlastsysoid=self.datlastsysoid)
             status, res = self.conn.execute_dict(SQL)
             if not status:
@@ -1656,7 +1657,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
         try:
             SQL = render_template("/".join([self.template_path,
                                             'properties.sql']),
-                                  scid=scid, tid=tid,
+                                  did=did, scid=scid, tid=tid,
                                   datlastsysoid=self.datlastsysoid)
             status, res = self.conn.execute_dict(SQL)
             if not status:
@@ -1736,7 +1737,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
                 data[k] = v
 
         try:
-            SQL, name = self.get_sql(scid, tid, data)
+            SQL, name = self.get_sql(did, scid, tid, data)
             SQL = re.sub('\n{2,}', '\n\n', SQL)
             SQL = SQL.strip('\n')
             if SQL == '':
@@ -2104,7 +2105,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
         else:
             return None
 
-    def get_sql(self, scid, tid, data):
+    def get_sql(self, did, scid, tid, data):
         """
         This function will generate create/update sql from model data
         coming from client
@@ -2112,7 +2113,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
         if tid is not None:
             SQL = render_template("/".join([self.template_path,
                                             'properties.sql']),
-                                  scid=scid, tid=tid,
+                                  did=did, scid=scid, tid=tid,
                                   datlastsysoid=self.datlastsysoid)
             status, res = self.conn.execute_dict(SQL)
             if not status:
@@ -2468,7 +2469,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
         """
         SQL = render_template("/".join([self.template_path,
                                         'properties.sql']),
-                              scid=scid, tid=tid,
+                              did=did, scid=scid, tid=tid,
                               datlastsysoid=self.datlastsysoid)
         status, res = self.conn.execute_dict(SQL)
         if not status:
@@ -2738,7 +2739,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
         """
         SQL = render_template("/".join([self.template_path,
                                         'properties.sql']),
-                              scid=scid, tid=tid,
+                              did=did, scid=scid, tid=tid,
                               datlastsysoid=self.datlastsysoid)
         status, res = self.conn.execute_dict(SQL)
         if not status:
@@ -2782,7 +2783,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
         """
         SQL = render_template("/".join([self.template_path,
                                         'properties.sql']),
-                              scid=scid, tid=tid,
+                              did=did, scid=scid, tid=tid,
                               datlastsysoid=self.datlastsysoid)
         status, res = self.conn.execute_dict(SQL)
         if not status:
@@ -2829,7 +2830,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
         """
         SQL = render_template("/".join([self.template_path,
                                         'properties.sql']),
-                              scid=scid, tid=tid,
+                              did=did, scid=scid, tid=tid,
                               datlastsysoid=self.datlastsysoid)
         status, res = self.conn.execute_dict(SQL)
         if not status:
@@ -2878,7 +2879,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
         """
         SQL = render_template("/".join([self.template_path,
                                         'properties.sql']),
-                              scid=scid, tid=tid,
+                              did=did, scid=scid, tid=tid,
                               datlastsysoid=self.datlastsysoid)
         status, res = self.conn.execute_dict(SQL)
         if not status:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.1_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.1_plus/properties.sql
index d995d00..a16cf87 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.1_plus/properties.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.1_plus/properties.sql
@@ -1,5 +1,9 @@
 SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS relacl_str,
-  (CASE WHEN length(spc.spcname) > 0 THEN spc.spcname ELSE 'pg_default' END) as spcname,
+  (CASE WHEN length(spc.spcname) > 0 THEN spc.spcname ELSE
+    (SELECT sp.spcname FROM pg_database dtb
+     JOIN pg_tablespace sp ON dtb.dattablespace=sp.oid
+     WHERE dtb.oid = {{ did }}::oid)
+  END) as spcname,
   (select nspname FROM pg_namespace WHERE oid = {{scid}}::oid ) as schema,
   pg_get_userbyid(rel.relowner) AS relowner, rel.relhasoids,
   rel.relhassubclass, rel.reltuples, des.description, con.conname, con.conkey,
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.5_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.5_plus/properties.sql
index d995d00..a16cf87 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.5_plus/properties.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.5_plus/properties.sql
@@ -1,5 +1,9 @@
 SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS relacl_str,
-  (CASE WHEN length(spc.spcname) > 0 THEN spc.spcname ELSE 'pg_default' END) as spcname,
+  (CASE WHEN length(spc.spcname) > 0 THEN spc.spcname ELSE
+    (SELECT sp.spcname FROM pg_database dtb
+     JOIN pg_tablespace sp ON dtb.dattablespace=sp.oid
+     WHERE dtb.oid = {{ did }}::oid)
+  END) as spcname,
   (select nspname FROM pg_namespace WHERE oid = {{scid}}::oid ) as schema,
   pg_get_userbyid(rel.relowner) AS relowner, rel.relhasoids,
   rel.relhassubclass, rel.reltuples, des.description, con.conname, con.conkey,
-- 
Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers

Reply via email to