bump product version to 4.1.6.2
[LibreOffice.git] / connectivity / source / commontools / FDatabaseMetaDataResultSet.cxx
blobb25e3bd25929e5f64051efdb5a2bc5a80de3a741
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 .
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"
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 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 ,m_bEOF(sal_True)
61 construct();
64 // -------------------------------------------------------------------------
65 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 ,m_bEOF(sal_True)
73 construct();
75 setType(_eType);
78 // -------------------------------------------------------------------------
79 ODatabaseMetaDataResultSet::~ODatabaseMetaDataResultSet()
82 // -------------------------------------------------------------------------
83 void ODatabaseMetaDataResultSet::construct()
85 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), PROPERTY_ID_FETCHSIZE, 0,&m_nFetchSize, ::getCppuType(static_cast<sal_Int32*>(0)));
86 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), PROPERTY_ID_RESULTSETTYPE, PropertyAttribute::READONLY,&m_nResultSetType, ::getCppuType(static_cast<sal_Int32*>(0)));
87 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), PROPERTY_ID_FETCHDIRECTION, 0, &m_nFetchDirection, ::getCppuType(static_cast<sal_Int32*>(0)));
88 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), PROPERTY_ID_RESULTSETCONCURRENCY, PropertyAttribute::READONLY,&m_nResultSetConcurrency, ::getCppuType(static_cast<sal_Int32*>(0)));
90 // -----------------------------------------------------------------------------
91 void ODatabaseMetaDataResultSet::setType(MetaDataResultSetType _eType)
93 switch( _eType )
95 case eCatalogs: setCatalogsMap(); break;
96 case eSchemas: setSchemasMap(); break;
97 case eColumnPrivileges: setColumnPrivilegesMap(); break;
98 case eColumns: setColumnsMap(); break;
99 case eTables: setTablesMap(); break;
100 case eTableTypes: setTableTypes(); break;
101 case eProcedureColumns: setProcedureColumnsMap(); break;
102 case eProcedures: setProceduresMap(); break;
103 case eExportedKeys: setExportedKeysMap(); break;
104 case eImportedKeys: setImportedKeysMap(); break;
105 case ePrimaryKeys: setPrimaryKeysMap(); break;
106 case eIndexInfo: setIndexInfoMap(); break;
107 case eTablePrivileges: setTablePrivilegesMap(); break;
108 case eCrossReference: setCrossReferenceMap(); break;
109 case eTypeInfo: setTypeInfoMap(); break;
110 case eBestRowIdentifier: setBestRowIdentifierMap(); break;
111 case eVersionColumns: setVersionColumnsMap(); break;
112 default:
113 OSL_FAIL("Wrong type!");
116 // -------------------------------------------------------------------------
117 void ODatabaseMetaDataResultSet::disposing(void)
119 OPropertySetHelper::disposing();
121 ::osl::MutexGuard aGuard(m_aMutex);
122 m_aStatement = NULL;
123 m_xMetaData.clear();
124 m_aRowsIter = m_aRows.end();
125 m_aRows.clear();
126 m_aRowsIter = m_aRows.end();
128 // -----------------------------------------------------------------------------
129 void SAL_CALL ODatabaseMetaDataResultSet::acquire() throw()
131 ODatabaseMetaDataResultSet_BASE::acquire();
133 // -----------------------------------------------------------------------------
134 void SAL_CALL ODatabaseMetaDataResultSet::release() throw()
136 ODatabaseMetaDataResultSet_BASE::release();
138 // -------------------------------------------------------------------------
139 Any SAL_CALL ODatabaseMetaDataResultSet::queryInterface( const Type & rType ) throw(RuntimeException)
141 Any aRet = OPropertySetHelper::queryInterface(rType);
142 return aRet.hasValue() ? aRet : ODatabaseMetaDataResultSet_BASE::queryInterface(rType);
144 // -------------------------------------------------------------------------
145 Sequence< Type > SAL_CALL ODatabaseMetaDataResultSet::getTypes( ) throw(RuntimeException)
147 ::cppu::OTypeCollection aTypes( ::getCppuType( (const Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ),
148 ::getCppuType( (const Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ),
149 ::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet > *)0 ));
151 return ::comphelper::concatSequences(aTypes.getTypes(),ODatabaseMetaDataResultSet_BASE::getTypes());
153 // -----------------------------------------------------------------------------
154 void ODatabaseMetaDataResultSet::setRows(const ORows& _rRows)
156 m_aRows = _rRows;
157 m_bBOF = sal_True;
158 m_bEOF = m_aRows.empty();
160 // -------------------------------------------------------------------------
161 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::findColumn( const OUString& columnName ) throw(SQLException, RuntimeException)
163 ::osl::MutexGuard aGuard( m_aMutex );
164 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
167 Reference< XResultSetMetaData > xMeta = getMetaData();
168 sal_Int32 nLen = xMeta->getColumnCount();
169 sal_Int32 i = 1;
170 for(;i<=nLen;++i)
171 if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) :
172 columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i))
174 break;
175 return i;
177 // -----------------------------------------------------------------------------
178 void ODatabaseMetaDataResultSet::checkIndex(sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException)
180 if(columnIndex >= (sal_Int32)(*m_aRowsIter).size() || columnIndex < 1)
181 ::dbtools::throwInvalidIndexException(*this);
183 // -------------------------------------------------------------------------
184 Reference< ::com::sun::star::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getBinaryStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
186 return NULL;
188 // -------------------------------------------------------------------------
189 Reference< ::com::sun::star::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getCharacterStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
191 return NULL;
194 // -------------------------------------------------------------------------
195 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
197 return getValue(columnIndex);
199 // -------------------------------------------------------------------------
201 sal_Int8 SAL_CALL ODatabaseMetaDataResultSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
203 return getValue(columnIndex);
205 // -------------------------------------------------------------------------
207 Sequence< sal_Int8 > SAL_CALL ODatabaseMetaDataResultSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
209 return getValue(columnIndex);
211 // -------------------------------------------------------------------------
213 ::com::sun::star::util::Date SAL_CALL ODatabaseMetaDataResultSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
215 return getValue(columnIndex);
217 // -------------------------------------------------------------------------
219 double SAL_CALL ODatabaseMetaDataResultSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
221 return getValue(columnIndex);
223 // -------------------------------------------------------------------------
225 float SAL_CALL ODatabaseMetaDataResultSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
227 return getValue(columnIndex);
229 // -------------------------------------------------------------------------
231 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
233 return getValue(columnIndex);
236 // -------------------------------------------------------------------------
238 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getRow( ) throw(SQLException, RuntimeException)
240 return 0;
242 // -------------------------------------------------------------------------
244 sal_Int64 SAL_CALL ODatabaseMetaDataResultSet::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
246 return getValue(columnIndex);
248 // -------------------------------------------------------------------------
250 Reference< XResultSetMetaData > SAL_CALL ODatabaseMetaDataResultSet::getMetaData( ) throw(SQLException, RuntimeException)
252 ::osl::MutexGuard aGuard( m_aMutex );
253 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
256 if(!m_xMetaData.is())
257 m_xMetaData = new ODatabaseMetaDataResultSetMetaData();
259 return m_xMetaData;
261 // -------------------------------------------------------------------------
262 Reference< XArray > SAL_CALL ODatabaseMetaDataResultSet::getArray( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
264 return NULL;
267 // -------------------------------------------------------------------------
269 Reference< XClob > SAL_CALL ODatabaseMetaDataResultSet::getClob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
271 return NULL;
273 // -------------------------------------------------------------------------
274 Reference< XBlob > SAL_CALL ODatabaseMetaDataResultSet::getBlob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
276 return NULL;
278 // -------------------------------------------------------------------------
280 Reference< XRef > SAL_CALL ODatabaseMetaDataResultSet::getRef( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
282 return NULL;
284 // -------------------------------------------------------------------------
286 Any SAL_CALL ODatabaseMetaDataResultSet::getObject( sal_Int32 columnIndex, const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
288 return getValue(columnIndex).makeAny();
290 // -------------------------------------------------------------------------
292 sal_Int16 SAL_CALL ODatabaseMetaDataResultSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
294 return getValue(columnIndex);
296 // -------------------------------------------------------------------------
298 OUString SAL_CALL ODatabaseMetaDataResultSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
300 return getValue(columnIndex);
303 // -------------------------------------------------------------------------
306 ::com::sun::star::util::Time SAL_CALL ODatabaseMetaDataResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
308 return getValue(columnIndex);
310 // -------------------------------------------------------------------------
313 ::com::sun::star::util::DateTime SAL_CALL ODatabaseMetaDataResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
315 return getValue(columnIndex);
317 // -------------------------------------------------------------------------
319 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isAfterLast( ) throw(SQLException, RuntimeException)
321 return m_bEOF;
323 // -------------------------------------------------------------------------
324 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isFirst( ) throw(SQLException, RuntimeException)
326 ::dbtools::throwFunctionSequenceException(*this);
327 return sal_False;
329 // -------------------------------------------------------------------------
330 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isLast( ) throw(SQLException, RuntimeException)
332 ::dbtools::throwFunctionSequenceException(*this);
333 return sal_False;
335 // -------------------------------------------------------------------------
336 void SAL_CALL ODatabaseMetaDataResultSet::beforeFirst( ) throw(SQLException, RuntimeException)
338 ::dbtools::throwFunctionSequenceException(*this);
340 // -------------------------------------------------------------------------
341 void SAL_CALL ODatabaseMetaDataResultSet::afterLast( ) throw(SQLException, RuntimeException)
343 ::dbtools::throwFunctionSequenceException(*this);
345 // -------------------------------------------------------------------------
347 void SAL_CALL ODatabaseMetaDataResultSet::close( ) throw(SQLException, RuntimeException)
350 ::osl::MutexGuard aGuard( m_aMutex );
351 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
354 dispose();
356 // -------------------------------------------------------------------------
358 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::first( ) throw(SQLException, RuntimeException)
360 ::dbtools::throwFunctionSequenceException(*this);
361 return sal_False;
363 // -------------------------------------------------------------------------
365 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::last( ) throw(SQLException, RuntimeException)
367 ::dbtools::throwFunctionSequenceException(*this);
368 return sal_False;
370 // -------------------------------------------------------------------------
371 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::absolute( sal_Int32 /*row*/ ) throw(SQLException, RuntimeException)
373 ::dbtools::throwFunctionSequenceException(*this);
374 return sal_False;
376 // -------------------------------------------------------------------------
377 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::relative( sal_Int32 /*row*/ ) throw(SQLException, RuntimeException)
379 ::dbtools::throwFunctionSequenceException(*this);
380 return sal_False;
382 // -------------------------------------------------------------------------
383 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::previous( ) throw(SQLException, RuntimeException)
385 ::dbtools::throwFunctionSequenceException(*this);
386 return sal_False;
388 // -------------------------------------------------------------------------
389 Reference< XInterface > SAL_CALL ODatabaseMetaDataResultSet::getStatement( ) throw(SQLException, RuntimeException)
391 return m_aStatement.get();
393 // -------------------------------------------------------------------------
395 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowDeleted( ) throw(SQLException, RuntimeException)
397 ::dbtools::throwFunctionSequenceException(*this);
398 return sal_False;
400 // -------------------------------------------------------------------------
401 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowInserted( ) throw(SQLException, RuntimeException)
403 ::dbtools::throwFunctionSequenceException(*this);
404 return sal_False;
406 // -------------------------------------------------------------------------
407 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowUpdated( ) throw(SQLException, RuntimeException)
409 ::dbtools::throwFunctionSequenceException(*this);
410 return sal_False;
412 // -------------------------------------------------------------------------
414 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isBeforeFirst( ) throw(SQLException, RuntimeException)
416 return m_bBOF;
418 // -------------------------------------------------------------------------
420 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::next( ) throw(SQLException, RuntimeException)
422 ::osl::MutexGuard aGuard( m_aMutex );
423 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
425 if ( m_bBOF )
427 m_aRowsIter = m_aRows.begin();
428 m_bBOF = sal_False;
430 else
432 if ( m_bEOF )
433 throwFunctionSequenceException( *this );
434 else
435 if ( m_aRowsIter != m_aRows.end() )
436 ++m_aRowsIter;
439 bool bSuccess = m_aRowsIter != m_aRows.end();
440 if ( !bSuccess )
442 m_bEOF = sal_True;
443 m_bBOF = m_aRows.empty();
445 return bSuccess;
447 // -------------------------------------------------------------------------
449 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::wasNull( ) throw(SQLException, RuntimeException)
451 ::osl::MutexGuard aGuard( m_aMutex );
452 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
455 if(m_aRowsIter == m_aRows.end() || !(*m_aRowsIter)[m_nColPos].is())
456 return sal_True;
458 return (*m_aRowsIter)[m_nColPos]->getValue().isNull();
460 // -------------------------------------------------------------------------
461 void SAL_CALL ODatabaseMetaDataResultSet::refreshRow( ) throw(SQLException, RuntimeException)
464 // -------------------------------------------------------------------------
466 void SAL_CALL ODatabaseMetaDataResultSet::cancel( ) throw(RuntimeException)
469 // -------------------------------------------------------------------------
470 void SAL_CALL ODatabaseMetaDataResultSet::clearWarnings( ) throw(SQLException, RuntimeException)
473 // -------------------------------------------------------------------------
474 Any SAL_CALL ODatabaseMetaDataResultSet::getWarnings( ) throw(SQLException, RuntimeException)
476 return Any();
478 // -------------------------------------------------------------------------
479 ::cppu::IPropertyArrayHelper* ODatabaseMetaDataResultSet::createArrayHelper( ) const
481 Sequence< Property > aProps;
482 describeProperties(aProps);
483 return new ::cppu::OPropertyArrayHelper(aProps);
485 // -------------------------------------------------------------------------
486 ::cppu::IPropertyArrayHelper & ODatabaseMetaDataResultSet::getInfoHelper()
488 return *const_cast<ODatabaseMetaDataResultSet*>(this)->getArrayHelper();
490 // -------------------------------------------------------------------------
491 void ODatabaseMetaDataResultSet::setProceduresMap()
493 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
494 pMetaData->setProceduresMap();
495 m_xMetaData = pMetaData;
497 // -------------------------------------------------------------------------
498 void ODatabaseMetaDataResultSet::setCatalogsMap()
500 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
501 pMetaData->setCatalogsMap();
502 m_xMetaData = pMetaData;
504 // -------------------------------------------------------------------------
505 void ODatabaseMetaDataResultSet::setSchemasMap()
507 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
508 pMetaData->setSchemasMap();
509 m_xMetaData = pMetaData;
511 // -------------------------------------------------------------------------
512 void ODatabaseMetaDataResultSet::setColumnPrivilegesMap()
514 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
515 pMetaData->setColumnPrivilegesMap();
516 m_xMetaData = pMetaData;
518 // -------------------------------------------------------------------------
519 void ODatabaseMetaDataResultSet::setColumnsMap()
522 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
523 pMetaData->setColumnsMap();
524 m_xMetaData = pMetaData;
526 // -------------------------------------------------------------------------
527 void ODatabaseMetaDataResultSet::setTablesMap()
530 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
531 pMetaData->setTablesMap();
532 m_xMetaData = pMetaData;
534 // -------------------------------------------------------------------------
535 void ODatabaseMetaDataResultSet::setProcedureColumnsMap()
537 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
538 pMetaData->setProcedureColumnsMap();
539 m_xMetaData = pMetaData;
541 // -------------------------------------------------------------------------
542 void ODatabaseMetaDataResultSet::setPrimaryKeysMap()
544 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
545 pMetaData->setPrimaryKeysMap();
546 m_xMetaData = pMetaData;
548 // -------------------------------------------------------------------------
549 void ODatabaseMetaDataResultSet::setIndexInfoMap()
551 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
552 pMetaData->setIndexInfoMap();
553 m_xMetaData = pMetaData;
555 // -------------------------------------------------------------------------
556 void ODatabaseMetaDataResultSet::setTablePrivilegesMap()
558 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
559 pMetaData->setTablePrivilegesMap();
560 m_xMetaData = pMetaData;
562 // -------------------------------------------------------------------------
563 void ODatabaseMetaDataResultSet::setCrossReferenceMap()
565 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
566 pMetaData->setCrossReferenceMap();
567 m_xMetaData = pMetaData;
569 // -------------------------------------------------------------------------
570 void ODatabaseMetaDataResultSet::setVersionColumnsMap()
572 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
573 pMetaData->setVersionColumnsMap();
574 m_xMetaData = pMetaData;
576 // -------------------------------------------------------------------------
577 void ODatabaseMetaDataResultSet::setBestRowIdentifierMap()
579 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
580 pMetaData->setBestRowIdentifierMap();
581 m_xMetaData = pMetaData;
583 // -------------------------------------------------------------------------
584 void ODatabaseMetaDataResultSet::setTypeInfoMap()
586 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
587 pMetaData->setTypeInfoMap();
588 m_xMetaData = pMetaData;
590 // -------------------------------------------------------------------------
591 void ODatabaseMetaDataResultSet::setTableTypes()
593 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
594 pMetaData->setTableTypes();
595 m_xMetaData = pMetaData;
597 // -------------------------------------------------------------------------
598 void ODatabaseMetaDataResultSet::setExportedKeysMap()
600 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
601 pMetaData->setExportedKeysMap();
602 m_xMetaData = pMetaData;
604 // -------------------------------------------------------------------------
605 void ODatabaseMetaDataResultSet::setImportedKeysMap()
607 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
608 pMetaData->setImportedKeysMap();
609 m_xMetaData = pMetaData;
611 // -----------------------------------------------------------------------------
612 Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL ODatabaseMetaDataResultSet::getPropertySetInfo( ) throw(RuntimeException)
614 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
616 // -----------------------------------------------------------------------------
617 ORowSetValueDecorator& ORowSetValueDecorator::operator=(const ORowSetValue& _aValue)
619 m_aValue = _aValue;
620 return *this;
622 // -----------------------------------------------------------------------------
623 const ORowSetValue& ODatabaseMetaDataResultSet::getValue(sal_Int32 columnIndex)
625 ::osl::MutexGuard aGuard( m_aMutex );
626 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
628 if ( isBeforeFirst() || isAfterLast() )
629 ::dbtools::throwFunctionSequenceException( *this );
631 checkIndex(columnIndex );
632 m_nColPos = columnIndex;
634 if(m_aRowsIter != m_aRows.end() && (*m_aRowsIter)[columnIndex].is())
635 return *(*m_aRowsIter)[columnIndex];
636 return m_aEmptyValue;
638 // -----------------------------------------------------------------------------
639 /// return an empty ORowSetValueDecorator
640 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getEmptyValue()
642 static ORowSetValueDecoratorRef aEmptyValueRef = new ORowSetValueDecorator();
643 return aEmptyValueRef;
645 // -----------------------------------------------------------------------------
646 /// return an ORowSetValueDecorator with 0 as value
647 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::get0Value()
649 static ORowSetValueDecoratorRef a0ValueRef = new ORowSetValueDecorator((sal_Int32)0);
650 return a0ValueRef;
652 // -----------------------------------------------------------------------------
653 /// return an ORowSetValueDecorator with 1 as value
654 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::get1Value()
656 static ORowSetValueDecoratorRef a1ValueRef = new ORowSetValueDecorator((sal_Int32)1);
657 return a1ValueRef;
659 // -----------------------------------------------------------------------------
660 /// return an ORowSetValueDecorator with ColumnSearch::BASIC as value
661 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getBasicValue()
663 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(ColumnSearch::BASIC);
664 return aValueRef;
666 // -----------------------------------------------------------------------------
667 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getSelectValue()
669 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(OUString("SELECT"));
670 return aValueRef;
672 // -----------------------------------------------------------------------------
673 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getInsertValue()
675 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(OUString("INSERT"));
676 return aValueRef;
678 // -----------------------------------------------------------------------------
679 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getDeleteValue()
681 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(OUString("DELETE"));
682 return aValueRef;
684 // -----------------------------------------------------------------------------
685 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getUpdateValue()
687 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(OUString("UPDATE"));
688 return aValueRef;
690 // -----------------------------------------------------------------------------
691 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getCreateValue()
693 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(OUString("CREATE"));
694 return aValueRef;
696 // -----------------------------------------------------------------------------
697 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getReadValue()
699 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(OUString("READ"));
700 return aValueRef;
702 // -----------------------------------------------------------------------------
703 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getAlterValue()
705 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(OUString("ALTER"));
706 return aValueRef;
708 // -----------------------------------------------------------------------------
709 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getDropValue()
711 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(OUString("DROP"));
712 return aValueRef;
714 // -----------------------------------------------------------------------------
715 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getQuoteValue()
717 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(OUString("'"));
718 return aValueRef;
720 // -----------------------------------------------------------------------------
721 void SAL_CALL ODatabaseMetaDataResultSet::initialize( const Sequence< Any >& _aArguments ) throw (Exception, RuntimeException)
723 if ( _aArguments.getLength() == 2 )
725 sal_Int32 nResultSetType = 0;
726 if ( _aArguments[0] >>= nResultSetType)
728 setType(static_cast<MetaDataResultSetType>(nResultSetType));
729 Sequence< Sequence<Any> > aRows;
730 if ( _aArguments[1] >>= aRows )
732 ORows aRowsToSet;
733 const Sequence<Any>* pRowsIter = aRows.getConstArray();
734 const Sequence<Any>* pRowsEnd = pRowsIter + aRows.getLength();
735 for (; pRowsIter != pRowsEnd;++pRowsIter)
737 ORow aRowToSet;
738 const Any* pRowIter = pRowsIter->getConstArray();
739 const Any* pRowEnd = pRowIter + pRowsIter->getLength();
740 for (; pRowIter != pRowEnd;++pRowIter)
742 ORowSetValueDecoratorRef aValue;
743 switch( pRowIter->getValueTypeClass() )
745 case TypeClass_BOOLEAN:
747 sal_Bool bValue = sal_False;
748 *pRowIter >>= bValue;
749 aValue = new ORowSetValueDecorator(ORowSetValue(bValue));
751 break;
752 case TypeClass_BYTE:
754 sal_Int8 nValue(0);
755 *pRowIter >>= nValue;
756 aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
758 break;
759 case TypeClass_SHORT:
760 case TypeClass_UNSIGNED_SHORT:
762 sal_Int16 nValue(0);
763 *pRowIter >>= nValue;
764 aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
766 break;
767 case TypeClass_LONG:
768 case TypeClass_UNSIGNED_LONG:
770 sal_Int32 nValue(0);
771 *pRowIter >>= nValue;
772 aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
774 break;
775 case TypeClass_HYPER:
776 case TypeClass_UNSIGNED_HYPER:
778 sal_Int64 nValue(0);
779 *pRowIter >>= nValue;
780 aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
782 break;
783 case TypeClass_FLOAT:
785 float nValue(0.0);
786 *pRowIter >>= nValue;
787 aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
789 break;
790 case TypeClass_DOUBLE:
792 double nValue(0.0);
793 *pRowIter >>= nValue;
794 aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
796 break;
797 case TypeClass_STRING:
799 OUString sValue;
800 *pRowIter >>= sValue;
801 aValue = new ORowSetValueDecorator(ORowSetValue(sValue));
803 break;
804 default:
805 break;
807 aRowToSet.push_back(aValue);
809 aRowsToSet.push_back(aRowToSet);
810 } // for (; pRowsIter != pRowsEnd;++pRowsIter
811 setRows(aRowsToSet);
816 // XServiceInfo
817 // --------------------------------------------------------------------------------
818 //------------------------------------------------------------------------------
819 OUString ODatabaseMetaDataResultSet::getImplementationName_Static( ) throw(RuntimeException)
821 return OUString("org.openoffice.comp.helper.DatabaseMetaDataResultSet");
823 //------------------------------------------------------------------------------
824 Sequence< OUString > ODatabaseMetaDataResultSet::getSupportedServiceNames_Static( ) throw (RuntimeException)
826 Sequence< OUString > aSNS( 1 );
827 aSNS[0] = "com.sun.star.sdbc.ResultSet";
828 return aSNS;
830 //------------------------------------------------------------------
831 OUString SAL_CALL ODatabaseMetaDataResultSet::getImplementationName( ) throw(RuntimeException)
833 return getImplementationName_Static();
836 //------------------------------------------------------------------
837 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::supportsService( const OUString& _rServiceName ) throw(RuntimeException)
839 Sequence< OUString > aSupported(getSupportedServiceNames());
840 const OUString* pSupported = aSupported.getConstArray();
841 const OUString* pEnd = pSupported + aSupported.getLength();
842 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
845 return pSupported != pEnd;
847 //------------------------------------------------------------------
848 Sequence< OUString > SAL_CALL ODatabaseMetaDataResultSet::getSupportedServiceNames( ) throw(RuntimeException)
850 return getSupportedServiceNames_Static();
852 // -------------------------------------------------------------------------
853 namespace connectivity
855 Reference< XInterface > SAL_CALL ODatabaseMetaDataResultSet_CreateInstance(const Reference< XComponentContext >& ) throw( Exception )
857 return *(new ODatabaseMetaDataResultSet());
861 // -----------------------------------------------------------------------------
862 namespace
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 }
872 using ::com::sun::star::uno::Reference;
873 using ::com::sun::star::uno::Sequence;
874 using ::com::sun::star::registry::XRegistryKey;
875 using ::com::sun::star::registry::InvalidRegistryException;
876 using ::com::sun::star::registry::InvalidValueException;
877 using ::com::sun::star::lang::XMultiServiceFactory;
879 //==========================================================================
880 //= registration
881 //==========================================================================
882 extern "C"
885 //---------------------------------------------------------------------------------------
886 SAL_DLLPUBLIC_EXPORT void* SAL_CALL dbtools_component_getFactory(const sal_Char* implName, ::com::sun::star::lang::XMultiServiceFactory* serviceManager, void* registryKey)
888 return cppu::component_getFactoryHelper(implName, serviceManager, registryKey, entries);
891 } // extern "C"
893 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */