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
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.
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.
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.
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.
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.
32
* You may link this product with any GPL'd Qt library such as Qt/Free
34
* All trademarks belong to their respective owners.
41
#include "toextract.h"
42
#include "tofilesize.h"
43
#include "tohighlightedtext.h"
46
#include "toresultview.h"
48
#include "toscriptui.h"
50
#include "totextview.h"
52
#include "toworksheet.h"
55
#include <kfiledialog.h>
58
#include <qcheckbox.h>
59
#include <qcombobox.h>
61
#include <qfiledialog.h>
64
#include <qlineedit.h>
65
#include <qmessagebox.h>
66
#include <qpushbutton.h>
67
#include <qradiobutton.h>
70
#include <qsplitter.h>
71
#include <qtabwidget.h>
72
#include <qtextview.h>
74
#include <qtoolbutton.h>
76
#include "toscript.moc"
77
#include "toscriptui.moc"
79
#include "icons/execute.xpm"
80
#include "icons/toscript.xpm"
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",
89
static toSQL SQLObjectList("toScript:ExtractObject",
91
" FROM (SELECT 'TABLESPACE',tablespace_name,NULL\n"
92
" FROM sys.dba_tablespaces\n"
94
" SELECT 'ROLE',role,NULL\n"
95
" FROM sys.dba_roles\n"
97
" SELECT 'PUBLIC',NULL,NULL\n"
100
" SELECT username,NULL,NULL\n"
101
" FROM sys.all_users)\n"
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"
112
"Extract objects available to extract from the database if you "
113
"don't have admin access, should have same columns");
115
static toSQL SQLPublicSynonymList("toScript:PublicSynonyms",
116
"SELECT synonym_name\n"
117
" FROM sys.all_synonyms WHERE owner = 'PUBLIC'\n"
119
"Extract all public synonyms from database");
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",
127
static toSQL SQLUserObjects("toScript:UserObjects",
129
" FROM (SELECT 'DATABASE LINK',db_link\n"
130
" FROM sys.all_db_links\n"
131
" WHERE owner = :own<char[101]>\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"
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"
144
" SELECT 'MATERIALIZED TABLE',mview_name AS object\n"
145
" FROM sys.all_mviews\n"
146
" WHERE owner = :own<char[101]>)\n"
150
static toSQL SQLUserObjects7("toScript:UserObjects",
152
" FROM (SELECT 'DATABASE LINK',db_link\n"
153
" FROM sys.all_db_links\n"
154
" WHERE owner = :own<char[101]>\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"
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"
167
" SELECT 'MATERIALIZED TABLE',mview_name AS object\n"
168
" FROM sys.all_mviews\n"
169
" WHERE owner = :own<char[101]>)\n"
174
static toSQL SQLSchemasMySQL("toScript:ExtractSchema",
176
"Get usernames available in database, must have same columns",
180
static toSQL SQLSchemas("toScript:ExtractSchema",
181
"SELECT username FROM sys.all_users ORDER BY username",
184
class toScriptTool : public toTool
187
virtual const char **pictureXPM(void)
189
return const_cast<const char**>(toscript_xpm);
193
: toTool(310, "DB Extraction/Compare/Search")
195
virtual const char *menuItem()
197
return "DB Extraction/Compare/Search";
199
virtual const char *toolbarTip()
201
return "DB or schema extraction, compare and search";
203
virtual bool canHandle(toConnection &conn)
207
return toExtract::canHandle(conn) && !toSQL::string(SQLObjectList, conn).isEmpty();
214
virtual QWidget *toolWindow(QWidget *main, toConnection &connection)
216
return new toScript(main, connection);
220
static toScriptTool ScriptTool;
222
toScript::toScript(QWidget *parent, toConnection &connection)
223
: toToolWidget(ScriptTool, "script.html", parent, connection)
225
QToolBar *toolbar = toAllocBar(this, tr("Extraction and Compare"));
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)),
232
toolbar->setStretchableWidget(new QLabel(toolbar, TO_KDE_TOOLBAR_WIDGET));
234
ScriptUI = new toScriptUI(this);
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);
244
Report = new toTextView(box);
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);
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 *)));
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);
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);
277
// Remove when migrate and resize is implemented
280
ScriptUI->Migrate->hide();
284
std::list<QString> cons = toMainWidget()->connections();
286
while (cons.size() > 0)
288
QString str = toShift(cons);
289
if (str == connection.description() && def == 0)
292
ScriptUI->SourceConnection->insertItem(str);
293
ScriptUI->DestinationConnection->insertItem(str);
295
ScriptUI->SourceConnection->setCurrentItem(def);
297
changeDestination(def);
298
ScriptUI->DestinationConnection->setCurrentItem(def);
300
connect(ScriptUI->AddButton, SIGNAL(clicked()), this, SLOT(newSize()));
301
connect(ScriptUI->Remove, SIGNAL(clicked()), this, SLOT(removeSize()));
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()));
311
connect(ScriptUI->SourceObjects, SIGNAL(expanded(QListViewItem *)),
312
this, SLOT(expandSource(QListViewItem *)));
313
connect(ScriptUI->DestinationObjects, SIGNAL(expanded(QListViewItem *)),
314
this, SLOT(expandDestination(QListViewItem *)));
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 &)));
321
ScriptUI->Schema->setCurrentItem(0);
322
setFocusProxy(ScriptUI->Tabs);
325
void toScript::delConnection(const QString &name)
327
for (int i = 0;i < ScriptUI->SourceConnection->count();i++)
329
if (ScriptUI->SourceConnection->text(i) == name)
331
ScriptUI->SourceConnection->removeItem(i);
335
for (int j = 0;j < ScriptUI->DestinationConnection->count();j++)
337
if (ScriptUI->DestinationConnection->text(j) == name)
339
ScriptUI->DestinationConnection->removeItem(j);
345
void toScript::addConnection(const QString &name)
347
ScriptUI->SourceConnection->insertItem(name);
348
ScriptUI->DestinationConnection->insertItem(name);
351
toScript::~toScript()
354
std::list<QString> toScript::createObjectList(QListView *source)
356
std::list<QString> lst;
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;
367
QListViewItem *next = NULL;
368
for (QListViewItem *item = source->firstChild();item;item = next)
370
toResultViewCheck * chk = dynamic_cast<toResultViewCheck *>(item);
372
if (chk && chk->isEnabled())
374
QString name = chk->text(0);
375
QString type = chk->text(1);
376
QString user = chk->text(2);
379
if (chk->isOn() && chk->isEnabled())
382
if (type == QString::fromLatin1("TABLE"))
385
line += QString::fromLatin1(".");
387
toPush(tables, line);
392
line += QString::fromLatin1(":");
394
line += QString::fromLatin1(".");
396
if (type == QString::fromLatin1("VIEW"))
397
toPush(userViews, line);
399
toPush(userOther, line);
403
else if (!type.isEmpty())
405
if (chk->isOn() && chk->isEnabled())
408
line += QString::fromLatin1(":");
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"))
416
else if (type == QString::fromLatin1("USER"))
419
toPush(otherGlobal, line);
424
if (item->firstChild() && chk && chk->isEnabled())
425
next = item->firstChild();
426
else if (item->nextSibling())
427
next = item->nextSibling();
433
next = next->parent();
435
while (next && !next->nextSibling());
437
next = next->nextSibling();
441
if (ScriptUI->IncludeDDL->isChecked())
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());
452
for_each(tables.begin(), tables.end(), PrefixString(lst, QString::fromLatin1("TABLE CONTENTS:")));
453
if (ScriptUI->IncludeDDL->isChecked())
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:")));
462
void toScript::execute(void)
467
if (ScriptUI->Compare->isChecked())
469
else if (ScriptUI->Extract->isChecked())
471
else if (ScriptUI->Migrate->isChecked())
473
else if (ScriptUI->Search->isChecked())
475
else if (ScriptUI->Report->isChecked())
479
toStatusMessage(tr("No mode selected"));
483
std::list<QString> sourceObjects = createObjectList(ScriptUI->SourceObjects);
485
std::list<QString> sourceDescription;
486
std::list<QString> destinationDescription;
489
toExtract source(toMainWidget()->connection(ScriptUI->SourceConnection->currentText()), this);
490
setupExtract(source);
494
if (ScriptUI->OutputTab->isChecked())
495
script += source.create(sourceObjects);
496
else if (ScriptUI->OutputFile->isChecked())
498
if (ScriptUI->Filename->text().isEmpty())
499
throw tr("No filename specified");
501
QFile file(ScriptUI->Filename->text());
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)
511
file.open(IO_WriteOnly);
513
if (file.status() != IO_Ok)
514
throw tr("Couldn't open file %1").arg(file.name());
516
QTextStream stream(&file);
517
source.create(stream, sourceObjects);
519
if (file.status() != IO_Ok)
520
throw tr("Error writing to file %1").arg(file.name());
522
script = tr("-- Script generated to file %1 successfully").arg(ScriptUI->Filename->text());
524
else if (ScriptUI->OutputDir->isChecked())
526
if (ScriptUI->Filename->text().isEmpty())
527
throw tr("No filename specified");
529
QFile file(ScriptUI->Filename->text() + QDir::separator() + "script.sql");
530
file.open(IO_WriteOnly);
532
if (file.status() != IO_Ok)
533
throw QString(tr("Couldn't open file %1")).arg(file.name());
535
QTextStream stream(&file);
537
stream << tr("rem Master script for DDL reverse engineering by TOra\n"
540
QFile pfile(ScriptUI->Filename->text() + QDir::separator() + "script.tpr");
541
pfile.open(IO_WriteOnly);
543
if (pfile.status() != IO_Ok)
544
throw QString(tr("Couldn't open file %1")).arg(pfile.name());
546
QTextStream pstream(&pfile);
548
QRegExp repl("\\W+");
549
for (std::list<QString>::iterator i = sourceObjects.begin();i != sourceObjects.end();i++)
551
std::list<QString> t;
552
t.insert(t.end(), *i);
554
fn.replace(repl, "_");
556
stream << "@" << fn << "\n";
558
QFile tf(ScriptUI->Filename->text() + QDir::separator() + fn);
559
tf.open(IO_WriteOnly);
560
pstream << tf.name() << "\n";
562
if (tf.status() != IO_Ok)
563
throw QString(tr("Couldn't open file %1")).arg(tf.name());
566
source.create(ts, t);
568
if (tf.status() != IO_Ok)
569
throw QString(tr("Error writing to file %1")).arg(tf.name());
572
script = tr("-- Scripts generate to directory %1 successfully").arg(ScriptUI->Filename->text());
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());
586
sourceDescription = source.describe(sourceObjects);
590
if (ScriptUI->Destination->isEnabled())
592
std::list<QString> destinationObjects = createObjectList(ScriptUI->DestinationObjects);
593
toExtract destination(toMainWidget()->connection(ScriptUI->
594
DestinationConnection->
595
currentText()), this);
596
setupExtract(destination);
601
destinationDescription = destination.describe(destinationObjects);
605
throw tr("Destination shouldn't be enabled now, internal error");
608
std::list<QString> drop;
609
std::list<QString> create;
611
toExtract::srcDst2DropCreate(sourceDescription, destinationDescription,
613
sourceDescription = drop;
614
destinationDescription = create;
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())
620
Worksheet->editor()->setText(script);
621
Worksheet->editor()->setFilename(QString::null);
622
Worksheet->editor()->setModified(true);
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();
635
if (ScriptUI->AllWords->isChecked())
637
else if (ScriptUI->AnyWords->isChecked())
639
else if (ScriptUI->RegExp->isChecked())
641
else if (ScriptUI->ExactMatch->isChecked())
643
std::list<QString> result;
644
for (std::list<QString>::iterator i = sourceDescription.begin();
645
i != sourceDescription.end();
648
QStringList ctx = QStringList::split(QString::fromLatin1("\01"), (*i).upper());
654
unsigned int count = 0;
655
for (unsigned int k = 0;k < words.count();k++)
657
QString s = words[k];
658
if (ctx.last().contains(s))
661
if ((searchMode == 2 && count > 0) || (searchMode == 1 && count == words.count()))
662
result.insert(result.end(), *i);
666
if (ctx.last() == word)
667
result.insert(result.end(), *i);
670
if (re.match(ctx.last()) >= 0)
671
result.insert(result.end(), *i);
675
fillDifference(result, SearchList);
682
QString res = toGenerateReport(source.connection(), sourceDescription);
683
Report->setText(res);
684
if (ScriptUI->OutputFile->isChecked())
686
if (ScriptUI->Filename->text().isEmpty())
687
toStatusMessage(tr("No filename specified"));
690
QFile file(ScriptUI->Filename->text());
691
file.open(IO_WriteOnly);
693
if (file.status() != IO_Ok)
694
toStatusMessage(tr("Couldn't open file %1").arg(file.name()));
697
QTextStream stream(&file);
700
if (file.status() != IO_Ok)
701
toStatusMessage(tr("Error writing to file %1").arg(file.name()));
711
fillDifference(sourceDescription, DropList);
712
fillDifference(destinationDescription, CreateList);
715
ScriptUI->Tabs->showPage(ScriptUI->DifferenceTab);
717
ScriptUI->Tabs->showPage(ScriptUI->ResultTab);
722
void toScript::fillDifference(std::list<QString> &objects, QListView *view)
725
QListViewItem *last = NULL;
728
for (std::list<QString>::iterator i = objects.begin();i != objects.end();i++)
730
// printf("Adding %s\n",(const char *)*i);
731
QStringList ctx = QStringList::split(QString::fromLatin1("\01"), *i);
734
while (last && lastLevel >= int(ctx.count()))
736
last = last->parent();
739
while (last && lastLevel >= 0 && !toCompareLists(lstCtx, ctx, (unsigned int)lastLevel))
741
last = last->parent();
746
throw tr("Internal error, lastLevel < 0");
747
while (lastLevel < int(ctx.count()) - 1)
750
last = new toResultViewMLine(last, NULL, ctx[lastLevel]);
752
last = new toResultViewMLine(view, NULL, ctx[lastLevel]);
755
QCheckListItem *item;
757
item = new toResultViewMLCheck(last, ctx[lastLevel], QCheckListItem::CheckBox);
759
item = new toResultViewMLCheck(view, ctx[lastLevel], QCheckListItem::CheckBox);
767
void toScript::changeConnection(int, bool source)
771
QListView *sourceL = NULL;
772
QListView *destinationL = NULL;
773
if (ScriptUI->SourceConnection->currentText() ==
774
ScriptUI->DestinationConnection->currentText())
778
destinationL = ScriptUI->SourceObjects;
779
sourceL = ScriptUI->DestinationObjects;
783
sourceL = ScriptUI->SourceObjects;
784
destinationL = ScriptUI->DestinationObjects;
787
if (sourceL && destinationL && sourceL->firstChild())
789
destinationL->clear();
790
QListViewItem *next = NULL;
791
QListViewItem *parent = NULL;
792
for (QListViewItem *item = sourceL->firstChild();item;item = next)
794
QListViewItem * lastParent = parent;
797
parent = new toResultViewCheck(destinationL, item->text(0),
798
QCheckListItem::CheckBox);
799
parent->setExpandable(true);
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())
810
next = item->nextSibling();
819
next = next->parent();
821
parent = parent->parent();
823
while (next && !next->nextSibling());
825
next = next->nextSibling();
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)
840
object = toQuery::readQueryNull(conn, SQLObjectList);
844
object = toQuery::readQueryNull(conn, SQLUserObjectList);
846
toQList schema = toQuery::readQuery(conn, SQLSchemas);
847
while (schema.size() > 0)
849
QString str = toShift(schema);
850
(source ? ScriptUI->SourceSchema : ScriptUI->DestinationSchema)->insertItem(str);
852
QListViewItem *lastTop = NULL;
853
QListViewItem *lastFirst = NULL;
854
while (object.size() > 0)
856
QString top = toShift(object);
857
QString first = toShift(object);
858
QString second = toShift(object);
860
if (top != (lastTop ? lastTop->text(0) : QString::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"));
871
if (first != (lastFirst ? lastFirst->text(0) : QString::null) && !first.isEmpty())
873
lastFirst = new toResultViewCheck(lastTop, first, QCheckListItem::CheckBox);
874
if (second.isEmpty())
875
lastFirst->setText(1, top);
877
if (!second.isEmpty() && lastFirst)
879
QListViewItem *item = new toResultViewCheck(lastFirst, second, QCheckListItem::CheckBox);
880
item->setText(1, first);
881
item->setText(2, top);
888
void toScript::readOwnerObjects(QListViewItem *item, toConnection &conn)
890
if (!item->parent() && !item->firstChild())
894
QListViewItem *lastFirst = NULL;
895
QString top = item->text(0);
896
toQuery object(conn, SQLUserObjects, top);
898
while (!object.eof())
900
QString first = object.readValueNull();
902
if (object.columns() > 1)
903
second = object.readValueNull();
910
if (first != (lastFirst ? lastFirst->text(0) : QString::null) && !first.isEmpty())
912
lastFirst = new toResultViewCheck(item, first, QCheckListItem::CheckBox);
913
if (second.isEmpty())
914
lastFirst->setText(1, top);
916
if (!second.isEmpty() && lastFirst)
918
QListViewItem *item = new toResultViewCheck(lastFirst, second, QCheckListItem::CheckBox);
919
item->setText(1, first);
920
item->setText(2, top);
924
if (top == QString::fromLatin1("PUBLIC"))
926
toQList object = toQuery::readQueryNull(conn, SQLPublicSynonymList);
927
QListViewItem *topItem = new toResultViewCheck(item, QString::fromLatin1("SYNONYM"), QCheckListItem::CheckBox);
928
while (object.size() > 0)
930
QListViewItem *item = new toResultViewCheck(topItem, toShift(object),
931
QCheckListItem::CheckBox);
932
item->setText(1, QString::fromLatin1("SYNONYM"));
933
item->setText(2, top);
941
void toScript::changeMode(int mode)
943
if (mode < 0 || mode > 4)
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);
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);
956
ScriptUI->IncludeContent->setEnabled(mode == 1);
957
ScriptUI->CommitDistance->setEnabled(mode == 1);
959
if (mode == 1 || mode == 2)
961
ScriptUI->IncludeHeader->setEnabled(true);
962
ScriptUI->IncludePrompt->setEnabled(true);
964
else if (mode == 0 || mode == 3 || mode == 4)
966
ScriptUI->IncludeHeader->setEnabled(false);
967
ScriptUI->IncludePrompt->setEnabled(false);
970
if (mode == 0 || mode == 2 || mode == 3 || mode == 4)
972
ScriptUI->IncludeDDL->setEnabled(false);
973
ScriptUI->IncludeDDL->setChecked(true);
976
ScriptUI->IncludeDDL->setEnabled(true);
978
ScriptUI->OutputGroup->setEnabled(mode == 1 || mode == 2 || mode == 4);
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());
990
void toScript::keepOn(QListViewItem *parent)
994
toResultViewCheck *pchk = dynamic_cast<toResultViewCheck *>(parent);
1000
void toScript::objectClicked(QListViewItem *parent)
1004
toResultViewCheck *pchk = dynamic_cast<toResultViewCheck *>(parent);
1007
if (!parent->parent() && !parent->firstChild())
1009
if (parent->listView() == ScriptUI->SourceObjects)
1010
expandSource(parent);
1011
else if (parent->listView() == ScriptUI->DestinationObjects)
1012
expandDestination(parent);
1014
bool on = pchk->isOn();
1015
QListViewItem *next = NULL;
1016
for (QListViewItem *item = parent->firstChild();item;item = next)
1018
toResultViewCheck * chk = dynamic_cast<toResultViewCheck *>(item);
1022
if (item->firstChild())
1023
next = item->firstChild();
1024
else if (item->nextSibling())
1025
next = item->nextSibling();
1031
next = next->parent();
1035
while (next && !next->nextSibling());
1037
next = next->nextSibling();
1042
void toScript::changeSchema(int, bool source)
1044
QString src = (source ? ScriptUI->SourceSchema : ScriptUI->DestinationSchema)->currentText();
1045
for (QListViewItem *parent = (source ?
1046
ScriptUI->SourceObjects :
1047
ScriptUI->DestinationObjects)->firstChild();
1049
parent = parent->nextSibling())
1051
toResultViewCheck * chk = dynamic_cast<toResultViewCheck *>(parent);
1054
bool ena = ((src == chk->text(0)) || (src == QString::fromLatin1("All")));
1056
QListViewItem *next = NULL;
1057
for (QListViewItem *item = parent;item;item = next)
1059
chk = dynamic_cast<toResultViewCheck *>(item);
1062
chk->setEnabled(ena);
1063
(source ? ScriptUI->SourceObjects : ScriptUI->DestinationObjects)->repaintItem(chk);
1066
if (item->firstChild())
1067
next = item->firstChild();
1068
else if (item->nextSibling() && item->nextSibling()->depth())
1069
next = item->nextSibling();
1075
next = next->parent();
1079
while (next && !next->nextSibling());
1083
next = next->nextSibling();
1091
void toScript::newSize(void)
1093
QString init = ScriptUI->Initial->sizeString();
1094
QString next = ScriptUI->Next->sizeString();
1095
QString max = ScriptUI->Limit->sizeString();
1097
maxNum.sprintf("%010d", ScriptUI->Limit->value());
1099
for (QListViewItem *item = ScriptUI->Sizes->firstChild();item;item = item->nextSibling())
1100
if (max == item->text(0))
1102
toStatusMessage(tr("Replacing existing size with new"), false, false);
1107
new QListViewItem(ScriptUI->Sizes, max, init, next, maxNum);
1108
ScriptUI->Sizes->setSorting(3);
1111
void toScript::removeSize(void)
1113
QListViewItem *item = ScriptUI->Sizes->selectedItem();
1118
void toScript::setupExtract(toExtract &extr)
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() );
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);
1149
extr.setSchema(ScriptUI->Schema->currentText());
1151
if (ScriptUI->DontResize->isChecked())
1152
extr.setResize(QString::null);
1153
else if (ScriptUI->AutoResize->isChecked())
1154
extr.setResize(QString::fromLatin1("1"));
1158
for (QListViewItem *item = ScriptUI->Sizes->firstChild();item;item = item->nextSibling())
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(":");
1168
extr.setResize(siz);
1172
void toScript::expandSource(QListViewItem *item)
1177
readOwnerObjects(item,
1178
toMainWidget()->connection(ScriptUI->SourceConnection->currentText()));
1183
void toScript::expandDestination(QListViewItem *item)
1188
readOwnerObjects(item,
1189
toMainWidget()->connection(ScriptUI->DestinationConnection->currentText()));
1194
void toScript::browseFile(void)
1196
if (ScriptUI->OutputFile->isChecked())
1198
QString f = toOpenFilename(QString::null, QString::null, this);
1200
ScriptUI->Filename->setText(f);
1202
else if (ScriptUI->OutputDir->isChecked())
1204
QString f = TOFileDialog::getExistingDirectory(QString::null, this);
1206
ScriptUI->Filename->setText(f);