LibreOffice Module connectivity (master) 1
component/CDatabaseMetaData.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 <file/FConnection.hxx>
22#include <com/sun/star/sdbc/ColumnSearch.hpp>
23#include <com/sun/star/sdbc/DataType.hpp>
24#include <com/sun/star/sdbc/ColumnValue.hpp>
25#include <com/sun/star/sdbc/SQLException.hpp>
26#include <com/sun/star/beans/XPropertySet.hpp>
27#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
29#include <comphelper/types.hxx>
30
31using namespace connectivity::component;
32using namespace connectivity::file;
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
39OComponentDatabaseMetaData::OComponentDatabaseMetaData(OConnection* _pCon) :ODatabaseMetaData(_pCon)
40{
41}
42
44{
45}
46
48{
50
51 static ODatabaseMetaDataResultSet::ORows aRows = []()
52 {
54 aTmp.reserve(6);
56 {
58 new ORowSetValueDecorator(OUString("VARCHAR")),
59 new ORowSetValueDecorator(DataType::VARCHAR),
60 new ORowSetValueDecorator(sal_Int32(65535)),
64 ODatabaseMetaDataResultSet::get1Value(), // ORowSetValue((sal_Int32)ColumnValue::NULLABLE
66 new ORowSetValueDecorator(sal_Int32(ColumnSearch::CHAR)),
75 new ORowSetValueDecorator(sal_Int32(10))
76 };
77
78 aTmp.push_back(aRow);
79
80 aRow[1] = new ORowSetValueDecorator(OUString("DECIMAL"));
81 aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL);
85 aTmp.push_back(aRow);
86
87 aRow[1] = new ORowSetValueDecorator(OUString("BOOL"));
88 aRow[2] = new ORowSetValueDecorator(DataType::BIT);
89 aRow[3] = new ORowSetValueDecorator(sal_Int32(20));
91 aRow[15] = new ORowSetValueDecorator(sal_Int32(15));
92 aTmp.push_back(aRow);
93
94 aRow[1] = new ORowSetValueDecorator(OUString("DATE"));
95 aRow[2] = new ORowSetValueDecorator(DataType::DATE);
99 aTmp.push_back(aRow);
100
101 aRow[1] = new ORowSetValueDecorator(OUString("TIME"));
102 aRow[2] = new ORowSetValueDecorator(DataType::TIME);
106 aTmp.push_back(aRow);
107
108 aRow[1] = new ORowSetValueDecorator(OUString("TIMESTAMP"));
109 aRow[2] = new ORowSetValueDecorator(DataType::TIMESTAMP);
113 aTmp.push_back(aRow);
114
115 return aTmp;
116 }();
117
118 pResult->setRows(std::move(aRows));
119 return pResult;
120}
121
123 const Any& /*catalog*/, const OUString& /*schemaPattern*/, const OUString& tableNamePattern,
124 const OUString& columnNamePattern )
125{
126 ::osl::MutexGuard aGuard( m_aMutex );
127
128
130 if(!xTables.is())
131 throw SQLException();
132
133 Reference< XNameAccess> xNames = xTables->getTables();
134 if(!xNames.is())
135 throw SQLException();
136
139
140 aRow[10] = new ORowSetValueDecorator(sal_Int32(10));
141
142 Sequence< OUString> aTabNames(xNames->getElementNames());
143 const OUString* pTabIter = aTabNames.getConstArray();
144 const OUString* pTabEnd = pTabIter + aTabNames.getLength();
145 for(;pTabIter != pTabEnd;++pTabIter)
146 {
147 if(match(tableNamePattern,*pTabIter,'\0'))
148 {
149 const Reference< XColumnsSupplier> xTable(xNames->getByName(*pTabIter),UNO_QUERY_THROW);
150 aRow[3] = new ORowSetValueDecorator(*pTabIter);
151
152 const Reference< XNameAccess> xColumns = xTable->getColumns();
153 if(!xColumns.is())
154 throw SQLException();
155
156 const Sequence< OUString> aColNames(xColumns->getElementNames());
157
158 const OUString* pColumnIter = aColNames.getConstArray();
159 const OUString* pEnd = pColumnIter + aColNames.getLength();
161 for(sal_Int32 i=1;pColumnIter != pEnd;++pColumnIter,++i)
162 {
163 if(match(columnNamePattern,*pColumnIter,'\0'))
164 {
165 aRow[4] = new ORowSetValueDecorator( *pColumnIter);
166
167 xColumns->getByName(*pColumnIter) >>= xColumn;
168 OSL_ENSURE(xColumn.is(),"Columns contains a column who isn't a fastpropertyset!");
169 aRow[5] = new ORowSetValueDecorator(::comphelper::getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))));
170 aRow[6] = new ORowSetValueDecorator(::comphelper::getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))));
171 aRow[7] = new ORowSetValueDecorator(::comphelper::getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))));
172 // aRow[8] = xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME));
173 aRow[9] = new ORowSetValueDecorator(::comphelper::getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))));
174 aRow[11] = new ORowSetValueDecorator(::comphelper::getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))));
175 // aRow[12] = xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME));
176 aRow[13] = new ORowSetValueDecorator(::comphelper::getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE))));
177 // aRow[14] = xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME));
178 // aRow[15] = xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME));
179 switch(aRow[5]->getValue().getInt32())
180 {
181 case DataType::CHAR:
182 case DataType::VARCHAR:
183 aRow[16] = new ORowSetValueDecorator(sal_Int32(254));
184 break;
185 case DataType::LONGVARCHAR:
186 aRow[16] = new ORowSetValueDecorator(sal_Int32(65535));
187 break;
188 default:
189 aRow[16] = new ORowSetValueDecorator(sal_Int32(0));
190 }
191 aRow[17] = new ORowSetValueDecorator(i);
192 switch(aRow[11]->getValue().getInt32())
193 {
194 case ColumnValue::NO_NULLS:
195 aRow[18] = new ORowSetValueDecorator(OUString("NO"));
196 break;
197 case ColumnValue::NULLABLE:
198 aRow[18] = new ORowSetValueDecorator(OUString("YES"));
199 break;
200 default:
201 aRow[18] = new ORowSetValueDecorator(OUString());
202 }
203 aRows.push_back(aRow);
204 }
205 }
206 }
207 }
208
210 pResult->setRows(std::move(aRows));
211
212 return pResult;
213}
214
216{
217 return SAL_MAX_INT32;
218}
219
221{
222 return SAL_MAX_INT32;
223}
224
226{
227 return SAL_MAX_INT32;
228}
229
231{
232 return 1;
233}
234
236{
237 return 256;
238}
239
240/* 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
ORowSetValueDecorator decorates an ORowSetValue so the value is "refcounted".
Definition: FValue.hxx:402
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 css::uno::Reference< css::sdbcx::XTablesSupplier > createCatalog()
mutable::osl::Mutex m_aMutex
const OUString & getNameByIndex(sal_Int32 _nIndex) const
Definition: propertyids.cxx:95
Reference< XColumn > xColumn
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]
#define SAL_MAX_INT32