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
>
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);
}
}
--
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers