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

Commit

Permalink
Remove the confusing and near-useless sequence combo box from the col…
Browse files Browse the repository at this point in the history
…umn dialog per discussion on support list.

git-svn-id: svn://svn.pgadmin.org/branches/REL-1_8_0_PATCHES@7003 a7884b65-44f6-0310-8a51-81a127f17b15
  • Loading branch information
dpage committed Jan 18, 2008
1 parent d7fc761 commit 23dce46
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 256 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG
Expand Up @@ -36,7 +36,9 @@ Changes

Date Dev Ver Change details
---------- --- ----- --------------
2008-01-18 DP 1.8.2 Fix the WITH ADMIN membership option when creating roles.
2008-01-18 DP 1.8.2 Remove the confusing and near-useless sequence combo box
from the column dialog per discussion on support list.
2008-01-18 DP 1.8.2 Fix the WITH ADMIN membership option when creating roles.
2008-01-16 DP 1.8.2 Refresh Views correctly on EnterpriseDB.
2008-01-14 DP 1.8.2 Fix the privilege editor on the Language dialogue, per
Bborie Park.
Expand Down
130 changes: 16 additions & 114 deletions pgadmin/dlg/dlgColumn.cpp
Expand Up @@ -28,9 +28,6 @@
#define txtDefault CTRL_TEXT("txtDefault")
#define chkNotNull CTRL_CHECKBOX("chkNotNull")
#define txtAttstattarget CTRL_TEXT("txtAttstattarget")
#define cbSequence CTRL_COMBOBOX("cbSequence")



BEGIN_EVENT_TABLE(dlgColumn, dlgTypeProperty)
EVT_TEXT(XRCID("txtLength"), dlgProperty::OnChange)
Expand All @@ -57,7 +54,6 @@ dlgColumn::dlgColumn(pgaFactory *f, frmMain *frame, pgColumn *node, pgTable *par
wxASSERT(!table || (table->GetMetaType() == PGM_TABLE || table->GetMetaType() == PGM_VIEW));

txtAttstattarget->SetValidator(numericValidator);
cbSequence->Disable();
}


Expand Down Expand Up @@ -117,9 +113,6 @@ int dlgColumn::Go(bool modal)
wxNotifyEvent ev;
OnSelChangeTyp(ev);

cbSequence->Append(database->GetSchemaPrefix(column->GetSerialSchema()) + column->GetSerialSequence());
cbSequence->SetSelection(0);

previousDefinition=GetDefinition();
if (column->GetColNumber() < 0) // Disable controls not valid for system columns
{
Expand Down Expand Up @@ -148,42 +141,11 @@ int dlgColumn::Go(bool modal)
AddType(wxT(" "), 0, wxT("serial"));
AddType(wxT(" "), 0, wxT("bigserial"));

if (table)
{
sequences.Add(wxEmptyString);
cbSequence->Append(_("<new sequence>"));

wxString sysRestr;
if (!settings->GetShowSystemObjects())
sysRestr = wxT(" AND ") + connection->SystemNamespaceRestriction(wxT("nspname"));

pgSet *set=connection->ExecuteSet(
wxT("SELECT nspname, relname\n")
wxT(" FROM pg_class cl\n")
wxT(" JOIN pg_namespace nsp ON nsp.oid=relnamespace\n")
wxT(" WHERE cl.relkind='S'\n")
+ sysRestr + wxT("\n")
+ wxT(" ORDER BY CASE WHEN ") + connection->SystemNamespaceRestriction(wxT("nspname"))
+ wxT(" THEN 0 ELSE 1 END, nspname, relname"));

if (set)
{
while (!set->Eof())
{
sequences.Add(qtIdent(set->GetVal(wxT("nspname"))) + wxT(".") + qtIdent(set->GetVal(wxT("relname"))));
cbSequence->Append(set->GetVal(wxT("nspname")) + wxT(".") + set->GetVal(wxT("relname")));
set->MoveNext();
}
delete set;
}
}
else
{
cbSequence->Append(wxT(" "));
if (!table)
{
cbClusterSet->Disable();
cbClusterSet = 0;
}
cbSequence->SetSelection(0);
}
return dlgTypeProperty::Go(modal);
}
Expand All @@ -194,7 +156,7 @@ wxString dlgColumn::GetSql()
wxString sql;
wxString name=GetName();

bool isSerial = (cbDatatype->GetValue() == wxT("serial") || cbDatatype->GetValue() == wxT("bigserial"));
bool isSerial = (cbDatatype->GetValue() == wxT("serial") || cbDatatype->GetValue() == wxT("bigserial"));

if (table)
{
Expand Down Expand Up @@ -287,80 +249,22 @@ wxString dlgColumn::GetSql()
}
else
{
if (isSerial)
{
wxString typname;
if (cbDatatype->GetValue() == wxT("serial"))
typname = wxT("int4");
else
typname = wxT("int8");
sql = wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier()
+ wxT("\n ADD COLUMN ") + qtIdent(name)
+ wxT(" ") + GetQuotedTypename(cbDatatype->GetGuessedSelection())
+ wxT(";\n");

wxString sequence;
bool newSequence = (cbSequence->GetCurrentSelection() <= 0);

if (connection->BackendMinimumVersion(8, 0) && newSequence)
{
sql +=wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier()
+ wxT("\n ADD COLUMN ") + qtIdent(name)
+ wxT(" ") + cbDatatype->GetValue() + wxT(";\n");
}
else
{
if (newSequence)
{
sequence = qtIdent(table->GetSchema()->GetName()) + wxT(".") +
qtIdent(table->GetName() + wxT("_") + name + wxT("_seq"));

sql = wxT("CREATE SEQUENCE ") + sequence + wxT(";\n");
}
else
sequence=sequences.Item(cbSequence->GetCurrentSelection());

sql +=wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier()
+ wxT("\n ADD COLUMN ") + qtIdent(name)
+ wxT(" ") + typname + wxT(";\n")
+ wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier()
+ wxT("\n ALTER COLUMN ") + qtIdent(name)
+ wxT(" SET DEFAULT nextval('") + sequence + wxT("'::text);\n");


if (connection->HasPrivilege(wxT("Table"), wxT("pg_depend"), wxT("insert")))
{
sql +=
wxT("INSERT INTO pg_depend(classid, objid, objsubid, refclassid, refobjid, refobjsubid, deptype)\n")
wxT("SELECT cl.oid, seq.oid, 0, cl.oid, ") + table->GetOidStr() + wxT(", attnum, 'i'\n")
wxT(" FROM pg_class cl, pg_attribute, pg_class seq\n")
wxT(" JOIN pg_namespace sn ON sn.OID=seq.relnamespace\n")
wxT(" WHERE cl.relname='pg_class'\n")
wxT(" AND seq.relname=") + qtDbString(table->GetName() + wxT("_") + name + wxT("_seq")) + wxT("\n")
wxT(" AND sn.nspname=") + qtDbString(table->GetSchema()->GetName()) + wxT("\n")
wxT(" AND attrelid=") + table->GetOidStr() + wxT(" AND attname=") + qtDbString(name) + wxT(";\n");
}
else
{
sql +=
wxT("-- Dependency information can't be added; no insert into pg_depend allowed.\n");
}
}
}
else
{
sql = wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier()
+ wxT("\n ADD COLUMN ") + qtIdent(name)
+ wxT(" ") + GetQuotedTypename(cbDatatype->GetGuessedSelection())
if (chkNotNull->GetValue())
sql += wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier()
+ wxT("\n ALTER COLUMN ") + qtIdent(name)
+ wxT(" SET NOT NULL;\n");

if (!isSerial && !txtDefault->GetValue().IsEmpty())
sql += wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier()
+ wxT("\n ALTER COLUMN ") + qtIdent(name)
+ wxT(" SET DEFAULT ") + txtDefault->GetValue()
+ wxT(";\n");

if (!isSerial && chkNotNull->GetValue())
sql += wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier()
+ wxT("\n ALTER COLUMN ") + qtIdent(name)
+ wxT(" SET NOT NULL;\n");

if (!isSerial && !txtDefault->GetValue().IsEmpty())
sql += wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier()
+ wxT("\n ALTER COLUMN ") + qtIdent(name)
+ wxT(" SET DEFAULT ") + txtDefault->GetValue()
+ wxT(";\n");
}
if (!txtAttstattarget->GetValue().IsEmpty())
sql += wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier()
+ wxT("\n ALTER COLUMN ") + qtIdent(name)
Expand Down Expand Up @@ -409,8 +313,6 @@ void dlgColumn::OnSelChangeTyp(wxCommandEvent &ev)
txtLength->Enable(isVarLen);

bool isSerial = (cbDatatype->GetValue() == wxT("serial") || cbDatatype->GetValue() == wxT("bigserial"));
cbSequence->Enable(isSerial && table!=0);
chkNotNull->Enable(!isSerial);
txtDefault->Enable(!isSerial);

CheckChange();
Expand Down
46 changes: 22 additions & 24 deletions pgadmin/dlg/dlgTable.cpp
Expand Up @@ -766,31 +766,29 @@ wxString dlgTable::GetSql()
sql += wxT(";\n");

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 ") + qtDbString(lstColumns->GetText(pos, 5))
+ wxT(";\n");
}

// Extra column info

// 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 ") + qtDbString(lstColumns->GetText(pos, 5))
+ wxT(";\n");
}
}

AppendComment(sql, wxT("TABLE"), schema, table);

Expand Down
30 changes: 7 additions & 23 deletions pgadmin/ui/dlgColumn.xrc
Expand Up @@ -70,59 +70,43 @@

<size>135,-1d</size>
</object>
<object class="wxStaticText" name="stSequence">

<label>Sequence</label>

<pos>5,67d</pos>
</object>
<object class="wxComboBox" name="cbSequence">

<content/>

<pos>70,65d</pos>

<size>135,12d</size>

<style>wxCB_READONLY|wxCB_DROPDOWN</style>
</object>
<object class="wxStaticText" name="stNotNull">

<label>Not NULL</label>

<pos>5,82d</pos>
<pos>5,67d</pos>
</object>
<object class="wxCheckBox" name="chkNotNull">

<label></label>

<pos>70,80d</pos>
<pos>70,65d</pos>

<size>13,12d</size>
</object>
<object class="wxStaticText" name="stAttstattarget">

<label>Statistics</label>

<pos>5,97d</pos>
<pos>5,82d</pos>
</object>
<object class="wxTextCtrl" name="txtAttstattarget">

<pos>70,95d</pos>
<pos>70,80d</pos>

<size>135,-1d</size>
</object>
<object class="wxStaticText" name="stComment">

<label>Comment</label>

<pos>5,117d</pos>
<pos>5,101d</pos>
</object>
<object class="wxTextCtrl" name="txtComment">

<pos>70,115d</pos>
<pos>70,100d</pos>

<size>135,65d</size>
<size>135,80d</size>

<style>wxTE_MULTILINE</style>
</object>
Expand Down

0 comments on commit 23dce46

Please sign in to comment.