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

« back to all changes in this revision

Viewing changes to pgadmin/dlg/dlgPackage.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
 
//////////////////////////////////////////////////////////////////////////
2
 
//
3
 
// pgAdmin III - PostgreSQL Tools
4
 
// RCS-ID:      $Id: dlgPackage.cpp 7324 2008-05-29 15:58:38Z dpage $
5
 
// Copyright (C) 2002 - 2008, The pgAdmin Development Team
6
 
// This software is released under the Artistic Licence
7
 
//
8
 
// dlgPackage.cpp - EnterpriseDB package Property
9
 
//
10
 
//////////////////////////////////////////////////////////////////////////
11
 
 
12
 
// wxWindows headers
13
 
#include <wx/wx.h>
14
 
 
15
 
// App headers
16
 
#include "pgAdmin3.h"
17
 
#include "utils/misc.h"
18
 
 
19
 
#include "dlg/dlgPackage.h"
20
 
#include "schema/edbPackage.h"
21
 
 
22
 
// pointer to controls
23
 
#define txtName             CTRL_TEXT("txtName")
24
 
#define txtComment          CTRL_TEXT("txtComment")
25
 
#define txtHeader           CTRL_SQLBOX("txtHeader")
26
 
#define txtBody             CTRL_SQLBOX("txtBody")
27
 
 
28
 
dlgProperty *edbPackageFactory::CreateDialog(frmMain *frame, pgObject *node, pgObject *parent)
29
 
{
30
 
    return new dlgPackage(this, frame, (edbPackage*)node, (pgSchema *)parent);
31
 
}
32
 
 
33
 
 
34
 
BEGIN_EVENT_TABLE(dlgPackage, dlgSecurityProperty)
35
 
    EVT_STC_MODIFIED(XRCID("txtHeader"),            dlgProperty::OnChangeStc)
36
 
    EVT_STC_MODIFIED(XRCID("txtBody"),              dlgProperty::OnChangeStc)
37
 
END_EVENT_TABLE();
38
 
 
39
 
 
40
 
dlgPackage::dlgPackage(pgaFactory *f, frmMain *frame, edbPackage *node, pgSchema *sch)
41
 
: dlgSecurityProperty(f, frame, node, wxT("dlgPackage"), wxT("EXECUTE"), "X")
42
 
{
43
 
    schema=sch;
44
 
    package=node;
45
 
 
46
 
    txtHeader->SetMarginType(1, wxSTC_MARGIN_NUMBER);
47
 
    txtHeader->SetMarginWidth(1, ConvertDialogToPixels(wxPoint(16, 0)).x);
48
 
 
49
 
    txtBody->SetMarginType(1, wxSTC_MARGIN_NUMBER);
50
 
    txtBody->SetMarginWidth(1, ConvertDialogToPixels(wxPoint(16, 0)).x);
51
 
}
52
 
 
53
 
 
54
 
 
55
 
pgObject *dlgPackage::GetObject()
56
 
{
57
 
    return package;
58
 
}
59
 
 
60
 
 
61
 
int dlgPackage::Go(bool modal)
62
 
{
63
 
        if (!connection->EdbMinimumVersion(8, 2))
64
 
                txtComment->Disable();
65
 
 
66
 
    cbOwner->Disable();
67
 
 
68
 
    AddGroups();
69
 
    AddUsers(cbOwner);
70
 
 
71
 
    if (package)
72
 
    {
73
 
        // edit mode
74
 
        txtName->Disable();
75
 
 
76
 
        txtHeader->SetText(package->GetHeaderInner());
77
 
        txtBody->SetText(package->GetBodyInner());
78
 
    }
79
 
    else
80
 
    {
81
 
        // create mode
82
 
 
83
 
    }
84
 
 
85
 
    return dlgSecurityProperty::Go(modal);
86
 
}
87
 
 
88
 
 
89
 
pgObject *dlgPackage::CreateObject(pgCollection *collection)
90
 
{
91
 
    pgObject *obj;
92
 
    
93
 
    if (collection->GetConnection()->EdbMinimumVersion(8, 2))
94
 
        obj=packageFactory.CreateObjects(collection, 0,
95
 
            wxT("   AND nspname = ") + qtDbString(GetName()));
96
 
    else
97
 
        obj=packageFactory.CreateObjects(collection, 0,
98
 
            wxT("   AND pkgname = ") + qtDbString(GetName()));
99
 
 
100
 
    return obj;
101
 
}
102
 
 
103
 
 
104
 
void dlgPackage::CheckChange()
105
 
{
106
 
    bool enable=true;
107
 
 
108
 
    CheckValid(enable, !txtName->GetValue().IsEmpty(), _("Please specify name."));
109
 
    CheckValid(enable, !txtHeader->GetText().IsEmpty(), _("Please specify package header."));
110
 
 
111
 
    if (package)
112
 
    {
113
 
       if (!(txtBody->GetText() != package->GetBodyInner() ||
114
 
           txtHeader->GetText() != package->GetHeaderInner())) 
115
 
           enable = false;
116
 
 
117
 
           if (txtComment->GetValue() != package->GetComment())
118
 
                   enable = true;
119
 
    }
120
 
 
121
 
    EnableOK(enable);
122
 
}
123
 
 
124
 
