Skip to content
This repository has been archived by the owner on Sep 15, 2022. It is now read-only.

Commit

Permalink
Set column stats and comments correctly when creating tables.
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.pgadmin.org/branches/REL-1_2_0_PATCHES@4036 a7884b65-44f6-0310-8a51-81a127f17b15
  • Loading branch information
dpage committed Mar 19, 2005
1 parent 29f9ef9 commit f3086a3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Expand Up @@ -17,6 +17,7 @@ The following list contains all changes to pgAdmin3, as present in cvs.
</ul>
<br>
<ul>
<li>2005-03-18 DP 1.2.1 Set column stats and comments correctly when creating tables.
<li>2005-03-18 DP 1.2.1 Include the hostname in the connect string for Kerberos support, per Magnus Hagander
<li>2005-03-04 DP 1.2.1 Fix aggregate SQL generation per James Prichard
<li>2005-02-07 AHP 1.2.1 fix libpq/ssl library detection
Expand Down
2 changes: 2 additions & 0 deletions src/include/dlgColumn.h
Expand Up @@ -29,6 +29,8 @@ class dlgColumn : public dlgTypeProperty
pgObject *GetObject();
wxString GetDefinition();
wxString GetPreviousDefinition() { return previousDefinition; }
wxString GetComment() { return txtComment->GetValue(); }
wxString GetStatistics() { return CTRL_TEXT("txtAttstattarget")->GetValue(); }

int Go(bool modal);

Expand Down
40 changes: 36 additions & 4 deletions src/ui/dlgTable.cpp
Expand Up @@ -84,6 +84,8 @@ dlgTable::dlgTable(frmMain *frame, pgTable *node, pgSchema *sch)
lstColumns->CreateColumns(frame, _("Column name"), _("Definition"), 90);
lstColumns->AddColumn(wxT("Inherited from table"), 0);
lstColumns->AddColumn(wxT("Column definition"), 0);
lstColumns->AddColumn(wxT("Column comment"), 0);
lstColumns->AddColumn(wxT("Column statistics"), 0);
lstColumns->AddColumn(wxT("Column"), 0);

lstConstraints->CreateColumns(frame, _("Constraint name"), _("Definition"), 90);
Expand Down Expand Up @@ -167,7 +169,7 @@ int dlgTable::Go(bool modal)
column->GetName(), column->GetDefinition());
previousColumns.Add(column->GetQuotedIdentifier()
+ wxT(" ") + column->GetDefinition());
lstColumns->SetItem(pos, 4, NumToStr((long)column));
lstColumns->SetItem(pos, 6, NumToStr((long)column));
if (inherited)
lstColumns->SetItem(pos, 2, _("Inherited"));
}
Expand Down Expand Up @@ -324,7 +326,7 @@ wxString dlgTable::GetSql()
{
sql += definition;

pgColumn *column=(pgColumn*) StrToLong(lstColumns->GetText(pos, 4));
pgColumn *column=(pgColumn*) StrToLong(lstColumns->GetText(pos, 6));
if (column)
{
index=tmpDef.Index(column->GetQuotedIdentifier()
Expand Down Expand Up @@ -460,6 +462,31 @@ wxString dlgTable::GetSql()

AppendOwnerNew(sql, wxT("TABLE ") + tabname);
}

// Extra column info
int pos;

// Statistics
for (pos=0 ; pos < lstColumns->GetItemCount() ; pos++)
{
if (!lstColumns->GetText(pos, 4).IsEmpty())
sql += wxT("ALTER TABLE ") + tabname
+ wxT(" ALTER COLUMN ") + qtIdent(lstColumns->GetText(pos, 0))
+ wxT(" SET STATISTICS ") + lstColumns->GetText(pos, 4)
+ wxT(";\n");
}

// Comments
for (pos=0 ; pos < lstColumns->GetItemCount() ; pos++)
{
if (!lstColumns->GetText(pos, 5).IsEmpty())
sql += wxT("COMMENT ON COLUMN ") + tabname
+ wxT(".") + qtIdent(lstColumns->GetText(pos, 0))
+ wxT(" IS ") + qtString(lstColumns->GetText(pos, 5))
+ wxT(";\n");
}


AppendComment(sql, wxT("TABLE"), schema, table);
sql += GetGrant(wxT("arwdRxt"), wxT("TABLE ") + tabname);

Expand Down Expand Up @@ -587,7 +614,7 @@ void dlgTable::OnSelChangeTable(wxCommandEvent &ev)
void dlgTable::OnChangeCol(wxCommandEvent &ev)
{
long pos=lstColumns->GetSelection();
pgColumn *column=(pgColumn*) StrToLong(lstColumns->GetText(pos, 4));
pgColumn *column=(pgColumn*) StrToLong(lstColumns->GetText(pos, 6));

dlgColumn col(mainForm, column, table);
col.CenterOnParent();
Expand All @@ -597,6 +624,8 @@ void dlgTable::OnChangeCol(wxCommandEvent &ev)
lstColumns->SetItem(pos, 0, col.GetName());
lstColumns->SetItem(pos, 1, col.GetDefinition());
lstColumns->SetItem(pos, 3, col.GetSql());
lstColumns->SetItem(pos, 4, col.GetStatistics());
lstColumns->SetItem(pos, 5, col.GetComment());
}
CheckChange();
}
Expand All @@ -612,6 +641,9 @@ void dlgTable::OnAddCol(wxCommandEvent &ev)
long pos = lstColumns->AppendItem(PGICON_COLUMN, col.GetName(), col.GetDefinition());
if (table && !connection->BackendMinimumVersion(8, 0))
lstColumns->SetItem(pos, 3, col.GetSql());
lstColumns->SetItem(pos, 4, col.GetStatistics());
lstColumns->SetItem(pos, 5, col.GetComment());

}

CheckChange();
Expand All @@ -634,7 +666,7 @@ void dlgTable::OnSelChangeCol(wxListEvent &ev)
wxString inheritedFromTable=lstColumns->GetText(pos, 2);

btnRemoveCol->Enable(inheritedFromTable.IsEmpty());
btnChangeCol->Enable(table != 0 && !lstColumns->GetText(pos, 4).IsEmpty());
btnChangeCol->Enable(table != 0 && !lstColumns->GetText(pos, 6).IsEmpty());
}


Expand Down

0 comments on commit f3086a3

Please sign in to comment.