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.
40
#include "tochangeconnection.h"
41
#include "toconnection.h"
43
#include "tocurrent.h"
45
#include "tonoblockquery.h"
46
#include "toresultlong.h"
47
#include "toresultparam.h"
48
#include "toresultstats.h"
49
#include "toresultview.h"
54
# include <kmenubar.h>
59
#include <qpopupmenu.h>
60
#include <qtabwidget.h>
62
#include <qtoolbutton.h>
63
#include <qworkspace.h>
65
#include "tocurrent.moc"
67
#include "icons/refresh.xpm"
68
#include "icons/tocurrent.xpm"
70
class toCurrentInfoTool : public toTool
73
std::map<toConnection *, QWidget *> Windows;
75
virtual const char **pictureXPM(void)
77
return const_cast<const char**>(tocurrent_xpm);
81
: toTool(240, "Current Session")
83
virtual const char *menuItem()
85
return "Current Session";
87
virtual QWidget *toolWindow(QWidget *parent, toConnection &connection)
89
std::map<toConnection *, QWidget *>::iterator i = Windows.find(&connection);
90
if (i != Windows.end())
93
(*i).second->setFocus();
98
QWidget *window = new toCurrent(parent, connection);
99
Windows[&connection] = window;
103
void closeWindow(toConnection &connection)
105
std::map<toConnection *, QWidget *>::iterator i = Windows.find(&connection);
106
if (i != Windows.end())
111
static toCurrentInfoTool CurrentTool;
113
static toSQL SQLVersion("toCurrent:Version",
114
"select banner \"Version\" from v$version",
115
"Display version of Oracle");
117
static toSQL SQLResourceLimit("toCurrent:ResourceLimit",
118
"SELECT * FROM v$resource_limit ORDER BY resource_name",
119
"List resource limits");
121
toCurrent::toCurrent(QWidget *main, toConnection &connection)
122
: toToolWidget(CurrentTool, "current.html", main, connection)
124
QToolBar *toolbar = toAllocBar(this, tr("Current Session"));
126
new QToolButton(QPixmap(const_cast<const char**>(refresh_xpm)),
129
this, SLOT(refresh(void)),
131
toolbar->setStretchableWidget(new QLabel(toolbar, TO_KDE_TOOLBAR_WIDGET));
132
new toChangeConnection(toolbar, TO_KDE_TOOLBAR_WIDGET);
134
Tabs = new QTabWidget(this);
136
Grants = new toListView(Tabs);
137
Grants->setSorting(0);
138
Grants->addColumn(tr("Privilege"));
139
Grants->addColumn(tr("Type"));
140
Grants->addColumn(tr("Grantable"));
141
Grants->setRootIsDecorated(true);
142
Tabs->addTab(Grants, tr("Privileges"));
144
Version = new toResultLong(true, false, toQuery::Background, Tabs);
145
Version->setSQL(SQLVersion);
146
Tabs->addTab(Version, tr("Version"));
148
Parameters = new toResultParam(Tabs);
149
Tabs->addTab(Parameters, tr("Parameters"));
151
Statistics = new toResultStats(false, Tabs);
152
Tabs->addTab(Statistics, tr("Statistics"));
154
ResourceLimit = new toResultLong(true, false, toQuery::Background, Tabs, "resource");
155
ResourceLimit->setSQL(SQLResourceLimit);
156
Tabs->addTab(ResourceLimit, tr("Resource Limits"));
159
connect(toMainWidget()->workspace(), SIGNAL(windowActivated(QWidget *)),
160
this, SLOT(windowActivated(QWidget *)));
162
connect(&Poll, SIGNAL(timeout()), this, SLOT(poll()));
170
void toCurrent::windowActivated(QWidget *widget)
176
ToolMenu = new QPopupMenu(this);
177
ToolMenu->insertItem(QPixmap(const_cast<const char**>(refresh_xpm)), tr("&Refresh"),
178
this, SLOT(refresh(void)),
179
toKeySequence(tr("F5", "Current session|Refresh")));
180
toMainWidget()->menuBar()->insertItem(tr("&Current Session"), ToolMenu, -1, toToolMenuIndex());
190
toCurrent::~toCurrent()
194
CurrentTool.closeWindow(connection());
199
static toSQL SQLRoleTabPrivs("toCurrent:RoleTabPrivs",
200
"select privilege||' on '||owner||'.'||table_name,grantable from role_tab_privs where role = :role<char[100]>",
201
"Get information about privileges granted on objects to a role, must have same binds and columns");
203
static toSQL SQLRoleSysPrivs("toCurrent:RoleSysPrivs",
204
"select privilege,admin_option from role_sys_privs where role = :role<char[100]>",
205
"Get information about system privileges granted to role, must have same binds and columns");
207
static toSQL SQLRoleRolePrivs("toCurrent:RoleRolePrivs",
208
"select granted_role,admin_option from role_role_privs where role = :role<char[100]>",
209
"Get information about roles granted to a role, must have same binds and columns");
211
static toSQL SQLUserTabPrivs("toCurrent:UserTabPrivs",
212
"select privilege || ' on ' || owner||'.'||table_name,grantable from user_tab_privs",
213
"Get information about privileges granted on objects to a user, must have same columns");
215
static toSQL SQLUserSysPrivs("toCurrent:UserSysPrivs",
216
"select privilege,admin_option from user_sys_privs",
217
"Get information about system privileges granted to user, must have same columns");
219
static toSQL SQLUserRolePrivs("toCurrent:UserRolePrivs",
220
"select granted_role,admin_option from user_role_privs",
221
"Get information about roles granted to a user, must have same columns");
223
void toCurrent::addList(bool isrole, QListViewItem *parent, const QString &type, const toSQL &sql, const QString &role)
225
Updates.insert(Updates.end(), update(isrole, parent, type, sql(connection()), role));
228
void toCurrent::poll()
234
while (Query && Query->poll())
244
if (CurrentUpdate.Parent)
245
item = new toResultViewItem(CurrentUpdate.Parent, NULL);
247
item = new toResultViewItem(Grants, NULL);
248
item->setText(0, Query->readValue());
249
item->setText(1, CurrentUpdate.Type);
250
item->setText(2, Query->readValue());
251
if (CurrentUpdate.IsRole)
253
addList(false, item, tr("System"), SQLRoleSysPrivs, item->text(0));
254
addList(false, item, tr("Object"), SQLRoleTabPrivs, item->text(0));
255
addList(true, item, tr("Role"), SQLRoleRolePrivs, item->text(0));
263
if ( Updates.empty() )
269
CurrentUpdate = toShift(Updates);
272
if (!CurrentUpdate.Role.isEmpty())
273
toPush(param, toQValue(CurrentUpdate.Role));
274
Query = new toNoBlockQuery(connection(),
280
catch (const QString &exc)
282
toStatusMessage(exc);
288
void toCurrent::refresh()
292
Parameters->refresh();
294
Statistics->refreshStats();
296
ResourceLimit->refresh();
302
addList(false, NULL, tr("System"), SQLUserSysPrivs);
303
addList(false, NULL, tr("Object"), SQLUserTabPrivs);
304
addList(true, NULL, tr("Role"), SQLUserRolePrivs);