Line data Source code
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 :
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/processfactory.hxx>
33 : #include <comphelper/types.hxx>
34 : #include <ucbhelper/content.hxx>
35 :
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;
46 :
47 0 : ODbaseDatabaseMetaData::ODbaseDatabaseMetaData(::connectivity::file::OConnection* _pCon) :ODatabaseMetaData(_pCon)
48 : {
49 : SAL_INFO( "connectivity.drivers", "dbase Ocke.Janssen@sun.com ODbaseDatabaseMetaData::ODbaseDatabaseMetaData" );
50 0 : }
51 :
52 0 : ODbaseDatabaseMetaData::~ODbaseDatabaseMetaData()
53 : {
54 0 : }
55 :
56 0 : Reference< XResultSet > ODbaseDatabaseMetaData::impl_getTypeInfo_throw( )
57 : {
58 : SAL_INFO( "connectivity.drivers", "dbase Ocke.Janssen@sun.com ODbaseDatabaseMetaData::impl_getTypeInfo_throw" );
59 0 : ::osl::MutexGuard aGuard( m_aMutex );
60 :
61 0 : ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo);
62 0 : Reference< XResultSet > xRef = pResult;
63 :
64 0 : static ODatabaseMetaDataResultSet::ORows aRows;
65 0 : if(aRows.empty())
66 : {
67 0 : ODatabaseMetaDataResultSet::ORow aRow;
68 0 : aRow.reserve(19);
69 :
70 0 : aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
71 0 : aRow.push_back(new ORowSetValueDecorator(OUString("VARCHAR")));
72 0 : aRow.push_back(new ORowSetValueDecorator(DataType::VARCHAR));
73 0 : aRow.push_back(new ORowSetValueDecorator((sal_Int32)254));
74 0 : aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue());
75 0 : aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue());
76 0 : aRow.push_back(new ORowSetValueDecorator(OUString("length")));
77 0 : aRow.push_back(new ORowSetValueDecorator((sal_Int32)ColumnValue::NULLABLE));
78 0 : aRow.push_back(ODatabaseMetaDataResultSet::get1Value());
79 0 : aRow.push_back(new ORowSetValueDecorator((sal_Int32)ColumnSearch::FULL));
80 0 : aRow.push_back(ODatabaseMetaDataResultSet::get1Value());
81 0 : aRow.push_back(ODatabaseMetaDataResultSet::get0Value());
82 0 : aRow.push_back(ODatabaseMetaDataResultSet::get0Value());
83 0 : aRow.push_back(new ORowSetValueDecorator(OUString("C")));
84 0 : aRow.push_back(ODatabaseMetaDataResultSet::get0Value());
85 0 : aRow.push_back(ODatabaseMetaDataResultSet::get0Value());
86 0 : aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
87 0 : aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
88 0 : aRow.push_back(new ORowSetValueDecorator((sal_Int32)10));
89 :
90 0 : aRows.push_back(aRow);
91 :
92 0 : aRow[1] = new ORowSetValueDecorator(OUString("LONGVARCHAR"));
93 0 : aRow[2] = new ORowSetValueDecorator(DataType::LONGVARCHAR);
94 0 : aRow[3] = new ORowSetValueDecorator((sal_Int32)2147483647);
95 0 : aRow[6] = new ORowSetValueDecorator();
96 0 : aRow[13] = new ORowSetValueDecorator(OUString("M"));
97 0 : aRows.push_back(aRow);
98 :
99 0 : aRow[1] = new ORowSetValueDecorator(OUString("DATE"));
100 0 : aRow[2] = new ORowSetValueDecorator(DataType::DATE);
101 0 : aRow[3] = new ORowSetValueDecorator((sal_Int32)10);
102 0 : aRow[13] = new ORowSetValueDecorator(OUString("D"));
103 0 : aRows.push_back(aRow);
104 :
105 0 : aRow[1] = new ORowSetValueDecorator(OUString("BOOLEAN"));
106 0 : aRow[2] = new ORowSetValueDecorator(DataType::BIT);
107 0 : aRow[3] = ODatabaseMetaDataResultSet::get1Value();
108 0 : aRow[4] = ODatabaseMetaDataResultSet::getEmptyValue();
109 0 : aRow[5] = ODatabaseMetaDataResultSet::getEmptyValue();
110 0 : aRow[6] = new ORowSetValueDecorator(OUString());
111 0 : aRow[9] = ODatabaseMetaDataResultSet::getBasicValue();
112 0 : aRow[13] = new ORowSetValueDecorator(OUString("L"));
113 0 : aRows.push_back(aRow);
114 :
115 0 : aRow[1] = new ORowSetValueDecorator(OUString("DOUBLE"));
116 0 : aRow[2] = new ORowSetValueDecorator(DataType::DOUBLE);
117 0 : aRow[3] = new ORowSetValueDecorator((sal_Int32)8);
118 0 : aRow[13] = new ORowSetValueDecorator(OUString("B"));
119 0 : aRows.push_back(aRow);
120 :
121 0 : aRow[11] = new ORowSetValueDecorator(sal_True);
122 0 : aRow[13] = new ORowSetValueDecorator(OUString("Y"));
123 0 : aRows.push_back(aRow);
124 :
125 0 : aRow[1] = new ORowSetValueDecorator(OUString("TIMESTAMP"));
126 0 : aRow[2] = new ORowSetValueDecorator(DataType::TIMESTAMP);
127 0 : aRow[11] = new ORowSetValueDecorator(sal_False);
128 0 : aRow[13] = new ORowSetValueDecorator(OUString("T"));
129 0 : aRows.push_back(aRow);
130 :
131 0 : aRow[1] = new ORowSetValueDecorator(OUString("INTEGER"));
132 0 : aRow[2] = new ORowSetValueDecorator(DataType::INTEGER);
133 0 : aRow[3] = new ORowSetValueDecorator((sal_Int32)10);
134 0 : aRow[13] = new ORowSetValueDecorator(OUString("I"));
135 0 : aRows.push_back(aRow);
136 :
137 0 : aRow[1] = new ORowSetValueDecorator(OUString("DECIMAL"));
138 0 : aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL);
139 0 : aRow[3] = new ORowSetValueDecorator((sal_Int32)20);
140 0 : aRow[6] = new ORowSetValueDecorator(OUString("length,scale"));
141 0 : aRow[13] = new ORowSetValueDecorator(OUString("F"));
142 0 : aRows.push_back(aRow);
143 :
144 0 : aRow[1] = new ORowSetValueDecorator(OUString("NUMERIC"));
145 0 : aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL);
146 0 : aRow[3] = new ORowSetValueDecorator((sal_Int32)16);
147 0 : aRow[13] = new ORowSetValueDecorator(OUString("N"));
148 0 : aRow[15] = new ORowSetValueDecorator((sal_Int32)16);
149 0 : aRows.push_back(aRow);
150 : }
151 :
152 0 : pResult->setRows(aRows);
153 0 : return xRef;
154 : }
155 :
156 0 : Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getColumns(
157 : const Any& /*catalog*/, const OUString& /*schemaPattern*/, const OUString& tableNamePattern,
158 : const OUString& columnNamePattern ) throw(SQLException, RuntimeException, std::exception)
159 : {
160 : SAL_INFO( "connectivity.drivers", "dbase Ocke.Janssen@sun.com ODbaseDatabaseMetaData::getColumns" );
161 0 : ::osl::MutexGuard aGuard( m_aMutex );
162 :
163 :
164 0 : Reference< XTablesSupplier > xTables = m_pConnection->createCatalog();
165 0 : if(!xTables.is())
166 0 : throw SQLException();
167 :
168 0 : Reference< XNameAccess> xNames = xTables->getTables();
169 0 : if(!xNames.is())
170 0 : throw SQLException();
171 :
172 0 : ODatabaseMetaDataResultSet::ORows aRows;
173 0 : ODatabaseMetaDataResultSet::ORow aRow(19);
174 :
175 0 : aRow[10] = new ORowSetValueDecorator((sal_Int32)10);
176 0 : Sequence< OUString> aTabNames(xNames->getElementNames());
177 0 : const OUString* pTabBegin = aTabNames.getConstArray();
178 0 : const OUString* pTabEnd = pTabBegin + aTabNames.getLength();
179 0 : for(;pTabBegin != pTabEnd;++pTabBegin)
180 : {
181 0 : if(match(tableNamePattern,*pTabBegin,'\0'))
182 : {
183 : Reference< XColumnsSupplier> xTable(
184 0 : xNames->getByName(*pTabBegin), css::uno::UNO_QUERY);
185 : OSL_ENSURE(xTable.is(),"Table not found! Normallya exception had to be thrown here!");
186 0 : aRow[3] = new ORowSetValueDecorator(*pTabBegin);
187 :
188 0 : Reference< XNameAccess> xColumns = xTable->getColumns();
189 0 : if(!xColumns.is())
190 0 : throw SQLException();
191 :
192 0 : Sequence< OUString> aColNames(xColumns->getElementNames());
193 :
194 0 : const OUString* pBegin = aColNames.getConstArray();
195 0 : const OUString* pEnd = pBegin + aColNames.getLength();
196 0 : Reference< XPropertySet> xColumn;
197 0 : for(sal_Int32 i=1;pBegin != pEnd;++pBegin,++i)
198 : {
199 0 : if(match(columnNamePattern,*pBegin,'\0'))
200 : {
201 0 : aRow[4] = new ORowSetValueDecorator(*pBegin);
202 :
203 : xColumn.set(
204 0 : xColumns->getByName(*pBegin), css::uno::UNO_QUERY);
205 : OSL_ENSURE(xColumn.is(),"Columns contains a column who isn't a fastpropertyset!");
206 0 : aRow[5] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))));
207 0 : aRow[6] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))));
208 0 : aRow[7] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))));
209 0 : aRow[9] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))));
210 0 : aRow[11] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))));
211 0 : aRow[13] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE))));
212 0 : switch((sal_Int32)aRow[5]->getValue())
213 : {
214 : case DataType::CHAR:
215 : case DataType::VARCHAR:
216 0 : aRow[16] = new ORowSetValueDecorator((sal_Int32)254);
217 0 : break;
218 : case DataType::LONGVARCHAR:
219 0 : aRow[16] = new ORowSetValueDecorator((sal_Int32)65535);
220 0 : break;
221 : default:
222 0 : aRow[16] = new ORowSetValueDecorator((sal_Int32)0);
223 : }
224 0 : aRow[17] = new ORowSetValueDecorator(i);
225 0 : switch(sal_Int32(aRow[11]->getValue()))
226 : {
227 : case ColumnValue::NO_NULLS:
228 0 : aRow[18] = new ORowSetValueDecorator(OUString("NO"));
229 0 : break;
230 : case ColumnValue::NULLABLE:
231 0 : aRow[18] = new ORowSetValueDecorator(OUString("YES"));
232 0 : break;
233 : default:
234 0 : aRow[18] = new ORowSetValueDecorator(OUString());
235 : }
236 0 : aRows.push_back(aRow);
237 : }
238 0 : }
239 : }
240 : }
241 0 : ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns);
242 0 : Reference< XResultSet > xRef = pResult;
243 0 : pResult->setRows(aRows);
244 :
245 0 : return xRef;
246 : }
247 :
248 0 : Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getIndexInfo(
249 : const Any& /*catalog*/, const OUString& /*schema*/, const OUString& table,
250 : sal_Bool unique, sal_Bool /*approximate*/ ) throw(SQLException, RuntimeException, std::exception)
251 : {
252 : SAL_INFO( "connectivity.drivers", "dbase Ocke.Janssen@sun.com ODbaseDatabaseMetaData::getIndexInfo" );
253 0 : ::osl::MutexGuard aGuard( m_aMutex );
254 :
255 0 : Reference< XTablesSupplier > xTables = m_pConnection->createCatalog();
256 0 : if(!xTables.is())
257 0 : throw SQLException();
258 :
259 0 : Reference< XNameAccess> xNames = xTables->getTables();
260 0 : if(!xNames.is())
261 0 : throw SQLException();
262 :
263 0 : ODatabaseMetaDataResultSet::ORows aRows;
264 0 : ODatabaseMetaDataResultSet::ORow aRow(14);
265 :
266 0 : aRow[5] = new ORowSetValueDecorator(OUString());
267 0 : aRow[10] = new ORowSetValueDecorator(OUString("A"));
268 :
269 : Reference< XIndexesSupplier> xTable(
270 0 : xNames->getByName(table), css::uno::UNO_QUERY);
271 0 : aRow[3] = new ORowSetValueDecorator(table);
272 0 : aRow[7] = new ORowSetValueDecorator((sal_Int32)3);
273 :
274 0 : Reference< XNameAccess> xIndexes = xTable->getIndexes();
275 0 : if(!xIndexes.is())
276 0 : throw SQLException();
277 :
278 0 : Sequence< OUString> aIdxNames(xIndexes->getElementNames());
279 :
280 0 : const OUString* pBegin = aIdxNames.getConstArray();
281 0 : const OUString* pEnd = pBegin + aIdxNames.getLength();
282 0 : Reference< XPropertySet> xIndex;
283 0 : for(;pBegin != pEnd;++pBegin)
284 : {
285 0 : xIndex.set(xIndexes->getByName(*pBegin), css::uno::UNO_QUERY);
286 : OSL_ENSURE(xIndex.is(),"Indexes contains a column who isn't a fastpropertyset!");
287 :
288 0 : if(unique && !getBOOL(xIndex->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISUNIQUE))))
289 0 : continue;
290 0 : aRow[4] = new ORowSetValueDecorator(getBOOL(xIndex->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISUNIQUE))));
291 0 : aRow[6] = new ORowSetValueDecorator(*pBegin);
292 :
293 0 : Reference< XUnoTunnel> xTunnel(xIndex,UNO_QUERY);
294 0 : if(xTunnel.is())
295 : {
296 0 : ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()) );
297 0 : if(pIndex)
298 : {
299 0 : aRow[11] = new ORowSetValueDecorator((sal_Int32)pIndex->getHeader().db_maxkeys);
300 0 : aRow[12] = new ORowSetValueDecorator((sal_Int32)pIndex->getHeader().db_pagecount);
301 : }
302 : }
303 :
304 0 : Reference<XColumnsSupplier> xColumnsSup(xIndex,UNO_QUERY);
305 0 : Reference< XNameAccess> xColumns = xColumnsSup->getColumns();
306 0 : Sequence< OUString> aColNames(xColumns->getElementNames());
307 :
308 0 : const OUString* pColBegin = aColNames.getConstArray();
309 0 : const OUString* pColEnd = pColBegin + aColNames.getLength();
310 0 : Reference< XPropertySet> xColumn;
311 0 : for(sal_Int32 j=1;pColBegin != pColEnd;++pColBegin,++j)
312 : {
313 0 : aRow[8] = new ORowSetValueDecorator(j);
314 0 : aRow[9] = new ORowSetValueDecorator(*pColBegin);
315 0 : aRows.push_back(aRow);
316 : }
317 0 : }
318 :
319 0 : ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eIndexInfo);
320 0 : Reference< XResultSet > xRef = pResult;
321 0 : pResult->setRows(aRows);
322 0 : return xRef;
323 : }
324 :
325 0 : OUString SAL_CALL ODbaseDatabaseMetaData::getURL( ) throw(SQLException, RuntimeException, std::exception)
326 : {
327 : SAL_INFO( "connectivity.drivers", "dbase Ocke.Janssen@sun.com ODbaseDatabaseMetaData::getURL" );
328 0 : ::osl::MutexGuard aGuard( m_aMutex );
329 0 : return OUString("sdbc:dbase:") + m_pConnection->getURL();
330 : }
331 :
332 0 : sal_Int32 SAL_CALL ODbaseDatabaseMetaData::getMaxBinaryLiteralLength( ) throw(SQLException, RuntimeException, std::exception)
333 : {
334 : SAL_INFO( "connectivity.drivers", "dbase Ocke.Janssen@sun.com ODbaseDatabaseMetaData::getMaxBinaryLiteralLength" );
335 0 : return SAL_MAX_INT32;
336 : }
337 :
338 0 : sal_Int32 SAL_CALL ODbaseDatabaseMetaData::getMaxCharLiteralLength( ) throw(SQLException, RuntimeException, std::exception)
339 : {
340 : SAL_INFO( "connectivity.drivers", "dbase Ocke.Janssen@sun.com ODbaseDatabaseMetaData::getMaxCharLiteralLength" );
341 0 : return 254;
342 : }
343 :
344 0 : sal_Int32 SAL_CALL ODbaseDatabaseMetaData::getMaxColumnNameLength( ) throw(SQLException, RuntimeException, std::exception)
345 : {
346 : SAL_INFO( "connectivity.drivers", "dbase Ocke.Janssen@sun.com ODbaseDatabaseMetaData::getMaxColumnNameLength" );
347 0 : return 10;
348 : }
349 :
350 0 : sal_Int32 SAL_CALL ODbaseDatabaseMetaData::getMaxColumnsInIndex( ) throw(SQLException, RuntimeException, std::exception)
351 : {
352 : SAL_INFO( "connectivity.drivers", "dbase Ocke.Janssen@sun.com ODbaseDatabaseMetaData::getMaxColumnsInIndex" );
353 0 : return 1;
354 : }
355 :
356 0 : sal_Int32 SAL_CALL ODbaseDatabaseMetaData::getMaxColumnsInTable( ) throw(SQLException, RuntimeException, std::exception)
357 : {
358 : SAL_INFO( "connectivity.drivers", "dbase Ocke.Janssen@sun.com ODbaseDatabaseMetaData::getMaxColumnsInTable" );
359 0 : return 128;
360 : }
361 :
362 0 : sal_Bool SAL_CALL ODbaseDatabaseMetaData::supportsAlterTableWithAddColumn( ) throw(SQLException, RuntimeException, std::exception)
363 : {
364 : SAL_INFO( "connectivity.drivers", "dbase Ocke.Janssen@sun.com ODbaseDatabaseMetaData::supportsAlterTableWithAddColumn" );
365 0 : return sal_True;
366 : }
367 :
368 0 : sal_Bool SAL_CALL ODbaseDatabaseMetaData::supportsAlterTableWithDropColumn( ) throw(SQLException, RuntimeException, std::exception)
369 : {
370 : SAL_INFO( "connectivity.drivers", "dbase Ocke.Janssen@sun.com ODbaseDatabaseMetaData::supportsAlterTableWithDropColumn" );
371 0 : return sal_False;
372 : }
373 :
374 0 : sal_Bool SAL_CALL ODbaseDatabaseMetaData::isReadOnly( ) throw(SQLException, RuntimeException, std::exception)
375 : {
376 : SAL_INFO( "connectivity.drivers", "dbase Ocke.Janssen@sun.com ODbaseDatabaseMetaData::isReadOnly" );
377 0 : ::osl::MutexGuard aGuard( m_aMutex );
378 :
379 0 : sal_Bool bReadOnly = sal_False;
380 0 : static OUString sReadOnly( "IsReadOnly" );
381 0 : ::ucbhelper::Content aFile(m_pConnection->getContent(),Reference< XCommandEnvironment >(), comphelper::getProcessComponentContext());
382 0 : aFile.getPropertyValue(sReadOnly) >>= bReadOnly;
383 :
384 0 : return bReadOnly;
385 : }
386 :
387 0 : sal_Bool ODbaseDatabaseMetaData::impl_storesMixedCaseQuotedIdentifiers_throw( )
388 : {
389 : SAL_INFO( "connectivity.drivers", "dbase Ocke.Janssen@sun.com ODbaseDatabaseMetaData::impl_storesMixedCaseQuotedIdentifiers_throw" );
390 0 : return sal_True;
391 : }
392 :
393 0 : sal_Bool ODbaseDatabaseMetaData::impl_supportsMixedCaseQuotedIdentifiers_throw( )
394 : {
395 : SAL_INFO( "connectivity.drivers", "dbase Ocke.Janssen@sun.com ODbaseDatabaseMetaData::impl_supportsMixedCaseQuotedIdentifiers_throw" );
396 0 : return sal_True;
397 : }
398 :
399 :
400 :
401 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|