LibreOffice Module connectivity (master) 1
WDatabaseMetaData.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
22#include <com/sun/star/sdbc/SQLException.hpp>
23#include <com/sun/star/text/XTextDocument.hpp>
24#include <com/sun/star/text/XTextTablesSupplier.hpp>
25
26using namespace ::com::sun::star;
27
29{
31 : OComponentDatabaseMetaData(pConnection)
32{
33}
34
36
38{
39 ::osl::MutexGuard aGuard(m_aMutex);
40
41 return "sdbc:writer:" + m_pConnection->getURL();
42}
43
44uno::Reference<sdbc::XResultSet> SAL_CALL OWriterDatabaseMetaData::getTables(
45 const uno::Any& /*catalog*/, const OUString& /*schemaPattern*/,
46 const OUString& tableNamePattern, const uno::Sequence<OUString>& types)
47{
48 ::osl::MutexGuard aGuard(m_aMutex);
49
52
53 // check if ORowSetValue type is given
54 // when no types are given then we have to return all tables e.g. TABLE
55
56 OUString aTable("TABLE");
57
58 bool bTableFound = true;
59 sal_Int32 nLength = types.getLength();
60 if (nLength)
61 {
62 bTableFound = false;
63
64 const OUString* pIter = types.getConstArray();
65 const OUString* pEnd = pIter + nLength;
66 for (; pIter != pEnd; ++pIter)
67 {
68 if (*pIter == aTable)
69 {
70 bTableFound = true;
71 break;
72 }
73 }
74 }
75 if (!bTableFound)
76 return pResult;
77
78 // get the table names from the document
79
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();
88
90 sal_Int32 nTableCount = aTableNames.getLength();
91 for (sal_Int32 nTable = 0; nTable < nTableCount; nTable++)
92 {
93 const OUString& rName = aTableNames[nTable];
94 if (match(tableNamePattern, rName, '\0'))
95 {
96 ODatabaseMetaDataResultSet::ORow aRow{ nullptr, nullptr, nullptr };
97 aRow.reserve(6);
98 aRow.push_back(new ORowSetValueDecorator(rName));
99 aRow.push_back(new ORowSetValueDecorator(aTable));
101 aRows.push_back(aRow);
102 }
103 }
104
105 pResult->setRows(std::move(aRows));
106
107 return pResult;
108}
109
110} // namespace
111
112/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static ORowSetValueDecoratorRef const & getEmptyValue()
return an empty ORowSetValueDecorator
std::vector< ORowSetValueDecoratorRef > ORow
@ eTables
describes a result set as expected by XDatabaseMetaData::getTables
const OUString & getURL() const
Definition: TConnection.hxx:62
ORowSetValueDecorator decorates an ORowSetValue so the value is "refcounted".
Definition: FValue.hxx:402
const css::uno::Reference< css::text::XTextDocument > & getDoc() const
css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTables(const css::uno::Any &catalog, const OUString &schemaPattern, const OUString &tableNamePattern, const css::uno::Sequence< OUString > &types) override
OWriterDatabaseMetaData(file::OConnection *pConnection)
mutable::osl::Mutex m_aMutex
bool match(const sal_Unicode *pWild, const sal_Unicode *pStr, const sal_Unicode cEscape)
Definition: CommonTools.cxx:51
sal_Int32 nLength