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 <com/sun/star/sdbc/ResultSetConcurrency.hpp>
30 #include <com/sun/star/sdbc/ResultSetType.hpp>
31 #include <com/sun/star/sdbc/FetchDirection.hpp>
32 #include <cppuhelper/typeprovider.hxx>
33 #include <comphelper/sequence.hxx>
34 #include "odbc/OResultSetMetaData.hxx"
35 #include "odbc/OTools.hxx"
36 #include <comphelper/types.hxx>
37 #include "FDatabaseMetaDataResultSetMetaData.hxx"
38 #include <connectivity/dbexception.hxx>
40 using namespace ::comphelper
;
43 using namespace connectivity::odbc
;
46 using namespace ::com::sun::star::lang
;
47 using namespace com::sun::star::uno
;
48 using namespace com::sun::star::beans
;
49 using namespace com::sun::star::sdbc
;
50 using namespace com::sun::star::util
;
53 ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet(OConnection
* _pConnection
)
54 :ODatabaseMetaDataResultSet_BASE(m_aMutex
)
55 ,OPropertySetHelper(ODatabaseMetaDataResultSet_BASE::rBHelper
)
57 ,m_aStatementHandle(_pConnection
->createStatementHandle())
60 ,m_pRowStatusArray(NULL
)
61 ,m_pConnection(_pConnection
)
62 ,m_nTextEncoding(_pConnection
->getTextEncoding())
64 ,m_nDriverColumnCount(0)
65 ,m_nCurrentFetchState(0)
69 OSL_ENSURE(m_pConnection
,"ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet: No parent set!");
70 if( SQL_NULL_HANDLE
== m_aStatementHandle
)
71 throw RuntimeException();
73 osl_atomic_increment( &m_refCount
);
74 m_pConnection
->acquire();
75 m_pRowStatusArray
= new SQLUSMALLINT
[1]; // the default value
76 osl_atomic_decrement( &m_refCount
);
81 ODatabaseMetaDataResultSet::~ODatabaseMetaDataResultSet()
83 OSL_ENSURE(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
,"Object wasn't disposed!");
84 if(!ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
)
86 osl_atomic_increment( &m_refCount
);
89 delete [] m_pRowStatusArray
;
92 void ODatabaseMetaDataResultSet::disposing(void)
94 OPropertySetHelper::disposing();
96 ::osl::MutexGuard
aGuard(m_aMutex
);
98 m_pConnection
->freeStatementHandle(m_aStatementHandle
);
102 m_pConnection
->release();
105 Any SAL_CALL
ODatabaseMetaDataResultSet::queryInterface( const Type
& rType
) throw(RuntimeException
, std::exception
)
107 Any aRet
= OPropertySetHelper::queryInterface(rType
);
108 return aRet
.hasValue() ? aRet
: ODatabaseMetaDataResultSet_BASE::queryInterface(rType
);
111 Reference
< XPropertySetInfo
> SAL_CALL
ODatabaseMetaDataResultSet::getPropertySetInfo( ) throw(RuntimeException
, std::exception
)
113 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
116 void SAL_CALL
ODatabaseMetaDataResultSet::acquire() throw()
118 ODatabaseMetaDataResultSet_BASE::acquire();
121 void SAL_CALL
ODatabaseMetaDataResultSet::release() throw()
123 ODatabaseMetaDataResultSet_BASE::release();
126 Sequence
< Type
> SAL_CALL
ODatabaseMetaDataResultSet::getTypes( ) throw(RuntimeException
, std::exception
)
128 ::cppu::OTypeCollection
aTypes( ::getCppuType( (const Reference
< XMultiPropertySet
> *)0 ),
129 ::getCppuType( (const Reference
< XFastPropertySet
> *)0 ),
130 ::getCppuType( (const Reference
< XPropertySet
> *)0 ));
132 return ::comphelper::concatSequences(aTypes
.getTypes(),ODatabaseMetaDataResultSet_BASE::getTypes());
135 sal_Int32
ODatabaseMetaDataResultSet::mapColumn (sal_Int32 column
)
137 sal_Int32 map
= column
;
139 if (!m_aColMapping
.empty())
141 // Validate column number
142 map
= m_aColMapping
[column
];
149 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSet::findColumn( const OUString
& columnName
) throw(SQLException
, RuntimeException
, std::exception
)
152 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
153 ::osl::MutexGuard
aGuard( m_aMutex
);
156 Reference
< XResultSetMetaData
> xMeta
= getMetaData();
157 sal_Int32 nLen
= xMeta
->getColumnCount();
161 if(xMeta
->isCaseSensitive(i
) ? columnName
== xMeta
->getColumnName(i
) :
162 columnName
.equalsIgnoreAsciiCase(xMeta
->getColumnName(i
)))
166 ::dbtools::throwInvalidColumnException( columnName
, *this );
168 return 0; // Never reached
171 template < typename T
, SQLSMALLINT sqlTypeId
> T
ODatabaseMetaDataResultSet::getInteger ( sal_Int32 columnIndex
)
173 ::cppu::OBroadcastHelper
& rBHelper(ODatabaseMetaDataResultSet_BASE::rBHelper
);
174 checkDisposed(rBHelper
.bDisposed
);
175 ::osl::MutexGuard
aGuard( m_aMutex
);
177 columnIndex
= mapColumn(columnIndex
);
179 if(columnIndex
<= m_nDriverColumnCount
)
181 getValue
<T
>(m_pConnection
, m_aStatementHandle
, columnIndex
, sqlTypeId
, m_bWasNull
, **this, nVal
);
183 if ( !m_aValueRange
.empty() )
185 ::std::map
<sal_Int32
, ::connectivity::TInt2IntMap
>::iterator
aValueRangeIter (m_aValueRange
.find(columnIndex
));
186 if ( aValueRangeIter
!= m_aValueRange
.end() )
187 return static_cast<T
>(aValueRangeIter
->second
[nVal
]);
196 Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
ODatabaseMetaDataResultSet::getBinaryStream( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
, std::exception
)
198 ::dbtools::throwFunctionNotSupportedException( "XRow::getBinaryStream", *this );
202 Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
ODatabaseMetaDataResultSet::getCharacterStream( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
, std::exception
)
204 ::dbtools::throwFunctionNotSupportedException( "XRow::getCharacterStream", *this );
209 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::getBoolean( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
212 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
213 ::osl::MutexGuard
aGuard( m_aMutex
);
215 columnIndex
= mapColumn(columnIndex
);
218 if(columnIndex
<= m_nDriverColumnCount
)
220 sal_Int32 nType
= getMetaData()->getColumnType(columnIndex
);
226 OTools::getValue(m_pConnection
,m_aStatementHandle
,columnIndex
,SQL_C_BIT
,m_bWasNull
,**this,&nValue
,sizeof nValue
);
231 bRet
= getInt(columnIndex
) != 0;
238 sal_Int8 SAL_CALL
ODatabaseMetaDataResultSet::getByte( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
240 return getInteger
<sal_Int8
, SQL_C_STINYINT
>( columnIndex
);
244 Sequence
< sal_Int8
> SAL_CALL
ODatabaseMetaDataResultSet::getBytes( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
247 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
248 ::osl::MutexGuard
aGuard( m_aMutex
);
251 columnIndex
= mapColumn(columnIndex
);
252 if(columnIndex
<= m_nDriverColumnCount
)
254 sal_Int32 nType
= getMetaData()->getColumnType(columnIndex
);
258 case DataType::VARCHAR
:
259 case DataType::LONGVARCHAR
:
261 OUString aRet
= OTools::getStringValue(m_pConnection
,m_aStatementHandle
,columnIndex
,SQL_C_BINARY
,m_bWasNull
,**this,m_nTextEncoding
);
262 return Sequence
<sal_Int8
>(reinterpret_cast<const sal_Int8
*>(aRet
.getStr()),sizeof(sal_Unicode
)*aRet
.getLength());
265 return OTools::getBytesValue(m_pConnection
,m_aStatementHandle
,columnIndex
,SQL_C_BINARY
,m_bWasNull
,**this);
269 return Sequence
<sal_Int8
>();
273 ::com::sun::star::util::Date SAL_CALL
ODatabaseMetaDataResultSet::getDate( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
275 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
276 ::osl::MutexGuard
aGuard( m_aMutex
);
279 columnIndex
= mapColumn(columnIndex
);
280 if(columnIndex
<= m_nDriverColumnCount
)
286 OTools::getValue(m_pConnection
,m_aStatementHandle
,columnIndex
,m_pConnection
->useOldDateFormat() ? SQL_C_DATE
: SQL_C_TYPE_DATE
,m_bWasNull
,**this,&aDate
,sizeof aDate
);
287 return Date(aDate
.day
,aDate
.month
,aDate
.year
);
295 double SAL_CALL
ODatabaseMetaDataResultSet::getDouble( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
298 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
299 ::osl::MutexGuard
aGuard( m_aMutex
);
302 columnIndex
= mapColumn(columnIndex
);
304 if(columnIndex
<= m_nDriverColumnCount
)
305 OTools::getValue(m_pConnection
,m_aStatementHandle
,columnIndex
,SQL_C_DOUBLE
,m_bWasNull
,**this,&nValue
,sizeof nValue
);
312 float SAL_CALL
ODatabaseMetaDataResultSet::getFloat( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
315 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
316 ::osl::MutexGuard
aGuard( m_aMutex
);
319 columnIndex
= mapColumn(columnIndex
);
321 if(columnIndex
<= m_nDriverColumnCount
)
322 OTools::getValue(m_pConnection
,m_aStatementHandle
,columnIndex
,SQL_C_FLOAT
,m_bWasNull
,**this,&nVal
,sizeof nVal
);
329 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSet::getInt( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
331 return getInteger
<sal_Int32
, SQL_C_SLONG
>( columnIndex
);
335 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSet::getRow( ) throw(SQLException
, RuntimeException
, std::exception
)
341 sal_Int64 SAL_CALL
ODatabaseMetaDataResultSet::getLong( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
343 return getInteger
<sal_Int64
, SQL_C_SBIGINT
>( columnIndex
);
347 Reference
< XResultSetMetaData
> SAL_CALL
ODatabaseMetaDataResultSet::getMetaData( ) throw(SQLException
, RuntimeException
, std::exception
)
349 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
350 ::osl::MutexGuard
aGuard( m_aMutex
);
351 return m_xMetaData
.is() ? m_xMetaData
: (m_xMetaData
= new OResultSetMetaData(m_pConnection
,m_aStatementHandle
));
354 Reference
< XArray
> SAL_CALL
ODatabaseMetaDataResultSet::getArray( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
, std::exception
)
356 ::dbtools::throwFunctionNotSupportedException( "XRow::getArray", *this );
360 Reference
< XClob
> SAL_CALL
ODatabaseMetaDataResultSet::getClob( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
, std::exception
)
362 ::dbtools::throwFunctionNotSupportedException( "XRow::getClob", *this );
366 Reference
< XBlob
> SAL_CALL
ODatabaseMetaDataResultSet::getBlob( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
, std::exception
)
368 ::dbtools::throwFunctionNotSupportedException( "XRow::getBlob", *this );
373 Reference
< XRef
> SAL_CALL
ODatabaseMetaDataResultSet::getRef( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
, std::exception
)
375 ::dbtools::throwFunctionNotSupportedException( "XRow::getRef", *this );
380 Any SAL_CALL
ODatabaseMetaDataResultSet::getObject( sal_Int32
/*columnIndex*/, const Reference
< ::com::sun::star::container::XNameAccess
>& /*typeMap*/ ) throw(SQLException
, RuntimeException
, std::exception
)
382 ::dbtools::throwFunctionNotSupportedException( "XRow::getObject", *this );
387 sal_Int16 SAL_CALL
ODatabaseMetaDataResultSet::getShort( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
389 return getInteger
<sal_Int16
, SQL_C_SSHORT
>( columnIndex
);
393 OUString SAL_CALL
ODatabaseMetaDataResultSet::getString( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
396 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
397 ::osl::MutexGuard
aGuard( m_aMutex
);
400 columnIndex
= mapColumn(columnIndex
);
402 if(columnIndex
<= m_nDriverColumnCount
)
403 aVal
= OTools::getStringValue(m_pConnection
,m_aStatementHandle
,columnIndex
,impl_getColumnType_nothrow(columnIndex
),m_bWasNull
,**this,m_nTextEncoding
);
413 ::com::sun::star::util::Time SAL_CALL
ODatabaseMetaDataResultSet::getTime( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
416 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
417 ::osl::MutexGuard
aGuard( m_aMutex
);
420 columnIndex
= mapColumn(columnIndex
);
421 TIME_STRUCT aTime
={0,0,0};
422 if(columnIndex
<= m_nDriverColumnCount
)
423 OTools::getValue(m_pConnection
,m_aStatementHandle
,columnIndex
,m_pConnection
->useOldDateFormat() ? SQL_C_TIME
: SQL_C_TYPE_TIME
,m_bWasNull
,**this,&aTime
,sizeof aTime
);
426 return Time(0, aTime
.second
,aTime
.minute
,aTime
.hour
, false);
431 ::com::sun::star::util::DateTime SAL_CALL
ODatabaseMetaDataResultSet::getTimestamp( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
, std::exception
)
434 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
435 ::osl::MutexGuard
aGuard( m_aMutex
);
438 columnIndex
= mapColumn(columnIndex
);
439 TIMESTAMP_STRUCT aTime
={0,0,0,0,0,0,0};
440 if(columnIndex
<= m_nDriverColumnCount
)
441 OTools::getValue(m_pConnection
,m_aStatementHandle
,columnIndex
,m_pConnection
->useOldDateFormat() ? SQL_C_TIMESTAMP
: SQL_C_TYPE_TIMESTAMP
, m_bWasNull
, **this, &aTime
, sizeof aTime
);
444 return DateTime(aTime
.fraction
, aTime
.second
, aTime
.minute
, aTime
.hour
,
445 aTime
.day
, aTime
.month
, aTime
.year
, false);
449 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::isAfterLast( ) throw(SQLException
, RuntimeException
, std::exception
)
452 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
453 ::osl::MutexGuard
aGuard( m_aMutex
);
456 return m_nCurrentFetchState
== SQL_NO_DATA
;
459 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::isFirst( ) throw(SQLException
, RuntimeException
, std::exception
)
462 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
463 ::osl::MutexGuard
aGuard( m_aMutex
);
466 return m_nRowPos
== 1;
469 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::isLast( ) throw(SQLException
, RuntimeException
, std::exception
)
472 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
473 ::osl::MutexGuard
aGuard( m_aMutex
);
476 return m_bEOF
&& m_nCurrentFetchState
!= SQL_NO_DATA
;
479 void SAL_CALL
ODatabaseMetaDataResultSet::beforeFirst( ) throw(SQLException
, RuntimeException
, std::exception
)
482 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
483 ::osl::MutexGuard
aGuard( m_aMutex
);
488 m_nCurrentFetchState
= SQL_SUCCESS
;
491 void SAL_CALL
ODatabaseMetaDataResultSet::afterLast( ) throw(SQLException
, RuntimeException
, std::exception
)
494 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
495 ::osl::MutexGuard
aGuard( m_aMutex
);
503 void SAL_CALL
ODatabaseMetaDataResultSet::close( ) throw(SQLException
, RuntimeException
, std::exception
)
507 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
508 ::osl::MutexGuard
aGuard( m_aMutex
);
515 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::first( ) throw(SQLException
, RuntimeException
, std::exception
)
518 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
519 ::osl::MutexGuard
aGuard( m_aMutex
);
523 m_nCurrentFetchState
= N3SQLFetchScroll(m_aStatementHandle
,SQL_FETCH_FIRST
,0);
524 OTools::ThrowException(m_pConnection
,m_nCurrentFetchState
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
525 bool bRet
= ( m_nCurrentFetchState
== SQL_SUCCESS
|| m_nCurrentFetchState
== SQL_SUCCESS_WITH_INFO
);
532 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::last( ) throw(SQLException
, RuntimeException
, std::exception
)
534 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
535 ::osl::MutexGuard
aGuard( m_aMutex
);
538 m_nCurrentFetchState
= N3SQLFetchScroll(m_aStatementHandle
,SQL_FETCH_LAST
,0);
539 OTools::ThrowException(m_pConnection
,m_nCurrentFetchState
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
540 // here I know definitely that I stand on the last record
541 bool bRet
= ( m_nCurrentFetchState
== SQL_SUCCESS
|| m_nCurrentFetchState
== SQL_SUCCESS_WITH_INFO
);
547 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::absolute( sal_Int32 row
) throw(SQLException
, RuntimeException
, std::exception
)
550 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
551 ::osl::MutexGuard
aGuard( m_aMutex
);
555 m_nCurrentFetchState
= N3SQLFetchScroll(m_aStatementHandle
,SQL_FETCH_ABSOLUTE
,row
);
556 OTools::ThrowException(m_pConnection
,m_nCurrentFetchState
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
557 bool bRet
= m_nCurrentFetchState
== SQL_SUCCESS
|| m_nCurrentFetchState
== SQL_SUCCESS_WITH_INFO
;
563 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::relative( sal_Int32 row
) throw(SQLException
, RuntimeException
, std::exception
)
566 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
567 ::osl::MutexGuard
aGuard( m_aMutex
);
571 m_nCurrentFetchState
= N3SQLFetchScroll(m_aStatementHandle
,SQL_FETCH_RELATIVE
,row
);
572 OTools::ThrowException(m_pConnection
,m_nCurrentFetchState
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
573 bool bRet
= m_nCurrentFetchState
== SQL_SUCCESS
|| m_nCurrentFetchState
== SQL_SUCCESS_WITH_INFO
;
579 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::previous( ) throw(SQLException
, RuntimeException
, std::exception
)
582 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
583 ::osl::MutexGuard
aGuard( m_aMutex
);
587 m_nCurrentFetchState
= N3SQLFetchScroll(m_aStatementHandle
,SQL_FETCH_PRIOR
,0);
588 OTools::ThrowException(m_pConnection
,m_nCurrentFetchState
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
589 bool bRet
= m_nCurrentFetchState
== SQL_SUCCESS
|| m_nCurrentFetchState
== SQL_SUCCESS_WITH_INFO
;
592 else if ( m_nCurrentFetchState
== SQL_NO_DATA
)
597 Reference
< XInterface
> SAL_CALL
ODatabaseMetaDataResultSet::getStatement( ) throw(SQLException
, RuntimeException
, std::exception
)
603 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::rowDeleted( ) throw(SQLException
, RuntimeException
, std::exception
)
606 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
607 ::osl::MutexGuard
aGuard( m_aMutex
);
610 return m_pRowStatusArray
[0] == SQL_ROW_DELETED
;
613 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::rowInserted( ) throw(SQLException
, RuntimeException
, std::exception
)
615 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
616 ::osl::MutexGuard
aGuard( m_aMutex
);
619 return m_pRowStatusArray
[0] == SQL_ROW_ADDED
;
622 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::rowUpdated( ) throw(SQLException
, RuntimeException
, std::exception
)
625 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
626 ::osl::MutexGuard
aGuard( m_aMutex
);
629 return m_pRowStatusArray
[0] == SQL_ROW_UPDATED
;
633 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::isBeforeFirst( ) throw(SQLException
, RuntimeException
, std::exception
)
636 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
637 ::osl::MutexGuard
aGuard( m_aMutex
);
640 return m_nRowPos
== 0;
644 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::next( ) throw(SQLException
, RuntimeException
, std::exception
)
647 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
648 ::osl::MutexGuard
aGuard( m_aMutex
);
652 SQLRETURN nOldFetchStatus
= m_nCurrentFetchState
;
653 // m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_NEXT,0);
654 m_nCurrentFetchState
= N3SQLFetch(m_aStatementHandle
);
655 OTools::ThrowException(m_pConnection
,m_nCurrentFetchState
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
656 bool bRet
= m_nCurrentFetchState
== SQL_SUCCESS
|| m_nCurrentFetchState
== SQL_SUCCESS_WITH_INFO
;
657 if(bRet
|| ( m_nCurrentFetchState
== SQL_NO_DATA
&& nOldFetchStatus
!= SQL_NO_DATA
) )
663 sal_Bool SAL_CALL
ODatabaseMetaDataResultSet::wasNull( ) throw(SQLException
, RuntimeException
, std::exception
)
666 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
667 ::osl::MutexGuard
aGuard( m_aMutex
);
673 void SAL_CALL
ODatabaseMetaDataResultSet::refreshRow( ) throw(SQLException
, RuntimeException
, std::exception
)
676 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
677 ::osl::MutexGuard
aGuard( m_aMutex
);
682 void SAL_CALL
ODatabaseMetaDataResultSet::cancel( ) throw(RuntimeException
, std::exception
)
685 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
686 ::osl::MutexGuard
aGuard( m_aMutex
);
689 OTools::ThrowException(m_pConnection
,N3SQLCancel(m_aStatementHandle
),m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
692 void SAL_CALL
ODatabaseMetaDataResultSet::clearWarnings( ) throw(SQLException
, RuntimeException
, std::exception
)
696 Any SAL_CALL
ODatabaseMetaDataResultSet::getWarnings( ) throw(SQLException
, RuntimeException
, std::exception
)
701 sal_Int32
ODatabaseMetaDataResultSet::getResultSetConcurrency() const throw(SQLException
, RuntimeException
)
703 return ResultSetConcurrency::READ_ONLY
;
706 sal_Int32
ODatabaseMetaDataResultSet::getResultSetType() const throw(SQLException
, RuntimeException
)
708 return ResultSetType::FORWARD_ONLY
;
711 sal_Int32
ODatabaseMetaDataResultSet::getFetchDirection() const throw(SQLException
, RuntimeException
)
713 return FetchDirection::FORWARD
;
716 sal_Int32
ODatabaseMetaDataResultSet::getFetchSize() const throw(SQLException
, RuntimeException
)
722 OUString
ODatabaseMetaDataResultSet::getCursorName() const throw(SQLException
, RuntimeException
)
728 ::cppu::IPropertyArrayHelper
* ODatabaseMetaDataResultSet::createArrayHelper( ) const
731 Sequence
< com::sun::star::beans::Property
> aProps(5);
732 com::sun::star::beans::Property
* pProperties
= aProps
.getArray();
734 pProperties
[nPos
++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME
),
735 PROPERTY_ID_CURSORNAME
, cppu::UnoType
<OUString
>::get(), 0);
736 pProperties
[nPos
++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION
),
737 PROPERTY_ID_FETCHDIRECTION
, cppu::UnoType
<sal_Int32
>::get(), 0);
738 pProperties
[nPos
++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE
),
739 PROPERTY_ID_FETCHSIZE
, cppu::UnoType
<sal_Int32
>::get(), 0);
740 pProperties
[nPos
++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY
),
741 PROPERTY_ID_RESULTSETCONCURRENCY
, cppu::UnoType
<sal_Int32
>::get(), 0);
742 pProperties
[nPos
++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE
),
743 PROPERTY_ID_RESULTSETTYPE
, cppu::UnoType
<sal_Int32
>::get(), 0);
745 return new ::cppu::OPropertyArrayHelper(aProps
);
748 ::cppu::IPropertyArrayHelper
& ODatabaseMetaDataResultSet::getInfoHelper()
750 return *const_cast<ODatabaseMetaDataResultSet
*>(this)->getArrayHelper();
753 sal_Bool
ODatabaseMetaDataResultSet::convertFastPropertyValue(
754 Any
& rConvertedValue
,
758 throw (::com::sun::star::lang::IllegalArgumentException
)
762 case PROPERTY_ID_CURSORNAME
:
763 case PROPERTY_ID_RESULTSETCONCURRENCY
:
764 case PROPERTY_ID_RESULTSETTYPE
:
765 throw ::com::sun::star::lang::IllegalArgumentException();
766 case PROPERTY_ID_FETCHDIRECTION
:
767 return ::comphelper::tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, getFetchDirection());
768 case PROPERTY_ID_FETCHSIZE
:
769 return ::comphelper::tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, getFetchSize());
776 void ODatabaseMetaDataResultSet::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
, const Any
& /*rValue*/ ) throw (Exception
, std::exception
)
780 case PROPERTY_ID_CURSORNAME
:
781 case PROPERTY_ID_RESULTSETCONCURRENCY
:
782 case PROPERTY_ID_RESULTSETTYPE
:
783 case PROPERTY_ID_FETCHDIRECTION
:
784 case PROPERTY_ID_FETCHSIZE
:
787 OSL_FAIL("setFastPropertyValue_NoBroadcast: Illegal handle value!");
791 void ODatabaseMetaDataResultSet::getFastPropertyValue( Any
& rValue
, sal_Int32 nHandle
) const
795 case PROPERTY_ID_CURSORNAME
:
796 rValue
<<= getCursorName();
798 case PROPERTY_ID_RESULTSETCONCURRENCY
:
799 rValue
<<= getResultSetConcurrency();
801 case PROPERTY_ID_RESULTSETTYPE
:
802 rValue
<<= getResultSetType();
804 case PROPERTY_ID_FETCHDIRECTION
:
805 rValue
<<= getFetchDirection();
807 case PROPERTY_ID_FETCHSIZE
:
808 rValue
<<= getFetchSize();
813 void ODatabaseMetaDataResultSet::openTypeInfo() throw(SQLException
, RuntimeException
)
816 aMap
[SQL_BIT
] = DataType::BIT
;
817 aMap
[SQL_TINYINT
] = DataType::TINYINT
;
818 aMap
[SQL_SMALLINT
] = DataType::SMALLINT
;
819 aMap
[SQL_INTEGER
] = DataType::INTEGER
;
820 aMap
[SQL_FLOAT
] = DataType::FLOAT
;
821 aMap
[SQL_REAL
] = DataType::REAL
;
822 aMap
[SQL_DOUBLE
] = DataType::DOUBLE
;
823 aMap
[SQL_BIGINT
] = DataType::BIGINT
;
825 aMap
[SQL_CHAR
] = DataType::CHAR
;
826 aMap
[SQL_WCHAR
] = DataType::CHAR
;
827 aMap
[SQL_VARCHAR
] = DataType::VARCHAR
;
828 aMap
[SQL_WVARCHAR
] = DataType::VARCHAR
;
829 aMap
[SQL_LONGVARCHAR
] = DataType::LONGVARCHAR
;
830 aMap
[SQL_WLONGVARCHAR
] = DataType::LONGVARCHAR
;
832 aMap
[SQL_TYPE_DATE
] = DataType::DATE
;
833 aMap
[SQL_DATE
] = DataType::DATE
;
834 aMap
[SQL_TYPE_TIME
] = DataType::TIME
;
835 aMap
[SQL_TIME
] = DataType::TIME
;
836 aMap
[SQL_TYPE_TIMESTAMP
] = DataType::TIMESTAMP
;
837 aMap
[SQL_TIMESTAMP
] = DataType::TIMESTAMP
;
839 aMap
[SQL_DECIMAL
] = DataType::DECIMAL
;
840 aMap
[SQL_NUMERIC
] = DataType::NUMERIC
;
842 aMap
[SQL_BINARY
] = DataType::BINARY
;
843 aMap
[SQL_VARBINARY
] = DataType::VARBINARY
;
844 aMap
[SQL_LONGVARBINARY
] = DataType::LONGVARBINARY
;
846 aMap
[SQL_GUID
] = DataType::VARBINARY
;
849 m_aValueRange
[2] = aMap
;
851 OTools::ThrowException(m_pConnection
,N3SQLGetTypeInfo(m_aStatementHandle
, SQL_ALL_TYPES
),m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
855 void ODatabaseMetaDataResultSet::openTables(const Any
& catalog
, const OUString
& schemaPattern
,
856 const OUString
& tableNamePattern
,
857 const Sequence
< OUString
>& types
) throw(SQLException
, RuntimeException
)
859 OString aPKQ
,aPKO
,aPKN
,aCOL
;
860 const OUString
*pSchemaPat
= NULL
;
862 if(schemaPattern
!= "%")
863 pSchemaPat
= &schemaPattern
;
867 if ( catalog
.hasValue() )
868 aPKQ
= OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
869 aPKO
= OUStringToOString(schemaPattern
,m_nTextEncoding
);
870 aPKN
= OUStringToOString(tableNamePattern
,m_nTextEncoding
);
872 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
873 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() && !aPKO
.isEmpty() ? aPKO
.getStr() : NULL
,
874 *pPKN
= aPKN
.getStr();
877 const char *pCOL
= NULL
;
878 const char* pComma
= ",";
879 const OUString
* pBegin
= types
.getConstArray();
880 const OUString
* pEnd
= pBegin
+ types
.getLength();
881 for(;pBegin
!= pEnd
;++pBegin
)
883 aCOL
+= OUStringToOString(*pBegin
,m_nTextEncoding
);
886 if ( !aCOL
.isEmpty() )
888 aCOL
= aCOL
.replaceAt(aCOL
.getLength()-1,1,pComma
);
889 pCOL
= aCOL
.getStr();
892 pCOL
= SQL_ALL_TABLE_TYPES
;
894 SQLRETURN nRetcode
= N3SQLTables(m_aStatementHandle
,
895 (SDB_ODBC_CHAR
*) pPKQ
, (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
896 (SDB_ODBC_CHAR
*) pPKO
, pPKO
? SQL_NTS
: 0,
897 (SDB_ODBC_CHAR
*) pPKN
, SQL_NTS
,
898 (SDB_ODBC_CHAR
*) pCOL
, pCOL
? SQL_NTS
: 0);
899 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
904 void ODatabaseMetaDataResultSet::openTablesTypes( ) throw(SQLException
, RuntimeException
)
906 SQLRETURN nRetcode
= N3SQLTables(m_aStatementHandle
,
910 (SDB_ODBC_CHAR
*) SQL_ALL_TABLE_TYPES
,SQL_NTS
);
911 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
913 m_aColMapping
.clear();
914 m_aColMapping
.push_back(-1);
915 m_aColMapping
.push_back(4);
916 m_xMetaData
= new OResultSetMetaData(m_pConnection
,m_aStatementHandle
,m_aColMapping
);
920 void ODatabaseMetaDataResultSet::openCatalogs() throw(SQLException
, RuntimeException
)
922 SQLRETURN nRetcode
= N3SQLTables(m_aStatementHandle
,
923 (SDB_ODBC_CHAR
*) SQL_ALL_CATALOGS
,SQL_NTS
,
924 (SDB_ODBC_CHAR
*) "",SQL_NTS
,
925 (SDB_ODBC_CHAR
*) "",SQL_NTS
,
926 (SDB_ODBC_CHAR
*) "",SQL_NTS
);
928 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
930 m_aColMapping
.clear();
931 m_aColMapping
.push_back(-1);
932 m_aColMapping
.push_back(1);
933 m_xMetaData
= new OResultSetMetaData(m_pConnection
,m_aStatementHandle
,m_aColMapping
);
937 void ODatabaseMetaDataResultSet::openSchemas() throw(SQLException
, RuntimeException
)
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
);
953 void ODatabaseMetaDataResultSet::openColumnPrivileges( const Any
& catalog
, const OUString
& schema
,
954 const OUString
& table
, const OUString
& columnNamePattern
)
955 throw(SQLException
, RuntimeException
)
957 const OUString
*pSchemaPat
= NULL
;
960 pSchemaPat
= &schema
;
964 OString aPKQ
,aPKO
,aPKN
,aCOL
;
966 if ( catalog
.hasValue() )
967 aPKQ
= OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
968 aPKO
= OUStringToOString(schema
,m_nTextEncoding
);
969 aPKN
= OUStringToOString(table
,m_nTextEncoding
);
970 aCOL
= OUStringToOString(columnNamePattern
,m_nTextEncoding
);
972 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
973 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() && !aPKO
.isEmpty() ? aPKO
.getStr() : NULL
,
974 *pPKN
= aPKN
.getStr(),
975 *pCOL
= aCOL
.getStr();
978 SQLRETURN nRetcode
= N3SQLColumnPrivileges(m_aStatementHandle
,
979 (SDB_ODBC_CHAR
*) pPKQ
, (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
980 (SDB_ODBC_CHAR
*) pPKO
, pPKO
? SQL_NTS
: 0 ,
981 (SDB_ODBC_CHAR
*) pPKN
, SQL_NTS
,
982 (SDB_ODBC_CHAR
*) pCOL
, SQL_NTS
);
983 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
988 void ODatabaseMetaDataResultSet::openColumns( const Any
& catalog
, const OUString
& schemaPattern
,
989 const OUString
& tableNamePattern
, const OUString
& columnNamePattern
)
990 throw(SQLException
, RuntimeException
)
992 const OUString
*pSchemaPat
= NULL
;
994 if(schemaPattern
!= "%")
995 pSchemaPat
= &schemaPattern
;
999 OString aPKQ
,aPKO
,aPKN
,aCOL
;
1000 if ( catalog
.hasValue() )
1001 aPKQ
= OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
1002 aPKO
= OUStringToOString(schemaPattern
,m_nTextEncoding
);
1003 aPKN
= OUStringToOString(tableNamePattern
,m_nTextEncoding
);
1004 aCOL
= OUStringToOString(columnNamePattern
,m_nTextEncoding
);
1006 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
1007 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() && !aPKO
.isEmpty() ? aPKO
.getStr() : NULL
,
1008 *pPKN
= aPKN
.getStr(),
1009 *pCOL
= aCOL
.getStr();
1012 SQLRETURN nRetcode
= N3SQLColumns(m_aStatementHandle
,
1013 (SDB_ODBC_CHAR
*) pPKQ
, (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
1014 (SDB_ODBC_CHAR
*) pPKO
, pPKO
? SQL_NTS
: 0,
1015 (SDB_ODBC_CHAR
*) pPKN
, SQL_NTS
,
1016 (SDB_ODBC_CHAR
*) pCOL
, SQL_NTS
);
1018 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1020 aMap
[SQL_BIT
] = DataType::BIT
;
1021 aMap
[SQL_TINYINT
] = DataType::TINYINT
;
1022 aMap
[SQL_SMALLINT
] = DataType::SMALLINT
;
1023 aMap
[SQL_INTEGER
] = DataType::INTEGER
;
1024 aMap
[SQL_FLOAT
] = DataType::FLOAT
;
1025 aMap
[SQL_REAL
] = DataType::REAL
;
1026 aMap
[SQL_DOUBLE
] = DataType::DOUBLE
;
1027 aMap
[SQL_BIGINT
] = DataType::BIGINT
;
1029 aMap
[SQL_CHAR
] = DataType::CHAR
;
1030 aMap
[SQL_WCHAR
] = DataType::CHAR
;
1031 aMap
[SQL_VARCHAR
] = DataType::VARCHAR
;
1032 aMap
[SQL_WVARCHAR
] = DataType::VARCHAR
;
1033 aMap
[SQL_LONGVARCHAR
] = DataType::LONGVARCHAR
;
1034 aMap
[SQL_WLONGVARCHAR
] = DataType::LONGVARCHAR
;
1036 aMap
[SQL_TYPE_DATE
] = DataType::DATE
;
1037 aMap
[SQL_DATE
] = DataType::DATE
;
1038 aMap
[SQL_TYPE_TIME
] = DataType::TIME
;
1039 aMap
[SQL_TIME
] = DataType::TIME
;
1040 aMap
[SQL_TYPE_TIMESTAMP
] = DataType::TIMESTAMP
;
1041 aMap
[SQL_TIMESTAMP
] = DataType::TIMESTAMP
;
1043 aMap
[SQL_DECIMAL
] = DataType::DECIMAL
;
1044 aMap
[SQL_NUMERIC
] = DataType::NUMERIC
;
1046 aMap
[SQL_BINARY
] = DataType::BINARY
;
1047 aMap
[SQL_VARBINARY
] = DataType::VARBINARY
;
1048 aMap
[SQL_LONGVARBINARY
] = DataType::LONGVARBINARY
;
1050 aMap
[SQL_GUID
] = DataType::VARBINARY
;
1052 m_aValueRange
[5] = aMap
;
1056 void ODatabaseMetaDataResultSet::openProcedureColumns( const Any
& catalog
, const OUString
& schemaPattern
,
1057 const OUString
& procedureNamePattern
,const OUString
& columnNamePattern
)
1058 throw(SQLException
, RuntimeException
)
1060 const OUString
*pSchemaPat
= NULL
;
1062 if(schemaPattern
!= "%")
1063 pSchemaPat
= &schemaPattern
;
1067 OString aPKQ
,aPKO
,aPKN
,aCOL
;
1068 if ( catalog
.hasValue() )
1069 aPKQ
= OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
1070 aPKO
= OUStringToOString(schemaPattern
,m_nTextEncoding
);
1071 aPKN
= OUStringToOString(procedureNamePattern
,m_nTextEncoding
);
1072 aCOL
= OUStringToOString(columnNamePattern
,m_nTextEncoding
);
1074 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
1075 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() && !aPKO
.isEmpty() ? aPKO
.getStr() : NULL
,
1076 *pPKN
= aPKN
.getStr(),
1077 *pCOL
= aCOL
.getStr();
1080 SQLRETURN nRetcode
= N3SQLProcedureColumns(m_aStatementHandle
,
1081 (SDB_ODBC_CHAR
*) pPKQ
, (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
1082 (SDB_ODBC_CHAR
*) pPKO
, pPKO
? SQL_NTS
: 0 ,
1083 (SDB_ODBC_CHAR
*) pPKN
, SQL_NTS
,
1084 (SDB_ODBC_CHAR
*) pCOL
, SQL_NTS
);
1086 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1090 void ODatabaseMetaDataResultSet::openProcedures(const Any
& catalog
, const OUString
& schemaPattern
,
1091 const OUString
& procedureNamePattern
)
1092 throw(SQLException
, RuntimeException
)
1094 const OUString
*pSchemaPat
= NULL
;
1096 if(schemaPattern
!= "%")
1097 pSchemaPat
= &schemaPattern
;
1101 OString aPKQ
,aPKO
,aPKN
;
1103 if ( catalog
.hasValue() )
1104 aPKQ
= OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
1105 aPKO
= OUStringToOString(schemaPattern
,m_nTextEncoding
);
1106 aPKN
= OUStringToOString(procedureNamePattern
,m_nTextEncoding
);
1108 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
1109 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() && !aPKO
.isEmpty() ? aPKO
.getStr() : NULL
,
1110 *pPKN
= aPKN
.getStr();
1113 SQLRETURN nRetcode
= N3SQLProcedures(m_aStatementHandle
,
1114 (SDB_ODBC_CHAR
*) pPKQ
, (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
1115 (SDB_ODBC_CHAR
*) pPKO
, pPKO
? SQL_NTS
: 0 ,
1116 (SDB_ODBC_CHAR
*) pPKN
, SQL_NTS
);
1117 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1121 void ODatabaseMetaDataResultSet::openSpecialColumns(bool _bRowVer
,const Any
& catalog
, const OUString
& schema
,
1122 const OUString
& table
,sal_Int32 scope
, bool nullable
)
1123 throw(SQLException
, RuntimeException
)
1125 // Some ODBC drivers really don't like getting an empty string as tableName
1126 // E.g. psqlodbc up to at least version 09.01.0100 segfaults
1127 if (table
.isEmpty())
1129 const char errMsg
[] = "ODBC: Trying to get special columns of empty table name";
1130 const char SQLState
[] = "HY009";
1131 throw SQLException( OUString(errMsg
, sizeof(errMsg
) - sizeof(errMsg
[0]), RTL_TEXTENCODING_ASCII_US
),
1133 OUString(SQLState
, sizeof(SQLState
) - sizeof(SQLState
[0]), RTL_TEXTENCODING_ASCII_US
),
1138 const OUString
*pSchemaPat
= NULL
;
1141 pSchemaPat
= &schema
;
1145 OString aPKQ
,aPKO
,aPKN
;
1146 if ( catalog
.hasValue() )
1147 aPKQ
= OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
1148 aPKO
= OUStringToOString(schema
,m_nTextEncoding
);
1149 aPKN
= OUStringToOString(table
,m_nTextEncoding
);
1151 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
1152 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() && !aPKO
.isEmpty() ? aPKO
.getStr() : NULL
,
1153 *pPKN
= aPKN
.getStr();
1156 SQLRETURN nRetcode
= N3SQLSpecialColumns(m_aStatementHandle
,_bRowVer
? SQL_ROWVER
: SQL_BEST_ROWID
,
1157 (SDB_ODBC_CHAR
*) pPKQ
, (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
1158 (SDB_ODBC_CHAR
*) pPKO
, pPKO
? SQL_NTS
: 0 ,
1159 (SDB_ODBC_CHAR
*) pPKN
, SQL_NTS
,
1161 nullable
? SQL_NULLABLE
: SQL_NO_NULLS
);
1162 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1166 void ODatabaseMetaDataResultSet::openVersionColumns(const Any
& catalog
, const OUString
& schema
,
1167 const OUString
& table
) throw(SQLException
, RuntimeException
)
1169 openSpecialColumns(true,catalog
,schema
,table
,SQL_SCOPE_TRANSACTION
,false);
1172 void ODatabaseMetaDataResultSet::openBestRowIdentifier( const Any
& catalog
, const OUString
& schema
,
1173 const OUString
& table
,sal_Int32 scope
,bool nullable
) throw(SQLException
, RuntimeException
)
1175 openSpecialColumns(false,catalog
,schema
,table
,scope
,nullable
);
1178 void ODatabaseMetaDataResultSet::openForeignKeys( const Any
& catalog
, const OUString
* schema
,
1179 const OUString
* table
,
1180 const Any
& catalog2
, const OUString
* schema2
,
1181 const OUString
* table2
) throw(SQLException
, RuntimeException
)
1183 OString aPKQ
, aPKN
, aFKQ
, aFKO
, aFKN
;
1184 if ( catalog
.hasValue() )
1185 aPKQ
= OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
1186 if ( catalog2
.hasValue() )
1187 aFKQ
= OUStringToOString(comphelper::getString(catalog2
),m_nTextEncoding
);
1189 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
1190 *pPKO
= schema
&& !schema
->isEmpty() ? OUStringToOString(*schema
,m_nTextEncoding
).getStr() : NULL
,
1191 *pPKN
= table
? (aPKN
= OUStringToOString(*table
,m_nTextEncoding
)).getStr(): NULL
,
1192 *pFKQ
= catalog2
.hasValue() && !aFKQ
.isEmpty() ? aFKQ
.getStr() : NULL
,
1193 *pFKO
= schema2
&& !schema2
->isEmpty() ? (aFKO
= OUStringToOString(*schema2
,m_nTextEncoding
)).getStr() : NULL
,
1194 *pFKN
= table2
? (aFKN
= OUStringToOString(*table2
,m_nTextEncoding
)).getStr() : NULL
;
1197 SQLRETURN nRetcode
= N3SQLForeignKeys(m_aStatementHandle
,
1198 (SDB_ODBC_CHAR
*) pPKQ
, (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
1199 (SDB_ODBC_CHAR
*) pPKO
, pPKO
? SQL_NTS
: 0,
1200 (SDB_ODBC_CHAR
*) pPKN
, pPKN
? SQL_NTS
: 0,
1201 (SDB_ODBC_CHAR
*) pFKQ
, (catalog2
.hasValue() && !aFKQ
.isEmpty()) ? SQL_NTS
: 0,
1202 (SDB_ODBC_CHAR
*) pFKO
, pFKO
? SQL_NTS
: 0,
1203 (SDB_ODBC_CHAR
*) pFKN
, SQL_NTS
1205 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1209 void ODatabaseMetaDataResultSet::openImportedKeys(const Any
& catalog
, const OUString
& schema
,
1210 const OUString
& table
) throw(SQLException
, RuntimeException
)
1213 openForeignKeys(Any(),NULL
,NULL
,catalog
, schema
.equalsAscii("%") ? &schema
: NULL
, &table
);
1216 void ODatabaseMetaDataResultSet::openExportedKeys(const Any
& catalog
, const OUString
& schema
,
1217 const OUString
& table
) throw(SQLException
, RuntimeException
)
1219 openForeignKeys(catalog
, schema
.equalsAscii("%") ? &schema
: NULL
, &table
,Any(),NULL
,NULL
);
1222 void ODatabaseMetaDataResultSet::openPrimaryKeys(const Any
& catalog
, const OUString
& schema
,
1223 const OUString
& table
) throw(SQLException
, RuntimeException
)
1225 const OUString
*pSchemaPat
= NULL
;
1228 pSchemaPat
= &schema
;
1232 OString aPKQ
,aPKO
,aPKN
;
1234 if ( catalog
.hasValue() )
1235 aPKQ
= OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
1236 aPKO
= OUStringToOString(schema
,m_nTextEncoding
);
1238 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
1239 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() && !aPKO
.isEmpty() ? aPKO
.getStr() : NULL
,
1240 *pPKN
= (aPKN
= OUStringToOString(table
,m_nTextEncoding
)).getStr();
1243 SQLRETURN nRetcode
= N3SQLPrimaryKeys(m_aStatementHandle
,
1244 (SDB_ODBC_CHAR
*) pPKQ
, (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
1245 (SDB_ODBC_CHAR
*) pPKO
, pPKO
? SQL_NTS
: 0 ,
1246 (SDB_ODBC_CHAR
*) pPKN
, SQL_NTS
);
1247 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1251 void ODatabaseMetaDataResultSet::openTablePrivileges(const Any
& catalog
, const OUString
& schemaPattern
,
1252 const OUString
& tableNamePattern
) throw(SQLException
, RuntimeException
)
1254 const OUString
*pSchemaPat
= NULL
;
1256 if(schemaPattern
!= "%")
1257 pSchemaPat
= &schemaPattern
;
1261 OString aPKQ
,aPKO
,aPKN
;
1263 if ( catalog
.hasValue() )
1264 aPKQ
= OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
1265 aPKO
= OUStringToOString(schemaPattern
,m_nTextEncoding
);
1267 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
1268 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() && !aPKO
.isEmpty() ? aPKO
.getStr() : NULL
,
1269 *pPKN
= (aPKN
= OUStringToOString(tableNamePattern
,m_nTextEncoding
)).getStr();
1272 SQLRETURN nRetcode
= N3SQLTablePrivileges(m_aStatementHandle
,
1273 (SDB_ODBC_CHAR
*) pPKQ
, (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
1274 (SDB_ODBC_CHAR
*) pPKO
, pPKO
? SQL_NTS
: 0 ,
1275 (SDB_ODBC_CHAR
*) pPKN
, SQL_NTS
);
1276 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1280 void ODatabaseMetaDataResultSet::openIndexInfo( const Any
& catalog
, const OUString
& schema
,
1281 const OUString
& table
, bool unique
, bool approximate
)
1282 throw(SQLException
, RuntimeException
)
1284 const OUString
*pSchemaPat
= NULL
;
1287 pSchemaPat
= &schema
;
1291 OString aPKQ
,aPKO
,aPKN
;
1293 if ( catalog
.hasValue() )
1294 aPKQ
= OUStringToOString(comphelper::getString(catalog
),m_nTextEncoding
);
1295 aPKO
= OUStringToOString(schema
,m_nTextEncoding
);
1297 const char *pPKQ
= catalog
.hasValue() && !aPKQ
.isEmpty() ? aPKQ
.getStr() : NULL
,
1298 *pPKO
= pSchemaPat
&& !pSchemaPat
->isEmpty() && !aPKO
.isEmpty() ? aPKO
.getStr() : NULL
,
1299 *pPKN
= (aPKN
= OUStringToOString(table
,m_nTextEncoding
)).getStr();
1302 SQLRETURN nRetcode
= N3SQLStatistics(m_aStatementHandle
,
1303 (SDB_ODBC_CHAR
*) pPKQ
, (catalog
.hasValue() && !aPKQ
.isEmpty()) ? SQL_NTS
: 0,
1304 (SDB_ODBC_CHAR
*) pPKO
, pPKO
? SQL_NTS
: 0 ,
1305 (SDB_ODBC_CHAR
*) pPKN
, SQL_NTS
,
1306 unique
? SQL_INDEX_UNIQUE
: SQL_INDEX_ALL
,
1307 approximate
? 1 : 0);
1308 OTools::ThrowException(m_pConnection
,nRetcode
,m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1312 void ODatabaseMetaDataResultSet::checkColumnCount()
1314 sal_Int16 nNumResultCols
=0;
1315 OTools::ThrowException(m_pConnection
,N3SQLNumResultCols(m_aStatementHandle
,&nNumResultCols
),m_aStatementHandle
,SQL_HANDLE_STMT
,*this);
1316 m_nDriverColumnCount
= nNumResultCols
;
1320 SWORD
ODatabaseMetaDataResultSet::impl_getColumnType_nothrow(sal_Int32 columnIndex
)
1322 ::std::map
<sal_Int32
,SWORD
>::iterator aFind
= m_aODBCColumnTypes
.find(columnIndex
);
1323 if ( aFind
== m_aODBCColumnTypes
.end() )
1324 aFind
= m_aODBCColumnTypes
.insert(::std::map
<sal_Int32
,SWORD
>::value_type(columnIndex
,OResultSetMetaData::getColumnODBCType(m_pConnection
,m_aStatementHandle
,*this,columnIndex
))).first
;
1325 return aFind
->second
;
1328 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */