Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / connectivity / source / drivers / ado / ADatabaseMetaDataResultSet.cxx
blobbb5bda634cfcaa944ff60dd131fcd0f27641df66
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 .
20 #include <comphelper/sequence.hxx>
21 #include <ado/ADatabaseMetaDataResultSet.hxx>
22 #include <ado/ADatabaseMetaDataResultSetMetaData.hxx>
23 #include <com/sun/star/sdbc/ColumnSearch.hpp>
24 #include <com/sun/star/sdbc/DataType.hpp>
25 #include <com/sun/star/sdbc/ColumnValue.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 <cppuhelper/typeprovider.hxx>
35 #include <comphelper/seqstream.hxx>
36 #include <connectivity/dbexception.hxx>
37 #include <rtl/ref.hxx>
39 #include <oledb.h>
41 using namespace dbtools;
42 using namespace connectivity::ado;
43 using namespace cppu;
44 using namespace ::comphelper;
46 using namespace com::sun::star::uno;
47 using namespace com::sun::star::lang;
48 using namespace com::sun::star::beans;
49 using namespace com::sun::star::sdbc;
52 ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet(ADORecordset* _pRecordSet)
53 :ODatabaseMetaDataResultSet_BASE(m_aMutex)
54 ,OPropertySetHelper(ODatabaseMetaDataResultSet_BASE::rBHelper)
55 ,m_pRecordSet(_pRecordSet)
56 ,m_nRowPos(0)
57 ,m_bWasNull(false)
58 ,m_bEOF(false)
59 ,m_bOnFirstAfterOpen(false)
61 osl_atomic_increment( &m_refCount );
62 m_aColMapping.push_back(-1);
63 if(_pRecordSet)
65 m_pRecordSet->AddRef();
66 VARIANT_BOOL bIsAtBOF;
67 m_pRecordSet->get_BOF(&bIsAtBOF);
68 m_bOnFirstAfterOpen = bIsAtBOF != VARIANT_TRUE;
70 else
71 m_bOnFirstAfterOpen = false;
72 osl_atomic_decrement( &m_refCount );
73 // allocBuffer();
77 ODatabaseMetaDataResultSet::~ODatabaseMetaDataResultSet()
79 if(m_pRecordSet)
80 m_pRecordSet->Release();
83 void ODatabaseMetaDataResultSet::disposing()
85 OPropertySetHelper::disposing();
87 ::osl::MutexGuard aGuard(m_aMutex);
88 if(m_pRecordSet)
89 m_pRecordSet->Close();
90 m_aStatement.clear();
91 m_xMetaData.clear();
94 Any SAL_CALL ODatabaseMetaDataResultSet::queryInterface( const Type & rType )
96 Any aRet = OPropertySetHelper::queryInterface(rType);
97 return aRet.hasValue() ? aRet : ODatabaseMetaDataResultSet_BASE::queryInterface(rType);
100 css::uno::Sequence< css::uno::Type > SAL_CALL ODatabaseMetaDataResultSet::getTypes( )
102 ::cppu::OTypeCollection aTypes( cppu::UnoType<css::beans::XMultiPropertySet>::get(),
103 cppu::UnoType<css::beans::XFastPropertySet>::get(),
104 cppu::UnoType<css::beans::XPropertySet>::get());
106 return ::comphelper::concatSequences(aTypes.getTypes(),ODatabaseMetaDataResultSet_BASE::getTypes());
109 void ODatabaseMetaDataResultSet::checkRecordSet()
111 if(!m_pRecordSet)
112 throwFunctionSequenceException(*this);
116 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::findColumn( const OUString& columnName )
118 ::osl::MutexGuard aGuard( m_aMutex );
119 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
122 Reference< XResultSetMetaData > xMeta = getMetaData();
123 sal_Int32 nLen = xMeta->getColumnCount();
124 sal_Int32 i = 1;
125 for(;i<=nLen;++i)
127 if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) :
128 columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i)))
129 return i;
132 ::dbtools::throwInvalidColumnException( columnName, *this );
133 assert(false);
134 return 0; // Never reached
136 #define BLOCK_SIZE 256
138 Reference< css::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getBinaryStream( sal_Int32 columnIndex )
140 ::osl::MutexGuard aGuard( m_aMutex );
141 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
143 checkRecordSet();
146 columnIndex = mapColumn(columnIndex);
147 WpADOField aField = ADOS::getField(m_pRecordSet,columnIndex);
148 if((aField.GetAttributes() & adFldLong) == adFldLong)
150 //Copy the data only up to the Actual Size of Field.
151 sal_Int32 nSize = aField.GetActualSize();
152 Sequence<sal_Int8> aData(nSize);
153 sal_Int32 index = 0;
154 while(index < nSize)
156 m_aValue = aField.GetChunk(BLOCK_SIZE);
157 if(m_aValue.isNull())
158 break;
159 UCHAR chData;
160 for(LONG index2 = 0;index2 < BLOCK_SIZE;++index2)
162 HRESULT hr = ::SafeArrayGetElement(m_aValue.parray,&index2,&chData);
163 if(SUCCEEDED(hr))
165 //Take BYTE by BYTE and advance Memory Location
166 aData.getArray()[index++] = chData;
168 else
169 break;
172 return index ? Reference< css::io::XInputStream >(new SequenceInputStream(aData)) : Reference< css::io::XInputStream >();
174 // else we ask for a bytesequence
175 aField.get_Value(m_aValue);
176 if(m_aValue.isNull())
177 return nullptr;
178 return new SequenceInputStream(m_aValue.getByteSequence());
181 Reference< css::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getCharacterStream( sal_Int32 /*columnIndex*/ )
183 ::dbtools::throwFeatureNotImplementedSQLException( "XRow::getCharacterStream", *this );
184 return nullptr;
188 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::getBoolean( sal_Int32 columnIndex )
190 ::osl::MutexGuard aGuard( m_aMutex );
192 if ( !m_aValueRange.empty() && columnIndex == 11 && (m_aValueRangeIter = m_aValueRange.find(columnIndex)) != m_aValueRange.end() )
194 getValue(2);
195 if ( m_aValue.getInt16() != adCurrency )
196 return false;
198 return getValue(columnIndex).getBool();
202 sal_Int8 SAL_CALL ODatabaseMetaDataResultSet::getByte( sal_Int32 columnIndex )
204 ::osl::MutexGuard aGuard( m_aMutex );
206 getValue(columnIndex);
208 columnIndex = mapColumn(columnIndex);
210 if(m_aValue.isNull())
211 return 0;
212 if ( !m_aValueRange.empty() && (m_aValueRangeIter = m_aValueRange.find(columnIndex)) != m_aValueRange.end())
213 return static_cast<sal_Int8>((*m_aValueRangeIter).second[m_aValue.getInt32()]);
214 else if(m_aStrValueRange.size() && (m_aStrValueRangeIter = m_aStrValueRange.find(columnIndex)) != m_aStrValueRange.end())
215 return static_cast<sal_Int8>((*m_aStrValueRangeIter).second[m_aValue.getString()]);
217 return m_aValue.getInt8();
221 Sequence< sal_Int8 > SAL_CALL ODatabaseMetaDataResultSet::getBytes( sal_Int32 columnIndex )
223 return getValue(columnIndex).getByteSequence();
227 css::util::Date SAL_CALL ODatabaseMetaDataResultSet::getDate( sal_Int32 columnIndex )
229 return getValue(columnIndex).getDate();
233 double SAL_CALL ODatabaseMetaDataResultSet::getDouble( sal_Int32 columnIndex )
235 return getValue(columnIndex).getDouble();
239 float SAL_CALL ODatabaseMetaDataResultSet::getFloat( sal_Int32 columnIndex )
241 return getValue(columnIndex).getFloat();
245 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getInt( sal_Int32 columnIndex )
247 ::osl::MutexGuard aGuard( m_aMutex );
250 getValue(columnIndex);
252 columnIndex = mapColumn(columnIndex);
253 if(m_aValue.isNull())
254 return 0;
256 if(m_aValueRange.size() && (m_aValueRangeIter = m_aValueRange.find(columnIndex)) != m_aValueRange.end())
257 return (*m_aValueRangeIter).second[m_aValue.getInt32()];
258 else if(m_aStrValueRange.size() && (m_aStrValueRangeIter = m_aStrValueRange.find(columnIndex)) != m_aStrValueRange.end())
259 return (*m_aStrValueRangeIter).second[m_aValue.getString()];
261 return m_aValue.getInt32();
265 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getRow( )
267 ::dbtools::throwFeatureNotImplementedSQLException( "XResultSet::getRow", *this );
268 return 0;
272 sal_Int64 SAL_CALL ODatabaseMetaDataResultSet::getLong( sal_Int32 /*columnIndex*/ )
274 ::dbtools::throwFeatureNotImplementedSQLException( "XRow::getLong", *this );
275 return sal_Int64(0);
279 Reference< XResultSetMetaData > SAL_CALL ODatabaseMetaDataResultSet::getMetaData( )
281 ::osl::MutexGuard aGuard( m_aMutex );
282 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
284 checkRecordSet();
287 if(!m_xMetaData.is())
288 m_xMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this);
290 return m_xMetaData;
293 Reference< XArray > SAL_CALL ODatabaseMetaDataResultSet::getArray( sal_Int32 /*columnIndex*/ )
295 ::dbtools::throwFeatureNotImplementedSQLException( "XRow::getRow", *this );
296 return nullptr;
300 Reference< XClob > SAL_CALL ODatabaseMetaDataResultSet::getClob( sal_Int32 /*columnIndex*/ )
302 ::dbtools::throwFeatureNotImplementedSQLException( "XRow::getRow", *this );
303 return nullptr;
306 Reference< XBlob > SAL_CALL ODatabaseMetaDataResultSet::getBlob( sal_Int32 /*columnIndex*/ )
308 ::dbtools::throwFeatureNotImplementedSQLException( "XRow::getRow", *this );
309 return nullptr;
313 Reference< XRef > SAL_CALL ODatabaseMetaDataResultSet::getRef( sal_Int32 /*columnIndex*/ )
315 ::dbtools::throwFeatureNotImplementedSQLException( "XRow::getRow", *this );
316 return nullptr;
320 Any SAL_CALL ODatabaseMetaDataResultSet::getObject( sal_Int32 columnIndex, const Reference< css::container::XNameAccess >& /*typeMap*/ )
322 ::osl::MutexGuard aGuard( m_aMutex );
323 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
325 checkRecordSet();
328 columnIndex = mapColumn(columnIndex);
329 return Any();
333 sal_Int16 SAL_CALL ODatabaseMetaDataResultSet::getShort( sal_Int32 columnIndex )
335 ::osl::MutexGuard aGuard( m_aMutex );
337 getValue(columnIndex);
339 columnIndex = mapColumn(columnIndex);
340 if(m_aValue.isNull())
341 return 0;
343 if(m_aValueRange.size() && (m_aValueRangeIter = m_aValueRange.find(columnIndex)) != m_aValueRange.end())
344 return static_cast<sal_Int16>((*m_aValueRangeIter).second[m_aValue.getInt32()]);
345 else if(m_aStrValueRange.size() && (m_aStrValueRangeIter = m_aStrValueRange.find(columnIndex)) != m_aStrValueRange.end())
346 return static_cast<sal_Int16>((*m_aStrValueRangeIter).second[m_aValue.getString()]);
348 return m_aValue.getInt16();
352 OUString SAL_CALL ODatabaseMetaDataResultSet::getString( sal_Int32 columnIndex )
354 ::osl::MutexGuard aGuard( m_aMutex );
356 getValue(columnIndex);
359 columnIndex = mapColumn(columnIndex);
360 if(m_aValue.isNull())
361 return OUString();
362 if(m_aIntValueRange.size() && (m_aIntValueRangeIter = m_aIntValueRange.find(columnIndex)) != m_aIntValueRange.end())
363 return (*m_aIntValueRangeIter).second[m_aValue.getInt32()];
365 return m_aValue.getString();
369 css::util::Time SAL_CALL ODatabaseMetaDataResultSet::getTime( sal_Int32 columnIndex )
371 return getValue(columnIndex).getTime();
375 css::util::DateTime SAL_CALL ODatabaseMetaDataResultSet::getTimestamp( sal_Int32 columnIndex )
377 return getValue(columnIndex).getDateTime();
381 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isAfterLast( )
383 ::osl::MutexGuard aGuard( m_aMutex );
384 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
386 checkRecordSet();
389 VARIANT_BOOL bIsAtEOF;
390 m_pRecordSet->get_EOF(&bIsAtEOF);
391 return bIsAtEOF == VARIANT_TRUE;
394 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isFirst( )
396 ::osl::MutexGuard aGuard( m_aMutex );
397 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
399 checkRecordSet();
402 return m_nRowPos == 1;
405 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isLast( )
407 ::osl::MutexGuard aGuard( m_aMutex );
408 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
410 checkRecordSet();
413 return true;
416 void SAL_CALL ODatabaseMetaDataResultSet::beforeFirst( )
418 ::osl::MutexGuard aGuard( m_aMutex );
419 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
421 checkRecordSet();
424 if(first())
425 previous();
428 void SAL_CALL ODatabaseMetaDataResultSet::afterLast( )
430 ::osl::MutexGuard aGuard( m_aMutex );
431 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
433 checkRecordSet();
436 if(last())
437 next();
438 m_bEOF = true;
442 void SAL_CALL ODatabaseMetaDataResultSet::close( )
445 ::osl::MutexGuard aGuard( m_aMutex );
446 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
449 dispose();
453 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::first( )
455 ::osl::MutexGuard aGuard( m_aMutex );
456 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
459 if(!m_pRecordSet)
460 return false;
462 bool bRet = SUCCEEDED(m_pRecordSet->MoveFirst());
463 if ( bRet )
464 m_nRowPos = 1;
465 return bRet;
469 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::last( )
471 ::osl::MutexGuard aGuard( m_aMutex );
472 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
475 return m_pRecordSet && SUCCEEDED(m_pRecordSet->MoveLast());
478 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::absolute( sal_Int32 row )
480 ::osl::MutexGuard aGuard( m_aMutex );
481 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
484 if(first())
486 OLEVariant aEmpty;
487 aEmpty.setNoArg();
488 bool bRet = SUCCEEDED(m_pRecordSet->Move(row,aEmpty));
489 if(bRet)
490 m_nRowPos = row;
491 return bRet;
493 return false;
496 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::relative( sal_Int32 row )
498 ::osl::MutexGuard aGuard( m_aMutex );
499 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
502 if(!m_pRecordSet)
503 return false;
505 OLEVariant aEmpty;
506 aEmpty.setNoArg();
507 bool bRet = SUCCEEDED(m_pRecordSet->Move(row,aEmpty));
508 if(bRet)
509 m_nRowPos += row;
510 return bRet;
513 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::previous( )
515 ::osl::MutexGuard aGuard( m_aMutex );
516 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
519 if(!m_pRecordSet)
520 return false;
522 bool bRet = SUCCEEDED(m_pRecordSet->MovePrevious());
523 if(bRet)
524 --m_nRowPos;
525 return bRet;
528 Reference< XInterface > SAL_CALL ODatabaseMetaDataResultSet::getStatement( )
530 return m_aStatement.get();
534 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowDeleted( )
536 ::osl::MutexGuard aGuard( m_aMutex );
537 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
539 checkRecordSet();
542 sal_Int32 eRec;
543 m_pRecordSet->get_Status(&eRec);
544 return (RecordStatusEnum(eRec) & adRecDeleted) == adRecDeleted;
547 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowInserted( )
548 { ::osl::MutexGuard aGuard( m_aMutex );
549 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
551 checkRecordSet();
554 sal_Int32 eRec;
555 m_pRecordSet->get_Status(&eRec);
556 return (RecordStatusEnum(eRec) & adRecNew) == adRecNew;
559 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowUpdated( )
561 ::osl::MutexGuard aGuard( m_aMutex );
562 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
564 checkRecordSet();
567 sal_Int32 eRec;
568 m_pRecordSet->get_Status(&eRec);
569 return (RecordStatusEnum(eRec) & adRecModified) == adRecModified;
573 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isBeforeFirst( )
575 ::osl::MutexGuard aGuard( m_aMutex );
576 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
579 if(!m_pRecordSet)
580 return true;
582 VARIANT_BOOL bIsAtBOF;
583 m_pRecordSet->get_BOF(&bIsAtBOF);
584 return bIsAtBOF == VARIANT_TRUE;
588 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::next( )
590 ::osl::MutexGuard aGuard( m_aMutex );
591 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
594 if(!m_pRecordSet)
595 return false;
597 if(m_bOnFirstAfterOpen)
599 m_bOnFirstAfterOpen = false;
600 return true;
602 else
603 return SUCCEEDED(m_pRecordSet->MoveNext());
607 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::wasNull( )
609 ::osl::MutexGuard aGuard( m_aMutex );
610 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
612 checkRecordSet();
615 return m_aValue.isNull();
618 void SAL_CALL ODatabaseMetaDataResultSet::refreshRow( )
620 ::osl::MutexGuard aGuard( m_aMutex );
621 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
623 checkRecordSet();
626 m_pRecordSet->Resync(adAffectCurrent);
630 void SAL_CALL ODatabaseMetaDataResultSet::cancel( )
632 ::osl::MutexGuard aGuard( m_aMutex );
633 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
635 checkRecordSet();
638 m_pRecordSet->Cancel();
641 void SAL_CALL ODatabaseMetaDataResultSet::clearWarnings( )
645 Any SAL_CALL ODatabaseMetaDataResultSet::getWarnings( )
647 return Any();
650 sal_Int32 ODatabaseMetaDataResultSet::getResultSetConcurrency()
652 return ResultSetConcurrency::READ_ONLY;
655 sal_Int32 ODatabaseMetaDataResultSet::getResultSetType()
657 return ResultSetType::FORWARD_ONLY;
660 sal_Int32 ODatabaseMetaDataResultSet::getFetchDirection()
662 return FetchDirection::FORWARD;
665 sal_Int32 ODatabaseMetaDataResultSet::getFetchSize() const
667 sal_Int32 nValue=-1;
668 if(m_pRecordSet)
669 m_pRecordSet->get_CacheSize(&nValue);
670 return nValue;
673 OUString ODatabaseMetaDataResultSet::getCursorName()
675 return OUString();
679 void ODatabaseMetaDataResultSet::setFetchDirection(sal_Int32 /*_par0*/)
681 ::dbtools::throwFeatureNotImplementedSQLException( "ResultSet::FetchDirection", *this );
684 void ODatabaseMetaDataResultSet::setFetchSize(sal_Int32 _par0)
686 if(m_pRecordSet)
687 m_pRecordSet->put_CacheSize(_par0);
690 ::cppu::IPropertyArrayHelper* ODatabaseMetaDataResultSet::createArrayHelper( ) const
693 return new ::cppu::OPropertyArrayHelper
697 ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME),
698 PROPERTY_ID_CURSORNAME,
699 cppu::UnoType<OUString>::get(),
703 ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION),
704 PROPERTY_ID_FETCHDIRECTION,
705 cppu::UnoType<sal_Int32>::get(),
709 ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE),
710 PROPERTY_ID_FETCHSIZE,
711 cppu::UnoType<sal_Int32>::get(),
715 ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY),
716 PROPERTY_ID_RESULTSETCONCURRENCY,
717 cppu::UnoType<sal_Int32>::get(),
721 ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE),
722 PROPERTY_ID_RESULTSETTYPE,
723 cppu::UnoType<sal_Int32>::get(),
730 ::cppu::IPropertyArrayHelper & ODatabaseMetaDataResultSet::getInfoHelper()
732 return *getArrayHelper();
735 sal_Bool ODatabaseMetaDataResultSet::convertFastPropertyValue(
736 Any & rConvertedValue,
737 Any & rOldValue,
738 sal_Int32 nHandle,
739 const Any& rValue )
741 switch(nHandle)
743 case PROPERTY_ID_CURSORNAME:
744 case PROPERTY_ID_RESULTSETCONCURRENCY:
745 case PROPERTY_ID_RESULTSETTYPE:
746 throw css::lang::IllegalArgumentException();
747 case PROPERTY_ID_FETCHDIRECTION:
748 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection());
749 case PROPERTY_ID_FETCHSIZE:
750 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize());
751 default:
754 return false;
757 void ODatabaseMetaDataResultSet::setFastPropertyValue_NoBroadcast(
758 sal_Int32 nHandle,
759 const Any& /*rValue*/
762 switch(nHandle)
764 case PROPERTY_ID_CURSORNAME:
765 case PROPERTY_ID_RESULTSETCONCURRENCY:
766 case PROPERTY_ID_RESULTSETTYPE:
767 case PROPERTY_ID_FETCHDIRECTION:
768 case PROPERTY_ID_FETCHSIZE:
769 throw Exception("cannot set prop " + OUString::number(nHandle), nullptr);
770 default:
771 OSL_FAIL("setFastPropertyValue_NoBroadcast: Illegal handle value!");
775 void ODatabaseMetaDataResultSet::getFastPropertyValue(
776 Any& rValue,
777 sal_Int32 nHandle
778 ) const
780 switch(nHandle)
782 case PROPERTY_ID_CURSORNAME:
783 rValue <<= getCursorName();
784 break;
785 case PROPERTY_ID_RESULTSETCONCURRENCY:
786 rValue <<= getResultSetConcurrency();
787 break;
788 case PROPERTY_ID_RESULTSETTYPE:
789 rValue <<= getResultSetType();
790 break;
791 case PROPERTY_ID_FETCHDIRECTION:
792 rValue <<= getFetchDirection();
793 break;
794 case PROPERTY_ID_FETCHSIZE:
795 rValue <<= getFetchSize();
796 break;
800 void ODatabaseMetaDataResultSet::setProceduresMap()
802 for(sal_Int32 i=1;i<4;i++)
803 m_aColMapping.push_back(i);
804 m_aColMapping.push_back(5);
805 m_aColMapping.push_back(7);
806 m_aColMapping.push_back(8);
807 m_aColMapping.push_back(6);
808 m_aColMapping.push_back(4);
810 ::std::map<sal_Int32,sal_Int32> aMap
812 {DB_PT_UNKNOWN, ProcedureResult::UNKNOWN},
813 {DB_PT_PROCEDURE, ProcedureResult::NONE},
814 {DB_PT_FUNCTION, ProcedureResult::RETURN}
816 m_aValueRange[4] = aMap;
818 rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this);
819 pMetaData->setProceduresMap();
820 m_xMetaData = pMetaData;
823 void ODatabaseMetaDataResultSet::setCatalogsMap()
825 m_aColMapping.push_back(1);
827 m_xMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this);
830 void ODatabaseMetaDataResultSet::setSchemasMap()
832 m_aColMapping.push_back(2);
834 m_xMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this);
837 void ODatabaseMetaDataResultSet::setColumnPrivilegesMap()
840 m_aColMapping.push_back(3);
841 m_aColMapping.push_back(4);
842 m_aColMapping.push_back(5);
843 m_aColMapping.push_back(6);
844 m_aColMapping.push_back(2);
845 m_aColMapping.push_back(9);
846 m_aColMapping.push_back(10);
848 rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this);
849 pMetaData->setColumnPrivilegesMap();
850 m_xMetaData = pMetaData;
853 void ODatabaseMetaDataResultSet::setColumnsMap()
856 for(sal_Int32 i=1;i<5;++i)
857 m_aColMapping.push_back(i);
859 m_aColMapping.push_back(12);
860 m_aColMapping.push_back(12); // is used as TYPE_NAME
862 m_aColMapping.push_back(14);
863 m_aColMapping.push_back(6);
864 m_aColMapping.push_back(17);
865 m_aColMapping.push_back(18);
867 m_aColMapping.push_back(11);
868 m_aColMapping.push_back(29);
869 m_aColMapping.push_back(9);
870 m_aColMapping.push_back(18);
871 m_aColMapping.push_back(18);
873 m_aColMapping.push_back(15);
874 m_aColMapping.push_back(7);
875 m_aColMapping.push_back(11);
877 ::std::map<sal_Int32,sal_Int32> aMap {
878 {adEmpty, ADOS::MapADOType2Jdbc(adEmpty)},
879 {adTinyInt, ADOS::MapADOType2Jdbc(adTinyInt)},
880 {adSmallInt, ADOS::MapADOType2Jdbc(adSmallInt)},
881 {adInteger, ADOS::MapADOType2Jdbc(adInteger)},
882 {adBigInt, ADOS::MapADOType2Jdbc(adBigInt)},
883 {adUnsignedTinyInt, ADOS::MapADOType2Jdbc(adUnsignedTinyInt)},
884 {adUnsignedSmallInt, ADOS::MapADOType2Jdbc(adUnsignedSmallInt)},
885 {adUnsignedInt, ADOS::MapADOType2Jdbc(adUnsignedInt)},
886 {adUnsignedBigInt, ADOS::MapADOType2Jdbc(adUnsignedBigInt)},
887 {adSingle, ADOS::MapADOType2Jdbc(adSingle)},
888 {adDouble, ADOS::MapADOType2Jdbc(adDouble)},
889 {adCurrency, ADOS::MapADOType2Jdbc(adCurrency)},
890 {adDecimal, ADOS::MapADOType2Jdbc(adDecimal)},
891 {adNumeric, ADOS::MapADOType2Jdbc(adNumeric)},
892 {adBoolean, ADOS::MapADOType2Jdbc(adBoolean)},
893 {adError, ADOS::MapADOType2Jdbc(adError)},
894 {adUserDefined, ADOS::MapADOType2Jdbc(adUserDefined)},
895 {adVariant, ADOS::MapADOType2Jdbc(adVariant)},
896 {adIDispatch, ADOS::MapADOType2Jdbc(adIDispatch)},
897 {adIUnknown, ADOS::MapADOType2Jdbc(adIUnknown)},
898 {adGUID, ADOS::MapADOType2Jdbc(adGUID)},
899 {adDate, ADOS::MapADOType2Jdbc(adDate)},
900 {adDBDate, ADOS::MapADOType2Jdbc(adDBDate)},
901 {adDBTime, ADOS::MapADOType2Jdbc(adDBTime)},
902 {adDBTimeStamp, ADOS::MapADOType2Jdbc(adDBTimeStamp)},
903 {adBSTR, ADOS::MapADOType2Jdbc(adBSTR)},
904 {adChar, ADOS::MapADOType2Jdbc(adChar)},
905 {adVarChar, ADOS::MapADOType2Jdbc(adVarChar)},
906 {adLongVarChar, ADOS::MapADOType2Jdbc(adLongVarChar)},
907 {adWChar, ADOS::MapADOType2Jdbc(adWChar)},
908 {adVarWChar, ADOS::MapADOType2Jdbc(adVarWChar)},
909 {adLongVarWChar, ADOS::MapADOType2Jdbc(adLongVarWChar)},
910 {adBinary, ADOS::MapADOType2Jdbc(adBinary)},
911 {adVarBinary, ADOS::MapADOType2Jdbc(adVarBinary)},
912 {adLongVarBinary, ADOS::MapADOType2Jdbc(adLongVarBinary)},
913 {adChapter, ADOS::MapADOType2Jdbc(adChapter)},
914 {adFileTime, ADOS::MapADOType2Jdbc(adFileTime)},
915 {adPropVariant, ADOS::MapADOType2Jdbc(adPropVariant)},
916 {adVarNumeric, ADOS::MapADOType2Jdbc(adVarNumeric)}
918 m_aValueRange[12] = aMap;
920 std::map< sal_Int32,OUString> aMap2 {
921 {0, "YES"},
922 {1, "NO"}
924 m_aIntValueRange[18] = aMap2;
926 rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this);
927 pMetaData->setColumnsMap();
928 m_xMetaData = pMetaData;
931 void ODatabaseMetaDataResultSet::setTablesMap()
934 for(sal_Int32 i=1;i<5;i++)
935 m_aColMapping.push_back(i);
936 m_aColMapping.push_back(6);
938 rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this);
939 pMetaData->setTablesMap();
940 m_xMetaData = pMetaData;
943 void ODatabaseMetaDataResultSet::setProcedureColumnsMap()
946 for(sal_Int32 i=1;i<5;i++)
947 m_aColMapping.push_back(i);
948 m_aColMapping.push_back(6);
949 m_aColMapping.push_back(10);
950 m_aColMapping.push_back(16);
951 m_aColMapping.push_back(13);
952 m_aColMapping.push_back(11);
953 m_aColMapping.push_back(12);
955 m_aColMapping.push_back(9);
956 m_aColMapping.push_back(14);
958 ::std::map<sal_Int32,sal_Int32> aMap
960 {DBTYPE_EMPTY, DataType::SQLNULL},
961 {DBTYPE_NULL, DataType::SQLNULL},
962 {DBTYPE_I2, DataType::SMALLINT},
963 {DBTYPE_I4, DataType::INTEGER},
964 {DBTYPE_R4, DataType::FLOAT},
965 {DBTYPE_R8, DataType::DOUBLE},
966 {DBTYPE_CY, DataType::BIGINT},
967 {DBTYPE_DATE, DataType::DATE},
968 {DBTYPE_BSTR, DataType::VARCHAR},
969 {DBTYPE_IDISPATCH, DataType::OBJECT},
970 {DBTYPE_ERROR, DataType::OTHER},
971 {DBTYPE_BOOL, DataType::BIT},
972 {DBTYPE_VARIANT, DataType::STRUCT},
973 {DBTYPE_IUNKNOWN, DataType::OTHER},
974 {DBTYPE_DECIMAL, DataType::DECIMAL},
975 {DBTYPE_UI1, DataType::TINYINT},
976 {DBTYPE_ARRAY, DataType::ARRAY},
977 {DBTYPE_BYREF, DataType::REF},
978 {DBTYPE_I1, DataType::CHAR},
979 {DBTYPE_UI2, DataType::SMALLINT},
980 {DBTYPE_UI4, DataType::INTEGER},
982 // aMap[The] = ;
983 // aMap[in] = ;
984 {DBTYPE_I8, DataType::BIGINT},
985 {DBTYPE_UI8, DataType::BIGINT},
986 {DBTYPE_GUID, DataType::OTHER},
987 {DBTYPE_VECTOR, DataType::OTHER},
988 {DBTYPE_FILETIME, DataType::OTHER},
989 {DBTYPE_RESERVED, DataType::OTHER},
991 // aMap[The] = ;
992 {DBTYPE_BYTES, DataType::VARBINARY},
993 {DBTYPE_STR, DataType::LONGVARCHAR},
994 {DBTYPE_WSTR, DataType::LONGVARCHAR},
995 {DBTYPE_NUMERIC, DataType::NUMERIC},
996 {DBTYPE_UDT, DataType::OTHER},
997 {DBTYPE_DBDATE, DataType::DATE},
998 {DBTYPE_DBTIME, DataType::TIME},
999 {DBTYPE_DBTIMESTAMP, DataType::TIMESTAMP},
1000 {DBTYPE_HCHAPTER, DataType::OTHER},
1001 {DBTYPE_PROPVARIANT, DataType::OTHER},
1002 {DBTYPE_VARNUMERIC, DataType::NUMERIC}
1005 m_aValueRange[10] = aMap;
1007 rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this);
1008 pMetaData->setProcedureColumnsMap();
1009 m_xMetaData = pMetaData;
1012 void ODatabaseMetaDataResultSet::setPrimaryKeysMap()
1015 sal_Int32 i=1;
1016 for(;i<5;i++)
1017 m_aColMapping.push_back(i);
1018 m_aColMapping.push_back(7);
1019 m_aColMapping.push_back(8);
1021 rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this);
1022 pMetaData->setProcedureColumnsMap();
1023 m_xMetaData = pMetaData;
1026 void ODatabaseMetaDataResultSet::setIndexInfoMap()
1029 sal_Int32 i=1;
1030 for(;i<4;i++)
1031 m_aColMapping.push_back(i);
1032 m_aColMapping.push_back(8);
1033 m_aColMapping.push_back(4);
1034 m_aColMapping.push_back(6);
1035 m_aColMapping.push_back(10);
1036 m_aColMapping.push_back(17);
1037 m_aColMapping.push_back(18);
1038 m_aColMapping.push_back(21);
1039 m_aColMapping.push_back(22);
1040 m_aColMapping.push_back(23);
1041 m_aColMapping.push_back(24);
1043 ::std::map<sal_Int32,sal_Int32> aMap
1045 { DBPROPVAL_IT_HASH, IndexType::HASHED },
1046 { DBPROPVAL_IT_CONTENT, IndexType::OTHER },
1047 { DBPROPVAL_IT_OTHER, IndexType::OTHER },
1048 { DBPROPVAL_IT_BTREE, IndexType::OTHER }
1051 m_aValueRange[10] = aMap;
1053 ::std::map<sal_Int32,sal_Int32> aMap2
1055 { 0, 1 },
1056 { 1, 0 }
1058 m_aValueRange[8] = aMap2;
1060 std::map< sal_Int32,OUString> aMap3
1062 { 0, "" },
1063 { DB_COLLATION_ASC, "A" },
1064 { DB_COLLATION_DESC, "D" }
1067 m_aIntValueRange[21] = aMap3;
1069 rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this);
1070 pMetaData->setIndexInfoMap();
1071 m_xMetaData = pMetaData;
1074 void ODatabaseMetaDataResultSet::setTablePrivilegesMap()
1077 sal_Int32 i=3;
1078 for(;i<6;i++)
1079 m_aColMapping.push_back(i);
1080 m_aColMapping.push_back(1);
1081 m_aColMapping.push_back(2);
1082 m_aColMapping.push_back(6);
1083 m_aColMapping.push_back(7);
1085 std::map< sal_Int32,OUString> aMap
1087 { 0, "YES" },
1088 { 1, "NO" }
1090 m_aIntValueRange[7] = aMap;
1093 rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this);
1094 pMetaData->setTablePrivilegesMap();
1095 m_xMetaData = pMetaData;
1098 void ODatabaseMetaDataResultSet::setCrossReferenceMap()
1101 sal_Int32 i=1;
1102 for(;i<5;i++)
1103 m_aColMapping.push_back(i);
1104 for(i=7;i<11;i++)
1105 m_aColMapping.push_back(i);
1107 m_aColMapping.push_back(13);
1108 m_aColMapping.push_back(14);
1109 m_aColMapping.push_back(15);
1110 m_aColMapping.push_back(17);
1111 m_aColMapping.push_back(16);
1112 m_aColMapping.push_back(18);
1114 std::map< OUString,sal_Int32> aMap
1116 { "CASCADE", KeyRule::CASCADE },
1117 { "RESTRICT", KeyRule::RESTRICT },
1118 { "SET NULL", KeyRule::SET_NULL },
1119 { "SET DEFAULT", KeyRule::SET_DEFAULT },
1120 { "NO ACTION", KeyRule::NO_ACTION }
1123 m_aStrValueRange[14] = aMap;
1124 m_aStrValueRange[15] = aMap;
1126 rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this);
1127 pMetaData->setCrossReferenceMap();
1128 m_xMetaData = pMetaData;
1131 void ODatabaseMetaDataResultSet::setTypeInfoMap(bool _bJetEngine)
1133 sal_Int32 i=1;
1134 for(;i<19;i++)
1135 m_aColMapping.push_back(i);
1137 std::map< OUString,sal_Int32> aMap1 { { OUString(), 10 } };
1139 m_aStrValueRange[18] = aMap1;
1141 ::std::map<sal_Int32,sal_Int32> aMap
1143 {adEmpty, ADOS::MapADOType2Jdbc(adEmpty)},
1144 {adTinyInt, ADOS::MapADOType2Jdbc(adTinyInt)},
1145 {adSmallInt, ADOS::MapADOType2Jdbc(adSmallInt)},
1146 {adInteger, ADOS::MapADOType2Jdbc(adInteger)},
1147 {adBigInt, ADOS::MapADOType2Jdbc(adBigInt)},
1148 {adUnsignedTinyInt, ADOS::MapADOType2Jdbc(adUnsignedTinyInt)},
1149 {adUnsignedSmallInt, ADOS::MapADOType2Jdbc(adUnsignedSmallInt)},
1150 {adUnsignedInt, ADOS::MapADOType2Jdbc(adUnsignedInt)},
1151 {adUnsignedBigInt, ADOS::MapADOType2Jdbc(adUnsignedBigInt)},
1152 {adSingle, ADOS::MapADOType2Jdbc(adSingle)},
1153 {adDouble, ADOS::MapADOType2Jdbc(adDouble)},
1154 {adCurrency, ADOS::MapADOType2Jdbc(adCurrency)},
1155 {adDecimal, ADOS::MapADOType2Jdbc(adDecimal)},
1156 {adNumeric, ADOS::MapADOType2Jdbc(adNumeric)},
1157 {adBoolean, ADOS::MapADOType2Jdbc(adBoolean)},
1158 {adError, ADOS::MapADOType2Jdbc(adError)},
1159 {adUserDefined, ADOS::MapADOType2Jdbc(adUserDefined)},
1160 {adVariant, ADOS::MapADOType2Jdbc(adVariant)},
1161 {adIDispatch, ADOS::MapADOType2Jdbc(adIDispatch)},
1162 {adIUnknown, ADOS::MapADOType2Jdbc(adIUnknown)},
1163 {adGUID, ADOS::MapADOType2Jdbc(adGUID)},
1164 {adDate, ADOS::MapADOType2Jdbc(_bJetEngine?adDBTimeStamp:adDate)},
1165 {adDBDate, ADOS::MapADOType2Jdbc(adDBDate)},
1166 {adDBTime, ADOS::MapADOType2Jdbc(adDBTime)},
1167 {adDBTimeStamp, ADOS::MapADOType2Jdbc(adDBTimeStamp)},
1168 {adBSTR, ADOS::MapADOType2Jdbc(adBSTR)},
1169 {adChar, ADOS::MapADOType2Jdbc(adChar)},
1170 {adVarChar, ADOS::MapADOType2Jdbc(adVarChar)},
1171 {adLongVarChar, ADOS::MapADOType2Jdbc(adLongVarChar)},
1172 {adWChar, ADOS::MapADOType2Jdbc(adWChar)},
1173 {adVarWChar, ADOS::MapADOType2Jdbc(adVarWChar)},
1174 {adLongVarWChar, ADOS::MapADOType2Jdbc(adLongVarWChar)},
1175 {adBinary, ADOS::MapADOType2Jdbc(adBinary)},
1176 {adVarBinary, ADOS::MapADOType2Jdbc(adVarBinary)},
1177 {adLongVarBinary, ADOS::MapADOType2Jdbc(adLongVarBinary)},
1178 {adChapter, ADOS::MapADOType2Jdbc(adChapter)},
1179 {adFileTime, ADOS::MapADOType2Jdbc(adFileTime)},
1180 {adPropVariant, ADOS::MapADOType2Jdbc(adPropVariant)},
1181 {adVarNumeric, ADOS::MapADOType2Jdbc(adVarNumeric)}
1182 // {adArray, ADOS::MapADOType2Jdbc(adArray)}
1185 m_aValueRange[2] = aMap;
1187 ::std::map<sal_Int32,sal_Int32> aColumnValueMapping
1189 { VARIANT_FALSE, ColumnValue::NO_NULLS },
1190 { VARIANT_TRUE, ColumnValue::NULLABLE }
1192 m_aValueRange[7] = aColumnValueMapping;
1194 // now adjust the column mapping
1195 // OJ 24.01.2002 96860
1196 ::std::map<sal_Int32,sal_Int32> aSearchMapping
1198 { DB_UNSEARCHABLE, ColumnSearch::NONE },
1199 { DB_LIKE_ONLY, ColumnSearch::CHAR },
1200 { DB_ALL_EXCEPT_LIKE, ColumnSearch::BASIC },
1201 { DB_SEARCHABLE, ColumnSearch::FULL }
1204 m_aValueRange[9] = aSearchMapping;
1206 ::std::map<sal_Int32,sal_Int32> aCurrencyMapping;
1207 m_aValueRange[11] = aCurrencyMapping;
1209 rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this);
1210 pMetaData->setTypeInfoMap();
1211 m_xMetaData = pMetaData;
1214 void SAL_CALL ODatabaseMetaDataResultSet::acquire() noexcept
1216 ODatabaseMetaDataResultSet_BASE::acquire();
1219 void SAL_CALL ODatabaseMetaDataResultSet::release() noexcept
1221 ODatabaseMetaDataResultSet_BASE::release();
1224 css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL ODatabaseMetaDataResultSet::getPropertySetInfo( )
1226 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
1229 OLEVariant ODatabaseMetaDataResultSet::getValue(sal_Int32 columnIndex )
1231 ::osl::MutexGuard aGuard( m_aMutex );
1232 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
1234 checkRecordSet();
1236 WpADOField aField = ADOS::getField(m_pRecordSet,columnIndex);
1237 aField.get_Value(m_aValue);
1238 return m_aValue;
1242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */