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

Commit

Permalink
Fix dlgIndex so that we don't specify column options (ASC/DESC, NULLS…
Browse files Browse the repository at this point in the history
… FIRST/LAST) for index types other than btree.

git-svn-id: svn://svn.pgadmin.org/trunk@7874 a7884b65-44f6-0310-8a51-81a127f17b15
  • Loading branch information
dpage committed May 20, 2009
1 parent 480aa5b commit c473ebe
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 7 deletions.
82 changes: 75 additions & 7 deletions pgadmin/dlg/dlgIndex.cpp
Expand Up @@ -158,6 +158,7 @@ BEGIN_EVENT_TABLE(dlgIndex, dlgIndexBase)
#ifdef __WXMAC__
EVT_SIZE( dlgIndex::OnChangeSize)
#endif
EVT_COMBOBOX(XRCID("cbType"), dlgIndex::OnSelectType)
END_EVENT_TABLE();


Expand Down Expand Up @@ -197,6 +198,56 @@ void dlgIndex::CheckChange()
}
}

void dlgIndex::OnSelectType(wxCommandEvent &ev)
{
// The column options available change depending on the
// index type. We need to clear the column list, and
// setup some of the other controls accordingly.

wxString newType = cbType->GetValue();
bool changingDefault = false;

// Detect if we're changing between default and btree (which are the same) to
// avoid annoying the user needlessly.
if ((m_previousType == wxEmptyString && cbType->GetValue() == wxT("btree")) ||
(m_previousType == wxT("btree") && cbType->GetValue() == wxEmptyString))
changingDefault = true;

if (lstColumns->GetItemCount() > 0 && !changingDefault)
{
if (wxMessageBox(_("Changing the index type will cause the column list to be cleared. Do you wish to continue?"), _("Change index type?"), wxYES_NO) == wxNO)
{
cbType->SetValue(m_previousType);
return;
}

// Move all the columns back to the combo
for (int pos = lstColumns->GetItemCount(); pos > 0; pos--)
{
wxString colName = lstColumns->GetItemText(pos - 1);

lstColumns->DeleteItem(pos - 1);
cbColumns->Append(colName);
}
}

if (newType == wxT("btree") || newType == wxEmptyString)
{
chkDesc->Enable(true);
rdbNullsFirst->Enable(true);
rdbNullsLast->Enable(true);
}
else
{
chkDesc->Enable(false);
rdbNullsFirst->Enable(false);
rdbNullsLast->Enable(false);
}

// Make a note of the type so we can compare if it changes again.
m_previousType = cbType->GetValue();
}


wxString dlgIndex::GetColumns()
{
Expand Down Expand Up @@ -235,8 +286,10 @@ int dlgIndex::Go(bool modal)
{
// edit mode: view only

// We only display the column options (ASC/DESC, NULLS FIRST/LAST)
// on PostgreSQL 8.3+, for btree indexes.
wxArrayString colsArr = index->GetColumnList();
if (this->database->BackendMinimumVersion(8, 3))
if (this->database->BackendMinimumVersion(8, 3) && index->GetIndexType() == wxT("btree"))
{
wxString colDef, colRest, colName, descDef, nullsDef;
const wxString firstOrder = wxT(" NULLS FIRST"), lastOrder = wxT(" NULLS LAST"), descOrder = wxT(" DESC");
Expand Down Expand Up @@ -350,21 +403,36 @@ void dlgIndex::OnAddCol(wxCommandEvent &ev)
{
if (chkDesc->GetValue())
{
lstColumns->SetItem(colIndex, 1, wxT("DESC"));
if (chkDesc->IsEnabled())
lstColumns->SetItem(colIndex, 1, wxT("DESC"));


if (rdbNullsLast->GetValue())
lstColumns->SetItem(colIndex, 2, wxT("LAST"));
{
if (rdbNullsLast->IsEnabled())
lstColumns->SetItem(colIndex, 2, wxT("LAST"));
}
else
lstColumns->SetItem(colIndex, 2, wxT("FIRST"));
{
if (rdbNullsLast->IsEnabled())
lstColumns->SetItem(colIndex, 2, wxT("FIRST"));
}
}
else
{
lstColumns->SetItem(colIndex, 1, wxT("ASC"));
if (chkDesc->IsEnabled())
lstColumns->SetItem(colIndex, 1, wxT("ASC"));

if (rdbNullsFirst->GetValue())
lstColumns->SetItem(colIndex, 2, wxT("FIRST"));
{
if (rdbNullsFirst->IsEnabled())
lstColumns->SetItem(colIndex, 2, wxT("FIRST"));
}
else
lstColumns->SetItem(colIndex, 2, wxT("LAST"));
{
if (rdbNullsLast->IsEnabled())
lstColumns->SetItem(colIndex, 2, wxT("LAST"));
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions pgadmin/include/dlg/dlgIndex.h
Expand Up @@ -59,10 +59,13 @@ class dlgIndex : public dlgIndexBase
void OnChangeSize(wxSizeEvent &ev);
#endif

void OnSelectType(wxCommandEvent &ev);
void OnDescChange(wxCommandEvent &ev);
void OnAddCol(wxCommandEvent &ev);
void OnRemoveCol(wxCommandEvent &ev);

wxString m_previousType;

DECLARE_EVENT_TABLE()
};

Expand Down

0 comments on commit c473ebe

Please sign in to comment.