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

« back to all changes in this revision

Viewing changes to toscript.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Albin Tonnerre
  • Date: 2007-05-29 13:13:36 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529131336-85ygaddivvmkd3xc
Tags: 1.3.21pre22-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
  - debian/rules: call dh_iconcache
  - Remove g++ build dependency
* Modify Maintainer value to match Debian-Maintainer-Field Spec

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
 
*****/
37
 
 
38
 
#include "utils.h"
39
 
 
40
 
#include "toconf.h"
41
 
#include "toextract.h"
42
 
#include "tofilesize.h"
43
 
#include "tohighlightedtext.h"
44
 
#include "tomain.h"
45
 
#include "toreport.h"
46
 
#include "toresultview.h"
47
 
#include "toscript.h"
48
 
#include "toscriptui.h"
49
 
#include "tosql.h"
50
 
#include "totextview.h"
51
 
#include "totool.h"
52
 
#include "toworksheet.h"
53
 
 
54
 
#ifdef TO_HAS_KPRINT
55
 
#include <kfiledialog.h>
56
 
#endif
57
 
 
58
 
#include <qcheckbox.h>
59
 
#include <qcombobox.h>
60
 
#include <qdir.h>
61
 
#include <qfiledialog.h>
62
 
#include <qlabel.h>
63
 
#include <qlayout.h>
64
 
#include <qlineedit.h>
65
 
#include <qmessagebox.h>
66
 
#include <qpushbutton.h>
67
 
#include <qradiobutton.h>
68
 
#include <qregexp.h>
69
 
#include <qspinbox.h>
70
 
#include <qsplitter.h>
71
 
#include <qtabwidget.h>
72
 
#include <qtextview.h>
73
 
#include <qtoolbar.h>
74
 
#include <qtoolbutton.h>
75
 
 
76
 
#include "toscript.moc"
77
 
#include "toscriptui.moc"
78
 
 
79
 
#include "icons/execute.xpm"
80
 
#include "icons/toscript.xpm"
81
 
 
82
 
static toSQL SQLObjectListMySQL("toScript:ExtractObject",
83
 
                                "TOAD 1,0,0 SHOW DATABASES",
84
 
                                "Extract objects available to extract from the database, "
85
 
                                "should have same columns",
86
 
                                "3.23",
87
 
                                "MySQL");
88
 
 
89
 
static toSQL SQLObjectList("toScript:ExtractObject",
90
 
                           "SELECT *\n"
91
 
                           "  FROM (SELECT 'TABLESPACE',tablespace_name,NULL\n"
92
 
                           "   FROM sys.dba_tablespaces\n"
93
 
                           " UNION\n"
94
 
                           " SELECT 'ROLE',role,NULL\n"
95
 
                           "   FROM sys.dba_roles\n"
96
 
                           " UNION\n"
97
 
                           " SELECT 'PUBLIC',NULL,NULL\n"
98
 
                           "   FROM dual\n"
99
 
                           " UNION\n"
100
 
                           " SELECT username,NULL,NULL\n"
101
 
                           "   FROM sys.all_users)\n"
102
 
                           "  ORDER BY 1,2,3",
103
 
                           "",
104
 
                           "0801");
105
 
 
106
 
static toSQL SQLUserObjectList("toScript:UserExtractObject",
107
 
                               "SELECT owner,object_type,object_name\n"
108
 
                               "  FROM sys.all_objects\n"
109
 
                               " WHERE object_type IN ('VIEW','TABLE','TYPE','SEQUENCE','PACKAGE',\n"
110
 
                               "                'PACKAGE BODY','FUNCTION','PROCEDURE')\n"
111
 
                               " ORDER BY 1,2,3",
112
 
                               "Extract objects available to extract from the database if you "
113
 
                               "don't have admin access, should have same columns");
114
 
 
115
 
static toSQL SQLPublicSynonymList("toScript:PublicSynonyms",
116
 
                                  "SELECT synonym_name\n"
117
 
                                  "  FROM sys.all_synonyms WHERE owner = 'PUBLIC'\n"
118
 
                                  " ORDER BY 1",
119
 
                                  "Extract all public synonyms from database");
120
 
 
121
 
static toSQL SQLUserObjectsMySQL("toScript:UserObjects",
122
 
                                 "SHOW TABLES FROM :own<noquote>",
123
 
                                 "Get the objects available for a user, must have same columns and binds",
124
 
                                 "3.23",
125
 
                                 "MySQL");
126
 
 
127
 
static toSQL SQLUserObjects("toScript:UserObjects",
128
 
                            "SELECT *\n"
129
 
                            "  FROM (SELECT 'DATABASE LINK',db_link\n"
130
 
                            "          FROM sys.all_db_links\n"
131
 
                            "         WHERE owner = :own<char[101]>\n"
132
 
                            "        UNION\n"
133
 
                            "        SELECT object_type,object_name\n"
134
 
                            "          FROM sys.all_objects\n"
135
 
                            "         WHERE object_type IN ('VIEW','TYPE','SEQUENCE','PACKAGE',\n"
136
 
                            "                               'PACKAGE BODY','FUNCTION','PROCEDURE','TRIGGER')\n"
137
 
                            "           AND owner = :own<char[101]>\n"
138
 
                            "         UNION\n"
139
 
                            "        SELECT 'TABLE',table_name\n"
140
 
                            "          FROM sys.all_tables\n"
141
 
                            "         WHERE temporary != 'Y' AND secondary = 'N' AND iot_name IS NULL\n"
142
 
                            "           AND owner = :own<char[101]>\n"
143
 
                            "        UNION\n"
144
 
                            "        SELECT 'MATERIALIZED TABLE',mview_name AS object\n"
145
 
                            "          FROM sys.all_mviews\n"
146
 
                            "         WHERE owner = :own<char[101]>)\n"
147
 
                            " ORDER BY 1,2",
148
 
                            "");
149
 
 
150
 
static toSQL SQLUserObjects7("toScript:UserObjects",
151
 
                             "SELECT *\n"
152
 
                             "  FROM (SELECT 'DATABASE LINK',db_link\n"
153
 
                             "          FROM sys.all_db_links\n"
154
 
                             "         WHERE owner = :own<char[101]>\n"
155
 
                             "        UNION\n"
156
 
                             "        SELECT object_type,object_name\n"
157
 
                             "          FROM sys.all_objects\n"
158
 
                             "         WHERE object_type IN ('VIEW','TYPE','SEQUENCE','PACKAGE',\n"
159
 
                             "                               'PACKAGE BODY','FUNCTION','PROCEDURE','TRIGGER')\n"
160
 
                             "           AND owner = :own<char[101]>\n"
161
 
                             "         UNION\n"
162
 
                             "        SELECT 'TABLE',table_name\n"
163
 
                             "          FROM sys.all_tables\n"
164
 
                             "         WHERE temporary != 'Y' AND secondary = 'N'\n"
165
 
                             "           AND owner = :own<char[101]>\n"
166
 
                             "        UNION\n"
167
 
                             "        SELECT 'MATERIALIZED TABLE',mview_name AS object\n"
168
 
                             "          FROM sys.all_mviews\n"
169
 
                             "         WHERE owner = :own<char[101]>)\n"
170
 
                             " ORDER BY 1,2",
171
 
                             "",
172
 
                             "0703");
173
 
 
174
 
static toSQL SQLSchemasMySQL("toScript:ExtractSchema",
175
 
                             "SHOW DATABASES",
176
 
                             "Get usernames available in database, must have same columns",
177
 
                             "3.23",
178
 
                             "MySQL");
179
 
 
180
 
static toSQL SQLSchemas("toScript:ExtractSchema",
181
 
                        "SELECT username FROM sys.all_users ORDER BY username",
182
 
                        "");
183
 
 
184
 
class toScriptTool : public toTool
185
 
{
186
 
protected:
187
 
    virtual const char **pictureXPM(void)
188
 
    {
189
 
        return const_cast<const char**>(toscript_xpm);
190
 
    }
191
 
public:
192
 
    toScriptTool()
193
 
            : toTool(310, "DB Extraction/Compare/Search")
194
 
    { }
195
 
    virtual const char *menuItem()
196
 
    {
197
 
        return "DB Extraction/Compare/Search";
198
 
    }
199
 
    virtual const char *toolbarTip()
200
 
    {
201
 
        return "DB or schema extraction, compare and search";
202
 
    }
203
 
    virtual bool canHandle(toConnection &conn)
204
 
    {
205
 
        try
206
 
        {
207
 
            return toExtract::canHandle(conn) && !toSQL::string(SQLObjectList, conn).isEmpty();
208
 
        }
209
 
        catch (...)
210
 
        {
211
 
            return false;
212
 
        }
213
 
    }
214
 
    virtual QWidget *toolWindow(QWidget *main, toConnection &connection)
215
 
    {
216
 
        return new toScript(main, connection);
217
 
    }
218
 
};
219
 
 
220
 
static toScriptTool ScriptTool;
221
 
 
222
 
toScript::toScript(QWidget *parent, toConnection &connection)
223
 
        : toToolWidget(ScriptTool, "script.html", parent, connection)
224
 
{
225
 
    QToolBar *toolbar = toAllocBar(this, tr("Extraction and Compare"));
226
 
 
227
 
    new QToolButton(QPixmap(const_cast<const char**>(execute_xpm)),
228
 
                    tr("Perform defined extraction"),
229
 
                    tr("Perform defined extraction"),
230
 
                    this, SLOT(execute(void)),
231
 
                    toolbar);
232
 
    toolbar->setStretchableWidget(new QLabel(toolbar, TO_KDE_TOOLBAR_WIDGET));
233
 
 
234
 
    ScriptUI = new toScriptUI(this);
235
 
 
236
 
    QSplitter *hsplitter = new QSplitter(Horizontal, ScriptUI->DifferenceTab);
237
 
    QVBox *box = new QVBox(ScriptUI->ResultTab);
238
 
    Worksheet = new toWorksheet(box, connection);
239
 
    SearchList = new toListView(box);
240
 
    SearchList->addColumn(tr("Search result"));
241
 
    SearchList->setRootIsDecorated(true);
242
 
    SearchList->setSorting(0);
243
 
    SearchList->hide();
244
 
    Report = new toTextView(box);
245
 
    Report->hide();
246
 
 
247
 
    DropList = new toListView(hsplitter);
248
 
    DropList->addColumn(tr("Dropped"));
249
 
    DropList->setRootIsDecorated(true);
250
 
    DropList->setSorting(0);
251
 
    CreateList = new toListView(hsplitter);
252
 
    CreateList->addColumn(tr("Created"));
253
 
    CreateList->setRootIsDecorated(true);
254
 
    CreateList->setSorting(0);
255
 
    ScriptUI->Tabs->setTabEnabled(ScriptUI->ResultTab, false);
256
 
    ScriptUI->Tabs->setTabEnabled(ScriptUI->DifferenceTab, false);
257
 
 
258
 
    connect(SearchList, SIGNAL(clicked(QListViewItem *)), this, SLOT(keepOn(QListViewItem *)));
259
 
    connect(DropList, SIGNAL(clicked(QListViewItem *)), this, SLOT(keepOn(QListViewItem *)));
260
 
    connect(CreateList, SIGNAL(clicked(QListViewItem *)), this, SLOT(keepOn(QListViewItem *)));
261
 
 
262
 
    QGridLayout *layout = new QGridLayout(ScriptUI->ResultTab);
263
 
    layout->addWidget(box, 0, 0);
264
 
    layout = new QGridLayout(ScriptUI->DifferenceTab);
265
 
    layout->addWidget(hsplitter, 0, 0);
266
 
 
267
 
    ScriptUI->Initial->setTitle(tr("&Initial"));
268
 
    ScriptUI->Limit->setTitle(tr("&Limit"));
269
 
    ScriptUI->Next->setTitle(tr("&Next"));
270
 
    connect(ScriptUI->ModeGroup, SIGNAL(clicked(int)), this, SLOT(changeMode(int)));
271
 
    ScriptUI->Tabs->setTabEnabled(ScriptUI->ResizeTab, false);
272
 
    ScriptUI->SourceObjects->setSorting(0);
273
 
    ScriptUI->SourceObjects->setResizeMode(QListView::AllColumns);
274
 
    ScriptUI->DestinationObjects->setSorting(0);
275
 
    ScriptUI->DestinationObjects->setResizeMode(QListView::AllColumns);
276
 
 
277
 
    // Remove when migrate and resize is implemented
278
 
#if 1
279
 
 
280
 
    ScriptUI->Migrate->hide();
281
 
#endif
282
 
 
283
 
    int def = 0;
284
 
    std::list<QString> cons = toMainWidget()->connections();
285
 
    int i = 0;
286
 
    while (cons.size() > 0)
287
 
    {
288
 
        QString str = toShift(cons);
289
 
        if (str == connection.description() && def == 0)
290
 
            def = i;
291
 
        i++;
292
 
        ScriptUI->SourceConnection->insertItem(str);
293
 
        ScriptUI->DestinationConnection->insertItem(str);
294
 
    }
295
 
    ScriptUI->SourceConnection->setCurrentItem(def);
296
 
    changeSource(def);
297
 
    changeDestination(def);
298
 
    ScriptUI->DestinationConnection->setCurrentItem(def);
299
 
 
300
 
    connect(ScriptUI->AddButton, SIGNAL(clicked()), this, SLOT(newSize()));
301
 
    connect(ScriptUI->Remove, SIGNAL(clicked()), this, SLOT(removeSize()));
302
 
 
303
 
    connect(ScriptUI->SourceConnection, SIGNAL(activated(int)), this, SLOT(changeSource(int)));
304
 
    connect(ScriptUI->DestinationConnection, SIGNAL(activated(int)), this, SLOT(changeDestination(int)));
305
 
    connect(ScriptUI->SourceSchema, SIGNAL(activated(int)), this, SLOT(changeSourceSchema(int)));
306
 
    connect(ScriptUI->DestinationSchema, SIGNAL(activated(int)), this, SLOT(changeDestinationSchema(int)));
307
 
    connect(ScriptUI->SourceObjects, SIGNAL(clicked(QListViewItem *)), this, SLOT(objectClicked(QListViewItem *)));
308
 
    connect(ScriptUI->DestinationObjects, SIGNAL(clicked(QListViewItem *)), this, SLOT(objectClicked(QListViewItem *)));
309
 
    connect(ScriptUI->Browse, SIGNAL(clicked()), this, SLOT(browseFile()));
310
 
 
311
 
    connect(ScriptUI->SourceObjects, SIGNAL(expanded(QListViewItem *)),
312
 
            this, SLOT(expandSource(QListViewItem *)));
313
 
    connect(ScriptUI->DestinationObjects, SIGNAL(expanded(QListViewItem *)),
314
 
            this, SLOT(expandDestination(QListViewItem *)));
315
 
 
316
 
    connect(toMainWidget(), SIGNAL(addedConnection(const QString &)),
317
 
            this, SLOT(addConnection(const QString &)));
318
 
    connect(toMainWidget(), SIGNAL(removedConnection(const QString &)),
319
 
            this, SLOT(delConnection(const QString &)));
320
 
 
321
 
    ScriptUI->Schema->setCurrentItem(0);
322
 
    setFocusProxy(ScriptUI->Tabs);
323
 
}
324
 
 
325
 
void toScript::delConnection(const QString &name)
326
 
{
327
 
    for (int i = 0;i < ScriptUI->SourceConnection->count();i++)
328
 
    {
329
 
        if (ScriptUI->SourceConnection->text(i) == name)
330
 
        {
331
 
            ScriptUI->SourceConnection->removeItem(i);
332
 
            break;
333
 
        }
334
 
    }
335
 
    for (int j = 0;j < ScriptUI->DestinationConnection->count();j++)
336
 
    {
337
 
        if (ScriptUI->DestinationConnection->text(j) == name)
338
 
        {
339
 
            ScriptUI->DestinationConnection->removeItem(j);
340
 
            break;
341
 
        }
342
 
    }
343
 
}
344
 
 
345
 
void toScript::addConnection(const QString &name)
346
 
{
347
 
    ScriptUI->SourceConnection->insertItem(name);
348
 
    ScriptUI->DestinationConnection->insertItem(name);
349
 
}
350
 
 
351
 
toScript::~toScript()
352
 
{}
353
 
 
354
 
std::list<QString> toScript::createObjectList(QListView *source)
355
 
{
356
 
    std::list<QString> lst;
357
 
 
358
 
    std::list<QString> otherGlobal;
359
 
    std::list<QString> profiles;
360
 
    std::list<QString> roles;
361
 
    std::list<QString> tableSpace;
362
 
    std::list<QString> tables;
363
 
    std::list<QString> userOther;
364
 
    std::list<QString> userViews;
365
 
    std::list<QString> users;
366
 
 
367
 
    QListViewItem *next = NULL;
368
 
    for (QListViewItem *item = source->firstChild();item;item = next)
369
 
    {
370
 
        toResultViewCheck * chk = dynamic_cast<toResultViewCheck *>(item);
371
 
 
372
 
        if (chk && chk->isEnabled())
373
 
        {
374
 
            QString name = chk->text(0);
375
 
            QString type = chk->text(1);
376
 
            QString user = chk->text(2);
377
 
            if (!user.isEmpty())
378
 
            {
379
 
                if (chk->isOn() && chk->isEnabled())
380
 
                {
381
 
                    QString line;
382
 
                    if (type == QString::fromLatin1("TABLE"))
383
 
                    {
384
 
                        line = user;
385
 
                        line += QString::fromLatin1(".");
386
 
                        line += name;
387
 
                        toPush(tables, line);
388
 
                    }
389
 
                    else
390
 
                    {
391
 
                        line = type;
392
 
                        line += QString::fromLatin1(":");
393
 
                        line += user;
394
 
                        line += QString::fromLatin1(".");
395
 
                        line += name;
396
 
                        if (type == QString::fromLatin1("VIEW"))
397
 
                            toPush(userViews, line);
398
 
                        else
399
 
                            toPush(userOther, line);
400
 
                    }
401
 
                }
402
 
            }
403
 
            else if (!type.isEmpty())
404
 
            {
405
 
                if (chk->isOn() && chk->isEnabled())
406
 
                {
407
 
                    QString line = type;
408
 
                    line += QString::fromLatin1(":");
409
 
                    line += name;
410
 
                    if (type == QString::fromLatin1("TABLESPACE"))
411
 
                        toPush(tableSpace, line);
412
 
                    else if (type == QString::fromLatin1("PROFILE"))
413
 
                        toPush(profiles, line);
414
 
                    else if (type == QString::fromLatin1("ROLE"))
415
 
                        toPush(roles, name);
416
 
                    else if (type == QString::fromLatin1("USER"))
417
 
                        toPush(users, name);
418
 
                    else
419
 
                        toPush(otherGlobal, line);
420
 
                }
421
 
            }
422
 
        }
423
 
 
424
 
        if (item->firstChild() && chk && chk->isEnabled())
425
 
            next = item->firstChild();
426
 
        else if (item->nextSibling())
427
 
            next = item->nextSibling();
428
 
        else
429
 
        {
430
 
            next = item;
431
 
            do
432
 
            {
433
 
                next = next->parent();
434
 
            }
435
 
            while (next && !next->nextSibling());
436
 
            if (next)
437
 
                next = next->nextSibling();
438
 
        }
439
 
    }
440
 
 
441
 
    if (ScriptUI->IncludeDDL->isChecked())
442
 
    {
443
 
        lst.insert(lst.end(), tableSpace.begin(), tableSpace.end());
444
 
        lst.insert(lst.end(), profiles.begin(), profiles.end());
445
 
        lst.insert(lst.end(), otherGlobal.begin(), otherGlobal.end());
446
 
        for_each(roles.begin(), roles.end(), PrefixString(lst, QString::fromLatin1("ROLE:")));
447
 
        for_each(users.begin(), users.end(), PrefixString(lst, QString::fromLatin1("USER:")));
448
 
        for_each(tables.begin(), tables.end(), PrefixString(lst, QString::fromLatin1("TABLE FAMILY:")));
449
 
        lst.insert(lst.end(), userViews.begin(), userViews.end());
450
 
        lst.insert(lst.end(), userOther.begin(), userOther.end());
451
 
    }
452
 
    for_each(tables.begin(), tables.end(), PrefixString(lst, QString::fromLatin1("TABLE CONTENTS:")));
453
 
    if (ScriptUI->IncludeDDL->isChecked())
454
 
    {
455
 
        for_each(tables.begin(), tables.end(), PrefixString(lst, QString::fromLatin1("TABLE REFERENCES:")));
456
 
        for_each(roles.begin(), roles.end(), PrefixString(lst, QString::fromLatin1("ROLE GRANTS:")));
457
 
        for_each(users.begin(), users.end(), PrefixString(lst, QString::fromLatin1("USER GRANTS:")));
458
 
    }
459
 
    return lst;
460
 
}
461
 
 
462
 
void toScript::execute(void)
463
 
{
464
 
    try
465
 
    {
466
 
        int mode;
467
 
        if (ScriptUI->Compare->isChecked())
468
 
            mode = 0;
469
 
        else if (ScriptUI->Extract->isChecked())
470
 
            mode = 1;
471
 
        else if (ScriptUI->Migrate->isChecked())
472
 
            mode = 2;
473
 
        else if (ScriptUI->Search->isChecked())
474
 
            mode = 3;
475
 
        else if (ScriptUI->Report->isChecked())
476
 
            mode = 4;
477
 
        else
478
 
        {
479
 
            toStatusMessage(tr("No mode selected"));
480
 
            return ;
481
 
        }
482
 
 
483
 
        std::list<QString> sourceObjects = createObjectList(ScriptUI->SourceObjects);
484
 
 
485
 
        std::list<QString> sourceDescription;
486
 
        std::list<QString> destinationDescription;
487
 
        QString script;
488
 
 
489
 
        toExtract source(toMainWidget()->connection(ScriptUI->SourceConnection->currentText()), this);
490
 
        setupExtract(source);
491
 
        switch (mode)
492
 
        {
493
 
        case 1:
494
 
            if (ScriptUI->OutputTab->isChecked())
495
 
                script += source.create(sourceObjects);
496
 
            else if (ScriptUI->OutputFile->isChecked())
497
 
            {
498
 
                if (ScriptUI->Filename->text().isEmpty())
499
 
                    throw tr("No filename specified");
500
 
 
501
 
                QFile file(ScriptUI->Filename->text());
502
 
                if (file.exists())
503
 
                {
504
 
                    if (TOMessageBox::warning(this, tr("Write over file?"),
505
 
                                              tr("The file %1 already exists,\nare you sure you want to continue and write over it?").arg(ScriptUI->Filename->text()),
506
 
                                              tr("&Yes"), tr("&Cancel"), QString::null, 0) != 0)
507
 
                    {
508
 
                        return ;
509
 
                    }
510
 
                }
511
 
                file.open(IO_WriteOnly);
512
 
 
513
 
                if (file.status() != IO_Ok)
514
 
                    throw tr("Couldn't open file %1").arg(file.name());
515
 
 
516
 
                QTextStream stream(&file);
517
 
                source.create(stream, sourceObjects);
518
 
 
519
 
                if (file.status() != IO_Ok)
520
 
                    throw tr("Error writing to file %1").arg(file.name());
521
 
 
522
 
                script = tr("-- Script generated to file %1 successfully").arg(ScriptUI->Filename->text());
523
 
            }
524
 
            else if (ScriptUI->OutputDir->isChecked())
525
 
            {
526
 
                if (ScriptUI->Filename->text().isEmpty())
527
 
                    throw tr("No filename specified");
528
 
 
529
 
                QFile file(ScriptUI->Filename->text() + QDir::separator() + "script.sql");
530
 
                file.open(IO_WriteOnly);
531
 
 
532
 
                if (file.status() != IO_Ok)
533
 
                    throw QString(tr("Couldn't open file %1")).arg(file.name());
534
 
 
535
 
                QTextStream stream(&file);
536
 
 
537
 
                stream << tr("rem Master script for DDL reverse engineering by TOra\n"
538
 
                             "\n");
539
 
 
540
 
                QFile pfile(ScriptUI->Filename->text() + QDir::separator() + "script.tpr");
541
 
                pfile.open(IO_WriteOnly);
542
 
 
543
 
                if (pfile.status() != IO_Ok)
544
 
                    throw QString(tr("Couldn't open file %1")).arg(pfile.name());
545
 
 
546
 
                QTextStream pstream(&pfile);
547
 
 
548
 
                QRegExp repl("\\W+");
549
 
                for (std::list<QString>::iterator i = sourceObjects.begin();i != sourceObjects.end();i++)
550
 
                {
551
 
                    std::list<QString> t;
552
 
                    t.insert(t.end(), *i);
553
 
                    QString fn = *i;
554
 
                    fn.replace(repl, "_");
555
 
                    fn += ".sql";
556
 
                    stream << "@" << fn << "\n";
557
 
 
558
 
                    QFile tf(ScriptUI->Filename->text() + QDir::separator() + fn);
559
 
                    tf.open(IO_WriteOnly);
560
 
                    pstream << tf.name() << "\n";
561
 
 
562
 
                    if (tf.status() != IO_Ok)
563
 
                        throw QString(tr("Couldn't open file %1")).arg(tf.name());
564
 
 
565
 
                    QTextStream ts(&tf);
566
 
                    source.create(ts, t);
567
 
 
568
 
                    if (tf.status() != IO_Ok)
569
 
                        throw QString(tr("Error writing to file %1")).arg(tf.name());
570
 
 
571
 
 
572
 
                    script = tr("-- Scripts generate to directory %1 successfully").arg(ScriptUI->Filename->text());
573
 
                    ;
574
 
                }
575
 
 
576
 
                if (file.status() != IO_Ok)
577
 
                    throw QString(tr("Error writing to file %1")).arg(file.name());
578
 
                if (pfile.status() != IO_Ok)
579
 
                    throw QString(tr("Error writing to file %1")).arg(pfile.name());
580
 
            }
581
 
            break;
582
 
        case 0:
583
 
        case 2:
584
 
        case 3:
585
 
        case 4:
586
 
            sourceDescription = source.describe(sourceObjects);
587
 
            break;
588
 
        }
589
 
 
590
 
        if (ScriptUI->Destination->isEnabled())
591
 
        {
592
 
            std::list<QString> destinationObjects = createObjectList(ScriptUI->DestinationObjects);
593
 
            toExtract destination(toMainWidget()->connection(ScriptUI->
594
 
                                  DestinationConnection->
595
 
                                  currentText()), this);
596
 
            setupExtract(destination);
597
 
            switch (mode)
598
 
            {
599
 
            case 0:
600
 
            case 2:
601
 
                destinationDescription = destination.describe(destinationObjects);
602
 
                break;
603
 
            case 1:
604
 
            case 3:
605
 
                throw tr("Destination shouldn't be enabled now, internal error");
606
 
            }
607
 
 
608
 
            std::list<QString> drop;
609
 
            std::list<QString> create;
610
 
 
611
 
            toExtract::srcDst2DropCreate(sourceDescription, destinationDescription,
612
 
                                         drop, create);
613
 
            sourceDescription = drop;
614
 
            destinationDescription = create;
615
 
        }
616
 
        ScriptUI->Tabs->setTabEnabled(ScriptUI->ResultTab, mode == 1 || mode == 2 || mode == 3 || mode == 4);
617
 
        ScriptUI->Tabs->setTabEnabled(ScriptUI->DifferenceTab, mode == 0 || mode == 2);
618
 
        if (!script.isEmpty())
619
 
        {
620
 
            Worksheet->editor()->setText(script);
621
 
            Worksheet->editor()->setFilename(QString::null);
622
 
            Worksheet->editor()->setModified(true);
623
 
        }
624
 
        if (mode == 3)
625
 
        {
626
 
            Worksheet->hide();
627
 
            Report->hide();
628
 
            SearchList->show();
629
 
            QRegExp re(ScriptUI->SearchWord->text(), false);
630
 
            QStringList words(QStringList::split(QRegExp(QString::fromLatin1(" ")),
631
 
                                                 ScriptUI->SearchWord->text().
632
 
                                                 upper().simplifyWhiteSpace()));
633
 
            QString word = ScriptUI->SearchWord->text().upper();
634
 
            int searchMode = 0;
635
 
            if (ScriptUI->AllWords->isChecked())
636
 
                searchMode = 1;
637
 
            else if (ScriptUI->AnyWords->isChecked())
638
 
                searchMode = 2;
639
 
            else if (ScriptUI->RegExp->isChecked())
640
 
                searchMode = 3;
641
 
            else if (ScriptUI->ExactMatch->isChecked())
642
 
                searchMode = 4;
643
 
            std::list<QString> result;
644
 
            for (std::list<QString>::iterator i = sourceDescription.begin();
645
 
                    i != sourceDescription.end();
646
 
                    i++)
647
 
            {
648
 
                QStringList ctx = QStringList::split(QString::fromLatin1("\01"), (*i).upper());
649
 
                switch (searchMode)
650
 
                {
651
 
                case 1:
652
 
                case 2:
653
 
                    {
654
 
                        unsigned int count = 0;
655
 
                        for (unsigned int k = 0;k < words.count();k++)
656
 
                        {
657
 
                            QString s = words[k];
658
 
                            if (ctx.last().contains(s))
659
 
                                count++;
660
 
                        }
661
 
                        if ((searchMode == 2 && count > 0) || (searchMode == 1 && count == words.count()))
662
 
                            result.insert(result.end(), *i);
663
 
                    }
664
 
                    break;
665
 
                case 4:
666
 
                    if (ctx.last() == word)
667
 
                        result.insert(result.end(), *i);
668
 
                    break;
669
 
                case 3:
670
 
                    if (re.match(ctx.last()) >= 0)
671
 
                        result.insert(result.end(), *i);
672
 
                    break;
673
 
                }
674
 
            }
675
 
            fillDifference(result, SearchList);
676
 
        }
677
 
        else if (mode == 4)
678
 
        {
679
 
            Worksheet->hide();
680
 
            SearchList->hide();
681
 
            Report->show();
682
 
            QString res = toGenerateReport(source.connection(), sourceDescription);
683
 
            Report->setText(res);
684
 
            if (ScriptUI->OutputFile->isChecked())
685
 
            {
686
 
                if (ScriptUI->Filename->text().isEmpty())
687
 
                    toStatusMessage(tr("No filename specified"));
688
 
                else
689
 
                {
690
 
                    QFile file(ScriptUI->Filename->text());
691
 
                    file.open(IO_WriteOnly);
692
 
 
693
 
                    if (file.status() != IO_Ok)
694
 
                        toStatusMessage(tr("Couldn't open file %1").arg(file.name()));
695
 
                    else
696
 
                    {
697
 
                        QTextStream stream(&file);
698
 
                        stream << res;
699
 
 
700
 
                        if (file.status() != IO_Ok)
701
 
                            toStatusMessage(tr("Error writing to file %1").arg(file.name()));
702
 
                    }
703
 
                }
704
 
            }
705
 
        }
706
 
        else
707
 
        {
708
 
            Worksheet->show();
709
 
            SearchList->hide();
710
 
            Report->hide();
711
 
            fillDifference(sourceDescription, DropList);
712
 
            fillDifference(destinationDescription, CreateList);
713
 
        }
714
 
        if (mode == 0)
715
 
            ScriptUI->Tabs->showPage(ScriptUI->DifferenceTab);
716
 
        else
717
 
            ScriptUI->Tabs->showPage(ScriptUI->ResultTab);
718
 
    }
719
 
    TOCATCH
720
 
}
721
 
 
722
 
