LibreOffice Module connectivity (master) 1
EDatabaseMetaData.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
21#include <com/sun/star/sdbc/ColumnSearch.hpp>
22#include <com/sun/star/sdbc/DataType.hpp>
23#include <com/sun/star/sdbc/ColumnValue.hpp>
24#include <com/sun/star/sdbc/SQLException.hpp>
25#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
27#include <comphelper/types.hxx>
28
29using namespace ::comphelper;
30
31using namespace connectivity;
32using namespace connectivity::flat;
33using namespace ::com::sun::star::uno;
34using namespace ::com::sun::star::beans;
35using namespace ::com::sun::star::sdbcx;
36using namespace ::com::sun::star::sdbc;
37using namespace ::com::sun::star::container;
38
39
40OFlatDatabaseMetaData::OFlatDatabaseMetaData(::connectivity::file::OConnection* _pCon) :ODatabaseMetaData(_pCon)
41{
42}
43
45{
46}
47
49{
51
52 static ODatabaseMetaDataResultSet::ORows aRows = []()
53 {
56 {
58 new ORowSetValueDecorator(OUString("CHAR")) ,
59 new ORowSetValueDecorator(DataType::CHAR) ,
60 new ORowSetValueDecorator(sal_Int32(254)) ,
64 new ORowSetValueDecorator(sal_Int32(ColumnValue::NULLABLE)) ,
66 new ORowSetValueDecorator(sal_Int32(ColumnSearch::CHAR)) ,
75 new ORowSetValueDecorator(sal_Int32(10))
76 };
77
78 tmp.push_back(aRow);
79
80 aRow[1] = new ORowSetValueDecorator(OUString("VARCHAR"));
81 aRow[2] = new ORowSetValueDecorator(DataType::VARCHAR);
84 tmp.push_back(aRow);
85
86
87 aRow[1] = new ORowSetValueDecorator(OUString("LONGVARCHAR"));
88 aRow[2] = new ORowSetValueDecorator(DataType::LONGVARCHAR);
89 aRow[3] = new ORowSetValueDecorator(sal_Int32(65535));
92 tmp.push_back(aRow);
93
94 aRow[1] = new ORowSetValueDecorator(OUString("DATE"));
95 aRow[2] = new ORowSetValueDecorator(DataType::DATE);
96 aRow[3] = new ORowSetValueDecorator(sal_Int32(10));
99 tmp.push_back(aRow);
100
101 aRow[1] = new ORowSetValueDecorator(OUString("TIME"));
102 aRow[2] = new ORowSetValueDecorator(DataType::TIME);
103 aRow[3] = new ORowSetValueDecorator(sal_Int32(8));
106 tmp.push_back(aRow);
107
108 aRow[1] = new ORowSetValueDecorator(OUString("TIMESTAMP"));
109 aRow[2] = new ORowSetValueDecorator(DataType::TIMESTAMP);
110 aRow[3] = new ORowSetValueDecorator(sal_Int32(19));
113 tmp.push_back(aRow);
114
115 aRow[1] = new ORowSetValueDecorator(OUString("BOOL"));
116 aRow[2] = new ORowSetValueDecorator(DataType::BIT);
119 tmp.push_back(aRow);
120
121 aRow[1] = new ORowSetValueDecorator(OUString("DECIMAL"));
122 aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL);
123 aRow[3] = new ORowSetValueDecorator(sal_Int32(20));
124 aRow[15] = new ORowSetValueDecorator(sal_Int32(15));
125 tmp.push_back(aRow);
126
127 aRow[1] = new ORowSetValueDecorator(OUString("DOUBLE"));
128 aRow[2] = new ORowSetValueDecorator(DataType::DOUBLE);
129 aRow[3] = new ORowSetValueDecorator(sal_Int32(20));
131 tmp.push_back(aRow);
132
133 aRow[1] = new ORowSetValueDecorator(OUString("NUMERIC"));
134 aRow[2] = new ORowSetValueDecorator(DataType::NUMERIC);
135 aRow[3] = new ORowSetValueDecorator(sal_Int32(20));
136 aRow[15] = new ORowSetValueDecorator(sal_Int32(20));
137 tmp.push_back(aRow);
138
139 return tmp;
140 }();
141
142 pResult->setRows(std::move(aRows));
143 return pResult;
144}
145
146Reference< XResultSet > SAL_CALL OFlatDatabaseMetaData::getColumns(
147 const Any& /*catalog*/, const OUString& /*schemaPattern*/, const OUString& tableNamePattern,
148 const OUString& columnNamePattern )
149{
150 ::osl::MutexGuard aGuard( m_aMutex );
151
152 Reference< XTablesSupplier > xTables = m_pConnection->createCatalog();
153 if(!xTables.is())
154 throw SQLException();
155
156 Reference< XNameAccess> xNames = xTables->getTables();
157 if(!xNames.is())
158 throw SQLException();
159
162 aRow[10] = new ORowSetValueDecorator(sal_Int32(10));
163 Sequence< OUString> aTabNames(xNames->getElementNames());
164 const OUString* pTabBegin = aTabNames.getConstArray();
165 const OUString* pTabEnd = pTabBegin + aTabNames.getLength();
166 for(;pTabBegin != pTabEnd;++pTabBegin)
167 {
168 if(match(tableNamePattern,*pTabBegin,'\0'))
169 {
170 Reference< XColumnsSupplier> xTable(
171 xNames->getByName(*pTabBegin), css::uno::UNO_QUERY);
172 aRow[3] = new ORowSetValueDecorator(*pTabBegin);
173
174 Reference< XNameAccess> xColumns = xTable->getColumns();
175 if(!xColumns.is())
176 throw SQLException();
177
178 Sequence< OUString> aColNames(xColumns->getElementNames());
179
180 const OUString* pBegin = aColNames.getConstArray();
181 const OUString* pEnd = pBegin + aColNames.getLength();
182 Reference< XPropertySet> xColumn;
183 for(sal_Int32 i=1;pBegin != pEnd;++pBegin,++i)
184 {
185 if(match(columnNamePattern,*pBegin,'\0'))
186 {
187 aRow[4] = new ORowSetValueDecorator(*pBegin);
188
189 xColumn.set(
190 xColumns->getByName(*pBegin), css::uno::UNO_QUERY);
191 OSL_ENSURE(xColumn.is(),"Columns contains a column who isn't a fastpropertyset!");
198
199 switch(aRow[5]->getValue().getInt32())
200 {
201 case DataType::CHAR:
202 case DataType::VARCHAR:
203 aRow[16] = new ORowSetValueDecorator(sal_Int32(254));
204 break;
205 case DataType::LONGVARCHAR:
206 aRow[16] = new ORowSetValueDecorator(sal_Int32(65535));
207 break;
208 default:
209 aRow[16] = new ORowSetValueDecorator(sal_Int32(0));
210 }
211 aRow[17] = new ORowSetValueDecorator(i);
212 switch(aRow[11]->getValue().getInt32())
213 {
214 case ColumnValue::NO_NULLS:
215 aRow[18] = new ORowSetValueDecorator(OUString("NO"));
216 break;
217 case ColumnValue::NULLABLE:
218 aRow[18] = new ORowSetValueDecorator(OUString("YES"));
219 break;
220 default:
221 aRow[18] = new ORowSetValueDecorator(OUString());
222 }
223 aRows.push_back(aRow);
224 }
225 }
226 }
227 }
228
230 pResult->setRows(std::move(aRows));
231
232 return pResult;
233}
234
236{
237 ::osl::MutexGuard aGuard( m_aMutex );
238 return "sdbc:flat:" + m_pConnection->getURL();
239}
240
241
242/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static ORowSetValueDecoratorRef const & getEmptyValue()
return an empty ORowSetValueDecorator
static ORowSetValueDecoratorRef const & getBasicValue()
return an ORowSetValueDecorator with ColumnSearch::BASIC as value
std::vector< ORowSetValueDecoratorRef > ORow
@ eTypeInfo
describes a result set as expected by XDatabaseMetaData::getTypeInfo
@ eColumns
describes a result set as expected by XDatabaseMetaData::getColumns
static ORowSetValueDecoratorRef const & get1Value()
return an ORowSetValueDecorator with 1 as value
static ORowSetValueDecoratorRef const & get0Value()
return an ORowSetValueDecorator with 0 as value
static ORowSetValueDecoratorRef const & getQuoteValue()
return an ORowSetValueDecorator with string ' as value
::dbtools::OPropertyMap & getPropMap()
Definition: TConnection.cxx:68
const OUString & getURL() const
Definition: TConnection.hxx:62
ORowSetValueDecorator decorates an ORowSetValue so the value is "refcounted".
Definition: FValue.hxx:402
virtual css::uno::Reference< css::sdbcx::XTablesSupplier > createCatalog()
virtual css::uno::Reference< css::sdbc::XResultSet > impl_getTypeInfo_throw() override
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getColumns(const css::uno::Any &catalog, const OUString &schemaPattern, const OUString &tableNamePattern, const OUString &columnNamePattern) override
virtual OUString SAL_CALL getURL() override
mutable::osl::Mutex m_aMutex
const OUString & getNameByIndex(sal_Int32 _nIndex) const
Definition: propertyids.cxx:95
Reference< XColumn > xColumn
sal_Int32 getINT32(const Any &_rAny)
OUString getString(const Any &_rAny)
static bool getValue(EContact *pContact, sal_Int32 nColumnNum, GType nType, GValue *pStackValue, bool &_out_rWasNull)
Definition: NResultSet.cxx:243
bool match(const sal_Unicode *pWild, const sal_Unicode *pStr, const sal_Unicode cEscape)
Definition: CommonTools.cxx:51
int i
#define PROPERTY_ID_TYPE
Definition: propertyids.hxx:51
#define PROPERTY_ID_ISNULLABLE
Definition: propertyids.hxx:55
#define PROPERTY_ID_PRECISION
Definition: propertyids.hxx:53
#define PROPERTY_ID_TYPENAME
Definition: propertyids.hxx:52
#define PROPERTY_ID_DEFAULTVALUE
Definition: propertyids.hxx:59
#define PROPERTY_ID_SCALE
Definition: propertyids.hxx:54
const Color aColNames[SC_RANGECOLORS]