summaryrefslogtreecommitdiffstats
path: root/connectivity/source/drivers/mork/MDatabaseMetaDataHelper.cxx
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
commit940b4d1848e8c70ab7642901a68594e8016caffc (patch)
treeeb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /connectivity/source/drivers/mork/MDatabaseMetaDataHelper.cxx
parentInitial commit. (diff)
downloadlibreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz
libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'connectivity/source/drivers/mork/MDatabaseMetaDataHelper.cxx')
-rw-r--r--connectivity/source/drivers/mork/MDatabaseMetaDataHelper.cxx123
1 files changed, 123 insertions, 0 deletions
diff --git a/connectivity/source/drivers/mork/MDatabaseMetaDataHelper.cxx b/connectivity/source/drivers/mork/MDatabaseMetaDataHelper.cxx
new file mode 100644
index 000000000..ca699bafa
--- /dev/null
+++ b/connectivity/source/drivers/mork/MDatabaseMetaDataHelper.cxx
@@ -0,0 +1,123 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "MConnection.hxx"
+#include "MDatabaseMetaDataHelper.hxx"
+
+// do we need it?
+static ::osl::Mutex m_aMetaMutex;
+
+#include <sal/log.hxx>
+
+#include "MorkParser.hxx"
+
+using namespace connectivity;
+using namespace connectivity::mork;
+
+
+MDatabaseMetaDataHelper::MDatabaseMetaDataHelper()
+{
+ SAL_INFO("connectivity.mork", "=> MDatabaseMetaDataHelper::MDatabaseMetaDataHelper()" );
+}
+
+
+MDatabaseMetaDataHelper::~MDatabaseMetaDataHelper()
+{
+}
+
+void MDatabaseMetaDataHelper::getTableStrings( OConnection* _pCon,
+ std::vector< OUString >& _rStrings)
+{
+ SAL_INFO("connectivity.mork", "=> MDatabaseMetaDataHelper::getTableStrings()");
+
+ /* add default tables */
+ _rStrings.push_back("AddressBook");
+ _rStrings.push_back("CollectedAddressBook");
+
+ /* retrieve list table names (not from collected ab) */
+ std::set<std::string> lists;
+ MorkParser* pMork = _pCon->getMorkParser("AddressBook");
+ pMork->retrieveLists(lists);
+ for (auto const& elem : lists)
+ {
+ OUString groupTableName = OStringToOUString(elem.c_str(), RTL_TEXTENCODING_UTF8);
+ SAL_INFO("connectivity.mork", "add Table " << groupTableName);
+
+ _rStrings.push_back(groupTableName);
+ // remember the list in the mork parser, we'll use it later
+ pMork->lists_.push_back(groupTableName);
+ }
+
+ std::set<std::string> lists_history;
+ pMork = _pCon->getMorkParser("CollectedAddressBook");
+ pMork->retrieveLists(lists_history);
+ for (auto const& elem : lists_history)
+ {
+ OUString groupTableName = OStringToOUString(elem.c_str(), RTL_TEXTENCODING_UTF8);
+ SAL_INFO("connectivity.mork", "add Table " << groupTableName);
+
+ _rStrings.push_back(groupTableName);
+ // remember the list in the mork parser, we'll use it later
+ pMork->lists_.push_back(groupTableName);
+ }
+}
+
+void MDatabaseMetaDataHelper::getTables( OConnection* _pCon,
+ const OUString& tableNamePattern,
+ ODatabaseMetaDataResultSet::ORows& _rRows)
+{
+
+ SAL_INFO("connectivity.mork", "=> MDatabaseMetaDataHelper::getTables()");
+
+ static ODatabaseMetaDataResultSet::ORows aRows;
+
+ SAL_INFO("connectivity.mork", "=> MDatabaseMetaDataHelper::getTables()" );
+ SAL_INFO("connectivity.mork", "tableNamePattern : " << tableNamePattern);
+ ::osl::MutexGuard aGuard( m_aMetaMutex );
+
+ ODatabaseMetaDataResultSet::ORows().swap(aRows); // this makes real clear where memory is freed as well
+ aRows.clear();
+
+ std::vector< OUString > tables;
+
+ getTableStrings( _pCon, tables );
+
+ for (OUString& aTableName : tables) {
+ ODatabaseMetaDataResultSet::ORow aRow { nullptr, nullptr, nullptr };
+
+ SAL_INFO("connectivity.mork", "TableName: " << aTableName );
+
+
+ // return tables to caller
+ if (match( tableNamePattern, aTableName, '\0' ))
+ {
+ if ( aTableName.isEmpty() ) {
+ aTableName = "AddressBook";
+ }
+
+ SAL_INFO("connectivity.mork", "TableName: " << aTableName);
+
+ aRow.push_back( new ORowSetValueDecorator( aTableName ) ); // Table/View name
+ if ((aTableName == "AddressBook") || (aTableName == "CollectedAddressBook"))
+ {
+ aRow.push_back( new ORowSetValueDecorator( OUString("TABLE") ) ); // Table type
+ }
+ else
+ {
+ aRow.push_back( new ORowSetValueDecorator( OUString("VIEW") ) ); // View type
+ }
+ aRow.push_back( ODatabaseMetaDataResultSet::getEmptyValue() ); // Remarks
+ aRows.push_back(aRow);
+ }
+ }
+
+ _rRows = aRows;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */