~ubuntu-branches/debian/sid/pgadmin3/sid

« back to all changes in this revision

Viewing changes to pgadmin/dlg/dlgColumn.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gerfried Fuchs
  • Date: 2009-07-30 12:27:16 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730122716-fddbh42on721bbs2
Tags: 1.10.0-1
* New upstream release.
* Adjusted watch file to match release candidates.
* Updated to Standards-Version 3.8.2:
  - Moved to Section: database.
  - Add DEB_BUILD_OPTIONS support for parallel building.
  - Move from findstring to filter suggestion for DEB_BUILD_OPTIONS parsing.
* pgagent got split into its own separate source package by upstream.
* Exclude Docs.vcproj from installation.
* Move doc-base.enus from pgadmin3 to pgadmin3-data package, the files are
  in there too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//////////////////////////////////////////////////////////////////////////
2
2
//
3
3
// pgAdmin III - PostgreSQL Tools
4
 
// RCS-ID:      $Id: dlgColumn.cpp 7160 2008-03-11 09:07:07Z dpage $
5
 
// Copyright (C) 2002 - 2008, The pgAdmin Development Team
6
 
// This software is released under the Artistic Licence
 
4
// RCS-ID:      $Id: dlgColumn.cpp 7758 2009-03-26 20:49:59Z dpage $
 
5
// Copyright (C) 2002 - 2009, The pgAdmin Development Team
 
6
// This software is released under the BSD Licence
7
7
//
8
8
// dlgColumns.cpp - PostgreSQL Columns Property
9
9
//
22
22
#include "schema/pgColumn.h"
23
23
#include "schema/pgTable.h"
24
24
#include "schema/pgDatatype.h"
 
25
#include "frm/frmMain.h"
 
26
#include "schema/pgUser.h"
 
27
#include "schema/pgGroup.h"
25
28
 
26
29
 
27
30
// pointer to controls
37
40
    EVT_TEXT(XRCID("txtAttstattarget"),             dlgProperty::OnChange)
38
41
    EVT_TEXT(XRCID("cbDatatype"),                   dlgColumn::OnSelChangeTyp)
39
42
    EVT_COMBOBOX(XRCID("cbDatatype"),               dlgColumn::OnSelChangeTyp)
 
43
    EVT_BUTTON(CTL_ADDPRIV,                         dlgColumn::OnAddPriv)
 
44
    EVT_BUTTON(CTL_DELPRIV,                         dlgColumn::OnDelPriv)
 
45
#ifdef __WXMAC__
 
46
    EVT_SIZE(                                       dlgColumn::OnChangeSize)
 
47
#endif
40
48
END_EVENT_TABLE();
41
49
 
42
50
 
51
59
{
52
60
    column=node;
53
61
    table=parentNode;
54
 
    wxASSERT(!table || (table->GetMetaType() == PGM_TABLE || table->GetMetaType() == PGM_VIEW));
 
62
    wxASSERT(!table || (table->GetMetaType() == PGM_TABLE || table->GetMetaType() == PGM_VIEW || table->GetMetaType() == GP_EXTTABLE || table->GetMetaType() == GP_PARTITION));
55
63
 
56
64
    txtAttstattarget->SetValidator(numericValidator);
57
 
}
58
 
 
 
65
 
 
66
    /* Column Level Privileges */
 
67
    securityChanged=false;
 
68
    if (node)
 
69
        connection = node->GetConnection();
 
70
    securityPage = new ctlSecurityPanel(nbNotebook, wxT("INSERT,SELECT,UPDATE,REFERENCES"), "arwx", frame->GetImageList());
 
71
    if (connection && connection->BackendMinimumVersion(8, 4) && (!node || node->CanCreate()))
 
72
    {
 
73
        // Fetch Groups Information
 
74
        pgSet *setGrp = connection->ExecuteSet(wxT("SELECT groname FROM pg_group ORDER BY groname"));
 
75
 
 
76
        if (setGrp)
 
77
        {
 
78
            while (!setGrp->Eof())
 
79
            {
 
80
                groups.Add(setGrp->GetVal(0));
 
81
                setGrp->MoveNext();
 
82
            }
 
83
            delete setGrp;
 
84
        }
 
85
 
 
86
        if (node)
 
87
        {
 
88
            wxString strAcl = node->GetAcl();
 
89
            if (!strAcl.IsEmpty())
 
90
            {
 
91
                wxArrayString aclArray;
 
92
                strAcl = strAcl.Mid(1, strAcl.Length()-2);
 
93
                getArrayFromCommaSeparatedList(strAcl, aclArray);
 
94
                wxString roleName;
 
95
                for (unsigned int index = 0; index < aclArray.Count(); index++)
 
96
                {
 
97
                    wxString strCurrAcl = aclArray[index];
 
98
 
 
99
                    /*
 
100
                    * In rare case, we can have ',' (comma) in the user name.
 
101
                    * But, we need to handle them also
 
102
                    */ 
 
103
                    if (strCurrAcl.Find(wxChar('=')) == wxNOT_FOUND)
 
104
                    {
 
105
                        // Check it is start of the ACL
 
106
                        if (strCurrAcl[0U] == (wxChar)'"')
 
107
                            roleName = strCurrAcl + wxT(",");
 
108
                        continue;
 
109
                    }
 
110
                    else
 
111
                        strCurrAcl = roleName + strCurrAcl;
 
112
 
 
113
                    if (strCurrAcl[0U] == (wxChar)'"')
 
114
                        strCurrAcl = strCurrAcl.Mid(1, strCurrAcl.Length()-1);
 
115
                    roleName = strCurrAcl.BeforeLast('=');
 
116
 
 
117
                    wxString value=strCurrAcl.Mid(roleName.Length()+1).BeforeLast('/');
 
118
 
 
119
                    int icon = userFactory.GetIconId();
 
120
 
 
121
                    if (roleName.Left(6).IsSameAs(wxT("group ")), false)
 
122
                    {
 
123
                        icon = groupFactory.GetIconId();
 
124
                        roleName = wxT("group ") + qtStrip(roleName.Mid(6));
 
125
                    }
 
126
                    else if (roleName.IsEmpty())
 
127
                    {
 
128
                        icon = PGICON_PUBLIC;
 
129
                        roleName = wxT("public");
 
130
                    }
 
131
                    else
 
132
                    {
 
133
                        roleName = qtStrip(roleName);
 
134
                        for (unsigned int index=0; index < groups.Count(); index++)
 
135
                            if (roleName == groups[index])
 
136
                            {
 
137
                                roleName = wxT("group ") + roleName;
 
138
                                icon = groupFactory.GetIconId();
 
139
                                break;
 
140
                            }
 
141
                    }
 
142
 
 
143
                    securityPage->lbPrivileges->AppendItem(icon, roleName, value);
 
144
                    currentAcl.Add(roleName + wxT("=") + value);
 
145
 
 
146
                    // Reset roleName
 
147
                    roleName.Empty();
 
148
                }
 
149
            }
 
150
        }
 
151
    }
 
152
    else
 
153
        securityPage->Disable();
 
154
 
 
155
}
 
156
 
 
157
 
 
158
#ifdef __WXMAC__
 
159
void dlgColumn::OnChangeSize(wxSizeEvent &ev)
 
160
{
 
161
    securityPage->lbPrivileges->SetSize(wxDefaultCoord, wxDefaultCoord,
 
162
        ev.GetSize().GetWidth(), ev.GetSize().GetHeight() - 550);
 
163
    if (GetAutoLayout())
 
164
    {
 
165
        Layout();
 
166
    }
 
167
}
 
168
#endif
59
169
 