bool dlgPackage::IsUpToDate()
125
 
{
126
 
        if (package && !package->IsUpToDate())
127
 
                return false;
128
 
        else
129
 
                return true;
130
 
}
131
 
 
132
 
 
133
 
wxString dlgPackage::GetSql()
134
 
{
135
 
    wxString sql;
136
 
    wxString qtName = schema->GetQuotedSchemaPrefix(schema->GetName()) + qtIdent(txtName->GetValue());
137
 
 
138
 
    if (!package || (package && txtHeader->GetText() != package->GetHeaderInner()))
139
 
    {
140
 
        if (package)
141
 
            sql = wxT("DROP PACKAGE BODY ") + qtName + wxT(";\n\n");
142
 
 
143
 
        sql += wxT("CREATE OR REPLACE PACKAGE ") + qtName + wxT("\nAS\n");
144
 
        sql += txtHeader->GetText();
145
 
        sql += wxT("\nEND ") + qtIdent(txtName->GetValue()) + wxT(";\n\n");
146
 
    }
147
 
 
148
 
        if (!package || (package && txtBody->GetText() != package->GetBodyInner())
149
 
                                 || (package && txtHeader->GetText() != package->GetHeaderInner()))
150
 
        {
151
 
                if (!txtBody->GetText().IsEmpty())
152
 
            {
153
 
                        sql += wxT("CREATE OR REPLACE PACKAGE BODY ") + qtName + wxT("\nAS\n");
154
 
                        sql += txtBody->GetText();
155
 
                        sql += wxT("\nEND ") + qtIdent(txtName->GetValue()) + wxT(";\n\n");
156
 
                }
157
 
                else
158
 
                {
159
 
                        if (package)
160
 
                                sql = wxT("DROP PACKAGE BODY ") + qtName + wxT(";\n\n");
161
 
                }
162
 
        }
163
 
 
164
 
    sql += GetGrant(wxT("X"), wxT("PACKAGE ") + qtName);
165
 
 
166
 
        AppendComment(sql, wxT("PACKAGE"), schema, package);
167
 
 
168
 
    return sql;
169
 
}
 
1
//////////////////////////////////////////////////////////////////////////
 
2
//
 
3
// pgAdmin III - PostgreSQL Tools
 
4
// RCS-ID:      $Id: dlgPackage.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
//
 
8
// dlgPackage.cpp - EnterpriseDB package Property
 
9
//
 
10
//////////////////////////////////////////////////////////////////////////
 
11
 
 
12
// wxWindows headers
 
13
#include <wx/wx.h>
 
14
 
 
15
// App headers
 
16
#include "pgAdmin3.h"
 
17
#include "utils/misc.h"
 
18
 
 
19
#include "dlg/dlgPackage.h"
 
20
#include "schema/edbPackage.h"
 
21
 
 
22
// pointer to controls
 
23
#define txtName             CTRL_TEXT("txtName")
 
24
#define txtComment          CTRL_TEXT("txtComment")
 
25
#define txtHeader           CTRL_SQLBOX("txtHeader")
 
26
#define txtBody             CTRL_SQLBOX("txtBody")
 
27
 
 
28
dlgProperty *edbPackageFactory::CreateDialog(frmMain *frame, pgObject *node, pgObject *parent)
 
29
{
 
30
    return new dlgPackage(this, frame, (edbPackage*)node, (pgSchema *)parent);
 
31
}
 
32
 
 
33
 
 
34
BEGIN_EVENT_TABLE(dlgPackage, dlgSecurityProperty)
 
35
    EVT_STC_MODIFIED(XRCID("txtHeader"),            dlgProperty::OnChangeStc)
 
36
    EVT_STC_MODIFIED(XRCID("txtBody"),              dlgProperty::OnChangeStc)
 
37
END_EVENT_TABLE();
 
38
 
 
39
 
 
40
dlgPackage::dlgPackage(pgaFactory *f, frmMain *frame, edbPackage *node, pgSchema *sch)
 
41
: dlgSecurityProperty(f, frame, node, wxT("dlgPackage"), wxT("EXECUTE"), "X")
 
42
{
 
43
    schema=sch;
 
44
    package=node;
 
45
 
 
46
    txtHeader->SetMarginType(1, wxSTC_MARGIN_NUMBER);
 
47
    txtHeader->SetMarginWidth(1, ConvertDialogToPixels(wxPoint(16, 0)).x);
 
48
 
 
49
    txtBody->SetMarginType(1, wxSTC_MARGIN_NUMBER);
 
50
    txtBody->SetMarginWidth(1, ConvertDialogToPixels(wxPoint(16, 0)).x);
 
51
}
 
