public inbox for [email protected]  
help / color / mirror / Atom feed
PATCH: move object to....(tablespace context)
3+ messages / 2 participants
[nested] [flat]

* PATCH: move object to....(tablespace context)
@ 2015-10-12 11:25 Sanket Mehta <[email protected]>
  2015-10-12 12:58 ` Re: PATCH: move object to....(tablespace context) Sanket Mehta <[email protected]>
  0 siblings, 1 reply; 3+ messages in thread

From: Sanket Mehta @ 2015-10-12 11:25 UTC (permalink / raw)
  To: pgadmin-hackers; +Cc: Ashesh Vashi <[email protected]>

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_context.patch (3.4K, 3-pgadmin_move_object_to_tablespace_context.patch)
  download | inline diff:
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);
 	}
 }


^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: PATCH: move object to....(tablespace context)
  2015-10-12 11:25 PATCH: move object to....(tablespace context) Sanket Mehta <[email protected]>
@ 2015-10-12 12:58 ` Sanket Mehta <[email protected]>
  2015-10-12 13:07   ` Re: PATCH: move object to....(tablespace context) Ashesh Vashi <[email protected]>
  0 siblings, 1 reply; 3+ messages in thread

From: Sanket Mehta @ 2015-10-12 12:58 UTC (permalink / raw)
  To: pgadmin-hackers; +Cc: Ashesh Vashi <[email protected]>

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);
 	}
 }


^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: PATCH: move object to....(tablespace context)
  2015-10-12 11:25 PATCH: move object to....(tablespace context) Sanket Mehta <[email protected]>
  2015-10-12 12:58 ` Re: PATCH: move object to....(tablespace context) Sanket Mehta <[email protected]>
@ 2015-10-12 13:07   ` Ashesh Vashi <[email protected]>
  0 siblings, 0 replies; 3+ messages in thread

From: Ashesh Vashi @ 2015-10-12 13:07 UTC (permalink / raw)
  To: Sanket Mehta <[email protected]>; +Cc: pgadmin-hackers

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

> Hi Ashesh,
>
> PFA the updated patch which includes the changes you have suggested.
> Please do review and commit it.
>
Hi Sanket,

Thanks for the patch.
It has been committed.

--

Thanks & Regards,

Ashesh Vashi
EnterpriseDB INDIA: Enterprise PostgreSQL Company
<http://www.enterprisedb.com;


*http://www.linkedin.com/in/asheshvashi*
<http://www.linkedin.com/in/asheshvashi;


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


^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2015-10-12 13:07 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-10-12 11:25 PATCH: move object to....(tablespace context) Sanket Mehta <[email protected]>
2015-10-12 12:58 ` Sanket Mehta <[email protected]>
2015-10-12 13:07   ` Ashesh Vashi <[email protected]>

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