summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOcke Janssen <oj@openoffice.org>2001-07-04 12:09:13 +0000
committerOcke Janssen <oj@openoffice.org>2001-07-04 12:09:13 +0000
commitcde779faa288e26330363c70daf1d6ec201285c1 (patch)
treeceb7fc2998b50748b40226f3137f9e56ac56724a
parent57af5d9b4828c24ddad307c744ccfa96a32a0445 (diff)
#85663# check if table is accessable and returns data
-rw-r--r--dbaccess/source/ui/dlg/AdabasStat.cxx220
-rw-r--r--dbaccess/source/ui/dlg/AdabasStat.hxx9
-rw-r--r--dbaccess/source/ui/dlg/AdabasStat.src10
-rw-r--r--dbaccess/source/ui/inc/dbu_resource.hrc8
4 files changed, 178 insertions, 69 deletions
diff --git a/dbaccess/source/ui/dlg/AdabasStat.cxx b/dbaccess/source/ui/dlg/AdabasStat.cxx
index d121349c1fb5..f49410a1096f 100644
--- a/dbaccess/source/ui/dlg/AdabasStat.cxx
+++ b/dbaccess/source/ui/dlg/AdabasStat.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: AdabasStat.cxx,v $
*
- * $Revision: 1.6 $
+ * $Revision: 1.7 $
*
- * last change: $Author: fme $ $Date: 2001-06-21 15:07:11 $
+ * last change: $Author: oj $ $Date: 2001-07-04 13:09:12 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -97,6 +97,9 @@
#ifndef _CONNECTIVITY_DBTOOLS_HXX_
#include <connectivity/dbtools.hxx>
#endif
+#ifndef _DBAUI_SQLMESSAGE_HXX_
+#include "sqlmessage.hxx"
+#endif
using namespace dbaui;
DBG_NAME(OAdabasStatistics);
@@ -131,6 +134,7 @@ OAdabasStatistics::OAdabasStatistics( Window* pParent,
,m_ET_MEMORYUSING( this , STR_ADABAS_HELP_MEMORYUSING,ResId(ET_MEMORYUSING))
,m_PB_OK( this , ResId(PB_OK))
,m_xConnection(_xCurrentConnection)
+ ,m_bErrorShown(sal_False)
{
DBG_CTOR(OAdabasStatistics,NULL);
@@ -141,86 +145,143 @@ OAdabasStatistics::OAdabasStatistics( Window* pParent,
return;
Reference<XStatement> xStmt;
Reference<XResultSet> xRes;
- try
- {
- ::rtl::OUString sTable = _rUser.toAsciiUpperCase();
- ::rtl::OUString aStmt(::rtl::OUString::createFromAscii("SELECT SERVERDBSIZE, UNUSEDPAGES FROM "));
- Reference<XPropertySet> xProp(m_xConnection,UNO_QUERY);
-
- aStmt += ::dbtools::quoteTableName(m_xConnection->getMetaData(),sTable);
- aStmt += ::rtl::OUString::createFromAscii(".\"SERVERDBSTATISTICS\"");
- xStmt = m_xConnection->createStatement();
- xRes = xStmt->executeQuery(aStmt);
+ sal_Bool bCanSelect = sal_False;
+ ::rtl::OUString aStmt;
+ ::rtl::OUString sSchema = _rUser.toAsciiUpperCase();
+ Reference<XDatabaseMetaData> xMetaData = m_xConnection->getMetaData();
+ // first read the sizes
+ try
+ {
+ bCanSelect = checkSystemTable(::rtl::OUString::createFromAscii("SERVERDBSTATISTICS"),sSchema);
- Reference<XRow> xRow(xRes,UNO_QUERY);
- // first the db sizes
- if(xRes.is() && xRes->next())
+ if(bCanSelect)
{
- double nUsedPages = xRow->getInt(1) / 256;
- double nFreePages = xRow->getInt(2) / 256;
+ aStmt = ::rtl::OUString::createFromAscii("SELECT SERVERDBSIZE, UNUSEDPAGES FROM ");
- m_ET_SIZE.SetText(::rtl::OUString::valueOf((INT32)nUsedPages));
- m_ET_FREESIZE.SetText(::rtl::OUString::valueOf((INT32)nFreePages));
- m_ET_MEMORYUSING.SetValue(((nUsedPages-nFreePages)/nUsedPages)*100);
- }
-
- xRow = NULL;
- ::comphelper::disposeComponent(xRes);
+ aStmt += ::dbtools::quoteTableName(xMetaData,sSchema);
+ aStmt += ::rtl::OUString::createFromAscii(".\"SERVERDBSTATISTICS\"");
- // then the db files
- aStmt = ::rtl::OUString::createFromAscii("SELECT DEVSPACENAME FROM ");
- aStmt += ::dbtools::quoteTableName(m_xConnection->getMetaData(),sTable);
- aStmt += ::rtl::OUString::createFromAscii(".\"DATADEVSPACES\"");
- xRes = xStmt->executeQuery(aStmt);
+ xStmt = m_xConnection->createStatement();
+ xRes = xStmt->executeQuery(aStmt);
- xRow = Reference<XRow>(xRes,UNO_QUERY);
- while(xRes.is() && xRes->next())
- {
- m_LB_DATADEVS.InsertEntry(xRow->getString(1));
- }
- xRow = NULL;
- ::comphelper::disposeComponent(xRes);
- aStmt = ::rtl::OUString::createFromAscii("SELECT * FROM ");
- aStmt += ::dbtools::quoteTableName(m_xConnection->getMetaData(),sTable);
- aStmt += ::rtl::OUString::createFromAscii(".CONFIGURATION WHERE DESCRIPTION LIKE 'SYS%DEVSPACE%NAME'");
- xRes = xStmt->executeQuery(aStmt);
- if(xRes.is() && xRes->next())
- {
- xRow = Reference<XRow>(xRes,UNO_QUERY);
- m_ET_SYSDEVSPACE.SetText(xRow->getString(2));
- }
- xRow = NULL;
- ::comphelper::disposeComponent(xRes);
+ Reference<XRow> xRow(xRes,UNO_QUERY);
+ // first the db sizes
+ if(xRes.is() && xRes->next())
+ {
+ double nUsedPages = xRow->getInt(1) / 256;
+ double nFreePages = xRow->getInt(2) / 256;
+ m_ET_SIZE.SetText(::rtl::OUString::valueOf((INT32)nUsedPages));
+ m_ET_FREESIZE.SetText(::rtl::OUString::valueOf((INT32)nFreePages));
+ m_ET_MEMORYUSING.SetValue(((nUsedPages-nFreePages)/nUsedPages)*100);
+ }
+ else
+ showError();
- aStmt = ::rtl::OUString::createFromAscii("SELECT * FROM ");
- aStmt += ::dbtools::quoteTableName(m_xConnection->getMetaData(),sTable);
- aStmt += ::rtl::OUString::createFromAscii(".CONFIGURATION WHERE DESCRIPTION = 'TRANSACTION LOG NAME'");
- xRes = xStmt->executeQuery(aStmt);
- if(xRes.is() && xRes->next())
- {
- xRow = Reference<XRow>(xRes,UNO_QUERY);
- m_ET_TRANSACTIONLOG.SetText(xRow->getString(2));
+ xRow = NULL;
}
- xRow = NULL;
- ::comphelper::disposeComponent(xRes);
- ::comphelper::disposeComponent(xStmt);
+ else
+ showError();
}
catch(const SQLException& e)
{
- ::comphelper::disposeComponent(xRes);
- ::comphelper::disposeComponent(xStmt);
- showError(SQLExceptionInfo(e),pParent,_xFactory);
+ ::dbaui::showError(SQLExceptionInfo(e),pParent,_xFactory);
}
catch(const Exception&)
{
- ::comphelper::disposeComponent(xRes);
- ::comphelper::disposeComponent(xStmt);
OSL_ENSURE(sal_False, "OAdabasStatistics::OAdabasStatistics: caught an exception!");
}
+ ::comphelper::disposeComponent(xStmt);
+
+ // now fill the datadev spaces
+ if(bCanSelect)
+ {
+ try
+ {
+ bCanSelect = checkSystemTable(::rtl::OUString::createFromAscii("DATADEVSPACES"),sSchema);
+
+ if(bCanSelect)
+ {
+ // then the db files
+ aStmt = ::rtl::OUString::createFromAscii("SELECT DEVSPACENAME FROM ");
+ aStmt += ::dbtools::quoteTableName(xMetaData,sSchema);
+ aStmt += ::rtl::OUString::createFromAscii(".\"DATADEVSPACES\"");
+ xStmt = m_xConnection->createStatement();
+ xRes = xStmt->executeQuery(aStmt);
+
+ Reference<XRow> xRow(xRes,UNO_QUERY);
+ while(xRes.is() && xRes->next())
+ {
+ m_LB_DATADEVS.InsertEntry(xRow->getString(1));
+ }
+ if(!m_LB_DATADEVS.GetEntryCount())
+ showError();
+ }
+ else
+ showError();
+ }
+ catch(const SQLException& e)
+ {
+ ::dbaui::showError(SQLExceptionInfo(e),pParent,_xFactory);
+ }
+ catch(const Exception&)
+ {
+ OSL_ENSURE(sal_False, "OAdabasStatistics::OAdabasStatistics: caught an exception!");
+ }
+ ::comphelper::disposeComponent(xStmt);
+
+ // now fill the sysdatadev spaces
+ if(bCanSelect)
+ {
+ try
+ {
+ bCanSelect = checkSystemTable(::rtl::OUString::createFromAscii("CONFIGURATION"),sSchema);
+
+ if(bCanSelect)
+ {
+ aStmt = ::rtl::OUString::createFromAscii("SELECT * FROM ");
+ aStmt += ::dbtools::quoteTableName(xMetaData,sSchema);
+ aStmt += ::rtl::OUString::createFromAscii(".CONFIGURATION WHERE DESCRIPTION LIKE 'SYS%DEVSPACE%NAME'");
+ xStmt = m_xConnection->createStatement();
+ xRes = xStmt->executeQuery(aStmt);
+ if(xRes.is() && xRes->next())
+ {
+ Reference<XRow> xRow(xRes,UNO_QUERY);
+ m_ET_SYSDEVSPACE.SetText(xRow->getString(2));
+ }
+ else
+ showError();
+
+ aStmt = ::rtl::OUString::createFromAscii("SELECT * FROM ");
+ aStmt += ::dbtools::quoteTableName(xMetaData,sSchema);
+ aStmt += ::rtl::OUString::createFromAscii(".CONFIGURATION WHERE DESCRIPTION = 'TRANSACTION LOG NAME'");
+ xRes = xStmt->executeQuery(aStmt);
+ if(xRes.is() && xRes->next())
+ {
+ Reference<XRow> xRow(xRes,UNO_QUERY);
+ m_ET_TRANSACTIONLOG.SetText(xRow->getString(2));
+ }
+ else
+ showError();
+ }
+ else
+ showError();
+ }
+ catch(const SQLException& e)
+ {
+ ::dbaui::showError(SQLExceptionInfo(e),pParent,_xFactory);
+ }
+ catch(const Exception&)
+ {
+ OSL_ENSURE(sal_False, "OAdabasStatistics::OAdabasStatistics: caught an exception!");
+ }
+ ::comphelper::disposeComponent(xStmt);
+ }
+ }
+
m_ET_SYSDEVSPACE.SetSpecialReadOnly(sal_True);
m_ET_TRANSACTIONLOG.SetSpecialReadOnly(sal_True);
m_LB_DATADEVS.SetSpecialReadOnly(sal_True);
@@ -234,5 +295,38 @@ OAdabasStatistics::~OAdabasStatistics()
DBG_DTOR(OAdabasStatistics,NULL);
}
// -----------------------------------------------------------------------------
+sal_Bool OAdabasStatistics::checkSystemTable(const ::rtl::OUString& _rsSystemTable, ::rtl::OUString& _rsSchemaName )
+{
+ sal_Bool bCanSelect = sal_False;
+ Reference<XResultSet> xRes = m_xConnection->getMetaData()->getTablePrivileges(Any(),::rtl::OUString::createFromAscii("%"), _rsSystemTable);
+ if(xRes.is())
+ {
+ Reference<XRow> xRow(xRes,UNO_QUERY);
+ static const ::rtl::OUString sSelect = ::rtl::OUString::createFromAscii("SELECT");
+ // first the db sizes
+ while(xRes.is() && xRes->next())
+ {
+ _rsSchemaName = xRow->getString(2);
+ if(sSelect == xRow->getString(6) && !xRow->wasNull())
+ {
+ bCanSelect = sal_True;
+ break;
+ }
+ }
+ ::comphelper::disposeComponent(xRes);
+ }
+ return bCanSelect;
+}
+// -----------------------------------------------------------------------------
+void OAdabasStatistics::showError()
+{
+ if(!m_bErrorShown)
+ {
+ OSQLMessageBox aMsg(GetParent(),GetText(),String(ModuleRes(STR_ADABAS_ERROR_SYSTEMTABLES)));
+ aMsg.Execute();
+ m_bErrorShown = sal_True;
+ }
+}
+// -----------------------------------------------------------------------------
}
diff --git a/dbaccess/source/ui/dlg/AdabasStat.hxx b/dbaccess/source/ui/dlg/AdabasStat.hxx
index 5a918fc1df6e..f3aa08ce214f 100644
--- a/dbaccess/source/ui/dlg/AdabasStat.hxx
+++ b/dbaccess/source/ui/dlg/AdabasStat.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: AdabasStat.hxx,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: fme $ $Date: 2001-06-21 15:07:11 $
+ * last change: $Author: oj $ $Date: 2001-07-04 13:09:12 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -112,6 +112,11 @@ namespace dbaui
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >
m_xConnection; /// valid as long as the page is active
+ sal_Bool m_bErrorShown; // true when we shown already the error
+
+ // check if the given table is accessable by the connected user
+ sal_Bool checkSystemTable(const ::rtl::OUString& _rsSystemTable, ::rtl::OUString& _rsSchemaName );
+ void showError();
public:
OAdabasStatistics( Window* pParent,
diff --git a/dbaccess/source/ui/dlg/AdabasStat.src b/dbaccess/source/ui/dlg/AdabasStat.src
index 724240ef229c..69c86dbbb8a8 100644
--- a/dbaccess/source/ui/dlg/AdabasStat.src
+++ b/dbaccess/source/ui/dlg/AdabasStat.src
@@ -2,9 +2,9 @@
*
* $RCSfile: AdabasStat.src,v $
*
- * $Revision: 1.15 $
+ * $Revision: 1.16 $
*
- * last change: $Author: kz $ $Date: 2001-06-29 02:08:06 $
+ * last change: $Author: oj $ $Date: 2001-07-04 13:09:12 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -544,6 +544,12 @@ String STR_ADABAS_HELP_MEMORYUSING
Text[ finnish ] = "Zur Zeit verbrauchter Speicherplatz";
};
+String STR_ADABAS_ERROR_SYSTEMTABLES
+{
+ Text = "Es knnen keine Informationen angezeigt werden, da keine Zugriffsberechtigung auf die bentigten Systemtabellen besteht!" ;
+ Text [ English ] = "Could no display the information. No access rights for system tables." ;
+};
+
diff --git a/dbaccess/source/ui/inc/dbu_resource.hrc b/dbaccess/source/ui/inc/dbu_resource.hrc
index d2270757723c..af3100dc2b86 100644
--- a/dbaccess/source/ui/inc/dbu_resource.hrc
+++ b/dbaccess/source/ui/inc/dbu_resource.hrc
@@ -2,9 +2,9 @@
*
* $RCSfile: dbu_resource.hrc,v $
*
- * $Revision: 1.52 $
+ * $Revision: 1.53 $
*
- * last change: $Author: oj $ $Date: 2001-07-03 07:46:45 $
+ * last change: $Author: oj $ $Date: 2001-07-04 13:09:13 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -438,6 +438,7 @@
#define STR_TABLE_PRIV_DROP RID_STRING_START + 177
#define STR_TABLE_PRIV_NAME RID_STRING_START + 178
#define STR_DSBROWSER_TITLE RID_STRING_START + 179
+#define STR_ADABAS_ERROR_SYSTEMTABLES RID_STRING_START + 180
//========================================================================
// untyped resources
@@ -452,6 +453,9 @@
/*************************************************************************
* history:
* $Log: not supported by cvs2svn $
+ * Revision 1.52 2001/07/03 07:46:45 oj
+ * #80211# set title for datasource browser
+ *
* Revision 1.51 2001/06/20 12:25:48 oj
* #88434# new query msg
*