~ubuntu-branches/ubuntu/wily/tora/wily-proposed

« back to all changes in this revision

Viewing changes to src/tobrowserconstraint.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Meskes
  • Date: 2009-04-07 13:16:05 UTC
  • mfrom: (1.2.7 upstream) (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090407131605-u422yigfv7jgg0l0
Tags: 2.0.0-3
* Cleaned up packaging a little bit.
* Added homepage information to control file.
* Bumped Standards-Version to 3.8.1.
* Released to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****
2
 
*
3
 
* TOra - An Oracle Toolkit for DBA's and developers
4
 
* Copyright (C) 2003-2005 Quest Software, Inc
5
 
* Portions Copyright (C) 2005 Other Contributors
6
 
7
 
* This program is free software; you can redistribute it and/or
8
 
* modify it under the terms of the GNU General Public License
9
 
* as published by the Free Software Foundation;  only version 2 of
10
 
* the License is valid for this program.
11
 
12
 
* This program is distributed in the hope that it will be useful,
13
 
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
* GNU General Public License for more details.
16
 
17
 
* You should have received a copy of the GNU General Public License
18
 
* along with this program; if not, write to the Free Software
19
 
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
 
*
21
 
*      As a special exception, you have permission to link this program
22
 
*      with the Oracle Client libraries and distribute executables, as long
23
 
*      as you follow the requirements of the GNU GPL in regard to all of the
24
 
*      software in the executable aside from Oracle client libraries.
25
 
*
26
 
*      Specifically you are not permitted to link this program with the
27
 
*      Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
28
 
*      And you are not permitted to distribute binaries compiled against
29
 
*      these libraries without written consent from Quest Software, Inc.
30
 
*      Observe that this does not disallow linking to the Qt Free Edition.
31
 
*
32
 
*      You may link this product with any GPL'd Qt library such as Qt/Free
33
 
*
34
 
* All trademarks belong to their respective owners.
35
 
*
36
 
*****/
 
1
 
 
2
/* BEGIN_COMMON_COPYRIGHT_HEADER
 
3
 *
 
4
 * TOra - An Oracle Toolkit for DBA's and developers
 
5
 * 
 
6
 * Shared/mixed copyright is held throughout files in this product
 
7
 * 
 
8
 * Portions Copyright (C) 2000-2001 Underscore AB
 
9
 * Portions Copyright (C) 2003-2005 Quest Software, Inc.
 
10
 * Portions Copyright (C) 2004-2008 Numerous Other Contributors
 
11
 * 
 
12
 * This program is free software; you can redistribute it and/or
 
13
 * modify it under the terms of the GNU General Public License
 
14
 * as published by the Free Software Foundation;  only version 2 of
 
15
 * the License is valid for this program.
 
16
 * 
 
17
 * This program is distributed in the hope that it will be useful,
 
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
 * GNU General Public License for more details.
 
21
 * 
 
22
 * You should have received a copy of the GNU General Public License
 
23
 * along with this program; if not, write to the Free Software
 
24
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
25
 * 
 
26
 *      As a special exception, you have permission to link this program
 
27
 *      with the Oracle Client libraries and distribute executables, as long
 
28
 *      as you follow the requirements of the GNU GPL in regard to all of the
 
29
 *      software in the executable aside from Oracle client libraries.
 
30
 * 
 
31
 *      Specifically you are not permitted to link this program with the
 
32
 *      Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
 
33
 *      And you are not permitted to distribute binaries compiled against
 
34
 *      these libraries. 
 
35
 * 
 
36
 *      You may link this product with any GPL'd Qt library.
 
37
 * 
 
38
 * All trademarks belong to their respective owners.
 
39
 *
 
40
 * END_COMMON_COPYRIGHT_HEADER */
37
41
 
38
42
#include "utils.h"
39
43
 
46
50
#include "totableselect.h"
47
51
 
48
52
#include <qapplication.h>
49
 
#include <qbuttongroup.h>
50
53
#include <qcombobox.h>
51
54
#include <qinputdialog.h>
52
55
#include <qlabel.h>
53
56
#include <qlineedit.h>
54
 
#include <qprogressdialog.h>
55
57
#include <qradiobutton.h>
56
58
#include <qtimer.h>
57
 
#include <qwidgetstack.h>
58
 
 
59
 
#include "tobrowserconstraint.moc"
60
 
#include "tobrowserconstraintui.moc"
 
59
 
 
60
#include <QStackedWidget>
 
61
#include <QProgressDialog>
 
62
 
61
63
 
62
64
void toBrowserConstraint::modifyConstraint(toConnection &conn, const QString &owner, const QString &table, QWidget *parent)
63
65
{
69
71
        try
70
72
        {
71
73
            QProgressDialog prog(tr("Performing constraint changes"),
72
 
                                 tr("Executing constraint change script"),
 
74
                                 tr("Stop"),
 
75
                                 0,
73
76
                                 statements.size(),
74
 
                                 &dialog, "progress", true);
75
 
            prog.setCaption(tr("Performing constraint changes"));
 
77
                                 &dialog);
 
78
            prog.setWindowTitle(tr("Performing constraint changes"));
76
79
            for (std::list<toSQLParse::statement>::iterator j = statements.begin();j != statements.end();j++)
77
80
            {
78
81
                QString sql = toSQLParse::indentStatement(*j, conn);
82
85
                if (i >= 0)
83
86
                    conn.execute(sql.mid(0, i + 1));
84
87
                qApp->processEvents();
85
 
                if (prog.wasCancelled())
86
 
                    throw tr("Cancelled ongoing constraint modification, constraints might be corrupt");
 
88
                if (prog.wasCanceled())
 
89
                    throw tr("Canceled ongoing constraint modification, constraints might be corrupt");
87
90
            }
88
91
        }
89
92
        TOCATCH
91
94
}
92
95
 
93
96
toBrowserConstraint::toBrowserConstraint(toConnection &conn, const QString &owner, const QString &table, QWidget *parent, const char *name)
94
 
        : toBrowserConstraintUI(parent, name, true), toConnectionWidget(conn, this), Extractor(conn, NULL)
 
97
        : QDialog(parent), toConnectionWidget(conn, this), Extractor(conn, NULL)
95
98
{
 
99
    setObjectName(name);
 
100
    setModal(true);
 
101
 
 
102
    setupUi(this);
96
103
    Extractor.setIndexes(false);
97
104
    Extractor.setConstraints(true);
98
105
    Extractor.setPrompt(false);
122
129
{
123
130
    try
124
131
    {
125
 
        QStringList parts = QStringList::split(".", table);
 
132
        QStringList parts = table.split(".");
126
133
        if (parts.size() > 1)
127
134
        {
128
135
            Owner = connection().unQuote(parts[0]);
173
180
        }
174
181
        Name->clear();
175
182
        for (std::map<QString, QString>::iterator i = Constraints.begin();i != Constraints.end();i++)
176
 
            Name->insertItem((*i).first);
 
183
            Name->addItem((*i).first);
177
184
 
178
185
        SourceColList->changeParams(Owner, Table);
179
186
        UniqueColList->changeParams(Owner, Table);
185
192
            for (std::list<toConnection::objectName>::iterator i = objects.begin();i != objects.end();i++)
186
193
            {
187
194
                if ((*i).Type == "TABLE" && (*i).Owner == Owner)
188
 
                    ReferTable->insertItem((*i).Name);
 
195
                    ReferTable->addItem((*i).Name);
189
196
            }
190
197
        }
191
198
 
267
274
    if (Table.isEmpty())
268
275
        return ;
269
276
    bool ok = false;
270
 
    QString name = QInputDialog::getText(tr("Enter new constraint name"),
 
277
    QString name = QInputDialog::getText(this,
 
278
                                         tr("Enter new constraint name"),
271
279
                                         tr("Enter name of new constraint."),
272
 
                                         QLineEdit::Normal, QString::null, &ok, this);
 
280
                                         QLineEdit::Normal,
 
281
                                         QString::null,
 
282
                                         &ok);
273
283
    if (ok)
274
284
    {
275
 
        Name->insertItem(name);
276
 
        Name->setCurrentItem(Name->count() - 1);
 
285
        Name->addItem(name);
 
286
        Name->setCurrentIndex(Name->count() - 1);
277
287
        changeConstraint();
278
288
    }
279
289
}
284
294
    {
285
295
        Constraints.erase(Current);
286
296
        Current = QString::null;
287
 
        Name->removeItem(Name->currentItem());
 
297
        Name->removeItem(Name->currentIndex());
288
298
        changeConstraint();
289
299
    }
290
300
}
307
317
        return ;
308
318
    Type->setEnabled(false);
309
319
 
310
 
    QString type = (*i).String.upper();
 
320
    QString type = (*i).String.toUpper();
311
321
    i++;
312
322
    if (type == "FOREIGN")
313
323
    {
314
 
        WidgetStack->raiseWidget(ReferentialPage);
315
 
        Type->setCurrentItem(0);
 
324
        WidgetStack->setCurrentIndex(WidgetStack->indexOf(ReferentialPage));
 
325
        Type->setCurrentIndex(0);
316
326
        if (i == statement.subTokens().end())
317
327
            return ;
318
328
 
332
342
        i++;  // Refered table finally
333
343
        if (i == statement.subTokens().end())
334
344
            return ;
335
 
        ReferTable->setCurrentText((*i).String);
 
345
        ReferTable->setItemText(ReferTable->currentIndex(), (*i).String);
336
346
        changeRefered();
337
347
        while (i != statement.subTokens().end() && (*i).Type != toSQLParse::statement::List)
338
348
            i++;
341
351
    }
342
352
    else if (type == "PRIMARY" || type == "UNIQUE")
343
353
    {
344
 
        WidgetStack->raiseWidget(PrimaryPage);
345
 
        Type->setCurrentItem(2);
 
354
        WidgetStack->setCurrentIndex(WidgetStack->indexOf(PrimaryPage));
 
355
        Type->setCurrentIndex(2);
346
356
        Primary->setChecked(type == "PRIMARY");
347
357
        Unique->setChecked(type == "UNIQUE");
348
358
        while (i != statement.subTokens().end() && (*i).Type != toSQLParse::statement::List)
352
362
    }
353
363
    else if (type == "CHECK")
354
364
    {
355
 
        WidgetStack->raiseWidget(CheckPage);
356
 
        Type->setCurrentItem(1);
 
365
        WidgetStack->setCurrentIndex(WidgetStack->indexOf(CheckPage));
 
366
        Type->setCurrentIndex(1);
357
367
        while (i != statement.subTokens().end() && (*i).Type != toSQLParse::statement::List)
358
368
            i++;
359
369
        if (i != statement.subTokens().end())
366
376
    if (!Current.isEmpty())
367
377
    {
368
378
        QString newDefinition;
369
 
        if (WidgetStack->visibleWidget() == ReferentialPage)
 
379
        if (WidgetStack->currentIndex() == WidgetStack->indexOf(ReferentialPage))
370
380
        {
371
381
            QString table = ReferTable->currentText();
372
382
            QString sourceCols = SourceColumns->text();
374
384
            if (!table.isEmpty() && !sourceCols.isEmpty() && !destinCols.isEmpty())
375
385
                newDefinition = "FOREIGN KEY (" + sourceCols + ") REFERENCES " + table + " (" + destinCols + ")";
376
386
        }
377
 
        else if (WidgetStack->visibleWidget() == PrimaryPage)
 
387
        else if (WidgetStack->currentIndex() == WidgetStack->indexOf(PrimaryPage))
378
388
        {
379
389
            QString columns = UniqueCols->text();
380
390
            if (!columns.isEmpty())
381
391
                newDefinition = (Primary->isChecked() ? "PRIMARY KEY (" : "UNIQUE (") + columns + ")";
382
392
        }
383
 
        else if (WidgetStack->visibleWidget() == CheckPage)
 
393
        else if (WidgetStack->currentIndex() == WidgetStack->indexOf(CheckPage))
384
394
        {
385
395
            QString checkCondition = CheckCondition->text();
386
396
            if (!checkCondition.isEmpty())
402
412
 
403
413
void toBrowserConstraint::changeRefered(void)
404
414
{
405
 
    QStringList parts = QStringList::split(".", ReferTable->currentText());
 
415
    QStringList parts = ReferTable->currentText().split(".");
406
416
    if (parts.size() > 1)
407
417
        ReferColList->changeParams(parts[0], parts[1]);
408
418
    else
414
424
    switch (type)
415
425
    {
416
426
    case 0:
417
 
        WidgetStack->raiseWidget(ReferentialPage);
 
427
        WidgetStack->setCurrentIndex(WidgetStack->indexOf(ReferentialPage));
418
428
        break;
419
429
    case 1:
420
 
        WidgetStack->raiseWidget(CheckPage);
 
430
        WidgetStack->setCurrentIndex(WidgetStack->indexOf(CheckPage));
421
431
        break;
422
432
    case 2:
423
 
        WidgetStack->raiseWidget(PrimaryPage);
 
433
        WidgetStack->setCurrentIndex(WidgetStack->indexOf(PrimaryPage));
424
434
        break;
425
435
    }
426
436
}