Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Interfaces Pgadmin Hackers > Sup****t of INH...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 11 Topic 4686 of 4873
Post > Topic >>

Sup****t of INHERIT in existing tables (8.2+ releases)

by guillaume@[EMAIL PROTECTED] (Guillaume Lelarge) Jul 12, 2008 at 12:30 AM

This is a multi-part message in MIME format.
--------------040705060901030501040600
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi,

I don't know if you have read this page 
(http://www.postgresonline.com/journal/index.php?/archives/59-How-to-Inherit,-Unherit-and-Merge-Inherit.html)

but it complains on the lack of inherit sup****t for existing tables.

So, here is a patch to add sup****t on adding inherited tables on already 
existing tables. The feature is available since PostgreSQL 8.2 release.

Tested on Linux. It works fine there. I didn't check Win32 platform 
because I didn't change any xrc files :) Didn't check on Mac OS X either 
cause I don't have one (btw, I'm following ebay's Mac Mini list to get 
one soon).

Regards.


-- 
Guillaume.
  http://www.postgresqlfr.org
  http://dalibo.com

--------------040705060901030501040600
Content-Type: text/x-patch;
 name="inherit82+.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="inherit82+.patch"

Index: pgadmin/include/schema/pgTable.h
===================================================================
--- pgadmin/include/schema/pgTable.h	(revision 7393)
+++ pgadmin/include/schema/pgTable.h	(working copy)
@[EMAIL PROTECTED]
 -72,6 +72,7 @[EMAIL PROTECTED]
     long GetInheritedTableCount() { if (inheritedTableCount < 0)
UpdateInheritance(); return inheritedTableCount; }
     wxString GetInheritedTables() { GetInheritedTableCount(); return
inheritedTables; }
     wxString GetQuotedInheritedTables() { GetInheritedTableCount();
return quotedInheritedTables; }
+    wxArrayString GetInheritedTablesOidList() { GetInheritedTableCount();
return inheritedTablesOidList; }
     wxArrayString GetQuotedInheritedTablesList() {
GetInheritedTableCount(); return quotedInheritedTablesList; }
     wxString GetCoveringIndex(ctlTree *browser, const wxString &collist);
     pgCollection *GetColumnCollection(ctlTree *browser);
@[EMAIL PROTECTED]
 -124,7 +125,7 @[EMAIL PROTECTED]
     long inheritedTableCount;
     wxString quotedInheritedTables, inheritedTables, primaryKey,
quotedPrimaryKey,
         primaryKeyName, primaryKeyColNumbers, tablespace;
-    wxArrayString quotedInheritedTablesList;
+    wxArrayString quotedInheritedTablesList, inheritedTablesOidList;
     slSet *replicationSet;
 	OID tablespaceOid;
 };
Index: pgadmin/include/dlg/dlgTable.h
===================================================================
--- pgadmin/include/dlg/dlgTable.h	(revision 7393)
+++ pgadmin/include/dlg/dlgTable.h	(working copy)
@[EMAIL PROTECTED]
 -56,7 +56,7 @[EMAIL PROTECTED]
     wxString GetItemConstraintType(ctlListView *list, long pos);
     bool hasPK;
 
-    wxArrayString previousColumns, previousConstraints;
+    wxArrayString previousColumns, previousConstraints, previousTables;
     wxArrayString tableOids, inheritedTableOids;
     wxTreeItemId columnsItem, constraintsItem;
 
Index: pgadmin/schema/pgTable.cpp
===================================================================
--- pgadmin/schema/pgTable.cpp	(revision 7393)
+++ pgadmin/schema/pgTable.cpp	(working copy)
@[EMAIL PROTECTED]
 -511,7 +511,7 @[EMAIL PROTECTED]
 {
     // not checked so far
     pgSet *props=ExecuteSet(
-        wxT("SELECT c.relname , nspname\n")
+        wxT("SELECT c.oid, c.relname , nspname\n")
         wxT("  FROM pg_inherits i\n")
         wxT("  JOIN pg_class c ON c.oid = i.inhparent\n")
         wxT("  JOIN pg_namespace n ON n.oid=c.relnamespace\n")
@[EMAIL PROTECTED]
 -533,6 +533,7 @[EMAIL PROTECTED]
                     + qtIdent(props->GetVal(wxT("relname")));
            
quotedInheritedTablesList.Add(GetQuotedSchemaPrefix(props->GetVal(wxT("nspname")))
                     + qtIdent(props->GetVal(wxT("relname"))));
+            inheritedTablesOidList.Add(props->GetVal(wxT("oid")));
             props->MoveNext();
             inheritedTableCount++;
         }
Index: pgadmin/dlg/dlgTable.cpp
===================================================================
--- pgadmin/dlg/dlgTable.cpp	(revision 7393)
+++ pgadmin/dlg/dlgTable.cpp	(working copy)
@[EMAIL PROTECTED]
 -157,14 +157,19 @[EMAIL PROTECTED]
         if (table->GetTablespaceOid() != 0)
             cbTablespace->SetKey(table->GetTablespaceOid());
 
+        inheritedTableOids=table->GetInheritedTablesOidList();
+
         wxArrayString qitl=table->GetQuotedInheritedTablesList();
         size_t i;
         for (i=0 ; i < qitl.GetCount() ; i++)
+        {
+            previousTables.Add(qitl.Item(i));
             lbTables->Append(qitl.Item(i));
+        }
 
-        btnAddTable->Disable();
-        lbTables->Disable();
-        cbTables->Disable();
+        btnAddTable->Enable(connection->BackendMinimumVersion(8, 2));
+        lbTables->Enable(connection->BackendMinimumVersion(8, 2));
+        cbTables->Enable(connection->BackendMinimumVersion(8, 2));
         chkHasOids->Enable(table->GetHasOids() &&
connection->BackendMinimumVersion(8, 0));
         cbTablespace->Enable(connection->BackendMinimumVersion(7, 5));
 
@[EMAIL PROTECTED]
 -278,11 +283,30 @[EMAIL PROTECTED]
         // create mode
         btnChangeCol->Hide();
 
+        // Add the default tablespace 
+        cbTablespace->Insert(_("<default tablespace>"), 0, (void *)0);
+        cbTablespace->SetSelection(0);
+    }
+
+    if (connection->BackendMinimumVersion(8,2) || !table)
+    {
         wxString systemRestriction;
         if (!settings->GetShowSystemObjects())
         systemRestriction = 
             wxT("   AND ") +
connection->SystemNamespaceRestriction(wxT("n.nspname"));
-            
+        
+        if (table)
+        {
+            wxString oids = table->GetOidStr();
+            int i;
+            for (i=0 ; i < (int)inheritedTableOids.GetCount() ; i++)
+            {
+                oids += wxT(", ") + inheritedTableOids.Item(i);
+            }
+            if (oids.Length() > 0)
+                systemRestriction += wxT(" AND c.oid NOT IN (") + oids +
wxT(")");
+        }
+    
         pgSet *set=connection->ExecuteSet(
             wxT("SELECT c.oid, c.relname , nspname\n")
             wxT("  FROM pg_class c\n")
@[EMAIL PROTECTED]
 -302,10 +326,6 @[EMAIL PROTECTED]
             }
             delete set;
         }
-
-        // Add the default tablespace 
-        cbTablespace->Insert(_("<default tablespace>"), 0, (void *)0);
-        cbTablespace->SetSelection(0);
     }
 
     FillConstraint();
@[EMAIL PROTECTED]
 -511,7 +531,7 @[EMAIL PROTECTED]
         wxArrayString tmpDef=previousColumns;
         wxString tmpsql;
 
-        // Build a tme****ary list of ADD COLUMNs, and fixup the list to
remove
+        // Build a tem****ary list of ADD COLUMNs, and fixup the list to
remove
         for (pos=0; pos < lstColumns->GetItemCount() ; pos++)
         {
             definition = lstColumns->GetText(pos, 3);
@[EMAIL PROTECTED]
 -555,10 +575,34 @[EMAIL PROTECTED]
         AppendNameChange(sql);
         AppendOwnerChange(sql, wxT("TABLE ") + tabname);
 
+        tmpDef=previousTables;
+        tmpsql.Empty();
+
+        // Build a tem****ary list of INHERIT tables, and fixup the list
to remove
+        for (pos = 0 ; pos < (int)lbTables->GetCount() ; pos++)
+        {
+            definition = lbTables->GetString(pos);
+            index = tmpDef.Index(definition);
+            if (index < 0)
+                tmpsql += wxT("ALTER TABLE ") +
table->GetQuotedFullIdentifier()
+                    +  wxT(" INHERIT ") + qtIdent(definition) +
wxT(";\n");
+            else
+                tmpDef.RemoveAt(index);
+        }
+
+        for (index = 0 ; index < (int)tmpDef.GetCount() ; index++)
+        {
+            definition = tmpDef.Item(index);
+            sql += wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier()
+                +  wxT(" NO INHERIT ") + qtIdent(definition) +
wxT(";\n");
+        }
+        // Add the ADD COLUMNs...
+        sql += tmpsql;
+
         tmpDef=previousConstraints;
         tmpsql.Empty();
 
-        // Build a tme****ary list of ADD CONSTRAINTs, and fixup the list
to remove
+        // Build a tem****ary list of ADD CONSTRAINTs, and fixup the list
to remove
         for (pos=0; pos < lstConstraints->GetItemCount() ; pos++)
         {
             wxString conname= qtIdent(lstConstraints->GetItemText(pos));

--------------040705060901030501040600
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0


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

--------------040705060901030501040600--
 




 11 Posts in Topic:
Support of INHERIT in existing tables (8.2+ releases)
guillaume@[EMAIL PROTECTE  2008-07-12 00:30:48 
Re: Support of INHERIT in existing tables (8.2+ releases)
dpage@[EMAIL PROTECTED]   2008-07-12 01:33:33 
Re: Support of INHERIT in existing tables (8.2+ releases)
dpage@[EMAIL PROTECTED]   2008-07-14 09:21:44 
Re: Support of INHERIT in existing tables (8.2+
guillaume@[EMAIL PROTECTE  2008-07-14 10:49:05 
Re: Support of INHERIT in existing tables (8.2+
guillaume@[EMAIL PROTECTE  2008-07-14 21:09:00 
Re: Support of INHERIT in existing tables (8.2+ releases)
dpage@[EMAIL PROTECTED]   2008-07-15 11:30:25 
Re: Support of INHERIT in existing tables (8.2+
guillaume@[EMAIL PROTECTE  2008-08-10 19:55:07 
Re: Support of INHERIT in existing tables (8.2+ releases)
dpage@[EMAIL PROTECTED]   2008-08-11 09:44:16 
Re: Support of INHERIT in existing tables (8.2+
guillaume@[EMAIL PROTECTE  2008-08-11 14:50:09 
Re: Support of INHERIT in existing tables (8.2+ releases)
dpage@[EMAIL PROTECTED]   2008-08-11 13:53:18 
Re: Support of INHERIT in existing tables (8.2+
guillaume@[EMAIL PROTECTE  2008-08-11 15:02:20 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Dec 1 22:41:02 CST 2008.