bump product version to 4.1.6.2
[LibreOffice.git] / connectivity / source / drivers / odbcbase / ODatabaseMetaDataResultSet.cxx
blob7b524cc9a02ab039d2b1ffe3801289c0414da852
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 <com/sun/star/sdbc/KeyRule.hpp>
25 #include <com/sun/star/sdbc/ProcedureResult.hpp>
26 #include <com/sun/star/sdbc/IndexType.hpp>
27 #include <comphelper/property.hxx>
28 #include <com/sun/star/lang/DisposedException.hpp>
29 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
30 #include <com/sun/star/sdbc/ResultSetType.hpp>
31 #include <com/sun/star/sdbc/FetchDirection.hpp>
32 #include <cppuhelper/typeprovider.hxx>
33 #include <comphelper/sequence.hxx>
34 #include "odbc/OResultSetMetaData.hxx"
35 #include "odbc/OTools.hxx"
36 #include <comphelper/types.hxx>
37 #include "FDatabaseMetaDataResultSetMetaData.hxx"
38 #include <connectivity/dbexception.hxx>
40 using namespace ::comphelper;
43 using namespace connectivity::odbc;
44 using namespace cppu;
45 //------------------------------------------------------------------------------
46 using namespace ::com::sun::star::lang;
47 using namespace com::sun::star::uno;
48 using namespace com::sun::star::beans;
49 using namespace com::sun::star::sdbc;
50 using namespace com::sun::star::util;
52 // -------------------------------------------------------------------------
53 ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet(OConnection* _pConnection)
54 :ODatabaseMetaDataResultSet_BASE(m_aMutex)
55 ,OPropertySetHelper(ODatabaseMetaDataResultSet_BASE::rBHelper)
57 ,m_aStatementHandle(_pConnection->createStatementHandle())
58 ,m_aStatement(NULL)
59 ,m_xMetaData(NULL)
60 ,m_pRowStatusArray(NULL)
61 ,m_pConnection(_pConnection)
62 ,m_nTextEncoding(_pConnection->getTextEncoding())
63 ,m_nRowPos(-1)
64 ,m_nDriverColumnCount(0)
65 ,m_nCurrentFetchState(0)
66 ,m_bWasNull(sal_True)
67 ,m_bEOF(sal_False)
69 OSL_ENSURE(m_pConnection,"ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet: No parent set!");
70 if( SQL_NULL_HANDLE == m_aStatementHandle )
71 throw RuntimeException();
73 osl_atomic_increment( &m_refCount );
74 m_pConnection->acquire();
75 m_pRowStatusArray = new SQLUSMALLINT[1]; // the default value
76 osl_atomic_decrement( &m_refCount );
77 // allocBuffer();
80 // -------------------------------------------------------------------------
81 ODatabaseMetaDataResultSet::~ODatabaseMetaDataResultSet()
83 OSL_ENSURE(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed,"Object wasn't disposed!");
84 if(!ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed)
86 osl_atomic_increment( &m_refCount );
87 dispose();
89 delete [] m_pRowStatusArray;
91 // -------------------------------------------------------------------------
92 void ODatabaseMetaDataResultSet::disposing(void)
94 OPropertySetHelper::disposing();
96 ::osl::MutexGuard aGuard(m_aMutex);
98 m_pConnection->freeStatementHandle(m_aStatementHandle);
100 m_aStatement = NULL;
101 m_xMetaData.clear();
102 m_pConnection->release();
104 // -------------------------------------------------------------------------
105 Any SAL_CALL ODatabaseMetaDataResultSet::queryInterface( const Type & rType ) throw(RuntimeException)
107 Any aRet = OPropertySetHelper::queryInterface(rType);
108 return aRet.hasValue() ? aRet : ODatabaseMetaDataResultSet_BASE::queryInterface(rType);
110 // -----------------------------------------------------------------------------
111 Reference< XPropertySetInfo > SAL_CALL ODatabaseMetaDataResultSet::getPropertySetInfo( ) throw(RuntimeException)
113 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
115 // -----------------------------------------------------------------------------
116 void SAL_CALL ODatabaseMetaDataResultSet::acquire() throw()
118 ODatabaseMetaDataResultSet_BASE::acquire();
120 // -----------------------------------------------------------------------------
121 void SAL_CALL ODatabaseMetaDataResultSet::release() throw()
123 ODatabaseMetaDataResultSet_BASE::release();
125 // -------------------------------------------------------------------------
126 Sequence< Type > SAL_CALL ODatabaseMetaDataResultSet::getTypes( ) throw(RuntimeException)
128 ::cppu::OTypeCollection aTypes( ::getCppuType( (const Reference< XMultiPropertySet > *)0 ),
129 ::getCppuType( (const Reference< XFastPropertySet > *)0 ),
130 ::getCppuType( (const Reference< XPropertySet > *)0 ));
132 return ::comphelper::concatSequences(aTypes.getTypes(),ODatabaseMetaDataResultSet_BASE::getTypes());
134 // -----------------------------------------------------------------------------
135 sal_Int32 ODatabaseMetaDataResultSet::mapColumn (sal_Int32 column)
137 sal_Int32 map = column;
139 if (!m_aColMapping.empty())
141 // Validate column number
142 map = m_aColMapping[column];
145 return map;
147 // -------------------------------------------------------------------------
149 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::findColumn( const OUString& columnName ) throw(SQLException, RuntimeException)
152 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
153 ::osl::MutexGuard aGuard( m_aMutex );
156 Reference< XResultSetMetaData > xMeta = getMetaData();
157 sal_Int32 nLen = xMeta->getColumnCount();
158 sal_Int32 i = 1;
159 for(;i<=nLen;++i)
160 if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) :
161 columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i)))
162 break;
163 return i;
166 template < typename T, SQLSMALLINT sqlTypeId > T ODatabaseMetaDataResultSet::getInteger ( sal_Int32 columnIndex )
168 ::cppu::OBroadcastHelper& rBHelper(ODatabaseMetaDataResultSet_BASE::rBHelper);
169 checkDisposed(rBHelper.bDisposed);
170 ::osl::MutexGuard aGuard( m_aMutex );
172 columnIndex = mapColumn(columnIndex);
173 T nVal = 0;
174 if(columnIndex <= m_nDriverColumnCount)
176 getValue<T>(m_pConnection, m_aStatementHandle, columnIndex, sqlTypeId, m_bWasNull, **this, nVal);
178 if ( !m_aValueRange.empty() )
180 ::std::map<sal_Int32, ::connectivity::TInt2IntMap >::iterator aValueRangeIter (m_aValueRange.find(columnIndex));
181 if ( aValueRangeIter != m_aValueRange.end() )
182 return static_cast<T>(aValueRangeIter->second[nVal]);
185 else
186 m_bWasNull = sal_True;
187 return nVal;
190 // -------------------------------------------------------------------------
191 Reference< ::com::sun::star::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getBinaryStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
193 ::dbtools::throwFunctionNotSupportedException( "XRow::getBinaryStream", *this );
194 return NULL;
196 // -------------------------------------------------------------------------
197 Reference< ::com::sun::star::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getCharacterStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
199 ::dbtools::throwFunctionNotSupportedException( "XRow::getCharacterStream", *this );
200 return NULL;
203 // -------------------------------------------------------------------------
204 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
207 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
208 ::osl::MutexGuard aGuard( m_aMutex );
210 columnIndex = mapColumn(columnIndex);
212 sal_Bool bRet = sal_False;
213 if(columnIndex <= m_nDriverColumnCount)
215 sal_Int32 nType = getMetaData()->getColumnType(columnIndex);
216 switch(nType)
218 case DataType::BIT:
220 sal_Int8 nValue = 0;
221 OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_BIT,m_bWasNull,**this,&nValue,sizeof nValue);
222 bRet = nValue != 0;
224 break;
225 default:
226 bRet = getInt(columnIndex) != 0;
229 return bRet;
231 // -------------------------------------------------------------------------
233 sal_Int8 SAL_CALL ODatabaseMetaDataResultSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
235 return getInteger<sal_Int8, SQL_C_STINYINT>( columnIndex );
237 // -------------------------------------------------------------------------
239 Sequence< sal_Int8 > SAL_CALL ODatabaseMetaDataResultSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
242 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
243 ::osl::MutexGuard aGuard( m_aMutex );
246 columnIndex = mapColumn(columnIndex);
247 if(columnIndex <= m_nDriverColumnCount)
249 sal_Int32 nType = getMetaData()->getColumnType(columnIndex);
250 switch(nType)
252 case DataType::CHAR:
253 case DataType::VARCHAR:
254 case DataType::LONGVARCHAR:
256 OUString aRet = OTools::getStringValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_BINARY,m_bWasNull,**this,m_nTextEncoding);
257 return Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(aRet.getStr()),sizeof(sal_Unicode)*aRet.getLength());
260 return OTools::getBytesValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_BINARY,m_bWasNull,**this);
262 else
263 m_bWasNull = sal_True;
264 return Sequence<sal_Int8>();
266 // -------------------------------------------------------------------------
268 ::com::sun::star::util::Date SAL_CALL ODatabaseMetaDataResultSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
270 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
271 ::osl::MutexGuard aGuard( m_aMutex );
274 columnIndex = mapColumn(columnIndex);
275 if(columnIndex <= m_nDriverColumnCount)
277 DATE_STRUCT aDate;
278 aDate.day = 0;
279 aDate.month = 0;
280 aDate.year = 0;
281 OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,m_pConnection->useOldDateFormat() ? SQL_C_DATE : SQL_C_TYPE_DATE,m_bWasNull,**this,&aDate,sizeof aDate);
282 return Date(aDate.day,aDate.month,aDate.year);
284 else
285 m_bWasNull = sal_True;
286 return Date();
288 // -------------------------------------------------------------------------
290 double SAL_CALL ODatabaseMetaDataResultSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
293 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
294 ::osl::MutexGuard aGuard( m_aMutex );
297 columnIndex = mapColumn(columnIndex);
298 double nValue(0.0);
299 if(columnIndex <= m_nDriverColumnCount)
300 OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_DOUBLE,m_bWasNull,**this,&nValue,sizeof nValue);
301 else
302 m_bWasNull = sal_True;
303 return nValue;
305 // -------------------------------------------------------------------------
307 float SAL_CALL ODatabaseMetaDataResultSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
310 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
311 ::osl::MutexGuard aGuard( m_aMutex );
314 columnIndex = mapColumn(columnIndex);
315 float nVal(0);
316 if(columnIndex <= m_nDriverColumnCount)
317 OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_FLOAT,m_bWasNull,**this,&nVal,sizeof nVal);
318 else
319 m_bWasNull = sal_True;
320 return nVal;
322 // -------------------------------------------------------------------------
324 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
326 return getInteger<sal_Int32, SQL_C_SLONG>( columnIndex );
328 // -------------------------------------------------------------------------
330 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getRow( ) throw(SQLException, RuntimeException)
332 return 0;
334 // -------------------------------------------------------------------------
336 sal_Int64 SAL_CALL ODatabaseMetaDataResultSet::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
338 return getInteger<sal_Int64, SQL_C_SBIGINT>( columnIndex );
340 // -------------------------------------------------------------------------
342 Reference< XResultSetMetaData > SAL_CALL ODatabaseMetaDataResultSet::getMetaData( ) throw(SQLException, RuntimeException)
344 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
345 ::osl::MutexGuard aGuard( m_aMutex );
346 return m_xMetaData.is() ? m_xMetaData : (m_xMetaData = new OResultSetMetaData(m_pConnection,m_aStatementHandle));
348 // -------------------------------------------------------------------------
349 Reference< XArray > SAL_CALL ODatabaseMetaDataResultSet::getArray( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
351 ::dbtools::throwFunctionNotSupportedException( "XRow::getArray", *this );
352 return NULL;
354 // -------------------------------------------------------------------------
355 Reference< XClob > SAL_CALL ODatabaseMetaDataResultSet::getClob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
357 ::dbtools::throwFunctionNotSupportedException( "XRow::getClob", *this );
358 return NULL;
360 // -------------------------------------------------------------------------
361 Reference< XBlob > SAL_CALL ODatabaseMetaDataResultSet::getBlob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
363 ::dbtools::throwFunctionNotSupportedException( "XRow::getBlob", *this );
364 return NULL;
366 // -------------------------------------------------------------------------
368 Reference< XRef > SAL_CALL ODatabaseMetaDataResultSet::getRef( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
370 ::dbtools::throwFunctionNotSupportedException( "XRow::getRef", *this );
371 return NULL;
373 // -------------------------------------------------------------------------
375 Any SAL_CALL ODatabaseMetaDataResultSet::getObject( sal_Int32 /*columnIndex*/, const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
377 ::dbtools::throwFunctionNotSupportedException( "XRow::getObject", *this );
378 return Any();
380 // -------------------------------------------------------------------------
382 sal_Int16 SAL_CALL ODatabaseMetaDataResultSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
384 return getInteger<sal_Int16, SQL_C_SSHORT>( columnIndex );
386 // -------------------------------------------------------------------------
388 OUString SAL_CALL ODatabaseMetaDataResultSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
391 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
392 ::osl::MutexGuard aGuard( m_aMutex );
395 columnIndex = mapColumn(columnIndex);
396 OUString aVal;
397 if(columnIndex <= m_nDriverColumnCount)
398 aVal = OTools::getStringValue(m_pConnection,m_aStatementHandle,columnIndex,impl_getColumnType_nothrow(columnIndex),m_bWasNull,**this,m_nTextEncoding);
399 else
400 m_bWasNull = sal_True;
402 return aVal;
405 // -------------------------------------------------------------------------
408 ::com::sun::star::util::Time SAL_CALL ODatabaseMetaDataResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
411 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
412 ::osl::MutexGuard aGuard( m_aMutex );
415 columnIndex = mapColumn(columnIndex);
416 TIME_STRUCT aTime={0,0,0};
417 if(columnIndex <= m_nDriverColumnCount)
418 OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,m_pConnection->useOldDateFormat() ? SQL_C_TIME : SQL_C_TYPE_TIME,m_bWasNull,**this,&aTime,sizeof aTime);
419 else
420 m_bWasNull = sal_True;
421 return Time(0, aTime.second,aTime.minute,aTime.hour, false);
423 // -------------------------------------------------------------------------
426 ::com::sun::star::util::DateTime SAL_CALL ODatabaseMetaDataResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
429 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
430 ::osl::MutexGuard aGuard( m_aMutex );
433 columnIndex = mapColumn(columnIndex);
434 TIMESTAMP_STRUCT aTime={0,0,0,0,0,0,0};
435 if(columnIndex <= m_nDriverColumnCount)
436 OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,m_pConnection->useOldDateFormat() ? SQL_C_TIMESTAMP : SQL_C_TYPE_TIMESTAMP,m_bWasNull,**this,&aTime,sizeof aTime);
437 else
438 m_bWasNull = sal_True;
439 return DateTime(aTime.fraction, aTime.second, aTime.minute, aTime.hour,
440 aTime.day, aTime.month, aTime.year, false);
442 // -------------------------------------------------------------------------
444 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isAfterLast( ) throw(SQLException, RuntimeException)
447 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
448 ::osl::MutexGuard aGuard( m_aMutex );
451 return m_nCurrentFetchState == SQL_NO_DATA;
453 // -------------------------------------------------------------------------
454 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isFirst( ) throw(SQLException, RuntimeException)
457 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
458 ::osl::MutexGuard aGuard( m_aMutex );
461 return m_nRowPos == 1;
463 // -------------------------------------------------------------------------
464 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isLast( ) throw(SQLException, RuntimeException)
467 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
468 ::osl::MutexGuard aGuard( m_aMutex );
471 return m_bEOF && m_nCurrentFetchState != SQL_NO_DATA;
473 // -------------------------------------------------------------------------
474 void SAL_CALL ODatabaseMetaDataResultSet::beforeFirst( ) throw(SQLException, RuntimeException)
477 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
478 ::osl::MutexGuard aGuard( m_aMutex );
481 if(first())
482 previous();
483 m_nCurrentFetchState = SQL_SUCCESS;
485 // -------------------------------------------------------------------------
486 void SAL_CALL ODatabaseMetaDataResultSet::afterLast( ) throw(SQLException, RuntimeException)
489 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
490 ::osl::MutexGuard aGuard( m_aMutex );
493 if(last())
494 next();
496 // -------------------------------------------------------------------------
498 void SAL_CALL ODatabaseMetaDataResultSet::close( ) throw(SQLException, RuntimeException)
502 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
503 ::osl::MutexGuard aGuard( m_aMutex );
506 dispose();
508 // -------------------------------------------------------------------------
510 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::first( ) throw(SQLException, RuntimeException)
513 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
514 ::osl::MutexGuard aGuard( m_aMutex );
516 m_bEOF = sal_False;
518 m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_FIRST,0);
519 OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
520 sal_Bool bRet = ( m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO );
521 if( bRet )
522 m_nRowPos = 1;
523 return bRet;
525 // -------------------------------------------------------------------------
527 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::last( ) throw(SQLException, RuntimeException)
529 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
530 ::osl::MutexGuard aGuard( m_aMutex );
533 m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_LAST,0);
534 OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
535 // here I know definitely that I stand on the last record
536 sal_Bool bRet = ( m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO );
537 if( bRet )
538 m_bEOF = sal_True;
539 return bRet;
541 // -------------------------------------------------------------------------
542 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException)
545 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
546 ::osl::MutexGuard aGuard( m_aMutex );
548 m_bEOF = sal_False;
550 m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_ABSOLUTE,row);
551 OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
552 sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
553 if(bRet)
554 m_nRowPos = row;
555 return bRet;
557 // -------------------------------------------------------------------------
558 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::relative( sal_Int32 row ) throw(SQLException, RuntimeException)
561 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
562 ::osl::MutexGuard aGuard( m_aMutex );
564 m_bEOF = sal_False;
566 m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_RELATIVE,row);
567 OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
568 sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
569 if(bRet)
570 m_nRowPos += row;
571 return bRet;
573 // -------------------------------------------------------------------------
574 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::previous( ) throw(SQLException, RuntimeException)
577 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
578 ::osl::MutexGuard aGuard( m_aMutex );
580 m_bEOF = sal_False;
582 m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
583 OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
584 sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
585 if(bRet)
586 --m_nRowPos;
587 else if ( m_nCurrentFetchState == SQL_NO_DATA )
588 m_nRowPos = 0;
589 return bRet;
591 // -------------------------------------------------------------------------
592 Reference< XInterface > SAL_CALL ODatabaseMetaDataResultSet::getStatement( ) throw(SQLException, RuntimeException)
594 return NULL;
596 // -------------------------------------------------------------------------
598 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowDeleted( ) throw(SQLException, RuntimeException)
601 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
602 ::osl::MutexGuard aGuard( m_aMutex );
605 return m_pRowStatusArray[0] == SQL_ROW_DELETED;
607 // -------------------------------------------------------------------------
608 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowInserted( ) throw(SQLException, RuntimeException)
610 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
611 ::osl::MutexGuard aGuard( m_aMutex );
614 return m_pRowStatusArray[0] == SQL_ROW_ADDED;
616 // -------------------------------------------------------------------------
617 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowUpdated( ) throw(SQLException, RuntimeException)
620 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
621 ::osl::MutexGuard aGuard( m_aMutex );
624 return m_pRowStatusArray[0] == SQL_ROW_UPDATED;
626 // -------------------------------------------------------------------------
628 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isBeforeFirst( ) throw(SQLException, RuntimeException)
631 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
632 ::osl::MutexGuard aGuard( m_aMutex );
635 return m_nRowPos == 0;
637 // -------------------------------------------------------------------------
639 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::next( ) throw(SQLException, RuntimeException)
642 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
643 ::osl::MutexGuard aGuard( m_aMutex );
645 m_bEOF = sal_False;
647 SQLRETURN nOldFetchStatus = m_nCurrentFetchState;
648 // m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_NEXT,0);
649 m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
650 OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
651 sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
652 if(bRet || ( m_nCurrentFetchState == SQL_NO_DATA && nOldFetchStatus != SQL_NO_DATA ) )
653 ++m_nRowPos;
654 return bRet;
656 // -------------------------------------------------------------------------
658 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::wasNull( ) throw(SQLException, RuntimeException)
661 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
662 ::osl::MutexGuard aGuard( m_aMutex );
665 return m_bWasNull;
667 // -------------------------------------------------------------------------
668 void SAL_CALL ODatabaseMetaDataResultSet::refreshRow( ) throw(SQLException, RuntimeException)
671 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
672 ::osl::MutexGuard aGuard( m_aMutex );
675 // -------------------------------------------------------------------------
677 void SAL_CALL ODatabaseMetaDataResultSet::cancel( ) throw(RuntimeException)
680 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
681 ::osl::MutexGuard aGuard( m_aMutex );
684 OTools::ThrowException(m_pConnection,N3SQLCancel(m_aStatementHandle),m_aStatementHandle,SQL_HANDLE_STMT,*this);
686 // -------------------------------------------------------------------------
687 void SAL_CALL ODatabaseMetaDataResultSet::clearWarnings( ) throw(SQLException, RuntimeException)
690 // -------------------------------------------------------------------------
691 Any SAL_CALL ODatabaseMetaDataResultSet::getWarnings( ) throw(SQLException, RuntimeException)
693 return Any();
695 //------------------------------------------------------------------------------
696 sal_Int32 ODatabaseMetaDataResultSet::getResultSetConcurrency() const throw(SQLException, RuntimeException)
698 return ResultSetConcurrency::READ_ONLY;
700 //------------------------------------------------------------------------------
701 sal_Int32 ODatabaseMetaDataResultSet::getResultSetType() const throw(SQLException, RuntimeException)
703 return ResultSetType::FORWARD_ONLY;
705 //------------------------------------------------------------------------------
706 sal_Int32 ODatabaseMetaDataResultSet::getFetchDirection() const throw(SQLException, RuntimeException)
708 return FetchDirection::FORWARD;
710 //------------------------------------------------------------------------------
711 sal_Int32 ODatabaseMetaDataResultSet::getFetchSize() const throw(SQLException, RuntimeException)
713 sal_Int32 nValue=1;
714 return nValue;
716 //------------------------------------------------------------------------------
717 OUString ODatabaseMetaDataResultSet::getCursorName() const throw(SQLException, RuntimeException)
719 return OUString();
722 // -------------------------------------------------------------------------
723 ::cppu::IPropertyArrayHelper* ODatabaseMetaDataResultSet::createArrayHelper( ) const
726 Sequence< com::sun::star::beans::Property > aProps(5);
727 com::sun::star::beans::Property* pProperties = aProps.getArray();
728 sal_Int32 nPos = 0;
729 DECL_PROP0(CURSORNAME, OUString);
730 DECL_PROP0(FETCHDIRECTION, sal_Int32);
731 DECL_PROP0(FETCHSIZE, sal_Int32);
732 DECL_PROP0(RESULTSETCONCURRENCY,sal_Int32);
733 DECL_PROP0(RESULTSETTYPE, sal_Int32);
735 return new ::cppu::OPropertyArrayHelper(aProps);
737 // -------------------------------------------------------------------------
738 ::cppu::IPropertyArrayHelper & ODatabaseMetaDataResultSet::getInfoHelper()
740 return *const_cast<ODatabaseMetaDataResultSet*>(this)->getArrayHelper();
742 // -------------------------------------------------------------------------
743 sal_Bool ODatabaseMetaDataResultSet::convertFastPropertyValue(
744 Any & rConvertedValue,
745 Any & rOldValue,
746 sal_Int32 nHandle,
747 const Any& rValue )
748 throw (::com::sun::star::lang::IllegalArgumentException)
750 switch(nHandle)
752 case PROPERTY_ID_CURSORNAME:
753 case PROPERTY_ID_RESULTSETCONCURRENCY:
754 case PROPERTY_ID_RESULTSETTYPE:
755 throw ::com::sun::star::lang::IllegalArgumentException();
756 case PROPERTY_ID_FETCHDIRECTION:
757 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection());
758 case PROPERTY_ID_FETCHSIZE:
759 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize());
760 default:
763 return sal_False;
765 // -------------------------------------------------------------------------
766 void ODatabaseMetaDataResultSet::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& /*rValue*/ ) throw (Exception)
768 switch(nHandle)
770 case PROPERTY_ID_CURSORNAME:
771 case PROPERTY_ID_RESULTSETCONCURRENCY:
772 case PROPERTY_ID_RESULTSETTYPE:
773 case PROPERTY_ID_FETCHDIRECTION:
774 case PROPERTY_ID_FETCHSIZE:
775 throw Exception();
776 default:
777 OSL_FAIL("setFastPropertyValue_NoBroadcast: Illegal handle value!");
780 // -------------------------------------------------------------------------
781 void ODatabaseMetaDataResultSet::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
783 switch(nHandle)
785 case PROPERTY_ID_CURSORNAME:
786 rValue <<= getCursorName();
787 break;
788 case PROPERTY_ID_RESULTSETCONCURRENCY:
789 rValue <<= getResultSetConcurrency();
790 break;
791 case PROPERTY_ID_RESULTSETTYPE:
792 rValue <<= getResultSetType();
793 break;
794 case PROPERTY_ID_FETCHDIRECTION:
795 rValue <<= getFetchDirection();
796 break;
797 case PROPERTY_ID_FETCHSIZE:
798 rValue <<= getFetchSize();
799 break;
802 // -------------------------------------------------------------------------
803 void ODatabaseMetaDataResultSet::openTypeInfo() throw(SQLException, RuntimeException)
805 TInt2IntMap aMap;
806 aMap[SQL_BIT] = DataType::BIT;
807 aMap[SQL_TINYINT] = DataType::TINYINT;
808 aMap[SQL_SMALLINT] = DataType::SMALLINT;
809 aMap[SQL_INTEGER] = DataType::INTEGER;
810 aMap[SQL_FLOAT] = DataType::FLOAT;
811 aMap[SQL_REAL] = DataType::REAL;
812 aMap[SQL_DOUBLE] = DataType::DOUBLE;
813 aMap[SQL_BIGINT] = DataType::BIGINT;
815 aMap[SQL_CHAR] = DataType::CHAR;
816 aMap[SQL_WCHAR] = DataType::CHAR;
817 aMap[SQL_VARCHAR] = DataType::VARCHAR;
818 aMap[SQL_WVARCHAR] = DataType::VARCHAR;
819 aMap[SQL_LONGVARCHAR] = DataType::LONGVARCHAR;
820 aMap[SQL_WLONGVARCHAR] = DataType::LONGVARCHAR;
822 aMap[SQL_TYPE_DATE] = DataType::DATE;
823 aMap[SQL_DATE] = DataType::DATE;
824 aMap[SQL_TYPE_TIME] = DataType::TIME;
825 aMap[SQL_TIME] = DataType::TIME;
826 aMap[SQL_TYPE_TIMESTAMP] = DataType::TIMESTAMP;
827 aMap[SQL_TIMESTAMP] = DataType::TIMESTAMP;
829 aMap[SQL_DECIMAL] = DataType::DECIMAL;
830 aMap[SQL_NUMERIC] = DataType::NUMERIC;
832 aMap[SQL_BINARY] = DataType::BINARY;
833 aMap[SQL_VARBINARY] = DataType::VARBINARY;
834 aMap[SQL_LONGVARBINARY] = DataType::LONGVARBINARY;
836 aMap[SQL_GUID] = DataType::VARBINARY;
839 m_aValueRange[2] = aMap;
841 OTools::ThrowException(m_pConnection,N3SQLGetTypeInfo(m_aStatementHandle, SQL_ALL_TYPES),m_aStatementHandle,SQL_HANDLE_STMT,*this);
842 checkColumnCount();
844 //-----------------------------------------------------------------------------
845 void ODatabaseMetaDataResultSet::openTables(const Any& catalog, const OUString& schemaPattern,
846 const OUString& tableNamePattern,
847 const Sequence< OUString >& types ) throw(SQLException, RuntimeException)
849 OString aPKQ,aPKO,aPKN,aCOL;
850 const OUString *pSchemaPat = NULL;
852 if(schemaPattern != "%")
853 pSchemaPat = &schemaPattern;
854 else
855 pSchemaPat = NULL;
857 if ( catalog.hasValue() )
858 aPKQ = OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
859 aPKO = OUStringToOString(schemaPattern,m_nTextEncoding);
860 aPKN = OUStringToOString(tableNamePattern,m_nTextEncoding);
862 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : NULL,
863 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() ? aPKO.getStr() : NULL,
864 *pPKN = aPKN.getStr();
867 const char *pCOL = NULL;
868 const char* pComma = ",";
869 const OUString* pBegin = types.getConstArray();
870 const OUString* pEnd = pBegin + types.getLength();
871 for(;pBegin != pEnd;++pBegin)
873 aCOL += OUStringToOString(*pBegin,m_nTextEncoding);
874 aCOL += pComma;
876 if ( !aCOL.isEmpty() )
878 aCOL = aCOL.replaceAt(aCOL.getLength()-1,1,pComma);
879 pCOL = aCOL.getStr();
881 else
882 pCOL = SQL_ALL_TABLE_TYPES;
884 SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle,
885 (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
886 (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0,
887 (SDB_ODBC_CHAR *) pPKN, SQL_NTS,
888 (SDB_ODBC_CHAR *) pCOL, pCOL ? SQL_NTS : 0);
889 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
890 checkColumnCount();
893 //-----------------------------------------------------------------------------
894 void ODatabaseMetaDataResultSet::openTablesTypes( ) throw(SQLException, RuntimeException)
896 SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle,
897 0,0,
898 0,0,
899 0,0,
900 (SDB_ODBC_CHAR *) SQL_ALL_TABLE_TYPES,SQL_NTS);
901 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
903 m_aColMapping.clear();
904 m_aColMapping.push_back(-1);
905 m_aColMapping.push_back(4);
906 m_xMetaData = new OResultSetMetaData(m_pConnection,m_aStatementHandle,m_aColMapping);
907 checkColumnCount();
909 // -------------------------------------------------------------------------
910 void ODatabaseMetaDataResultSet::openCatalogs() throw(SQLException, RuntimeException)
912 SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle,
913 (SDB_ODBC_CHAR *) SQL_ALL_CATALOGS,SQL_NTS,
914 (SDB_ODBC_CHAR *) "",SQL_NTS,
915 (SDB_ODBC_CHAR *) "",SQL_NTS,
916 (SDB_ODBC_CHAR *) "",SQL_NTS);
918 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
920 m_aColMapping.clear();
921 m_aColMapping.push_back(-1);
922 m_aColMapping.push_back(1);
923 m_xMetaData = new OResultSetMetaData(m_pConnection,m_aStatementHandle,m_aColMapping);
924 checkColumnCount();
926 // -------------------------------------------------------------------------
927 void ODatabaseMetaDataResultSet::openSchemas() throw(SQLException, RuntimeException)
929 SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle,
930 (SDB_ODBC_CHAR *) "",SQL_NTS,
931 (SDB_ODBC_CHAR *) SQL_ALL_SCHEMAS,SQL_NTS,
932 (SDB_ODBC_CHAR *) "",SQL_NTS,
933 (SDB_ODBC_CHAR *) "",SQL_NTS);
934 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
936 m_aColMapping.clear();
937 m_aColMapping.push_back(-1);
938 m_aColMapping.push_back(2);
939 m_xMetaData = new OResultSetMetaData(m_pConnection,m_aStatementHandle,m_aColMapping);
940 checkColumnCount();
942 // -------------------------------------------------------------------------
943 void ODatabaseMetaDataResultSet::openColumnPrivileges( const Any& catalog, const OUString& schema,
944 const OUString& table, const OUString& columnNamePattern )
945 throw(SQLException, RuntimeException)
947 const OUString *pSchemaPat = NULL;
949 if(schema != "%")
950 pSchemaPat = &schema;
951 else
952 pSchemaPat = NULL;
954 OString aPKQ,aPKO,aPKN,aCOL;
956 if ( catalog.hasValue() )
957 aPKQ = OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
958 aPKO = OUStringToOString(schema,m_nTextEncoding);
959 aPKN = OUStringToOString(table,m_nTextEncoding);
960 aCOL = OUStringToOString(columnNamePattern,m_nTextEncoding);
962 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : NULL,
963 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() ? aPKO.getStr() : NULL,
964 *pPKN = aPKN.getStr(),
965 *pCOL = aCOL.getStr();
968 SQLRETURN nRetcode = N3SQLColumnPrivileges(m_aStatementHandle,
969 (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
970 (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 ,
971 (SDB_ODBC_CHAR *) pPKN, SQL_NTS,
972 (SDB_ODBC_CHAR *) pCOL, SQL_NTS);
973 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
975 checkColumnCount();
977 // -------------------------------------------------------------------------
978 void ODatabaseMetaDataResultSet::openColumns( const Any& catalog, const OUString& schemaPattern,
979 const OUString& tableNamePattern, const OUString& columnNamePattern )
980 throw(SQLException, RuntimeException)
982 const OUString *pSchemaPat = NULL;
984 if(schemaPattern != "%")
985 pSchemaPat = &schemaPattern;
986 else
987 pSchemaPat = NULL;
989 OString aPKQ,aPKO,aPKN,aCOL;
990 if ( catalog.hasValue() )
991 aPKQ = OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
992 aPKO = OUStringToOString(schemaPattern,m_nTextEncoding);
993 aPKN = OUStringToOString(tableNamePattern,m_nTextEncoding);
994 aCOL = OUStringToOString(columnNamePattern,m_nTextEncoding);
996 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : NULL,
997 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() && !pSchemaPat->isEmpty() ? aPKO.getStr() : NULL,
998 *pPKN = aPKN.getStr(),
999 *pCOL = aCOL.getStr();
1002 SQLRETURN nRetcode = N3SQLColumns(m_aStatementHandle,
1003 (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
1004 (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0,
1005 (SDB_ODBC_CHAR *) pPKN, SQL_NTS,
1006 (SDB_ODBC_CHAR *) pCOL, SQL_NTS);
1008 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1009 TInt2IntMap aMap;
1010 aMap[SQL_BIT] = DataType::BIT;
1011 aMap[SQL_TINYINT] = DataType::TINYINT;
1012 aMap[SQL_SMALLINT] = DataType::SMALLINT;
1013 aMap[SQL_INTEGER] = DataType::INTEGER;
1014 aMap[SQL_FLOAT] = DataType::FLOAT;
1015 aMap[SQL_REAL] = DataType::REAL;
1016 aMap[SQL_DOUBLE] = DataType::DOUBLE;
1017 aMap[SQL_BIGINT] = DataType::BIGINT;
1019 aMap[SQL_CHAR] = DataType::CHAR;
1020 aMap[SQL_WCHAR] = DataType::CHAR;
1021 aMap[SQL_VARCHAR] = DataType::VARCHAR;
1022 aMap[SQL_WVARCHAR] = DataType::VARCHAR;
1023 aMap[SQL_LONGVARCHAR] = DataType::LONGVARCHAR;
1024 aMap[SQL_WLONGVARCHAR] = DataType::LONGVARCHAR;
1026 aMap[SQL_TYPE_DATE] = DataType::DATE;
1027 aMap[SQL_DATE] = DataType::DATE;
1028 aMap[SQL_TYPE_TIME] = DataType::TIME;
1029 aMap[SQL_TIME] = DataType::TIME;
1030 aMap[SQL_TYPE_TIMESTAMP] = DataType::TIMESTAMP;
1031 aMap[SQL_TIMESTAMP] = DataType::TIMESTAMP;
1033 aMap[SQL_DECIMAL] = DataType::DECIMAL;
1034 aMap[SQL_NUMERIC] = DataType::NUMERIC;
1036 aMap[SQL_BINARY] = DataType::BINARY;
1037 aMap[SQL_VARBINARY] = DataType::VARBINARY;
1038 aMap[SQL_LONGVARBINARY] = DataType::LONGVARBINARY;
1040 aMap[SQL_GUID] = DataType::VARBINARY;
1042 m_aValueRange[5] = aMap;
1043 checkColumnCount();
1045 // -------------------------------------------------------------------------
1046 void ODatabaseMetaDataResultSet::openProcedureColumns( const Any& catalog, const OUString& schemaPattern,
1047 const OUString& procedureNamePattern,const OUString& columnNamePattern )
1048 throw(SQLException, RuntimeException)
1050 const OUString *pSchemaPat = NULL;
1052 if(schemaPattern != "%")
1053 pSchemaPat = &schemaPattern;
1054 else
1055 pSchemaPat = NULL;
1057 OString aPKQ,aPKO,aPKN,aCOL;
1058 if ( catalog.hasValue() )
1059 aPKQ = OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1060 aPKO = OUStringToOString(schemaPattern,m_nTextEncoding);
1061 aPKN = OUStringToOString(procedureNamePattern,m_nTextEncoding);
1062 aCOL = OUStringToOString(columnNamePattern,m_nTextEncoding);
1064 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : NULL,
1065 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() ? aPKO.getStr() : NULL,
1066 *pPKN = aPKN.getStr(),
1067 *pCOL = aCOL.getStr();
1070 SQLRETURN nRetcode = N3SQLProcedureColumns(m_aStatementHandle,
1071 (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
1072 (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 ,
1073 (SDB_ODBC_CHAR *) pPKN, SQL_NTS,
1074 (SDB_ODBC_CHAR *) pCOL, SQL_NTS);
1076 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1077 checkColumnCount();
1079 // -------------------------------------------------------------------------
1080 void ODatabaseMetaDataResultSet::openProcedures(const Any& catalog, const OUString& schemaPattern,
1081 const OUString& procedureNamePattern)
1082 throw(SQLException, RuntimeException)
1084 const OUString *pSchemaPat = NULL;
1086 if(schemaPattern != "%")
1087 pSchemaPat = &schemaPattern;
1088 else
1089 pSchemaPat = NULL;
1091 OString aPKQ,aPKO,aPKN;
1093 if ( catalog.hasValue() )
1094 aPKQ = OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1095 aPKO = OUStringToOString(schemaPattern,m_nTextEncoding);
1096 aPKN = OUStringToOString(procedureNamePattern,m_nTextEncoding);
1098 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : NULL,
1099 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() ? aPKO.getStr() : NULL,
1100 *pPKN = aPKN.getStr();
1103 SQLRETURN nRetcode = N3SQLProcedures(m_aStatementHandle,
1104 (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
1105 (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 ,
1106 (SDB_ODBC_CHAR *) pPKN, SQL_NTS);
1107 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1108 checkColumnCount();
1110 // -------------------------------------------------------------------------
1111 void ODatabaseMetaDataResultSet::openSpecialColumns(sal_Bool _bRowVer,const Any& catalog, const OUString& schema,
1112 const OUString& table,sal_Int32 scope, sal_Bool nullable )
1113 throw(SQLException, RuntimeException)
1115 // Some ODBC drivers really don't like getting an empty string as tableName
1116 // E.g. psqlodbc up to at least version 09.01.0100 segfaults
1117 if (table.isEmpty())
1119 const char errMsg[] = "ODBC: Trying to get special columns of empty table name";
1120 const char SQLState[] = "HY009";
1121 throw SQLException( OUString(errMsg, sizeof(errMsg) - sizeof(errMsg[0]), RTL_TEXTENCODING_ASCII_US),
1122 *this,
1123 OUString(SQLState, sizeof(SQLState) - sizeof(SQLState[0]), RTL_TEXTENCODING_ASCII_US),
1125 Any() );
1128 const OUString *pSchemaPat = NULL;
1130 if(schema != "%")
1131 pSchemaPat = &schema;
1132 else
1133 pSchemaPat = NULL;
1135 OString aPKQ,aPKO,aPKN;
1136 if ( catalog.hasValue() )
1137 aPKQ = OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1138 aPKO = OUStringToOString(schema,m_nTextEncoding);
1139 aPKN = OUStringToOString(table,m_nTextEncoding);
1141 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : NULL,
1142 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() ? aPKO.getStr() : NULL,
1143 *pPKN = aPKN.getStr();
1146 SQLRETURN nRetcode = N3SQLSpecialColumns(m_aStatementHandle,_bRowVer ? SQL_ROWVER : SQL_BEST_ROWID,
1147 (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
1148 (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 ,
1149 (SDB_ODBC_CHAR *) pPKN, SQL_NTS,
1150 (SQLSMALLINT)scope,
1151 nullable ? SQL_NULLABLE : SQL_NO_NULLS);
1152 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1153 checkColumnCount();
1155 // -------------------------------------------------------------------------
1156 void ODatabaseMetaDataResultSet::openVersionColumns(const Any& catalog, const OUString& schema,
1157 const OUString& table) throw(SQLException, RuntimeException)
1159 openSpecialColumns(sal_True,catalog,schema,table,SQL_SCOPE_TRANSACTION,sal_False);
1161 // -------------------------------------------------------------------------
1162 void ODatabaseMetaDataResultSet::openBestRowIdentifier( const Any& catalog, const OUString& schema,
1163 const OUString& table,sal_Int32 scope,sal_Bool nullable ) throw(SQLException, RuntimeException)
1165 openSpecialColumns(sal_False,catalog,schema,table,scope,nullable);
1167 // -------------------------------------------------------------------------
1168 void ODatabaseMetaDataResultSet::openForeignKeys( const Any& catalog, const OUString* schema,
1169 const OUString* table,
1170 const Any& catalog2, const OUString* schema2,
1171 const OUString* table2) throw(SQLException, RuntimeException)
1173 OString aPKQ, aPKN, aFKQ, aFKO, aFKN;
1174 if ( catalog.hasValue() )
1175 aPKQ = OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1176 if ( catalog2.hasValue() )
1177 aFKQ = OUStringToOString(comphelper::getString(catalog2),m_nTextEncoding);
1179 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : NULL,
1180 *pPKO = schema && !schema->isEmpty() ? OUStringToOString(*schema,m_nTextEncoding).getStr() : NULL,
1181 *pPKN = table ? (aPKN = OUStringToOString(*table,m_nTextEncoding)).getStr(): NULL,
1182 *pFKQ = catalog2.hasValue() && !aFKQ.isEmpty() ? aFKQ.getStr() : NULL,
1183 *pFKO = schema2 && !schema2->isEmpty() ? (aFKO = OUStringToOString(*schema2,m_nTextEncoding)).getStr() : NULL,
1184 *pFKN = table2 ? (aFKN = OUStringToOString(*table2,m_nTextEncoding)).getStr() : NULL;
1187 SQLRETURN nRetcode = N3SQLForeignKeys(m_aStatementHandle,
1188 (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
1189 (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0,
1190 (SDB_ODBC_CHAR *) pPKN, pPKN ? SQL_NTS : 0,
1191 (SDB_ODBC_CHAR *) pFKQ, (catalog2.hasValue() && !aFKQ.isEmpty()) ? SQL_NTS : 0,
1192 (SDB_ODBC_CHAR *) pFKO, pFKO ? SQL_NTS : 0,
1193 (SDB_ODBC_CHAR *) pFKN, SQL_NTS
1195 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1196 checkColumnCount();
1198 // -------------------------------------------------------------------------
1199 void ODatabaseMetaDataResultSet::openImportedKeys(const Any& catalog, const OUString& schema,
1200 const OUString& table) throw(SQLException, RuntimeException)
1203 openForeignKeys(Any(),NULL,NULL,catalog,!schema.compareToAscii("%") ? &schema : NULL,&table);
1205 // -------------------------------------------------------------------------
1206 void ODatabaseMetaDataResultSet::openExportedKeys(const Any& catalog, const OUString& schema,
1207 const OUString& table) throw(SQLException, RuntimeException)
1209 openForeignKeys(catalog,!schema.compareToAscii("%") ? &schema : NULL,&table,Any(),NULL,NULL);
1211 // -------------------------------------------------------------------------
1212 void ODatabaseMetaDataResultSet::openPrimaryKeys(const Any& catalog, const OUString& schema,
1213 const OUString& table) throw(SQLException, RuntimeException)
1215 const OUString *pSchemaPat = NULL;
1217 if(schema != "%")
1218 pSchemaPat = &schema;
1219 else
1220 pSchemaPat = NULL;
1222 OString aPKQ,aPKO,aPKN;
1224 if ( catalog.hasValue() )
1225 aPKQ = OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1226 aPKO = OUStringToOString(schema,m_nTextEncoding);
1228 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : NULL,
1229 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() ? aPKO.getStr() : NULL,
1230 *pPKN = (aPKN = OUStringToOString(table,m_nTextEncoding)).getStr();
1233 SQLRETURN nRetcode = N3SQLPrimaryKeys(m_aStatementHandle,
1234 (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
1235 (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 ,
1236 (SDB_ODBC_CHAR *) pPKN, SQL_NTS);
1237 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1238 checkColumnCount();
1240 // -------------------------------------------------------------------------
1241 void ODatabaseMetaDataResultSet::openTablePrivileges(const Any& catalog, const OUString& schemaPattern,
1242 const OUString& tableNamePattern) throw(SQLException, RuntimeException)
1244 const OUString *pSchemaPat = NULL;
1246 if(schemaPattern != "%")
1247 pSchemaPat = &schemaPattern;
1248 else
1249 pSchemaPat = NULL;
1251 OString aPKQ,aPKO,aPKN;
1253 if ( catalog.hasValue() )
1254 aPKQ = OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1255 aPKO = OUStringToOString(schemaPattern,m_nTextEncoding);
1257 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : NULL,
1258 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() ? aPKO.getStr() : NULL,
1259 *pPKN = (aPKN = OUStringToOString(tableNamePattern,m_nTextEncoding)).getStr();
1262 SQLRETURN nRetcode = N3SQLTablePrivileges(m_aStatementHandle,
1263 (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
1264 (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 ,
1265 (SDB_ODBC_CHAR *) pPKN, SQL_NTS);
1266 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1267 checkColumnCount();
1269 // -------------------------------------------------------------------------
1270 void ODatabaseMetaDataResultSet::openIndexInfo( const Any& catalog, const OUString& schema,
1271 const OUString& table,sal_Bool unique,sal_Bool approximate )
1272 throw(SQLException, RuntimeException)
1274 const OUString *pSchemaPat = NULL;
1276 if(schema != "%")
1277 pSchemaPat = &schema;
1278 else
1279 pSchemaPat = NULL;
1281 OString aPKQ,aPKO,aPKN;
1283 if ( catalog.hasValue() )
1284 aPKQ = OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1285 aPKO = OUStringToOString(schema,m_nTextEncoding);
1287 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : NULL,
1288 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() ? aPKO.getStr() : NULL,
1289 *pPKN = (aPKN = OUStringToOString(table,m_nTextEncoding)).getStr();
1292 SQLRETURN nRetcode = N3SQLStatistics(m_aStatementHandle,
1293 (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
1294 (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 ,
1295 (SDB_ODBC_CHAR *) pPKN, SQL_NTS,
1296 unique ? SQL_INDEX_UNIQUE : SQL_INDEX_ALL,
1297 approximate);
1298 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1299 checkColumnCount();
1301 // -------------------------------------------------------------------------
1302 void ODatabaseMetaDataResultSet::checkColumnCount()
1304 sal_Int16 nNumResultCols=0;
1305 OTools::ThrowException(m_pConnection,N3SQLNumResultCols(m_aStatementHandle,&nNumResultCols),m_aStatementHandle,SQL_HANDLE_STMT,*this);
1306 m_nDriverColumnCount = nNumResultCols;
1308 // -----------------------------------------------------------------------------
1310 SWORD ODatabaseMetaDataResultSet::impl_getColumnType_nothrow(sal_Int32 columnIndex)
1312 ::std::map<sal_Int32,SWORD>::iterator aFind = m_aODBCColumnTypes.find(columnIndex);
1313 if ( aFind == m_aODBCColumnTypes.end() )
1314 aFind = m_aODBCColumnTypes.insert(::std::map<sal_Int32,SWORD>::value_type(columnIndex,OResultSetMetaData::getColumnODBCType(m_pConnection,m_aStatementHandle,*this,columnIndex))).first;
1315 return aFind->second;
1318 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */