Hi,

Here is a patch to add the support for this new 8.5 functionality. Ticket is 
http://code.pgadmin.org/trac/ticket/95, commitfest item is 
https://commitfest.postgresql.org/action/patch_view?id=73.

It was a quite simple patch. I used the git-svn method to get the code, and 
build the patch. I'm not really used to it right now, I hope to find a real 
use of this method.

Comments?

PS: there are something like 10 new functionalities that need to be supported 
by pgAdmin, I made a list that I'll add as tickets on our trac instance.


-- 
Guillaume.
 http://www.postgresqlfr.org
 http://dalibo.com
diff --git a/pgadmin/dlg/dlgColumn.cpp b/pgadmin/dlg/dlgColumn.cpp
index 520725c..689bf65 100644
--- a/pgadmin/dlg/dlgColumn.cpp
+++ b/pgadmin/dlg/dlgColumn.cpp
@@ -31,6 +31,7 @@
 #define txtDefault          CTRL_TEXT("txtDefault")
 #define chkNotNull          CTRL_CHECKBOX("chkNotNull")
 #define txtAttstattarget    CTRL_TEXT("txtAttstattarget")
+#define txtAttdistinct      CTRL_TEXT("txtAttdistinct")
 
 BEGIN_EVENT_TABLE(dlgColumn, dlgTypeProperty)
     EVT_TEXT(XRCID("txtLength"),                    dlgProperty::OnChange)
@@ -38,6 +39,7 @@ BEGIN_EVENT_TABLE(dlgColumn, dlgTypeProperty)
     EVT_TEXT(XRCID("txtDefault"),                   dlgProperty::OnChange)
     EVT_CHECKBOX(XRCID("chkNotNull"),               dlgProperty::OnChange)
     EVT_TEXT(XRCID("txtAttstattarget"),             dlgProperty::OnChange)
+    EVT_TEXT(XRCID("txtAttdistinct"),             dlgProperty::OnChange)
     EVT_TEXT(XRCID("cbDatatype"),                   dlgColumn::OnSelChangeTyp)
     EVT_COMBOBOX(XRCID("cbDatatype"),               dlgColumn::OnSelChangeTyp)
     EVT_BUTTON(CTL_ADDPRIV,                         dlgColumn::OnAddPriv)
@@ -62,6 +64,8 @@ dlgColumn::dlgColumn(pgaFactory *f, frmMain *frame, pgColumn *node, pgTable *par
     wxASSERT(!table || (table->GetMetaType() == PGM_TABLE || table->GetMetaType() == PGM_VIEW || table->GetMetaType() == GP_EXTTABLE || table->GetMetaType() == GP_PARTITION));
 
     txtAttstattarget->SetValidator(numericValidator);
+    if (connection && connection->BackendMinimumVersion(8, 5))
+        txtAttdistinct->SetValidator(numericValidator);
 
     /* Column Level Privileges */
     securityChanged=false;
@@ -206,6 +210,8 @@ int dlgColumn::Go(bool modal)
         txtDefault->SetValue(column->GetDefault());
         chkNotNull->SetValue(column->GetNotNull());
         txtAttstattarget->SetValue(NumToStr(column->GetAttstattarget()));
+        if (connection && connection->BackendMinimumVersion(8, 5))
+            txtAttdistinct->SetValue(NumToStr(column->GetAttdistinct()));
 
         wxString fullType = column->GetRawTypename();
         if (column->GetIsArray())
@@ -253,6 +259,7 @@ int dlgColumn::Go(bool modal)
             txtLength->Disable();
             cbDatatype->Disable();
             txtAttstattarget->Disable();
+            txtAttdistinct->Disable();
         }
         else if (column->GetTable()->GetMetaType() == PGM_VIEW) // Disable controls not valid for view columns
         {
@@ -261,6 +268,7 @@ int dlgColumn::Go(bool modal)
             txtLength->Disable();
             cbDatatype->Disable();
             txtAttstattarget->Disable();
+            txtAttdistinct->Disable();
         }
          else if (column->GetTable()->GetMetaType() == GP_EXTTABLE) // Disable controls not valid for external table columns
         {
@@ -269,6 +277,7 @@ int dlgColumn::Go(bool modal)
             txtLength->Disable();
             cbDatatype->Disable();
             txtAttstattarget->Disable();
+            txtAttdistinct->Disable();
             txtDefault->Disable();
         }
     }
@@ -288,6 +297,7 @@ int dlgColumn::Go(bool modal)
         }
 
         txtAttstattarget->Disable();
+        txtAttdistinct->Disable();
         txtComment->Disable();
     }
     return dlgTypeProperty::Go(modal);
@@ -389,6 +399,19 @@ wxString dlgColumn::GetSql()
                     sql += wxT(" SET STATISTICS ") + txtAttstattarget->GetValue();
                 sql += wxT(";\n");
             }
+            if (connection->BackendMinimumVersion(8, 5))
+            {
+                if (txtAttdistinct->GetValue() != NumToStr(column->GetAttdistinct()))
+                {
+                    sql += wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier()
+                        +  wxT("\n   ALTER COLUMN ") + qtIdent(name);
+                    if (txtAttdistinct->GetValue().IsEmpty())
+                        sql += wxT(" SET STATISTICS DISTINCT 0");
+                    else
+                        sql += wxT(" SET STATISTICS DISTINCT ") + txtAttdistinct->GetValue();
+                    sql += wxT(";\n");
+                }
+            }
         }
         else
         {
@@ -409,6 +432,15 @@ wxString dlgColumn::GetSql()
                     + wxT("\n   ALTER COLUMN ") + qtIdent(name)
                     + wxT(" SET STATISTICS ") + txtAttstattarget->GetValue()
                     + wxT(";\n");
+
+            if (connection->BackendMinimumVersion(8, 5))
+            {
+                if (!txtAttdistinct->GetValue().IsEmpty())
+                    sql += wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier()
+                        + wxT("\n   ALTER COLUMN ") + qtIdent(name)
+                        + wxT(" SET DISTINCT ") + txtAttdistinct->GetValue()
+                        + wxT(";\n");
+            }
         }
 
         AppendComment(sql, wxT("COLUMN ") + table->GetQuotedFullIdentifier() 
@@ -494,7 +526,8 @@ void dlgColumn::CheckChange()
                     || (cbDatatype->GetCount() > 1 && cbDatatype->GetGuessedStringSelection() != column->GetRawTypename())
                     || (isVarLen && varlen != column->GetLength())
                     || (isVarPrec && varprec != column->GetPrecision())
-                    || txtAttstattarget->GetValue() != NumToStr(column->GetAttstattarget());
+                    || txtAttstattarget->GetValue() != NumToStr(column->GetAttstattarget())
+                    || txtAttdistinct->GetValue() != NumToStr(column->GetAttdistinct());
 
         EnableOK(enable | securityChanged);
     }
diff --git a/pgadmin/include/schema/pgColumn.h b/pgadmin/include/schema/pgColumn.h
index 425631c..7a82f0e 100644
--- a/pgadmin/include/schema/pgColumn.h
+++ b/pgadmin/include/schema/pgColumn.h
@@ -83,6 +83,8 @@ public:
     void iSetAttTypId(const OID o) { attTypId =o; }
     long GetAttstattarget() const { return attstattarget; }
     void iSetAttstattarget(const long l) { attstattarget=l; }
+    long GetAttdistinct() const { return attdistinct; }
+    void iSetAttdistinct(const long l) { attdistinct=l; }
     wxString GetSerialSequence() const { return serialSequence; }
     void iSetSerialSequence(const wxString &s) { serialSequence=s; }
     wxString GetSerialSchema() const { return serialSchema; }
@@ -108,7 +110,7 @@ public:
 private:
     wxString varTypename, quotedTypename, defaultVal, tableName, quotedFullTable, storage, rawTypename;
     wxString serialSequence, serialSchema, pkCols, inheritedTableName;
-    long colNumber, length, precision, statistics, attstattarget;
+    long colNumber, length, precision, statistics, attstattarget, attdistinct;
     long typlen, typmod, inheritedCount;
     bool isPK, isFK, notNull, isArray, isLocal;
     OID attTypId;
diff --git a/pgadmin/schema/pgColumn.cpp b/pgadmin/schema/pgColumn.cpp
index 619d45b..f9264cf 100644
--- a/pgadmin/schema/pgColumn.cpp
+++ b/pgadmin/schema/pgColumn.cpp
@@ -120,6 +120,10 @@ wxString pgColumn::GetSql(ctlTree *browser)
                     sql += wxT("ALTER TABLE ") + GetQuotedFullTable()
                         + wxT(" ALTER COLUMN ") + GetQuotedIdentifier()
                         + wxT(" SET STATISTICS ") + NumToStr(GetAttstattarget()) + wxT(";\n");
+                if (database->BackendMinimumVersion(8, 5) && GetAttdistinct() >= 0)
+                    sql += wxT("ALTER TABLE ") + GetQuotedFullTable()
+                        + wxT(" ALTER COLUMN ") + GetQuotedIdentifier()
+                        + wxT(" SET STATISTICS DISTINCT ") + NumToStr(GetAttdistinct()) + wxT(";\n");
 
                 sql += GetCommentSql();
 
@@ -314,6 +318,8 @@ void pgColumn::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *prop
                     properties->AppendItem(_("Inherited"), false);
                 }
                 properties->AppendItem(_("Statistics"), GetAttstattarget());
+                if (database->BackendMinimumVersion(8, 5))
+                    properties->AppendItem(_("Distincts"), GetAttdistinct());
 
 
                 properties->AppendItem(_("System column?"), GetSystemObject());
@@ -378,6 +384,10 @@ pgObject *pgColumnFactory::CreateObjects(pgCollection *coll, ctlTree *browser, c
         wxT("       ELSE NULL\n")
         wxT("  END AS inhrelname");
 
+    if (database->BackendMinimumVersion(8, 5))
+        sql += 
+            wxT(",\n")
+            wxT("  attdistinct");
     if (database->BackendMinimumVersion(7, 4))
         sql += 
             wxT(",\n")
@@ -453,6 +463,8 @@ pgObject *pgColumnFactory::CreateObjects(pgCollection *coll, ctlTree *browser, c
             column->iSetInheritedTableName(columns->GetVal(wxT("inhrelname")));
             column->iSetIsLocal(columns->GetBool(wxT("attislocal")));
             column->iSetAttstattarget(columns->GetLong(wxT("attstattarget")));
+            if (database->BackendMinimumVersion(8, 5))
+                column->iSetAttdistinct(columns->GetLong(wxT("attdistinct")));
             if (database->BackendMinimumVersion(8, 4))
                 column->iSetAcl(columns->GetVal(wxT("attacl")));
 
diff --git a/pgadmin/ui/dlgColumn.xrc b/pgadmin/ui/dlgColumn.xrc
index c16f8ec..a0a0983 100644
--- a/pgadmin/ui/dlgColumn.xrc
+++ b/pgadmin/ui/dlgColumn.xrc
@@ -17,10 +17,10 @@
             <object class="wxPanel" name="pnlProperties">
               <object class="wxFlexGridSizer">
                 <cols>2</cols>
-                <rows>9</rows>
+                <rows>10</rows>
                 <vgap>5</vgap>
                 <hgap>5</hgap>
-                <growablerows>7</growablerows>
+                <growablerows>8</growablerows>
                 <growablecols>1</growablecols>
                 <object class="sizeritem">
                   <object class="wxStaticText" name="stName">
@@ -117,6 +117,19 @@
                   <border>4</border>
                 </object>
                 <object class="sizeritem">
+                  <object class="wxStaticText" name="stAttdistinct">
+                    <label>Distincts</label>
+                  </object>
+                  <flag>wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>
+                <object class="sizeritem">
+                  <object class="wxTextCtrl" name="txtAttdistinct">
+                  </object>
+                  <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>
+                <object class="sizeritem">
                   <object class="wxStaticText" name="stComment">
                     <label>Comment</label>
                   </object>
-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers

Reply via email to