fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / connectivity / source / drivers / dbase / DDatabaseMetaData.cxx
blobc4623c0fa2fa7e171d3c6db414461e458455f7f3
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/sdbc/DataType.hpp>
22 #include <com/sun/star/sdbc/ResultSetType.hpp>
23 #include <com/sun/star/sdbc/ColumnValue.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
26 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
27 #include <com/sun/star/sdbcx/XIndexesSupplier.hpp>
28 #include "FDatabaseMetaDataResultSet.hxx"
29 #include <com/sun/star/lang/XUnoTunnel.hpp>
30 #include "dbase/DIndex.hxx"
31 #include "connectivity/FValue.hxx"
32 #include <comphelper/extract.hxx>
33 #include <comphelper/processfactory.hxx>
34 #include <comphelper/types.hxx>
35 #include <ucbhelper/content.hxx>
36 #include <rtl/logfile.hxx>
38 using namespace ::comphelper;
39 using namespace connectivity::dbase;
40 using namespace connectivity;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::beans;
43 using namespace ::com::sun::star::sdbcx;
44 using namespace ::com::sun::star::sdbc;
45 using namespace ::com::sun::star::container;
46 using namespace ::com::sun::star::ucb;
47 using namespace ::com::sun::star::lang;
49 ODbaseDatabaseMetaData::ODbaseDatabaseMetaData(::connectivity::file::OConnection* _pCon) :ODatabaseMetaData(_pCon)
51 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseDatabaseMetaData::ODbaseDatabaseMetaData" );
53 // -------------------------------------------------------------------------
54 ODbaseDatabaseMetaData::~ODbaseDatabaseMetaData()
57 // -------------------------------------------------------------------------
58 Reference< XResultSet > ODbaseDatabaseMetaData::impl_getTypeInfo_throw( )
60 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseDatabaseMetaData::impl_getTypeInfo_throw" );
61 ::osl::MutexGuard aGuard( m_aMutex );
63 ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo);
64 Reference< XResultSet > xRef = pResult;
66 static ODatabaseMetaDataResultSet::ORows aRows;
67 if(aRows.empty())
69 ODatabaseMetaDataResultSet::ORow aRow;
70 aRow.reserve(18);
72 aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
73 aRow.push_back(new ORowSetValueDecorator(OUString("VARCHAR")));
74 aRow.push_back(new ORowSetValueDecorator(DataType::VARCHAR));
75 aRow.push_back(new ORowSetValueDecorator((sal_Int32)254));
76 aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue());
77 aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue());
78 aRow.push_back(new ORowSetValueDecorator(OUString("length")));
79 aRow.push_back(new ORowSetValueDecorator((sal_Int32)ColumnValue::NULLABLE));
80 aRow.push_back(ODatabaseMetaDataResultSet::get1Value());
81 aRow.push_back(new ORowSetValueDecorator((sal_Int32)ColumnSearch::FULL));
82 aRow.push_back(ODatabaseMetaDataResultSet::get1Value());
83 aRow.push_back(ODatabaseMetaDataResultSet::get0Value());
84 aRow.push_back(ODatabaseMetaDataResultSet::get0Value());
85 aRow.push_back(new ORowSetValueDecorator(OUString("C")));
86 aRow.push_back(ODatabaseMetaDataResultSet::get0Value());
87 aRow.push_back(ODatabaseMetaDataResultSet::get0Value());
88 aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
89 aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
90 aRow.push_back(new ORowSetValueDecorator((sal_Int32)10));
92 aRows.push_back(aRow);
94 aRow[1] = new ORowSetValueDecorator(OUString("LONGVARCHAR"));
95 aRow[2] = new ORowSetValueDecorator(DataType::LONGVARCHAR);
96 aRow[3] = new ORowSetValueDecorator((sal_Int32)2147483647);
97 aRow[6] = new ORowSetValueDecorator();
98 aRow[13] = new ORowSetValueDecorator(OUString("M"));
99 aRows.push_back(aRow);
101 aRow[1] = new ORowSetValueDecorator(OUString("DATE"));
102 aRow[2] = new ORowSetValueDecorator(DataType::DATE);
103 aRow[3] = new ORowSetValueDecorator((sal_Int32)10);
104 aRow[13] = new ORowSetValueDecorator(OUString("D"));
105 aRows.push_back(aRow);
107 aRow[1] = new ORowSetValueDecorator(OUString("BOOLEAN"));
108 aRow[2] = new ORowSetValueDecorator(DataType::BIT);
109 aRow[3] = ODatabaseMetaDataResultSet::get1Value();
110 aRow[4] = ODatabaseMetaDataResultSet::getEmptyValue();
111 aRow[5] = ODatabaseMetaDataResultSet::getEmptyValue();
112 aRow[6] = new ORowSetValueDecorator(OUString());
113 aRow[9] = ODatabaseMetaDataResultSet::getBasicValue();
114 aRow[13] = new ORowSetValueDecorator(OUString("L"));
115 aRows.push_back(aRow);
117 aRow[1] = new ORowSetValueDecorator(OUString("DOUBLE"));
118 aRow[2] = new ORowSetValueDecorator(DataType::DOUBLE);
119 aRow[3] = new ORowSetValueDecorator((sal_Int32)8);
120 aRow[13] = new ORowSetValueDecorator(OUString("B"));
121 aRows.push_back(aRow);
123 aRow[11] = new ORowSetValueDecorator(sal_True);
124 aRow[13] = new ORowSetValueDecorator(OUString("Y"));
125 aRows.push_back(aRow);
127 aRow[1] = new ORowSetValueDecorator(OUString("TIMESTAMP"));
128 aRow[2] = new ORowSetValueDecorator(DataType::TIMESTAMP);
129 aRow[11] = new ORowSetValueDecorator(sal_False);
130 aRow[13] = new ORowSetValueDecorator(OUString("T"));
131 aRows.push_back(aRow);
133 aRow[1] = new ORowSetValueDecorator(OUString("INTEGER"));
134 aRow[2] = new ORowSetValueDecorator(DataType::INTEGER);
135 aRow[3] = new ORowSetValueDecorator((sal_Int32)10);
136 aRow[13] = new ORowSetValueDecorator(OUString("I"));
137 aRows.push_back(aRow);
139 aRow[1] = new ORowSetValueDecorator(OUString("DECIMAL"));
140 aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL);
141 aRow[3] = new ORowSetValueDecorator((sal_Int32)20);
142 aRow[6] = new ORowSetValueDecorator(OUString("length,scale"));
143 aRow[13] = new ORowSetValueDecorator(OUString("F"));
144 aRows.push_back(aRow);
146 aRow[1] = new ORowSetValueDecorator(OUString("NUMERIC"));
147 aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL);
148 aRow[3] = new ORowSetValueDecorator((sal_Int32)16);
149 aRow[13] = new ORowSetValueDecorator(OUString("N"));
150 aRow[15] = new ORowSetValueDecorator((sal_Int32)16);
151 aRows.push_back(aRow);
154 pResult->setRows(aRows);
155 return xRef;
157 // -------------------------------------------------------------------------
158 Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getColumns(
159 const Any& /*catalog*/, const OUString& /*schemaPattern*/, const OUString& tableNamePattern,
160 const OUString& columnNamePattern ) throw(SQLException, RuntimeException)
162 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseDatabaseMetaData::getColumns" );
163 ::osl::MutexGuard aGuard( m_aMutex );
166 Reference< XTablesSupplier > xTables = m_pConnection->createCatalog();
167 if(!xTables.is())
168 throw SQLException();
170 Reference< XNameAccess> xNames = xTables->getTables();
171 if(!xNames.is())
172 throw SQLException();
174 ODatabaseMetaDataResultSet::ORows aRows;
175 ODatabaseMetaDataResultSet::ORow aRow(19);
177 aRow[10] = new ORowSetValueDecorator((sal_Int32)10);
178 Sequence< OUString> aTabNames(xNames->getElementNames());
179 const OUString* pTabBegin = aTabNames.getConstArray();
180 const OUString* pTabEnd = pTabBegin + aTabNames.getLength();
181 for(;pTabBegin != pTabEnd;++pTabBegin)
183 if(match(tableNamePattern,*pTabBegin,'\0'))
185 Reference< XColumnsSupplier> xTable;
186 ::cppu::extractInterface(xTable,xNames->getByName(*pTabBegin));
187 OSL_ENSURE(xTable.is(),"Table not found! Normallya exception had to be thrown here!");
188 aRow[3] = new ORowSetValueDecorator(*pTabBegin);
190 Reference< XNameAccess> xColumns = xTable->getColumns();
191 if(!xColumns.is())
192 throw SQLException();
194 Sequence< OUString> aColNames(xColumns->getElementNames());
196 const OUString* pBegin = aColNames.getConstArray();
197 const OUString* pEnd = pBegin + aColNames.getLength();
198 Reference< XPropertySet> xColumn;
199 for(sal_Int32 i=1;pBegin != pEnd;++pBegin,++i)
201 if(match(columnNamePattern,*pBegin,'\0'))
203 aRow[4] = new ORowSetValueDecorator(*pBegin);
205 ::cppu::extractInterface(xColumn,xColumns->getByName(*pBegin));
206 OSL_ENSURE(xColumn.is(),"Columns contains a column who isn't a fastpropertyset!");
207 aRow[5] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))));
208 aRow[6] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))));
209 aRow[7] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))));
210 aRow[9] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))));
211 aRow[11] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))));
212 aRow[13] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE))));
213 switch((sal_Int32)aRow[5]->getValue())
215 case DataType::CHAR:
216 case DataType::VARCHAR:
217 aRow[16] = new ORowSetValueDecorator((sal_Int32)254);
218 break;
219 case DataType::LONGVARCHAR:
220 aRow[16] = new ORowSetValueDecorator((sal_Int32)65535);
221 break;
222 default:
223 aRow[16] = new ORowSetValueDecorator((sal_Int32)0);
225 aRow[17] = new ORowSetValueDecorator(i);
226 switch(sal_Int32(aRow[11]->getValue()))
228 case ColumnValue::NO_NULLS:
229 aRow[18] = new ORowSetValueDecorator(OUString("NO"));
230 break;
231 case ColumnValue::NULLABLE:
232 aRow[18] = new ORowSetValueDecorator(OUString("YES"));
233 break;
234 default:
235 aRow[18] = new ORowSetValueDecorator(OUString());
237 aRows.push_back(aRow);
242 ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns);
243 Reference< XResultSet > xRef = pResult;
244 pResult->setRows(aRows);
246 return xRef;
248 // -------------------------------------------------------------------------
249 Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getIndexInfo(
250 const Any& /*catalog*/, const OUString& /*schema*/, const OUString& table,
251 sal_Bool unique, sal_Bool /*approximate*/ ) throw(SQLException, RuntimeException)
253 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseDatabaseMetaData::getIndexInfo" );
254 ::osl::MutexGuard aGuard( m_aMutex );
256 Reference< XTablesSupplier > xTables = m_pConnection->createCatalog();
257 if(!xTables.is())
258 throw SQLException();
260 Reference< XNameAccess> xNames = xTables->getTables();
261 if(!xNames.is())
262 throw SQLException();
264 ODatabaseMetaDataResultSet::ORows aRows;
265 ODatabaseMetaDataResultSet::ORow aRow(14);
267 aRow[5] = new ORowSetValueDecorator(OUString());
268 aRow[10] = new ORowSetValueDecorator(OUString("A"));
270 Reference< XIndexesSupplier> xTable;
271 ::cppu::extractInterface(xTable,xNames->getByName(table));
272 aRow[3] = new ORowSetValueDecorator(table);
273 aRow[7] = new ORowSetValueDecorator((sal_Int32)3);
275 Reference< XNameAccess> xIndexes = xTable->getIndexes();
276 if(!xIndexes.is())
277 throw SQLException();
279 Sequence< OUString> aIdxNames(xIndexes->getElementNames());
281 const OUString* pBegin = aIdxNames.getConstArray();
282 const OUString* pEnd = pBegin + aIdxNames.getLength();
283 Reference< XPropertySet> xIndex;
284 for(;pBegin != pEnd;++pBegin)
286 ::cppu::extractInterface(xIndex,xIndexes->getByName(*pBegin));
287 OSL_ENSURE(xIndex.is(),"Indexes contains a column who isn't a fastpropertyset!");
289 if(unique && !getBOOL(xIndex->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISUNIQUE))))
290 continue;
291 aRow[4] = new ORowSetValueDecorator(getBOOL(xIndex->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISUNIQUE))));
292 aRow[6] = new ORowSetValueDecorator(*pBegin);
294 Reference< XUnoTunnel> xTunnel(xIndex,UNO_QUERY);
295 if(xTunnel.is())
297 ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()) );
298 if(pIndex)
300 aRow[11] = new ORowSetValueDecorator((sal_Int32)pIndex->getHeader().db_maxkeys);
301 aRow[12] = new ORowSetValueDecorator((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 Reference< XPropertySet> xColumn;
312 for(sal_Int32 j=1;pColBegin != pColEnd;++pColBegin,++j)
314 aRow[8] = new ORowSetValueDecorator(j);
315 aRow[9] = new ORowSetValueDecorator(*pColBegin);
316 aRows.push_back(aRow);
320 ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eIndexInfo);
321 Reference< XResultSet > xRef = pResult;
322 pResult->setRows(aRows);
323 return xRef;
325 // -------------------------------------------------------------------------
326 OUString SAL_CALL ODbaseDatabaseMetaData::getURL( ) throw(SQLException, RuntimeException)
328 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseDatabaseMetaData::getURL" );
329 ::osl::MutexGuard aGuard( m_aMutex );
330 return OUString("sdbc:dbase:") + m_pConnection->getURL();
332 // -------------------------------------------------------------------------
333 sal_Int32 SAL_CALL ODbaseDatabaseMetaData::getMaxBinaryLiteralLength( ) throw(SQLException, RuntimeException)
335 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseDatabaseMetaData::getMaxBinaryLiteralLength" );
336 return STRING_MAXLEN;
338 // -------------------------------------------------------------------------
339 sal_Int32 SAL_CALL ODbaseDatabaseMetaData::getMaxCharLiteralLength( ) throw(SQLException, RuntimeException)
341 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseDatabaseMetaData::getMaxCharLiteralLength" );
342 return 254;
344 // -------------------------------------------------------------------------
345 sal_Int32 SAL_CALL ODbaseDatabaseMetaData::getMaxColumnNameLength( ) throw(SQLException, RuntimeException)
347 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseDatabaseMetaData::getMaxColumnNameLength" );
348 return 10;
350 // -------------------------------------------------------------------------
351 sal_Int32 SAL_CALL ODbaseDatabaseMetaData::getMaxColumnsInIndex( ) throw(SQLException, RuntimeException)
353 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseDatabaseMetaData::getMaxColumnsInIndex" );
354 return 1;
356 // -------------------------------------------------------------------------
357 sal_Int32 SAL_CALL ODbaseDatabaseMetaData::getMaxColumnsInTable( ) throw(SQLException, RuntimeException)
359 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseDatabaseMetaData::getMaxColumnsInTable" );
360 return 128;
362 // -----------------------------------------------------------------------------
363 sal_Bool SAL_CALL ODbaseDatabaseMetaData::supportsAlterTableWithAddColumn( ) throw(SQLException, RuntimeException)
365 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseDatabaseMetaData::supportsAlterTableWithAddColumn" );
366 return sal_True;
368 // -------------------------------------------------------------------------
369 sal_Bool SAL_CALL ODbaseDatabaseMetaData::supportsAlterTableWithDropColumn( ) throw(SQLException, RuntimeException)
371 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseDatabaseMetaData::supportsAlterTableWithDropColumn" );
372 return sal_False;
374 // -----------------------------------------------------------------------------
375 sal_Bool SAL_CALL ODbaseDatabaseMetaData::isReadOnly( ) throw(SQLException, RuntimeException)
377 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseDatabaseMetaData::isReadOnly" );
378 ::osl::MutexGuard aGuard( m_aMutex );
380 sal_Bool bReadOnly = sal_False;
381 static OUString sReadOnly( "IsReadOnly" );
382 ::ucbhelper::Content aFile(m_pConnection->getContent(),Reference< XCommandEnvironment >(), comphelper::getProcessComponentContext());
383 aFile.getPropertyValue(sReadOnly) >>= bReadOnly;
385 return bReadOnly;
387 // -----------------------------------------------------------------------------
388 sal_Bool ODbaseDatabaseMetaData::impl_storesMixedCaseQuotedIdentifiers_throw( )
390 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseDatabaseMetaData::impl_storesMixedCaseQuotedIdentifiers_throw" );
391 return sal_True;
393 // -----------------------------------------------------------------------------
394 sal_Bool ODbaseDatabaseMetaData::impl_supportsMixedCaseQuotedIdentifiers_throw( )
396 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseDatabaseMetaData::impl_supportsMixedCaseQuotedIdentifiers_throw" );
397 return sal_True;
399 // -----------------------------------------------------------------------------
402 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */