~ubuntu-branches/ubuntu/utopic/pgadmin3/utopic-proposed

« back to all changes in this revision

Viewing changes to pgadmin/dlg/dlgIndex.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gerfried Fuchs
  • Date: 2011-06-07 23:03:54 UTC
  • mfrom: (1.3.1 upstream) (13 sid)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20110607230354-3td4j9y71u4ahcvj
Tags: 1.14.0~beta1-1
* New upstream development release, adding Build-Depends on
  postgresql-server-dev-all >= 117~.
* Add Build-Depends on quilt, (un)patch to debian/rules and patch for fixing
  the include for kwlist.h in pgadmin/db/keywords.c.
* Add pg_config --includedir-server output to CPPFLAGS.
* Remove unrecognized configure options: --with-wx-config,
  --with-pgsql-include, --enable-gtk2, --enable-unicode.
* Clean up manually the files that are left behind after the broken
  distclean.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//////////////////////////////////////////////////////////////////////////
2
2
//
3
3
// pgAdmin III - PostgreSQL Tools
4
 
// 
5
 
// Copyright (C) 2002 - 2010, The pgAdmin Development Team
 
4
//
 
5
// Copyright (C) 2002 - 2011, The pgAdmin Development Team
6
6
// This software is released under the PostgreSQL Licence
7
7
//
8
8
// dlgIndex.cpp - PostgreSQL Index Property
30
30
#define txtWhere        CTRL_TEXT("txtWhere")
31
31
#define txtFillFactor   CTRL_TEXT("txtFillFactor")
32
32
#define cbOpClass       CTRL_COMBOBOX("cbOpClass")
33
 
 
34
33
#define chkDesc         CTRL_CHECKBOX("chkDesc")
35
34
#define rdbNullsFirst   CTRL_RADIOBUTTON("rdbNullsFirst")
36
35
#define rdbNullsLast    CTRL_RADIOBUTTON("rdbNullsLast")
 
36
#define cbCollation     CTRL_COMBOBOX("cbCollation")
37
37
 
38
38
 
39
39
BEGIN_EVENT_TABLE(dlgIndexBase, dlgCollistProperty)
40
 
    EVT_TEXT(XRCID("cbTablespace"),                 dlgProperty::OnChange)
41
 
    EVT_COMBOBOX(XRCID("cbTablespace"),             dlgProperty::OnChange)
42
 
    EVT_TEXT(XRCID("txtFillFactor"),                dlgProperty::OnChange)
43
 
    EVT_LIST_ITEM_SELECTED(XRCID("lstColumns"),     dlgIndexBase::OnSelectListCol)
44
 
    EVT_COMBOBOX(XRCID("cbColumns"),                dlgIndexBase::OnSelectComboCol)
 
40
        EVT_TEXT(XRCID("cbTablespace"),                 dlgProperty::OnChange)
 
41
        EVT_COMBOBOX(XRCID("cbTablespace"),             dlgProperty::OnChange)
 
42
        EVT_TEXT(XRCID("txtFillFactor"),                dlgProperty::OnChange)
 
43
        EVT_LIST_ITEM_SELECTED(XRCID("lstColumns"),     dlgIndexBase::OnSelectListCol)
 
44
        EVT_COMBOBOX(XRCID("cbColumns"),                dlgIndexBase::OnSelectComboCol)
45
45
END_EVENT_TABLE();
46
46
 
47
47
 
48
48
dlgProperty *pgIndexFactory::CreateDialog(frmMain *frame, pgObject *node, pgObject *parent)
49
49
{
50
 
    return new dlgIndex(this, frame, (pgIndex*)node, (pgTable*)parent);
 
50
        return new dlgIndex(this, frame, (pgIndex *)node, (pgTable *)parent);
51
51
}
52
52
 
53
53
 
54
54
dlgIndexBase::dlgIndexBase(pgaFactory *f, frmMain *frame, const wxString &resName, pgIndexBase *node, pgTable *parentNode)
55
 
: dlgCollistProperty(f, frame, resName, parentNode)
 
55
        : dlgCollistProperty(f, frame, resName, parentNode)
56
56
{
57
 
    index=node;
58
 
    wxASSERT(!table || table->GetMetaType() == PGM_TABLE || table->GetMetaType() == GP_PARTITION);
 
57
        index = node;
 
58
        wxASSERT(!table || table->GetMetaType() == PGM_TABLE || table->GetMetaType() == GP_PARTITION);
59
59
}
60
60
 
61
61
 
62
62
dlgIndexBase::dlgIndexBase(pgaFactory *f, frmMain *frame, const wxString &resName, ctlListView *colList)
63
 
: dlgCollistProperty(f, frame, resName, colList)
 
63
        : dlgCollistProperty(f, frame, resName, colList)
64
64
{
65
 
    index=0;
 
65
        index = 0;
66
66
}
67
67
 
68
68
 
69
69
pgObject *dlgIndexBase::GetObject()
70
70
{
71
 
    return index;
 
71
        return index;
72
72
}
73
73
 
74
74
 
75
75
int dlgIndexBase::Go(bool modal)
76
76
{
77
77
 
78
 
    if (index)
79
 
    {
80
 
        // edit mode: view only
81
 
        txtName->Disable();
82
 
        cbColumns->Disable();
83
 
 
84
 
        if (txtFillFactor)
85
 
        {
86
 
            txtFillFactor->SetValue(index->GetFillFactor());
87
 
        }
88
 
    }
89
 
    else
90
 
    {
91
 
        // create mode
92
 
    }
93
 
 
94
 
    if (txtFillFactor)
95
 
    {
96
 
        txtFillFactor->SetValidator(numericValidator);
97
 
        if (connection->BackendMinimumVersion(8, 2))
98
 
            txtFillFactor->Enable();
99
 
        else
100
 
            txtFillFactor->Disable();
101
 
    }
102
 
 
103
 
    btnAddCol->Disable();
104
 
    btnRemoveCol->Disable();
105
 
 
106
 
    return dlgCollistProperty::Go(modal);
 
78
        if (index)
 
79
        {
 
80
                // edit mode: view only
 
81
                txtName->Disable();
 
82
                cbColumns->Disable();
 
83
 
 
84
                if (txtFillFactor)
 
85
                {
 
86
                        txtFillFactor->SetValue(index->GetFillFactor());
 
87
                }
 
88
        }
 
89
        else
 
90
        {
 
91
                // create mode
 
92
        }
 
93
 
 
94
        if (txtFillFactor)
 
95
        {
 
96
                txtFillFactor->SetValidator(numericValidator);
 
97
                if (connection->BackendMinimumVersion(8, 2))
 
98
                        txtFillFactor->Enable();
 
99
                else
 
100
                        txtFillFactor->Disable();
 
101
        }
 
102
 
 
103
        btnAddCol->Disable();
 
104
        btnRemoveCol->Disable();
 
105
 
 
106
        return dlgCollistProperty::Go(modal);
107
107
}
108
108
 
109
109
void dlgIndexBase::OnSelectListCol(wxListEvent &ev)
110
110
{
111
 
    OnSelectCol();
 
111
        OnSelectCol();
112
112
}
113
113
 
114
114
void dlgIndexBase::OnSelectComboCol(wxCommandEvent &ev)
115
115
{
116
 
    if (cbType)
117
 
    {
118
 
        if (cbType->GetValue().Length() > 0)
119
 
        {
120
 
            cbOpClass->Clear();
121
 
 
122
 
            wxString sql = wxT("SELECT opcname FROM pg_opclass ");
123
 
            sql+= wxT("WHERE opcintype=");
124
 
            sql+= NumToStr(cbColumns->GetOIDKey(cbColumns->GetCurrentSelection()));
125
 
            sql+= wxT("AND opcmethod=") + cbType->GetStringKey(cbType->GetCurrentSelection())
126
 
                + wxT(" AND NOT opcdefault")
127
 
                + wxT(" ORDER BY 1");
128
 
            pgSet *set=connection->ExecuteSet(sql);
129
 
            if (set)
130
 
            {
131
 
                while (!set->Eof())
132
 
                {
133
 
                    cbOpClass->Append(set->GetVal(0));
134
 
                    set->MoveNext();
135
 
                }
136
 
                delete set;
137
 
            }
138
 
        }
139
 
    }
140
 
 
141
 
    OnSelectCol();
 
116
        if (cbType)
 
117
        {
 
118
                if (cbType->GetValue().Length() > 0)
 
119
                {
 
120
                        cbOpClass->Clear();
 
121
 
 
122
                        wxString sql = wxT("SELECT opcname FROM pg_opclass ");
 
123
                        sql += wxT("WHERE opcintype=");
 
124
                        sql += NumToStr(cbColumns->GetOIDKey(cbColumns->GetCurrentSelection()));
 
125
                        sql += wxT("AND opcmethod=") + cbType->GetStringKey(cbType->GetCurrentSelection())
 
126
                               + wxT(" AND NOT opcdefault")
 
127
                               + wxT(" ORDER BY 1");
 
128
                        pgSet *set = connection->ExecuteSet(sql);
 
129
                        if (set)
 
130
                        {
 
131
                                while (!set->Eof())
 
132
                                {
 
133
                                        cbOpClass->Append(set->GetVal(0));
 
134
                                        set->MoveNext();
 
135
                                }
 
136
                                delete set;
 
137
                        }
 
138
                }
 
139
        }
 
140
 
 
141
        OnSelectCol();
142
142
}
143
143
 
144
144
void dlgIndexBase::OnSelectCol()
147
147
        if (index)
148
148
                return;
149
149
 
150
 
    if (lstColumns->GetSelection() != wxNOT_FOUND)
151
 
        btnRemoveCol->Enable(true);
152
 
    else
153
 
        btnRemoveCol->Enable(false);
 
150
        if (lstColumns->GetSelection() != wxNOT_FOUND)
 
151
                btnRemoveCol->Enable(true);
 
152
        else
 
153
                btnRemoveCol->Enable(false);
154
154
 
155
 
    if (cbColumns->GetSelection() != wxNOT_FOUND && !cbColumns->GetValue().IsEmpty())
156
 
        btnAddCol->Enable(true);
157
 
    else
158
 
        btnAddCol->Enable(false);
 
155
        if (cbColumns->GetSelection() != wxNOT_FOUND && !cbColumns->GetValue().IsEmpty())
 
156
                btnAddCol->Enable(true);
 
157
        else
 
158
                btnAddCol->Enable(false);
159
159
}
160
160
 
161
161
 
162
162
void dlgIndexBase::CheckChange()
163
163
{
164
 
    if (index)
165
 
    {
166
 
        EnableOK(txtComment->GetValue() != index->GetComment() ||
167
 
                 cbTablespace->GetOIDKey() != index->GetTablespaceOid());
168
 
    }
169
 
    else
170
 
    {
171
 
        bool enable=true;
172
 
        txtComment->Enable(!GetName().IsEmpty());
173
 
        CheckValid(enable, lstColumns->GetItemCount() > 0, _("Please specify columns."));
174
 
        EnableOK(enable);
175
 
    }
 
164
        if (index)
 
165
        {
 
166
                EnableOK(txtComment->GetValue() != index->GetComment() ||
 
167
                         cbTablespace->GetOIDKey() != index->GetTablespaceOid());
 
168
        }
 
169
        else
 
170
        {
 
171
                bool enable = true;
 
172
                txtComment->Enable(!GetName().IsEmpty());
 
173
                CheckValid(enable, lstColumns->GetItemCount() > 0, _("Please specify columns."));
 
174
                EnableOK(enable);
 
175
        }
176
176
}
177
177
 
178
178
 
179
179
BEGIN_EVENT_TABLE(dlgIndex, dlgIndexBase)
180
 
    EVT_BUTTON(XRCID("btnAddCol"),                  dlgIndex::OnAddCol)
181
 
    EVT_BUTTON(XRCID("btnRemoveCol"),               dlgIndex::OnRemoveCol)
182
 
    EVT_CHECKBOX(XRCID("chkClustered"),             dlgProperty::OnChange)
183
 
    EVT_CHECKBOX(XRCID("chkDesc"),                  dlgIndex::OnDescChange)
 
180
        EVT_BUTTON(XRCID("btnAddCol"),                  dlgIndex::OnAddCol)
 
181
        EVT_BUTTON(XRCID("btnRemoveCol"),               dlgIndex::OnRemoveCol)
 
182
        EVT_CHECKBOX(XRCID("chkClustered"),             dlgProperty::OnChange)
 
183
        EVT_CHECKBOX(XRCID("chkDesc"),                  dlgIndex::OnDescChange)
184
184
#ifdef __WXMAC__
185
 
    EVT_SIZE(                                       dlgIndex::OnChangeSize)
 
185
        EVT_SIZE(                                       dlgIndex::OnChangeSize)
186
186
#endif
187
 
    EVT_COMBOBOX(XRCID("cbType"),                   dlgIndex::OnSelectType)
 
187
        EVT_COMBOBOX(XRCID("cbType"),                   dlgIndex::OnSelectType)
188
188
END_EVENT_TABLE();
189
189
 
190
 
        
 
190
 
191
191
dlgIndex::dlgIndex(pgaFactory *f, frmMain *frame, pgIndex *index, pgTable *parentNode)
192
 
: dlgIndexBase(f, frame, wxT("dlgIndex"), index, parentNode)
 
192
        : dlgIndexBase(f, frame, wxT("dlgIndex"), index, parentNode)
193
193
{
194
 
    lstColumns->AddColumn(_("Column name"), 90);
195
 
    lstColumns->AddColumn(_("Order"), 40);
196
 
    lstColumns->AddColumn(_("NULLs order"), 50);
197
 
    lstColumns->AddColumn(_("Op. class"), 40);
 
194
        lstColumns->AddColumn(_("Column name"), 90);
 
195
        lstColumns->AddColumn(_("Order"), 40);
 
196
        lstColumns->AddColumn(_("NULLs order"), 50);
 
197
        lstColumns->AddColumn(_("Op. class"), 40);
 
198
        lstColumns->AddColumn(_("Collation"), 40);
198
199
}
199
200
 
200
201
 
201
202
void dlgIndex::CheckChange()
202
203
{
203
 
    bool fill=false;
204
 
 
205
 
    if (index)
206
 
    {
207
 
        if (txtFillFactor)
208
 
        {
209
 
            fill = txtFillFactor->GetValue() != index->GetFillFactor() && !txtFillFactor->GetValue().IsEmpty();
210
 
        }
211
 
 
212
 
        EnableOK(fill || 
213
 
                 txtComment->GetValue() != index->GetComment() || 
214
 
                 chkClustered->GetValue() != index->GetIsClustered() ||
215
 
                 cbTablespace->GetOIDKey() != index->GetTablespaceOid() ||
216
 
                 (txtName->GetValue() != index->GetName() && 
217
 
                 txtName->GetValue().Length() != 0));
218
 
    }
219
 
    else
220
 
    {
221
 
        wxString name=GetName();
222
 
 
223
 
        bool enable=true;
224
 
        CheckValid(enable, !name.IsEmpty() || (name.IsEmpty() && this->database->BackendMinimumVersion(9, 0)), _("Please specify name."));
225
 
        CheckValid(enable, lstColumns->GetItemCount() > 0, _("Please specify columns."));
226
 
        EnableOK(enable);
227
 
    }
 
204
        bool fill = false;
 
205
 
 
206
        if (index)
 
207
        {
 
208
                if (txtFillFactor)
 
209
                {
 
210
                        fill = txtFillFactor->GetValue() != index->GetFillFactor() && !txtFillFactor->GetValue().IsEmpty();
 
211
                }
 
212
 
 
213
                EnableOK(fill ||
 
214
                         txtComment->GetValue() != index->GetComment() ||
 
215
                         chkClustered->GetValue() != index->GetIsClustered() ||
 
216
                         cbTablespace->GetOIDKey() != index->GetTablespaceOid() ||
 
217
                         (txtName->GetValue() != index->GetName() &&
 
218
                          txtName->GetValue().Length() != 0));
 
219
        }
 
220
        else
 
221
        {
 
222
                wxString name = GetName();
 
223
 
 
224
                bool enable = true;
 
225
                CheckValid(enable, !name.IsEmpty() || (name.IsEmpty() && this->database->BackendMinimumVersion(9, 0)), _("Please specify name."));
 
226
                CheckValid(enable, lstColumns->GetItemCount() > 0, _("Please specify columns."));
 
227
                EnableOK(enable);
 
228
        }
228
229
}
229
230
 
230
231
void dlgIndex::OnSelectType(wxCommandEvent &ev)
231
232
{
232
 
    // The column options available change depending on the
233
 
    // index type. We need to clear the column list, and 
234
 
    // setup some of the other controls accordingly.
235
 
 
236
 
    wxString newType = cbType->GetValue();
237
 
    bool changingDefault = false;
238
 
 
239
 
    // Detect if we're changing between default and btree (which are the same) to
240
 
    // avoid annoying the user needlessly.
241
 
    if ((m_previousType == wxEmptyString && cbType->GetValue() == wxT("btree")) ||
242
 
        (m_previousType == wxT("btree") && cbType->GetValue() == wxEmptyString))
243
 
        changingDefault = true;
244
 
 
245
 
    if (lstColumns->GetItemCount() > 0 && !changingDefault)
246
 
    {
247
 
        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)
248
 
        {
249
 
            cbType->SetValue(m_previousType);
250
 
            return;
251
 
        }
252
 
 
253
 
        // Move all the columns back to the combo
254
 
        for (int pos = lstColumns->GetItemCount(); pos > 0; pos--)
255
 
        {
256
 
            wxString colName = lstColumns->GetItemText(pos - 1);
257
 
 
258
 
            lstColumns->DeleteItem(pos - 1);
259
 
            cbColumns->Append(colName);
260
 
        }
261
 
    }
262
 
 
263
 
    if (newType == wxT("btree") || newType == wxEmptyString)
264
 
    {
265
 
        cbOpClass->Enable(true);
266
 
        chkDesc->Enable(true);
267
 
        rdbNullsFirst->Enable(true);
268
 
        rdbNullsLast->Enable(true);
269
 
    }
270
 
    else
271
 
    {
272
 
        cbOpClass->Enable(false);
273
 
        chkDesc->Enable(false);
274
 
        rdbNullsFirst->Enable(false);
275
 
        rdbNullsLast->Enable(false);
276
 
    }
277
 
 
278
 
    // Make a note of the type so we can compare if it changes again.
279
 
    m_previousType = cbType->GetValue();
 
233
        // The column options available change depending on the
 
234
        // index type. We need to clear the column list, and
 
235
        // setup some of the other controls accordingly.
 
236
 
 
237
        wxString newType = cbType->GetValue();
 
238
        bool changingDefault = false;
 
239
 
 
240
        // Detect if we're changing between default and btree (which are the same) to
 
241
        // avoid annoying the user needlessly.
 
242
        if ((m_previousType == wxEmptyString && cbType->GetValue() == wxT("btree")) ||
 
243
                (m_previousType == wxT("btree") && cbType->GetValue() == wxEmptyString))
 
244
                changingDefault = true;
 
245
 
 
246
        if (lstColumns->GetItemCount() > 0 && !changingDefault)
 
247
        {
 
248
                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)
 
249
                {
 
250
                        cbType->SetValue(m_previousType);
 
251
                        return;
 
252
                }
 
253
 
 
254
                // Move all the columns back to the combo
 
255
                for (int pos = lstColumns->GetItemCount(); pos > 0; pos--)
 
256
                {
 
257
                        wxString colName = lstColumns->GetItemText(pos - 1);
 
258
 
 
259
                        lstColumns->DeleteItem(pos - 1);
 
260
                        cbColumns->Append(colName);
 
261
                }
 
262
        }
 
263
 
 
264
        if (newType == wxT("btree") || newType == wxEmptyString)
 
265
        {
 
266
                cbOpClass->Enable(true);
 
267
                chkDesc->Enable(true);
 
268
                rdbNullsFirst->Enable(true);
 
269
                rdbNullsLast->Enable(true);
 
270
        }
 
271
        else
 
272
        {
 
273
                cbOpClass->Enable(false);
 
274
                chkDesc->Enable(false);
 
275
                rdbNullsFirst->Enable(false);
 
276
                rdbNullsLast->Enable(false);
 
277
        }
 
278
 
 
279
        // Make a note of the type so we can compare if it changes again.
 
280
        m_previousType = cbType->GetValue();
280
281
}
281
282
 
282
283
 
283
284
wxString dlgIndex::GetColumns()
284
285
{
285
 
    wxString sql;
286
 
 
287
 
    int pos;
288
 
    // iterate cols
289
 
    for (pos=0 ; pos < lstColumns->GetItemCount() ; pos++)
290
 
    {
291
 
        if (pos)
292
 
            sql += wxT(", ");
293
 
 
294
 
        sql += qtIdent(lstColumns->GetItemText(pos));
295
 
 
296
 
        wxString opclass = lstColumns->GetText(pos, 3);
297
 
        if (!opclass.IsEmpty())
298
 
            sql += wxT(" ") + opclass;
299
 
 
300
 
        if (this->database->BackendMinimumVersion(8, 3))
301
 
        {
302
 
            wxString order = lstColumns->GetText(pos, 1);
303
 
            if (!order.IsEmpty())
304
 
                sql += wxT(" ") + order;
305
 
 
306
 
            wxString nullsOrder = lstColumns->GetText(pos, 2);
307
 
            if (!nullsOrder.IsEmpty())
308
 
                sql += wxT(" NULLS ") + nullsOrder;
309
 
        }
310
 
    }
311
 
    return sql;
 
286
        wxString sql;
 
287
 
 
288
        int pos;
 
289
        // iterate cols
 
290
        for (pos = 0 ; pos < lstColumns->GetItemCount() ; pos++)
 
291
        {
 
292
                if (pos)
 
293
                        sql += wxT(", ");
 
294
 
 
295
                sql += qtIdent(lstColumns->GetItemText(pos));
 
296
 
 
297
                if (this->database->BackendMinimumVersion(9, 1))
 
298
                {
 
299
                        wxString collation = lstColumns->GetText(pos, 4);
 
300
                        if (!collation.IsEmpty() && collation != wxT("pg_catalog.\"default\""))
 
301
                                sql += wxT(" COLLATE ") + collation;
 
302
                }
 
303
 
 
304
                wxString opclass = lstColumns->GetText(pos, 3);
 
305
                if (!opclass.IsEmpty())
 
306
                        sql += wxT(" ") + opclass;
 
307
 
 
308
                if (this->database->BackendMinimumVersion(8, 3))
 
309
                {
 
310
                        wxString order = lstColumns->GetText(pos, 1);
 
311
                        if (!order.IsEmpty())
 
312
                                sql += wxT(" ") + order;
 
313
 
 
314
                        wxString nullsOrder = lstColumns->GetText(pos, 2);
 
315
                        if (!nullsOrder.IsEmpty())
 
316
                                sql += wxT(" NULLS ") + nullsOrder;
 
317
                }
 
318
        }
 
319
        return sql;
312
320
}
313
321
 
314
322
 
315
323
int dlgIndex::Go(bool modal)
316
324
{
317
 
    if (!connection->BackendMinimumVersion(7, 4))
318
 
        chkClustered->Disable();
319
 
 
320
 
    if (index)
321
 
    {
322
 
        // edit mode: view only
323
 
 
324
 
        // We only display the column options (ASC/DESC, NULLS FIRST/LAST)
325
 
        // on PostgreSQL 8.3+, for btree indexes.
 
325
        if (!connection->BackendMinimumVersion(7, 4))
 
326
                chkClustered->Disable();
 
327
 
 
328
        if (index)
 
329
        {
 
330
                // edit mode: view only
 
331
 
 
332
                // We only display the column options (ASC/DESC, NULLS FIRST/LAST)
 
333
                // on PostgreSQL 8.3+, for btree indexes.
326
334
                wxArrayString colsArr = index->GetColumnList();
327
 
        wxString colDef, colRest, colName, descDef, nullsDef, opclassDef;
328
 
        const wxString firstOrder = wxT(" NULLS FIRST"), lastOrder = wxT(" NULLS LAST"), descOrder = wxT(" DESC");
329
 
        if (this->database->BackendMinimumVersion(8, 3) && index->GetIndexType() == wxT("btree"))
330
 
        {
331
 
            for (int colIdx=0,colsCount=colsArr.Count(); colIdx<colsCount; colIdx++)
332
 
            {
333
 
                colDef = colsArr.Item(colIdx);
334
 
 
335
 
                if (colDef.EndsWith(firstOrder.GetData(), &colRest))
336
 
                {
337
 
                    colDef = colRest;
338
 
                    nullsDef = wxT("FIRST");
339
 
                }
340
 
                else if (colDef.EndsWith(lastOrder.GetData(), &colRest))
341
 
                {
342
 
                    colDef = colRest;
343
 
                    nullsDef = wxT("LAST");
344
 
                }
345
 
                else
346
 
                    nullsDef = wxT("");
347
 
 
348
 
                if (colDef.EndsWith(descOrder.GetData(), &colRest))
349
 
                {
350
 
                    colDef = colRest;
351
 
                    descDef = wxT("DESC");
352
 
                    if (nullsDef.IsEmpty())
353
 
                        nullsDef = wxT("FIRST");
354
 
                }
355
 
                else
356
 
                {
357
 
                    descDef = wxT("ASC");
358
 
                    if (nullsDef.IsEmpty())
359
 
                        nullsDef = wxT("LAST");
360
 
                }
361
 
 
362
 
                int pos = colDef.First(wxT(" "));
363
 
                if (pos > 0)
364
 
                {
365
 
                    opclassDef = colDef.Mid(pos + 1);
366
 
                    colDef = colDef.Mid(0, pos - 1);
367
 
                }
368
 
                else
369
 
                    opclassDef = wxEmptyString;
370
 
 
371
 
                            lstColumns->InsertItem(colIdx, colDef, columnFactory.GetIconId());
372
 
                lstColumns->SetItem(colIdx, 1, descDef);
373
 
                lstColumns->SetItem(colIdx, 2, nullsDef);
374
 
                lstColumns->SetItem(colIdx, 3, opclassDef);
375
 
            }
376
 
        }
377
 
        else
378
 
        {
379
 
            for (int colIdx=0,colsCount=colsArr.Count(); colIdx<colsCount; colIdx++)
380
 
            {
381
 
                int pos = colDef.First(wxT(" "));
382
 
                if (pos > 0)
383
 
                {
384
 
                    colDef = colRest;
385
 
                    opclassDef = colDef.Mid(pos + 1);
386
 
                    colDef = colDef.Mid(0, pos - 1);
387
 
                }
388
 
                else
389
 
                    opclassDef = wxEmptyString;
390
 
 
391
 
                            lstColumns->InsertItem(colIdx, colsArr.Item(colIdx), columnFactory.GetIconId());
392
 
                lstColumns->SetItem(colIdx, 3, cbOpClass->GetValue());
393
 
            }
394
 
        }
395
 
 
396
 
        cbType->Append(index->GetIndexType());
397
 
        chkUnique->SetValue(index->GetIsUnique());
398
 
        chkClustered->SetValue(index->GetIsClustered());
399
 
        txtWhere->SetValue(index->GetConstraint());
400
 
        cbType->SetSelection(0);
401
 
        cbType->Disable();
402
 
        txtWhere->Disable();
403
 
        chkUnique->Disable();
404
 
        chkConcurrent->Disable();
405
 
        PrepareTablespace(cbTablespace, index->GetTablespaceOid());
406
 
        cbOpClass->Disable();
407
 
        chkDesc->Disable();
408
 
        rdbNullsFirst->Disable();
409
 
        rdbNullsLast->Disable();
410
 
    }
411
 
    else
412
 
    {
413
 
        // create mode
414
 
        PrepareTablespace(cbTablespace);
415
 
        cbType->Append(wxT(""));
416
 
        pgSet *set=connection->ExecuteSet(wxT(
417
 
            "SELECT oid, amname FROM pg_am"));
418
 
        if (set)
419
 
        {
420
 
            while (!set->Eof())
421
 
            {
422
 
                cbType->Append(set->GetVal(1), set->GetVal(0));
423
 
                set->MoveNext();
424
 
            }
425
 
            delete set;
426
 
        }
427
 
 
428
 
        if (!this->database->BackendMinimumVersion(8, 2))
429
 
            chkConcurrent->Disable();
430
 
 
431
 
        if (!this->database->BackendMinimumVersion(8, 3))
432
 
        {
433
 
            chkDesc->Disable();
434
 
            rdbNullsFirst->Disable();
435
 
            rdbNullsLast->Disable();
436
 
        }
437
 
 
438
 
        // Add the default tablespace 
439
 
        cbTablespace->Insert(_("<default tablespace>"), 0, (void *)0);
440
 
        cbTablespace->SetSelection(0);
441
 
    }
442
 
 
443
 
    int returnCode = dlgIndexBase::Go(modal);
444
 
 
445
 
    if (index && connection->BackendMinimumVersion(8, 0))
446
 
        txtName->Enable(true);
447
 
 
448
 
    // This fixes a UI glitch on MacOS X
449
 
    // Because of the new layout code, the Columns pane doesn't size itself properly
450
 
    SetSize(GetSize().GetWidth()+1, GetSize().GetHeight());
451
 
    SetSize(GetSize().GetWidth()-1, GetSize().GetHeight());
452
 
 
453
 
    return returnCode;
 
335
                wxArrayString collationsArray = index->GetCollationsArray();
 
336
                wxString colDef, colRest, colName, descDef, nullsDef, opclassDef, collation;
 
337
                const wxString firstOrder = wxT(" NULLS FIRST"), lastOrder = wxT(" NULLS LAST"), descOrder = wxT(" DESC");
 
338
                if (this->database->BackendMinimumVersion(8, 3) && index->GetIndexType() == wxT("btree"))
 
339
                {
 
340
                        for (int colIdx = 0, colsCount = colsArr.Count(); colIdx < colsCount; colIdx++)
 
341
                        {
 
342
                                colDef = colsArr.Item(colIdx);
 
343
 
 
344
                                if (colDef.EndsWith(firstOrder.GetData(), &colRest))
 
345
                                {
 
346
                                        colDef = colRest;
 
347
                                        nullsDef = wxT("FIRST");
 
348
                                }
 
349
                                else if (colDef.EndsWith(lastOrder.GetData(), &colRest))
 
350
                                {
 
351
                                        colDef = colRest;
 
352
                                        nullsDef = wxT("LAST");
 
353
                                }
 
354
                                else
 
355
                                        nullsDef = wxT("");
 
356
 
 
357
                                if (colDef.EndsWith(descOrder.GetData(), &colRest))
 
358
                                {
 
359
                                        colDef = colRest;
 
360
                                        descDef = wxT("DESC");
 
361
                                        if (nullsDef.IsEmpty())
 
362
                                                nullsDef = wxT("FIRST");
 
363
                                }
 
364
                                else
 
365
                                {
 
366
                                        descDef = wxT("ASC");
 
367
                                        if (nullsDef.IsEmpty())
 
368
                                                nullsDef = wxT("LAST");
 
369
                                }
 
370
 
 
371
                                int pos = colDef.First(wxT(" "));
 
372
                                if (pos > 0)
 
373
                                {
 
374
                                        opclassDef = colDef.Mid(pos + 1);
 
375
                                        colDef = colDef.Mid(0, pos - 1);
 
376
                                }
 
377
                                else
 
378
                                        opclassDef = wxEmptyString;
 
379
 
 
380
                                lstColumns->InsertItem(colIdx, colDef, columnFactory.GetIconId());
 
381
                                lstColumns->SetItem(colIdx, 1, descDef);
 
382
                                lstColumns->SetItem(colIdx, 2, nullsDef);
 
383
                                lstColumns->SetItem(colIdx, 3, opclassDef);
 
384
                                lstColumns->SetItem(colIdx, 4, collationsArray.Item(colIdx));
 
385
                        }
 
386
                }
 
387
                else
 
388
                {
 
389
                        for (int colIdx = 0, colsCount = colsArr.Count(); colIdx < colsCount; colIdx++)
 
390
                        {
 
391
                                int pos = colDef.First(wxT(" "));
 
392
                                if (pos > 0)
 
393
                                {
 
394
                                        colDef = colRest;
 
395
                                        opclassDef = colDef.Mid(pos + 1);
 
396
                                        colDef = colDef.Mid(0, pos - 1);
 
397
                                }
 
398
                                else
 
399
                                        opclassDef = wxEmptyString;
 
400
 
 
401
                                lstColumns->InsertItem(colIdx, colsArr.Item(colIdx), columnFactory.GetIconId());
 
402
                                lstColumns->SetItem(colIdx, 3, cbOpClass->GetValue());
 
403
                                lstColumns->SetItem(colIdx, 4, collationsArray.Item(colIdx));
 
404
                        }
 
405
                }
 
406
 
 
407
                cbType->Append(index->GetIndexType());
 
408
                chkUnique->SetValue(index->GetIsUnique());
 
409
                chkClustered->SetValue(index->GetIsClustered());
 
410
                txtWhere->SetValue(index->GetConstraint());
 
411
                cbType->SetSelection(0);
 
412
                cbType->Disable();
 
413
                txtWhere->Disable();
 
414
                chkUnique->Disable();
 
415
                chkConcurrent->Disable();
 
416
                PrepareTablespace(cbTablespace, index->GetTablespaceOid());
 
417
                cbOpClass->Disable();
 
418
                chkDesc->Disable();
 
419
                rdbNullsFirst->Disable();
 
420
                rdbNullsLast->Disable();
 
421
                cbCollation->Disable();
 
422
        }
 
423
        else
 
424
        {
 
425
                // create mode
 
426
                PrepareTablespace(cbTablespace);
 
427
                cbType->Append(wxT(""));
 
428
                pgSet *set = connection->ExecuteSet(wxT(
 
429
                                                        "SELECT oid, amname FROM pg_am"));
 
430
                if (set)
 
431
                {
 
432
                        while (!set->Eof())
 
433
                        {
 
434
                                cbType->Append(set->GetVal(1), set->GetVal(0));
 
435
                                set->MoveNext();
 
436
                        }
 
437
                        delete set;
 
438
                }
 
439
 
 
440
                if (connection->BackendMinimumVersion(9, 1))
 
441
                {
 
442
                        // fill collation combobox
 
443
                        cbCollation->Append(wxEmptyString);
 
444
                        set = connection->ExecuteSet(
 
445
                                  wxT("SELECT nspname, collname\n")
 
446
                                  wxT("  FROM pg_collation c, pg_namespace n\n")
 
447
                                  wxT("  WHERE c.collnamespace=n.oid\n")
 
448
                                  wxT("  ORDER BY nspname, collname"));
 
449
                        if (set)
 
450
                        {
 
451
                                while (!set->Eof())
 
452
                                {
 
453
                                        wxString name = qtIdent(set->GetVal(wxT("nspname"))) + wxT(".") + qtIdent(set->GetVal(wxT("collname")));
 
454
                                        cbCollation->Append(name);
 
455
                                        set->MoveNext();
 
456
                                }
 
457
                                delete set;
 
458
                        }
 
459
                        cbCollation->SetSelection(0);
 
460
                }
 
461
                else
 
462
                        cbCollation->Disable();
 
463
 
 
464
                if (!this->database->BackendMinimumVersion(8, 2))
 
465
                        chkConcurrent->Disable();
 
466
 
 
467
                if (!this->database->BackendMinimumVersion(8, 3))
 
468
                {
 
469
                        chkDesc->Disable();
 
470
                        rdbNullsFirst->Disable();
 
471
                        rdbNullsLast->Disable();
 
472
                }
 
473
 
 
474
                // Add the default tablespace
 
475
                cbTablespace->Insert(_("<default tablespace>"), 0, (void *)0);
 
476
                cbTablespace->SetSelection(0);
 
477
        }
 
478
 
 
479
        int returnCode = dlgIndexBase::Go(modal);
 
480
 
 
481
        if (index && connection->BackendMinimumVersion(8, 0))
 
482
                txtName->Enable(true);
 
483
 
 
484
        // This fixes a UI glitch on MacOS X
 
485
        // Because of the new layout code, the Columns pane doesn't size itself properly
 
486
        SetSize(GetSize().GetWidth() + 1, GetSize().GetHeight());
 
487
        SetSize(GetSize().GetWidth() - 1, GetSize().GetHeight());
 
488
 
 
489
        return returnCode;
454
490
}
455
491
 
