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