void toScript::fillDifference(std::list<QString> &objects, QListView *view)
723
 
{
724
 
    view->clear();
725
 
    QListViewItem *last = NULL;
726
 
    int lastLevel = 0;
727
 
    QStringList lstCtx;
728
 
    for (std::list<QString>::iterator i = objects.begin();i != objects.end();i++)
729
 
    {
730
 
        //    printf("Adding %s\n",(const char *)*i);
731
 
        QStringList ctx = QStringList::split(QString::fromLatin1("\01"), *i);
732
 
        if (last)
733
 
        {
734
 
            while (last && lastLevel >= int(ctx.count()))
735
 
            {
736
 
                last = last->parent();
737
 
                lastLevel--;
738
 
            }
739
 
            while (last && lastLevel >= 0 && !toCompareLists(lstCtx, ctx, (unsigned int)lastLevel))
740
 
            {
741
 
                last = last->parent();
742
 
                lastLevel--;
743
 
            }
744
 
        }
745
 
        if (lastLevel < 0)
746
 
            throw tr("Internal error, lastLevel < 0");
747
 
        while (lastLevel < int(ctx.count()) - 1)
748
 
        {
749
 
            if (last)
750
 
                last = new toResultViewMLine(last, NULL, ctx[lastLevel]);
751
 
            else
752
 
                last = new toResultViewMLine(view, NULL, ctx[lastLevel]);
753
 
            lastLevel++;
754
 
        }
755
 
        QCheckListItem *item;
756
 
        if (last)
757
 
            item = new toResultViewMLCheck(last, ctx[lastLevel], QCheckListItem::CheckBox);
758
 
        else
759
 
            item = new toResultViewMLCheck(view, ctx[lastLevel], QCheckListItem::CheckBox);
760
 
        last = item;
761
 
        item->setOn(true);
762
 
        lstCtx = ctx;
763
 
        lastLevel++;
764
 
    }
765
 
}
766
 
 
767
 
void toScript::changeConnection(int, bool source)
768
 
{
769
 
    try
770
 
    {
771
 
        QListView *sourceL = NULL;
772
 
        QListView *destinationL = NULL;
773
 
        if (ScriptUI->SourceConnection->currentText() ==
774
 
                ScriptUI->DestinationConnection->currentText())
775
 
        {
776
 
            if (source)
777
 
            {
778
 
                destinationL = ScriptUI->SourceObjects;
779
 
                sourceL = ScriptUI->DestinationObjects;
780
 
            }
781
 
            else
782
 
            {
783
 
                sourceL = ScriptUI->SourceObjects;
784
 
                destinationL = ScriptUI->DestinationObjects;
785
 
            }
786
 
        }
787
 
        if (sourceL && destinationL && sourceL->firstChild())
788
 
        {
789
 
            destinationL->clear();
790
 
            QListViewItem *next = NULL;
791
 
            QListViewItem *parent = NULL;
792
 
            for (QListViewItem *item = sourceL->firstChild();item;item = next)
793
 
            {
794
 
                QListViewItem * lastParent = parent;
795
 
                if (!parent)
796
 
                {
797
 
                    parent = new toResultViewCheck(destinationL, item->text(0),
798
 
                                                   QCheckListItem::CheckBox);
799
 
                    parent->setExpandable(true);
800
 
                }
801
 
                else
802
 
                    parent = new toResultViewCheck(parent, item->text(0),
803
 
                                                   QCheckListItem::CheckBox);
804
 
                parent->setText(1, item->text(1));
805
 
                parent->setText(2, item->text(2));
806
 
                if (item->firstChild())
807
 
                    next = item->firstChild();
808
 
                else if (item->nextSibling())
809
 
                {
810
 
                    next = item->nextSibling();
811
 
                    parent = lastParent;
812
 
                }
813
 
                else
814
 
                {
815
 
                    next = item;
816
 
                    parent = lastParent;
817
 
                    do
818
 
                    {
819
 
                        next = next->parent();
820
 
                        if (parent)
821
 
                            parent = parent->parent();
822
 
                    }
823
 
                    while (next && !next->nextSibling());
824
 
                    if (next)
825
 
                        next = next->nextSibling();
826
 
                }
827
 
            }
828
 
            return ;
829
 
        }
830
 
        (source ? ScriptUI->SourceObjects : ScriptUI->DestinationObjects)->clear();
831
 
        (source ? ScriptUI->SourceSchema : ScriptUI->DestinationSchema)->clear();
832
 
        (source ? ScriptUI->SourceSchema : ScriptUI->DestinationSchema)->insertItem(tr("All"));
833
 
        toConnection &conn = toMainWidget()->connection((source ?
834
 
                             ScriptUI->SourceConnection :
835
 
                             ScriptUI->DestinationConnection)
836
 
                             ->currentText());
837
 
        toQList object;
838
 
        try
839
 
        {
840
 
            object = toQuery::readQueryNull(conn, SQLObjectList);
841
 
        }
842
 
        catch (...)
843
 
        {
844
 
            object = toQuery::readQueryNull(conn, SQLUserObjectList);
845
 
        }
846
 
        toQList schema = toQuery::readQuery(conn, SQLSchemas);
847
 
        while (schema.size() > 0)
848
 
        {
849
 
            QString str = toShift(schema);
850
 
            (source ? ScriptUI->SourceSchema : ScriptUI->DestinationSchema)->insertItem(str);
851
 
        }
852
 
        QListViewItem *lastTop = NULL;
853
 
        QListViewItem *lastFirst = NULL;
854
 
        while (object.size() > 0)
855
 
        {
856
 
            QString top = toShift(object);
857
 
            QString first = toShift(object);
858
 
            QString second = toShift(object);
859
 
 
860
 
            if (top != (lastTop ? lastTop->text(0) : QString::null))
861
 
            {
862
 
                lastFirst = NULL;
863
 
                lastTop = new toResultViewCheck((source ?
864
 
                                                 ScriptUI->SourceObjects :
865
 
                                                 ScriptUI->DestinationObjects),
866
 
                                                top, QCheckListItem::CheckBox);
867
 
                lastTop->setExpandable(true);
868
 
                if (!second.isEmpty() || first.isEmpty())
869
 
                    lastTop->setText(1, QString::fromLatin1("DATABASE"));
870
 
            }
871
 
            if (first != (lastFirst ? lastFirst->text(0) : QString::null) && !first.isEmpty())
872
 
            {
873
 
                lastFirst = new toResultViewCheck(lastTop, first, QCheckListItem::CheckBox);
874
 
                if (second.isEmpty())
875
 
                    lastFirst->setText(1, top);
876
 
            }
877
 
            if (!second.isEmpty() && lastFirst)
878
 
            {
879
 
                QListViewItem *item = new toResultViewCheck(lastFirst, second, QCheckListItem::CheckBox);
880
 
                item->setText(1, first);
881
 
                item->setText(2, top);
882
 
            }
883
 
        }
884
 
    }
885
 
    TOCATCH
886
 
}
887
 
 
888
 
void toScript::readOwnerObjects(QListViewItem *item, toConnection &conn)
889
 
{
890
 
    if (!item->parent() && !item->firstChild())
891
 
    {
892
 
        try
893
 
        {
894
 
            QListViewItem *lastFirst = NULL;
895
 
            QString top = item->text(0);
896
 
            toQuery object(conn, SQLUserObjects, top);
897
 
 
898
 
            while (!object.eof())
899
 
            {
900
 
                QString first = object.readValueNull();
901
 
                QString second;
902
 
                if (object.columns() > 1)
903
 
                    second = object.readValueNull();
904
 
                else
905
 
                {
906
 
                    second = first;
907
 
                    first = "TABLE";
908
 
                }
909
 
 
910
 
                if (first != (lastFirst ? lastFirst->text(0) : QString::null) && !first.isEmpty())
911
 
                {
912
 
                    lastFirst = new toResultViewCheck(item, first, QCheckListItem::CheckBox);
913
 
                    if (second.isEmpty())
914
 
                        lastFirst->setText(1, top);
915
 
                }
916
 
                if (!second.isEmpty() && lastFirst)
917
 
                {
918
 
                    QListViewItem *item = new toResultViewCheck(lastFirst, second, QCheckListItem::CheckBox);
919
 
                    item->setText(1, first);
920
 
                    item->setText(2, top);
921
 
                }
922
 
            }
923
 
 
924
 
            if (top == QString::fromLatin1("PUBLIC"))
925
 
            {
926
 
                toQList object = toQuery::readQueryNull(conn, SQLPublicSynonymList);
927
 
                QListViewItem *topItem = new toResultViewCheck(item, QString::fromLatin1("SYNONYM"), QCheckListItem::CheckBox);
928
 
                while (object.size() > 0)
929
 
                {
930
 
                    QListViewItem *item = new toResultViewCheck(topItem, toShift(object),
931
 
                                          QCheckListItem::CheckBox);
932
 
                    item->setText(1, QString::fromLatin1("SYNONYM"));
933
 
                    item->setText(2, top);
934
 
                }
935
 
            }
936
 
        }
937
 
        TOCATCH
938
 
    }
939
 
}
940
 
 
941
 
