Hi Ashesh,

I have created a patch regarding an issue in pgadmin related to tablespace
context.

*Issue:*
While moving Table/Index/materialized view/All to another tablespace,
pgadmin gives error mentioned below:
ERROR: syntax error at or near "MOVE"

*Reason:*
As mentioned in commit id: 3c4cf080879b386d4ed1814667aca025caafe608
in PostgreSQL database, ALTER TABLESPACE src MOVE dest OWNED BY username
syntax has been changed

*Current implementation in postgreSQL db is as below:*
ALTER TABLE/INDEX/MATERIALIZED VIEW ALL IN TABLESPACE src OWNED BY username
SET TABLESPACE dest

*Changes made:*
Changes made to generate sql as per current implementation in PostgreSQL.


Please do review and commit it.


Regards,
Sanket Mehta
Sr Software engineer
Enterprisedb
diff --git a/pgadmin/dlg/dlgMoveTablespace.cpp b/pgadmin/dlg/dlgMoveTablespace.cpp
index cc78a71..677023b 100644
--- a/pgadmin/dlg/dlgMoveTablespace.cpp
+++ b/pgadmin/dlg/dlgMoveTablespace.cpp
@@ -101,15 +101,32 @@ wxString dlgMoveTablespace::GetTablespace()
 wxString dlgMoveTablespace::GetKind()
 {
 	if (cbKind->GetValue().Cmp(_("Tables")) == 0)
-		return wxT("TABLES");
+		return wxT("TABLE");
 	if (cbKind->GetValue().Cmp(_("Indexes")) == 0)
-		return wxT("INDEXES");
+		return wxT("INDEX");
 	if (cbKind->GetValue().Cmp(_("Materialized views")) == 0)
-		return wxT("MATERIALIZED VIEWS");
+		return wxT("MATERIALIZED VIEW");
 
 	return wxT("ALL");
 }
 
+wxArrayString dlgMoveTablespace::GetAllKinds()
+{
+	wxArrayString kinds;
+	for(unsigned int i = 1; i < cbKind->GetCount(); ++i)
+	{
+		if (cbKind->GetString(i).Cmp(_("Tables")) == 0)
+			kinds.Add(wxT("TABLE"));
+		else if (cbKind->GetString(i).Cmp(_("Indexes")) == 0)
+			kinds.Add(wxT("INDEX"));
+		else if (cbKind->GetString(i).Cmp(_("Materialized views")) == 0)
+			kinds.Add(wxT("MATERIALIZED VIEW"));
+		else
+			kinds.Add(cbKind->GetString(i));
+	}
+	return kinds;
+}
+
 wxString dlgMoveTablespace::GetOwner()
 {
 	return cbOwner->GetValue();
diff --git a/pgadmin/include/dlg/dlgMoveTablespace.h b/pgadmin/include/dlg/dlgMoveTablespace.h
index 41f55a6..c749eac 100644
--- a/pgadmin/include/dlg/dlgMoveTablespace.h
+++ b/pgadmin/include/dlg/dlgMoveTablespace.h
@@ -30,7 +30,7 @@ public:
 	wxString GetTablespace();
 	wxString GetKind();
 	wxString GetOwner();
-
+	wxArrayString GetAllKinds();
 private:
 	pgConn *connection;
 	frmMain *parent;
diff --git a/pgadmin/schema/pgTablespace.cpp b/pgadmin/schema/pgTablespace.cpp
index 97d2209..98bf33d 100644
--- a/pgadmin/schema/pgTablespace.cpp
+++ b/pgadmin/schema/pgTablespace.cpp
@@ -253,15 +253,30 @@ void pgTablespace::MoveTablespace(frmMain *form)
 	dlgMoveTablespace rdo(form, GetConnection(), this);
 	if (rdo.ShowModal() != wxID_CANCEL)
 	{
-		if (wxMessageBox(wxString::Format(_("Are you sure you wish to move objects from %s to %s?"), (const char *)GetQuotedFullIdentifier().mb_str(), (const char *)rdo.GetTablespace().mb_str()), _("Move tablespace?"), wxYES_NO) != wxYES)
+		if (wxMessageBox(wxString::Format(_("Are you sure you wish to move objects from %s to %s?"), GetQuotedFullIdentifier().c_str(),rdo.GetTablespace().c_str()), _("Move tablespace?"), wxYES_NO) != wxYES)
 			return;
+		wxString kind = rdo.GetKind();
+		if(kind.compare(wxT("ALL")) != 0)
+		{
+			query = wxT("ALTER ") + kind;
+			query += wxT(" ALL IN TABLESPACE ") + GetQuotedFullIdentifier();
+			if (rdo.GetOwner().Length() > 0)
+				query += wxT(" OWNED BY ") + qtIdent(rdo.GetOwner());
+			query += wxT(" SET TABLESPACE ") + qtIdent(rdo.GetTablespace());
+		}
+		else
+		{
+			wxArrayString allKinds = rdo.GetAllKinds();
+			for(size_t index = 0; index < allKinds.GetCount(); ++index)
+			{
+				query += wxT("ALTER ") + allKinds.Item(index);
+				query += wxT(" ALL IN TABLESPACE ") + GetQuotedFullIdentifier();
+				if (rdo.GetOwner().Length() > 0)
+					query += wxT(" OWNED BY ") + qtIdent(rdo.GetOwner());
+				query += wxT(" SET TABLESPACE ") + qtIdent(rdo.GetTablespace()) + wxT(";\n");
 
-		query = wxT("ALTER TABLESPACE ") + GetQuotedFullIdentifier();
-		query += wxT(" MOVE ") + rdo.GetKind().Upper();
-		if (rdo.GetOwner().Length() > 0)
-			query += wxT(" OWNED BY ") + qtIdent(rdo.GetOwner());
-		query += wxT(" TO ") + qtIdent(rdo.GetTablespace());
-
+			}
+		}
 		GetConnection()->ExecuteVoid(query);
 	}
 }
-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers

Reply via email to