150
if (lstColumns->GetSelection() != wxNOT_FOUND)
151
btnRemoveCol->Enable(true);
153
btnRemoveCol->Enable(false);
150
if (lstColumns->GetSelection() != wxNOT_FOUND)
151
btnRemoveCol->Enable(true);
153
btnRemoveCol->Enable(false);
155
if (cbColumns->GetSelection() != wxNOT_FOUND && !cbColumns->GetValue().IsEmpty())
156
btnAddCol->Enable(true);
158
btnAddCol->Enable(false);
155
if (cbColumns->GetSelection() != wxNOT_FOUND && !cbColumns->GetValue().IsEmpty())
156
btnAddCol->Enable(true);
158
btnAddCol->Enable(false);
162
162
void dlgIndexBase::CheckChange()
166
EnableOK(txtComment->GetValue() != index->GetComment() ||
167
cbTablespace->GetOIDKey() != index->GetTablespaceOid());
172
txtComment->Enable(!GetName().IsEmpty());
173
CheckValid(enable, lstColumns->GetItemCount() > 0, _("Please specify columns."));
166
EnableOK(txtComment->GetValue() != index->GetComment() ||
167
cbTablespace->GetOIDKey() != index->GetTablespaceOid());
172
txtComment->Enable(!GetName().IsEmpty());
173
CheckValid(enable, lstColumns->GetItemCount() > 0, _("Please specify columns."));
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)
185
EVT_SIZE( dlgIndex::OnChangeSize)
185
EVT_SIZE( dlgIndex::OnChangeSize)
187
EVT_COMBOBOX(XRCID("cbType"), dlgIndex::OnSelectType)
187
EVT_COMBOBOX(XRCID("cbType"), dlgIndex::OnSelectType)
188
188
END_EVENT_TABLE();
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)
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);
201
202
void dlgIndex::CheckChange()
209
fill = txtFillFactor->GetValue() != index->GetFillFactor() && !txtFillFactor->GetValue().IsEmpty();
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));
221
wxString name=GetName();
224
CheckValid(enable, !name.IsEmpty() || (name.IsEmpty() && this->database->BackendMinimumVersion(9, 0)), _("Please specify name."));
225
CheckValid(enable, lstColumns->GetItemCount() > 0, _("Please specify columns."));
210
fill = txtFillFactor->GetValue() != index->GetFillFactor() && !txtFillFactor->GetValue().IsEmpty();
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));
222
wxString name = GetName();
225
CheckValid(enable, !name.IsEmpty() || (name.IsEmpty() && this->database->BackendMinimumVersion(9, 0)), _("Please specify name."));
226
CheckValid(enable, lstColumns->GetItemCount() > 0, _("Please specify columns."));
230
231
void dlgIndex::OnSelectType(wxCommandEvent &ev)
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.
236
wxString newType = cbType->GetValue();
237
bool changingDefault = false;
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;
245
if (lstColumns->GetItemCount() > 0 && !changingDefault)
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)
249
cbType->SetValue(m_previousType);
253
// Move all the columns back to the combo
254
for (int pos = lstColumns->GetItemCount(); pos > 0; pos--)
256
wxString colName = lstColumns->GetItemText(pos - 1);
258
lstColumns->DeleteItem(pos - 1);
259
cbColumns->Append(colName);
263
if (newType == wxT("btree") || newType == wxEmptyString)
265
cbOpClass->Enable(true);
266
chkDesc->Enable(true);
267
rdbNullsFirst->Enable(true);
268
rdbNullsLast->Enable(true);
272
cbOpClass->Enable(false);
273
chkDesc->Enable(false);
274
rdbNullsFirst->Enable(false);
275
rdbNullsLast->Enable(false);
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.
237
wxString newType = cbType->GetValue();
238
bool changingDefault = false;
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;
246
if (lstColumns->GetItemCount() > 0 && !changingDefault)
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)
250
cbType->SetValue(m_previousType);
254
// Move all the columns back to the combo
255
for (int pos = lstColumns->GetItemCount(); pos > 0; pos--)
257
wxString colName = lstColumns->GetItemText(pos - 1);
259
lstColumns->DeleteItem(pos - 1);
260
cbColumns->Append(colName);
264
if (newType == wxT("btree") || newType == wxEmptyString)
266
cbOpClass->Enable(true);
267
chkDesc->Enable(true);
268
rdbNullsFirst->Enable(true);
269
rdbNullsLast->Enable(true);
273
cbOpClass->Enable(false);
274
chkDesc->Enable(false);
275
rdbNullsFirst->Enable(false);
276
rdbNullsLast->Enable(false);
279
// Make a note of the type so we can compare if it changes again.
280
m_previousType = cbType->GetValue();
283
284
wxString dlgIndex::GetColumns()
289
for (pos=0 ; pos < lstColumns->GetItemCount() ; pos++)
294
sql += qtIdent(lstColumns->GetItemText(pos));
296
wxString opclass = lstColumns->GetText(pos, 3);
297
if (!opclass.IsEmpty())
298
sql += wxT(" ") + opclass;
300
if (this->database->BackendMinimumVersion(8, 3))
302
wxString order = lstColumns->GetText(pos, 1);
303
if (!order.IsEmpty())
304
sql += wxT(" ") + order;
306
wxString nullsOrder = lstColumns->GetText(pos, 2);
307
if (!nullsOrder.IsEmpty())
308
sql += wxT(" NULLS ") + nullsOrder;
290
for (pos = 0 ; pos < lstColumns->GetItemCount() ; pos++)
295
sql += qtIdent(lstColumns->GetItemText(pos));
297
if (this->database->BackendMinimumVersion(9, 1))
299
wxString collation = lstColumns->GetText(pos, 4);
300
if (!collation.IsEmpty() && collation != wxT("pg_catalog.\"default\""))
301
sql += wxT(" COLLATE ") + collation;
304
wxString opclass = lstColumns->GetText(pos, 3);
305
if (!opclass.IsEmpty())
306
sql += wxT(" ") + opclass;
308
if (this->database->BackendMinimumVersion(8, 3))
310
wxString order = lstColumns->GetText(pos, 1);
311
if (!order.IsEmpty())
312
sql += wxT(" ") + order;
314
wxString nullsOrder = lstColumns->GetText(pos, 2);
315
if (!nullsOrder.IsEmpty())
316
sql += wxT(" NULLS ") + nullsOrder;
315
323
int dlgIndex::Go(bool modal)
317
if (!connection->BackendMinimumVersion(7, 4))
318
chkClustered->Disable();
322
// edit mode: view only
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();
330
// edit mode: view only
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"))
331
for (int colIdx=0,colsCount=colsArr.Count(); colIdx<colsCount; colIdx++)
333
colDef = colsArr.Item(colIdx);
335
if (colDef.EndsWith(firstOrder.GetData(), &colRest))
338
nullsDef = wxT("FIRST");
340
else if (colDef.EndsWith(lastOrder.GetData(), &colRest))
343
nullsDef = wxT("LAST");
348
if (colDef.EndsWith(descOrder.GetData(), &colRest))
351
descDef = wxT("DESC");
352
if (nullsDef.IsEmpty())
353
nullsDef = wxT("FIRST");
357
descDef = wxT("ASC");
358
if (nullsDef.IsEmpty())
359
nullsDef = wxT("LAST");
362
int pos = colDef.First(wxT(" "));
365
opclassDef = colDef.Mid(pos + 1);
366
colDef = colDef.Mid(0, pos - 1);
369
opclassDef = wxEmptyString;
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);
379
for (int colIdx=0,colsCount=colsArr.Count(); colIdx<colsCount; colIdx++)
381
int pos = colDef.First(wxT(" "));
385
opclassDef = colDef.Mid(pos + 1);
386
colDef = colDef.Mid(0, pos - 1);
389
opclassDef = wxEmptyString;
391
lstColumns->InsertItem(colIdx, colsArr.Item(colIdx), columnFactory.GetIconId());
392
lstColumns->SetItem(colIdx, 3, cbOpClass->GetValue());
396
cbType->Append(index->GetIndexType());
397
chkUnique->SetValue(index->GetIsUnique());
398
chkClustered->SetValue(index->GetIsClustered());
399
txtWhere->SetValue(index->GetConstraint());
400
cbType->SetSelection(0);
403
chkUnique->Disable();
404
chkConcurrent->Disable();
405
PrepareTablespace(cbTablespace, index->GetTablespaceOid());
406
cbOpClass->Disable();
408
rdbNullsFirst->Disable();
409
rdbNullsLast->Disable();
414
PrepareTablespace(cbTablespace);
415
cbType->Append(wxT(""));
416
pgSet *set=connection->ExecuteSet(wxT(
417
"SELECT oid, amname FROM pg_am"));
422
cbType->Append(set->GetVal(1), set->GetVal(0));
428
if (!this->database->BackendMinimumVersion(8, 2))
429
chkConcurrent->Disable();
431
if (!this->database->BackendMinimumVersion(8, 3))
434
rdbNullsFirst->Disable();
435
rdbNullsLast->Disable();
438
// Add the default tablespace
439
cbTablespace->Insert(_("<default tablespace>"), 0, (void *)0);
440
cbTablespace->SetSelection(0);
443
int returnCode = dlgIndexBase::Go(modal);
445
if (index && connection->BackendMinimumVersion(8, 0))
446
txtName->Enable(true);
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());
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"))
340
for (int colIdx = 0, colsCount = colsArr.Count(); colIdx < colsCount; colIdx++)
342
colDef = colsArr.Item(colIdx);
344
if (colDef.EndsWith(firstOrder.GetData(), &colRest))
347
nullsDef = wxT("FIRST");
349
else if (colDef.EndsWith(lastOrder.GetData(), &colRest))
352
nullsDef = wxT("LAST");
357
if (colDef.EndsWith(descOrder.GetData(), &colRest))
360
descDef = wxT("DESC");
361
if (nullsDef.IsEmpty())
362
nullsDef = wxT("FIRST");
366
descDef = wxT("ASC");
367
if (nullsDef.IsEmpty())
368
nullsDef = wxT("LAST");
371
int pos = colDef.First(wxT(" "));
374
opclassDef = colDef.Mid(pos + 1);
375
colDef = colDef.Mid(0, pos - 1);
378
opclassDef = wxEmptyString;
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));
389
for (int colIdx = 0, colsCount = colsArr.Count(); colIdx < colsCount; colIdx++)
391
int pos = colDef.First(wxT(" "));
395
opclassDef = colDef.Mid(pos + 1);
396
colDef = colDef.Mid(0, pos - 1);
399
opclassDef = wxEmptyString;
401
lstColumns->InsertItem(colIdx, colsArr.Item(colIdx), columnFactory.GetIconId());
402
lstColumns->SetItem(colIdx, 3, cbOpClass->GetValue());
403
lstColumns->SetItem(colIdx, 4, collationsArray.Item(colIdx));
407
cbType->Append(index->GetIndexType());
408
chkUnique->SetValue(index->GetIsUnique());
409
chkClustered->SetValue(index->GetIsClustered());
410
txtWhere->SetValue(index->GetConstraint());
411
cbType->SetSelection(0);
414
chkUnique->Disable();
415
chkConcurrent->Disable();
416
PrepareTablespace(cbTablespace, index->GetTablespaceOid());
417
cbOpClass->Disable();
419
rdbNullsFirst->Disable();
420
rdbNullsLast->Disable();
421
cbCollation->Disable();
426
PrepareTablespace(cbTablespace);
427
cbType->Append(wxT(""));
428
pgSet *set = connection->ExecuteSet(wxT(
429
"SELECT oid, amname FROM pg_am"));
434
cbType->Append(set->GetVal(1), set->GetVal(0));
440
if (connection->BackendMinimumVersion(9, 1))
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"));
453
wxString name = qtIdent(set->GetVal(wxT("nspname"))) + wxT(".") + qtIdent(set->GetVal(wxT("collname")));
454
cbCollation->Append(name);
459
cbCollation->SetSelection(0);
462
cbCollation->Disable();
464
if (!this->database->BackendMinimumVersion(8, 2))
465
chkConcurrent->Disable();
467
if (!this->database->BackendMinimumVersion(8, 3))
470
rdbNullsFirst->Disable();
471
rdbNullsLast->Disable();
474
// Add the default tablespace
475
cbTablespace->Insert(_("<default tablespace>"), 0, (void *)0);
476
cbTablespace->SetSelection(0);
479
int returnCode = dlgIndexBase::Go(modal);
481
if (index && connection->BackendMinimumVersion(8, 0))
482
txtName->Enable(true);
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());
457
493
void dlgIndex::OnAddCol(wxCommandEvent &ev)
459
wxString colName=cbColumns->GetValue();
461
if (!colName.IsEmpty())
463
long colIndex = lstColumns->InsertItem(lstColumns->GetItemCount(), colName, columnFactory.GetIconId());
466
if (this->database->BackendMinimumVersion(8, 3))
468
if (chkDesc->GetValue())
470
if (chkDesc->IsEnabled())
471
lstColumns->SetItem(colIndex, 1, wxT("DESC"));
474
if (rdbNullsLast->GetValue())
476
if (rdbNullsLast->IsEnabled())
477
lstColumns->SetItem(colIndex, 2, wxT("LAST"));
481
if (rdbNullsLast->IsEnabled())
482
lstColumns->SetItem(colIndex, 2, wxT("FIRST"));
487
if (chkDesc->IsEnabled())
488
lstColumns->SetItem(colIndex, 1, wxT("ASC"));
490
if (rdbNullsFirst->GetValue())
492
if (rdbNullsFirst->IsEnabled())
493
lstColumns->SetItem(colIndex, 2, wxT("FIRST"));
497
if (rdbNullsLast->IsEnabled())
498
lstColumns->SetItem(colIndex, 2, wxT("LAST"));
502
lstColumns->SetItem(colIndex, 3, cbOpClass->GetValue());
505
cbColumns->Delete(cbColumns->GetCurrentSelection());
506
if (cbColumns->GetCount())
507
cbColumns->SetSelection(0);
510
if (!cbColumns->GetCount())
511
btnAddCol->Disable();
495
wxString colName = cbColumns->GetValue();
497
if (!colName.IsEmpty())
499
long colIndex = lstColumns->InsertItem(lstColumns->GetItemCount(), colName, columnFactory.GetIconId());
502
if (this->database->BackendMinimumVersion(8, 3))
504
if (chkDesc->GetValue())
506
if (chkDesc->IsEnabled())
507
lstColumns->SetItem(colIndex, 1, wxT("DESC"));
510
if (rdbNullsLast->GetValue())
512
if (rdbNullsLast->IsEnabled())
513
lstColumns->SetItem(colIndex, 2, wxT("LAST"));
517
if (rdbNullsLast->IsEnabled())
518
lstColumns->SetItem(colIndex, 2, wxT("FIRST"));
523
if (chkDesc->IsEnabled())
524
lstColumns->SetItem(colIndex, 1, wxT("ASC"));
526
if (rdbNullsFirst->GetValue())
528
if (rdbNullsFirst->IsEnabled())
529
lstColumns->SetItem(colIndex, 2, wxT("FIRST"));
533
if (rdbNullsLast->IsEnabled())
534
lstColumns->SetItem(colIndex, 2, wxT("LAST"));
538
lstColumns->SetItem(colIndex, 3, cbOpClass->GetValue());
539
lstColumns->SetItem(colIndex, 4, cbCollation->GetValue());
542
cbColumns->Delete(cbColumns->GetCurrentSelection());
543
if (cbColumns->GetCount())
544
cbColumns->SetSelection(0);
547
if (!cbColumns->GetCount())
548
btnAddCol->Disable();
516
553
void dlgIndex::OnRemoveCol(wxCommandEvent &ev)
518
long pos=lstColumns->GetSelection();
521
wxString colName=lstColumns->GetItemText(pos);
523
lstColumns->DeleteItem(pos);
524
cbColumns->Append(colName);
527
btnRemoveCol->Disable();
555
long pos = lstColumns->GetSelection();
558
wxString colName = lstColumns->GetItemText(pos);
560
lstColumns->DeleteItem(pos);
561
cbColumns->Append(colName);
564
btnRemoveCol->Disable();
532
569
void dlgIndex::OnChangeSize(wxSizeEvent &ev)
534
571
lstColumns->SetSize(wxDefaultCoord, wxDefaultCoord,
535
ev.GetSize().GetWidth(), ev.GetSize().GetHeight() - 700);
572
ev.GetSize().GetWidth(), ev.GetSize().GetHeight() - 700);
543
580
wxString dlgIndex::GetSql()
549
wxString name=GetName();
552
sql = wxT("CREATE ");
553
if (chkUnique->GetValue())
554
sql += wxT("UNIQUE ");
556
sql += wxT("INDEX ");
558
if (chkConcurrent->GetValue())
559
sql += wxT("CONCURRENTLY ");
561
sql += qtIdent(name);
563
sql += wxT("\n ON ") + table->GetQuotedFullIdentifier();
565
if (cbType->GetCurrentSelection() > 0)
566
AppendIfFilled(sql, wxT(" USING "), cbType->GetValue());
568
sql += wxT(" (") + GetColumns()
573
if (connection->BackendMinimumVersion(8, 2) && txtFillFactor->GetValue().Length() > 0)
574
sql += wxT("\n WITH (FILLFACTOR=") + txtFillFactor->GetValue() + wxT(")");
577
if (cbTablespace->GetOIDKey() > 0)
578
AppendIfFilled(sql, wxT("\n TABLESPACE "), qtIdent(cbTablespace->GetValue()));
580
AppendIfFilled(sql, wxT(" WHERE "), txtWhere->GetValue());
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");
590
if(connection->BackendMinimumVersion(8, 0))
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");
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())
604
if (connection->BackendMinimumVersion(7, 4))
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");
614
AppendComment(sql, wxT("INDEX"), table->GetSchema(), index);
586
wxString name = GetName();
589
sql = wxT("CREATE ");
590
if (chkUnique->GetValue())
591
sql += wxT("UNIQUE ");
593
sql += wxT("INDEX ");
595
if (chkConcurrent->GetValue())
596
sql += wxT("CONCURRENTLY ");
598
sql += qtIdent(name);
600
sql += wxT("\n ON ") + table->GetQuotedFullIdentifier();
602
if (cbType->GetCurrentSelection() > 0)
603
AppendIfFilled(sql, wxT(" USING "), cbType->GetValue());
605
sql += wxT(" (") + GetColumns()
610
if (connection->BackendMinimumVersion(8, 2) && txtFillFactor->GetValue().Length() > 0)
611
sql += wxT("\n WITH (FILLFACTOR=") + txtFillFactor->GetValue() + wxT(")");
614
if (cbTablespace->GetOIDKey() > 0)
615
AppendIfFilled(sql, wxT("\n TABLESPACE "), qtIdent(cbTablespace->GetValue()));
617
AppendIfFilled(sql, wxT(" WHERE "), txtWhere->GetValue());
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");
627
if(connection->BackendMinimumVersion(8, 0))
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");
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())
641
if (connection->BackendMinimumVersion(7, 4))
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");
651
AppendComment(sql, wxT("INDEX"), table->GetSchema(), index);
620
657
pgObject *dlgIndex::CreateObject(pgCollection *collection)
622
wxString name=GetName();
659
wxString name = GetName();
624
pgObject *obj=indexFactory.CreateObjects(collection, 0, wxT(
625
"\n AND cls.relname=") + qtDbString(name) + wxT(
626
"\n AND cls.relnamespace=") + table->GetSchema()->GetOidStr());
661
pgObject *obj = indexFactory.CreateObjects(collection, 0, wxT(
662
"\n AND cls.relname=") + qtDbString(name) + wxT(
663
"\n AND cls.relnamespace=") + table->GetSchema()->GetOidStr());
630
667
void dlgIndex::OnDescChange(wxCommandEvent &ev)
632
if (chkDesc->GetValue())
634
rdbNullsFirst->SetValue(true);
638
rdbNullsLast->SetValue(true);
669
if (chkDesc->GetValue())
671
rdbNullsFirst->SetValue(true);
675
rdbNullsLast->SetValue(true);