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

« back to all changes in this revision

Viewing changes to pgadmin/agent/dlgStep.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: dlgStep.cpp 6930 2008-01-02 00:10:01Z dpage $
5
 
// Copyright (C) 2002 - 2008, The pgAdmin Development Team
6
 
// This software is released under the Artistic Licence
 
4
// RCS-ID:      $Id: dlgStep.cpp 7915 2009-06-11 09:40:07Z dpage $
 
5
// Copyright (C) 2002 - 2009, The pgAdmin Development Team
 
6
// This software is released under the BSD Licence
7
7
//
8
8
// dlgStep.cpp - PostgreSQL Step Property
9
9
//
14
14
#include "utils/misc.h"
15
15
#include "agent/dlgStep.h"
16
16
#include "agent/pgaStep.h"
 
17
#include "dlg/dlgSelectDatabase.h"
 
18
#include "schema/pgTable.h"
17
19
 
18
20
 
19
21
// pointer to controls
20
 
#define txtID                           CTRL_TEXT("txtID")
 
22
#define txtID               CTRL_TEXT("txtID")
21
23
#define chkEnabled          CTRL_CHECKBOX("chkEnabled")
22
 
#define cbDatabase          CTRL_COMBOBOX("cbDatabase")
23
24
#define rbxKind             CTRL_RADIOBOX("rbxKind")
24
25
#define rbxOnError          CTRL_RADIOBOX("rbxOnError")
25
26
#define pnlDefinition       CTRL_PANEL("pnlDefinition")
26
27
#define txtSqlBox           CTRL_TEXT("txtSqlBox")
 
28
#define cbDatabase          CTRL_COMBOBOX2("cbDatabase")
 
29
#define txtConnStr          CTRL_TEXT("txtConnStr")
 
30
#define btnSelDatabase      CTRL_BUTTON("btnSelDatabase")
 
31
#define rbRemoteConn        CTRL_RADIOBUTTON("rbRemoteConn")
 
32
#define rbLocalConn         CTRL_RADIOBUTTON("rbLocalConn")
27
33
 
28
34
#define CTL_SQLBOX  188
29
35
 
32
38
    EVT_COMBOBOX(XRCID("cbDatabase"),               dlgProperty::OnChange)
33
39
    EVT_RADIOBOX(XRCID("rbxKind"),                  dlgProperty::OnChange)
34
40
    EVT_RADIOBOX(XRCID("rbxOnError"),               dlgProperty::OnChange)
 
41
    EVT_TEXT(XRCID("txtConnStr"),                   dlgProperty::OnChange)
35
42
    EVT_STC_MODIFIED(CTL_SQLBOX,                    dlgProperty::OnChangeStc)
 
43
    EVT_BUTTON(XRCID("btnSelDatabase"),             dlgStep::OnSelectDatabase)
 
44
    EVT_RADIOBUTTON(XRCID("rbRemoteConn"),          dlgStep::OnSelRemoteConn)
 
45
    EVT_RADIOBUTTON(XRCID("rbLocalConn"),           dlgStep::OnSelLocalConn)
36
46
END_EVENT_TABLE();
37
47
 
38
48
 
61
71
    delete placeholder;
62
72
    sizer->Layout();
63
73
 
64
 
        txtID->Disable();
 
74
 
 
75
    txtID->Disable();
65
76
}
66
77
 
67
78
 
73
84
 
