merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / commontools / FDatabaseMetaDataResultSet.cxx
blob17fe520b1d832b0d44a05ce6912c5252afa7a4f0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: FDatabaseMetaDataResultSet.cxx,v $
10 * $Revision: 1.24 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
34 #include "ParameterSubstitution.hxx"
35 #include "FDatabaseMetaDataResultSet.hxx"
36 #include "FDatabaseMetaDataResultSetMetaData.hxx"
37 #include <com/sun/star/sdbc/DataType.hpp>
38 #include <com/sun/star/sdbc/ColumnSearch.hpp>
39 #include <com/sun/star/sdbc/KeyRule.hpp>
40 #include <com/sun/star/sdbc/ProcedureResult.hpp>
41 #include <com/sun/star/sdbc/IndexType.hpp>
42 #include <comphelper/property.hxx>
43 #include <com/sun/star/lang/DisposedException.hpp>
44 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
45 #include <com/sun/star/sdbc/ResultSetType.hpp>
46 #include <com/sun/star/sdbc/FetchDirection.hpp>
47 #include <com/sun/star/beans/PropertyAttribute.hpp>
48 #include <cppuhelper/typeprovider.hxx>
49 #include <comphelper/sequence.hxx>
50 #include <cppuhelper/factory.hxx>
51 #include <cppuhelper/implementationentry.hxx>
52 #include "connectivity/dbexception.hxx"
53 #include "TConnection.hxx"
55 using namespace connectivity;
56 using namespace dbtools;
57 using namespace cppu;
58 //------------------------------------------------------------------------------
59 using namespace ::com::sun::star::beans;
60 using namespace ::com::sun::star::uno;
61 using namespace ::com::sun::star::sdbcx;
62 using namespace ::com::sun::star::sdbc;
63 using namespace ::com::sun::star::container;
64 using namespace ::com::sun::star::lang;
65 // -------------------------------------------------------------------------
66 ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet()
67 :ODatabaseMetaDataResultSet_BASE(m_aMutex)
68 ,::comphelper::OPropertyContainer(ODatabaseMetaDataResultSet_BASE::rBHelper)
69 ,m_aStatement(NULL)
70 ,m_xMetaData(NULL)
71 ,m_bBOF(sal_True)
72 ,m_bEOF(sal_True)
74 construct();
77 // -------------------------------------------------------------------------
78 ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet( MetaDataResultSetType _eType )
79 :ODatabaseMetaDataResultSet_BASE(m_aMutex)
80 ,::comphelper::OPropertyContainer(ODatabaseMetaDataResultSet_BASE::rBHelper)
81 ,m_aStatement(NULL)
82 ,m_xMetaData(NULL)
83 ,m_bBOF(sal_True)
84 ,m_bEOF(sal_True)
86 construct();
88 setType(_eType);
91 // -------------------------------------------------------------------------
92 ODatabaseMetaDataResultSet::~ODatabaseMetaDataResultSet()
95 // -------------------------------------------------------------------------
96 void ODatabaseMetaDataResultSet::construct()
98 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), PROPERTY_ID_FETCHSIZE, 0,&m_nFetchSize, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
99 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), PROPERTY_ID_RESULTSETTYPE, PropertyAttribute::READONLY,&m_nResultSetType, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
100 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), PROPERTY_ID_FETCHDIRECTION, 0, &m_nFetchDirection, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
101 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), PROPERTY_ID_RESULTSETCONCURRENCY, PropertyAttribute::READONLY,&m_nResultSetConcurrency, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
103 // -----------------------------------------------------------------------------
104 void ODatabaseMetaDataResultSet::setType(MetaDataResultSetType _eType)
106 switch( _eType )
108 case eCatalogs: setCatalogsMap(); break;
109 case eSchemas: setSchemasMap(); break;
110 case eColumnPrivileges: setColumnPrivilegesMap(); break;
111 case eColumns: setColumnsMap(); break;
112 case eTables: setTablesMap(); break;
113 case eTableTypes: setTableTypes(); break;
114 case eProcedureColumns: setProcedureColumnsMap(); break;
115 case eProcedures: setProceduresMap(); break;
116 case eExportedKeys: setExportedKeysMap(); break;
117 case eImportedKeys: setImportedKeysMap(); break;
118 case ePrimaryKeys: setPrimaryKeysMap(); break;
119 case eIndexInfo: setIndexInfoMap(); break;
120 case eTablePrivileges: setTablePrivilegesMap(); break;
121 case eCrossReference: setCrossReferenceMap(); break;
122 case eTypeInfo: setTypeInfoMap(); break;
123 case eBestRowIdentifier: setBestRowIdentifierMap(); break;
124 case eVersionColumns: setVersionColumnsMap(); break;
125 default:
126 OSL_ENSURE(0,"Wrong type!");
129 // -------------------------------------------------------------------------
130 void ODatabaseMetaDataResultSet::disposing(void)
132 OPropertySetHelper::disposing();
134 ::osl::MutexGuard aGuard(m_aMutex);
135 m_aStatement = NULL;
136 m_xMetaData.clear();
137 m_aRowsIter = m_aRows.end();
138 m_aRows.clear();
139 m_aRowsIter = m_aRows.end();
141 // -----------------------------------------------------------------------------
142 void SAL_CALL ODatabaseMetaDataResultSet::acquire() throw()
144 ODatabaseMetaDataResultSet_BASE::acquire();
146 // -----------------------------------------------------------------------------
147 void SAL_CALL ODatabaseMetaDataResultSet::release() throw()
149 ODatabaseMetaDataResultSet_BASE::release();
151 // -------------------------------------------------------------------------
152 Any SAL_CALL ODatabaseMetaDataResultSet::queryInterface( const Type & rType ) throw(RuntimeException)
154 Any aRet = OPropertySetHelper::queryInterface(rType);
155 return aRet.hasValue() ? aRet : ODatabaseMetaDataResultSet_BASE::queryInterface(rType);
157 // -------------------------------------------------------------------------
158 Sequence< Type > SAL_CALL ODatabaseMetaDataResultSet::getTypes( ) throw(RuntimeException)
160 ::cppu::OTypeCollection aTypes( ::getCppuType( (const Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ),
161 ::getCppuType( (const Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ),
162 ::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet > *)0 ));
164 return ::comphelper::concatSequences(aTypes.getTypes(),ODatabaseMetaDataResultSet_BASE::getTypes());
166 // -----------------------------------------------------------------------------
167 void ODatabaseMetaDataResultSet::setRows(const ORows& _rRows)
169 m_aRows = _rRows;
170 m_bBOF = sal_True;
171 m_bEOF = m_aRows.empty();
173 // -------------------------------------------------------------------------
174 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::findColumn( const ::rtl::OUString& columnName ) throw(SQLException, RuntimeException)
176 ::osl::MutexGuard aGuard( m_aMutex );
177 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
180 Reference< XResultSetMetaData > xMeta = getMetaData();
181 sal_Int32 nLen = xMeta->getColumnCount();
182 sal_Int32 i = 1;
183 for(;i<=nLen;++i)
184 if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) :
185 columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i))
187 break;
188 return i;
190 // -----------------------------------------------------------------------------
191 void ODatabaseMetaDataResultSet::checkIndex(sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException)
193 if(columnIndex >= (sal_Int32)(*m_aRowsIter).size() || columnIndex < 1)
194 ::dbtools::throwInvalidIndexException(*this);
196 // -------------------------------------------------------------------------
197 Reference< ::com::sun::star::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getBinaryStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
199 return NULL;
201 // -------------------------------------------------------------------------
202 Reference< ::com::sun::star::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getCharacterStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
204 return NULL;
207 // -------------------------------------------------------------------------
208 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
210 return getValue(columnIndex);
212 // -------------------------------------------------------------------------
214 sal_Int8 SAL_CALL ODatabaseMetaDataResultSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
216 return getValue(columnIndex);
218 // -------------------------------------------------------------------------
220 Sequence< sal_Int8 > SAL_CALL ODatabaseMetaDataResultSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
222 return getValue(columnIndex);
224 // -------------------------------------------------------------------------
226 ::com::sun::star::util::Date SAL_CALL ODatabaseMetaDataResultSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
228 return getValue(columnIndex);
230 // -------------------------------------------------------------------------
232 double SAL_CALL ODatabaseMetaDataResultSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
234 return getValue(columnIndex);
236 // -------------------------------------------------------------------------
238 float SAL_CALL ODatabaseMetaDataResultSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
240 return getValue(columnIndex);
242 // -------------------------------------------------------------------------
244 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
246 return getValue(columnIndex);
249 // -------------------------------------------------------------------------
251 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getRow( ) throw(SQLException, RuntimeException)
253 return 0;
255 // -------------------------------------------------------------------------
257 sal_Int64 SAL_CALL ODatabaseMetaDataResultSet::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
259 return getValue(columnIndex);
261 // -------------------------------------------------------------------------
263 Reference< XResultSetMetaData > SAL_CALL ODatabaseMetaDataResultSet::getMetaData( ) throw(SQLException, RuntimeException)
265 ::osl::MutexGuard aGuard( m_aMutex );
266 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
269 if(!m_xMetaData.is())
270 m_xMetaData = new ODatabaseMetaDataResultSetMetaData();
272 return m_xMetaData;
274 // -------------------------------------------------------------------------
275 Reference< XArray > SAL_CALL ODatabaseMetaDataResultSet::getArray( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
277 return NULL;
280 // -------------------------------------------------------------------------
282 Reference< XClob > SAL_CALL ODatabaseMetaDataResultSet::getClob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
284 return NULL;
286 // -------------------------------------------------------------------------
287 Reference< XBlob > SAL_CALL ODatabaseMetaDataResultSet::getBlob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
289 return NULL;
291 // -------------------------------------------------------------------------
293 Reference< XRef > SAL_CALL ODatabaseMetaDataResultSet::getRef( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
295 return NULL;
297 // -------------------------------------------------------------------------
299 Any SAL_CALL ODatabaseMetaDataResultSet::getObject( sal_Int32 columnIndex, const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
301 return getValue(columnIndex).makeAny();
303 // -------------------------------------------------------------------------
305 sal_Int16 SAL_CALL ODatabaseMetaDataResultSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
307 return getValue(columnIndex);
309 // -------------------------------------------------------------------------
311 ::rtl::OUString SAL_CALL ODatabaseMetaDataResultSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
313 return getValue(columnIndex);
316 // -------------------------------------------------------------------------
319 ::com::sun::star::util::Time SAL_CALL ODatabaseMetaDataResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
321 return getValue(columnIndex);
323 // -------------------------------------------------------------------------
326 ::com::sun::star::util::DateTime SAL_CALL ODatabaseMetaDataResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
328 return getValue(columnIndex);
330 // -------------------------------------------------------------------------
332 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isAfterLast( ) throw(SQLException, RuntimeException)
334 return m_bEOF;
336 // -------------------------------------------------------------------------
337 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isFirst( ) throw(SQLException, RuntimeException)
339 ::dbtools::throwFunctionSequenceException(*this);
340 return sal_False;
342 // -------------------------------------------------------------------------
343 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isLast( ) throw(SQLException, RuntimeException)
345 ::dbtools::throwFunctionSequenceException(*this);
346 return sal_False;
348 // -------------------------------------------------------------------------
349 void SAL_CALL ODatabaseMetaDataResultSet::beforeFirst( ) throw(SQLException, RuntimeException)
351 ::dbtools::throwFunctionSequenceException(*this);
353 // -------------------------------------------------------------------------
354 void SAL_CALL ODatabaseMetaDataResultSet::afterLast( ) throw(SQLException, RuntimeException)
356 ::dbtools::throwFunctionSequenceException(*this);
358 // -------------------------------------------------------------------------
360 void SAL_CALL ODatabaseMetaDataResultSet::close( ) throw(SQLException, RuntimeException)
363 ::osl::MutexGuard aGuard( m_aMutex );
364 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
367 dispose();
369 // -------------------------------------------------------------------------
371 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::first( ) throw(SQLException, RuntimeException)
373 ::dbtools::throwFunctionSequenceException(*this);
374 return sal_False;
376 // -------------------------------------------------------------------------
378 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::last( ) throw(SQLException, RuntimeException)
380 ::dbtools::throwFunctionSequenceException(*this);
381 return sal_False;
383 // -------------------------------------------------------------------------
384 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::absolute( sal_Int32 /*row*/ ) throw(SQLException, RuntimeException)
386 ::dbtools::throwFunctionSequenceException(*this);
387 return sal_False;
389 // -------------------------------------------------------------------------
390 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::relative( sal_Int32 /*row*/ ) throw(SQLException, RuntimeException)
392 ::dbtools::throwFunctionSequenceException(*this);
393 return sal_False;
395 // -------------------------------------------------------------------------
396 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::previous( ) throw(SQLException, RuntimeException)
398 ::dbtools::throwFunctionSequenceException(*this);
399 return sal_False;
401 // -------------------------------------------------------------------------
402 Reference< XInterface > SAL_CALL ODatabaseMetaDataResultSet::getStatement( ) throw(SQLException, RuntimeException)
404 return m_aStatement.get();
406 // -------------------------------------------------------------------------
408 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowDeleted( ) throw(SQLException, RuntimeException)
410 ::dbtools::throwFunctionSequenceException(*this);
411 return sal_False;
413 // -------------------------------------------------------------------------
414 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowInserted( ) throw(SQLException, RuntimeException)
416 ::dbtools::throwFunctionSequenceException(*this);
417 return sal_False;
419 // -------------------------------------------------------------------------
420 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowUpdated( ) throw(SQLException, RuntimeException)
422 ::dbtools::throwFunctionSequenceException(*this);
423 return sal_False;
425 // -------------------------------------------------------------------------
427 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isBeforeFirst( ) throw(SQLException, RuntimeException)
429 return m_bBOF;
431 // -------------------------------------------------------------------------
433 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::next( ) throw(SQLException, RuntimeException)
435 ::osl::MutexGuard aGuard( m_aMutex );
436 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
438 if ( m_bBOF )
440 m_aRowsIter = m_aRows.begin();
441 m_bBOF = sal_False;
443 else
445 if ( m_bEOF )
446 throwFunctionSequenceException( *this );
447 else
448 if ( m_aRowsIter != m_aRows.end() )
449 ++m_aRowsIter;
452 bool bSuccess = m_aRowsIter != m_aRows.end();
453 if ( !bSuccess )
455 m_bEOF = sal_True;
456 m_bBOF = m_aRows.empty();
458 return bSuccess;
460 // -------------------------------------------------------------------------
462 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::wasNull( ) throw(SQLException, RuntimeException)
464 ::osl::MutexGuard aGuard( m_aMutex );
465 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
468 if(m_aRowsIter == m_aRows.end() || !(*m_aRowsIter)[m_nColPos].isValid())
469 return sal_True;
471 return (*m_aRowsIter)[m_nColPos]->getValue().isNull();
473 // -------------------------------------------------------------------------
474 void SAL_CALL ODatabaseMetaDataResultSet::refreshRow( ) throw(SQLException, RuntimeException)
477 // -------------------------------------------------------------------------
479 void SAL_CALL ODatabaseMetaDataResultSet::cancel( ) throw(RuntimeException)
482 // -------------------------------------------------------------------------
483 void SAL_CALL ODatabaseMetaDataResultSet::clearWarnings( ) throw(SQLException, RuntimeException)
486 // -------------------------------------------------------------------------
487 Any SAL_CALL ODatabaseMetaDataResultSet::getWarnings( ) throw(SQLException, RuntimeException)
489 return Any();
491 // -------------------------------------------------------------------------
492 ::cppu::IPropertyArrayHelper* ODatabaseMetaDataResultSet::createArrayHelper( ) const
494 Sequence< Property > aProps;
495 describeProperties(aProps);
496 return new ::cppu::OPropertyArrayHelper(aProps);
498 // -------------------------------------------------------------------------
499 ::cppu::IPropertyArrayHelper & ODatabaseMetaDataResultSet::getInfoHelper()
501 return *const_cast<ODatabaseMetaDataResultSet*>(this)->getArrayHelper();
503 // -------------------------------------------------------------------------
504 void ODatabaseMetaDataResultSet::setProceduresMap()
506 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
507 pMetaData->setProceduresMap();
508 m_xMetaData = pMetaData;
510 // -------------------------------------------------------------------------
511 void ODatabaseMetaDataResultSet::setCatalogsMap()
513 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
514 pMetaData->setCatalogsMap();
515 m_xMetaData = pMetaData;
517 // -------------------------------------------------------------------------
518 void ODatabaseMetaDataResultSet::setSchemasMap()
520 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
521 pMetaData->setSchemasMap();
522 m_xMetaData = pMetaData;
524 // -------------------------------------------------------------------------
525 void ODatabaseMetaDataResultSet::setColumnPrivilegesMap()
527 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
528 pMetaData->setColumnPrivilegesMap();
529 m_xMetaData = pMetaData;
531 // -------------------------------------------------------------------------
532 void ODatabaseMetaDataResultSet::setColumnsMap()
535 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
536 pMetaData->setColumnsMap();
537 m_xMetaData = pMetaData;
539 // -------------------------------------------------------------------------
540 void ODatabaseMetaDataResultSet::setTablesMap()
543 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
544 pMetaData->setTablesMap();
545 m_xMetaData = pMetaData;
547 // -------------------------------------------------------------------------
548 void ODatabaseMetaDataResultSet::setProcedureColumnsMap()
550 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
551 pMetaData->setProcedureColumnsMap();
552 m_xMetaData = pMetaData;
554 // -------------------------------------------------------------------------
555 void ODatabaseMetaDataResultSet::setPrimaryKeysMap()
557 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
558 pMetaData->setPrimaryKeysMap();
559 m_xMetaData = pMetaData;
561 // -------------------------------------------------------------------------
562 void ODatabaseMetaDataResultSet::setIndexInfoMap()
564 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
565 pMetaData->setIndexInfoMap();
566 m_xMetaData = pMetaData;
568 // -------------------------------------------------------------------------
569 void ODatabaseMetaDataResultSet::setTablePrivilegesMap()
571 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
572 pMetaData->setTablePrivilegesMap();
573 m_xMetaData = pMetaData;
575 // -------------------------------------------------------------------------
576 void ODatabaseMetaDataResultSet::setCrossReferenceMap()
578 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
579 pMetaData->setCrossReferenceMap();
580 m_xMetaData = pMetaData;
582 // -------------------------------------------------------------------------
583 void ODatabaseMetaDataResultSet::setVersionColumnsMap()
585 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
586 pMetaData->setVersionColumnsMap();
587 m_xMetaData = pMetaData;
589 // -------------------------------------------------------------------------
590 void ODatabaseMetaDataResultSet::setBestRowIdentifierMap()
592 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
593 pMetaData->setBestRowIdentifierMap();
594 m_xMetaData = pMetaData;
596 // -------------------------------------------------------------------------
597 void ODatabaseMetaDataResultSet::setTypeInfoMap()
599 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
600 pMetaData->setTypeInfoMap();
601 m_xMetaData = pMetaData;
603 // -------------------------------------------------------------------------
604 void ODatabaseMetaDataResultSet::setTableTypes()
606 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
607 pMetaData->setTableTypes();
608 m_xMetaData = pMetaData;
610 // -------------------------------------------------------------------------
611 void ODatabaseMetaDataResultSet::setExportedKeysMap()
613 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
614 pMetaData->setExportedKeysMap();
615 m_xMetaData = pMetaData;
617 // -------------------------------------------------------------------------
618 void ODatabaseMetaDataResultSet::setImportedKeysMap()
620 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
621 pMetaData->setImportedKeysMap();
622 m_xMetaData = pMetaData;
624 // -----------------------------------------------------------------------------
625 Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL ODatabaseMetaDataResultSet::getPropertySetInfo( ) throw(RuntimeException)
627 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
629 // -----------------------------------------------------------------------------
630 ORowSetValueDecorator& ORowSetValueDecorator::operator=(const ORowSetValue& _aValue)
632 m_aValue = _aValue;
633 return *this;
635 // -----------------------------------------------------------------------------
636 const ORowSetValue& ODatabaseMetaDataResultSet::getValue(sal_Int32 columnIndex)
638 ::osl::MutexGuard aGuard( m_aMutex );
639 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
641 if ( isBeforeFirst() || isAfterLast() )
642 ::dbtools::throwFunctionSequenceException( *this );
644 checkIndex(columnIndex );
645 m_nColPos = columnIndex;
647 if(m_aRowsIter != m_aRows.end() && (*m_aRowsIter)[columnIndex].isValid())
648 return *(*m_aRowsIter)[columnIndex];
649 return m_aEmptyValue;
651 // -----------------------------------------------------------------------------
652 /// return an empty ORowSetValueDecorator
653 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getEmptyValue()
655 static ORowSetValueDecoratorRef aEmptyValueRef = new ORowSetValueDecorator();
656 return aEmptyValueRef;
658 // -----------------------------------------------------------------------------
659 /// return an ORowSetValueDecorator with 0 as value
660 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::get0Value()
662 static ORowSetValueDecoratorRef a0ValueRef = new ORowSetValueDecorator((sal_Int32)0);
663 return a0ValueRef;
665 // -----------------------------------------------------------------------------
666 /// return an ORowSetValueDecorator with 1 as value
667 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::get1Value()
669 static ORowSetValueDecoratorRef a1ValueRef = new ORowSetValueDecorator((sal_Int32)1);
670 return a1ValueRef;
672 // -----------------------------------------------------------------------------
673 /// return an ORowSetValueDecorator with ColumnSearch::BASIC as value
674 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getBasicValue()
676 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(ColumnSearch::BASIC);
677 return aValueRef;
679 // -----------------------------------------------------------------------------
680 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getSelectValue()
682 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("SELECT"));
683 return aValueRef;
685 // -----------------------------------------------------------------------------
686 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getInsertValue()
688 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("INSERT"));
689 return aValueRef;
691 // -----------------------------------------------------------------------------
692 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getDeleteValue()
694 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("DELETE"));
695 return aValueRef;
697 // -----------------------------------------------------------------------------
698 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getUpdateValue()
700 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("UPDATE"));
701 return aValueRef;
703 // -----------------------------------------------------------------------------
704 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getCreateValue()
706 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("CREATE"));
707 return aValueRef;
709 // -----------------------------------------------------------------------------
710 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getReadValue()
712 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("READ"));
713 return aValueRef;
715 // -----------------------------------------------------------------------------
716 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getAlterValue()
718 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("ALTER"));
719 return aValueRef;
721 // -----------------------------------------------------------------------------
722 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getDropValue()
724 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("DROP"));
725 return aValueRef;
727 // -----------------------------------------------------------------------------
728 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getQuoteValue()
730 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("'"));
731 return aValueRef;
733 // -----------------------------------------------------------------------------
734 void SAL_CALL ODatabaseMetaDataResultSet::initialize( const Sequence< Any >& _aArguments ) throw (Exception, RuntimeException)
736 if ( _aArguments.getLength() == 2 )
738 sal_Int32 nResultSetType = 0;
739 if ( _aArguments[0] >>= nResultSetType)
741 setType(static_cast<MetaDataResultSetType>(nResultSetType));
742 Sequence< Sequence<Any> > aRows;
743 if ( _aArguments[1] >>= aRows )
745 ORows aRowsToSet;
746 const Sequence<Any>* pRowsIter = aRows.getConstArray();
747 const Sequence<Any>* pRowsEnd = pRowsIter + aRows.getLength();
748 for (; pRowsIter != pRowsEnd;++pRowsIter)
750 ORow aRowToSet;
751 const Any* pRowIter = pRowsIter->getConstArray();
752 const Any* pRowEnd = pRowIter + pRowsIter->getLength();
753 for (; pRowIter != pRowEnd;++pRowIter)
755 ORowSetValueDecoratorRef aValue;
756 switch( pRowIter->getValueTypeClass() )
758 case TypeClass_BOOLEAN:
760 sal_Bool bValue = sal_False;
761 *pRowIter >>= bValue;
762 aValue = new ORowSetValueDecorator(ORowSetValue(bValue));
764 break;
765 case TypeClass_BYTE:
767 sal_Int8 nValue;
768 *pRowIter >>= nValue;
769 aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
771 break;
772 case TypeClass_SHORT:
773 case TypeClass_UNSIGNED_SHORT:
775 sal_Int16 nValue;
776 *pRowIter >>= nValue;
777 aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
779 break;
780 case TypeClass_LONG:
781 case TypeClass_UNSIGNED_LONG:
783 sal_Int32 nValue;
784 *pRowIter >>= nValue;
785 aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
787 break;
788 case TypeClass_HYPER:
789 case TypeClass_UNSIGNED_HYPER:
791 sal_Int64 nValue;
792 *pRowIter >>= nValue;
793 aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
795 break;
796 case TypeClass_FLOAT:
798 float nValue;
799 *pRowIter >>= nValue;
800 aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
802 break;
803 case TypeClass_DOUBLE:
805 double nValue;
806 *pRowIter >>= nValue;
807 aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
809 break;
810 case TypeClass_STRING:
812 ::rtl::OUString sValue;
813 *pRowIter >>= sValue;
814 aValue = new ORowSetValueDecorator(ORowSetValue(sValue));
816 break;
817 default:
818 break;
820 aRowToSet.push_back(aValue);
822 aRowsToSet.push_back(aRowToSet);
823 } // for (; pRowsIter != pRowsEnd;++pRowsIter
824 setRows(aRowsToSet);
829 // XServiceInfo
830 // --------------------------------------------------------------------------------
831 //------------------------------------------------------------------------------
832 rtl::OUString ODatabaseMetaDataResultSet::getImplementationName_Static( ) throw(RuntimeException)
834 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.helper.DatabaseMetaDataResultSet"));
836 //------------------------------------------------------------------------------
837 Sequence< ::rtl::OUString > ODatabaseMetaDataResultSet::getSupportedServiceNames_Static( ) throw (RuntimeException)
839 Sequence< ::rtl::OUString > aSNS( 1 );
840 aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.ResultSet");
841 return aSNS;
843 //------------------------------------------------------------------
844 ::rtl::OUString SAL_CALL ODatabaseMetaDataResultSet::getImplementationName( ) throw(RuntimeException)
846 return getImplementationName_Static();
849 //------------------------------------------------------------------
850 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
852 Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
853 const ::rtl::OUString* pSupported = aSupported.getConstArray();
854 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
855 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
858 return pSupported != pEnd;
860 //------------------------------------------------------------------
861 Sequence< ::rtl::OUString > SAL_CALL ODatabaseMetaDataResultSet::getSupportedServiceNames( ) throw(RuntimeException)
863 return getSupportedServiceNames_Static();
865 // -------------------------------------------------------------------------
866 namespace connectivity
868 Reference< XInterface > SAL_CALL ODatabaseMetaDataResultSet_CreateInstance(const Reference< XComponentContext >& ) throw( Exception )
870 return *(new ODatabaseMetaDataResultSet());
874 // -----------------------------------------------------------------------------
875 namespace
877 cppu::ImplementationEntry entries[] = {
878 { &ODatabaseMetaDataResultSet_CreateInstance, &ODatabaseMetaDataResultSet::getImplementationName_Static, &ODatabaseMetaDataResultSet::getSupportedServiceNames_Static,
879 &cppu::createSingleComponentFactory, 0, 0 },
880 { &ParameterSubstitution::create, &ParameterSubstitution::getImplementationName_Static, &ParameterSubstitution::getSupportedServiceNames_Static,
881 &cppu::createSingleComponentFactory, 0, 0 },
882 { 0, 0, 0, 0, 0, 0 }
885 using ::rtl::OUString;
886 using ::com::sun::star::uno::Reference;
887 using ::com::sun::star::uno::Sequence;
888 using ::com::sun::star::registry::XRegistryKey;
889 using ::com::sun::star::registry::InvalidRegistryException;
890 using ::com::sun::star::registry::InvalidValueException;
891 using ::com::sun::star::lang::XMultiServiceFactory;
893 //==========================================================================
894 //= registration
895 //==========================================================================
896 extern "C"
899 //---------------------------------------------------------------------------------------
900 SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(const sal_Char** _ppEnvTypeName, uno_Environment** /*_ppEnv*/)
902 *_ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
905 //---------------------------------------------------------------------------------------
906 SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo(void* serviceManager, com::sun::star::registry::XRegistryKey* registryKey)
908 return cppu::component_writeInfoHelper(serviceManager, registryKey, entries);
910 //---------------------------------------------------------------------------------------
911 SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(const sal_Char* implName, ::com::sun::star::lang::XMultiServiceFactory* serviceManager, void* registryKey)
913 return cppu::component_getFactoryHelper(implName, serviceManager, registryKey, entries);
916 } // extern "C"