nss: upgrade to release 3.73
[LibreOffice.git] / connectivity / source / drivers / dbase / DDatabaseMetaData.cxx
blobb896e942cb01a748ff61bd4d7bbe2120fa5f1eef
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 <dbase/DDatabaseMetaData.hxx>
21 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
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/beans/XPropertySet.hpp>
26 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
27 #include <com/sun/star/sdbcx/XIndexesSupplier.hpp>
28 #include <FDatabaseMetaDataResultSet.hxx>
29 #include <dbase/DIndex.hxx>
30 #include <connectivity/FValue.hxx>
31 #include <comphelper/processfactory.hxx>
32 #include <comphelper/servicehelper.hxx>
33 #include <comphelper/types.hxx>
34 #include <ucbhelper/content.hxx>
36 using namespace ::comphelper;
37 using namespace connectivity::dbase;
38 using namespace connectivity;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::beans;
41 using namespace ::com::sun::star::sdbcx;
42 using namespace ::com::sun::star::sdbc;
43 using namespace ::com::sun::star::container;
44 using namespace ::com::sun::star::ucb;
45 using namespace ::com::sun::star::lang;
47 ODbaseDatabaseMetaData::ODbaseDatabaseMetaData(::connectivity::file::OConnection* _pCon) :ODatabaseMetaData(_pCon)
51 ODbaseDatabaseMetaData::~ODbaseDatabaseMetaData()
55 Reference< XResultSet > ODbaseDatabaseMetaData::impl_getTypeInfo_throw( )
57 ::osl::MutexGuard aGuard( m_aMutex );
59 ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo);
60 Reference< XResultSet > xRef = pResult;
62 static ODatabaseMetaDataResultSet::ORows aRows;
63 if(aRows.empty())
65 ODatabaseMetaDataResultSet::ORow aRow;
66 aRow.reserve(19);
68 aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
69 aRow.push_back(new ORowSetValueDecorator(OUString("VARCHAR")));
70 aRow.push_back(new ORowSetValueDecorator(DataType::VARCHAR));
71 aRow.push_back(new ORowSetValueDecorator(sal_Int32(254)));
72 aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue());
73 aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue());
74 aRow.push_back(new ORowSetValueDecorator(OUString("length")));
75 aRow.push_back(new ORowSetValueDecorator(sal_Int32(ColumnValue::NULLABLE)));
76 aRow.push_back(ODatabaseMetaDataResultSet::get1Value());
77 aRow.push_back(new ORowSetValueDecorator(sal_Int32(ColumnSearch::FULL)));
78 aRow.push_back(ODatabaseMetaDataResultSet::get1Value());
79 aRow.push_back(ODatabaseMetaDataResultSet::get0Value());
80 aRow.push_back(ODatabaseMetaDataResultSet::get0Value());
81 aRow.push_back(new ORowSetValueDecorator(OUString("C")));
82 aRow.push_back(ODatabaseMetaDataResultSet::get0Value());
83 aRow.push_back(ODatabaseMetaDataResultSet::get0Value());
84 aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
85 aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
86 aRow.push_back(new ORowSetValueDecorator(sal_Int32(10)));
88 aRows.push_back(aRow);
90 aRow[1] = new ORowSetValueDecorator(OUString("LONGVARCHAR"));
91 aRow[2] = new ORowSetValueDecorator(DataType::LONGVARCHAR);
92 aRow[3] = new ORowSetValueDecorator(sal_Int32(2147483647));
93 aRow[6] = new ORowSetValueDecorator();
94 aRow[13] = new ORowSetValueDecorator(OUString("M"));
95 aRows.push_back(aRow);
97 aRow[1] = new ORowSetValueDecorator(OUString("DATE"));
98 aRow[2] = new ORowSetValueDecorator(DataType::DATE);
99 aRow[3] = new ORowSetValueDecorator(sal_Int32(10));
100 aRow[13] = new ORowSetValueDecorator(OUString("D"));
101 aRows.push_back(aRow);
103 aRow[1] = new ORowSetValueDecorator(OUString("BOOLEAN"));
104 aRow[2] = new ORowSetValueDecorator(DataType::BIT);
105 aRow[3] = ODatabaseMetaDataResultSet::get1Value();
106 aRow[4] = ODatabaseMetaDataResultSet::getEmptyValue();
107 aRow[5] = ODatabaseMetaDataResultSet::getEmptyValue();
108 aRow[6] = new ORowSetValueDecorator(OUString());
109 aRow[9] = ODatabaseMetaDataResultSet::getBasicValue();
110 aRow[13] = new ORowSetValueDecorator(OUString("L"));
111 aRows.push_back(aRow);
113 aRow[1] = new ORowSetValueDecorator(OUString("DOUBLE"));
114 aRow[2] = new ORowSetValueDecorator(DataType::DOUBLE);
115 aRow[3] = new ORowSetValueDecorator(sal_Int32(8));
116 aRow[13] = new ORowSetValueDecorator(OUString("B"));
117 aRows.push_back(aRow);
119 aRow[11] = new ORowSetValueDecorator(true);
120 aRow[13] = new ORowSetValueDecorator(OUString("Y"));
121 aRows.push_back(aRow);
123 aRow[1] = new ORowSetValueDecorator(OUString("TIMESTAMP"));
124 aRow[2] = new ORowSetValueDecorator(DataType::TIMESTAMP);
125 aRow[11] = new ORowSetValueDecorator(false);
126 aRow[13] = new ORowSetValueDecorator(OUString("T"));
127 aRows.push_back(aRow);
129 aRow[1] = new ORowSetValueDecorator(OUString("INTEGER"));
130 aRow[2] = new ORowSetValueDecorator(DataType::INTEGER);
131 aRow[3] = new ORowSetValueDecorator(sal_Int32(10));
132 aRow[13] = new ORowSetValueDecorator(OUString("I"));
133 aRows.push_back(aRow);
135 aRow[1] = new ORowSetValueDecorator(OUString("DECIMAL"));
136 aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL);
137 aRow[3] = new ORowSetValueDecorator(sal_Int32(20));
138 aRow[6] = new ORowSetValueDecorator(OUString("length,scale"));
139 aRow[13] = new ORowSetValueDecorator(OUString("F"));
140 aRows.push_back(aRow);
142 aRow[1] = new ORowSetValueDecorator(OUString("NUMERIC"));
143 aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL);
144 aRow[3] = new ORowSetValueDecorator(sal_Int32(16));
145 aRow[13] = new ORowSetValueDecorator(OUString("N"));
146 aRow[15] = new ORowSetValueDecorator(sal_Int32(16));
147 aRows.push_back(aRow);
150 pResult->setRows(aRows);
151 return xRef;
154 Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getColumns(
155 const Any& /*catalog*/, const OUString& /*schemaPattern*/, const OUString& tableNamePattern,
156 const OUString& columnNamePattern )
158 ::osl::MutexGuard aGuard( m_aMutex );
160 Reference< XTablesSupplier > xTables = m_pConnection->createCatalog();
161 if(!xTables.is())
162 throw SQLException();
164 Reference< XNameAccess> xNames = xTables->getTables();
165 if(!xNames.is())
166 throw SQLException();
168 ODatabaseMetaDataResultSet::ORows aRows;
169 ODatabaseMetaDataResultSet::ORow aRow(19);
173 aRow[10] = new ORowSetValueDecorator(sal_Int32(10));
174 Sequence< OUString> aTabNames(xNames->getElementNames());
175 const OUString* pTabBegin = aTabNames.getConstArray();
176 const OUString* pTabEnd = pTabBegin + aTabNames.getLength();
177 for(;pTabBegin != pTabEnd;++pTabBegin)
179 if(match(tableNamePattern,*pTabBegin,'\0'))
181 Reference< XColumnsSupplier> xTable(
182 xNames->getByName(*pTabBegin), css::uno::UNO_QUERY);
183 OSL_ENSURE(xTable.is(),"Table not found! Normally an exception had to be thrown here!");
184 aRow[3] = new ORowSetValueDecorator(*pTabBegin);
186 Reference< XNameAccess> xColumns = xTable->getColumns();
187 if(!xColumns.is())
188 throw SQLException();
190 Sequence< OUString> aColNames(xColumns->getElementNames());
192 const OUString* pBegin = aColNames.getConstArray();
193 const OUString* pEnd = pBegin + aColNames.getLength();
194 Reference< XPropertySet> xColumn;
195 for(sal_Int32 i=1;pBegin != pEnd;++pBegin,++i)
197 if(match(columnNamePattern,*pBegin,'\0'))
199 aRow[4] = new ORowSetValueDecorator(*pBegin);
201 xColumn.set(
202 xColumns->getByName(*pBegin), css::uno::UNO_QUERY);
203 OSL_ENSURE(xColumn.is(),"Columns contains a column who isn't a fastpropertyset!");
204 aRow[5] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))));
205 aRow[6] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))));
206 aRow[7] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))));
207 aRow[9] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))));
208 aRow[11] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))));
209 aRow[13] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE))));
210 switch(static_cast<sal_Int32>(aRow[5]->getValue()))
212 case DataType::CHAR:
213 case DataType::VARCHAR:
214 aRow[16] = new ORowSetValueDecorator(sal_Int32(254));
215 break;
216 case DataType::LONGVARCHAR:
217 aRow[16] = new ORowSetValueDecorator(sal_Int32(65535));
218 break;
219 default:
220 aRow[16] = new ORowSetValueDecorator(sal_Int32(0));
222 aRow[17] = new ORowSetValueDecorator(i);
223 switch(sal_Int32(aRow[11]->getValue()))
225 case ColumnValue::NO_NULLS:
226 aRow[18] = new ORowSetValueDecorator(OUString("NO"));
227 break;
228 case ColumnValue::NULLABLE:
229 aRow[18] = new ORowSetValueDecorator(OUString("YES"));
230 break;
231 default:
232 aRow[18] = new ORowSetValueDecorator(OUString());
234 aRows.push_back(aRow);
240 catch (const WrappedTargetException& e)
242 SQLException aSql;
243 if (e.TargetException >>= aSql)
244 throw aSql;
245 throw WrappedTargetRuntimeException(e.Message, e.Context, e.TargetException);
247 ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns);
248 Reference< XResultSet > xRef = pResult;
249 pResult->setRows(aRows);
251 return xRef;
254 Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getIndexInfo(
255 const Any& /*catalog*/, const OUString& /*schema*/, const OUString& table,
256 sal_Bool unique, sal_Bool /*approximate*/ )
258 ::osl::MutexGuard aGuard( m_aMutex );
260 Reference< XTablesSupplier > xTables = m_pConnection->createCatalog();
261 if(!xTables.is())
262 throw SQLException();
264 Reference< XNameAccess> xNames = xTables->getTables();
265 if(!xNames.is())
266 throw SQLException();
268 ODatabaseMetaDataResultSet::ORows aRows;
269 ODatabaseMetaDataResultSet::ORow aRow(14);
271 aRow[5] = new ORowSetValueDecorator(OUString());
272 aRow[10] = new ORowSetValueDecorator(OUString("A"));
274 Reference< XIndexesSupplier> xTable(
275 xNames->getByName(table), css::uno::UNO_QUERY);
276 aRow[3] = new ORowSetValueDecorator(table);
277 aRow[7] = new ORowSetValueDecorator(sal_Int32(3));
279 Reference< XNameAccess> xIndexes = xTable->getIndexes();
280 if(!xIndexes.is())
281 throw SQLException();
283 Sequence< OUString> aIdxNames(xIndexes->getElementNames());
285 const OUString* pBegin = aIdxNames.getConstArray();
286 const OUString* pEnd = pBegin + aIdxNames.getLength();
287 Reference< XPropertySet> xIndex;
288 for(;pBegin != pEnd;++pBegin)
290 xIndex.set(xIndexes->getByName(*pBegin), css::uno::UNO_QUERY);
291 OSL_ENSURE(xIndex.is(),"Indexes contains a column who isn't a fastpropertyset!");
293 if(unique && !getBOOL(xIndex->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISUNIQUE))))
294 continue;
295 aRow[4] = new ORowSetValueDecorator(getBOOL(xIndex->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISUNIQUE))));
296 aRow[6] = new ORowSetValueDecorator(*pBegin);
298 auto pIndex = comphelper::getUnoTunnelImplementation<ODbaseIndex>(xIndex);
299 if(pIndex)
301 aRow[11] = new ORowSetValueDecorator(static_cast<sal_Int32>(pIndex->getHeader().db_maxkeys));
302 aRow[12] = new ORowSetValueDecorator(static_cast<sal_Int32>(pIndex->getHeader().db_pagecount));
305 Reference<XColumnsSupplier> xColumnsSup(xIndex,UNO_QUERY);
306 Reference< XNameAccess> xColumns = xColumnsSup->getColumns();
307 Sequence< OUString> aColNames(xColumns->getElementNames());
309 const OUString* pColBegin = aColNames.getConstArray();
310 const OUString* pColEnd = pColBegin + aColNames.getLength();
311 for(sal_Int32 j=1;pColBegin != pColEnd;++pColBegin,++j)
313 aRow[8] = new ORowSetValueDecorator(j);
314 aRow[9] = new ORowSetValueDecorator(*pColBegin);
315 aRows.push_back(aRow);
319 ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eIndexInfo);
320 Reference< XResultSet > xRef = pResult;
321 pResult->setRows(aRows);
322 return xRef;
325 OUString SAL_CALL ODbaseDatabaseMetaData::getURL( )
327 ::osl::MutexGuard aGuard( m_aMutex );
328 return "sdbc:dbase:" + m_pConnection->getURL();
331 sal_Int32 SAL_CALL ODbaseDatabaseMetaData::getMaxBinaryLiteralLength( )
333 return SAL_MAX_INT32;
336 sal_Int32 SAL_CALL ODbaseDatabaseMetaData::getMaxCharLiteralLength( )
338 return 254;
341 sal_Int32 SAL_CALL ODbaseDatabaseMetaData::getMaxColumnNameLength( )
343 return 10;
346 sal_Int32 SAL_CALL ODbaseDatabaseMetaData::getMaxColumnsInIndex( )
348 return 1;
351 sal_Int32 SAL_CALL ODbaseDatabaseMetaData::getMaxColumnsInTable( )
353 return 128;
356 sal_Bool SAL_CALL ODbaseDatabaseMetaData::supportsAlterTableWithAddColumn( )
358 return true;
361 sal_Bool SAL_CALL ODbaseDatabaseMetaData::supportsAlterTableWithDropColumn( )
363 return false;
366 sal_Bool SAL_CALL ODbaseDatabaseMetaData::isReadOnly( )
368 ::osl::MutexGuard aGuard( m_aMutex );
370 bool bReadOnly = false;
371 ::ucbhelper::Content aFile(m_pConnection->getContent(),Reference< XCommandEnvironment >(), comphelper::getProcessComponentContext());
372 aFile.getPropertyValue("IsReadOnly") >>= bReadOnly;
374 return bReadOnly;
377 bool ODbaseDatabaseMetaData::impl_storesMixedCaseQuotedIdentifiers_throw( )
379 return true;
382 bool ODbaseDatabaseMetaData::impl_supportsMixedCaseQuotedIdentifiers_throw( )
384 return true;
388 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */