public inbox for [email protected]  
help / color / mirror / Atom feed
From: Sanket Mehta <[email protected]>
To: pgadmin-hackers <[email protected]>
Cc: Ashesh Vashi <[email protected]>
Subject: Re: PATCH: move object to....(tablespace context)
Date: Mon, 12 Oct 2015 18:28:00 +0530
Message-ID: <CA+yw=mNk=yi5HEdtiPWKY84EKxA6anWHxQ9Fw2LKc0e1b2kvzQ@mail.gmail.com> (raw)
In-Reply-To: <CA+yw=mMq5vuUc+g0Y=KkYrKBkf_xagKYEcCbOzxy+m+AOYpx-Q@mail.gmail.com>
References: <CA+yw=mMq5vuUc+g0Y=KkYrKBkf_xagKYEcCbOzxy+m+AOYpx-Q@mail.gmail.com>
List-Unsubscribe:  <mailto:[email protected]?body=unsub%20pgadmin-hackers>

Hi Ashesh,

PFA the updated patch which includes the changes you have suggested.
Please do review and commit it.

Regards,
Sanket Mehta
Sr Software engineer
Enterprisedb

On Mon, Oct 12, 2015 at 4:55 PM, Sanket Mehta <[email protected]
> wrote:

> 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
>


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


Attachments:

  [text/x-patch] pgadmin_move_object_to_tablespace_contextv2.patch (3.2K, 3-pgadmin_move_object_to_tablespace_contextv2.patch)
  download | inline diff:
diff --git a/pgadmin/dlg/dlgMoveTablespace.cpp b/pgadmin/dlg/dlgMoveTablespace.cpp
index cc78a71..84fd0d5 100644
--- a/pgadmin/dlg/dlgMoveTablespace.cpp
+++ b/pgadmin/dlg/dlgMoveTablespace.cpp
@@ -98,16 +98,22 @@ wxString dlgMoveTablespace::GetTablespace()
 	return cbMoveTo->GetValue();
 }
 
-wxString dlgMoveTablespace::GetKind()
+wxArrayString dlgMoveTablespace::GetKind()
 {
+	wxArrayString kinds;
 	if (cbKind->GetValue().Cmp(_("Tables")) == 0)
-		return wxT("TABLES");
-	if (cbKind->GetValue().Cmp(_("Indexes")) == 0)
-		return wxT("INDEXES");
-	if (cbKind->GetValue().Cmp(_("Materialized views")) == 0)
-		return wxT("MATERIALIZED VIEWS");
-
-	return wxT("ALL");
+		kinds.Add(wxT("TABLE"));
+	else if (cbKind->GetValue().Cmp(_("Indexes")) == 0)
+		kinds.Add(wxT("INDEX"));
+	else if (cbKind->GetValue().Cmp(_("Materialized views")) == 0)
+		kinds.Add(wxT("MATERIALIZED VIEW"));
+	else
+	{
+		kinds.Add(wxT("TABLE"));
+		kinds.Add(wxT("INDEX"));
+		kinds.Add(wxT("MATERIALIZED VIEW"));
+	}
+	return kinds;
 }
 
 wxString dlgMoveTablespace::GetOwner()
diff --git a/pgadmin/include/dlg/dlgMoveTablespace.h b/pgadmin/include/dlg/dlgMoveTablespace.h
index 41f55a6..d8a9451 100644
--- a/pgadmin/include/dlg/dlgMoveTablespace.h
+++ b/pgadmin/include/dlg/dlgMoveTablespace.h
@@ -28,9 +28,8 @@ public:
 	dlgMoveTablespace(frmMain *win, pgConn *conn, pgTablespace *tblspc);
 	~dlgMoveTablespace();
 	wxString GetTablespace();
-	wxString GetKind();
+	wxArrayString GetKind();
 	wxString GetOwner();
-
 private:
 	pgConn *connection;
 	frmMain *parent;
diff --git a/pgadmin/schema/pgTablespace.cpp b/pgadmin/schema/pgTablespace.cpp
index 97d2209..346c39f 100644
--- a/pgadmin/schema/pgTablespace.cpp
+++ b/pgadmin/schema/pgTablespace.cpp
@@ -253,15 +253,34 @@ 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;
 
-		query = wxT("ALTER TABLESPACE ") + GetQuotedFullIdentifier();
-		query += wxT(" MOVE ") + rdo.GetKind().Upper();
+		wxArrayString kind = rdo.GetKind();
+		wxString      ownerInfo,
+		              moveTo = qtIdent(rdo.GetTablespace()),
+			      currTblSpace = GetQuotedFullIdentifier();
+
 		if (rdo.GetOwner().Length() > 0)
-			query += wxT(" OWNED BY ") + qtIdent(rdo.GetOwner());
-		query += wxT(" TO ") + qtIdent(rdo.GetTablespace());
+		{
+			ownerInfo = wxString::Format(
+				wxT(" OWNED BY %s"),
+				qtIdent(rdo.GetOwner()).c_str());
+		}
 
+		for(size_t index = 0; index < kind.GetCount(); ++index)
+		{
+			query += wxString::Format(
+				wxT("ALTER %s ALL IN TABLESPACE %s%s SET TABLESPACE %s;\n"),
+				kind.Item(index).c_str(),
+				currTblSpace.c_str(),
+				ownerInfo.c_str(),
+				moveTo.c_str());
+		}
 		GetConnection()->ExecuteVoid(query);
 	}
 }


view thread (3+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: PATCH: move object to....(tablespace context)
  In-Reply-To: <CA+yw=mNk=yi5HEdtiPWKY84EKxA6anWHxQ9Fw2LKc0e1b2kvzQ@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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