60
170
pgObject *dlgColumn::GetObject()
61
171
{
65
175
 
66
176
int dlgColumn::Go(bool modal)
67
177
{
 
178
    if (connection->BackendMinimumVersion(8, 4))
 
179
    {
 
180
        securityPage->SetConnection(connection);
 
181
        
 
182
        if (securityPage->cbGroups)
 
183
        {
 
184
            // Fetch Groups Information
 
185
            for ( unsigned int index=0; index < groups.Count();)
 
186
                securityPage->cbGroups->Append(wxT("group ") + groups[index++]);
 
187
 
 
188
            // Fetch Users Information
 
189
            if (settings->GetShowUsersForPrivileges())
 
190
            {
 
191
                securityPage->stGroup->SetLabel(_("Group/User"));
 
192
                dlgProperty::AddUsers(securityPage->cbGroups);
 
193
            }
 
194
        }
 
195
        securityPage->lbPrivileges->GetParent()->Layout();
 
196
    }
 
197
    
 
198
 
68
199
    if (column)
69
200
    {
70
201
        // edit mode
76
207
        chkNotNull->SetValue(column->GetNotNull());
77
208
        txtAttstattarget->SetValue(NumToStr(column->GetAttstattarget()));
78
209
 
79
 
                wxString fullType = column->GetRawTypename();
80
 
                if (column->GetIsArray())
81
 
                        fullType += wxT("[]");
 
210
        wxString fullType = column->GetRawTypename();
 
211
        if (column->GetIsArray())
 
212
            fullType += wxT("[]");
82
213
        cbDatatype->Append(fullType);
83
214
        AddType(wxT("?"), column->GetAttTypId(), fullType);
84
215
 
131
262
            cbDatatype->Disable();
132
263
            txtAttstattarget->Disable();
133
264
        }
 
265
         else if (column->GetTable()->GetMetaType() == GP_EXTTABLE) // Disable controls not valid for external table columns
 
266
        {
 
267
            txtName->Disable();
 
268
            chkNotNull->Disable();
 
269
            txtLength->Disable();
 
270
            cbDatatype->Disable();
 
271
            txtAttstattarget->Disable();
 
272
            txtDefault->Disable();
 
273
        }
134
274
    }
135
275
    else
136
276
    {
142
282
        AddType(wxT(" "), 0, wxT("bigserial"));
143
283
 
144
284
        if (!table)
145
 
                {
 
285
        {
146
286
            cbClusterSet->Disable();
147
287
            cbClusterSet = 0;
148
288
        }
159
299
    wxString sql;
160
300
    wxString name=GetName();
161
301
 
162
 
        bool isSerial = (cbDatatype->GetValue() == wxT("serial") || cbDatatype->GetValue() == wxT("bigserial"));
 
302
    bool isSerial = (cbDatatype->GetValue() == wxT("serial") || cbDatatype->GetValue() == wxT("bigserial"));
163
303
 
164
304
    if (table)
165
305
    {
273
413
 
274
414
        AppendComment(sql, wxT("COLUMN ") + table->GetQuotedFullIdentifier() 
275
415
                + wxT(".") + qtIdent(name), column);
 
416
 
 
417
        // securityPage will exists only for PG 8.4 and later
 
418
        if (connection->BackendMinimumVersion(8, 4))
 
419
            sql += securityPage->GetGrant(wxT("arwx"), table->GetQuotedFullIdentifier(), &currentAcl, qtIdent(name));
276
420
    }
277
421
    return sql;
278
422
}
351
495
                    || (isVarLen && varlen != column->GetLength())
352
496
                    || (isVarPrec && varprec != column->GetPrecision())
353
497
                    || txtAttstattarget->GetValue() != NumToStr(column->GetAttstattarget());
354
 
        EnableOK(enable);
 
498
 
 
499
        EnableOK(enable | securityChanged);
355
500
    }
356
501
    else
357
502
    {
374
519
}
375
520
 
376
521
 
377
 
 
378
 
 
379
 
 
380
 
 
 
522
void dlgColumn::OnAddPriv(wxCommandEvent &ev)
 
523
{
 
524
    securityChanged=true;
 
525
    CheckChange();
 
526
}
 
527
 
 
528
 
 
529
void dlgColumn::OnDelPriv(wxCommandEvent &ev)
 
530
{
 
531
    securityChanged=true;
 
532
    CheckChange();
 
533
}
381
534