bump product version to 7.2.5.1
[LibreOffice.git] / connectivity / source / drivers / writer / WDatabaseMetaData.cxx
blob99c81b7c284011af70c2456713f82061eb90ac43
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <writer/WDatabaseMetaData.hxx>
21 #include <writer/WConnection.hxx>
22 #include <com/sun/star/sdbc/SQLException.hpp>
23 #include <com/sun/star/text/XTextDocument.hpp>
24 #include <com/sun/star/text/XTextTablesSupplier.hpp>
26 using namespace ::com::sun::star;
28 namespace connectivity::writer
30 OWriterDatabaseMetaData::OWriterDatabaseMetaData(file::OConnection* pConnection)
31 : OComponentDatabaseMetaData(pConnection)
35 OWriterDatabaseMetaData::~OWriterDatabaseMetaData() = default;
37 OUString SAL_CALL OWriterDatabaseMetaData::getURL()
39 ::osl::MutexGuard aGuard(m_aMutex);
41 return "sdbc:writer:" + m_pConnection->getURL();
44 uno::Reference<sdbc::XResultSet> SAL_CALL OWriterDatabaseMetaData::getTables(
45 const uno::Any& /*catalog*/, const OUString& /*schemaPattern*/,
46 const OUString& tableNamePattern, const uno::Sequence<OUString>& types)
48 ::osl::MutexGuard aGuard(m_aMutex);
50 rtl::Reference<ODatabaseMetaDataResultSet> pResult
51 = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTables);
53 // check if ORowSetValue type is given
54 // when no types are given then we have to return all tables e.g. TABLE
56 OUString aTable("TABLE");
58 bool bTableFound = true;
59 sal_Int32 nLength = types.getLength();
60 if (nLength)
62 bTableFound = false;
64 const OUString* pIter = types.getConstArray();
65 const OUString* pEnd = pIter + nLength;
66 for (; pIter != pEnd; ++pIter)
68 if (*pIter == aTable)
70 bTableFound = true;
71 break;
75 if (!bTableFound)
76 return pResult;
78 // get the table names from the document
80 OWriterConnection::ODocHolder aDocHolder(static_cast<OWriterConnection*>(m_pConnection));
81 uno::Reference<text::XTextTablesSupplier> xDoc(aDocHolder.getDoc(), uno::UNO_QUERY);
82 if (!xDoc.is())
83 throw sdbc::SQLException();
84 uno::Reference<container::XNameAccess> xTables = xDoc->getTextTables();
85 if (!xTables.is())
86 throw sdbc::SQLException();
87 uno::Sequence<OUString> aTableNames = xTables->getElementNames();
89 ODatabaseMetaDataResultSet::ORows aRows;
90 sal_Int32 nTableCount = aTableNames.getLength();
91 for (sal_Int32 nTable = 0; nTable < nTableCount; nTable++)
93 OUString aName = aTableNames[nTable];
94 if (match(tableNamePattern, aName, '\0'))
96 ODatabaseMetaDataResultSet::ORow aRow{ nullptr, nullptr, nullptr };
97 aRow.reserve(6);
98 aRow.push_back(new ORowSetValueDecorator(aName));
99 aRow.push_back(new ORowSetValueDecorator(aTable));
100 aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
101 aRows.push_back(aRow);
105 pResult->setRows(aRows);
107 return pResult;
110 } // namespace
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */