1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
/*****
*
* TOra - An Oracle Toolkit for DBA's and developers
* Copyright (C) 2003-2005 Quest Software, Inc
* Portions Copyright (C) 2005 Other Contributors
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; only version 2 of
* the License is valid for this program.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* As a special exception, you have permission to link this program
* with the Oracle Client libraries and distribute executables, as long
* as you follow the requirements of the GNU GPL in regard to all of the
* software in the executable aside from Oracle client libraries.
*
* Specifically you are not permitted to link this program with the
* Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
* And you are not permitted to distribute binaries compiled against
* these libraries without written consent from Quest Software, Inc.
* Observe that this does not disallow linking to the Qt Free Edition.
*
* You may link this product with any GPL'd Qt library such as Qt/Free
*
* All trademarks belong to their respective owners.
*
*****/
#include "utils.h"
#include "tochangeconnection.h"
#include "toconf.h"
#include "toconnection.h"
#include "toextract.h"
#include "tohighlightedtext.h"
#include "toinvalid.h"
#include "tomain.h"
#include "toresultextract.h"
#include "toresultlong.h"
#include "toresultview.h"
#include "tosql.h"
#include "totool.h"
#ifdef TO_KDE
# include <kmenubar.h>
#endif
#include <qlabel.h>
#include <qlineedit.h>
#include <qmenubar.h>
#include <qpopupmenu.h>
#include <qprogressdialog.h>
#include <qsplitter.h>
#include <qtoolbar.h>
#include <qtoolbutton.h>
#include <qworkspace.h>
#include "toinvalid.moc"
#include "icons/refresh.xpm"
#include "icons/toinvalid.xpm"
#include "icons/compile.xpm"
static toSQL SQLListInvalid("toInvalid:ListInvalid",
"SELECT owner \"Owner\",object_name \"Object\",object_type \"Type\",status \"Status\"\n"
" FROM sys.all_objects\n"
" WHERE status <> 'VALID'",
"Get invalid objects, must have same first three columns.");
static toSQL SQLListSource("toInvalid:ListSource",
"SELECT Text FROM SYS.ALL_SOURCE\n"
" WHERE Owner = :f1<char[101]> AND Name = :f2<char[101]> AND type = :f3<char[101]>",
"List source of an object.");
static toSQL SQLReadErrors("toInvalid:ReadErrors",
"SELECT Line-1,Text FROM sys.All_Errors\n"
" WHERE OWNER = :f1<char[101]>\n"
" AND NAME = :f2<char[101]>\n"
" AND TYPE = :f3<char[101]>",
" ORDER BY Type,Line",
"Get lines with errors in object (Observe first line 0)");
class toInvalidTool : public toTool
{
virtual const char **pictureXPM(void)
{
return const_cast<const char**>(toinvalid_xpm);
}
public:
toInvalidTool()
: toTool(130, "Invalid Objects")
{ }
virtual const char *menuItem()
{
return "Invalid Objects";
}
virtual QWidget *toolWindow(QWidget *parent, toConnection &connection)
{
return new toInvalid(parent, connection);
}
};
static toInvalidTool InvalidTool;
toInvalid::toInvalid(QWidget *main, toConnection &connection)
: toToolWidget(InvalidTool, "invalid.html", main, connection)
{
QToolBar *toolbar = toAllocBar(this, tr("Invalid Objects"));
new QToolButton(QPixmap(const_cast<const char**>(refresh_xpm)),
tr("Refresh list"),
tr("Refresh list"),
this, SLOT(refresh()),
toolbar);
new QToolButton(QPixmap(const_cast<const char**>(compile_xpm)),
tr("Recompile all invalid"),
tr("Recompile all invalid"),
this, SLOT(recompileSelected()),
toolbar);
toolbar->setStretchableWidget(new QLabel(toolbar, TO_KDE_TOOLBAR_WIDGET));
new toChangeConnection(toolbar, TO_KDE_TOOLBAR_WIDGET);
QSplitter *splitter = new QSplitter(Horizontal, this);
Objects = new toResultLong(false, false, toQuery::Background, splitter);
Objects->setSQL(SQLListInvalid);
Objects->setSelectionMode(QListView::Single);
connect(Objects, SIGNAL(selectionChanged()), this, SLOT(changeSelection()));
Source = new toResultExtract(false, splitter);
Source->setSQL(SQLListSource);
connect(Source, SIGNAL(executed()), this, SLOT(refresh()));
#if 0
{
QValueList<int> sizes = splitter->sizes();
sizes[0] = 300;
splitter->setSizes(sizes);
splitter->setResizeMode(Objects, QSplitter::KeepSize);
}
#endif
ToolMenu = NULL;
connect(toMainWidget()->workspace(), SIGNAL(windowActivated(QWidget *)),
this, SLOT(windowActivated(QWidget *)));
refresh();
setFocusProxy(Objects);
}
void toInvalid::recompileSelected(void)
{
QProgressDialog progress(tr("Recompiling all invalid"),
tr("Cancel"), Objects->childCount(), this, "progress", true);
progress.setCaption("Recompiling");
progress.show();
for (QListViewItem *item = Objects->firstChild();item;item = item->nextSibling())
{
toResultViewItem * ci = dynamic_cast<toResultViewItem *>(item);
if (ci)
{
toConnection &conn = connection();
progress.setLabelText("Recompiling " + ci->allText(1) + "." + ci->allText(2));
progress.setProgress(progress.progress() + 1);
qApp->processEvents();
if (progress.wasCancelled())
break;
QString type = ci->allText(2);
QString sql;
if (type == "INDEX")
sql = "ALTER " + ci->allText(2) + " " + conn.quote(ci->allText(0)) + "." + conn.quote(ci->allText(1)) + " REBUILD";
else if (type == "PACKAGE BODY")
sql = "ALTER PACKAGE " + conn.quote(ci->allText(0)) + "." + conn.quote(ci->allText(1)) + " COMPILE BODY";
else
sql = "ALTER " + ci->allText(2) + " " + conn.quote(ci->allText(0)) + "." + conn.quote(ci->allText(1)) + " COMPILE";
try
{
conn.execute(sql);
}
catch (...)
{}
}
}
if (progress.isVisible())
progress.close();
qApp->processEvents();
this->refresh();
}
void toInvalid::windowActivated(QWidget *widget)
{
if (widget == this)
{
if (!ToolMenu)
{
ToolMenu = new QPopupMenu(this);
ToolMenu->insertItem(QPixmap(const_cast<const char**>(refresh_xpm)), tr("&Refresh"),
this, SLOT(refresh(void)),
toKeySequence(tr("F5", "Invalid|Refresh")));
toMainWidget()->menuBar()->insertItem(tr("&Invalid"), ToolMenu, -1, toToolMenuIndex());
}
}
else
{
delete ToolMenu;
ToolMenu = NULL;
}
}
void toInvalid::refresh(void)
{
QListViewItem *item = Objects->selectedItem();
QString owner;
QString object;
QString type;
if (item)
{
owner = item->text(0);
object = item->text(1);
type = item->text(2);
}
Objects->refresh();
if (item)
{
for (item = Objects->firstChild();item;item = item->nextSibling())
{
if (item->text(0) == owner && item->text(1) == object && item->text(2) == type)
{
Objects->setSelected(item, true);
break;
}
}
changeSelection();
}
}
void toInvalid::changeSelection(void)
{
try
{
QListViewItem *item = Objects->selectedItem();
if (item)
{
Source->changeParams(item->text(0), item->text(1), item->text(2));
std::map<int, QString> Errors;
toQuery errors(connection(), SQLReadErrors, item->text(0), item->text(1), item->text(2));
while (!errors.eof())
{
int line = errors.readValue().toInt();
Errors[line] += QString::fromLatin1(" ");
Errors[line] += errors.readValue();
}
Source->editor()->setErrors(Errors);
}
}
TOCATCH
}
|