52
 
 
53
 
 
54
 
 
55
pgObject *dlgPackage::GetObject()
 
56
{
 
57
    return package;
 
58
}
 
59
 
 
60
 
 
61
int dlgPackage::Go(bool modal)
 
62
{
 
63
    if (!connection->EdbMinimumVersion(8, 2))
 
64
        txtComment->Disable();
 
65
 
 
66
    cbOwner->Disable();
 
67
 
 
68
    AddGroups();
 
69
    AddUsers(cbOwner);
 
70
 
 
71
    if (package)
 
72
    {
 
73
        // edit mode
 
74
        txtName->Disable();
 
75
 
 
76
        txtHeader->SetText(package->GetHeaderInner());
 
77
        txtBody->SetText(package->GetBodyInner());
 
78
    }
 
79
    else
 
80
    {
 
81
        // create mode
 
82
 
 
83
    }
 
84
 
 
85
    return dlgSecurityProperty::Go(modal);
 
86
}
 
87
 
 
88
 
 
89
pgObject *dlgPackage::CreateObject(pgCollection *collection)
 
90
{
 
91
    pgObject *obj;
 
92
    
 
93
    if (collection->GetConnection()->EdbMinimumVersion(8, 2))
 
94
        obj=packageFactory.CreateObjects(collection, 0,
 
95
            wxT("   AND nspname = ") + qtDbString(GetName()));
 
96
    else
 
97
        obj=packageFactory.CreateObjects(collection, 0,
 
98
            wxT("   AND pkgname = ") + qtDbString(GetName()));
 
99
 
 
100
    return obj;
 
101
}
 
102
 
 
103
 
 
104
#ifdef __WXMAC__
 
105
void dlgPackage::OnChangeSize(wxSizeEvent &ev)
 
106
{
 
107
    SetPrivilegesLayout();
 
108
    if (GetAutoLayout())
 
109
    {
 
110
        Layout();
 
111
    }
 
112
}
 
113
#endif
 
114
 
 
115
 
 
116
void dlgPackage::CheckChange()
 
117
{
 
118
    bool enable=true;
 
119
 
 
120
    CheckValid(enable, !txtName->GetValue().IsEmpty(), _("Please specify name."));
 
121
    CheckValid(enable, !txtHeader->GetText().IsEmpty(), _("Please specify package header."));
 
122
 
 
123
    if (package)
 
124
    {
 
125
       if (!(txtBody->GetText() != package->GetBodyInner() ||
 
126
           txtHeader->GetText() != package->GetHeaderInner())) 
 
127
           enable = false;
 
128
 
 
129
       if (txtComment->GetValue() != package->GetComment())
 
130
           enable = true;
 
131
    }
 
132
 
 
133
    EnableOK(enable);
 
134
}
 
135
 
 
136
bool dlgPackage::IsUpToDate()
 
137
{
 
138
    if (package && !package->IsUpToDate())
 
139
        return false;
 
140
    else
 
141
        return true;
 
142
}
 
143
 
 
144
 
 
145
wxString dlgPackage::GetSql()
 
146
{
 
147
    wxString sql;
 
148
    wxString qtName = schema->GetQuotedSchemaPrefix(schema->GetName()) + qtIdent(txtName->GetValue());
 
149
 
 
150
    if (!package || (package && txtHeader->GetText() != package->GetHeaderInner()))
 
151
    {
 
152
        if (package)
 
153
            sql = wxT("DROP PACKAGE BODY ") + qtName + wxT(";\n\n");
 
154
 
 
155
        sql += wxT("CREATE OR REPLACE PACKAGE ") + qtName + wxT("\nIS\n");
 
156
        sql += txtHeader->GetText();
 
157
        sql += wxT("\nEND ") + qtIdent(txtName->GetValue()) + wxT(";\n\n");
 
158
    }
 
159
 
 
160
    if (!package || (package && txtBody->GetText() != package->GetBodyInner())
 
161
                 || (package && txtHeader->GetText() != package->GetHeaderInner()))
 
162
    {
 
163
        if (!txtBody->GetText().IsEmpty())
 
164
        {
 
165
            sql += wxT("CREATE OR REPLACE PACKAGE BODY ") + qtName + wxT("\nIS\n");
 
166
            sql += txtBody->GetText();
 
167
            sql += wxT("\nEND ") + qtIdent(txtName->GetValue()) + wxT(";\n\n");
 
168
        }
 
169
        else
 
170
        {
 
171
            if (package)
 
172
                sql = wxT("DROP PACKAGE BODY ") + qtName + wxT(";\n\n");
 
173
        }
 
174
    }
 
175
 
 
176
    sql += GetGrant(wxT("X"), wxT("PACKAGE ") + qtName);
 
177
 
 
178
    AppendComment(sql, wxT("PACKAGE"), schema, package);
 
179
 
 
180
    return sql;
 
181
}