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

« back to all changes in this revision

Viewing changes to src/dlg/dlgView.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: dlgView.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
// dlgView.cpp - PostgreSQL View 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 "pgDefs.h"
 
19
 
 
20
#include "ctl/ctlSQLBox.h"
 
21
#include "dlgView.h"
 
22
#include "pgView.h"
 
23
#include "pgSchema.h"
 
24
 
 
25
 
 
26
 
 
27
// pointer to controls
 
28
#define pnlDefinition   CTRL_PANEL("pnlDefinition")
 
29
#define txtSqlBox       CTRL_SQLBOX("txtSqlBox")
 
30
 
 
31
 
 
32
 
 
33
BEGIN_EVENT_TABLE(dlgView, dlgSecurityProperty)
 
34
    EVT_STC_MODIFIED(XRCID("txtSqlBox"),            dlgProperty::OnChangeStc)
 
35
END_EVENT_TABLE();
 
36
 
 
37
 
 
38
dlgProperty *pgViewFactory::CreateDialog(frmMain *frame, pgObject *node, pgObject *parent)
 
39
{
 
40
    return new dlgView(this, frame, (pgView*)node, (pgSchema*)parent);
 
41
}
 
42
 
 
43
dlgView::dlgView(pgaFactory *f, frmMain *frame, pgView *node, pgSchema *sch)
 
44
: dlgSecurityProperty(f, frame, node, wxT("dlgView"), wxT("INSERT,SELECT,UPDATE,DELETE,RULE,REFERENCE,TRIGGER"), "arwdRxt")
 
45
{
 
46
    schema=sch;
 
47
    view=node;
 
48
}
 
49
 
 
50
 
 
51
pgObject *dlgView::GetObject()
 
52
{
 
53
    return view;
 
54
}
 
55
 
 
56
 
 
57
int dlgView::Go(bool modal)
 
58
{
 
59
    AddGroups();
 
60
    AddUsers();
 
61
 
 
62
    if (view)
 
63
    {
 
64
        // edit mode
 
65
 
 
66
        oldDefinition=view->GetFormattedDefinition();
 
67
        txtSqlBox->SetText(oldDefinition);
 
68
    }
 
69
    else
 
70
    {
 
71
        // create mode
 
72
    }
 
73
 
 
74
    return dlgSecurityProperty::Go(modal);
 
75
}
 
76
 
 
77
 
 
78
pgObject *dlgView::CreateObject(pgCollection *collection)
 
79
{
 
80
    pgObject *obj=viewFactory.CreateObjects(collection, 0, 
 
81
        wxT("\n   AND c.relname=") + qtString(txtName->GetValue()) +
 
82
        wxT("\n   AND c.relnamespace=") + schema->GetOidStr());
 
83
    return obj;
 
84
}
 
85
 
 
86
 
 
87
void dlgView::CheckChange()
 
88
{
 
89
    wxString name=GetName();
 
90
    if (view)
 
91
    {
 
92
        EnableOK(txtComment->GetValue() != view->GetComment()
 
93
              || txtSqlBox->GetText() != oldDefinition
 
94
              || cbOwner->GetValue() != view->GetOwner()
 
95
              || name != view->GetName());
 
96
    }
 
97
    else
 
98
    {
 
99
        bool enable=true;
 
100
 
 
101
        CheckValid(enable, !name.IsEmpty(), _("Please specify name."));
 
102
        CheckValid(enable, txtSqlBox->GetText().Length() > 14 , _("Please enter function definition."));
 
103
 
 
104
        EnableOK(enable);
 
105
    }
 
106
}
 
107
 
 
108
 
 
109
wxString dlgView::GetSql()
 
110
{
 
111
    wxString sql, name=GetName();
 
112
 
 
113
 
 
114
    if (view)
 
115
    {
 
116
        // edit mode
 
117
 
 
118
        if (name != view->GetName())
 
119
        {
 
120
            sql += wxT("ALTER TABLE ") + view->GetQuotedFullIdentifier()
 
121
                +  wxT(" RENAME TO ") + qtIdent(name) + wxT(";\n");
 
122
        }
 
123
    }
 
124
 
 
125
    if (!view || txtSqlBox->GetText() != oldDefinition)
 
126
    {
 
127
        sql += wxT("CREATE OR REPLACE VIEW ") + schema->GetQuotedPrefix() + qtIdent(name) + wxT(" AS\n")
 
128
            + txtSqlBox->GetText()
 
129
            + wxT(";\n");
 
130
    }
 
131
 
 
132
        if (view)
 
133
                AppendOwnerChange(sql, wxT("TABLE ") + schema->GetQuotedPrefix() + qtIdent(name));
 
134
        else
 
135
                AppendOwnerNew(sql, wxT("TABLE ") + schema->GetQuotedPrefix() + qtIdent(name));
 
136
 
 
137
 
 
138
    sql +=  GetGrant(wxT("arwdRxt"), wxT("TABLE ") + schema->GetQuotedPrefix() + qtIdent(name));
 
139
 
 
140
    AppendComment(sql, wxT("VIEW"), schema, view);
 
141
    return sql;
 
142
}
 
143