1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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(u
"TABLE"_ustr
);
58 bool bTableFound
= true;
59 sal_Int32 nLength
= types
.getLength();
64 const OUString
* pIter
= types
.getConstArray();
65 const OUString
* pEnd
= pIter
+ nLength
;
66 for (; pIter
!= pEnd
; ++pIter
)
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
);
83 throw sdbc::SQLException();
84 uno::Reference
<container::XNameAccess
> xTables
= xDoc
->getTextTables();
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 const OUString
& rName
= aTableNames
[nTable
];
94 if (match(tableNamePattern
, rName
, '\0'))
96 ODatabaseMetaDataResultSet::ORow aRow
{ nullptr,
99 new ORowSetValueDecorator(rName
),
100 new ORowSetValueDecorator(aTable
),
101 ODatabaseMetaDataResultSet::getEmptyValue() };
102 aRows
.push_back(aRow
);
106 pResult
->setRows(std::move(aRows
));
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */