1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <cppuhelper/typeprovider.hxx>
30 #include <comphelper/sequence.hxx>
31 #include "odbc/OResultSetMetaData.hxx"
32 #include "odbc/OTools.hxx"
33 #include <comphelper/types.hxx>
34 #include "FDatabaseMetaDataResultSetMetaData.hxx"
35 #include <connectivity/dbexception.hxx>
37 using namespace ::comphelper
;
40 using namespace connectivity::odbc
;
43 using namespace ::com::sun::star::lang
;
44 using namespace com::sun::star::uno
;
45 using namespace com::sun::star::beans
;
46 using namespace com::sun::star::sdbc
;
47 using namespace com::sun::star::util
;
50 ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet(OConnection
* _pConnection
)
51 :ODatabaseMetaDataResultSet_BASE(m_aMutex
)
52 ,OPropertySetHelper(ODatabaseMetaDataResultSet_BASE::rBHelper
)
54 ,m_aStatementHandle(_pConnection
->createStatementHandle())
57 ,m_pRowStatusArray(NULL
)
58 ,m_pConnection(_pConnection
)
59 ,m_nTextEncoding(_pConnection
->getTextEncoding())
61 ,m_nDriverColumnCount(0)
62 ,m_nCurrentFetchState(0)
66 OSL_ENSURE(m_pConnection
,"ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet: No parent set!");
67 if( SQL_NULL_HANDLE
== m_aStatementHandle
)
68 throw RuntimeException();
70 osl_atomic_increment( &m_refCount
);
71 m_pConnection
->acquire();
72 m_pRowStatusArray
= new SQLUSMALLINT
[1]; // the default value
73 osl_atomic_decrement( &m_refCount
);
78 ODatabaseMetaDataResultSet::~ODatabaseMetaDataResultSet()
80 OSL_ENSURE(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
,"Object wasn't disposed!");
81 if(!ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
)
83 osl_atomic_increment( &m_refCount
);
86 delete [] m_pRowStatusArray
;
89 void ODatabaseMetaDataResultSet::disposing()
91 OPropertySetHelper::disposing();
93 ::osl::MutexGuard
aGuard(m_aMutex
);
95 m_pConnection
->freeStatementHandle(m_aStatementHandle
);
99 m_pConnection
->release();
102 Any SAL_CALL
ODatabaseMetaDataResultSet::queryInterface( const Type
& rType
) throw(RuntimeException
, std::exception
)
104 Any aRet
= OPropertySetHelper::queryInterface(rType
);
105 return aRet
.hasValue() ? aRet
: ODatabaseMetaDataResultSet_BASE::queryInterface(rType
);
108 Reference
< XPropertySetInfo
> SAL_CALL
ODatabaseMetaDataResultSet::getPropertySetInfo( ) throw(RuntimeException
, std::exception
)
110 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
113 void SAL_CALL
ODatabaseMetaDataResultSet::acquire() throw()
115 ODatabaseMetaDataResultSet_BASE::acquire();
118 void SAL_CALL
ODatabaseMetaDataResultSet::release() throw()
120 ODatabaseMetaDataResultSet_BASE::release();
123 Sequence
< Type
> SAL_CALL
ODatabaseMetaDataResultSet::getTypes( ) throw(RuntimeException
, std::exception
)
125 ::cppu::OTypeCollection
aTypes( cppu::UnoType
<XMultiPropertySet
>::get(),
126 cppu::UnoType
<XFastPropertySet
>::get(),
127 cppu::UnoType
<XPropertySet
>::get());
129 return ::comphelper::concatSequences(aTypes
.getTypes(),ODatabaseMetaDataResultSet_BASE::getTypes());
132 sal_Int32
ODatabaseMetaDataResultSet::mapColumn (sal_Int32 column
)
134 sal_Int32 map
= column
;
136 if (!m_aColMapping
.empty())
138 // Validate column number
139 map
= m_aColMapping
[column
];
146 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSet::findColumn( const OUString
& columnName
) throw(SQLException
, RuntimeException
, std::exception
)
149 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
150 ::osl::MutexGuard
aGuard( m_aMutex
);
153 Reference
< XResultSetMetaData
> xMeta
= getMetaData();
154 sal_Int32 nLen
= xMeta
->getColumnCount();
158 if(xMeta
->isCaseSensitive(i
) ? columnName
== xMeta
->getColumnName(i
) :
159 columnName
.equalsIgnoreAsciiCase(xMeta
->getColumnName(i
)))
163 ::dbtools::throwInvalidColumnException( columnName
, *this );
165 return 0; // Never reached
168 template < typename T
, SQLSMALLINT sqlTypeId
> T
ODatabaseMetaDataResultSet::getInteger ( sal_Int32 columnIndex
)
170 ::cppu::OBroadcastHelper
& rBHelper(ODatabaseMetaDataResultSet_BASE::rBHelper
);
171 checkDisposed(rBHelper
.bDisposed
);
172 ::osl::MutexGuard
aGuard( m_aMutex
);
174 columnIndex
= mapColumn(columnIndex
);
176 if(columnIndex
<= m_nDriverColumnCount
)
178 getValue
<T
>(m_pConnection
, m_aStatementHandle
, columnIndex
, sqlTypeId
, m_bWasNull
, **this, nVal
);
180 if ( !m_aValueRange
.empty() )
182 ::std::map
<sal_Int32
, ::connectivity::TInt2IntMap
>::iterator
aValueRangeIter (m_aValueRange
.find(columnIndex
));
183 if ( aValueRangeIter
!= m_aValueRange
.end() )
184 return static_cast<T
>(aValueRangeIter
->second
[nVal
]);
193 Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
ODatabaseMetaDataResultSet::getBinaryStream( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
, std::exception
)
195 ::dbtools::throwFunctionNotSupportedSQLException( "XRow::getBinaryStream", *this );
199 Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
ODatabaseMetaDataResultSet::getCharacterStream( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
, std::exception
)
201 ::dbtools::throwFunctionNotSupportedSQLException( "XRow::getCharacterStream", *this );
206 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::getBoolean( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
209 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
210 ::osl::MutexGuard
aGuard( m_aMutex
);
212 columnIndex
= mapColumn(columnIndex
);
215 if(columnIndex
<= m_nDriverColumnCount
)
217 sal_Int32 nType
= getMetaData()->getColumnType(columnIndex
);
223 OTools::getValue(m_pConnection
,m_aStatementHandle
,columnIndex
,SQL_C_BIT
,m_bWasNull
,**this,&nValue
,sizeof nValue
);
228 bRet
= getInt(columnIndex
) != 0;
235 sal_Int8 SAL_CALL
ODatabaseMetaDataResultSet::getByte( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
237 return getInteger
<sal_Int8
, SQL_C_STINYINT
>( columnIndex
);
241 Sequence
< sal_Int8
> SAL_CALL
ODatabaseMetaDataResultSet::getBytes( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
244 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
245 ::osl::MutexGuard
aGuard( m_aMutex
);
248 columnIndex
= mapColumn(columnIndex
);
249 if(columnIndex
<= m_nDriverColumnCount
)
251 sal_Int32 nType
= getMetaData()->getColumnType(columnIndex
);
255 case DataType::VARCHAR
:
256 case DataType::LONGVARCHAR
:
258 OUString aRet
= OTools::getStringValue(m_pConnection
,m_aStatementHandle
,columnIndex
,SQL_C_BINARY
,m_bWasNull
,**this,m_nTextEncoding
);
259 return Sequence
<sal_Int8
>(reinterpret_cast<const sal_Int8
*>(aRet
.getStr()),sizeof(sal_Unicode
)*aRet
.getLength());
262 return OTools::getBytesValue(m_pConnection
,m_aStatementHandle
,columnIndex
,SQL_C_BINARY
,m_bWasNull
,**this);
266 return Sequence
<sal_Int8
>();
270 ::com::sun::star::util::Date SAL_CALL
ODatabaseMetaDataResultSet::getDate( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
272 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
273 ::osl::MutexGuard
aGuard( m_aMutex
);
276 columnIndex
= mapColumn(columnIndex
);
277 if(columnIndex
<= m_nDriverColumnCount
)
283 OTools::getValue(m_pConnection
,m_aStatementHandle
,columnIndex
,m_pConnection
->useOldDateFormat() ? SQL_C_DATE
: SQL_C_TYPE_DATE
,m_bWasNull
,**this,&aDate
,sizeof aDate
);
284 return Date(aDate
.day
,aDate
.month
,aDate
.year
);
292 double SAL_CALL
ODatabaseMetaDataResultSet::getDouble( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
295 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
296 ::osl::MutexGuard
aGuard( m_aMutex
);
299 columnIndex
= mapColumn(columnIndex
);
301 if(columnIndex
<= m_nDriverColumnCount
)
302 OTools::getValue(m_pConnection
,m_aStatementHandle
,columnIndex
,SQL_C_DOUBLE
,m_bWasNull
,**this,&nValue
,sizeof nValue
);
309 float SAL_CALL
ODatabaseMetaDataResultSet::getFloat( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
312 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
313 ::osl::MutexGuard
aGuard( m_aMutex
);
316 columnIndex
= mapColumn(columnIndex
);
318 if(columnIndex
<= m_nDriverColumnCount
)
319 OTools::getValue(m_pConnection
,m_aStatementHandle
,columnIndex
,SQL_C_FLOAT
,m_bWasNull
,**this,&nVal
,sizeof nVal
);
326 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSet::getInt( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
328 return getInteger
<sal_Int32
, SQL_C_SLONG
>( columnIndex
);
332 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSet::getRow( ) throw(SQLException
, RuntimeException
, std::exception
)
338 sal_Int64 SAL_CALL
ODatabaseMetaDataResultSet::getLong( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
340 return getInteger
<sal_Int64
, SQL_C_SBIGINT
>( columnIndex
);
344 Reference
< XResultSetMetaData
> SAL_CALL
ODatabaseMetaDataResultSet::getMetaData( ) throw(SQLException
, RuntimeException
, std::exception
)
346 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
347 ::osl::MutexGuard
aGuard( m_aMutex
);
348 return m_xMetaData
.is() ? m_xMetaData
: (m_xMetaData
= new OResultSetMetaData(m_pConnection
,m_aStatementHandle
));
351 Reference
< XArray
> SAL_CALL
ODatabaseMetaDataResultSet::getArray( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
, std::exception
)
353 ::dbtools::throwFunctionNotSupportedSQLException( "XRow::getArray", *this );
357 Reference
< XClob
> SAL_CALL
ODatabaseMetaDataResultSet::getClob( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
, std::exception
)
359 ::dbtools::throwFunctionNotSupportedSQLException( "XRow::getClob", *this );
363 Reference
< XBlob
> SAL_CALL
ODatabaseMetaDataResultSet::getBlob( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
, std::exception
)
365 ::dbtools::throwFunctionNotSupportedSQLException( "XRow::getBlob", *this );
370 Reference
< XRef
> SAL_CALL
ODatabaseMetaDataResultSet::getRef( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
, std::exception
)
372 ::dbtools::throwFunctionNotSupportedSQLException( "XRow::getRef", *this );
377 Any SAL_CALL
ODatabaseMetaDataResultSet::getObject( sal_Int32
/*columnIndex*/, const Reference
< ::com::sun::star::container::XNameAccess
>& /*typeMap*/ ) throw(SQLException
, RuntimeException
, std::exception
)
379 ::dbtools::throwFunctionNotSupportedSQLException( "XRow::getObject", *this );
384 sal_Int16 SAL_CALL
ODatabaseMetaDataResultSet::getShort( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
386 return getInteger
<sal_Int16
, SQL_C_SSHORT
>( columnIndex
);
390 OUString SAL_CALL
ODatabaseMetaDataResultSet::getString( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
393 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
394 ::osl::MutexGuard
aGuard( m_aMutex
);
397 columnIndex
= mapColumn(columnIndex
);
399 if(columnIndex
<= m_nDriverColumnCount
)
400 aVal
= OTools::getStringValue(m_pConnection
,m_aStatementHandle
,columnIndex
,impl_getColumnType_nothrow(columnIndex
),m_bWasNull
,**this,m_nTextEncoding
);
410 ::com::sun::star::util::Time SAL_CALL
ODatabaseMetaDataResultSet::getTime( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
413 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
414 ::osl::MutexGuard
aGuard( m_aMutex
);
417 columnIndex
= mapColumn(columnIndex
);
418 TIME_STRUCT aTime
={0,0,0};
419 if(columnIndex
<= m_nDriverColumnCount
)
420 OTools::getValue(m_pConnection
,m_aStatementHandle
,columnIndex
,m_pConnection
->useOldDateFormat() ? SQL_C_TIME
: SQL_C_TYPE_TIME
,m_bWasNull
,**this,&aTime
,sizeof aTime
);
423 return Time(0, aTime
.second
,aTime
.minute
,aTime
.hour
, false);
428 ::com::sun::star::util::DateTime SAL_CALL
ODatabaseMetaDataResultSet::getTimestamp( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
431 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
432 ::osl::MutexGuard
aGuard( m_aMutex
);
435 columnIndex
= mapColumn(columnIndex
);
436 TIMESTAMP_STRUCT aTime
={0,0,0,0,0,0,0};
437 if(columnIndex
<= m_nDriverColumnCount
)
438 OTools::getValue(m_pConnection
,m_aStatementHandle
,columnIndex
,m_pConnection
->useOldDateFormat() ? SQL_C_TIMESTAMP
: SQL_C_TYPE_TIMESTAMP
, m_bWasNull
, **this, &aTime
, sizeof aTime
);
441 return DateTime(aTime
.fraction
, aTime
.second
, aTime
.minute
, aTime
.hour
,
442 aTime
.day
, aTime
.month
, aTime
.year
, false);
446 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::isAfterLast( ) throw(SQLException
, RuntimeException
, std::exception
)
449 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
450 ::osl::MutexGuard
aGuard( m_aMutex
);
453 return m_nCurrentFetchState
== SQL_NO_DATA
;
456 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::isFirst( ) throw(SQLException
, RuntimeException
, std::exception
)
459 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
460 ::osl::MutexGuard
aGuard( m_aMutex
);
463 return m_nRowPos
== 1;
466 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::isLast( ) throw(SQLException
, RuntimeException
, std::exception
)
469 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
470 ::osl::MutexGuard
aGuard( m_aMutex
);
473 return m_bEOF
&& m_nCurrentFetchState
!= SQL_NO_DATA
;
476 void SAL_CALL
ODatabaseMetaDataResultSet::beforeFirst( ) throw(SQLException
, RuntimeException
, std::exception
)
479 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
480 ::osl::MutexGuard
aGuard( m_aMutex
);
485 m_nCurrentFetchState
= SQL_SUCCESS
;
488 void SAL_CALL
ODatabaseMetaDataResultSet::afterLast( ) throw(SQLException
, RuntimeException
, std::exception
)
491 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
492 ::osl::MutexGuard
aGuard( m_aMutex
);
500 void SAL_CALL
ODatabaseMetaDataResultSet::close( ) throw(SQLException
, RuntimeException
, std::exception
)
504 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
505 ::osl::MutexGuard
aGuard( m_aMutex
);
512 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::first( ) throw(SQLException
, RuntimeException
, std::exception
)
515 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
516 ::osl::MutexGuard
aGuard( m_aMutex
);
520 m_nCurrentFetchState
= N3SQLFetchScroll(m_aStatementHandle
,SQL_FETCH_FIRST
,0);
521 OTools::ThrowException(m_pConnection
,m_nCurrentFetchState
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
522 bool bRet
= ( m_nCurrentFetchState
== SQL_SUCCESS
|| m_nCurrentFetchState
== SQL_SUCCESS_WITH_INFO
);
529 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::last( ) throw(SQLException
, RuntimeException
, std::exception
)
531 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
532 ::osl::MutexGuard
aGuard( m_aMutex
);
535 m_nCurrentFetchState
= N3SQLFetchScroll(m_aStatementHandle
,SQL_FETCH_LAST
,0);
536 OTools::ThrowException(m_pConnection
,m_nCurrentFetchState
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
537 // here I know definitely that I stand on the last record
538 bool bRet
= ( m_nCurrentFetchState
== SQL_SUCCESS
|| m_nCurrentFetchState
== SQL_SUCCESS_WITH_INFO
);
544 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::absolute( sal_Int32 row
) throw(SQLException
, RuntimeException
, std::exception
)
547 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
548 ::osl::MutexGuard
aGuard( m_aMutex
);
552 m_nCurrentFetchState
= N3SQLFetchScroll(m_aStatementHandle
,SQL_FETCH_ABSOLUTE
,row
);
553 OTools::ThrowException(m_pConnection
,m_nCurrentFetchState
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
554 bool bRet
= m_nCurrentFetchState
== SQL_SUCCESS
|| m_nCurrentFetchState
== SQL_SUCCESS_WITH_INFO
;
560 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::relative( sal_Int32 row
) throw(SQLException
, RuntimeException
, std::exception
)
563 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
564 ::osl::MutexGuard
aGuard( m_aMutex
);
568 m_nCurrentFetchState
= N3SQLFetchScroll(m_aStatementHandle
,SQL_FETCH_RELATIVE
,row
);
569 OTools::ThrowException(m_pConnection
,m_nCurrentFetchState
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
570 bool bRet
= m_nCurrentFetchState
== SQL_SUCCESS
|| m_nCurrentFetchState
== SQL_SUCCESS_WITH_INFO
;
576 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::previous( ) throw(SQLException
, RuntimeException
, std::exception
)
579 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
580 ::osl::MutexGuard
aGuard( m_aMutex
);
584 m_nCurrentFetchState
= N3SQLFetchScroll(m_aStatementHandle
,SQL_FETCH_PRIOR
,0);
585 OTools::ThrowException(m_pConnection
,m_nCurrentFetchState
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
586 bool bRet
= m_nCurrentFetchState
== SQL_SUCCESS
|| m_nCurrentFetchState
== SQL_SUCCESS_WITH_INFO
;
589 else if ( m_nCurrentFetchState
== SQL_NO_DATA
)
594 Reference
< XInterface
> SAL_CALL
ODatabaseMetaDataResultSet::getStatement( ) throw(SQLException
, RuntimeException
, std::exception
)
600 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::rowDeleted( ) throw(SQLException
, RuntimeException
, std::exception
)
603 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
604 ::osl::MutexGuard
aGuard( m_aMutex
);
607 return m_pRowStatusArray
[0] == SQL_ROW_DELETED
;
610 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::rowInserted( ) throw(SQLException
, RuntimeException
, std::exception
)
612 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
613 ::osl::MutexGuard
aGuard( m_aMutex
);
616 return m_pRowStatusArray
[0] == SQL_ROW_ADDED
;
619 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::rowUpdated( ) throw(SQLException
, RuntimeException
, std::exception
)
622 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
623 ::osl::MutexGuard
aGuard( m_aMutex
);
626 return m_pRowStatusArray
[0] == SQL_ROW_UPDATED
;
630 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::isBeforeFirst( ) throw(SQLException
, RuntimeException
, std::exception
)
633 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
634 ::osl::MutexGuard
aGuard( m_aMutex
);
637 return m_nRowPos
== 0;
641 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::next( ) throw(SQLException
, RuntimeException
, std::exception
)
644 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
645 ::osl::MutexGuard
aGuard( m_aMutex
);
649 SQLRETURN nOldFetchStatus
= m_nCurrentFetchState
;
650 // m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_NEXT,0);
651 m_nCurrentFetchState
= N3SQLFetch(m_aStatementHandle
);
652 OTools::ThrowException(m_pConnection
,m_nCurrentFetchState
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
653 bool bRet
= m_nCurrentFetchState
== SQL_SUCCESS
|| m_nCurrentFetchState
== SQL_SUCCESS_WITH_INFO
;
654 if(bRet
|| ( m_nCurrentFetchState
== SQL_NO_DATA
&& nOldFetchStatus
!= SQL_NO_DATA
) )
660 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::wasNull( ) throw(SQLException
, RuntimeException
, std::exception
)
663 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
664 ::osl::MutexGuard
aGuard( m_aMutex
);
670 void SAL_CALL
ODatabaseMetaDataResultSet::refreshRow( ) throw(SQLException
, RuntimeException
, std::exception
)
673 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
674 ::osl::MutexGuard
aGuard( m_aMutex
);
679 void SAL_CALL
ODatabaseMetaDataResultSet::cancel( ) throw(RuntimeException
, std::exception
)
682 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
683 ::osl::MutexGuard
aGuard( m_aMutex
);
686 N3SQLCancel(m_aStatementHandle
);
689 void SAL_CALL
ODatabaseMetaDataResultSet::clearWarnings( ) throw(SQLException
, RuntimeException
, std::exception
)
693 Any SAL_CALL
ODatabaseMetaDataResultSet::getWarnings( ) throw(SQLException
, RuntimeException
, std::exception
)
698 sal_Int32
ODatabaseMetaDataResultSet::getFetchSize() throw(SQLException
, RuntimeException
)
704 OUString
ODatabaseMetaDataResultSet::getCursorName() throw(SQLException
, RuntimeException
)
710 ::cppu::IPropertyArrayHelper
* ODatabaseMetaDataResultSet::createArrayHelper( ) const
713 Sequence
< com::sun::star::beans::Property
> aProps(5);
714 com::sun::star::beans::Property
* pProperties
= aProps
.getArray();
716 pProperties
[nPos
++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME
),
717 PROPERTY_ID_CURSORNAME
, cppu::UnoType
<OUString
>::get(), 0);
718 pProperties
[nPos
++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION
),
719 PROPERTY_ID_FETCHDIRECTION
, cppu::UnoType
<sal_Int32
>::get(), 0);
720 pProperties
[nPos
++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE
),
721 PROPERTY_ID_FETCHSIZE
, cppu::UnoType
<sal_Int32
>::get(), 0);
722 pProperties
[nPos
++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY
),
723 PROPERTY_ID_RESULTSETCONCURRENCY
, cppu::UnoType
<sal_Int32
>::get(), 0);
724 pProperties
[nPos
++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE
),
725 PROPERTY_ID_RESULTSETTYPE
, cppu::UnoType
<sal_Int32
>::get(), 0);
727 return new ::cppu::OPropertyArrayHelper(aProps
);
730 ::cppu::IPropertyArrayHelper
& ODatabaseMetaDataResultSet::getInfoHelper()
732 return *getArrayHelper();
735 sal_Bool
ODatabaseMetaDataResultSet::convertFastPropertyValue(
736 Any
& rConvertedValue
,
740 throw (::com::sun::star::lang::IllegalArgumentException
)
744 case PROPERTY_ID_CURSORNAME
:
745 case PROPERTY_ID_RESULTSETCONCURRENCY
:
746 case PROPERTY_ID_RESULTSETTYPE
:
747 throw ::com::sun::star::lang::IllegalArgumentException();
748 case PROPERTY_ID_FETCHDIRECTION
:
749 return ::comphelper::tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, getFetchDirection());
750 case PROPERTY_ID_FETCHSIZE
:
751 return ::comphelper::tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, getFetchSize());
758 void ODatabaseMetaDataResultSet::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
, const Any
& /*rValue*/ ) throw (Exception
, std::exception
)
762 case PROPERTY_ID_CURSORNAME
:
763 case PROPERTY_ID_RESULTSETCONCURRENCY
:
764 case PROPERTY_ID_RESULTSETTYPE
:
765 case PROPERTY_ID_FETCHDIRECTION
:
766 case PROPERTY_ID_FETCHSIZE
:
769 OSL_FAIL("setFastPropertyValue_NoBroadcast: Illegal handle value!");
773 void ODatabaseMetaDataResultSet::getFastPropertyValue( Any
& rValue
, sal_Int32 nHandle
) const
777 case PROPERTY_ID_CURSORNAME
:
778 rValue
<<= getCursorName();
780 case PROPERTY_ID_RESULTSETCONCURRENCY
:
781 rValue
<<= getResultSetConcurrency();
783 case PROPERTY_ID_RESULTSETTYPE
:
784 rValue
<<= getResultSetType();
786 case PROPERTY_ID_FETCHDIRECTION
:
787 rValue
<<= getFetchDirection();
789 case PROPERTY_ID_FETCHSIZE
:
790 rValue
<<= getFetchSize();
795 void ODatabaseMetaDataResultSet::openTypeInfo() throw(SQLException
, RuntimeException
)
798 aMap
[SQL_BIT
] = DataType::BIT
;
799 aMap
[SQL_TINYINT
] = DataType::TINYINT
;
800 aMap
[SQL_SMALLINT
] = DataType::SMALLINT
;
801 aMap
[SQL_INTEGER
] = DataType::INTEGER
;
802 aMap
[SQL_FLOAT
] = DataType::FLOAT
;
803 aMap
[SQL_REAL
] = DataType::REAL
;
804 aMap
[SQL_DOUBLE
] = DataType::DOUBLE
;
805 aMap
[SQL_BIGINT
] = DataType::BIGINT
;
807 aMap
[SQL_CHAR
] = DataType::CHAR
;
808 aMap
[SQL_WCHAR
] = DataType::CHAR
;
809 aMap
[SQL_VARCHAR
] = DataType::VARCHAR
;
810 aMap
[SQL_WVARCHAR
] = DataType::VARCHAR
;
811 aMap
[SQL_LONGVARCHAR
] = DataType::LONGVARCHAR
;
812 aMap
[SQL_WLONGVARCHAR
] = DataType::LONGVARCHAR
;
814 aMap
[SQL_TYPE_DATE
] = DataType::DATE
;
815 aMap
[SQL_DATE
] = DataType::DATE
;
816 aMap
[SQL_TYPE_TIME
] = DataType::TIME
;
817 aMap
[SQL_TIME
] = DataType::TIME
;
818 aMap
[SQL_TYPE_TIMESTAMP
] = DataType::TIMESTAMP
;
819 aMap
[SQL_TIMESTAMP
] = DataType::TIMESTAMP
;
821 aMap
[SQL_DECIMAL
] = DataType::DECIMAL
;
822 aMap
[SQL_NUMERIC
] = DataType::NUMERIC
;
824 aMap
[SQL_BINARY
] = DataType::BINARY
;
825 aMap
[SQL_VARBINARY
] = DataType::VARBINARY
;
826 aMap
[SQL_LONGVARBINARY
] = DataType::LONGVARBINARY
;
828 aMap
[SQL_GUID
] = DataType::VARBINARY
;
831 m_aValueRange
[2] = aMap
;
833 OTools::ThrowException(m_pConnection
,N3SQLGetTypeInfo(m_aStatementHandle
, SQL_ALL_TYPES
),m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
837 void ODatabaseMetaDataResultSet::openTables(const Any
& catalog
, const OUString
& schemaPattern
,
838 const OUString
& tableNamePattern
,
839 const Sequence
< OUString
>& types
) throw(SQLException
, RuntimeException
)
841 OString aPKQ
,aPKO
,aPKN
,aCOL
;
842 const OUString
*pSchemaPat
= NULL
;
844 if(schemaPattern
!= "%")
845 pSchemaPat
= &schemaPattern
;
849 if ( catalog
.hasValue() )
850 aPKQ
= OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
851 aPKO
= OUStringToOString(schemaPattern
,m_nTextEncoding
);
852 aPKN
= OUStringToOString(tableNamePattern
,m_nTextEncoding
);
854 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
855 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() && !aPKO
.isEmpty() ? aPKO
.getStr() : NULL
,
856 *pPKN
= aPKN
.getStr();
859 const char *pCOL
= NULL
;
860 const char* pComma
= ",";
861 const OUString
* pBegin
= types
.getConstArray();
862 const OUString
* pEnd
= pBegin
+ types
.getLength();
863 for(;pBegin
!= pEnd
;++pBegin
)
865 aCOL
+= OUStringToOString(*pBegin
,m_nTextEncoding
);
868 if ( !aCOL
.isEmpty() )
870 aCOL
= aCOL
.replaceAt(aCOL
.getLength()-1,1,pComma
);
871 pCOL
= aCOL
.getStr();
874 pCOL
= SQL_ALL_TABLE_TYPES
;
876 SQLRETURN nRetcode
= N3SQLTables(m_aStatementHandle
,
877 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKQ
)), (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
878 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKO
)), pPKO
? SQL_NTS
: 0,
879 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKN
)), SQL_NTS
,
880 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pCOL
)), pCOL
? SQL_NTS
: 0);
881 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
886 void ODatabaseMetaDataResultSet::openTablesTypes( ) throw(SQLException
, RuntimeException
)
888 SQLRETURN nRetcode
= N3SQLTables(m_aStatementHandle
,
892 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(SQL_ALL_TABLE_TYPES
)),SQL_NTS
);
893 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
895 m_aColMapping
.clear();
896 m_aColMapping
.push_back(-1);
897 m_aColMapping
.push_back(4);
898 m_xMetaData
= new OResultSetMetaData(m_pConnection
,m_aStatementHandle
,m_aColMapping
);
902 void ODatabaseMetaDataResultSet::openCatalogs() throw(SQLException
, RuntimeException
)
904 SQLRETURN nRetcode
= N3SQLTables(m_aStatementHandle
,
905 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(SQL_ALL_CATALOGS
)),SQL_NTS
,
906 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>("")),SQL_NTS
,
907 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>("")),SQL_NTS
,
908 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>("")),SQL_NTS
);
910 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
912 m_aColMapping
.clear();
913 m_aColMapping
.push_back(-1);
914 m_aColMapping
.push_back(1);
915 m_xMetaData
= new OResultSetMetaData(m_pConnection
,m_aStatementHandle
,m_aColMapping
);
919 void ODatabaseMetaDataResultSet::openSchemas() throw(SQLException
, RuntimeException
)
921 SQLRETURN nRetcode
= N3SQLTables(m_aStatementHandle
,
922 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>("")),SQL_NTS
,
923 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(SQL_ALL_SCHEMAS
)),SQL_NTS
,
924 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>("")),SQL_NTS
,
925 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>("")),SQL_NTS
);
926 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
928 m_aColMapping
.clear();
929 m_aColMapping
.push_back(-1);
930 m_aColMapping
.push_back(2);
931 m_xMetaData
= new OResultSetMetaData(m_pConnection
,m_aStatementHandle
,m_aColMapping
);
935 void ODatabaseMetaDataResultSet::openColumnPrivileges( const Any
& catalog
, const OUString
& schema
,
936 const OUString
& table
, const OUString
& columnNamePattern
)
937 throw(SQLException
, RuntimeException
)
939 const OUString
*pSchemaPat
= NULL
;
942 pSchemaPat
= &schema
;
946 OString aPKQ
,aPKO
,aPKN
,aCOL
;
948 if ( catalog
.hasValue() )
949 aPKQ
= OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
950 aPKO
= OUStringToOString(schema
,m_nTextEncoding
);
951 aPKN
= OUStringToOString(table
,m_nTextEncoding
);
952 aCOL
= OUStringToOString(columnNamePattern
,m_nTextEncoding
);
954 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
955 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() && !aPKO
.isEmpty() ? aPKO
.getStr() : NULL
,
956 *pPKN
= aPKN
.getStr(),
957 *pCOL
= aCOL
.getStr();
960 SQLRETURN nRetcode
= N3SQLColumnPrivileges(m_aStatementHandle
,
961 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKQ
)), (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
962 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKO
)), pPKO
? SQL_NTS
: 0 ,
963 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKN
)), SQL_NTS
,
964 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pCOL
)), SQL_NTS
);
965 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
970 void ODatabaseMetaDataResultSet::openColumns( const Any
& catalog
, const OUString
& schemaPattern
,
971 const OUString
& tableNamePattern
, const OUString
& columnNamePattern
)
972 throw(SQLException
, RuntimeException
)
974 const OUString
*pSchemaPat
= NULL
;
976 if(schemaPattern
!= "%")
977 pSchemaPat
= &schemaPattern
;
981 OString aPKQ
,aPKO
,aPKN
,aCOL
;
982 if ( catalog
.hasValue() )
983 aPKQ
= OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
984 aPKO
= OUStringToOString(schemaPattern
,m_nTextEncoding
);
985 aPKN
= OUStringToOString(tableNamePattern
,m_nTextEncoding
);
986 aCOL
= OUStringToOString(columnNamePattern
,m_nTextEncoding
);
988 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
989 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() && !aPKO
.isEmpty() ? aPKO
.getStr() : NULL
,
990 *pPKN
= aPKN
.getStr(),
991 *pCOL
= aCOL
.getStr();
994 SQLRETURN nRetcode
= N3SQLColumns(m_aStatementHandle
,
995 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKQ
)), (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
996 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKO
)), pPKO
? SQL_NTS
: 0,
997 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKN
)), SQL_NTS
,
998 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pCOL
)), SQL_NTS
);
1000 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1002 aMap
[SQL_BIT
] = DataType::BIT
;
1003 aMap
[SQL_TINYINT
] = DataType::TINYINT
;
1004 aMap
[SQL_SMALLINT
] = DataType::SMALLINT
;
1005 aMap
[SQL_INTEGER
] = DataType::INTEGER
;
1006 aMap
[SQL_FLOAT
] = DataType::FLOAT
;
1007 aMap
[SQL_REAL
] = DataType::REAL
;
1008 aMap
[SQL_DOUBLE
] = DataType::DOUBLE
;
1009 aMap
[SQL_BIGINT
] = DataType::BIGINT
;
1011 aMap
[SQL_CHAR
] = DataType::CHAR
;
1012 aMap
[SQL_WCHAR
] = DataType::CHAR
;
1013 aMap
[SQL_VARCHAR
] = DataType::VARCHAR
;
1014 aMap
[SQL_WVARCHAR
] = DataType::VARCHAR
;
1015 aMap
[SQL_LONGVARCHAR
] = DataType::LONGVARCHAR
;
1016 aMap
[SQL_WLONGVARCHAR
] = DataType::LONGVARCHAR
;
1018 aMap
[SQL_TYPE_DATE
] = DataType::DATE
;
1019 aMap
[SQL_DATE
] = DataType::DATE
;
1020 aMap
[SQL_TYPE_TIME
] = DataType::TIME
;
1021 aMap
[SQL_TIME
] = DataType::TIME
;
1022 aMap
[SQL_TYPE_TIMESTAMP
] = DataType::TIMESTAMP
;
1023 aMap
[SQL_TIMESTAMP
] = DataType::TIMESTAMP
;
1025 aMap
[SQL_DECIMAL
] = DataType::DECIMAL
;
1026 aMap
[SQL_NUMERIC
] = DataType::NUMERIC
;
1028 aMap
[SQL_BINARY
] = DataType::BINARY
;
1029 aMap
[SQL_VARBINARY
] = DataType::VARBINARY
;
1030 aMap
[SQL_LONGVARBINARY
] = DataType::LONGVARBINARY
;
1032 aMap
[SQL_GUID
] = DataType::VARBINARY
;
1034 m_aValueRange
[5] = aMap
;
1038 void ODatabaseMetaDataResultSet::openProcedureColumns( const Any
& catalog
, const OUString
& schemaPattern
,
1039 const OUString
& procedureNamePattern
,const OUString
& columnNamePattern
)
1040 throw(SQLException
, RuntimeException
)
1042 const OUString
*pSchemaPat
= NULL
;
1044 if(schemaPattern
!= "%")
1045 pSchemaPat
= &schemaPattern
;
1049 OString aPKQ
,aPKO
,aPKN
,aCOL
;
1050 if ( catalog
.hasValue() )
1051 aPKQ
= OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
1052 aPKO
= OUStringToOString(schemaPattern
,m_nTextEncoding
);
1053 aPKN
= OUStringToOString(procedureNamePattern
,m_nTextEncoding
);
1054 aCOL
= OUStringToOString(columnNamePattern
,m_nTextEncoding
);
1056 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
1057 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() && !aPKO
.isEmpty() ? aPKO
.getStr() : NULL
,
1058 *pPKN
= aPKN
.getStr(),
1059 *pCOL
= aCOL
.getStr();
1062 SQLRETURN nRetcode
= N3SQLProcedureColumns(m_aStatementHandle
,
1063 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKQ
)), (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
1064 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKO
)), pPKO
? SQL_NTS
: 0 ,
1065 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKN
)), SQL_NTS
,
1066 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pCOL
)), SQL_NTS
);
1068 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1072 void ODatabaseMetaDataResultSet::openProcedures(const Any
& catalog
, const OUString
& schemaPattern
,
1073 const OUString
& procedureNamePattern
)
1074 throw(SQLException
, RuntimeException
)
1076 const OUString
*pSchemaPat
= NULL
;
1078 if(schemaPattern
!= "%")
1079 pSchemaPat
= &schemaPattern
;
1083 OString aPKQ
,aPKO
,aPKN
;
1085 if ( catalog
.hasValue() )
1086 aPKQ
= OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
1087 aPKO
= OUStringToOString(schemaPattern
,m_nTextEncoding
);
1088 aPKN
= OUStringToOString(procedureNamePattern
,m_nTextEncoding
);
1090 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
1091 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() && !aPKO
.isEmpty() ? aPKO
.getStr() : NULL
,
1092 *pPKN
= aPKN
.getStr();
1095 SQLRETURN nRetcode
= N3SQLProcedures(m_aStatementHandle
,
1096 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKQ
)), (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
1097 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKO
)), pPKO
? SQL_NTS
: 0 ,
1098 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKN
)), SQL_NTS
);
1099 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1103 void ODatabaseMetaDataResultSet::openSpecialColumns(bool _bRowVer
,const Any
& catalog
, const OUString
& schema
,
1104 const OUString
& table
,sal_Int32 scope
, bool nullable
)
1105 throw(SQLException
, RuntimeException
)
1107 // Some ODBC drivers really don't like getting an empty string as tableName
1108 // E.g. psqlodbc up to at least version 09.01.0100 segfaults
1109 if (table
.isEmpty())
1111 const char errMsg
[] = "ODBC: Trying to get special columns of empty table name";
1112 const char SQLState
[] = "HY009";
1113 throw SQLException( OUString(errMsg
, sizeof(errMsg
) - sizeof(errMsg
[0]), RTL_TEXTENCODING_ASCII_US
),
1115 OUString(SQLState
, sizeof(SQLState
) - sizeof(SQLState
[0]), RTL_TEXTENCODING_ASCII_US
),
1120 const OUString
*pSchemaPat
= NULL
;
1123 pSchemaPat
= &schema
;
1127 OString aPKQ
,aPKO
,aPKN
;
1128 if ( catalog
.hasValue() )
1129 aPKQ
= OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
1130 aPKO
= OUStringToOString(schema
,m_nTextEncoding
);
1131 aPKN
= OUStringToOString(table
,m_nTextEncoding
);
1133 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
1134 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() && !aPKO
.isEmpty() ? aPKO
.getStr() : NULL
,
1135 *pPKN
= aPKN
.getStr();
1138 SQLRETURN nRetcode
= N3SQLSpecialColumns(m_aStatementHandle
,_bRowVer
? SQL_ROWVER
: SQL_BEST_ROWID
,
1139 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKQ
)), (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
1140 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKO
)), pPKO
? SQL_NTS
: 0 ,
1141 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKN
)), SQL_NTS
,
1143 nullable
? SQL_NULLABLE
: SQL_NO_NULLS
);
1144 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1148 void ODatabaseMetaDataResultSet::openVersionColumns(const Any
& catalog
, const OUString
& schema
,
1149 const OUString
& table
) throw(SQLException
, RuntimeException
)
1151 openSpecialColumns(true,catalog
,schema
,table
,SQL_SCOPE_TRANSACTION
,false);
1154 void ODatabaseMetaDataResultSet::openBestRowIdentifier( const Any
& catalog
, const OUString
& schema
,
1155 const OUString
& table
,sal_Int32 scope
,bool nullable
) throw(SQLException
, RuntimeException
)
1157 openSpecialColumns(false,catalog
,schema
,table
,scope
,nullable
);
1160 void ODatabaseMetaDataResultSet::openForeignKeys( const Any
& catalog
, const OUString
* schema
,
1161 const OUString
* table
,
1162 const Any
& catalog2
, const OUString
* schema2
,
1163 const OUString
* table2
) throw(SQLException
, RuntimeException
)
1165 OString aPKQ
, aPKO
, aPKN
, aFKQ
, aFKO
, aFKN
;
1166 if ( catalog
.hasValue() )
1167 aPKQ
= OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
1168 if ( catalog2
.hasValue() )
1169 aFKQ
= OUStringToOString(comphelper::getString(catalog2
),m_nTextEncoding
);
1171 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
1172 *pPKO
= schema
&& !schema
->isEmpty() ? (aPKO
= OUStringToOString(*schema
,m_nTextEncoding
)).getStr() : NULL
,
1173 *pPKN
= table
? (aPKN
= OUStringToOString(*table
,m_nTextEncoding
)).getStr(): NULL
,
1174 *pFKQ
= catalog2
.hasValue() && !aFKQ
.isEmpty() ? aFKQ
.getStr() : NULL
,
1175 *pFKO
= schema2
&& !schema2
->isEmpty() ? (aFKO
= OUStringToOString(*schema2
,m_nTextEncoding
)).getStr() : NULL
,
1176 *pFKN
= table2
? (aFKN
= OUStringToOString(*table2
,m_nTextEncoding
)).getStr() : NULL
;
1179 SQLRETURN nRetcode
= N3SQLForeignKeys(m_aStatementHandle
,
1180 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKQ
)), (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
1181 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKO
)), pPKO
? SQL_NTS
: 0,
1182 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKN
)), pPKN
? SQL_NTS
: 0,
1183 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pFKQ
)), (catalog2
.hasValue() && !aFKQ
.isEmpty()) ? SQL_NTS
: 0,
1184 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pFKO
)), pFKO
? SQL_NTS
: 0,
1185 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pFKN
)), SQL_NTS
1187 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1191 void ODatabaseMetaDataResultSet::openImportedKeys(const Any
& catalog
, const OUString
& schema
,
1192 const OUString
& table
) throw(SQLException
, RuntimeException
)
1195 openForeignKeys(Any(),NULL
,NULL
,catalog
, schema
== "%" ? &schema
: NULL
, &table
);
1198 void ODatabaseMetaDataResultSet::openExportedKeys(const Any
& catalog
, const OUString
& schema
,
1199 const OUString
& table
) throw(SQLException
, RuntimeException
)
1201 openForeignKeys(catalog
, schema
== "%" ? &schema
: NULL
, &table
,Any(),NULL
,NULL
);
1204 void ODatabaseMetaDataResultSet::openPrimaryKeys(const Any
& catalog
, const OUString
& schema
,
1205 const OUString
& table
) throw(SQLException
, RuntimeException
)
1207 const OUString
*pSchemaPat
= NULL
;
1210 pSchemaPat
= &schema
;
1214 OString aPKQ
,aPKO
,aPKN
;
1216 if ( catalog
.hasValue() )
1217 aPKQ
= OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
1218 aPKO
= OUStringToOString(schema
,m_nTextEncoding
);
1220 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
1221 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() && !aPKO
.isEmpty() ? aPKO
.getStr() : NULL
,
1222 *pPKN
= (aPKN
= OUStringToOString(table
,m_nTextEncoding
)).getStr();
1225 SQLRETURN nRetcode
= N3SQLPrimaryKeys(m_aStatementHandle
,
1226 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKQ
)), (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
1227 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKO
)), pPKO
? SQL_NTS
: 0 ,
1228 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKN
)), SQL_NTS
);
1229 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1233 void ODatabaseMetaDataResultSet::openTablePrivileges(const Any
& catalog
, const OUString
& schemaPattern
,
1234 const OUString
& tableNamePattern
) throw(SQLException
, RuntimeException
)
1236 const OUString
*pSchemaPat
= NULL
;
1238 if(schemaPattern
!= "%")
1239 pSchemaPat
= &schemaPattern
;
1243 OString aPKQ
,aPKO
,aPKN
;
1245 if ( catalog
.hasValue() )
1246 aPKQ
= OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
1247 aPKO
= OUStringToOString(schemaPattern
,m_nTextEncoding
);
1249 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
1250 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() && !aPKO
.isEmpty() ? aPKO
.getStr() : NULL
,
1251 *pPKN
= (aPKN
= OUStringToOString(tableNamePattern
,m_nTextEncoding
)).getStr();
1254 SQLRETURN nRetcode
= N3SQLTablePrivileges(m_aStatementHandle
,
1255 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKQ
)), (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
1256 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKO
)), pPKO
? SQL_NTS
: 0 ,
1257 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKN
)), SQL_NTS
);
1258 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1262 void ODatabaseMetaDataResultSet::openIndexInfo( const Any
& catalog
, const OUString
& schema
,
1263 const OUString
& table
, bool unique
, bool approximate
)
1264 throw(SQLException
, RuntimeException
)
1266 const OUString
*pSchemaPat
= NULL
;
1269 pSchemaPat
= &schema
;
1273 OString aPKQ
,aPKO
,aPKN
;
1275 if ( catalog
.hasValue() )
1276 aPKQ
= OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
1277 aPKO
= OUStringToOString(schema
,m_nTextEncoding
);
1279 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
1280 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() && !aPKO
.isEmpty() ? aPKO
.getStr() : NULL
,
1281 *pPKN
= (aPKN
= OUStringToOString(table
,m_nTextEncoding
)).getStr();
1284 SQLRETURN nRetcode
= N3SQLStatistics(m_aStatementHandle
,
1285 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKQ
)), (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
1286 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKO
)), pPKO
? SQL_NTS
: 0 ,
1287 reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(pPKN
)), SQL_NTS
,
1288 unique
? SQL_INDEX_UNIQUE
: SQL_INDEX_ALL
,
1289 approximate
? 1 : 0);
1290 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1294 void ODatabaseMetaDataResultSet::checkColumnCount()
1296 sal_Int16 nNumResultCols
=0;
1297 OTools::ThrowException(m_pConnection
,N3SQLNumResultCols(m_aStatementHandle
,&nNumResultCols
),m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1298 m_nDriverColumnCount
= nNumResultCols
;
1302 SWORD
ODatabaseMetaDataResultSet::impl_getColumnType_nothrow(sal_Int32 columnIndex
)
1304 ::std::map
<sal_Int32
,SWORD
>::iterator aFind
= m_aODBCColumnTypes
.find(columnIndex
);
1305 if ( aFind
== m_aODBCColumnTypes
.end() )
1306 aFind
= m_aODBCColumnTypes
.insert(::std::map
<sal_Int32
,SWORD
>::value_type(columnIndex
,OResultSetMetaData::getColumnODBCType(m_pConnection
,m_aStatementHandle
,*this,columnIndex
))).first
;
1307 return aFind
->second
;
1310 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */