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 :
21 : #include "ParameterSubstitution.hxx"
22 : #include "FDatabaseMetaDataResultSet.hxx"
23 : #include "FDatabaseMetaDataResultSetMetaData.hxx"
24 : #include <com/sun/star/sdbc/DataType.hpp>
25 : #include <com/sun/star/sdbc/ColumnSearch.hpp>
26 : #include <com/sun/star/sdbc/KeyRule.hpp>
27 : #include <com/sun/star/sdbc/ProcedureResult.hpp>
28 : #include <com/sun/star/sdbc/IndexType.hpp>
29 : #include <comphelper/property.hxx>
30 : #include <com/sun/star/lang/DisposedException.hpp>
31 : #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
32 : #include <com/sun/star/sdbc/ResultSetType.hpp>
33 : #include <com/sun/star/sdbc/FetchDirection.hpp>
34 : #include <com/sun/star/beans/PropertyAttribute.hpp>
35 : #include <cppuhelper/typeprovider.hxx>
36 : #include <comphelper/sequence.hxx>
37 : #include <cppuhelper/factory.hxx>
38 : #include <cppuhelper/implementationentry.hxx>
39 : #include "connectivity/dbexception.hxx"
40 : #include "TConnection.hxx"
41 :
42 : using namespace connectivity;
43 : using namespace dbtools;
44 : using namespace cppu;
45 : //------------------------------------------------------------------------------
46 : using namespace ::com::sun::star::beans;
47 : using namespace ::com::sun::star::uno;
48 : using namespace ::com::sun::star::sdbcx;
49 : using namespace ::com::sun::star::sdbc;
50 : using namespace ::com::sun::star::container;
51 : using namespace ::com::sun::star::lang;
52 : // -------------------------------------------------------------------------
53 0 : ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet()
54 : :ODatabaseMetaDataResultSet_BASE(m_aMutex)
55 : ,::comphelper::OPropertyContainer(ODatabaseMetaDataResultSet_BASE::rBHelper)
56 : ,m_aStatement(NULL)
57 : ,m_xMetaData(NULL)
58 : ,m_bBOF(sal_True)
59 0 : ,m_bEOF(sal_True)
60 : {
61 0 : construct();
62 0 : }
63 :
64 : // -------------------------------------------------------------------------
65 81 : ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet( MetaDataResultSetType _eType )
66 : :ODatabaseMetaDataResultSet_BASE(m_aMutex)
67 : ,::comphelper::OPropertyContainer(ODatabaseMetaDataResultSet_BASE::rBHelper)
68 : ,m_aStatement(NULL)
69 : ,m_xMetaData(NULL)
70 : ,m_bBOF(sal_True)
71 81 : ,m_bEOF(sal_True)
72 : {
73 81 : construct();
74 :
75 81 : setType(_eType);
76 81 : }
77 :
78 : // -------------------------------------------------------------------------
79 162 : ODatabaseMetaDataResultSet::~ODatabaseMetaDataResultSet()
80 : {
81 162 : }
82 : // -------------------------------------------------------------------------
83 81 : void ODatabaseMetaDataResultSet::construct()
84 : {
85 81 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), PROPERTY_ID_FETCHSIZE, 0,&m_nFetchSize, ::getCppuType(static_cast<sal_Int32*>(0)));
86 81 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), PROPERTY_ID_RESULTSETTYPE, PropertyAttribute::READONLY,&m_nResultSetType, ::getCppuType(static_cast<sal_Int32*>(0)));
87 81 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), PROPERTY_ID_FETCHDIRECTION, 0, &m_nFetchDirection, ::getCppuType(static_cast<sal_Int32*>(0)));
88 81 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), PROPERTY_ID_RESULTSETCONCURRENCY, PropertyAttribute::READONLY,&m_nResultSetConcurrency, ::getCppuType(static_cast<sal_Int32*>(0)));
89 81 : }
90 : // -----------------------------------------------------------------------------
91 81 : void ODatabaseMetaDataResultSet::setType(MetaDataResultSetType _eType)
92 : {
93 81 : switch( _eType )
94 : {
95 0 : case eCatalogs: setCatalogsMap(); break;
96 0 : case eSchemas: setSchemasMap(); break;
97 0 : case eColumnPrivileges: setColumnPrivilegesMap(); break;
98 76 : case eColumns: setColumnsMap(); break;
99 5 : case eTables: setTablesMap(); break;
100 0 : case eTableTypes: setTableTypes(); break;
101 0 : case eProcedureColumns: setProcedureColumnsMap(); break;
102 0 : case eProcedures: setProceduresMap(); break;
103 0 : case eExportedKeys: setExportedKeysMap(); break;
104 0 : case eImportedKeys: setImportedKeysMap(); break;
105 0 : case ePrimaryKeys: setPrimaryKeysMap(); break;
106 0 : case eIndexInfo: setIndexInfoMap(); break;
107 0 : case eTablePrivileges: setTablePrivilegesMap(); break;
108 0 : case eCrossReference: setCrossReferenceMap(); break;
109 0 : case eTypeInfo: setTypeInfoMap(); break;
110 0 : case eBestRowIdentifier: setBestRowIdentifierMap(); break;
111 0 : case eVersionColumns: setVersionColumnsMap(); break;
112 : default:
113 : OSL_FAIL("Wrong type!");
114 : }
115 81 : }
116 : // -------------------------------------------------------------------------
117 81 : void ODatabaseMetaDataResultSet::disposing(void)
118 : {
119 81 : OPropertySetHelper::disposing();
120 :
121 81 : ::osl::MutexGuard aGuard(m_aMutex);
122 81 : m_aStatement = NULL;
123 81 : m_xMetaData.clear();
124 81 : m_aRowsIter = m_aRows.end();
125 81 : m_aRows.clear();
126 81 : m_aRowsIter = m_aRows.end();
127 81 : }
128 : // -----------------------------------------------------------------------------
129 572 : void SAL_CALL ODatabaseMetaDataResultSet::acquire() throw()
130 : {
131 572 : ODatabaseMetaDataResultSet_BASE::acquire();
132 572 : }
133 : // -----------------------------------------------------------------------------
134 572 : void SAL_CALL ODatabaseMetaDataResultSet::release() throw()
135 : {
136 572 : ODatabaseMetaDataResultSet_BASE::release();
137 572 : }
138 : // -------------------------------------------------------------------------
139 165 : Any SAL_CALL ODatabaseMetaDataResultSet::queryInterface( const Type & rType ) throw(RuntimeException)
140 : {
141 165 : Any aRet = OPropertySetHelper::queryInterface(rType);
142 165 : return aRet.hasValue() ? aRet : ODatabaseMetaDataResultSet_BASE::queryInterface(rType);
143 : }
144 : // -------------------------------------------------------------------------
145 0 : Sequence< Type > SAL_CALL ODatabaseMetaDataResultSet::getTypes( ) throw(RuntimeException)
146 : {
147 0 : ::cppu::OTypeCollection aTypes( ::getCppuType( (const Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ),
148 0 : ::getCppuType( (const Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ),
149 0 : ::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet > *)0 ));
150 :
151 0 : return ::comphelper::concatSequences(aTypes.getTypes(),ODatabaseMetaDataResultSet_BASE::getTypes());
152 : }
153 : // -----------------------------------------------------------------------------
154 81 : void ODatabaseMetaDataResultSet::setRows(const ORows& _rRows)
155 : {
156 81 : m_aRows = _rRows;
157 81 : m_bBOF = sal_True;
158 81 : m_bEOF = m_aRows.empty();
159 81 : }
160 : // -------------------------------------------------------------------------
161 0 : sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::findColumn( const ::rtl::OUString& columnName ) throw(SQLException, RuntimeException)
162 : {
163 0 : ::osl::MutexGuard aGuard( m_aMutex );
164 0 : checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
165 :
166 :
167 0 : Reference< XResultSetMetaData > xMeta = getMetaData();
168 0 : sal_Int32 nLen = xMeta->getColumnCount();
169 0 : sal_Int32 i = 1;
170 0 : for(;i<=nLen;++i)
171 0 : if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) :
172 0 : columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i))
173 0 : )
174 0 : break;
175 0 : return i;
176 : }
177 : // -----------------------------------------------------------------------------
178 1268 : void ODatabaseMetaDataResultSet::checkIndex(sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException)
179 : {
180 1268 : if(columnIndex >= (sal_Int32)(*m_aRowsIter).size() || columnIndex < 1)
181 0 : ::dbtools::throwInvalidIndexException(*this);
182 1268 : }
183 : // -------------------------------------------------------------------------
184 0 : Reference< ::com::sun::star::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getBinaryStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
185 : {
186 0 : return NULL;
187 : }
188 : // -------------------------------------------------------------------------
189 0 : Reference< ::com::sun::star::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getCharacterStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
190 : {
191 0 : return NULL;
192 : }
193 :
194 : // -------------------------------------------------------------------------
195 0 : sal_Bool SAL_CALL ODatabaseMetaDataResultSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
196 : {
197 0 : return getValue(columnIndex);
198 : }
199 : // -------------------------------------------------------------------------
200 :
201 0 : sal_Int8 SAL_CALL ODatabaseMetaDataResultSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
202 : {
203 0 : return getValue(columnIndex);
204 : }
205 : // -------------------------------------------------------------------------
206 :
207 0 : Sequence< sal_Int8 > SAL_CALL ODatabaseMetaDataResultSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
208 : {
209 0 : return getValue(columnIndex);
210 : }
211 : // -------------------------------------------------------------------------
212 :
213 0 : ::com::sun::star::util::Date SAL_CALL ODatabaseMetaDataResultSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
214 : {
215 0 : return getValue(columnIndex);
216 : }
217 : // -------------------------------------------------------------------------
218 :
219 0 : double SAL_CALL ODatabaseMetaDataResultSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
220 : {
221 0 : return getValue(columnIndex);
222 : }
223 : // -------------------------------------------------------------------------
224 :
225 0 : float SAL_CALL ODatabaseMetaDataResultSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
226 : {
227 0 : return getValue(columnIndex);
228 : }
229 : // -------------------------------------------------------------------------
230 :
231 666 : sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
232 : {
233 666 : return getValue(columnIndex);
234 : }
235 :
236 : // -------------------------------------------------------------------------
237 :
238 0 : sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getRow( ) throw(SQLException, RuntimeException)
239 : {
240 0 : return 0;
241 : }
242 : // -------------------------------------------------------------------------
243 :
244 0 : sal_Int64 SAL_CALL ODatabaseMetaDataResultSet::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
245 : {
246 0 : return getValue(columnIndex);
247 : }
248 : // -------------------------------------------------------------------------
249 :
250 0 : Reference< XResultSetMetaData > SAL_CALL ODatabaseMetaDataResultSet::getMetaData( ) throw(SQLException, RuntimeException)
251 : {
252 0 : ::osl::MutexGuard aGuard( m_aMutex );
253 0 : checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
254 :
255 :
256 0 : if(!m_xMetaData.is())
257 0 : m_xMetaData = new ODatabaseMetaDataResultSetMetaData();
258 :
259 0 : return m_xMetaData;
260 : }
261 : // -------------------------------------------------------------------------
262 0 : Reference< XArray > SAL_CALL ODatabaseMetaDataResultSet::getArray( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
263 : {
264 0 : return NULL;
265 : }
266 :
267 : // -------------------------------------------------------------------------
268 :
269 0 : Reference< XClob > SAL_CALL ODatabaseMetaDataResultSet::getClob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
270 : {
271 0 : return NULL;
272 : }
273 : // -------------------------------------------------------------------------
274 0 : Reference< XBlob > SAL_CALL ODatabaseMetaDataResultSet::getBlob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
275 : {
276 0 : return NULL;
277 : }
278 : // -------------------------------------------------------------------------
279 :
280 0 : Reference< XRef > SAL_CALL ODatabaseMetaDataResultSet::getRef( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
281 : {
282 0 : return NULL;
283 : }
284 : // -------------------------------------------------------------------------
285 :
286 0 : Any SAL_CALL ODatabaseMetaDataResultSet::getObject( sal_Int32 columnIndex, const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
287 : {
288 0 : return getValue(columnIndex).makeAny();
289 : }
290 : // -------------------------------------------------------------------------
291 :
292 0 : sal_Int16 SAL_CALL ODatabaseMetaDataResultSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
293 : {
294 0 : return getValue(columnIndex);
295 : }
296 : // -------------------------------------------------------------------------
297 :
298 602 : ::rtl::OUString SAL_CALL ODatabaseMetaDataResultSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
299 : {
300 602 : return getValue(columnIndex);
301 : }
302 :
303 : // -------------------------------------------------------------------------
304 :
305 :
306 0 : ::com::sun::star::util::Time SAL_CALL ODatabaseMetaDataResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
307 : {
308 0 : return getValue(columnIndex);
309 : }
310 : // -------------------------------------------------------------------------
311 :
312 :
313 0 : ::com::sun::star::util::DateTime SAL_CALL ODatabaseMetaDataResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
314 : {
315 0 : return getValue(columnIndex);
316 : }
317 : // -------------------------------------------------------------------------
318 :
319 1268 : sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isAfterLast( ) throw(SQLException, RuntimeException)
320 : {
321 1268 : return m_bEOF;
322 : }
323 : // -------------------------------------------------------------------------
324 0 : sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isFirst( ) throw(SQLException, RuntimeException)
325 : {
326 0 : ::dbtools::throwFunctionSequenceException(*this);
327 0 : return sal_False;
328 : }
329 : // -------------------------------------------------------------------------
330 0 : sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isLast( ) throw(SQLException, RuntimeException)
331 : {
332 0 : ::dbtools::throwFunctionSequenceException(*this);
333 0 : return sal_False;
334 : }
335 : // -------------------------------------------------------------------------
336 0 : void SAL_CALL ODatabaseMetaDataResultSet::beforeFirst( ) throw(SQLException, RuntimeException)
337 : {
338 0 : ::dbtools::throwFunctionSequenceException(*this);
339 0 : }
340 : // -------------------------------------------------------------------------
341 0 : void SAL_CALL ODatabaseMetaDataResultSet::afterLast( ) throw(SQLException, RuntimeException)
342 : {
343 0 : ::dbtools::throwFunctionSequenceException(*this);
344 0 : }
345 : // -------------------------------------------------------------------------
346 :
347 0 : void SAL_CALL ODatabaseMetaDataResultSet::close( ) throw(SQLException, RuntimeException)
348 : {
349 : {
350 0 : ::osl::MutexGuard aGuard( m_aMutex );
351 0 : checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
352 :
353 : }
354 0 : dispose();
355 0 : }
356 : // -------------------------------------------------------------------------
357 :
358 0 : sal_Bool SAL_CALL ODatabaseMetaDataResultSet::first( ) throw(SQLException, RuntimeException)
359 : {
360 0 : ::dbtools::throwFunctionSequenceException(*this);
361 0 : return sal_False;
362 : }
363 : // -------------------------------------------------------------------------
364 :
365 0 : sal_Bool SAL_CALL ODatabaseMetaDataResultSet::last( ) throw(SQLException, RuntimeException)
366 : {
367 0 : ::dbtools::throwFunctionSequenceException(*this);
368 0 : return sal_False;
369 : }
370 : // -------------------------------------------------------------------------
371 0 : sal_Bool SAL_CALL ODatabaseMetaDataResultSet::absolute( sal_Int32 /*row*/ ) throw(SQLException, RuntimeException)
372 : {
373 0 : ::dbtools::throwFunctionSequenceException(*this);
374 0 : return sal_False;
375 : }
376 : // -------------------------------------------------------------------------
377 0 : sal_Bool SAL_CALL ODatabaseMetaDataResultSet::relative( sal_Int32 /*row*/ ) throw(SQLException, RuntimeException)
378 : {
379 0 : ::dbtools::throwFunctionSequenceException(*this);
380 0 : return sal_False;
381 : }
382 : // -------------------------------------------------------------------------
383 0 : sal_Bool SAL_CALL ODatabaseMetaDataResultSet::previous( ) throw(SQLException, RuntimeException)
384 : {
385 0 : ::dbtools::throwFunctionSequenceException(*this);
386 0 : return sal_False;
387 : }
388 : // -------------------------------------------------------------------------
389 0 : Reference< XInterface > SAL_CALL ODatabaseMetaDataResultSet::getStatement( ) throw(SQLException, RuntimeException)
390 : {
391 0 : return m_aStatement.get();
392 : }
393 : // -------------------------------------------------------------------------
394 :
395 0 : sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowDeleted( ) throw(SQLException, RuntimeException)
396 : {
397 0 : ::dbtools::throwFunctionSequenceException(*this);
398 0 : return sal_False;
399 : }
400 : // -------------------------------------------------------------------------
401 0 : sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowInserted( ) throw(SQLException, RuntimeException)
402 : {
403 0 : ::dbtools::throwFunctionSequenceException(*this);
404 0 : return sal_False;
405 : }
406 : // -------------------------------------------------------------------------
407 0 : sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowUpdated( ) throw(SQLException, RuntimeException)
408 : {
409 0 : ::dbtools::throwFunctionSequenceException(*this);
410 0 : return sal_False;
411 : }
412 : // -------------------------------------------------------------------------
413 :
414 1268 : sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isBeforeFirst( ) throw(SQLException, RuntimeException)
415 : {
416 1268 : return m_bBOF;
417 : }
418 : // -------------------------------------------------------------------------
419 :
420 160 : sal_Bool SAL_CALL ODatabaseMetaDataResultSet::next( ) throw(SQLException, RuntimeException)
421 : {
422 160 : ::osl::MutexGuard aGuard( m_aMutex );
423 160 : checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
424 :
425 160 : if ( m_bBOF )
426 : {
427 80 : m_aRowsIter = m_aRows.begin();
428 80 : m_bBOF = sal_False;
429 : }
430 : else
431 : {
432 80 : if ( m_bEOF )
433 0 : throwFunctionSequenceException( *this );
434 : else
435 80 : if ( m_aRowsIter != m_aRows.end() )
436 80 : ++m_aRowsIter;
437 : }
438 :
439 160 : bool bSuccess = m_aRowsIter != m_aRows.end();
440 160 : if ( !bSuccess )
441 : {
442 4 : m_bEOF = sal_True;
443 4 : m_bBOF = m_aRows.empty();
444 : }
445 160 : return bSuccess;
446 : }
447 : // -------------------------------------------------------------------------
448 :
449 0 : sal_Bool SAL_CALL ODatabaseMetaDataResultSet::wasNull( ) throw(SQLException, RuntimeException)
450 : {
451 0 : ::osl::MutexGuard aGuard( m_aMutex );
452 0 : checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
453 :
454 :
455 0 : if(m_aRowsIter == m_aRows.end() || !(*m_aRowsIter)[m_nColPos].is())
456 0 : return sal_True;
457 :
458 0 : return (*m_aRowsIter)[m_nColPos]->getValue().isNull();
459 : }
460 : // -------------------------------------------------------------------------
461 0 : void SAL_CALL ODatabaseMetaDataResultSet::refreshRow( ) throw(SQLException, RuntimeException)
462 : {
463 0 : }
464 : // -------------------------------------------------------------------------
465 :
466 0 : void SAL_CALL ODatabaseMetaDataResultSet::cancel( ) throw(RuntimeException)
467 : {
468 0 : }
469 : // -------------------------------------------------------------------------
470 0 : void SAL_CALL ODatabaseMetaDataResultSet::clearWarnings( ) throw(SQLException, RuntimeException)
471 : {
472 0 : }
473 : // -------------------------------------------------------------------------
474 0 : Any SAL_CALL ODatabaseMetaDataResultSet::getWarnings( ) throw(SQLException, RuntimeException)
475 : {
476 0 : return Any();
477 : }
478 : // -------------------------------------------------------------------------
479 0 : ::cppu::IPropertyArrayHelper* ODatabaseMetaDataResultSet::createArrayHelper( ) const
480 : {
481 0 : Sequence< Property > aProps;
482 0 : describeProperties(aProps);
483 0 : return new ::cppu::OPropertyArrayHelper(aProps);
484 : }
485 : // -------------------------------------------------------------------------
486 0 : ::cppu::IPropertyArrayHelper & ODatabaseMetaDataResultSet::getInfoHelper()
487 : {
488 0 : return *const_cast<ODatabaseMetaDataResultSet*>(this)->getArrayHelper();
489 : }
490 : // -------------------------------------------------------------------------
491 0 : void ODatabaseMetaDataResultSet::setProceduresMap()
492 : {
493 0 : ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
494 0 : pMetaData->setProceduresMap();
495 0 : m_xMetaData = pMetaData;
496 0 : }
497 : // -------------------------------------------------------------------------
498 0 : void ODatabaseMetaDataResultSet::setCatalogsMap()
499 : {
500 0 : ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
501 0 : pMetaData->setCatalogsMap();
502 0 : m_xMetaData = pMetaData;
503 0 : }
504 : // -------------------------------------------------------------------------
505 0 : void ODatabaseMetaDataResultSet::setSchemasMap()
506 : {
507 0 : ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
508 0 : pMetaData->setSchemasMap();
509 0 : m_xMetaData = pMetaData;
510 0 : }
511 : // -------------------------------------------------------------------------
512 0 : void ODatabaseMetaDataResultSet::setColumnPrivilegesMap()
513 : {
514 0 : ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
515 0 : pMetaData->setColumnPrivilegesMap();
516 0 : m_xMetaData = pMetaData;
517 0 : }
518 : // -------------------------------------------------------------------------
519 76 : void ODatabaseMetaDataResultSet::setColumnsMap()
520 : {
521 :
522 76 : ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
523 76 : pMetaData->setColumnsMap();
524 76 : m_xMetaData = pMetaData;
525 76 : }
526 : // -------------------------------------------------------------------------
527 5 : void ODatabaseMetaDataResultSet::setTablesMap()
528 : {
529 :
530 5 : ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
531 5 : pMetaData->setTablesMap();
532 5 : m_xMetaData = pMetaData;
533 5 : }
534 : // -------------------------------------------------------------------------
535 0 : void ODatabaseMetaDataResultSet::setProcedureColumnsMap()
536 : {
537 0 : ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
538 0 : pMetaData->setProcedureColumnsMap();
539 0 : m_xMetaData = pMetaData;
540 0 : }
541 : // -------------------------------------------------------------------------
542 0 : void ODatabaseMetaDataResultSet::setPrimaryKeysMap()
543 : {
544 0 : ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
545 0 : pMetaData->setPrimaryKeysMap();
546 0 : m_xMetaData = pMetaData;
547 0 : }
548 : // -------------------------------------------------------------------------
549 0 : void ODatabaseMetaDataResultSet::setIndexInfoMap()
550 : {
551 0 : ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
552 0 : pMetaData->setIndexInfoMap();
553 0 : m_xMetaData = pMetaData;
554 0 : }
555 : // -------------------------------------------------------------------------
556 0 : void ODatabaseMetaDataResultSet::setTablePrivilegesMap()
557 : {
558 0 : ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
559 0 : pMetaData->setTablePrivilegesMap();
560 0 : m_xMetaData = pMetaData;
561 0 : }
562 : // -------------------------------------------------------------------------
563 0 : void ODatabaseMetaDataResultSet::setCrossReferenceMap()
564 : {
565 0 : ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
566 0 : pMetaData->setCrossReferenceMap();
567 0 : m_xMetaData = pMetaData;
568 0 : }
569 : // -------------------------------------------------------------------------
570 0 : void ODatabaseMetaDataResultSet::setVersionColumnsMap()
571 : {
572 0 : ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
573 0 : pMetaData->setVersionColumnsMap();
574 0 : m_xMetaData = pMetaData;
575 0 : }
576 : // -------------------------------------------------------------------------
577 0 : void ODatabaseMetaDataResultSet::setBestRowIdentifierMap()
578 : {
579 0 : ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
580 0 : pMetaData->setBestRowIdentifierMap();
581 0 : m_xMetaData = pMetaData;
582 0 : }
583 : // -------------------------------------------------------------------------
584 0 : void ODatabaseMetaDataResultSet::setTypeInfoMap()
585 : {
586 0 : ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
587 0 : pMetaData->setTypeInfoMap();
588 0 : m_xMetaData = pMetaData;
589 0 : }
590 : // -------------------------------------------------------------------------
591 0 : void ODatabaseMetaDataResultSet::setTableTypes()
592 : {
593 0 : ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
594 0 : pMetaData->setTableTypes();
595 0 : m_xMetaData = pMetaData;
596 0 : }
597 : // -------------------------------------------------------------------------
598 0 : void ODatabaseMetaDataResultSet::setExportedKeysMap()
599 : {
600 0 : ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
601 0 : pMetaData->setExportedKeysMap();
602 0 : m_xMetaData = pMetaData;
603 0 : }
604 : // -------------------------------------------------------------------------
605 0 : void ODatabaseMetaDataResultSet::setImportedKeysMap()
606 : {
607 0 : ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
608 0 : pMetaData->setImportedKeysMap();
609 0 : m_xMetaData = pMetaData;
610 0 : }
611 : // -----------------------------------------------------------------------------
612 0 : Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL ODatabaseMetaDataResultSet::getPropertySetInfo( ) throw(RuntimeException)
613 : {
614 0 : return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
615 : }
616 : // -----------------------------------------------------------------------------
617 0 : ORowSetValueDecorator& ORowSetValueDecorator::operator=(const ORowSetValue& _aValue)
618 : {
619 0 : m_aValue = _aValue;
620 0 : return *this;
621 : }
622 : // -----------------------------------------------------------------------------
623 1268 : const ORowSetValue& ODatabaseMetaDataResultSet::getValue(sal_Int32 columnIndex)
624 : {
625 1268 : ::osl::MutexGuard aGuard( m_aMutex );
626 1268 : checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
627 :
628 1268 : if ( isBeforeFirst() || isAfterLast() )
629 0 : ::dbtools::throwFunctionSequenceException( *this );
630 :
631 1268 : checkIndex(columnIndex );
632 1268 : m_nColPos = columnIndex;
633 :
634 1268 : if(m_aRowsIter != m_aRows.end() && (*m_aRowsIter)[columnIndex].is())
635 1268 : return *(*m_aRowsIter)[columnIndex];
636 0 : return m_aEmptyValue;
637 : }
638 : // -----------------------------------------------------------------------------
639 : /// return an empty ORowSetValueDecorator
640 391 : ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getEmptyValue()
641 : {
642 391 : static ORowSetValueDecoratorRef aEmptyValueRef = new ORowSetValueDecorator();
643 391 : return aEmptyValueRef;
644 : }
645 : // -----------------------------------------------------------------------------
646 : /// return an ORowSetValueDecorator with 0 as value
647 0 : ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::get0Value()
648 : {
649 0 : static ORowSetValueDecoratorRef a0ValueRef = new ORowSetValueDecorator((sal_Int32)0);
650 0 : return a0ValueRef;
651 : }
652 : // -----------------------------------------------------------------------------
653 : /// return an ORowSetValueDecorator with 1 as value
654 0 : ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::get1Value()
655 : {
656 0 : static ORowSetValueDecoratorRef a1ValueRef = new ORowSetValueDecorator((sal_Int32)1);
657 0 : return a1ValueRef;
658 : }
659 : // -----------------------------------------------------------------------------
660 : /// return an ORowSetValueDecorator with ColumnSearch::BASIC as value
661 0 : ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getBasicValue()
662 : {
663 0 : static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(ColumnSearch::BASIC);
664 0 : return aValueRef;
665 : }
666 : // -----------------------------------------------------------------------------
667 0 : ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getSelectValue()
668 : {
669 0 : static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SELECT")));
670 0 : return aValueRef;
671 : }
672 : // -----------------------------------------------------------------------------
673 0 : ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getInsertValue()
674 : {
675 0 : static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("INSERT")));
676 0 : return aValueRef;
677 : }
678 : // -----------------------------------------------------------------------------
679 0 : ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getDeleteValue()
680 : {
681 0 : static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DELETE")));
682 0 : return aValueRef;
683 : }
684 : // -----------------------------------------------------------------------------
685 0 : ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getUpdateValue()
686 : {
687 0 : static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UPDATE")));
688 0 : return aValueRef;
689 : }
690 : // -----------------------------------------------------------------------------
691 0 : ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getCreateValue()
692 : {
693 0 : static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CREATE")));
694 0 : return aValueRef;
695 : }
696 : // -----------------------------------------------------------------------------
697 0 : ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getReadValue()
698 : {
699 0 : static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("READ")));
700 0 : return aValueRef;
701 : }
702 : // -----------------------------------------------------------------------------
703 0 : ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getAlterValue()
704 : {
705 0 : static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ALTER")));
706 0 : return aValueRef;
707 : }
708 : // -----------------------------------------------------------------------------
709 0 : ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getDropValue()
710 : {
711 0 : static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DROP")));
712 0 : return aValueRef;
713 : }
714 : // -----------------------------------------------------------------------------
715 0 : ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getQuoteValue()
716 : {
717 0 : static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("'")));
718 0 : return aValueRef;
719 : }
720 : // -----------------------------------------------------------------------------
721 0 : void SAL_CALL ODatabaseMetaDataResultSet::initialize( const Sequence< Any >& _aArguments ) throw (Exception, RuntimeException)
722 : {
723 0 : if ( _aArguments.getLength() == 2 )
724 : {
725 0 : sal_Int32 nResultSetType = 0;
726 0 : if ( _aArguments[0] >>= nResultSetType)
727 : {
728 0 : setType(static_cast<MetaDataResultSetType>(nResultSetType));
729 0 : Sequence< Sequence<Any> > aRows;
730 0 : if ( _aArguments[1] >>= aRows )
731 : {
732 0 : ORows aRowsToSet;
733 0 : const Sequence<Any>* pRowsIter = aRows.getConstArray();
734 0 : const Sequence<Any>* pRowsEnd = pRowsIter + aRows.getLength();
735 0 : for (; pRowsIter != pRowsEnd;++pRowsIter)
736 : {
737 0 : ORow aRowToSet;
738 0 : const Any* pRowIter = pRowsIter->getConstArray();
739 0 : const Any* pRowEnd = pRowIter + pRowsIter->getLength();
740 0 : for (; pRowIter != pRowEnd;++pRowIter)
741 : {
742 0 : ORowSetValueDecoratorRef aValue;
743 0 : switch( pRowIter->getValueTypeClass() )
744 : {
745 : case TypeClass_BOOLEAN:
746 : {
747 0 : sal_Bool bValue = sal_False;
748 0 : *pRowIter >>= bValue;
749 0 : aValue = new ORowSetValueDecorator(ORowSetValue(bValue));
750 : }
751 0 : break;
752 : case TypeClass_BYTE:
753 : {
754 0 : sal_Int8 nValue(0);
755 0 : *pRowIter >>= nValue;
756 0 : aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
757 : }
758 0 : break;
759 : case TypeClass_SHORT:
760 : case TypeClass_UNSIGNED_SHORT:
761 : {
762 0 : sal_Int16 nValue(0);
763 0 : *pRowIter >>= nValue;
764 0 : aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
765 : }
766 0 : break;
767 : case TypeClass_LONG:
768 : case TypeClass_UNSIGNED_LONG:
769 : {
770 0 : sal_Int32 nValue(0);
771 0 : *pRowIter >>= nValue;
772 0 : aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
773 : }
774 0 : break;
775 : case TypeClass_HYPER:
776 : case TypeClass_UNSIGNED_HYPER:
777 : {
778 0 : sal_Int64 nValue(0);
779 0 : *pRowIter >>= nValue;
780 0 : aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
781 : }
782 0 : break;
783 : case TypeClass_FLOAT:
784 : {
785 0 : float nValue(0.0);
786 0 : *pRowIter >>= nValue;
787 0 : aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
788 : }
789 0 : break;
790 : case TypeClass_DOUBLE:
791 : {
792 0 : double nValue(0.0);
793 0 : *pRowIter >>= nValue;
794 0 : aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
795 : }
796 0 : break;
797 : case TypeClass_STRING:
798 : {
799 0 : ::rtl::OUString sValue;
800 0 : *pRowIter >>= sValue;
801 0 : aValue = new ORowSetValueDecorator(ORowSetValue(sValue));
802 : }
803 0 : break;
804 : default:
805 0 : break;
806 : }
807 0 : aRowToSet.push_back(aValue);
808 0 : }
809 0 : aRowsToSet.push_back(aRowToSet);
810 0 : } // for (; pRowsIter != pRowsEnd;++pRowsIter
811 0 : setRows(aRowsToSet);
812 0 : }
813 : }
814 : }
815 0 : }
816 : // XServiceInfo
817 : // --------------------------------------------------------------------------------
818 : //------------------------------------------------------------------------------
819 0 : rtl::OUString ODatabaseMetaDataResultSet::getImplementationName_Static( ) throw(RuntimeException)
820 : {
821 0 : return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.helper.DatabaseMetaDataResultSet"));
822 : }
823 : //------------------------------------------------------------------------------
824 0 : Sequence< ::rtl::OUString > ODatabaseMetaDataResultSet::getSupportedServiceNames_Static( ) throw (RuntimeException)
825 : {
826 0 : Sequence< ::rtl::OUString > aSNS( 1 );
827 0 : aSNS[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdbc.ResultSet"));
828 0 : return aSNS;
829 : }
830 : //------------------------------------------------------------------
831 0 : ::rtl::OUString SAL_CALL ODatabaseMetaDataResultSet::getImplementationName( ) throw(RuntimeException)
832 : {
833 0 : return getImplementationName_Static();
834 : }
835 :
836 : //------------------------------------------------------------------
837 0 : sal_Bool SAL_CALL ODatabaseMetaDataResultSet::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
838 : {
839 0 : Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
840 0 : const ::rtl::OUString* pSupported = aSupported.getConstArray();
841 0 : const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
842 0 : for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
843 : ;
844 :
845 0 : return pSupported != pEnd;
846 : }
847 : //------------------------------------------------------------------
848 0 : Sequence< ::rtl::OUString > SAL_CALL ODatabaseMetaDataResultSet::getSupportedServiceNames( ) throw(RuntimeException)
849 : {
850 0 : return getSupportedServiceNames_Static();
851 : }
852 : // -------------------------------------------------------------------------
853 : namespace connectivity
854 : {
855 0 : Reference< XInterface > SAL_CALL ODatabaseMetaDataResultSet_CreateInstance(const Reference< XComponentContext >& ) throw( Exception )
856 : {
857 0 : return *(new ODatabaseMetaDataResultSet());
858 : }
859 : }
860 :
861 : // -----------------------------------------------------------------------------
862 : namespace
863 : {
864 : cppu::ImplementationEntry entries[] = {
865 : { &ODatabaseMetaDataResultSet_CreateInstance, &ODatabaseMetaDataResultSet::getImplementationName_Static, &ODatabaseMetaDataResultSet::getSupportedServiceNames_Static,
866 : &cppu::createSingleComponentFactory, 0, 0 },
867 : { &ParameterSubstitution::create, &ParameterSubstitution::getImplementationName_Static, &ParameterSubstitution::getSupportedServiceNames_Static,
868 : &cppu::createSingleComponentFactory, 0, 0 },
869 : { 0, 0, 0, 0, 0, 0 }
870 : };
871 : }
872 : using ::rtl::OUString;
873 : using ::com::sun::star::uno::Reference;
874 : using ::com::sun::star::uno::Sequence;
875 : using ::com::sun::star::registry::XRegistryKey;
876 : using ::com::sun::star::registry::InvalidRegistryException;
877 : using ::com::sun::star::registry::InvalidValueException;
878 : using ::com::sun::star::lang::XMultiServiceFactory;
879 :
880 : //==========================================================================
881 : //= registration
882 : //==========================================================================
883 : extern "C"
884 : {
885 :
886 : //---------------------------------------------------------------------------------------
887 0 : SAL_DLLPUBLIC_EXPORT void* SAL_CALL dbtools_component_getFactory(const sal_Char* implName, ::com::sun::star::lang::XMultiServiceFactory* serviceManager, void* registryKey)
888 : {
889 0 : return cppu::component_getFactoryHelper(implName, serviceManager, registryKey, entries);
890 : }
891 :
892 : } // extern "C"
893 :
894 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|