1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "TConnection.hxx"
31 #include "odbc/ODatabaseMetaDataResultSet.hxx"
32 #include <com/sun/star/sdbc/DataType.hpp>
33 #include <com/sun/star/sdbc/KeyRule.hpp>
34 #include <com/sun/star/sdbc/ProcedureResult.hpp>
35 #include <com/sun/star/sdbc/IndexType.hpp>
36 #include <comphelper/property.hxx>
37 #include <com/sun/star/lang/DisposedException.hpp>
38 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
39 #include <com/sun/star/sdbc/ResultSetType.hpp>
40 #include <com/sun/star/sdbc/FetchDirection.hpp>
41 #include <cppuhelper/typeprovider.hxx>
42 #include <comphelper/sequence.hxx>
43 #include "odbc/OResultSetMetaData.hxx"
44 #include "odbc/OTools.hxx"
45 #include <comphelper/types.hxx>
46 #include "FDatabaseMetaDataResultSetMetaData.hxx"
47 #include <connectivity/dbexception.hxx>
49 using namespace ::comphelper
;
52 using namespace connectivity::odbc
;
54 //------------------------------------------------------------------------------
55 using namespace ::com::sun::star::lang
;
56 using namespace com::sun::star::uno
;
57 using namespace com::sun::star::beans
;
58 using namespace com::sun::star::sdbc
;
59 using namespace com::sun::star::util
;
61 // -------------------------------------------------------------------------
62 ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet(OConnection
* _pConnection
)
63 :ODatabaseMetaDataResultSet_BASE(m_aMutex
)
64 ,OPropertySetHelper(ODatabaseMetaDataResultSet_BASE::rBHelper
)
66 ,m_aStatementHandle(_pConnection
->createStatementHandle())
69 ,m_pRowStatusArray(NULL
)
70 ,m_pConnection(_pConnection
)
71 ,m_nTextEncoding(_pConnection
->getTextEncoding())
74 ,m_nDriverColumnCount(0)
75 ,m_nCurrentFetchState(0)
78 ,m_bFreeHandle(sal_False
)
80 OSL_ENSURE(m_pConnection
,"ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet: No parent set!");
81 osl_incrementInterlockedCount( &m_refCount
);
82 m_pConnection
->acquire();
83 m_pRowStatusArray
= new SQLUSMALLINT
[1]; // the default value
84 osl_decrementInterlockedCount( &m_refCount
);
88 // -------------------------------------------------------------------------
89 ODatabaseMetaDataResultSet::~ODatabaseMetaDataResultSet()
91 OSL_ENSURE(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
,"Object wasn't disposed!");
92 if(!ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
)
94 osl_incrementInterlockedCount( &m_refCount
);
97 delete [] m_pRowStatusArray
;
99 // -------------------------------------------------------------------------
100 void ODatabaseMetaDataResultSet::disposing(void)
102 OPropertySetHelper::disposing();
104 ::osl::MutexGuard
aGuard(m_aMutex
);
106 m_pConnection
->freeStatementHandle(m_aStatementHandle
);
110 m_pConnection
->release();
112 // -------------------------------------------------------------------------
113 Any SAL_CALL
ODatabaseMetaDataResultSet::queryInterface( const Type
& rType
) throw(RuntimeException
)
115 Any aRet
= OPropertySetHelper::queryInterface(rType
);
116 return aRet
.hasValue() ? aRet
: ODatabaseMetaDataResultSet_BASE::queryInterface(rType
);
118 // -----------------------------------------------------------------------------
119 Reference
< XPropertySetInfo
> SAL_CALL
ODatabaseMetaDataResultSet::getPropertySetInfo( ) throw(RuntimeException
)
121 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
123 // -----------------------------------------------------------------------------
124 void SAL_CALL
ODatabaseMetaDataResultSet::acquire() throw()
126 ODatabaseMetaDataResultSet_BASE::acquire();
128 // -----------------------------------------------------------------------------
129 void SAL_CALL
ODatabaseMetaDataResultSet::release() throw()
131 ODatabaseMetaDataResultSet_BASE::release();
133 // -------------------------------------------------------------------------
134 Sequence
< Type
> SAL_CALL
ODatabaseMetaDataResultSet::getTypes( ) throw(RuntimeException
)
136 ::cppu::OTypeCollection
aTypes( ::getCppuType( (const Reference
< XMultiPropertySet
> *)0 ),
137 ::getCppuType( (const Reference
< XFastPropertySet
> *)0 ),
138 ::getCppuType( (const Reference
< XPropertySet
> *)0 ));
140 return ::comphelper::concatSequences(aTypes
.getTypes(),ODatabaseMetaDataResultSet_BASE::getTypes());
142 // -----------------------------------------------------------------------------
143 sal_Int32
ODatabaseMetaDataResultSet::mapColumn (sal_Int32 column
)
145 sal_Int32 map
= column
;
147 if (!m_aColMapping
.empty())
149 // Validate column number
150 map
= m_aColMapping
[column
];
155 // -------------------------------------------------------------------------
157 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSet::findColumn( const ::rtl::OUString
& columnName
) throw(SQLException
, RuntimeException
)
160 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
161 ::osl::MutexGuard
aGuard( m_aMutex
);
164 Reference
< XResultSetMetaData
> xMeta
= getMetaData();
165 sal_Int32 nLen
= xMeta
->getColumnCount();
168 if(xMeta
->isCaseSensitive(i
) ? columnName
== xMeta
->getColumnName(i
) :
169 columnName
.equalsIgnoreAsciiCase(xMeta
->getColumnName(i
)))
174 template < typename T
, SQLSMALLINT sqlTypeId
> T
ODatabaseMetaDataResultSet::getInteger ( sal_Int32 columnIndex
)
176 ::cppu::OBroadcastHelper
& rBHelper(ODatabaseMetaDataResultSet_BASE::rBHelper
);
177 checkDisposed(rBHelper
.bDisposed
);
178 ::osl::MutexGuard
aGuard( m_aMutex
);
180 columnIndex
= mapColumn(columnIndex
);
182 if(columnIndex
<= m_nDriverColumnCount
)
184 getValue
<T
>(m_pConnection
, m_aStatementHandle
, columnIndex
, sqlTypeId
, m_bWasNull
, **this, nVal
);
186 if ( !m_aValueRange
.empty() )
188 ::std::map
<sal_Int32
, ::connectivity::TInt2IntMap
>::iterator
aValueRangeIter (m_aValueRange
.find(columnIndex
));
189 if ( aValueRangeIter
!= m_aValueRange
.end() )
190 return static_cast<T
>(aValueRangeIter
->second
[nVal
]);
194 m_bWasNull
= sal_True
;
198 // -------------------------------------------------------------------------
199 Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
ODatabaseMetaDataResultSet::getBinaryStream( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
201 ::dbtools::throwFunctionNotSupportedException( "XRow::getBinaryStream", *this );
204 // -------------------------------------------------------------------------
205 Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
ODatabaseMetaDataResultSet::getCharacterStream( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
207 ::dbtools::throwFunctionNotSupportedException( "XRow::getCharacterStream", *this );
211 // -------------------------------------------------------------------------
212 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::getBoolean( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
215 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
216 ::osl::MutexGuard
aGuard( m_aMutex
);
218 columnIndex
= mapColumn(columnIndex
);
220 sal_Bool bRet
= sal_False
;
221 if(columnIndex
<= m_nDriverColumnCount
)
223 sal_Int32 nType
= getMetaData()->getColumnType(columnIndex
);
229 OTools::getValue(m_pConnection
,m_aStatementHandle
,columnIndex
,SQL_C_BIT
,m_bWasNull
,**this,&nValue
,sizeof nValue
);
234 bRet
= getInt(columnIndex
) != 0;
239 // -------------------------------------------------------------------------
241 sal_Int8 SAL_CALL
ODatabaseMetaDataResultSet::getByte( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
243 return getInteger
<sal_Int8
, SQL_C_STINYINT
>( columnIndex
);
245 // -------------------------------------------------------------------------
247 Sequence
< sal_Int8
> SAL_CALL
ODatabaseMetaDataResultSet::getBytes( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
250 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
251 ::osl::MutexGuard
aGuard( m_aMutex
);
254 columnIndex
= mapColumn(columnIndex
);
255 if(columnIndex
<= m_nDriverColumnCount
)
257 sal_Int32 nType
= getMetaData()->getColumnType(columnIndex
);
260 case DataType::VARCHAR
:
261 case DataType::LONGVARCHAR
:
263 ::rtl::OUString aRet
= OTools::getStringValue(m_pConnection
,m_aStatementHandle
,columnIndex
,SQL_C_BINARY
,m_bWasNull
,**this,m_nTextEncoding
);
264 return Sequence
<sal_Int8
>(reinterpret_cast<const sal_Int8
*>(aRet
.getStr()),sizeof(sal_Unicode
)*aRet
.getLength());
267 return OTools::getBytesValue(m_pConnection
,m_aStatementHandle
,columnIndex
,SQL_C_BINARY
,m_bWasNull
,**this);
270 m_bWasNull
= sal_True
;
271 return Sequence
<sal_Int8
>();
273 // -------------------------------------------------------------------------
275 ::com::sun::star::util::Date SAL_CALL
ODatabaseMetaDataResultSet::getDate( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
277 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
278 ::osl::MutexGuard
aGuard( m_aMutex
);
281 columnIndex
= mapColumn(columnIndex
);
282 if(columnIndex
<= m_nDriverColumnCount
)
288 OTools::getValue(m_pConnection
,m_aStatementHandle
,columnIndex
,m_pConnection
->useOldDateFormat() ? SQL_C_DATE
: SQL_C_TYPE_DATE
,m_bWasNull
,**this,&aDate
,sizeof aDate
);
289 return Date(aDate
.day
,aDate
.month
,aDate
.year
);
292 m_bWasNull
= sal_True
;
295 // -------------------------------------------------------------------------
297 double SAL_CALL
ODatabaseMetaDataResultSet::getDouble( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
300 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
301 ::osl::MutexGuard
aGuard( m_aMutex
);
304 columnIndex
= mapColumn(columnIndex
);
306 if(columnIndex
<= m_nDriverColumnCount
)
307 OTools::getValue(m_pConnection
,m_aStatementHandle
,columnIndex
,SQL_C_DOUBLE
,m_bWasNull
,**this,&nValue
,sizeof nValue
);
309 m_bWasNull
= sal_True
;
312 // -------------------------------------------------------------------------
314 float SAL_CALL
ODatabaseMetaDataResultSet::getFloat( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
317 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
318 ::osl::MutexGuard
aGuard( m_aMutex
);
321 columnIndex
= mapColumn(columnIndex
);
323 if(columnIndex
<= m_nDriverColumnCount
)
324 OTools::getValue(m_pConnection
,m_aStatementHandle
,columnIndex
,SQL_C_FLOAT
,m_bWasNull
,**this,&nVal
,sizeof nVal
);
326 m_bWasNull
= sal_True
;
329 // -------------------------------------------------------------------------
331 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSet::getInt( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
333 return getInteger
<sal_Int32
, SQL_C_SLONG
>( columnIndex
);
335 // -------------------------------------------------------------------------
337 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSet::getRow( ) throw(SQLException
, RuntimeException
)
341 // -------------------------------------------------------------------------
343 sal_Int64 SAL_CALL
ODatabaseMetaDataResultSet::getLong( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
345 return getInteger
<sal_Int64
, SQL_C_SBIGINT
>( columnIndex
);
347 // -------------------------------------------------------------------------
349 Reference
< XResultSetMetaData
> SAL_CALL
ODatabaseMetaDataResultSet::getMetaData( ) throw(SQLException
, RuntimeException
)
351 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
352 ::osl::MutexGuard
aGuard( m_aMutex
);
353 return m_xMetaData
.is() ? m_xMetaData
: (m_xMetaData
= new OResultSetMetaData(m_pConnection
,m_aStatementHandle
));
355 // -------------------------------------------------------------------------
356 Reference
< XArray
> SAL_CALL
ODatabaseMetaDataResultSet::getArray( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
358 ::dbtools::throwFunctionNotSupportedException( "XRow::getArray", *this );
361 // -------------------------------------------------------------------------
362 Reference
< XClob
> SAL_CALL
ODatabaseMetaDataResultSet::getClob( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
364 ::dbtools::throwFunctionNotSupportedException( "XRow::getClob", *this );
367 // -------------------------------------------------------------------------
368 Reference
< XBlob
> SAL_CALL
ODatabaseMetaDataResultSet::getBlob( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
370 ::dbtools::throwFunctionNotSupportedException( "XRow::getBlob", *this );
373 // -------------------------------------------------------------------------
375 Reference
< XRef
> SAL_CALL
ODatabaseMetaDataResultSet::getRef( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
377 ::dbtools::throwFunctionNotSupportedException( "XRow::getRef", *this );
380 // -------------------------------------------------------------------------
382 Any SAL_CALL
ODatabaseMetaDataResultSet::getObject( sal_Int32
/*columnIndex*/, const Reference
< ::com::sun::star::container::XNameAccess
>& /*typeMap*/ ) throw(SQLException
, RuntimeException
)
384 ::dbtools::throwFunctionNotSupportedException( "XRow::getObject", *this );
387 // -------------------------------------------------------------------------
389 sal_Int16 SAL_CALL
ODatabaseMetaDataResultSet::getShort( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
391 return getInteger
<sal_Int16
, SQL_C_SSHORT
>( columnIndex
);
393 // -------------------------------------------------------------------------
395 ::rtl::OUString SAL_CALL
ODatabaseMetaDataResultSet::getString( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
398 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
399 ::osl::MutexGuard
aGuard( m_aMutex
);
402 columnIndex
= mapColumn(columnIndex
);
403 ::rtl::OUString aVal
;
404 if(columnIndex
<= m_nDriverColumnCount
)
405 aVal
= OTools::getStringValue(m_pConnection
,m_aStatementHandle
,columnIndex
,impl_getColumnType_nothrow(columnIndex
),m_bWasNull
,**this,m_nTextEncoding
);
407 m_bWasNull
= sal_True
;
412 // -------------------------------------------------------------------------
415 ::com::sun::star::util::Time SAL_CALL
ODatabaseMetaDataResultSet::getTime( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
418 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
419 ::osl::MutexGuard
aGuard( m_aMutex
);
422 columnIndex
= mapColumn(columnIndex
);
423 TIME_STRUCT aTime
={0,0,0};
424 if(columnIndex
<= m_nDriverColumnCount
)
425 OTools::getValue(m_pConnection
,m_aStatementHandle
,columnIndex
,m_pConnection
->useOldDateFormat() ? SQL_C_TIME
: SQL_C_TYPE_TIME
,m_bWasNull
,**this,&aTime
,sizeof aTime
);
427 m_bWasNull
= sal_True
;
428 return Time(0,aTime
.second
,aTime
.minute
,aTime
.hour
);
430 // -------------------------------------------------------------------------
433 ::com::sun::star::util::DateTime SAL_CALL
ODatabaseMetaDataResultSet::getTimestamp( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
436 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
437 ::osl::MutexGuard
aGuard( m_aMutex
);
440 columnIndex
= mapColumn(columnIndex
);
441 TIMESTAMP_STRUCT aTime
={0,0,0,0,0,0,0};
442 if(columnIndex
<= m_nDriverColumnCount
)
443 OTools::getValue(m_pConnection
,m_aStatementHandle
,columnIndex
,m_pConnection
->useOldDateFormat() ? SQL_C_TIMESTAMP
: SQL_C_TYPE_TIMESTAMP
,m_bWasNull
,**this,&aTime
,sizeof aTime
);
445 m_bWasNull
= sal_True
;
446 return DateTime((sal_uInt16
)aTime
.fraction
/ODBC_FRACTION_UNITS_PER_HSECOND
,aTime
.second
,aTime
.minute
,aTime
.hour
,aTime
.day
,aTime
.month
,aTime
.year
);
448 // -------------------------------------------------------------------------
450 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::isAfterLast( ) throw(SQLException
, RuntimeException
)
453 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
454 ::osl::MutexGuard
aGuard( m_aMutex
);
457 return m_nCurrentFetchState
== SQL_NO_DATA
;
459 // -------------------------------------------------------------------------
460 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::isFirst( ) throw(SQLException
, RuntimeException
)
463 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
464 ::osl::MutexGuard
aGuard( m_aMutex
);
467 return m_nRowPos
== 1;
469 // -------------------------------------------------------------------------
470 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::isLast( ) throw(SQLException
, RuntimeException
)
473 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
474 ::osl::MutexGuard
aGuard( m_aMutex
);
477 return m_bEOF
&& m_nCurrentFetchState
!= SQL_NO_DATA
;
479 // -------------------------------------------------------------------------
480 void SAL_CALL
ODatabaseMetaDataResultSet::beforeFirst( ) throw(SQLException
, RuntimeException
)
483 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
484 ::osl::MutexGuard
aGuard( m_aMutex
);
489 m_nCurrentFetchState
= SQL_SUCCESS
;
491 // -------------------------------------------------------------------------
492 void SAL_CALL
ODatabaseMetaDataResultSet::afterLast( ) throw(SQLException
, RuntimeException
)
495 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
496 ::osl::MutexGuard
aGuard( m_aMutex
);
502 // -------------------------------------------------------------------------
504 void SAL_CALL
ODatabaseMetaDataResultSet::close( ) throw(SQLException
, RuntimeException
)
508 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
509 ::osl::MutexGuard
aGuard( m_aMutex
);
514 // -------------------------------------------------------------------------
516 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::first( ) throw(SQLException
, RuntimeException
)
519 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
520 ::osl::MutexGuard
aGuard( m_aMutex
);
524 m_nCurrentFetchState
= N3SQLFetchScroll(m_aStatementHandle
,SQL_FETCH_FIRST
,0);
525 OTools::ThrowException(m_pConnection
,m_nCurrentFetchState
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
526 sal_Bool bRet
= ( m_nCurrentFetchState
== SQL_SUCCESS
|| m_nCurrentFetchState
== SQL_SUCCESS_WITH_INFO
);
531 // -------------------------------------------------------------------------
533 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::last( ) throw(SQLException
, RuntimeException
)
535 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
536 ::osl::MutexGuard
aGuard( m_aMutex
);
539 m_nCurrentFetchState
= N3SQLFetchScroll(m_aStatementHandle
,SQL_FETCH_LAST
,0);
540 OTools::ThrowException(m_pConnection
,m_nCurrentFetchState
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
541 // here I know definitely that I stand on the last record
542 sal_Bool bRet
= ( m_nCurrentFetchState
== SQL_SUCCESS
|| m_nCurrentFetchState
== SQL_SUCCESS_WITH_INFO
);
547 // -------------------------------------------------------------------------
548 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::absolute( sal_Int32 row
) throw(SQLException
, RuntimeException
)
551 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
552 ::osl::MutexGuard
aGuard( m_aMutex
);
556 m_nCurrentFetchState
= N3SQLFetchScroll(m_aStatementHandle
,SQL_FETCH_ABSOLUTE
,row
);
557 OTools::ThrowException(m_pConnection
,m_nCurrentFetchState
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
558 sal_Bool bRet
= m_nCurrentFetchState
== SQL_SUCCESS
|| m_nCurrentFetchState
== SQL_SUCCESS_WITH_INFO
;
563 // -------------------------------------------------------------------------
564 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::relative( sal_Int32 row
) throw(SQLException
, RuntimeException
)
567 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
568 ::osl::MutexGuard
aGuard( m_aMutex
);
572 m_nCurrentFetchState
= N3SQLFetchScroll(m_aStatementHandle
,SQL_FETCH_RELATIVE
,row
);
573 OTools::ThrowException(m_pConnection
,m_nCurrentFetchState
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
574 sal_Bool bRet
= m_nCurrentFetchState
== SQL_SUCCESS
|| m_nCurrentFetchState
== SQL_SUCCESS_WITH_INFO
;
579 // -------------------------------------------------------------------------
580 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::previous( ) throw(SQLException
, RuntimeException
)
583 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
584 ::osl::MutexGuard
aGuard( m_aMutex
);
588 m_nCurrentFetchState
= N3SQLFetchScroll(m_aStatementHandle
,SQL_FETCH_PRIOR
,0);
589 OTools::ThrowException(m_pConnection
,m_nCurrentFetchState
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
590 sal_Bool bRet
= m_nCurrentFetchState
== SQL_SUCCESS
|| m_nCurrentFetchState
== SQL_SUCCESS_WITH_INFO
;
593 else if ( m_nCurrentFetchState
== SQL_NO_DATA
)
597 // -------------------------------------------------------------------------
598 Reference
< XInterface
> SAL_CALL
ODatabaseMetaDataResultSet::getStatement( ) throw(SQLException
, RuntimeException
)
602 // -------------------------------------------------------------------------
604 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::rowDeleted( ) throw(SQLException
, RuntimeException
)
607 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
608 ::osl::MutexGuard
aGuard( m_aMutex
);
611 return m_pRowStatusArray
[0] == SQL_ROW_DELETED
;
613 // -------------------------------------------------------------------------
614 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::rowInserted( ) throw(SQLException
, RuntimeException
)
616 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
617 ::osl::MutexGuard
aGuard( m_aMutex
);
620 return m_pRowStatusArray
[0] == SQL_ROW_ADDED
;
622 // -------------------------------------------------------------------------
623 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::rowUpdated( ) throw(SQLException
, RuntimeException
)
626 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
627 ::osl::MutexGuard
aGuard( m_aMutex
);
630 return m_pRowStatusArray
[0] == SQL_ROW_UPDATED
;
632 // -------------------------------------------------------------------------
634 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::isBeforeFirst( ) throw(SQLException
, RuntimeException
)
637 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
638 ::osl::MutexGuard
aGuard( m_aMutex
);
641 return m_nRowPos
== 0;
643 // -------------------------------------------------------------------------
645 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::next( ) throw(SQLException
, RuntimeException
)
648 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
649 ::osl::MutexGuard
aGuard( m_aMutex
);
653 SQLRETURN nOldFetchStatus
= m_nCurrentFetchState
;
654 // m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_NEXT,0);
655 m_nCurrentFetchState
= N3SQLFetch(m_aStatementHandle
);
656 OTools::ThrowException(m_pConnection
,m_nCurrentFetchState
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
657 sal_Bool bRet
= m_nCurrentFetchState
== SQL_SUCCESS
|| m_nCurrentFetchState
== SQL_SUCCESS_WITH_INFO
;
658 if(bRet
|| ( m_nCurrentFetchState
== SQL_NO_DATA
&& nOldFetchStatus
!= SQL_NO_DATA
) )
662 // -------------------------------------------------------------------------
664 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::wasNull( ) throw(SQLException
, RuntimeException
)
667 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
668 ::osl::MutexGuard
aGuard( m_aMutex
);
673 // -------------------------------------------------------------------------
674 void SAL_CALL
ODatabaseMetaDataResultSet::refreshRow( ) throw(SQLException
, RuntimeException
)
677 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
678 ::osl::MutexGuard
aGuard( m_aMutex
);
681 // -------------------------------------------------------------------------
683 void SAL_CALL
ODatabaseMetaDataResultSet::cancel( ) throw(RuntimeException
)
686 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
687 ::osl::MutexGuard
aGuard( m_aMutex
);
690 OTools::ThrowException(m_pConnection
,N3SQLCancel(m_aStatementHandle
),m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
692 // -------------------------------------------------------------------------
693 void SAL_CALL
ODatabaseMetaDataResultSet::clearWarnings( ) throw(SQLException
, RuntimeException
)
696 // -------------------------------------------------------------------------
697 Any SAL_CALL
ODatabaseMetaDataResultSet::getWarnings( ) throw(SQLException
, RuntimeException
)
701 //------------------------------------------------------------------------------
702 sal_Int32
ODatabaseMetaDataResultSet::getResultSetConcurrency() const throw(SQLException
, RuntimeException
)
704 return ResultSetConcurrency::READ_ONLY
;
706 //------------------------------------------------------------------------------
707 sal_Int32
ODatabaseMetaDataResultSet::getResultSetType() const throw(SQLException
, RuntimeException
)
709 return ResultSetType::FORWARD_ONLY
;
711 //------------------------------------------------------------------------------
712 sal_Int32
ODatabaseMetaDataResultSet::getFetchDirection() const throw(SQLException
, RuntimeException
)
714 return FetchDirection::FORWARD
;
716 //------------------------------------------------------------------------------
717 sal_Int32
ODatabaseMetaDataResultSet::getFetchSize() const throw(SQLException
, RuntimeException
)
722 //------------------------------------------------------------------------------
723 ::rtl::OUString
ODatabaseMetaDataResultSet::getCursorName() const throw(SQLException
, RuntimeException
)
725 return ::rtl::OUString();
728 // -------------------------------------------------------------------------
729 ::cppu::IPropertyArrayHelper
* ODatabaseMetaDataResultSet::createArrayHelper( ) const
732 Sequence
< com::sun::star::beans::Property
> aProps(5);
733 com::sun::star::beans::Property
* pProperties
= aProps
.getArray();
735 DECL_PROP0(CURSORNAME
, ::rtl::OUString
);
736 DECL_PROP0(FETCHDIRECTION
, sal_Int32
);
737 DECL_PROP0(FETCHSIZE
, sal_Int32
);
738 DECL_PROP0(RESULTSETCONCURRENCY
,sal_Int32
);
739 DECL_PROP0(RESULTSETTYPE
, sal_Int32
);
741 return new ::cppu::OPropertyArrayHelper(aProps
);
743 // -------------------------------------------------------------------------
744 ::cppu::IPropertyArrayHelper
& ODatabaseMetaDataResultSet::getInfoHelper()
746 return *const_cast<ODatabaseMetaDataResultSet
*>(this)->getArrayHelper();
748 // -------------------------------------------------------------------------
749 sal_Bool
ODatabaseMetaDataResultSet::convertFastPropertyValue(
750 Any
& rConvertedValue
,
754 throw (::com::sun::star::lang::IllegalArgumentException
)
758 case PROPERTY_ID_CURSORNAME
:
759 case PROPERTY_ID_RESULTSETCONCURRENCY
:
760 case PROPERTY_ID_RESULTSETTYPE
:
761 throw ::com::sun::star::lang::IllegalArgumentException();
762 case PROPERTY_ID_FETCHDIRECTION
:
763 return ::comphelper::tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, getFetchDirection());
764 case PROPERTY_ID_FETCHSIZE
:
765 return ::comphelper::tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, getFetchSize());
771 // -------------------------------------------------------------------------
772 void ODatabaseMetaDataResultSet::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
, const Any
& /*rValue*/ ) throw (Exception
)
776 case PROPERTY_ID_CURSORNAME
:
777 case PROPERTY_ID_RESULTSETCONCURRENCY
:
778 case PROPERTY_ID_RESULTSETTYPE
:
779 case PROPERTY_ID_FETCHDIRECTION
:
780 case PROPERTY_ID_FETCHSIZE
:
783 OSL_FAIL("setFastPropertyValue_NoBroadcast: Illegal handle value!");
786 // -------------------------------------------------------------------------
787 void ODatabaseMetaDataResultSet::getFastPropertyValue( Any
& rValue
, sal_Int32 nHandle
) const
791 case PROPERTY_ID_CURSORNAME
:
792 rValue
<<= getCursorName();
794 case PROPERTY_ID_RESULTSETCONCURRENCY
:
795 rValue
<<= getResultSetConcurrency();
797 case PROPERTY_ID_RESULTSETTYPE
:
798 rValue
<<= getResultSetType();
800 case PROPERTY_ID_FETCHDIRECTION
:
801 rValue
<<= getFetchDirection();
803 case PROPERTY_ID_FETCHSIZE
:
804 rValue
<<= getFetchSize();
808 // -------------------------------------------------------------------------
809 void ODatabaseMetaDataResultSet::openTypeInfo() throw(SQLException
, RuntimeException
)
812 aMap
[SQL_BIT
] = DataType::BIT
;
813 aMap
[SQL_TINYINT
] = DataType::TINYINT
;
814 aMap
[SQL_SMALLINT
] = DataType::SMALLINT
;
815 aMap
[SQL_INTEGER
] = DataType::INTEGER
;
816 aMap
[SQL_FLOAT
] = DataType::FLOAT
;
817 aMap
[SQL_REAL
] = DataType::REAL
;
818 aMap
[SQL_DOUBLE
] = DataType::DOUBLE
;
819 aMap
[SQL_BIGINT
] = DataType::BIGINT
;
821 aMap
[SQL_CHAR
] = DataType::CHAR
;
822 aMap
[SQL_WCHAR
] = DataType::CHAR
;
823 aMap
[SQL_VARCHAR
] = DataType::VARCHAR
;
824 aMap
[SQL_WVARCHAR
] = DataType::VARCHAR
;
825 aMap
[SQL_LONGVARCHAR
] = DataType::LONGVARCHAR
;
826 aMap
[SQL_WLONGVARCHAR
] = DataType::LONGVARCHAR
;
828 aMap
[SQL_TYPE_DATE
] = DataType::DATE
;
829 aMap
[SQL_DATE
] = DataType::DATE
;
830 aMap
[SQL_TYPE_TIME
] = DataType::TIME
;
831 aMap
[SQL_TIME
] = DataType::TIME
;
832 aMap
[SQL_TYPE_TIMESTAMP
] = DataType::TIMESTAMP
;
833 aMap
[SQL_TIMESTAMP
] = DataType::TIMESTAMP
;
835 aMap
[SQL_DECIMAL
] = DataType::DECIMAL
;
836 aMap
[SQL_NUMERIC
] = DataType::NUMERIC
;
838 aMap
[SQL_BINARY
] = DataType::BINARY
;
839 aMap
[SQL_VARBINARY
] = DataType::VARBINARY
;
840 aMap
[SQL_LONGVARBINARY
] = DataType::LONGVARBINARY
;
842 aMap
[SQL_GUID
] = DataType::VARBINARY
;
845 m_aValueRange
[2] = aMap
;
847 OTools::ThrowException(m_pConnection
,N3SQLGetTypeInfo(m_aStatementHandle
, SQL_ALL_TYPES
),m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
850 //-----------------------------------------------------------------------------
851 void ODatabaseMetaDataResultSet::openTables(const Any
& catalog
, const ::rtl::OUString
& schemaPattern
,
852 const ::rtl::OUString
& tableNamePattern
,
853 const Sequence
< ::rtl::OUString
>& types
) throw(SQLException
, RuntimeException
)
855 m_bFreeHandle
= sal_True
;
856 ::rtl::OString aPKQ
,aPKO
,aPKN
,aCOL
;
857 const ::rtl::OUString
*pSchemaPat
= NULL
;
859 if(schemaPattern
.toChar() != '%')
860 pSchemaPat
= &schemaPattern
;
864 if ( catalog
.hasValue() )
865 aPKQ
= ::rtl::OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
866 aPKO
= ::rtl::OUStringToOString(schemaPattern
,m_nTextEncoding
);
867 aPKN
= ::rtl::OUStringToOString(tableNamePattern
,m_nTextEncoding
);
869 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
870 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() ? aPKO
.getStr() : NULL
,
871 *pPKN
= aPKN
.getStr();
874 const char *pCOL
= NULL
;
875 const char* pComma
= ",";
876 const ::rtl::OUString
* pBegin
= types
.getConstArray();
877 const ::rtl::OUString
* pEnd
= pBegin
+ types
.getLength();
878 for(;pBegin
!= pEnd
;++pBegin
)
880 aCOL
+= ::rtl::OUStringToOString(*pBegin
,m_nTextEncoding
);
883 if ( !aCOL
.isEmpty() )
885 aCOL
= aCOL
.replaceAt(aCOL
.getLength()-1,1,pComma
);
886 pCOL
= aCOL
.getStr();
889 pCOL
= SQL_ALL_TABLE_TYPES
;
891 SQLRETURN nRetcode
= N3SQLTables(m_aStatementHandle
,
892 (SDB_ODBC_CHAR
*) pPKQ
, (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
893 (SDB_ODBC_CHAR
*) pPKO
, pPKO
? SQL_NTS
: 0,
894 (SDB_ODBC_CHAR
*) pPKN
, SQL_NTS
,
895 (SDB_ODBC_CHAR
*) pCOL
, pCOL
? SQL_NTS
: 0);
896 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
900 //-----------------------------------------------------------------------------
901 void ODatabaseMetaDataResultSet::openTablesTypes( ) throw(SQLException
, RuntimeException
)
903 m_bFreeHandle
= sal_True
;
904 SQLRETURN nRetcode
= N3SQLTables(m_aStatementHandle
,
908 (SDB_ODBC_CHAR
*) SQL_ALL_TABLE_TYPES
,SQL_NTS
);
909 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
911 m_aColMapping
.clear();
912 m_aColMapping
.push_back(-1);
913 m_aColMapping
.push_back(4);
914 m_xMetaData
= new OResultSetMetaData(m_pConnection
,m_aStatementHandle
,m_aColMapping
);
917 // -------------------------------------------------------------------------
918 void ODatabaseMetaDataResultSet::openCatalogs() throw(SQLException
, RuntimeException
)
920 m_bFreeHandle
= sal_True
;
921 SQLRETURN nRetcode
= N3SQLTables(m_aStatementHandle
,
922 (SDB_ODBC_CHAR
*) SQL_ALL_CATALOGS
,SQL_NTS
,
923 (SDB_ODBC_CHAR
*) "",SQL_NTS
,
924 (SDB_ODBC_CHAR
*) "",SQL_NTS
,
925 (SDB_ODBC_CHAR
*) "",SQL_NTS
);
927 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
929 m_aColMapping
.clear();
930 m_aColMapping
.push_back(-1);
931 m_aColMapping
.push_back(1);
932 m_xMetaData
= new OResultSetMetaData(m_pConnection
,m_aStatementHandle
,m_aColMapping
);
935 // -------------------------------------------------------------------------
936 void ODatabaseMetaDataResultSet::openSchemas() throw(SQLException
, RuntimeException
)
938 m_bFreeHandle
= sal_True
;
939 SQLRETURN nRetcode
= N3SQLTables(m_aStatementHandle
,
940 (SDB_ODBC_CHAR
*) "",SQL_NTS
,
941 (SDB_ODBC_CHAR
*) SQL_ALL_SCHEMAS
,SQL_NTS
,
942 (SDB_ODBC_CHAR
*) "",SQL_NTS
,
943 (SDB_ODBC_CHAR
*) "",SQL_NTS
);
944 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
946 m_aColMapping
.clear();
947 m_aColMapping
.push_back(-1);
948 m_aColMapping
.push_back(2);
949 m_xMetaData
= new OResultSetMetaData(m_pConnection
,m_aStatementHandle
,m_aColMapping
);
952 // -------------------------------------------------------------------------
953 void ODatabaseMetaDataResultSet::openColumnPrivileges( const Any
& catalog
, const ::rtl::OUString
& schema
,
954 const ::rtl::OUString
& table
, const ::rtl::OUString
& columnNamePattern
)
955 throw(SQLException
, RuntimeException
)
957 const ::rtl::OUString
*pSchemaPat
= NULL
;
959 if(schema
.toChar() != '%')
960 pSchemaPat
= &schema
;
964 m_bFreeHandle
= sal_True
;
965 ::rtl::OString aPKQ
,aPKO
,aPKN
,aCOL
;
967 if ( catalog
.hasValue() )
968 aPKQ
= ::rtl::OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
969 aPKO
= ::rtl::OUStringToOString(schema
,m_nTextEncoding
);
970 aPKN
= ::rtl::OUStringToOString(table
,m_nTextEncoding
);
971 aCOL
= ::rtl::OUStringToOString(columnNamePattern
,m_nTextEncoding
);
973 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
974 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() ? aPKO
.getStr() : NULL
,
975 *pPKN
= aPKN
.getStr(),
976 *pCOL
= aCOL
.getStr();
979 SQLRETURN nRetcode
= N3SQLColumnPrivileges(m_aStatementHandle
,
980 (SDB_ODBC_CHAR
*) pPKQ
, (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
981 (SDB_ODBC_CHAR
*) pPKO
, pPKO
? SQL_NTS
: 0 ,
982 (SDB_ODBC_CHAR
*) pPKN
, SQL_NTS
,
983 (SDB_ODBC_CHAR
*) pCOL
, SQL_NTS
);
984 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
988 // -------------------------------------------------------------------------
989 void ODatabaseMetaDataResultSet::openColumns( const Any
& catalog
, const ::rtl::OUString
& schemaPattern
,
990 const ::rtl::OUString
& tableNamePattern
, const ::rtl::OUString
& columnNamePattern
)
991 throw(SQLException
, RuntimeException
)
993 const ::rtl::OUString
*pSchemaPat
= NULL
;
995 if(schemaPattern
.toChar() != '%')
996 pSchemaPat
= &schemaPattern
;
1000 m_bFreeHandle
= sal_True
;
1001 ::rtl::OString aPKQ
,aPKO
,aPKN
,aCOL
;
1002 if ( catalog
.hasValue() )
1003 aPKQ
= ::rtl::OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
1004 aPKO
= ::rtl::OUStringToOString(schemaPattern
,m_nTextEncoding
);
1005 aPKN
= ::rtl::OUStringToOString(tableNamePattern
,m_nTextEncoding
);
1006 aCOL
= ::rtl::OUStringToOString(columnNamePattern
,m_nTextEncoding
);
1008 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
1009 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() && !pSchemaPat
->isEmpty() ? aPKO
.getStr() : NULL
,
1010 *pPKN
= aPKN
.getStr(),
1011 *pCOL
= aCOL
.getStr();
1014 SQLRETURN nRetcode
= N3SQLColumns(m_aStatementHandle
,
1015 (SDB_ODBC_CHAR
*) pPKQ
, (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
1016 (SDB_ODBC_CHAR
*) pPKO
, pPKO
? SQL_NTS
: 0,
1017 (SDB_ODBC_CHAR
*) pPKN
, SQL_NTS
,
1018 (SDB_ODBC_CHAR
*) pCOL
, SQL_NTS
);
1020 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1022 aMap
[SQL_BIT
] = DataType::BIT
;
1023 aMap
[SQL_TINYINT
] = DataType::TINYINT
;
1024 aMap
[SQL_SMALLINT
] = DataType::SMALLINT
;
1025 aMap
[SQL_INTEGER
] = DataType::INTEGER
;
1026 aMap
[SQL_FLOAT
] = DataType::FLOAT
;
1027 aMap
[SQL_REAL
] = DataType::REAL
;
1028 aMap
[SQL_DOUBLE
] = DataType::DOUBLE
;
1029 aMap
[SQL_BIGINT
] = DataType::BIGINT
;
1031 aMap
[SQL_CHAR
] = DataType::CHAR
;
1032 aMap
[SQL_WCHAR
] = DataType::CHAR
;
1033 aMap
[SQL_VARCHAR
] = DataType::VARCHAR
;
1034 aMap
[SQL_WVARCHAR
] = DataType::VARCHAR
;
1035 aMap
[SQL_LONGVARCHAR
] = DataType::LONGVARCHAR
;
1036 aMap
[SQL_WLONGVARCHAR
] = DataType::LONGVARCHAR
;
1038 aMap
[SQL_TYPE_DATE
] = DataType::DATE
;
1039 aMap
[SQL_DATE
] = DataType::DATE
;
1040 aMap
[SQL_TYPE_TIME
] = DataType::TIME
;
1041 aMap
[SQL_TIME
] = DataType::TIME
;
1042 aMap
[SQL_TYPE_TIMESTAMP
] = DataType::TIMESTAMP
;
1043 aMap
[SQL_TIMESTAMP
] = DataType::TIMESTAMP
;
1045 aMap
[SQL_DECIMAL
] = DataType::DECIMAL
;
1046 aMap
[SQL_NUMERIC
] = DataType::NUMERIC
;
1048 aMap
[SQL_BINARY
] = DataType::BINARY
;
1049 aMap
[SQL_VARBINARY
] = DataType::VARBINARY
;
1050 aMap
[SQL_LONGVARBINARY
] = DataType::LONGVARBINARY
;
1052 aMap
[SQL_GUID
] = DataType::VARBINARY
;
1054 m_aValueRange
[5] = aMap
;
1057 // -------------------------------------------------------------------------
1058 void ODatabaseMetaDataResultSet::openProcedureColumns( const Any
& catalog
, const ::rtl::OUString
& schemaPattern
,
1059 const ::rtl::OUString
& procedureNamePattern
,const ::rtl::OUString
& columnNamePattern
)
1060 throw(SQLException
, RuntimeException
)
1062 const ::rtl::OUString
*pSchemaPat
= NULL
;
1064 if(schemaPattern
.toChar() != '%')
1065 pSchemaPat
= &schemaPattern
;
1069 m_bFreeHandle
= sal_True
;
1070 ::rtl::OString aPKQ
,aPKO
,aPKN
,aCOL
;
1071 if ( catalog
.hasValue() )
1072 aPKQ
= ::rtl::OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
1073 aPKO
= ::rtl::OUStringToOString(schemaPattern
,m_nTextEncoding
);
1074 aPKN
= ::rtl::OUStringToOString(procedureNamePattern
,m_nTextEncoding
);
1075 aCOL
= ::rtl::OUStringToOString(columnNamePattern
,m_nTextEncoding
);
1077 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
1078 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() ? aPKO
.getStr() : NULL
,
1079 *pPKN
= aPKN
.getStr(),
1080 *pCOL
= aCOL
.getStr();
1083 SQLRETURN nRetcode
= N3SQLProcedureColumns(m_aStatementHandle
,
1084 (SDB_ODBC_CHAR
*) pPKQ
, (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
1085 (SDB_ODBC_CHAR
*) pPKO
, pPKO
? SQL_NTS
: 0 ,
1086 (SDB_ODBC_CHAR
*) pPKN
, SQL_NTS
,
1087 (SDB_ODBC_CHAR
*) pCOL
, SQL_NTS
);
1089 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1092 // -------------------------------------------------------------------------
1093 void ODatabaseMetaDataResultSet::openProcedures(const Any
& catalog
, const ::rtl::OUString
& schemaPattern
,
1094 const ::rtl::OUString
& procedureNamePattern
)
1095 throw(SQLException
, RuntimeException
)
1097 const ::rtl::OUString
*pSchemaPat
= NULL
;
1099 if(schemaPattern
.toChar() != '%')
1100 pSchemaPat
= &schemaPattern
;
1104 m_bFreeHandle
= sal_True
;
1105 ::rtl::OString aPKQ
,aPKO
,aPKN
,aCOL
;
1107 if ( catalog
.hasValue() )
1108 aPKQ
= ::rtl::OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
1109 aPKO
= ::rtl::OUStringToOString(schemaPattern
,m_nTextEncoding
);
1110 aPKN
= ::rtl::OUStringToOString(procedureNamePattern
,m_nTextEncoding
);
1112 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
1113 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() ? aPKO
.getStr() : NULL
,
1114 *pPKN
= aPKN
.getStr();
1117 SQLRETURN nRetcode
= N3SQLProcedures(m_aStatementHandle
,
1118 (SDB_ODBC_CHAR
*) pPKQ
, (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
1119 (SDB_ODBC_CHAR
*) pPKO
, pPKO
? SQL_NTS
: 0 ,
1120 (SDB_ODBC_CHAR
*) pPKN
, SQL_NTS
);
1121 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1124 // -------------------------------------------------------------------------
1125 void ODatabaseMetaDataResultSet::openSpecialColumns(sal_Bool _bRowVer
,const Any
& catalog
, const ::rtl::OUString
& schema
,
1126 const ::rtl::OUString
& table
,sal_Int32 scope
, sal_Bool nullable
)
1127 throw(SQLException
, RuntimeException
)
1129 // Some ODBC drivers really don't like getting an empty string as tableName
1130 // E.g. psqlodbc up to at least version 09.01.0100 segfaults
1131 if (table
.isEmpty())
1133 const char errMsg
[] = "ODBC: Trying to get special columns of empty table name";
1134 const char SQLState
[] = "HY009";
1135 throw SQLException( ::rtl::OUString(errMsg
, sizeof(errMsg
) - sizeof(errMsg
[0]), RTL_TEXTENCODING_ASCII_US
),
1137 ::rtl::OUString(SQLState
, sizeof(SQLState
) - sizeof(SQLState
[0]), RTL_TEXTENCODING_ASCII_US
),
1142 const ::rtl::OUString
*pSchemaPat
= NULL
;
1144 if(schema
.toChar() != '%')
1145 pSchemaPat
= &schema
;
1149 m_bFreeHandle
= sal_True
;
1150 ::rtl::OString aPKQ
,aPKO
,aPKN
,aCOL
;
1151 if ( catalog
.hasValue() )
1152 aPKQ
= ::rtl::OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
1153 aPKO
= ::rtl::OUStringToOString(schema
,m_nTextEncoding
);
1154 aPKN
= ::rtl::OUStringToOString(table
,m_nTextEncoding
);
1156 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
1157 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() ? aPKO
.getStr() : NULL
,
1158 *pPKN
= aPKN
.getStr();
1161 SQLRETURN nRetcode
= N3SQLSpecialColumns(m_aStatementHandle
,_bRowVer
? SQL_ROWVER
: SQL_BEST_ROWID
,
1162 (SDB_ODBC_CHAR
*) pPKQ
, (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
1163 (SDB_ODBC_CHAR
*) pPKO
, pPKO
? SQL_NTS
: 0 ,
1164 (SDB_ODBC_CHAR
*) pPKN
, SQL_NTS
,
1166 nullable
? SQL_NULLABLE
: SQL_NO_NULLS
);
1167 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1170 // -------------------------------------------------------------------------
1171 void ODatabaseMetaDataResultSet::openVersionColumns(const Any
& catalog
, const ::rtl::OUString
& schema
,
1172 const ::rtl::OUString
& table
) throw(SQLException
, RuntimeException
)
1174 openSpecialColumns(sal_True
,catalog
,schema
,table
,SQL_SCOPE_TRANSACTION
,sal_False
);
1176 // -------------------------------------------------------------------------
1177 void ODatabaseMetaDataResultSet::openBestRowIdentifier( const Any
& catalog
, const ::rtl::OUString
& schema
,
1178 const ::rtl::OUString
& table
,sal_Int32 scope
,sal_Bool nullable
) throw(SQLException
, RuntimeException
)
1180 openSpecialColumns(sal_False
,catalog
,schema
,table
,scope
,nullable
);
1182 // -------------------------------------------------------------------------
1183 void ODatabaseMetaDataResultSet::openForeignKeys( const Any
& catalog
, const ::rtl::OUString
* schema
,
1184 const ::rtl::OUString
* table
,
1185 const Any
& catalog2
, const ::rtl::OUString
* schema2
,
1186 const ::rtl::OUString
* table2
) throw(SQLException
, RuntimeException
)
1188 m_bFreeHandle
= sal_True
;
1190 ::rtl::OString aPKQ
,aPKO
,aPKN
, aFKQ
, aFKO
, aFKN
;
1191 if ( catalog
.hasValue() )
1192 aPKQ
= ::rtl::OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
1193 if ( catalog2
.hasValue() )
1194 aFKQ
= ::rtl::OUStringToOString(comphelper::getString(catalog2
),m_nTextEncoding
);
1196 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
1197 *pPKO
= schema
&& !schema
->isEmpty() ? ::rtl::OUStringToOString(*schema
,m_nTextEncoding
).getStr() : NULL
,
1198 *pPKN
= table
? (aPKN
= ::rtl::OUStringToOString(*table
,m_nTextEncoding
)).getStr(): NULL
,
1199 *pFKQ
= catalog2
.hasValue() && !aFKQ
.isEmpty() ? aFKQ
.getStr() : NULL
,
1200 *pFKO
= schema2
&& !schema2
->isEmpty() ? (aFKO
= ::rtl::OUStringToOString(*schema2
,m_nTextEncoding
)).getStr() : NULL
,
1201 *pFKN
= table2
? (aFKN
= ::rtl::OUStringToOString(*table2
,m_nTextEncoding
)).getStr() : NULL
;
1204 SQLRETURN nRetcode
= N3SQLForeignKeys(m_aStatementHandle
,
1205 (SDB_ODBC_CHAR
*) pPKQ
, (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
1206 (SDB_ODBC_CHAR
*) pPKO
, pPKO
? SQL_NTS
: 0,
1207 (SDB_ODBC_CHAR
*) pPKN
, pPKN
? SQL_NTS
: 0,
1208 (SDB_ODBC_CHAR
*) pFKQ
, (catalog2
.hasValue() && !aFKQ
.isEmpty()) ? SQL_NTS
: 0,
1209 (SDB_ODBC_CHAR
*) pFKO
, pFKO
? SQL_NTS
: 0,
1210 (SDB_ODBC_CHAR
*) pFKN
, SQL_NTS
1212 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1215 // -------------------------------------------------------------------------
1216 void ODatabaseMetaDataResultSet::openImportedKeys(const Any
& catalog
, const ::rtl::OUString
& schema
,
1217 const ::rtl::OUString
& table
) throw(SQLException
, RuntimeException
)
1220 openForeignKeys(Any(),NULL
,NULL
,catalog
,!schema
.compareToAscii("%") ? &schema
: NULL
,&table
);
1222 // -------------------------------------------------------------------------
1223 void ODatabaseMetaDataResultSet::openExportedKeys(const Any
& catalog
, const ::rtl::OUString
& schema
,
1224 const ::rtl::OUString
& table
) throw(SQLException
, RuntimeException
)
1226 openForeignKeys(catalog
,!schema
.compareToAscii("%") ? &schema
: NULL
,&table
,Any(),NULL
,NULL
);
1228 // -------------------------------------------------------------------------
1229 void ODatabaseMetaDataResultSet::openPrimaryKeys(const Any
& catalog
, const ::rtl::OUString
& schema
,
1230 const ::rtl::OUString
& table
) throw(SQLException
, RuntimeException
)
1232 const ::rtl::OUString
*pSchemaPat
= NULL
;
1234 if(schema
.toChar() != '%')
1235 pSchemaPat
= &schema
;
1239 m_bFreeHandle
= sal_True
;
1240 ::rtl::OString aPKQ
,aPKO
,aPKN
,aCOL
;
1242 if ( catalog
.hasValue() )
1243 aPKQ
= ::rtl::OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
1244 aPKO
= ::rtl::OUStringToOString(schema
,m_nTextEncoding
);
1246 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
1247 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() ? aPKO
.getStr() : NULL
,
1248 *pPKN
= (aPKN
= ::rtl::OUStringToOString(table
,m_nTextEncoding
)).getStr();
1251 SQLRETURN nRetcode
= N3SQLPrimaryKeys(m_aStatementHandle
,
1252 (SDB_ODBC_CHAR
*) pPKQ
, (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
1253 (SDB_ODBC_CHAR
*) pPKO
, pPKO
? SQL_NTS
: 0 ,
1254 (SDB_ODBC_CHAR
*) pPKN
, SQL_NTS
);
1255 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1258 // -------------------------------------------------------------------------
1259 void ODatabaseMetaDataResultSet::openTablePrivileges(const Any
& catalog
, const ::rtl::OUString
& schemaPattern
,
1260 const ::rtl::OUString
& tableNamePattern
) throw(SQLException
, RuntimeException
)
1262 const ::rtl::OUString
*pSchemaPat
= NULL
;
1264 if(schemaPattern
.toChar() != '%')
1265 pSchemaPat
= &schemaPattern
;
1269 m_bFreeHandle
= sal_True
;
1270 ::rtl::OString aPKQ
,aPKO
,aPKN
;
1272 if ( catalog
.hasValue() )
1273 aPKQ
= ::rtl::OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
1274 aPKO
= ::rtl::OUStringToOString(schemaPattern
,m_nTextEncoding
);
1276 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
1277 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() ? aPKO
.getStr() : NULL
,
1278 *pPKN
= (aPKN
= ::rtl::OUStringToOString(tableNamePattern
,m_nTextEncoding
)).getStr();
1281 SQLRETURN nRetcode
= N3SQLTablePrivileges(m_aStatementHandle
,
1282 (SDB_ODBC_CHAR
*) pPKQ
, (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
1283 (SDB_ODBC_CHAR
*) pPKO
, pPKO
? SQL_NTS
: 0 ,
1284 (SDB_ODBC_CHAR
*) pPKN
, SQL_NTS
);
1285 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1288 // -------------------------------------------------------------------------
1289 void ODatabaseMetaDataResultSet::openIndexInfo( const Any
& catalog
, const ::rtl::OUString
& schema
,
1290 const ::rtl::OUString
& table
,sal_Bool unique
,sal_Bool approximate
)
1291 throw(SQLException
, RuntimeException
)
1293 const ::rtl::OUString
*pSchemaPat
= NULL
;
1295 if(schema
.toChar() != '%')
1296 pSchemaPat
= &schema
;
1300 m_bFreeHandle
= sal_True
;
1301 ::rtl::OString aPKQ
,aPKO
,aPKN
;
1303 if ( catalog
.hasValue() )
1304 aPKQ
= ::rtl::OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
1305 aPKO
= ::rtl::OUStringToOString(schema
,m_nTextEncoding
);
1307 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
1308 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() ? aPKO
.getStr() : NULL
,
1309 *pPKN
= (aPKN
= ::rtl::OUStringToOString(table
,m_nTextEncoding
)).getStr();
1312 SQLRETURN nRetcode
= N3SQLStatistics(m_aStatementHandle
,
1313 (SDB_ODBC_CHAR
*) pPKQ
, (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
1314 (SDB_ODBC_CHAR
*) pPKO
, pPKO
? SQL_NTS
: 0 ,
1315 (SDB_ODBC_CHAR
*) pPKN
, SQL_NTS
,
1316 unique
? SQL_INDEX_UNIQUE
: SQL_INDEX_ALL
,
1318 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1321 // -------------------------------------------------------------------------
1322 void ODatabaseMetaDataResultSet::checkColumnCount()
1324 sal_Int16 nNumResultCols
=0;
1325 OTools::ThrowException(m_pConnection
,N3SQLNumResultCols(m_aStatementHandle
,&nNumResultCols
),m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1326 m_nDriverColumnCount
= nNumResultCols
;
1328 // -----------------------------------------------------------------------------
1330 SWORD
ODatabaseMetaDataResultSet::impl_getColumnType_nothrow(sal_Int32 columnIndex
)
1332 ::std::map
<sal_Int32
,SWORD
>::iterator aFind
= m_aODBCColumnTypes
.find(columnIndex
);
1333 if ( aFind
== m_aODBCColumnTypes
.end() )
1334 aFind
= m_aODBCColumnTypes
.insert(::std::map
<sal_Int32
,SWORD
>::value_type(columnIndex
,OResultSetMetaData::getColumnODBCType(m_pConnection
,m_aStatementHandle
,*this,columnIndex
))).first
;
1335 return aFind
->second
;
1338 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */