1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// dlgRepSequence.cpp - PostgreSQL Slony-I Sequence Property
//
//////////////////////////////////////////////////////////////////////////
// wxWindows headers
#include <wx/wx.h>
// App headers
#include "pgAdmin3.h"
#include "slony/dlgRepSequence.h"
#include "slony/slCluster.h"
#include "slony/slSet.h"
#include "slony/slSequence.h"
#include "schema/pgDatatype.h"
// pointer to controls
#define txtID CTRL_TEXT("txtID")
#define cbSequence CTRL_COMBOBOX2("cbSequence")
BEGIN_EVENT_TABLE(dlgRepSequence, dlgProperty)
EVT_TEXT(XRCID("txtID"), dlgRepSequence::OnChange)
EVT_TEXT(XRCID("cbSequence"), dlgRepSequence::OnChange)
EVT_COMBOBOX(XRCID("cbSequence"), dlgRepSequence::OnChangeSel)
EVT_TEXT(XRCID("cbSequence"), dlgRepSequence::OnChange)
END_EVENT_TABLE();
dlgProperty *slSlSequenceFactory::CreateDialog(frmMain *frame, pgObject *node, pgObject *parent)
{
return new dlgRepSequence(this, frame, (slSequence *)node, (slSet *)parent);
}
dlgRepSequence::dlgRepSequence(pgaFactory *f, frmMain *frame, slSequence *node, slSet *s)
: dlgRepProperty(f, frame, s->GetCluster(), wxT("dlgRepSequence"))
{
sequence = node;
set = s;
}
pgObject *dlgRepSequence::GetObject()
{
return sequence;
}
int dlgRepSequence::Go(bool modal)
{
txtID->SetValidator(numericValidator);
if (sequence)
{
// edit mode
cbSequence->Append(sequence->GetName());
cbSequence->SetSelection(0);
txtID->SetValue(NumToStr(sequence->GetSlId()));
cbSequence->Disable();
txtComment->Disable();
txtID->Disable();
}
else
{
// create mode
wxString restriction;
if (!settings->GetShowSystemObjects())
restriction = wxT("\n AND ") + connection->SystemNamespaceRestriction(wxT("nspname"));
pgSet *tabs = connection->ExecuteSet(
wxT("SELECT DISTINCT cl.oid, nspname, relname\n")
wxT(" FROM pg_class cl\n")
wxT(" JOIN pg_namespace nsp ON relnamespace=nsp.oid\n")
wxT(" LEFT JOIN ") + cluster->GetSchemaPrefix() + wxT("sl_sequence s ON s.seq_reloid=cl.oid\n")
wxT(" WHERE s.seq_id IS NULL AND cl.relkind = 'S'") + restriction + wxT("\n")
wxT(" ORDER BY nspname, relname")
);
if (tabs)
{
while (!tabs->Eof())
{
cbSequence->Append(tabs->GetVal(wxT("nspname")) + wxT(".") + tabs->GetVal(wxT("relname")),
(void *)tabs->GetOid(wxT("oid")));
tabs->MoveNext();
}
delete tabs;
}
}
return dlgProperty::Go(modal);
}
pgObject *dlgRepSequence::CreateObject(pgCollection *collection)
{
pgObject *obj = slSequenceFactory.CreateObjects(collection, 0,
wxT(" WHERE seq_reloid = ") + NumToStr((OID)cbSequence->wxItemContainer::GetClientData(cbSequence->GetGuessedSelection())));
return obj;
}
void dlgRepSequence::OnChangeSel(wxCommandEvent &ev)
{
cbSequence->GuessSelection(ev);
OnChange(ev);
}
void dlgRepSequence::CheckChange()
{
if (sequence)
{
EnableOK(txtComment->GetValue() != sequence->GetComment());
}
else
{
bool enable = true;
CheckValid(enable, cbSequence->GetGuessedSelection() >= 0, _("Please select sequence to replicate."));
EnableOK(enable);
}
}
wxString dlgRepSequence::GetSql()
{
wxString sql;
if (sequence)
{
// edit mode
}
else
{
// create mode
sql = wxT("SELECT ") + cluster->GetSchemaPrefix() + wxT("setaddsequence(")
+ NumToStr(set->GetSlId()) + wxT(", ");
if (StrToLong(txtID->GetValue()) > 0)
sql += txtID->GetValue();
else
sql += wxT("(SELECT COALESCE(MAX(seq_id), 0) + 1 FROM ") + cluster->GetSchemaPrefix() + wxT("sl_sequence)");
sql += wxT(", ") + qtDbString(cbSequence->GetGuessedStringSelection())
+ wxT(", ") + qtDbString(txtComment->GetValue())
+ wxT(")\n");
}
return sql;
}
|