void toScript::changeMode(int mode)
942
 
{
943
 
    if (mode < 0 || mode > 4)
944
 
        return ;
945
 
 
946
 
    if (mode == 0 || mode == 2)
947
 
        ScriptUI->Destination->setEnabled(true);
948
 
    else if (mode == 1 || mode == 3 || mode == 4)
949
 
        ScriptUI->Destination->setEnabled(false);
950
 
 
951
 
    if (mode == 1 || mode == 2)
952
 
        ScriptUI->Tabs->setTabEnabled(ScriptUI->ResizeTab, true);
953
 
    else if (mode == 0 || mode == 3 || mode == 4)
954
 
        ScriptUI->Tabs->setTabEnabled(ScriptUI->ResizeTab, false);
955
 
 
956
 
    ScriptUI->IncludeContent->setEnabled(mode == 1);
957
 
    ScriptUI->CommitDistance->setEnabled(mode == 1);
958
 
 
959
 
    if (mode == 1 || mode == 2)
960
 
    {
961
 
        ScriptUI->IncludeHeader->setEnabled(true);
962
 
        ScriptUI->IncludePrompt->setEnabled(true);
963
 
    }
964
 
    else if (mode == 0 || mode == 3 || mode == 4)
965
 
    {
966
 
        ScriptUI->IncludeHeader->setEnabled(false);
967
 
        ScriptUI->IncludePrompt->setEnabled(false);
968
 
    }
969
 
 
970
 
    if (mode == 0 || mode == 2 || mode == 3 || mode == 4)
971
 
    {
972
 
        ScriptUI->IncludeDDL->setEnabled(false);
973
 
        ScriptUI->IncludeDDL->setChecked(true);
974
 
    }
975
 
    else if (mode == 1)
976
 
        ScriptUI->IncludeDDL->setEnabled(true);
977
 
 
978
 
    ScriptUI->OutputGroup->setEnabled(mode == 1 || mode == 2 || mode == 4);
979
 
 
980
 
    ScriptUI->IncludeConstraints->setEnabled(ScriptUI->IncludeDDL->isChecked());
981
 
    ScriptUI->IncludeIndexes->setEnabled(ScriptUI->IncludeDDL->isChecked());
982
 
    ScriptUI->IncludeGrants->setEnabled(ScriptUI->IncludeDDL->isChecked());
983
 
    ScriptUI->IncludeStorage->setEnabled(ScriptUI->IncludeDDL->isChecked() && mode != 3);
984
 
    ScriptUI->IncludeParallell->setEnabled(ScriptUI->IncludeDDL->isChecked() && mode != 3);
985
 
    ScriptUI->IncludePartition->setEnabled(ScriptUI->IncludeDDL->isChecked() && mode != 3);
986
 
    ScriptUI->IncludeCode->setEnabled(ScriptUI->IncludeDDL->isChecked());
987
 
    ScriptUI->IncludeComment->setEnabled(ScriptUI->IncludeDDL->isChecked());
988
 
}
989
 
 
990
 
void toScript::keepOn(QListViewItem *parent)
991
 
{
992
 
    if (!parent)
993
 
        return ;
994
 
    toResultViewCheck *pchk = dynamic_cast<toResultViewCheck *>(parent);
995
 
    if (!pchk)
996
 
        return ;
997
 
    pchk->setOn(true);
998
 
}
999
 
 
1000
 
void toScript::objectClicked(QListViewItem *parent)
1001
 
{
1002
 
    if (!parent)
1003
 
        return ;
1004
 
    toResultViewCheck *pchk = dynamic_cast<toResultViewCheck *>(parent);
1005
 
    if (!pchk)
1006
 
        return ;
1007
 
    if (!parent->parent() && !parent->firstChild())
1008
 
    {
1009
 
        if (parent->listView() == ScriptUI->SourceObjects)
1010
 
            expandSource(parent);
1011
 
        else if (parent->listView() == ScriptUI->DestinationObjects)
1012
 
            expandDestination(parent);
1013
 
    }
1014
 
    bool on = pchk->isOn();
1015
 
    QListViewItem *next = NULL;
1016
 
    for (QListViewItem *item = parent->firstChild();item;item = next)
1017
 
    {
1018
 
        toResultViewCheck * chk = dynamic_cast<toResultViewCheck *>(item);
1019
 
        if (chk)
1020
 
            chk->setOn(on);
1021
 
 
1022
 
        if (item->firstChild())
1023
 
            next = item->firstChild();
1024
 
        else if (item->nextSibling())
1025
 
            next = item->nextSibling();
1026
 
        else
1027
 
        {
1028
 
            next = item;
1029
 
            do
1030
 
            {
1031
 
                next = next->parent();
1032
 
                if (next == parent)
1033
 
                    return ;
1034
 
            }
1035
 
            while (next && !next->nextSibling());
1036
 
            if (next)
1037
 
                next = next->nextSibling();
1038
 
        }
1039
 
    }
1040
 
}
1041
 
 
1042
 
void toScript::changeSchema(int, bool source)
1043
 
{
1044
 
    QString src = (source ? ScriptUI->SourceSchema : ScriptUI->DestinationSchema)->currentText();
1045
 
    for (QListViewItem *parent = (source ?
1046
 
                                  ScriptUI->SourceObjects :
1047
 
                                  ScriptUI->DestinationObjects)->firstChild();
1048
 
            parent;
1049
 
            parent = parent->nextSibling())
1050
 
    {
1051
 
        toResultViewCheck * chk = dynamic_cast<toResultViewCheck *>(parent);
1052
 
        if (chk)
1053
 
        {
1054
 
            bool ena = ((src == chk->text(0)) || (src == QString::fromLatin1("All")));
1055
 
 
1056
 
            QListViewItem *next = NULL;
1057
 
            for (QListViewItem *item = parent;item;item = next)
1058
 
            {
1059
 
                chk = dynamic_cast<toResultViewCheck *>(item);
1060
 
                if (chk)
1061
 
                {
1062
 
                    chk->setEnabled(ena);
1063
 
                    (source ? ScriptUI->SourceObjects : ScriptUI->DestinationObjects)->repaintItem(chk);
1064
 
                }
1065
 
 
1066
 
                if (item->firstChild())
1067
 
                    next = item->firstChild();
1068
 
                else if (item->nextSibling() && item->nextSibling()->depth())
1069
 
                    next = item->nextSibling();
1070
 
                else
1071
 
                {
1072
 
                    next = item;
1073
 
                    do
1074
 
                    {
1075
 
                        next = next->parent();
1076
 
                        if (next == parent)
1077
 
                            break;
1078
 
                    }
1079
 
                    while (next && !next->nextSibling());
1080
 
                    if (next == parent)
1081
 
                        break;
1082
 
                    if (next)
1083
 
                        next = next->nextSibling();
1084
 
                }
1085
 
            }
1086
 
 
1087
 
        }
1088
 
    }
1089
 
}
1090
 
 
1091
 
void toScript::newSize(void)
1092
 
{
1093
 
    QString init = ScriptUI->Initial->sizeString();
1094
 
    QString next = ScriptUI->Next->sizeString();
1095
 
    QString max = ScriptUI->Limit->sizeString();
1096
 
    QString maxNum;
1097
 
    maxNum.sprintf("%010d", ScriptUI->Limit->value());
1098
 
 
1099
 
    for (QListViewItem *item = ScriptUI->Sizes->firstChild();item;item = item->nextSibling())
1100
 
        if (max == item->text(0))
1101
 
        {
1102
 
            toStatusMessage(tr("Replacing existing size with new"), false, false);
1103
 
            delete item;
1104
 
            break;
1105
 
        }
1106
 
 
1107
 
    new QListViewItem(ScriptUI->Sizes, max, init, next, maxNum);
1108
 
    ScriptUI->Sizes->setSorting(3);
1109
 
}
1110
 
 
1111
 
void toScript::removeSize(void)
1112
 
{
1113
 
    QListViewItem *item = ScriptUI->Sizes->selectedItem();
1114
 
    if (item)
1115
 
        delete item;
1116
 
}
1117
 
 
1118
 
void toScript::setupExtract(toExtract &extr)
1119
 
{
1120
 
    extr.setCode (ScriptUI->IncludeCode->isEnabled() &&
1121
 
                  ScriptUI->IncludeCode->isChecked() );
1122
 
    extr.setComments (ScriptUI->IncludeComment->isEnabled() &&
1123
 
                      ScriptUI->IncludeComment->isChecked() );
1124
 
    extr.setConstraints(ScriptUI->IncludeConstraints->isEnabled() &&
1125
 
                        ScriptUI->IncludeConstraints->isChecked());
1126
 
    extr.setContents (ScriptUI->IncludeContent->isEnabled() &&
1127
 
                      ScriptUI->IncludeContent->isChecked() ,
1128
 
                      ScriptUI->CommitDistance->value() );
1129
 
    extr.setGrants (ScriptUI->IncludeGrants->isEnabled() &&
1130
 
                    ScriptUI->IncludeGrants->isChecked() );
1131
 
    extr.setHeading (ScriptUI->IncludeHeader->isEnabled() &&
1132
 
                     ScriptUI->IncludeHeader->isChecked() );
1133
 
    extr.setIndexes (ScriptUI->IncludeIndexes->isEnabled() &&
1134
 
                     ScriptUI->IncludeIndexes->isChecked() );
1135
 
    extr.setParallel (ScriptUI->IncludeParallell->isEnabled() &&
1136
 
                      ScriptUI->IncludeParallell->isChecked() );
1137
 
    extr.setPartition (ScriptUI->IncludePartition->isEnabled() &&
1138
 
                       ScriptUI->IncludePartition->isChecked() );
1139
 
    extr.setPrompt (ScriptUI->IncludePrompt->isEnabled() &&
1140
 
                    ScriptUI->IncludePrompt->isChecked() );
1141
 
    extr.setStorage (ScriptUI->IncludeStorage->isEnabled() &&
1142
 
                     ScriptUI->IncludeStorage->isChecked() );
1143
 
 
1144
 
    if (ScriptUI->Schema->currentText() == tr("Same"))
1145
 
        extr.setSchema(QString::fromLatin1("1"));
1146
 
    else if (ScriptUI->Schema->currentText() == tr("None"))
1147
 
        extr.setSchema(QString::null);
1148
 
    else
1149
 
        extr.setSchema(ScriptUI->Schema->currentText());
1150
 
 
1151
 
    if (ScriptUI->DontResize->isChecked())
1152
 
        extr.setResize(QString::null);
1153
 
    else if (ScriptUI->AutoResize->isChecked())
1154
 
        extr.setResize(QString::fromLatin1("1"));
1155
 
    else
1156
 
    {
1157
 
        QString siz;
1158
 
        for (QListViewItem *item = ScriptUI->Sizes->firstChild();item;item = item->nextSibling())
1159
 
        {
1160
 
            siz += item->text(0);
1161
 
            siz += QString::fromLatin1(":");
1162
 
            siz += item->text(1);
1163
 
            siz += QString::fromLatin1(":");
1164
 
            siz += item->text(2);
1165
 
            if (item->nextSibling())
1166
 
                siz += QString::fromLatin1(":");
1167
 
        }
1168
 
        extr.setResize(siz);
1169
 
    }
1170
 
}
1171
 
 
1172
 
void toScript::expandSource(QListViewItem *item)
1173
 
{
1174
 
    try
1175
 
    {
1176
 
        if (item)
1177
 
            readOwnerObjects(item,
1178
 
                             toMainWidget()->connection(ScriptUI->SourceConnection->currentText()));
1179
 
    }
1180
 
    TOCATCH
1181
 
}
1182
 
 
1183
 
void toScript::expandDestination(QListViewItem *item)
1184
 
{
1185
 
    try
1186
 
    {
1187
 
        if (item)
1188
 
            readOwnerObjects(item,
1189
 
                             toMainWidget()->connection(ScriptUI->DestinationConnection->currentText()));
1190
 
    }
1191
 
    TOCATCH
1192
 
}
1193
 
 
1194
 
void toScript::browseFile(void)
1195
 
{
1196
 
    if (ScriptUI->OutputFile->isChecked())
1197
 
    {
1198
 
        QString f = toOpenFilename(QString::null, QString::null, this);
1199
 
        if (!f.isEmpty())
1200
 
            ScriptUI->Filename->setText(f);
1201
 
    }
1202
 
    else if (ScriptUI->OutputDir->isChecked())
1203
 
    {
1204
 
        QString f = TOFileDialog::getExistingDirectory(QString::null, this);
1205
 
        if (!f.isEmpty())
1206
 
            ScriptUI->Filename->setText(f);
1207
 
    }
1208
 
}