74
85
int dlgStep::Go(bool modal)
75
86
{
 
87
        int returncode;
 
88
        
 
89
    hasConnStrSupport = connection->TableHasColumn(wxT("pgagent"), wxT("pga_jobstep"), wxT("jstconnstr"));
76
90
    cbDatabase->Append(wxT(" "));
77
91
    cbDatabase->SetSelection(0);
78
92
 
90
104
    if (step)
91
105
    {
92
106
        // edit mode
93
 
                recId = step->GetRecId();
94
 
                txtID->SetValue(NumToStr(recId));
95
 
        if (step->GetDbname().IsEmpty())
96
 
            cbDatabase->SetSelection(0);
 
107
        recId = step->GetRecId();
 
108
        txtID->SetValue(NumToStr(recId));
 
109
 
 
110
        if (step->HasConnectionString())
 
111
        {
 
112
            rbRemoteConn->SetValue(true);
 
113
            txtConnStr->Enable(true);
 
114
            txtConnStr->ChangeValue(step->GetConnStr());
 
115
            btnSelDatabase->Enable(true);
 
116
            cbDatabase->Enable(false);
 
117
        }
97
118
        else
98
 
            cbDatabase->SetValue(step->GetDbname());
 
119
        {
 
120
            rbLocalConn->SetValue(true);
 
121
            if (step->GetDbname().IsEmpty())
 
122
                cbDatabase->SetSelection(0);
 
123
            else
 
124
                cbDatabase->SetValue(step->GetDbname());
 
125
        }
 
126
 
99
127
        rbxKind->SetSelection(wxString(wxT("sb")).Find(step->GetKindChar()));
100
128
        rbxOnError->SetSelection(wxString(wxT("fsi")).Find(step->GetOnErrorChar()));
101
129
        sqlBox->SetText(step->GetCode());
105
133
    else
106
134
    {
107
135
        // create mode
 
136
        rbLocalConn->SetValue(true);
 
137
        cbDatabase->Enable(true);
 
138
        btnSelDatabase->Enable(false);
 
139
        txtConnStr->Enable(false);
 
140
        if (!hasConnStrSupport)
 
141
            rbLocalConn->Enable(false);
108
142
    }
109
143
 
110
 
    return dlgProperty::Go(modal);
 
144
    returncode = dlgProperty::Go(modal);
 
145
        
 
146
        SetSqlReadOnly(true);
 
147
 
 
148
        return returncode;
111
149
}
112
150
 
113
151
 
128
166
    {
129
167
        enable  =  name != step->GetName()
130
168
                || chkEnabled->GetValue() != step->GetEnabled()
131
 
                || cbDatabase->GetValue().Trim() != step->GetDbname()
132
169
                || rbxKind->GetSelection() != wxString(wxT("sb")).Find(step->GetKindChar())
133
170
                || rbxOnError->GetSelection() != wxString(wxT("fsi")).Find(step->GetOnErrorChar())
134
171
                || txtComment->GetValue() != step->GetComment()
135
172
                || sqlBox->GetText() != step->GetCode();
 
173
 
 
174
        if (!enable && rbxKind->GetSelection() == 0)
 
175
        {
 
176
            if (hasConnStrSupport)
 
177
            {
 
178
                if (step->HasConnectionString())
 
179
                {
 
180
                    if (rbRemoteConn->GetValue())
 
181
                        enable = txtConnStr->GetValue().Trim() != step->GetConnStr();
 
182
                    else
 
183
                        enable = true;
 
184
                }
 
185
                else
 
186
                {
 
187
                    if (rbRemoteConn->GetValue())
 
188
                        enable = true;
 
189
                    else
 
190
                        enable = cbDatabase->GetValue().Trim() != step->GetDbname();
 
191
                }
 
192
            }
 
193
            else
 
194
            {
 
195
                enable = cbDatabase->GetValue().Trim() != step->GetDbname();
 
196
            }
 
197
        }
136
198
    }
137
199
    else
138
200
    {
139
201
        enable=true;
140
202
    }
141
203
 
142
 
        if (statusBar)
143
 
                statusBar->SetStatusText(wxEmptyString);
 
204
    if (statusBar)
 
205
        statusBar->SetStatusText(wxEmptyString);
144
206
 
145
207
    CheckValid(enable, !name.IsEmpty(), _("Please specify name."));
146
208
    CheckValid(enable, sqlBox->GetLength() > 0, _("Please specify code to execute."));
148
210
    // Disable/enable the database combo
149
211
    if (rbxKind->GetSelection() == 1)
150
212
    {
151
 
        cbDatabase->SetSelection(0);
 
213
        rbRemoteConn->Enable(false);
 
214
        rbLocalConn->Enable(false);
 
215
        // I don't see any reason to make
 
216
        // the database combobox selection to 0
 
217
        //cbDatabase->SetSelection(0);
 
218
        txtConnStr->Enable(false);
 
219
        btnSelDatabase->Enable(false);
152
220
        cbDatabase->Enable(false);
153
221
    }
154
222
    else
155
223
    {
156
 
        cbDatabase->Enable(true);
157
 
        CheckValid(enable, !cbDatabase->GetValue().Trim().IsEmpty(), _("Please select a database."));
 
224
        if (hasConnStrSupport)
 
225
        {
 
226
            rbRemoteConn->Enable(true);
 
227
            rbLocalConn->Enable(true);
 
228
            if (rbRemoteConn->GetValue())
 
229
            {
 
230
                wxString validConnStr;                
 
231
 
 
232
                btnSelDatabase->Enable(true);
 
233
                txtConnStr->Enable(true);
 
234
                cbDatabase->Enable(false);
 
235
                CheckValid(enable, !txtConnStr->GetValue().Trim().IsEmpty(), _("Please select a connection string."));
 
236
                CheckValid(enable, dlgSelectDatabase::getValidConnectionString(txtConnStr->GetValue().Trim(), validConnStr), _("Please enter a valid connection string"));
 
237
            }
 
238
            else
 
239
            {
 
240
                cbDatabase->Enable(true);
 
241
                btnSelDatabase->Enable(false);
 
242
                txtConnStr->Enable(false);
 
243
                CheckValid(enable, !cbDatabase->GetValue().Trim().IsEmpty(), _("Please select a database."));
 
244
            }
 
245
        }
 
246
        else
 
247
        {
 
248
            cbDatabase->Enable(true);
 
249
            // Make sure both radio buttons are disabled
 
250
            rbRemoteConn->Enable(false);
 
251
            rbLocalConn->Enable(false);
 
252
            CheckValid(enable, !cbDatabase->GetValue().Trim().IsEmpty(), _("Please select a database."));
 
253
        }
158
254
    }
159
255
 
160
256
    EnableOK(enable);
178
274
        wxString name=GetName();
179
275
        wxString kind = wxT("sb")[rbxKind->GetSelection()];
180
276
        wxString onerror = wxT("fsi")[rbxOnError->GetSelection()];
181
 
        wxString db;
 
277
        wxString db, connstr;
182
278
        wxString jstjobid;
183
279
        if (jobId)
184
280
            jstjobid = NumToStr(jobId);
185
281
        else
186
282
            jstjobid = wxT("<JobId>");
187
 
 
188
 
        db = qtDbString(cbDatabase->GetValue().Trim());
189
 
 
190
 
        sql = wxT("INSERT INTO pgagent.pga_jobstep (jstid, jstjobid, jstname, jstdesc, jstenabled, jstkind, jstonerror, jstcode, jstdbname)\n")
191
 
              wxT("SELECT <StpId>, ") + jstjobid + wxT(", ") + qtDbString(name) + wxT(", ") + qtDbString(txtComment->GetValue()) + wxT(", ")
 
283
        // SQL script expected
 
284
        if (rbxKind->GetSelection() == 0)
 
285
        {
 
286
            if (hasConnStrSupport && rbRemoteConn->GetValue())
 
287
                        {
 
288
                connstr = qtDbString(txtConnStr->GetValue().Trim());
 
289
                                db = wxT("''");
 
290
                        }
 
291
            else
 
292
                        {
 
293
                db = qtDbString(cbDatabase->GetValue().Trim());
 
294
                                connstr = wxT("''");
 
295
                        }
 
296
        }
 
297
        else
 
298
        {
 
299
            db = wxT("''");
 
300
            connstr = wxT("''");
 
301
        }
 
302
 
 
303
        sql = wxT("INSERT INTO pgagent.pga_jobstep (jstid, jstjobid, jstname, jstdesc, jstenabled, jstkind, jstonerror, jstcode, jstdbname");
 
304
        if (hasConnStrSupport)
 
305
            sql += wxT(", jstconnstr");
 
306
        sql += wxT(")\n ") \
 
307
               wxT("SELECT <StpId>, ") + jstjobid + wxT(", ") + qtDbString(name) + wxT(", ") + qtDbString(txtComment->GetValue()) + wxT(", ")
192
308
                + BoolToStr(chkEnabled->GetValue()) + wxT(", ") + qtDbString(kind) + wxT(", ") 
193
 
                + qtDbString(onerror) + wxT(", ") + qtDbString(sqlBox->GetText()) + wxT(", ") + db + wxT(";\n");
 
309
                + qtDbString(onerror) + wxT(", ") + qtDbString(sqlBox->GetText()) + wxT(", ") + db;
 
310
        if (hasConnStrSupport)
 
311
        {
 
312
            sql += wxT(", ") + connstr;
 
313
        }
 
314
        sql += wxT(";\n");
194
315
    }
195
316
    return sql;
196
317
}
203
324
    if (step)
204
325
    {
205
326
        // edit mode
206
 
 
207
327
        wxString name=GetName();
 
328
        wxString kind = wxT("sb")[rbxKind->GetSelection()];
208
329
 
209
330
        wxString vars;
210
331
        if (name != step->GetName())
219
340
                vars.Append(wxT(", "));
220
341
            vars.Append(wxT("jstenabled=") + BoolToStr(chkEnabled->GetValue()));
221
342
        }
222
 
        if (cbDatabase->GetValue().Trim() != step->GetDbname())
 
343
        if (hasConnStrSupport && kind == wxT("s"))
223
344
        {
224
 
            if (!vars.IsEmpty())
225
 
                vars.Append(wxT(", "));
226
 
            
227
 
            if (!cbDatabase->GetCurrentSelection())
228
 
                vars.Append(wxT("jstdbname=''"));
 
345
            if (rbRemoteConn->GetValue())
 
346
            {
 
347
                if (step->HasConnectionString())
 
348
                {
 
349
                    if (txtConnStr->GetValue().Trim() != step->GetConnStr())
 
350
                    {
 
351
                        if (!vars.IsEmpty())
 
352
                            vars.Append(wxT(", "));
 
353
                        vars.Append(wxT("jstconnstr=") + qtDbString(txtConnStr->GetValue().Trim()));
 
354
                    }
 
355
                }
 
356
                else
 
357
                {
 
358
                    if (!vars.IsEmpty())
 
359
                        vars.Append(wxT(", "));
 
360
                    vars.Append(wxT("jstconnstr=") + qtDbString(txtConnStr->GetValue().Trim()) + wxT(", "));
 
361
                    vars.Append(wxT("jstdbname=''"));
 
362
                }
 
363
            }
229
364
            else
230
 
                vars.Append(wxT("jstdbname=") + qtDbString(cbDatabase->GetValue()));
231
 
        }