456
492
 
457
493
void dlgIndex::OnAddCol(wxCommandEvent &ev)
458
494
{
459
 
    wxString colName=cbColumns->GetValue();
460
 
 
461
 
    if (!colName.IsEmpty())
462
 
    {
463
 
        long colIndex = lstColumns->InsertItem(lstColumns->GetItemCount(), colName, columnFactory.GetIconId());
464
 
 
465
 
 
466
 
        if (this->database->BackendMinimumVersion(8, 3))
467
 
        {
468
 
            if (chkDesc->GetValue())
469
 
            {
470
 
                if (chkDesc->IsEnabled())
471
 
                    lstColumns->SetItem(colIndex, 1, wxT("DESC"));
472
 
 
473
 
 
474
 
                if (rdbNullsLast->GetValue())
475
 
                {
476
 
                    if (rdbNullsLast->IsEnabled())
477
 
                        lstColumns->SetItem(colIndex, 2, wxT("LAST"));
478
 
                }
479
 
                else
480
 
                {
481
 
                    if (rdbNullsLast->IsEnabled())
482
 
                        lstColumns->SetItem(colIndex, 2, wxT("FIRST"));
483
 
                }
484
 
            }
485
 
            else
486
 
            {
487
 
                if (chkDesc->IsEnabled())
488
 
                    lstColumns->SetItem(colIndex, 1, wxT("ASC"));
489
 
 
490
 
                if (rdbNullsFirst->GetValue())
491
 
                {
492
 
                    if (rdbNullsFirst->IsEnabled())
493
 
                        lstColumns->SetItem(colIndex, 2, wxT("FIRST"));
494
 
                }
495
 
                else
496
 
                {
497
 
                    if (rdbNullsLast->IsEnabled())
498
 
                        lstColumns->SetItem(colIndex, 2, wxT("LAST"));
499
 
                }
500
 
            }
501
 
 
502
 
            lstColumns->SetItem(colIndex, 3, cbOpClass->GetValue());
503
 
        }
504
 
 
505
 
        cbColumns->Delete(cbColumns->GetCurrentSelection());
506
 
        if (cbColumns->GetCount())
507
 
            cbColumns->SetSelection(0);
508
 
 
509
 
        CheckChange();
510
 
        if (!cbColumns->GetCount())
511
 
            btnAddCol->Disable();
512
 
    }
 
495
        wxString colName = cbColumns->GetValue();
 
496
 
 
497
        if (!colName.IsEmpty())
 
498
        {
 
499
                long colIndex = lstColumns->InsertItem(lstColumns->GetItemCount(), colName, columnFactory.GetIconId());
 
500
 
 
501
 
 
502
                if (this->database->BackendMinimumVersion(8, 3))
 
503
                {
 
504
                        if (chkDesc->GetValue())
 
505
                        {
 
506
                                if (chkDesc->IsEnabled())
 
507
                                        lstColumns->SetItem(colIndex, 1, wxT("DESC"));
 
508
 
 
509
 
 
510
                                if (rdbNullsLast->GetValue())
 
511
                                {
 
512
                                        if (rdbNullsLast->IsEnabled())
 
513
                                                lstColumns->SetItem(colIndex, 2, wxT("LAST"));
 
514
                                }
 
515
                                else
 
516
                                {
 
517
                                        if (rdbNullsLast->IsEnabled())
 
518
                                                lstColumns->SetItem(colIndex, 2, wxT("FIRST"));
 
519
                                }
 
520
                        }
 
521
                        else
 
522
                        {
 
523
                                if (chkDesc->IsEnabled())
 
524
                                        lstColumns->SetItem(colIndex, 1, wxT("ASC"));
 
525
 
 
526
                                if (rdbNullsFirst->GetValue())
 
527
                                {
 
528
                                        if (rdbNullsFirst->IsEnabled())
 
529
                                                lstColumns->SetItem(colIndex, 2, wxT("FIRST"));
 
530
                                }
 
531
                                else
 
532
                                {
 
533
                                        if (rdbNullsLast->IsEnabled())
 
534
                                                lstColumns->SetItem(colIndex, 2, wxT("LAST"));
 
535
                                }
 
536
                        }
 
537
 
 
538
                        lstColumns->SetItem(colIndex, 3, cbOpClass->GetValue());
 
539
                        lstColumns->SetItem(colIndex, 4, cbCollation->GetValue());
 
540
                }
 
541
 
 
542
                cbColumns->Delete(cbColumns->GetCurrentSelection());
 
543
                if (cbColumns->GetCount())
 
544
                        cbColumns->SetSelection(0);
 
545
 
 
546
                CheckChange();
 
547
                if (!cbColumns->GetCount())
 
548
                        btnAddCol->Disable();
 
549
        }
513
550
}
514
551
 
515
552
 
516
553
void dlgIndex::OnRemoveCol(wxCommandEvent &ev)
517
554
{
518
 
    long pos=lstColumns->GetSelection();
519
 
    if (pos >= 0)
520
 
    {
521
 
        wxString colName=lstColumns->GetItemText(pos);
522
 
 
523
 
        lstColumns->DeleteItem(pos);
524
 
        cbColumns->Append(colName);
525
 
 
526
 
        CheckChange();
527
 
        btnRemoveCol->Disable();
528
 
    }
 
555
        long pos = lstColumns->GetSelection();
 
556
        if (pos >= 0)
 
557
        {
 
558
                wxString colName = lstColumns->GetItemText(pos);
 
559
 
 
560
                lstColumns->DeleteItem(pos);
 
561
                cbColumns->Append(colName);
 
562
 
 
563
                CheckChange();
 
564
                btnRemoveCol->Disable();
 
565
        }
529
566
}
530
567
 
531
568
#ifdef __WXMAC__
532
569
void dlgIndex::OnChangeSize(wxSizeEvent &ev)
533
570
{
534
571
        lstColumns->SetSize(wxDefaultCoord, wxDefaultCoord,
535
 
            ev.GetSize().GetWidth(), ev.GetSize().GetHeight() - 700);
536
 
    if (GetAutoLayout())
537
 
    {
538
 
        Layout();
539
 
    }
 
572
                            ev.GetSize().GetWidth(), ev.GetSize().GetHeight() - 700);
 
573
        if (GetAutoLayout())
 
574
        {
 
575
                Layout();
 
576
        }
540
577
}
541
578
#endif
542
579
 
543
580
wxString dlgIndex::GetSql()
544
581
{
545
 
    wxString sql;
546
 
 
547
 
    if (table)
548
 
    {
549
 
        wxString name=GetName();
550
 
        if (!index)
551
 
        {
552
 
            sql = wxT("CREATE ");
553
 
            if (chkUnique->GetValue())
554
 
                sql += wxT("UNIQUE ");
555
 
 
556
 
            sql += wxT("INDEX ");
557
 
 
558
 
            if (chkConcurrent->GetValue())
559
 
                sql += wxT("CONCURRENTLY ");
560
 
 
561
 
            sql += qtIdent(name);
562
 
 
563
 
            sql += wxT("\n   ON ") + table->GetQuotedFullIdentifier();
564
 
 
565
 
            if (cbType->GetCurrentSelection() > 0)
566
 
                AppendIfFilled(sql, wxT(" USING "), cbType->GetValue());
567
 
 
568
 
            sql += wxT(" (") + GetColumns()
569
 
                + wxT(")");
570
 
 
571
 
            if (txtFillFactor)
572
 
            {
573
 
                if (connection->BackendMinimumVersion(8, 2) && txtFillFactor->GetValue().Length() > 0)
574
 
                    sql += wxT("\n  WITH (FILLFACTOR=") + txtFillFactor->GetValue() + wxT(")");
575
 
            }
576
 
 
577
 
            if (cbTablespace->GetOIDKey() > 0)
578
 
                AppendIfFilled(sql, wxT("\n  TABLESPACE "), qtIdent(cbTablespace->GetValue()));
579
 
 
580
 
            AppendIfFilled(sql, wxT(" WHERE "), txtWhere->GetValue());
581
 
            sql +=  wxT(";\n");
582
 
        }
583
 
        else
584
 
        {
585
 
            if (connection->BackendMinimumVersion(8, 2) && txtFillFactor->GetValue().Length() > 0)
586
 
                sql += wxT("ALTER INDEX ") + qtIdent(index->GetSchema()->GetName()) + wxT(".")
587
 
                    + qtIdent(index->GetName()) +  wxT(" SET (FILLFACTOR=")
588
 
                    + txtFillFactor->GetValue() + wxT(");\n");
589
 
 
590
 
            if(connection->BackendMinimumVersion(8, 0))
591
 
            {
592
 
                if (index->GetName() != txtName->GetValue() &&
593
 
                    !txtName->GetValue().IsEmpty())
594
 
                    sql += wxT("ALTER INDEX ") + qtIdent(index->GetSchema()->GetName()) + wxT(".")
595
 
                        + qtIdent(index->GetName()) +  wxT(" RENAME TO ")
596
 
                        + qtIdent(txtName->GetValue()) + wxT(";\n");
597
 
 
598
 
                if (cbTablespace->GetOIDKey() != index->GetTablespaceOid())
599
 
                    sql += wxT("ALTER INDEX ") + qtIdent(index->GetSchema()->GetName()) + wxT(".") + qtIdent(name) 
600
 
                        +  wxT(" SET TABLESPACE ") + qtIdent(cbTablespace->GetValue())
601
 
                        +  wxT(";\n");
602
 
            }
603
 
        }
604
 
        if (connection->BackendMinimumVersion(7, 4))
605
 
        {
606
 
            if (index && index->GetIsClustered() && !chkClustered->GetValue())
607
 
                sql += wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier()
608
 
                    +  wxT(" SET WITHOUT CLUSTER;\n");
609
 
            else if (chkClustered->GetValue() && (!index || !index->GetIsClustered()))
610
 
                sql += wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier()
611
 
                    +  wxT(" CLUSTER ON ") + qtIdent(name) + wxT(";\n");
612
 
        }
613
 
 
614
 
        AppendComment(sql, wxT("INDEX"), table->GetSchema(), index);
615
 
    }
616
 
    return sql;
 
582
        wxString sql;
 
583
 
 
584
        if (table)
 
585
        {
 
586
                wxString name = GetName();
 
587
                if (!index)
 
588
                {
 
589
                        sql = wxT("CREATE ");
 
590
                        if (chkUnique->GetValue())
 
591
                                sql += wxT("UNIQUE ");
 
592
 
 
593
                        sql += wxT("INDEX ");
 
594
 
 
595
                        if (chkConcurrent->GetValue())
 
596
                                sql += wxT("CONCURRENTLY ");
 
597
 
 
598
                        sql += qtIdent(name);
 
599
 
 
600
                        sql += wxT("\n   ON ") + table->GetQuotedFullIdentifier();
 
601
 
 
602
                        if (cbType->GetCurrentSelection() > 0)
 
603
                                AppendIfFilled(sql, wxT(" USING "), cbType->GetValue());
 
604
 
 
605
                        sql += wxT(" (") + GetColumns()
 
606
                               + wxT(")");
 
607
 
 
608
                        if (txtFillFactor)
 
609
                        {
 
610
                                if (connection->BackendMinimumVersion(8, 2) && txtFillFactor->GetValue().Length() > 0)
 
611
                                        sql += wxT("\n  WITH (FILLFACTOR=") + txtFillFactor->GetValue() + wxT(")");
 
612
                        }
 
613
 
 
614
                        if (cbTablespace->GetOIDKey() > 0)
 
615
                                AppendIfFilled(sql, wxT("\n  TABLESPACE "), qtIdent(cbTablespace->GetValue()));
 
616
 
 
617
                        AppendIfFilled(sql, wxT(" WHERE "), txtWhere->GetValue());
 
618
                        sql +=  wxT(";\n");
 
619
                }
 
620
                else
 
621
                {
 
622
                        if (connection->BackendMinimumVersion(8, 2) && txtFillFactor->GetValue().Length() > 0)
 
623
                                sql += wxT("ALTER INDEX ") + qtIdent(index->GetSchema()->GetName()) + wxT(".")
 
624
                                       + qtIdent(index->GetName()) +  wxT(" SET (FILLFACTOR=")
 
625
                                       + txtFillFactor->GetValue() + wxT(");\n");
 
626
 
 
627
                        if(connection->BackendMinimumVersion(8, 0))
 
628
                        {
 
629
                                if (index->GetName() != txtName->GetValue() &&
 
630
                                        !txtName->GetValue().IsEmpty())
 
631
                                        sql += wxT("ALTER INDEX ") + qtIdent(index->GetSchema()->GetName()) + wxT(".")
 
632
                                               + qtIdent(index->GetName()) +  wxT(" RENAME TO ")
 
633
                                               + qtIdent(txtName->GetValue()) + wxT(";\n");
 
634
 
 
635
                                if (cbTablespace->GetOIDKey() != index->GetTablespaceOid())
 
636
                                        sql += wxT("ALTER INDEX ") + qtIdent(index->GetSchema()->GetName()) + wxT(".") + qtIdent(name)
 
637
                                               +  wxT(" SET TABLESPACE ") + qtIdent(cbTablespace->GetValue())
 
638
                                               +  wxT(";\n");
 
639
                        }
 
640
                }
 
641
                if (connection->BackendMinimumVersion(7, 4))
 
642
                {
 
643
                        if (index && index->GetIsClustered() && !chkClustered->GetValue())
 
644
                                sql += wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier()
 
645
                                       +  wxT(" SET WITHOUT CLUSTER;\n");
 
646
                        else if (chkClustered->GetValue() && (!index || !index->GetIsClustered()))
 
647
                                sql += wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier()
 
648
                                       +  wxT(" CLUSTER ON ") + qtIdent(name) + wxT(";\n");
 
649
                }
 
650
 
 
651
                AppendComment(sql, wxT("INDEX"), table->GetSchema(), index);
 
652
        }
 
653
        return sql;
617
654
}
618
655
 
619
656
 
620
657
pgObject *dlgIndex::CreateObject(pgCollection *collection)
621
658
{
622
 
    wxString name=GetName();
 
659
        wxString name = GetName();
623
660
 
624
 
    pgObject *obj=indexFactory.CreateObjects(collection, 0, wxT(
625
 
        "\n   AND cls.relname=") + qtDbString(name) + wxT(
626
 
        "\n   AND cls.relnamespace=") + table->GetSchema()->GetOidStr());
627
 
    return obj;
 
661
        pgObject *obj = indexFactory.CreateObjects(collection, 0, wxT(
 
662
                            "\n   AND cls.relname=") + qtDbString(name) + wxT(
 
663
                            "\n   AND cls.relnamespace=") + table->GetSchema()->GetOidStr());
 
664
        return obj;
628
665
}
629
666
 
630
667
void dlgIndex::OnDescChange(wxCommandEvent &ev)
631
668
{
632
 
    if (chkDesc->GetValue())
633
 
    {
634
 
        rdbNullsFirst->SetValue(true);
635
 
    }
636
 
    else
637
 
    {
638
 
        rdbNullsLast->SetValue(true);
639
 
    }
 
669
        if (chkDesc->GetValue())
 
670
        {
 
671
                rdbNullsFirst->SetValue(true);
 
672
        }
 
673
        else
 
674
        {
 
675
                rdbNullsLast->SetValue(true);
 
676
        }
640
677
}