bump product version to 7.2.5.1
[LibreOffice.git] / connectivity / source / drivers / odbc / ODatabaseMetaDataResultSet.cxx
blob576c3d3e9bef334e569311011d9d8890a6e649ad
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 <TConnection.hxx>
22 #include <odbc/ODatabaseMetaDataResultSet.hxx>
23 #include <com/sun/star/sdbc/DataType.hpp>
24 #include <comphelper/property.hxx>
25 #include <cppuhelper/typeprovider.hxx>
26 #include <comphelper/sequence.hxx>
27 #include <odbc/OResultSetMetaData.hxx>
28 #include <odbc/OTools.hxx>
29 #include <comphelper/types.hxx>
30 #include <connectivity/dbexception.hxx>
32 using namespace ::comphelper;
35 using namespace connectivity::odbc;
36 using namespace cppu;
38 using namespace ::com::sun::star::lang;
39 using namespace com::sun::star::uno;
40 using namespace com::sun::star::beans;
41 using namespace com::sun::star::sdbc;
42 using namespace com::sun::star::util;
45 ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet(OConnection* _pConnection)
46 :ODatabaseMetaDataResultSet_BASE(m_aMutex)
47 ,OPropertySetHelper(ODatabaseMetaDataResultSet_BASE::rBHelper)
49 ,m_aStatementHandle(_pConnection->createStatementHandle())
50 ,m_aStatement(nullptr)
51 ,m_pConnection(_pConnection)
52 ,m_nTextEncoding(_pConnection->getTextEncoding())
53 ,m_nRowPos(-1)
54 ,m_nDriverColumnCount(0)
55 ,m_nCurrentFetchState(0)
56 ,m_bWasNull(true)
57 ,m_bEOF(false)
59 OSL_ENSURE(m_pConnection.is(),"ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet: No parent set!");
60 if( SQL_NULL_HANDLE == m_aStatementHandle )
61 throw RuntimeException();
63 osl_atomic_increment( &m_refCount );
64 m_pRowStatusArray.reset( new SQLUSMALLINT[1] ); // the default value
65 osl_atomic_decrement( &m_refCount );
69 ODatabaseMetaDataResultSet::~ODatabaseMetaDataResultSet()
71 OSL_ENSURE(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed,"Object wasn't disposed!");
72 if(!ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed)
74 osl_atomic_increment( &m_refCount );
75 dispose();
79 void ODatabaseMetaDataResultSet::disposing()
81 OPropertySetHelper::disposing();
83 ::osl::MutexGuard aGuard(m_aMutex);
85 m_pConnection->freeStatementHandle(m_aStatementHandle);
87 m_aStatement = nullptr;
88 m_xMetaData.clear();
89 m_pConnection.clear();
92 Any SAL_CALL ODatabaseMetaDataResultSet::queryInterface( const Type & rType )
94 Any aRet = OPropertySetHelper::queryInterface(rType);
95 return aRet.hasValue() ? aRet : ODatabaseMetaDataResultSet_BASE::queryInterface(rType);
98 Reference< XPropertySetInfo > SAL_CALL ODatabaseMetaDataResultSet::getPropertySetInfo( )
100 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
103 void SAL_CALL ODatabaseMetaDataResultSet::acquire() noexcept
105 ODatabaseMetaDataResultSet_BASE::acquire();
108 void SAL_CALL ODatabaseMetaDataResultSet::release() noexcept
110 ODatabaseMetaDataResultSet_BASE::release();
113 Sequence< Type > SAL_CALL ODatabaseMetaDataResultSet::getTypes( )
115 ::cppu::OTypeCollection aTypes( cppu::UnoType<XMultiPropertySet>::get(),
116 cppu::UnoType<XFastPropertySet>::get(),
117 cppu::UnoType<XPropertySet>::get());
119 return ::comphelper::concatSequences(aTypes.getTypes(),ODatabaseMetaDataResultSet_BASE::getTypes());
122 sal_Int32 ODatabaseMetaDataResultSet::mapColumn (sal_Int32 column)
124 sal_Int32 map = column;
126 if (!m_aColMapping.empty())
128 // Validate column number
129 map = m_aColMapping[column];
132 return map;
136 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::findColumn( const OUString& columnName )
139 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
140 ::osl::MutexGuard aGuard( m_aMutex );
143 Reference< XResultSetMetaData > xMeta = getMetaData();
144 sal_Int32 nLen = xMeta->getColumnCount();
145 sal_Int32 i = 1;
146 for(;i<=nLen;++i)
148 if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) :
149 columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i)))
150 return i;
153 ::dbtools::throwInvalidColumnException( columnName, *this );
154 assert(false);
155 return 0; // Never reached
158 template < typename T, SQLSMALLINT sqlTypeId > T ODatabaseMetaDataResultSet::getInteger ( sal_Int32 columnIndex )
160 ::cppu::OBroadcastHelper& rBHelper(ODatabaseMetaDataResultSet_BASE::rBHelper);
161 checkDisposed(rBHelper.bDisposed);
162 ::osl::MutexGuard aGuard( m_aMutex );
164 columnIndex = mapColumn(columnIndex);
165 T nVal = 0;
166 if(columnIndex <= m_nDriverColumnCount)
168 getValue<T>(m_pConnection.get(), m_aStatementHandle, columnIndex, sqlTypeId, m_bWasNull, **this, nVal);
170 if ( !m_aValueRange.empty() )
172 auto aValueRangeIter = m_aValueRange.find(columnIndex);
173 if ( aValueRangeIter != m_aValueRange.end() )
174 return static_cast<T>(aValueRangeIter->second[nVal]);
177 else
178 m_bWasNull = true;
179 return nVal;
183 Reference< css::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getBinaryStream( sal_Int32 /*columnIndex*/ )
185 ::dbtools::throwFunctionNotSupportedSQLException( "XRow::getBinaryStream", *this );
186 return nullptr;
189 Reference< css::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getCharacterStream( sal_Int32 /*columnIndex*/ )
191 ::dbtools::throwFunctionNotSupportedSQLException( "XRow::getCharacterStream", *this );
192 return nullptr;
196 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::getBoolean( sal_Int32 columnIndex )
199 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
200 ::osl::MutexGuard aGuard( m_aMutex );
202 columnIndex = mapColumn(columnIndex);
204 bool bRet = false;
205 if(columnIndex <= m_nDriverColumnCount)
207 sal_Int32 nType = getMetaData()->getColumnType(columnIndex);
208 switch(nType)
210 case DataType::BIT:
212 sal_Int8 nValue = 0;
213 OTools::getValue(m_pConnection.get(),m_aStatementHandle,columnIndex,SQL_C_BIT,m_bWasNull,**this,&nValue,sizeof nValue);
214 bRet = nValue != 0;
216 break;
217 default:
218 bRet = getInt(columnIndex) != 0;
221 return bRet;
225 sal_Int8 SAL_CALL ODatabaseMetaDataResultSet::getByte( sal_Int32 columnIndex )
227 return getInteger<sal_Int8, SQL_C_STINYINT>( columnIndex );
231 Sequence< sal_Int8 > SAL_CALL ODatabaseMetaDataResultSet::getBytes( sal_Int32 columnIndex )
234 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
235 ::osl::MutexGuard aGuard( m_aMutex );
238 columnIndex = mapColumn(columnIndex);
239 if(columnIndex <= m_nDriverColumnCount)
241 sal_Int32 nType = getMetaData()->getColumnType(columnIndex);
242 switch(nType)
244 case DataType::CHAR:
245 case DataType::VARCHAR:
246 case DataType::LONGVARCHAR:
248 OUString const & aRet = OTools::getStringValue(m_pConnection.get(),m_aStatementHandle,columnIndex,SQL_C_BINARY,m_bWasNull,**this,m_nTextEncoding);
249 return Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(aRet.getStr()),sizeof(sal_Unicode)*aRet.getLength());
252 return OTools::getBytesValue(m_pConnection.get(),m_aStatementHandle,columnIndex,SQL_C_BINARY,m_bWasNull,**this);
254 else
255 m_bWasNull = true;
256 return Sequence<sal_Int8>();
260 css::util::Date SAL_CALL ODatabaseMetaDataResultSet::getDate( sal_Int32 columnIndex )
262 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
263 ::osl::MutexGuard aGuard( m_aMutex );
266 columnIndex = mapColumn(columnIndex);
267 if(columnIndex <= m_nDriverColumnCount)
269 DATE_STRUCT aDate;
270 aDate.day = 0;
271 aDate.month = 0;
272 aDate.year = 0;
273 OTools::getValue(m_pConnection.get(),m_aStatementHandle,columnIndex,m_pConnection->useOldDateFormat() ? SQL_C_DATE : SQL_C_TYPE_DATE,m_bWasNull,**this,&aDate,sizeof aDate);
274 return Date(aDate.day,aDate.month,aDate.year);
276 else
277 m_bWasNull = true;
278 return Date();
282 double SAL_CALL ODatabaseMetaDataResultSet::getDouble( sal_Int32 columnIndex )
285 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
286 ::osl::MutexGuard aGuard( m_aMutex );
289 columnIndex = mapColumn(columnIndex);
290 double nValue(0.0);
291 if(columnIndex <= m_nDriverColumnCount)
292 OTools::getValue(m_pConnection.get(),m_aStatementHandle,columnIndex,SQL_C_DOUBLE,m_bWasNull,**this,&nValue,sizeof nValue);
293 else
294 m_bWasNull = true;
295 return nValue;
299 float SAL_CALL ODatabaseMetaDataResultSet::getFloat( sal_Int32 columnIndex )
302 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
303 ::osl::MutexGuard aGuard( m_aMutex );
306 columnIndex = mapColumn(columnIndex);
307 float nVal(0);
308 if(columnIndex <= m_nDriverColumnCount)
309 OTools::getValue(m_pConnection.get(),m_aStatementHandle,columnIndex,SQL_C_FLOAT,m_bWasNull,**this,&nVal,sizeof nVal);
310 else
311 m_bWasNull = true;
312 return nVal;
316 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getInt( sal_Int32 columnIndex )
318 return getInteger<sal_Int32, SQL_C_SLONG>( columnIndex );
322 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getRow( )
324 return 0;
328 sal_Int64 SAL_CALL ODatabaseMetaDataResultSet::getLong( sal_Int32 columnIndex )
330 return getInteger<sal_Int64, SQL_C_SBIGINT>( columnIndex );
334 Reference< XResultSetMetaData > SAL_CALL ODatabaseMetaDataResultSet::getMetaData( )
336 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
337 ::osl::MutexGuard aGuard( m_aMutex );
338 if (!m_xMetaData.is())
339 m_xMetaData = new OResultSetMetaData(m_pConnection.get(),m_aStatementHandle);
340 return m_xMetaData;
343 Reference< XArray > SAL_CALL ODatabaseMetaDataResultSet::getArray( sal_Int32 /*columnIndex*/ )
345 ::dbtools::throwFunctionNotSupportedSQLException( "XRow::getArray", *this );
346 return nullptr;
349 Reference< XClob > SAL_CALL ODatabaseMetaDataResultSet::getClob( sal_Int32 /*columnIndex*/ )
351 ::dbtools::throwFunctionNotSupportedSQLException( "XRow::getClob", *this );
352 return nullptr;
355 Reference< XBlob > SAL_CALL ODatabaseMetaDataResultSet::getBlob( sal_Int32 /*columnIndex*/ )
357 ::dbtools::throwFunctionNotSupportedSQLException( "XRow::getBlob", *this );
358 return nullptr;
362 Reference< XRef > SAL_CALL ODatabaseMetaDataResultSet::getRef( sal_Int32 /*columnIndex*/ )
364 ::dbtools::throwFunctionNotSupportedSQLException( "XRow::getRef", *this );
365 return nullptr;
369 Any SAL_CALL ODatabaseMetaDataResultSet::getObject( sal_Int32 /*columnIndex*/, const Reference< css::container::XNameAccess >& /*typeMap*/ )
371 ::dbtools::throwFunctionNotSupportedSQLException( "XRow::getObject", *this );
372 return Any();
376 sal_Int16 SAL_CALL ODatabaseMetaDataResultSet::getShort( sal_Int32 columnIndex )
378 return getInteger<sal_Int16, SQL_C_SSHORT>( columnIndex );
382 OUString SAL_CALL ODatabaseMetaDataResultSet::getString( sal_Int32 columnIndex )
385 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
386 ::osl::MutexGuard aGuard( m_aMutex );
389 columnIndex = mapColumn(columnIndex);
390 OUString aVal;
391 if(columnIndex <= m_nDriverColumnCount)
392 aVal = OTools::getStringValue(m_pConnection.get(),m_aStatementHandle,columnIndex,impl_getColumnType_nothrow(columnIndex),m_bWasNull,**this,m_nTextEncoding);
393 else
394 m_bWasNull = true;
396 return aVal;
400 css::util::Time SAL_CALL ODatabaseMetaDataResultSet::getTime( sal_Int32 columnIndex )
403 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
404 ::osl::MutexGuard aGuard( m_aMutex );
407 columnIndex = mapColumn(columnIndex);
408 TIME_STRUCT aTime={0,0,0};
409 if(columnIndex <= m_nDriverColumnCount)
410 OTools::getValue(m_pConnection.get(),m_aStatementHandle,columnIndex,m_pConnection->useOldDateFormat() ? SQL_C_TIME : SQL_C_TYPE_TIME,m_bWasNull,**this,&aTime,sizeof aTime);
411 else
412 m_bWasNull = true;
413 return Time(0, aTime.second,aTime.minute,aTime.hour, false);
417 css::util::DateTime SAL_CALL ODatabaseMetaDataResultSet::getTimestamp( sal_Int32 columnIndex )
420 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
421 ::osl::MutexGuard aGuard( m_aMutex );
424 columnIndex = mapColumn(columnIndex);
425 TIMESTAMP_STRUCT aTime={0,0,0,0,0,0,0};
426 if(columnIndex <= m_nDriverColumnCount)
427 OTools::getValue(m_pConnection.get(),m_aStatementHandle,columnIndex,m_pConnection->useOldDateFormat() ? SQL_C_TIMESTAMP : SQL_C_TYPE_TIMESTAMP, m_bWasNull, **this, &aTime, sizeof aTime);
428 else
429 m_bWasNull = true;
430 return DateTime(aTime.fraction, aTime.second, aTime.minute, aTime.hour,
431 aTime.day, aTime.month, aTime.year, false);
435 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isAfterLast( )
438 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
439 ::osl::MutexGuard aGuard( m_aMutex );
442 return m_nCurrentFetchState == SQL_NO_DATA;
445 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isFirst( )
448 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
449 ::osl::MutexGuard aGuard( m_aMutex );
452 return m_nRowPos == 1;
455 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isLast( )
458 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
459 ::osl::MutexGuard aGuard( m_aMutex );
462 return m_bEOF && m_nCurrentFetchState != SQL_NO_DATA;
465 void SAL_CALL ODatabaseMetaDataResultSet::beforeFirst( )
468 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
469 ::osl::MutexGuard aGuard( m_aMutex );
472 if(first())
473 previous();
474 m_nCurrentFetchState = SQL_SUCCESS;
477 void SAL_CALL ODatabaseMetaDataResultSet::afterLast( )
480 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
481 ::osl::MutexGuard aGuard( m_aMutex );
484 if(last())
485 next();
489 void SAL_CALL ODatabaseMetaDataResultSet::close( )
493 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
494 ::osl::MutexGuard aGuard( m_aMutex );
497 dispose();
501 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::first( )
504 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
505 ::osl::MutexGuard aGuard( m_aMutex );
507 m_bEOF = false;
509 m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_FIRST,0);
510 OTools::ThrowException(m_pConnection.get(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
511 bool bRet = ( m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO );
512 if( bRet )
513 m_nRowPos = 1;
514 return bRet;
518 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::last( )
520 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
521 ::osl::MutexGuard aGuard( m_aMutex );
524 m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_LAST,0);
525 OTools::ThrowException(m_pConnection.get(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
526 // here I know definitely that I stand on the last record
527 bool bRet = ( m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO );
528 if( bRet )
529 m_bEOF = true;
530 return bRet;
533 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::absolute( sal_Int32 row )
536 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
537 ::osl::MutexGuard aGuard( m_aMutex );
539 m_bEOF = false;
541 m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_ABSOLUTE,row);
542 OTools::ThrowException(m_pConnection.get(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
543 bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
544 if(bRet)
545 m_nRowPos = row;
546 return bRet;
549 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::relative( sal_Int32 row )
552 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
553 ::osl::MutexGuard aGuard( m_aMutex );
555 m_bEOF = false;
557 m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_RELATIVE,row);
558 OTools::ThrowException(m_pConnection.get(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
559 bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
560 if(bRet)
561 m_nRowPos += row;
562 return bRet;
565 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::previous( )
568 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
569 ::osl::MutexGuard aGuard( m_aMutex );
571 m_bEOF = false;
573 m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
574 OTools::ThrowException(m_pConnection.get(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
575 bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
576 if(bRet)
577 --m_nRowPos;
578 else if ( m_nCurrentFetchState == SQL_NO_DATA )
579 m_nRowPos = 0;
580 return bRet;
583 Reference< XInterface > SAL_CALL ODatabaseMetaDataResultSet::getStatement( )
585 return nullptr;
589 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowDeleted( )
592 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
593 ::osl::MutexGuard aGuard( m_aMutex );
596 return m_pRowStatusArray[0] == SQL_ROW_DELETED;
599 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowInserted( )
601 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
602 ::osl::MutexGuard aGuard( m_aMutex );
605 return m_pRowStatusArray[0] == SQL_ROW_ADDED;
608 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowUpdated( )
611 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
612 ::osl::MutexGuard aGuard( m_aMutex );
615 return m_pRowStatusArray[0] == SQL_ROW_UPDATED;
619 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isBeforeFirst( )
622 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
623 ::osl::MutexGuard aGuard( m_aMutex );
626 return m_nRowPos == 0;
630 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::next( )
633 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
634 ::osl::MutexGuard aGuard( m_aMutex );
636 m_bEOF = false;
638 SQLRETURN nOldFetchStatus = m_nCurrentFetchState;
639 // m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_NEXT,0);
640 m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
641 OTools::ThrowException(m_pConnection.get(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
642 bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
643 if(bRet || ( m_nCurrentFetchState == SQL_NO_DATA && nOldFetchStatus != SQL_NO_DATA ) )
644 ++m_nRowPos;
645 return bRet;
649 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::wasNull( )
652 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
653 ::osl::MutexGuard aGuard( m_aMutex );
656 return m_bWasNull;
659 void SAL_CALL ODatabaseMetaDataResultSet::refreshRow( )
662 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
663 ::osl::MutexGuard aGuard( m_aMutex );
668 void SAL_CALL ODatabaseMetaDataResultSet::cancel( )
671 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
672 ::osl::MutexGuard aGuard( m_aMutex );
675 N3SQLCancel(m_aStatementHandle);
678 void SAL_CALL ODatabaseMetaDataResultSet::clearWarnings( )
682 Any SAL_CALL ODatabaseMetaDataResultSet::getWarnings( )
684 return Any();
687 sal_Int32 ODatabaseMetaDataResultSet::getFetchSize()
689 return 1;
692 OUString ODatabaseMetaDataResultSet::getCursorName()
694 return OUString();
698 ::cppu::IPropertyArrayHelper* ODatabaseMetaDataResultSet::createArrayHelper( ) const
701 Sequence< css::beans::Property > aProps(5);
702 css::beans::Property* pProperties = aProps.getArray();
703 sal_Int32 nPos = 0;
704 pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME),
705 PROPERTY_ID_CURSORNAME, cppu::UnoType<OUString>::get(), 0);
706 pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION),
707 PROPERTY_ID_FETCHDIRECTION, cppu::UnoType<sal_Int32>::get(), 0);
708 pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE),
709 PROPERTY_ID_FETCHSIZE, cppu::UnoType<sal_Int32>::get(), 0);
710 pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY),
711 PROPERTY_ID_RESULTSETCONCURRENCY, cppu::UnoType<sal_Int32>::get(), 0);
712 pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE),
713 PROPERTY_ID_RESULTSETTYPE, cppu::UnoType<sal_Int32>::get(), 0);
715 return new ::cppu::OPropertyArrayHelper(aProps);
718 ::cppu::IPropertyArrayHelper & ODatabaseMetaDataResultSet::getInfoHelper()
720 return *getArrayHelper();
723 sal_Bool ODatabaseMetaDataResultSet::convertFastPropertyValue(
724 Any & rConvertedValue,
725 Any & rOldValue,
726 sal_Int32 nHandle,
727 const Any& rValue )
729 switch(nHandle)
731 case PROPERTY_ID_CURSORNAME:
732 case PROPERTY_ID_RESULTSETCONCURRENCY:
733 case PROPERTY_ID_RESULTSETTYPE:
734 throw css::lang::IllegalArgumentException();
735 case PROPERTY_ID_FETCHDIRECTION:
736 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection());
737 case PROPERTY_ID_FETCHSIZE:
738 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize());
739 default:
742 return false;
745 void ODatabaseMetaDataResultSet::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& /*rValue*/ )
747 switch(nHandle)
749 case PROPERTY_ID_CURSORNAME:
750 case PROPERTY_ID_RESULTSETCONCURRENCY:
751 case PROPERTY_ID_RESULTSETTYPE:
752 case PROPERTY_ID_FETCHDIRECTION:
753 case PROPERTY_ID_FETCHSIZE:
754 throw Exception("cannot set prop " + OUString::number(nHandle), nullptr);
755 default:
756 OSL_FAIL("setFastPropertyValue_NoBroadcast: Illegal handle value!");
760 void ODatabaseMetaDataResultSet::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
762 switch(nHandle)
764 case PROPERTY_ID_CURSORNAME:
765 rValue <<= getCursorName();
766 break;
767 case PROPERTY_ID_RESULTSETCONCURRENCY:
768 rValue <<= sal_Int32(css::sdbc::ResultSetConcurrency::READ_ONLY);
769 break;
770 case PROPERTY_ID_RESULTSETTYPE:
771 rValue <<= sal_Int32(css::sdbc::ResultSetType::FORWARD_ONLY);
772 break;
773 case PROPERTY_ID_FETCHDIRECTION:
774 rValue <<= getFetchDirection();
775 break;
776 case PROPERTY_ID_FETCHSIZE:
777 rValue <<= getFetchSize();
778 break;
782 void ODatabaseMetaDataResultSet::openTypeInfo()
784 ::std::map<sal_Int32,sal_Int32> aMap;
785 aMap[SQL_BIT] = DataType::BIT;
786 aMap[SQL_TINYINT] = DataType::TINYINT;
787 aMap[SQL_SMALLINT] = DataType::SMALLINT;
788 aMap[SQL_INTEGER] = DataType::INTEGER;
789 aMap[SQL_FLOAT] = DataType::FLOAT;
790 aMap[SQL_REAL] = DataType::REAL;
791 aMap[SQL_DOUBLE] = DataType::DOUBLE;
792 aMap[SQL_BIGINT] = DataType::BIGINT;
794 aMap[SQL_CHAR] = DataType::CHAR;
795 aMap[SQL_WCHAR] = DataType::CHAR;
796 aMap[SQL_VARCHAR] = DataType::VARCHAR;
797 aMap[SQL_WVARCHAR] = DataType::VARCHAR;
798 aMap[SQL_LONGVARCHAR] = DataType::LONGVARCHAR;
799 aMap[SQL_WLONGVARCHAR] = DataType::LONGVARCHAR;
801 aMap[SQL_TYPE_DATE] = DataType::DATE;
802 aMap[SQL_DATE] = DataType::DATE;
803 aMap[SQL_TYPE_TIME] = DataType::TIME;
804 aMap[SQL_TIME] = DataType::TIME;
805 aMap[SQL_TYPE_TIMESTAMP] = DataType::TIMESTAMP;
806 aMap[SQL_TIMESTAMP] = DataType::TIMESTAMP;
808 aMap[SQL_DECIMAL] = DataType::DECIMAL;
809 aMap[SQL_NUMERIC] = DataType::NUMERIC;
811 aMap[SQL_BINARY] = DataType::BINARY;
812 aMap[SQL_VARBINARY] = DataType::VARBINARY;
813 aMap[SQL_LONGVARBINARY] = DataType::LONGVARBINARY;
815 aMap[SQL_GUID] = DataType::VARBINARY;
818 m_aValueRange[2] = aMap;
820 OTools::ThrowException(m_pConnection.get(),N3SQLGetTypeInfo(m_aStatementHandle, SQL_ALL_TYPES),m_aStatementHandle,SQL_HANDLE_STMT,*this);
821 checkColumnCount();
824 void ODatabaseMetaDataResultSet::openTables(const Any& catalog, const OUString& schemaPattern,
825 std::u16string_view tableNamePattern,
826 const Sequence< OUString >& types )
828 OString aPKQ,aPKO,aPKN,aCOL;
829 const OUString *pSchemaPat = nullptr;
831 if(schemaPattern != "%")
832 pSchemaPat = &schemaPattern;
833 else
834 pSchemaPat = nullptr;
836 if ( catalog.hasValue() )
837 aPKQ = OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
838 aPKO = OUStringToOString(schemaPattern,m_nTextEncoding);
839 aPKN = OUStringToOString(tableNamePattern,m_nTextEncoding);
841 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : nullptr,
842 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() && !aPKO.isEmpty() ? aPKO.getStr() : nullptr,
843 *pPKN = aPKN.getStr();
846 const char *pCOL = nullptr;
847 const char* const pComma = ",";
848 const OUString* pBegin = types.getConstArray();
849 const OUString* pEnd = pBegin + types.getLength();
850 for(;pBegin != pEnd;++pBegin)
852 aCOL += OUStringToOString(*pBegin,m_nTextEncoding) + pComma;
854 if ( !aCOL.isEmpty() )
856 aCOL = aCOL.replaceAt(aCOL.getLength()-1,1,pComma);
857 pCOL = aCOL.getStr();
859 else
860 pCOL = SQL_ALL_TABLE_TYPES;
862 SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle,
863 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKQ)), (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
864 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKO)), pPKO ? SQL_NTS : 0,
865 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKN)), SQL_NTS,
866 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pCOL)), pCOL ? SQL_NTS : 0);
867 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
868 checkColumnCount();
872 void ODatabaseMetaDataResultSet::openTablesTypes( )
874 SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle,
875 nullptr,0,
876 nullptr,0,
877 nullptr,0,
878 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(SQL_ALL_TABLE_TYPES)),SQL_NTS);
879 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
881 m_aColMapping.clear();
882 m_aColMapping.push_back(-1);
883 m_aColMapping.push_back(4);
884 m_xMetaData = new OResultSetMetaData(m_pConnection.get(),m_aStatementHandle,m_aColMapping);
885 checkColumnCount();
888 void ODatabaseMetaDataResultSet::openCatalogs()
890 SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle,
891 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(SQL_ALL_CATALOGS)),SQL_NTS,
892 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>("")),SQL_NTS,
893 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>("")),SQL_NTS,
894 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>("")),SQL_NTS);
896 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
898 m_aColMapping.clear();
899 m_aColMapping.push_back(-1);
900 m_aColMapping.push_back(1);
901 m_xMetaData = new OResultSetMetaData(m_pConnection.get(),m_aStatementHandle,m_aColMapping);
902 checkColumnCount();
905 void ODatabaseMetaDataResultSet::openSchemas()
907 SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle,
908 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>("")),SQL_NTS,
909 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(SQL_ALL_SCHEMAS)),SQL_NTS,
910 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>("")),SQL_NTS,
911 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>("")),SQL_NTS);
912 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
914 m_aColMapping.clear();
915 m_aColMapping.push_back(-1);
916 m_aColMapping.push_back(2);
917 m_xMetaData = new OResultSetMetaData(m_pConnection.get(),m_aStatementHandle,m_aColMapping);
918 checkColumnCount();
921 void ODatabaseMetaDataResultSet::openColumnPrivileges( const Any& catalog, const OUString& schema,
922 std::u16string_view table,
923 std::u16string_view columnNamePattern )
925 const OUString *pSchemaPat = nullptr;
927 if(schema != "%")
928 pSchemaPat = &schema;
929 else
930 pSchemaPat = nullptr;
932 OString aPKQ,aPKO,aPKN,aCOL;
934 if ( catalog.hasValue() )
935 aPKQ = OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
936 aPKO = OUStringToOString(schema,m_nTextEncoding);
937 aPKN = OUStringToOString(table,m_nTextEncoding);
938 aCOL = OUStringToOString(columnNamePattern,m_nTextEncoding);
940 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : nullptr,
941 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() && !aPKO.isEmpty() ? aPKO.getStr() : nullptr,
942 *pPKN = aPKN.getStr(),
943 *pCOL = aCOL.getStr();
946 SQLRETURN nRetcode = N3SQLColumnPrivileges(m_aStatementHandle,
947 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKQ)), (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
948 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKO)), pPKO ? SQL_NTS : 0 ,
949 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKN)), SQL_NTS,
950 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pCOL)), SQL_NTS);
951 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
953 checkColumnCount();
956 void ODatabaseMetaDataResultSet::openColumns( const Any& catalog, const OUString& schemaPattern,
957 std::u16string_view tableNamePattern, std::u16string_view columnNamePattern )
959 const OUString *pSchemaPat = nullptr;
961 if(schemaPattern != "%")
962 pSchemaPat = &schemaPattern;
963 else
964 pSchemaPat = nullptr;
966 OString aPKQ,aPKO,aPKN,aCOL;
967 if ( catalog.hasValue() )
968 aPKQ = OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
969 aPKO = OUStringToOString(schemaPattern,m_nTextEncoding);
970 aPKN = OUStringToOString(tableNamePattern,m_nTextEncoding);
971 aCOL = OUStringToOString(columnNamePattern,m_nTextEncoding);
973 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : nullptr,
974 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() && !aPKO.isEmpty() ? aPKO.getStr() : nullptr,
975 *pPKN = aPKN.getStr(),
976 *pCOL = aCOL.getStr();
979 SQLRETURN nRetcode = N3SQLColumns(m_aStatementHandle,
980 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKQ)), (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
981 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKO)), pPKO ? SQL_NTS : 0,
982 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKN)), SQL_NTS,
983 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pCOL)), SQL_NTS);
985 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
986 ::std::map<sal_Int32,sal_Int32> aMap;
987 aMap[SQL_BIT] = DataType::BIT;
988 aMap[SQL_TINYINT] = DataType::TINYINT;
989 aMap[SQL_SMALLINT] = DataType::SMALLINT;
990 aMap[SQL_INTEGER] = DataType::INTEGER;
991 aMap[SQL_FLOAT] = DataType::FLOAT;
992 aMap[SQL_REAL] = DataType::REAL;
993 aMap[SQL_DOUBLE] = DataType::DOUBLE;
994 aMap[SQL_BIGINT] = DataType::BIGINT;
996 aMap[SQL_CHAR] = DataType::CHAR;
997 aMap[SQL_WCHAR] = DataType::CHAR;
998 aMap[SQL_VARCHAR] = DataType::VARCHAR;
999 aMap[SQL_WVARCHAR] = DataType::VARCHAR;
1000 aMap[SQL_LONGVARCHAR] = DataType::LONGVARCHAR;
1001 aMap[SQL_WLONGVARCHAR] = DataType::LONGVARCHAR;
1003 aMap[SQL_TYPE_DATE] = DataType::DATE;
1004 aMap[SQL_DATE] = DataType::DATE;
1005 aMap[SQL_TYPE_TIME] = DataType::TIME;
1006 aMap[SQL_TIME] = DataType::TIME;
1007 aMap[SQL_TYPE_TIMESTAMP] = DataType::TIMESTAMP;
1008 aMap[SQL_TIMESTAMP] = DataType::TIMESTAMP;
1010 aMap[SQL_DECIMAL] = DataType::DECIMAL;
1011 aMap[SQL_NUMERIC] = DataType::NUMERIC;
1013 aMap[SQL_BINARY] = DataType::BINARY;
1014 aMap[SQL_VARBINARY] = DataType::VARBINARY;
1015 aMap[SQL_LONGVARBINARY] = DataType::LONGVARBINARY;
1017 aMap[SQL_GUID] = DataType::VARBINARY;
1019 m_aValueRange[5] = aMap;
1020 checkColumnCount();
1023 void ODatabaseMetaDataResultSet::openProcedureColumns( const Any& catalog, const OUString& schemaPattern,
1024 std::u16string_view procedureNamePattern,std::u16string_view columnNamePattern )
1026 const OUString *pSchemaPat = nullptr;
1028 if(schemaPattern != "%")
1029 pSchemaPat = &schemaPattern;
1030 else
1031 pSchemaPat = nullptr;
1033 OString aPKQ,aPKO,aPKN,aCOL;
1034 if ( catalog.hasValue() )
1035 aPKQ = OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1036 aPKO = OUStringToOString(schemaPattern,m_nTextEncoding);
1037 aPKN = OUStringToOString(procedureNamePattern,m_nTextEncoding);
1038 aCOL = OUStringToOString(columnNamePattern,m_nTextEncoding);
1040 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : nullptr,
1041 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() && !aPKO.isEmpty() ? aPKO.getStr() : nullptr,
1042 *pPKN = aPKN.getStr(),
1043 *pCOL = aCOL.getStr();
1046 SQLRETURN nRetcode = N3SQLProcedureColumns(m_aStatementHandle,
1047 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKQ)), (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
1048 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKO)), pPKO ? SQL_NTS : 0 ,
1049 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKN)), SQL_NTS,
1050 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pCOL)), SQL_NTS);
1052 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1053 checkColumnCount();
1056 void ODatabaseMetaDataResultSet::openProcedures(const Any& catalog, const OUString& schemaPattern,
1057 std::u16string_view procedureNamePattern)
1059 const OUString *pSchemaPat = nullptr;
1061 if(schemaPattern != "%")
1062 pSchemaPat = &schemaPattern;
1063 else
1064 pSchemaPat = nullptr;
1066 OString aPKQ,aPKO,aPKN;
1068 if ( catalog.hasValue() )
1069 aPKQ = OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1070 aPKO = OUStringToOString(schemaPattern,m_nTextEncoding);
1071 aPKN = OUStringToOString(procedureNamePattern,m_nTextEncoding);
1073 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : nullptr,
1074 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() && !aPKO.isEmpty() ? aPKO.getStr() : nullptr,
1075 *pPKN = aPKN.getStr();
1078 SQLRETURN nRetcode = N3SQLProcedures(m_aStatementHandle,
1079 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKQ)), (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
1080 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKO)), pPKO ? SQL_NTS : 0 ,
1081 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKN)), SQL_NTS);
1082 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1083 checkColumnCount();
1086 void ODatabaseMetaDataResultSet::openSpecialColumns(bool _bRowVer,const Any& catalog, const OUString& schema,
1087 std::u16string_view table,sal_Int32 scope, bool nullable )
1089 // Some ODBC drivers really don't like getting an empty string as tableName
1090 // E.g. psqlodbc up to at least version 09.01.0100 segfaults
1091 if (table.empty())
1093 static constexpr OUStringLiteral errMsg
1094 = u"ODBC: Trying to get special columns of empty table name";
1095 static constexpr OUStringLiteral SQLState = u"HY009";
1096 throw SQLException( errMsg, *this, SQLState, -1, Any() );
1099 const OUString *pSchemaPat = nullptr;
1101 if(schema != "%")
1102 pSchemaPat = &schema;
1103 else
1104 pSchemaPat = nullptr;
1106 OString aPKQ,aPKO,aPKN;
1107 if ( catalog.hasValue() )
1108 aPKQ = OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1109 aPKO = OUStringToOString(schema,m_nTextEncoding);
1110 aPKN = OUStringToOString(table,m_nTextEncoding);
1112 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : nullptr,
1113 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() && !aPKO.isEmpty() ? aPKO.getStr() : nullptr,
1114 *pPKN = aPKN.getStr();
1117 SQLRETURN nRetcode = N3SQLSpecialColumns(m_aStatementHandle,_bRowVer ? SQL_ROWVER : SQL_BEST_ROWID,
1118 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKQ)), (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
1119 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKO)), pPKO ? SQL_NTS : 0 ,
1120 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKN)), SQL_NTS,
1121 static_cast<SQLSMALLINT>(scope),
1122 nullable ? SQL_NULLABLE : SQL_NO_NULLS);
1123 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1124 checkColumnCount();
1127 void ODatabaseMetaDataResultSet::openVersionColumns(const Any& catalog, const OUString& schema,
1128 std::u16string_view table)
1130 openSpecialColumns(true,catalog,schema,table,SQL_SCOPE_TRANSACTION,false);
1133 void ODatabaseMetaDataResultSet::openBestRowIdentifier( const Any& catalog, const OUString& schema,
1134 std::u16string_view table,sal_Int32 scope,bool nullable )
1136 openSpecialColumns(false,catalog,schema,table,scope,nullable);
1139 void ODatabaseMetaDataResultSet::openForeignKeys( const Any& catalog, const OUString* schema,
1140 const OUString* table,
1141 const Any& catalog2, const OUString* schema2,
1142 const OUString* table2)
1144 OString aPKQ, aPKO, aPKN, aFKQ, aFKO, aFKN;
1145 if ( catalog.hasValue() )
1146 aPKQ = OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1147 if ( catalog2.hasValue() )
1148 aFKQ = OUStringToOString(comphelper::getString(catalog2),m_nTextEncoding);
1150 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : nullptr;
1151 const char *pPKO = nullptr;
1152 if (schema && !schema->isEmpty())
1154 aPKO = OUStringToOString(*schema,m_nTextEncoding);
1155 pPKO = aPKO.getStr();
1157 const char *pPKN = nullptr;
1158 if (table)
1160 aPKN = OUStringToOString(*table,m_nTextEncoding);
1161 pPKN = aPKN.getStr();
1163 const char *pFKQ = catalog2.hasValue() && !aFKQ.isEmpty() ? aFKQ.getStr() : nullptr;
1164 const char *pFKO = nullptr;
1165 if (schema2 && !schema2->isEmpty())
1167 aFKO = OUStringToOString(*schema2,m_nTextEncoding);
1168 pFKO = aFKO.getStr();
1170 const char *pFKN = nullptr;
1171 if (table2)
1173 aFKN = OUStringToOString(*table2,m_nTextEncoding);
1174 pFKN = aFKN.getStr();
1177 SQLRETURN nRetcode = N3SQLForeignKeys(m_aStatementHandle,
1178 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKQ)), (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
1179 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKO)), pPKO ? SQL_NTS : 0,
1180 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKN)), pPKN ? SQL_NTS : 0,
1181 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pFKQ)), (catalog2.hasValue() && !aFKQ.isEmpty()) ? SQL_NTS : 0,
1182 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pFKO)), pFKO ? SQL_NTS : 0,
1183 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pFKN)), SQL_NTS
1185 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1186 checkColumnCount();
1189 void ODatabaseMetaDataResultSet::openImportedKeys(const Any& catalog, const OUString& schema,
1190 const OUString& table)
1193 openForeignKeys(Any(),nullptr,nullptr,catalog, schema == "%" ? &schema : nullptr, &table);
1196 void ODatabaseMetaDataResultSet::openExportedKeys(const Any& catalog, const OUString& schema,
1197 const OUString& table)
1199 openForeignKeys(catalog, schema == "%" ? &schema : nullptr, &table,Any(),nullptr,nullptr);
1202 void ODatabaseMetaDataResultSet::openPrimaryKeys(const Any& catalog, const OUString& schema,
1203 std::u16string_view table)
1205 const OUString *pSchemaPat = nullptr;
1207 if(schema != "%")
1208 pSchemaPat = &schema;
1209 else
1210 pSchemaPat = nullptr;
1212 OString aPKQ,aPKO,aPKN;
1214 if ( catalog.hasValue() )
1215 aPKQ = OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1216 aPKO = OUStringToOString(schema,m_nTextEncoding);
1217 aPKN = OUStringToOString(table,m_nTextEncoding);
1219 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : nullptr,
1220 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() && !aPKO.isEmpty() ? aPKO.getStr() : nullptr,
1221 *pPKN = aPKN.getStr();
1224 SQLRETURN nRetcode = N3SQLPrimaryKeys(m_aStatementHandle,
1225 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKQ)), (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
1226 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKO)), pPKO ? SQL_NTS : 0 ,
1227 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKN)), SQL_NTS);
1228 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1229 checkColumnCount();
1232 void ODatabaseMetaDataResultSet::openTablePrivileges(const Any& catalog, const OUString& schemaPattern,
1233 std::u16string_view tableNamePattern)
1235 const OUString *pSchemaPat = nullptr;
1237 if(schemaPattern != "%")
1238 pSchemaPat = &schemaPattern;
1239 else
1240 pSchemaPat = nullptr;
1242 OString aPKQ,aPKO,aPKN;
1244 if ( catalog.hasValue() )
1245 aPKQ = OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1246 aPKO = OUStringToOString(schemaPattern,m_nTextEncoding);
1247 aPKN = OUStringToOString(tableNamePattern,m_nTextEncoding);
1249 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : nullptr,
1250 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() && !aPKO.isEmpty() ? aPKO.getStr() : nullptr,
1251 *pPKN = aPKN.getStr();
1253 SQLRETURN nRetcode = N3SQLTablePrivileges(m_aStatementHandle,
1254 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKQ)), (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
1255 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKO)), pPKO ? SQL_NTS : 0 ,
1256 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKN)), SQL_NTS);
1257 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1258 checkColumnCount();
1261 void ODatabaseMetaDataResultSet::openIndexInfo( const Any& catalog, const OUString& schema,
1262 std::u16string_view table, bool unique, bool approximate )
1264 const OUString *pSchemaPat = nullptr;
1266 if(schema != "%")
1267 pSchemaPat = &schema;
1268 else
1269 pSchemaPat = nullptr;
1271 OString aPKQ,aPKO,aPKN;
1273 if ( catalog.hasValue() )
1274 aPKQ = OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1275 aPKO = OUStringToOString(schema,m_nTextEncoding);
1276 aPKN = OUStringToOString(table,m_nTextEncoding);
1278 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : nullptr,
1279 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() && !aPKO.isEmpty() ? aPKO.getStr() : nullptr,
1280 *pPKN = aPKN.getStr();
1282 SQLRETURN nRetcode = N3SQLStatistics(m_aStatementHandle,
1283 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKQ)), (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
1284 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKO)), pPKO ? SQL_NTS : 0 ,
1285 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKN)), SQL_NTS,
1286 unique ? SQL_INDEX_UNIQUE : SQL_INDEX_ALL,
1287 approximate ? 1 : 0);
1288 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1289 checkColumnCount();
1292 void ODatabaseMetaDataResultSet::checkColumnCount()
1294 sal_Int16 nNumResultCols=0;
1295 OTools::ThrowException(m_pConnection.get(),N3SQLNumResultCols(m_aStatementHandle,&nNumResultCols),m_aStatementHandle,SQL_HANDLE_STMT,*this);
1296 m_nDriverColumnCount = nNumResultCols;
1300 SWORD ODatabaseMetaDataResultSet::impl_getColumnType_nothrow(sal_Int32 columnIndex)
1302 std::map<sal_Int32,SWORD>::iterator aFind = m_aODBCColumnTypes.find(columnIndex);
1303 if ( aFind == m_aODBCColumnTypes.end() )
1304 aFind = m_aODBCColumnTypes.emplace(
1305 columnIndex,
1306 OResultSetMetaData::getColumnODBCType(m_pConnection.get(),m_aStatementHandle,*this,columnIndex)
1307 ).first;
1308 return aFind->second;
1311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */