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

« back to all changes in this revision

Viewing changes to src/dlg/dlgCheck.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Raphael Enrici, src/frm/frmBackup.cpp, debian/control
  • Date: 2006-10-06 21:06:48 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 edgy)
  • Revision ID: james.westby@ubuntu.com-20061006210648-nscnazrse5jbwswf
* Patched frmBackup.cpp to ensure the schema is specified when backing up
  individual tables. (Closes: #387256)
  [src/frm/frmBackup.cpp]
* Cleaned up and updated description of the package. (Closes: #379188)
  [debian/control]

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//////////////////////////////////////////////////////////////////////////
 
2
//
 
3
// pgAdmin III - PostgreSQL Tools
 
4
// RCS-ID:      $Id: dlgCheck.cpp 4874 2006-01-06 17:33:27Z dpage $
 
5
// Copyright (C) 2002 - 2006, The pgAdmin Development Team
 
6
// This software is released under the Artistic Licence
 
7
//
 
8
// dlgCheck.cpp - PostgreSQL Check Property
 
9
//
 
10
//////////////////////////////////////////////////////////////////////////
 
11
 
 
12
// wxWindows headers
 
13
#include <wx/wx.h>
 
14
 
 
15
// App headers
 
16
#include "pgAdmin3.h"
 
17
#include "misc.h"
 
18
#include "frmMain.h"
 
19
#include "pgTable.h"
 
20
#include "pgCheck.h"
 
21
#include "dlgCheck.h"
 
22
 
 
23
 
 
24
#define chkDeferrable   CTRL_CHECKBOX("chkDeferrable")
 
25
#define chkDeferred     CTRL_CHECKBOX("chkDeferred")
 
26
#define stDeferred      CTRL_STATIC("stDeferred")
 
27
#define txtWhere        CTRL_TEXT("txtWhere")
 
28
 
 
29
 
 
30
BEGIN_EVENT_TABLE(dlgCheck, dlgProperty)
 
31
    EVT_TEXT(XRCID("txtWhere"),                 dlgProperty::OnChange)
 
32
    EVT_CHECKBOX(XRCID("chkDeferrable"),        dlgCheck::OnCheckDeferrable)
 
33
END_EVENT_TABLE();
 
34
 
 
35
 
 
36
dlgProperty *pgCheckFactory::CreateDialog(frmMain *frame, pgObject *node, pgObject *parent)
 
37
{
 
38
    return new dlgCheck(this, frame, (pgCheck*)node, (pgTable*)parent);
 
39
}
 
40
 
 
41
 
 
42
dlgCheck::dlgCheck(pgaFactory *f, frmMain *frame, pgCheck *node, pgTable *parentNode)
 
43
: dlgProperty(f, frame, wxT("dlgCheck"))
 
44
{
 
45
    check=node;
 
46
    table=parentNode;
 
47
}
 
48
 
 
49
 
 
50
void dlgCheck::OnCheckDeferrable(wxCommandEvent &ev)
 
51
{
 
52
    bool canDef=chkDeferrable->GetValue();
 
53
    stDeferred->Enable(canDef);
 
54
    if (!canDef)
 
55
        chkDeferred->SetValue(false);
 
56
    chkDeferred->Enable(canDef);
 
57
}
 
58
 
 
59
 
 
60
void dlgCheck::CheckChange()
 
61
{
 
62
    if (check)
 
63
    {
 
64
        EnableOK(txtComment->GetValue() != check->GetComment());
 
65
    }
 
66
    else
 
67
    {
 
68
        bool enable=true;
 
69
        txtComment->Enable(!GetName().IsEmpty());
 
70
        CheckValid(enable, !txtWhere->GetValue().IsEmpty(), _("Please specify condition."));
 
71
        EnableOK(enable);
 
72
    }
 
73
}
 
74
 
 
75
 
 
76
pgObject *dlgCheck::GetObject()
 
77
{
 
78
    return check;
 
79
}
 
80
 
 
81
 
 
82
pgObject *dlgCheck::CreateObject(pgCollection *collection)
 
83
{
 
84
    wxString name=GetName();
 
85
 
 
86
    if (name.IsEmpty())
 
87
        return 0;
 
88
 
 
89
    pgObject *obj=checkFactory.CreateObjects(collection, 0, wxT(
 
90
        "\n   AND conname=") + qtString(name) + wxT(
 
91
        "\n   AND relnamespace=") + table->GetSchema()->GetOidStr());
 
92
    return obj;
 
93
}
 
94
 
 
95
 
 
96
int dlgCheck::Go(bool modal)
 
97
{
 
98
    if (check)
 
99
    {
 
100
        // edit mode: view only
 
101
        txtName->Disable();
 
102
 
 
103
        txtWhere->SetValue(check->GetDefinition());
 
104
        txtWhere->Disable();
 
105
 
 
106
        chkDeferrable->SetValue(check->GetDeferrable());
 
107
        chkDeferred->SetValue(check->GetDeferred());
 
108
        chkDeferrable->Disable();
 
109
        chkDeferred->Disable();
 
110
    }
 
111
    else
 
112
    {
 
113
        // create mode
 
114
        txtComment->Disable();
 
115
        if (!table)
 
116
        {
 
117
            cbClusterSet->Disable();
 
118
            cbClusterSet = 0;
 
119
        }
 
120
    }
 
121
    return dlgProperty::Go(modal);
 
122
}
 
123
 
 
124
 
 
125
wxString dlgCheck::GetSql()
 
126
{
 
127
    wxString sql;
 
128
    wxString name=GetName();
 
129
 
 
130
    if (!check)
 
131
    {
 
132
        sql = wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier()
 
133
            + wxT(" ADD");
 
134
        AppendIfFilled(sql, wxT(" CONSTRAINT "), qtIdent(name));
 
135
        sql +=wxT(" CHECK ") + GetDefinition()
 
136
            + wxT(";\n");
 
137
    }
 
138
    if (!name.IsEmpty())
 
139
        AppendComment(sql, wxT("CONSTRAINT ") + qtIdent(name) 
 
140
            + wxT(" ON ") + table->GetQuotedFullIdentifier(), check);
 
141
    return sql;
 
142
}
 
143
 
 
144
 
 
145
wxString dlgCheck::GetDefinition()
 
146
{
 
147
    wxString sql;
 
148
 
 
149
    sql = wxT("(") + txtWhere->GetValue() + wxT(")");
 
150
 
 
151
    return sql;
 
152
}