232
 
        if (rbxKind->GetSelection() != wxString(wxT("sb")).Find(step->GetKindChar()))
233
 
        {
234
 
            wxString kind = wxT("sb")[rbxKind->GetSelection()];
 
365
            {
 
366
                if (step->HasConnectionString())
 
367
                {
 
368
                    if (!vars.IsEmpty())
 
369
                        vars.Append(wxT(", "));
 
370
                    vars.Append(wxT("jstdbname=") + qtDbString(cbDatabase->GetValue().Trim()) + wxT(", "));
 
371
                    vars.Append(wxT("jstconnstr=''"));
 
372
                }
 
373
                else
 
374
                {
 
375
                    if (cbDatabase->GetValue().Trim() != step->GetDbname())
 
376
                    {
 
377
                        if (!vars.IsEmpty())
 
378
                            vars.Append(wxT(", "));
 
379
                        vars.Append(wxT("jstdbname=") + qtDbString(cbDatabase->GetValue().Trim()));
 
380
                    }
 
381
                }
 
382
            }
 
383
        }
 
384
        else if (kind == wxT("s"))
 
385
        {
 
386
            if (cbDatabase->GetValue().Trim() != step->GetDbname())
 
387
            {
 
388
                if (!vars.IsEmpty())
 
389
                    vars.Append(wxT(", "));
 
390
                vars.Append(wxT("jstdbname=") + qtDbString(cbDatabase->GetValue().Trim()));
 
391
            }
 
392
        }
 
393
        else
 
394
        {
 
395
            if (!vars.IsEmpty())
 
396
                vars.Append(wxT(", "));
 
397
            vars.Append(wxT("jstdbname=''"));
 
398
            if (hasConnStrSupport)
 
399
                vars.Append(wxT(", jstconnstr=''"));
 
400
        }
 
401
        if (rbxKind->GetSelection() != kind)
 
402
        {
235
403
            if (!vars.IsEmpty())
236
404
                vars.Append(wxT(", "));
237
405
            vars.Append(wxT("jstkind=") + qtDbString(kind));
278
446
        else
279
447
                return true;
280
448
}
 
449
 
 
450
void dlgStep::OnSelectDatabase(wxCommandEvent &ev)
 
451
{
 
452
    dlgSelectDatabase dlgSD(this, wxID_ANY);
 
453
    if (dlgSD.ShowModal() == wxID_OK)
 
454
    {
 
455
        wxString strConnStr = dlgSD.getConnInfo();
 
456
        if (!strConnStr.IsEmpty())
 
457
            txtConnStr->SetValue(strConnStr);
 
458
    }
 
459
}
 
460
 
 
461
void dlgStep::OnSelRemoteConn(wxCommandEvent& ev)
 
462
{
 
463
    if (rbRemoteConn->GetValue())
 
464
    {
 
465
        cbDatabase->Enable(false);
 
466
        btnSelDatabase->Enable(true);
 
467
        txtConnStr->Enable(true);
 
468
    }
 
469
    dlgProperty::OnChange(ev);
 
470
}
 
471
 
 
472
void dlgStep::OnSelLocalConn(wxCommandEvent& ev)
 
473
{
 
474
    if (rbLocalConn->GetValue())
 
475
    {
 
476
        cbDatabase->Enable(true);
 
477
        btnSelDatabase->Enable(false);
 
478
        txtConnStr->Enable(false);
 
479
    }
 
480
    dlgProperty::OnChange(ev);
 
481
}
 
482
 
 
483