Patch for ALTER DATABASE - Mailing list pgadmin-hackers

From Guillaume Lelarge
Subject Patch for ALTER DATABASE
Date
Msg-id 491DE528.5070106@lelarge.info
Whole thread Raw
Responses Re: Patch for ALTER DATABASE  ("Dave Page" <dpage@pgadmin.org>)
List pgadmin-hackers
Hi,

This patch adds ALTER DATABASE SET TABLESPACE support (8.4 only) and
re-adds ALTER DATABASE RENAME TO support (8.0 and over).

Works for me on Linux (NAME and TABLESPACE), Mac OS X and Windows (both
NAME only).

Regards.


--
Guillaume.
 http://www.postgresqlfr.org
 http://dalibo.com
Index: pgadmin/include/dlg/dlgDatabase.h
===================================================================
--- pgadmin/include/dlg/dlgDatabase.h    (révision 7497)
+++ pgadmin/include/dlg/dlgDatabase.h    (copie de travail)
@@ -26,6 +26,7 @@
     void CheckChange();
     wxString GetSql();
     wxString GetSql2();
+    bool GetDisconnectFirst();
     pgObject *CreateObject(pgCollection *collection);
     pgObject *GetObject();
     wxString GetHelpPage() const;
Index: pgadmin/include/dlg/dlgProperty.h
===================================================================
--- pgadmin/include/dlg/dlgProperty.h    (révision 7497)
+++ pgadmin/include/dlg/dlgProperty.h    (copie de travail)
@@ -41,6 +41,7 @@

     virtual wxString GetSql() =0;
     virtual wxString GetSql2() { return wxEmptyString; };
+    virtual bool GetDisconnectFirst() { return false; };
     virtual pgObject *CreateObject(pgCollection *collection) =0;
     virtual pgObject *GetObject() =0;
     virtual void SetObject(pgObject *obj) {} // only necessary if apply is implemented
Index: pgadmin/dlg/dlgProperty.cpp
===================================================================
--- pgadmin/dlg/dlgProperty.cpp    (révision 7497)
+++ pgadmin/dlg/dlgProperty.cpp    (copie de travail)
@@ -763,6 +763,14 @@

 bool dlgProperty::apply(const wxString &sql, const wxString &sql2)
 {
+    pgConn *myConn = connection;
+
+    if (GetDisconnectFirst())
+    {
+        myConn = database->GetServer()->GetConnection();
+        database->Disconnect();
+    }
+
     if (!sql.IsEmpty())
     {
         wxString tmp;
@@ -788,7 +796,7 @@
         else
             tmp = sql;

-        if (!connection->ExecuteVoid(tmp))
+        if (!myConn->ExecuteVoid(tmp))
         {
             // error message is displayed inside ExecuteVoid
             return false;
@@ -826,7 +834,7 @@
         else
             tmp = sql2;

-        if (!connection->ExecuteVoid(tmp))
+        if (!myConn->ExecuteVoid(tmp))
         {
             // error message is displayed inside ExecuteVoid
             // Warn the user about partially applied changes, but don't bail out.
@@ -883,7 +891,7 @@
         EndModal(0);
         return;
     }
-
+
     wxString sql;
     wxString sql2;
     if (chkReadOnly->GetValue())
Index: pgadmin/dlg/dlgDatabase.cpp
===================================================================
--- pgadmin/dlg/dlgDatabase.cpp    (révision 7497)
+++ pgadmin/dlg/dlgDatabase.cpp    (copie de travail)
@@ -141,7 +141,7 @@

         // Even with 7.4+, we don't currently have a way to change the database name
         // as it must be done from a different database.
-        // if (!connection->BackendMinimumVersion(7, 4))
+        if (!connection->BackendMinimumVersion(7, 4))
             txtName->Disable();

         if (!connection->BackendMinimumVersion(8, 0))
@@ -165,7 +165,10 @@
         }

         PrepareTablespace(cbTablespace, database->GetTablespaceOid());
-        cbTablespace->Disable();
+        if (connection->BackendMinimumVersion(8, 4))
+            cbTablespace->Enable();
+        else
+            cbTablespace->Disable();
         txtPath->SetValue(database->GetPath());
         txtPath->Disable();

@@ -311,6 +312,7 @@
                || txtComment->GetValue() != database->GetComment()
                || txtName->GetValue() != database->GetName()
                || cbOwner->GetValue() != database->GetOwner()
+               || cbTablespace->GetValue() != database->GetTablespace()
                || dirtyVars;
     }

@@ -428,6 +430,15 @@

         AppendComment(sql, wxT("DATABASE"), 0, database);

+        if (connection->BackendMinimumVersion(8, 4))
+        {
+            if (cbTablespace->GetCurrentSelection() > 0 && cbTablespace->GetOIDKey() > 0
+                && cbTablespace->GetOIDKey() != database->GetTablespaceOid())
+                sql += wxT("ALTER DATABASE ") + qtIdent(name)
+                    +  wxT(" SET TABLESPACE ") + qtIdent(cbTablespace->GetValue())
+                    +  wxT(";\n");
+        }
+
         if (!connection->BackendMinimumVersion(8, 2))
             sql += GetGrant(wxT("CT"), wxT("DATABASE ") + qtIdent(name));
         else
@@ -528,4 +539,9 @@
     return sql;
 }

-
+bool dlgDatabase::GetDisconnectFirst()
+{
+    if (database)
+      return true;
+    return false;
+}

pgadmin-hackers by date:

Previous
From: "Dave Page"
Date:
Subject: Re: Buglets in dlgFunction
Next
From: "Dave Page"
Date:
Subject: Re: Patch for ALTER DATABASE