diff options
Diffstat (limited to 'connectivity/source/drivers/odbcbase')
-rw-r--r-- | connectivity/source/drivers/odbcbase/OConnection.cxx | 670 | ||||
-rw-r--r-- | connectivity/source/drivers/odbcbase/ODatabaseMetaData.cxx | 1743 | ||||
-rw-r--r-- | connectivity/source/drivers/odbcbase/ODatabaseMetaDataResultSet.cxx | 1323 | ||||
-rw-r--r-- | connectivity/source/drivers/odbcbase/ODriver.cxx | 229 | ||||
-rw-r--r-- | connectivity/source/drivers/odbcbase/OPreparedStatement.cxx | 973 | ||||
-rw-r--r-- | connectivity/source/drivers/odbcbase/OResultSet.cxx | 1755 | ||||
-rw-r--r-- | connectivity/source/drivers/odbcbase/OResultSetMetaData.cxx | 312 | ||||
-rw-r--r-- | connectivity/source/drivers/odbcbase/OStatement.cxx | 1154 | ||||
-rw-r--r-- | connectivity/source/drivers/odbcbase/OTools.cxx | 946 | ||||
-rw-r--r-- | connectivity/source/drivers/odbcbase/makefile.mk | 90 |
10 files changed, 9195 insertions, 0 deletions
diff --git a/connectivity/source/drivers/odbcbase/OConnection.cxx b/connectivity/source/drivers/odbcbase/OConnection.cxx new file mode 100644 index 000000000000..0c79db546b3f --- /dev/null +++ b/connectivity/source/drivers/odbcbase/OConnection.cxx @@ -0,0 +1,670 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "odbc/OTools.hxx" +#include "odbc/OConnection.hxx" +#include "odbc/ODatabaseMetaData.hxx" +#include "odbc/OFunctions.hxx" +#include "odbc/ODriver.hxx" +#include "odbc/OStatement.hxx" +#include "odbc/OPreparedStatement.hxx" +#include <com/sun/star/sdbc/ColumnValue.hpp> +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/lang/DisposedException.hpp> +#include <connectivity/dbcharset.hxx> +#include <connectivity/FValue.hxx> +#include <comphelper/extract.hxx> +#include "diagnose_ex.h" +#include <connectivity/dbexception.hxx> + +#include <string.h> + +using namespace connectivity::odbc; +using namespace connectivity; +using namespace dbtools; + +//------------------------------------------------------------------------------ +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::sdbc; +// -------------------------------------------------------------------------------- +OConnection::OConnection(const SQLHANDLE _pDriverHandle,ODBCDriver* _pDriver) + : OSubComponent<OConnection, OConnection_BASE>((::cppu::OWeakObject*)_pDriver, this) + ,m_pDriver(_pDriver) + ,m_pDriverHandleCopy(_pDriverHandle) + ,m_nStatementCount(0) + ,m_bClosed(sal_True) + ,m_bUseCatalog(sal_False) + ,m_bUseOldDateFormat(sal_False) + ,m_bParameterSubstitution(sal_False) + ,m_bIgnoreDriverPrivileges(sal_False) + ,m_bPreventGetVersionColumns(sal_False) + ,m_bReadOnly(sal_True) +{ + m_pDriver->acquire(); +} +//----------------------------------------------------------------------------- +OConnection::~OConnection() +{ + if(!isClosed( )) + close(); + + if ( SQL_NULL_HANDLE != m_aConnectionHandle ) + N3SQLFreeHandle( SQL_HANDLE_DBC, m_aConnectionHandle ); + m_aConnectionHandle = SQL_NULL_HANDLE; + + m_pDriver->release(); + m_pDriver = NULL; +} +//----------------------------------------------------------------------------- +void SAL_CALL OConnection::release() throw() +{ + relase_ChildImpl(); +} +// ----------------------------------------------------------------------------- +oslGenericFunction OConnection::getOdbcFunction(sal_Int32 _nIndex) const +{ + OSL_ENSURE(m_pDriver,"OConnection::getOdbcFunction: m_pDriver is null!"); + return m_pDriver->getOdbcFunction(_nIndex); +} +//----------------------------------------------------------------------------- +SQLRETURN OConnection::OpenConnection(const ::rtl::OUString& aConnectStr,sal_Int32 nTimeOut, sal_Bool bSilent) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if (m_aConnectionHandle == SQL_NULL_HANDLE) + return -1; + + SQLRETURN nSQLRETURN = 0; + SDB_ODBC_CHAR szConnStrOut[4096]; + SDB_ODBC_CHAR szConnStrIn[2048]; + SQLSMALLINT cbConnStrOut; + memset(szConnStrOut,'\0',4096); + memset(szConnStrIn,'\0',2048); + ::rtl::OString aConStr(::rtl::OUStringToOString(aConnectStr,getTextEncoding())); + memcpy(szConnStrIn, (SDB_ODBC_CHAR*) aConStr.getStr(), ::std::min<sal_Int32>((sal_Int32)2048,aConStr.getLength())); + +#ifndef MACOSX + N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_LOGIN_TIMEOUT,(SQLPOINTER)nTimeOut,SQL_IS_UINTEGER); + // Verbindung aufbauen +#endif + +#ifdef LINUX + OSL_UNUSED( bSilent ); + nSQLRETURN = N3SQLDriverConnect(m_aConnectionHandle, + NULL, + szConnStrIn, + (SQLSMALLINT) ::std::min((sal_Int32)2048,aConStr.getLength()), + szConnStrOut, + (SQLSMALLINT) (sizeof(szConnStrOut)/sizeof(SDB_ODBC_CHAR)) -1, + &cbConnStrOut, + SQL_DRIVER_NOPROMPT); + if (nSQLRETURN == SQL_ERROR || nSQLRETURN == SQL_NO_DATA || SQL_SUCCESS_WITH_INFO == nSQLRETURN) + return nSQLRETURN; +#else + + SQLUSMALLINT nSilent = bSilent ? SQL_DRIVER_NOPROMPT : SQL_DRIVER_COMPLETE; + nSQLRETURN = N3SQLDriverConnect(m_aConnectionHandle, + NULL, + szConnStrIn, + (SQLSMALLINT) ::std::min<sal_Int32>((sal_Int32)2048,aConStr.getLength()), + szConnStrOut, + (SQLSMALLINT) sizeof szConnStrOut, + &cbConnStrOut, + nSilent); + if (nSQLRETURN == SQL_ERROR || nSQLRETURN == SQL_NO_DATA) + return nSQLRETURN; + + m_bClosed = sal_False; + +#endif //LINUX + + try + { + ::rtl::OUString aVal; + OTools::GetInfo(this,m_aConnectionHandle,SQL_DATA_SOURCE_READ_ONLY,aVal,*this,getTextEncoding()); + m_bReadOnly = !aVal.compareToAscii("Y"); + } + catch(Exception&) + { + m_bReadOnly = sal_True; + } + try + { + ::rtl::OUString sVersion; + OTools::GetInfo(this,m_aConnectionHandle,SQL_DRIVER_ODBC_VER,sVersion,*this,getTextEncoding()); + m_bUseOldDateFormat = sVersion == ::rtl::OUString::createFromAscii("02.50") || sVersion == ::rtl::OUString::createFromAscii("02.00"); + } + catch(Exception&) + { + } + + + // autocoomit ist immer default + + if (!m_bReadOnly) + N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_AUTOCOMMIT,(SQLPOINTER)SQL_AUTOCOMMIT_ON,SQL_IS_INTEGER); + + return nSQLRETURN; +} +//----------------------------------------------------------------------------- +SQLRETURN OConnection::Construct(const ::rtl::OUString& url,const Sequence< PropertyValue >& info) throw(SQLException) +{ + m_aConnectionHandle = SQL_NULL_HANDLE; + m_sURL = url; + setConnectionInfo(info); + + // Connection allozieren + N3SQLAllocHandle(SQL_HANDLE_DBC,m_pDriverHandleCopy,&m_aConnectionHandle); + if(m_aConnectionHandle == SQL_NULL_HANDLE) + throw SQLException(); + + sal_Int32 nLen = url.indexOf(':'); + nLen = url.indexOf(':',nLen+1); + ::rtl::OUString aDSN(RTL_CONSTASCII_USTRINGPARAM("DSN=")), aUID, aPWD, aSysDrvSettings; + aDSN += url.copy(nLen+1); + + const char* pUser = "user"; + const char* pTimeout = "Timeout"; + const char* pSilent = "Silent"; + const char* pPwd = "password"; + const char* pUseCatalog = "UseCatalog"; + const char* pSysDrv = "SystemDriverSettings"; + const char* pCharSet = "CharSet"; + const char* pParaName = "ParameterNameSubstitution"; + const char* pPrivName = "IgnoreDriverPrivileges"; + const char* pVerColName = "PreventGetVersionColumns"; // #i60273# + const char* pRetrieving = "IsAutoRetrievingEnabled"; + const char* pRetriStmt = "AutoRetrievingStatement"; + + sal_Int32 nTimeout = 20; + sal_Bool bSilent = sal_True; + const PropertyValue *pBegin = info.getConstArray(); + const PropertyValue *pEnd = pBegin + info.getLength(); + for(;pBegin != pEnd;++pBegin) + { + if(!pBegin->Name.compareToAscii(pTimeout)) + OSL_VERIFY( pBegin->Value >>= nTimeout ); + else if(!pBegin->Name.compareToAscii(pSilent)) + OSL_VERIFY( pBegin->Value >>= bSilent ); + else if(!pBegin->Name.compareToAscii(pPrivName)) + OSL_VERIFY( pBegin->Value >>= m_bIgnoreDriverPrivileges ); + else if(!pBegin->Name.compareToAscii(pVerColName)) + OSL_VERIFY( pBegin->Value >>= m_bPreventGetVersionColumns ); + else if(!pBegin->Name.compareToAscii(pParaName)) + OSL_VERIFY( pBegin->Value >>= m_bParameterSubstitution ); + else if(!pBegin->Name.compareToAscii(pRetrieving)) + { + sal_Bool bAutoRetrievingEnabled = sal_False; + OSL_VERIFY( pBegin->Value >>= bAutoRetrievingEnabled ); + enableAutoRetrievingEnabled(bAutoRetrievingEnabled); + } + else if(!pBegin->Name.compareToAscii(pRetriStmt)) + { + ::rtl::OUString sGeneratedValueStatement; + OSL_VERIFY( pBegin->Value >>= sGeneratedValueStatement ); + setAutoRetrievingStatement(sGeneratedValueStatement); + } + else if(!pBegin->Name.compareToAscii(pUser)) + { + OSL_VERIFY( pBegin->Value >>= aUID ); + aDSN = aDSN + ::rtl::OUString::createFromAscii(";UID=") + aUID; + } + else if(!pBegin->Name.compareToAscii(pPwd)) + { + OSL_VERIFY( pBegin->Value >>= aPWD ); + aDSN = aDSN + ::rtl::OUString::createFromAscii(";PWD=") + aPWD; + } + else if(!pBegin->Name.compareToAscii(pUseCatalog)) + { + OSL_VERIFY( pBegin->Value >>= m_bUseCatalog ); + } + else if(!pBegin->Name.compareToAscii(pSysDrv)) + { + OSL_VERIFY( pBegin->Value >>= aSysDrvSettings ); + aDSN += ::rtl::OUString::createFromAscii(";"); + aDSN += aSysDrvSettings; + } + else if(0 == pBegin->Name.compareToAscii(pCharSet)) + { + ::rtl::OUString sIanaName; + OSL_VERIFY( pBegin->Value >>= sIanaName ); + + ::dbtools::OCharsetMap aLookupIanaName; + ::dbtools::OCharsetMap::const_iterator aLookup = aLookupIanaName.find(sIanaName, ::dbtools::OCharsetMap::IANA()); + if (aLookup != aLookupIanaName.end()) + m_nTextEncoding = (*aLookup).getEncoding(); + else + m_nTextEncoding = RTL_TEXTENCODING_DONTKNOW; + if(m_nTextEncoding == RTL_TEXTENCODING_DONTKNOW) + m_nTextEncoding = osl_getThreadTextEncoding(); + } + } + m_sUser = aUID; + + SQLRETURN nSQLRETURN = OpenConnection(aDSN,nTimeout, bSilent); + if (nSQLRETURN == SQL_ERROR || nSQLRETURN == SQL_NO_DATA) + { + OTools::ThrowException(this,nSQLRETURN,m_aConnectionHandle,SQL_HANDLE_DBC,*this,sal_False); + } + return nSQLRETURN; +} +// XServiceInfo +// -------------------------------------------------------------------------------- +IMPLEMENT_SERVICE_INFO(OConnection, "com.sun.star.sdbc.drivers.odbc.OConnection", "com.sun.star.sdbc.Connection") + +// -------------------------------------------------------------------------------- +Reference< XStatement > SAL_CALL OConnection::createStatement( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OConnection_BASE::rBHelper.bDisposed); + + Reference< XStatement > xReturn = new OStatement(this); + m_aStatements.push_back(WeakReferenceHelper(xReturn)); + return xReturn; +} +// -------------------------------------------------------------------------------- +Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OConnection_BASE::rBHelper.bDisposed); + + Reference< XPreparedStatement > xReturn = new OPreparedStatement(this,sql); + m_aStatements.push_back(WeakReferenceHelper(xReturn)); + return xReturn; +} +// -------------------------------------------------------------------------------- +Reference< XPreparedStatement > SAL_CALL OConnection::prepareCall( const ::rtl::OUString& /*sql*/ ) throw(SQLException, RuntimeException) +{ + ::dbtools::throwFeatureNotImplementedException( "XConnection::prepareCall", *this ); + return NULL; +} +// -------------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OConnection::nativeSQL( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + ::rtl::OString aSql(::rtl::OUStringToOString(sql.getStr(),getTextEncoding())); + char pOut[2048]; + SQLINTEGER nOutLen; + OTools::ThrowException(this,N3SQLNativeSql(m_aConnectionHandle,(SDB_ODBC_CHAR*)aSql.getStr(),aSql.getLength(),(SDB_ODBC_CHAR*)pOut,sizeof pOut - 1,&nOutLen),m_aConnectionHandle,SQL_HANDLE_DBC,*this); + return ::rtl::OUString(pOut,nOutLen,getTextEncoding()); +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::setAutoCommit( sal_Bool autoCommit ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OConnection_BASE::rBHelper.bDisposed); + + + OTools::ThrowException(this,N3SQLSetConnectAttr(m_aConnectionHandle, + SQL_ATTR_AUTOCOMMIT, + (SQLPOINTER)((autoCommit) ? SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF) ,SQL_IS_INTEGER), + m_aConnectionHandle,SQL_HANDLE_DBC,*this); +} +// -------------------------------------------------------------------------------- +sal_Bool SAL_CALL OConnection::getAutoCommit( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OConnection_BASE::rBHelper.bDisposed); + + + sal_uInt32 nOption = 0; + OTools::ThrowException(this,N3SQLGetConnectAttr(m_aConnectionHandle, + SQL_ATTR_AUTOCOMMIT, &nOption,0,0),m_aConnectionHandle,SQL_HANDLE_DBC,*this); + return nOption == SQL_AUTOCOMMIT_ON ; +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::commit( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OConnection_BASE::rBHelper.bDisposed); + + + OTools::ThrowException(this,N3SQLEndTran(SQL_HANDLE_DBC,m_aConnectionHandle,SQL_COMMIT),m_aConnectionHandle,SQL_HANDLE_DBC,*this); +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::rollback( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OConnection_BASE::rBHelper.bDisposed); + + + OTools::ThrowException(this,N3SQLEndTran(SQL_HANDLE_DBC,m_aConnectionHandle,SQL_ROLLBACK),m_aConnectionHandle,SQL_HANDLE_DBC,*this); +} +// -------------------------------------------------------------------------------- +sal_Bool SAL_CALL OConnection::isClosed( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return OConnection_BASE::rBHelper.bDisposed; +} +// -------------------------------------------------------------------------------- +Reference< XDatabaseMetaData > SAL_CALL OConnection::getMetaData( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OConnection_BASE::rBHelper.bDisposed); + + Reference< XDatabaseMetaData > xMetaData = m_xMetaData; + if(!xMetaData.is()) + { + xMetaData = new ODatabaseMetaData(m_aConnectionHandle,this); + m_xMetaData = xMetaData; + } + + return xMetaData; +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::setReadOnly( sal_Bool readOnly ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OConnection_BASE::rBHelper.bDisposed); + + + OTools::ThrowException(this, + N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_ACCESS_MODE,reinterpret_cast< SQLPOINTER >( readOnly ),SQL_IS_INTEGER), + m_aConnectionHandle,SQL_HANDLE_DBC,*this); +} +// -------------------------------------------------------------------------------- +sal_Bool SAL_CALL OConnection::isReadOnly() throw(SQLException, RuntimeException) +{ + // const member which will initialized only once + return m_bReadOnly; +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::setCatalog( const ::rtl::OUString& catalog ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OConnection_BASE::rBHelper.bDisposed); + + + ::rtl::OString aCat(::rtl::OUStringToOString(catalog.getStr(),getTextEncoding())); + OTools::ThrowException(this, + N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_CURRENT_CATALOG,(SDB_ODBC_CHAR*)aCat.getStr(),SQL_NTS), + m_aConnectionHandle,SQL_HANDLE_DBC,*this); +} +// -------------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OConnection::getCatalog( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OConnection_BASE::rBHelper.bDisposed); + + + sal_Int32 nValueLen; + char pCat[1024]; + OTools::ThrowException(this, + N3SQLGetConnectAttr(m_aConnectionHandle,SQL_ATTR_CURRENT_CATALOG,(SDB_ODBC_CHAR*)pCat,(sizeof pCat)-1,&nValueLen), + m_aConnectionHandle,SQL_HANDLE_DBC,*this); + + return ::rtl::OUString(pCat,nValueLen,getTextEncoding()); +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::setTransactionIsolation( sal_Int32 level ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OConnection_BASE::rBHelper.bDisposed); + + + OTools::ThrowException(this,N3SQLSetConnectAttr(m_aConnectionHandle, + SQL_ATTR_TXN_ISOLATION, + (SQLPOINTER)level,SQL_IS_INTEGER), + m_aConnectionHandle,SQL_HANDLE_DBC,*this); +} +// -------------------------------------------------------------------------------- +sal_Int32 SAL_CALL OConnection::getTransactionIsolation( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OConnection_BASE::rBHelper.bDisposed); + + + sal_Int32 nTxn = 0; + SQLINTEGER nValueLen; + OTools::ThrowException(this, + N3SQLGetConnectAttr(m_aConnectionHandle,SQL_ATTR_TXN_ISOLATION,&nTxn,sizeof nTxn,&nValueLen), + m_aConnectionHandle,SQL_HANDLE_DBC,*this); + return nTxn; +} +// -------------------------------------------------------------------------------- +Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OConnection::getTypeMap( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OConnection_BASE::rBHelper.bDisposed); + + + return NULL; +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::setTypeMap( const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException) +{ + ::dbtools::throwFeatureNotImplementedException( "XConnection::setTypeMap", *this ); +} +// -------------------------------------------------------------------------------- +// XCloseable +void SAL_CALL OConnection::close( ) throw(SQLException, RuntimeException) +{ + { + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OConnection_BASE::rBHelper.bDisposed); + + } + dispose(); +} +// -------------------------------------------------------------------------------- +// XWarningsSupplier +Any SAL_CALL OConnection::getWarnings( ) throw(SQLException, RuntimeException) +{ + return Any(); +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::clearWarnings( ) throw(SQLException, RuntimeException) +{ +} +//-------------------------------------------------------------------- +void OConnection::buildTypeInfo() throw( SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + Reference< XResultSet> xRs = getMetaData ()->getTypeInfo (); + if(xRs.is()) + { + Reference< XRow> xRow(xRs,UNO_QUERY); + // Information for a single SQL type + + ::connectivity::ORowSetValue aValue; + ::std::vector<sal_Int32> aTypes; + Reference<XResultSetMetaData> xResultSetMetaData = Reference<XResultSetMetaDataSupplier>(xRs,UNO_QUERY)->getMetaData(); + sal_Int32 nCount = xResultSetMetaData->getColumnCount(); + // Loop on the result set until we reach end of file + while (xRs->next ()) + { + OTypeInfo aInfo; + sal_Int32 nPos = 1; + if ( aTypes.empty() ) + { + if ( nCount < 1 ) + nCount = 18; + aTypes.reserve(nCount+1); + aTypes.push_back(-1); + for (sal_Int32 j = 1; j <= nCount ; ++j) + aTypes.push_back(xResultSetMetaData->getColumnType(j)); + } + + aValue.fill(nPos,aTypes[nPos],xRow); + aInfo.aTypeName = aValue; + ++nPos; + aValue.fill(nPos,aTypes[nPos],xRow); + aInfo.nType = aValue; + ++nPos; + aValue.fill(nPos,aTypes[nPos],xRow); + aInfo.nPrecision = aValue; + ++nPos; + aValue.fill(nPos,aTypes[nPos],xRow); + aInfo.aLiteralPrefix = aValue; + ++nPos; + aValue.fill(nPos,aTypes[nPos],xRow); + aInfo.aLiteralSuffix = aValue; + ++nPos; + aValue.fill(nPos,aTypes[nPos],xRow); + aInfo.aCreateParams = aValue; + ++nPos; + aValue.fill(nPos,aTypes[nPos],xRow); + aInfo.bNullable = (sal_Int32)aValue == ColumnValue::NULLABLE; + ++nPos; + aValue.fill(nPos,aTypes[nPos],xRow); + aInfo.bCaseSensitive = (sal_Bool)aValue; + ++nPos; + aValue.fill(nPos,aTypes[nPos],xRow); + aInfo.nSearchType = aValue; + ++nPos; + aValue.fill(nPos,aTypes[nPos],xRow); + aInfo.bUnsigned = (sal_Bool)aValue; + ++nPos; + aValue.fill(nPos,aTypes[nPos],xRow); + aInfo.bCurrency = (sal_Bool)aValue; + ++nPos; + aValue.fill(nPos,aTypes[nPos],xRow); + aInfo.bAutoIncrement = (sal_Bool)aValue; + ++nPos; + aValue.fill(nPos,aTypes[nPos],xRow); + aInfo.aLocalTypeName = aValue; + ++nPos; + aValue.fill(nPos,aTypes[nPos],xRow); + aInfo.nMinimumScale = aValue; + ++nPos; + aValue.fill(nPos,aTypes[nPos],xRow); + aInfo.nMaximumScale = aValue; + if ( nCount >= 18 ) + { + nPos = 18; + aValue.fill(nPos,aTypes[nPos],xRow); + aInfo.nNumPrecRadix = aValue; + } + + // check if values are less than zero like it happens in a oracle jdbc driver + if( aInfo.nPrecision < 0) + aInfo.nPrecision = 0; + if( aInfo.nMinimumScale < 0) + aInfo.nMinimumScale = 0; + if( aInfo.nMaximumScale < 0) + aInfo.nMaximumScale = 0; + if( aInfo.nNumPrecRadix < 0) + aInfo.nNumPrecRadix = 10; + + // Now that we have the type info, save it + // in the Hashtable if we don't already have an + // entry for this SQL type. + + m_aTypeInfo.push_back(aInfo); + } + + // Close the result set/statement. + + Reference< XCloseable> xClose(xRs,UNO_QUERY); + if(xClose.is()) + xClose->close(); + } +} +//------------------------------------------------------------------------------ +void OConnection::disposing() +{ + ::osl::MutexGuard aGuard(m_aMutex); + + OConnection_BASE::disposing(); + + for (::std::map< SQLHANDLE,OConnection*>::iterator aConIter = m_aConnections.begin();aConIter != m_aConnections.end();++aConIter ) + aConIter->second->dispose(); + + ::std::map< SQLHANDLE,OConnection*>().swap(m_aConnections); + + if(!m_bClosed) + N3SQLDisconnect(m_aConnectionHandle); + m_bClosed = sal_True; + + dispose_ChildImpl(); +} +// ----------------------------------------------------------------------------- +OConnection* OConnection::cloneConnection() +{ + return new OConnection(m_pDriverHandleCopy,m_pDriver); +} +// ----------------------------------------------------------------------------- +SQLHANDLE OConnection::createStatementHandle() +{ + OConnection* pConnectionTemp = this; + sal_Bool bNew = sal_False; + try + { + sal_Int32 nMaxStatements = getMetaData()->getMaxStatements(); + if(nMaxStatements && nMaxStatements <= m_nStatementCount) + { + OConnection* pConnection = cloneConnection(); + pConnection->acquire(); + pConnection->Construct(m_sURL,getConnectionInfo()); + pConnectionTemp = pConnection; + bNew = sal_True; + } + } + catch(SQLException&) + { + } + + SQLHANDLE aStatementHandle = SQL_NULL_HANDLE; + SQLRETURN nRetcode = N3SQLAllocHandle(SQL_HANDLE_STMT,pConnectionTemp->getConnection(),&aStatementHandle); + OSL_UNUSED( nRetcode ); + ++m_nStatementCount; + if(bNew) + m_aConnections.insert(::std::map< SQLHANDLE,OConnection*>::value_type(aStatementHandle,pConnectionTemp)); + + return aStatementHandle; + +} +// ----------------------------------------------------------------------------- +void OConnection::freeStatementHandle(SQLHANDLE& _pHandle) +{ + ::std::map< SQLHANDLE,OConnection*>::iterator aFind = m_aConnections.find(_pHandle); + + N3SQLFreeStmt(_pHandle,SQL_RESET_PARAMS); + N3SQLFreeStmt(_pHandle,SQL_UNBIND); + N3SQLFreeStmt(_pHandle,SQL_CLOSE); + N3SQLFreeHandle(SQL_HANDLE_STMT,_pHandle); + + _pHandle = SQL_NULL_HANDLE; + + if(aFind != m_aConnections.end()) + { + aFind->second->dispose(); + m_aConnections.erase(aFind); + } + --m_nStatementCount; +} +// ----------------------------------------------------------------------------- + + + diff --git a/connectivity/source/drivers/odbcbase/ODatabaseMetaData.cxx b/connectivity/source/drivers/odbcbase/ODatabaseMetaData.cxx new file mode 100644 index 000000000000..dc9349732084 --- /dev/null +++ b/connectivity/source/drivers/odbcbase/ODatabaseMetaData.cxx @@ -0,0 +1,1743 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "odbc/ODatabaseMetaData.hxx" +#include "odbc/OTools.hxx" +#ifndef _CONNECTIVITY_ODBC_ORESULTSET_HXX_ +#include "odbc/ODatabaseMetaDataResultSet.hxx" +#endif +#include "FDatabaseMetaDataResultSet.hxx" +#include <com/sun/star/sdbc/DataType.hpp> +#include <com/sun/star/sdbc/ResultSetType.hpp> +#include <com/sun/star/sdbc/ResultSetConcurrency.hpp> +#include "odbc/OFunctiondefs.hxx" +#include "stdio.h" +#include "TPrivilegesResultSet.hxx" +#include <connectivity/dbexception.hxx> +#include <rtl/ustrbuf.hxx> + +using namespace connectivity::odbc; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::sdbc; + +ODatabaseMetaData::ODatabaseMetaData(const SQLHANDLE _pHandle,OConnection* _pCon) + : ::connectivity::ODatabaseMetaDataBase(_pCon,_pCon->getConnectionInfo()) + ,m_aConnectionHandle(_pHandle) + ,m_pConnection(_pCon) + ,m_bUseCatalog(sal_True) + ,m_bOdbc3(sal_True) +{ + OSL_ENSURE(m_pConnection,"ODatabaseMetaData::ODatabaseMetaData: No connection set!"); + if(!m_pConnection->isCatalogUsed()) + { + osl_incrementInterlockedCount( &m_refCount ); + try + { + m_bUseCatalog = !(usesLocalFiles() || usesLocalFilePerTable()); + ::rtl::OUString sVersion = getDriverVersion(); + m_bOdbc3 = sVersion != ::rtl::OUString::createFromAscii("02.50") && sVersion != ::rtl::OUString::createFromAscii("02.00"); + } + catch(SQLException& ) + { // doesn't matter here + } + osl_decrementInterlockedCount( &m_refCount ); + } +} +// ------------------------------------------------------------------------- +ODatabaseMetaData::~ODatabaseMetaData() +{ +} +// ------------------------------------------------------------------------- +Reference< XResultSet > ODatabaseMetaData::impl_getTypeInfo_throw( ) +{ + Reference< XResultSet > xRef; + try + { + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + xRef = pResult; + pResult->openTypeInfo(); + } + catch(SQLException&) + { + xRef = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo); + } + + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getCatalogs( ) throw(SQLException, RuntimeException) +{ + Reference< XResultSet > xRef; + if(!m_bUseCatalog) + { + xRef = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eCatalogs); + } + else + { + try + { + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + xRef = pResult; + pResult->openCatalogs(); + } + catch(SQLException&) + { + xRef = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eCatalogs); + } + } + + return xRef; +} +// ------------------------------------------------------------------------- +::rtl::OUString ODatabaseMetaData::impl_getCatalogSeparator_throw( ) +{ + ::rtl::OUString aVal; + if ( m_bUseCatalog ) + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CATALOG_NAME_SEPARATOR,aVal,*this,m_pConnection->getTextEncoding()); + + return aVal; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getSchemas( ) throw(SQLException, RuntimeException) +{ + Reference< XResultSet > xRef; + try + { + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + xRef = pResult; + pResult->openSchemas(); + } + catch(SQLException&) + { + xRef = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eSchemas); + } + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumnPrivileges( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, + const ::rtl::OUString& columnNamePattern ) throw(SQLException, RuntimeException) +{ + Reference< XResultSet > xRef; + try + { + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + xRef = pResult; + pResult->openColumnPrivileges(m_bUseCatalog ? catalog : Any(),schema,table,columnNamePattern); + } + catch(SQLException&) + { + xRef = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumnPrivileges); + } + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns( + const Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& tableNamePattern, + const ::rtl::OUString& columnNamePattern ) throw(SQLException, RuntimeException) +{ + Reference< XResultSet > xRef; + try + { + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + xRef = pResult; + pResult->openColumns(m_bUseCatalog ? catalog : Any(),schemaPattern,tableNamePattern,columnNamePattern); + } + catch(SQLException&) + { + xRef = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns); + } + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables( + const Any& catalog, const ::rtl::OUString& schemaPattern, + const ::rtl::OUString& tableNamePattern, const Sequence< ::rtl::OUString >& types ) throw(SQLException, RuntimeException) +{ + Reference< XResultSet > xRef; + try + { + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + xRef = pResult; + pResult->openTables(m_bUseCatalog ? catalog : Any(),schemaPattern,tableNamePattern,types); + } + catch(SQLException&) + { + xRef = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTables); + } + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getProcedureColumns( + const Any& catalog, const ::rtl::OUString& schemaPattern, + const ::rtl::OUString& procedureNamePattern, const ::rtl::OUString& columnNamePattern ) throw(SQLException, RuntimeException) +{ + Reference< XResultSet > xRef; + try + { + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + xRef = pResult; + pResult->openProcedureColumns(m_bUseCatalog ? catalog : Any(),schemaPattern,procedureNamePattern,columnNamePattern); + } + catch(SQLException&) + { + xRef = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eProcedureColumns); + } + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getProcedures( + const Any& catalog, const ::rtl::OUString& schemaPattern, + const ::rtl::OUString& procedureNamePattern ) throw(SQLException, RuntimeException) +{ + Reference< XResultSet > xRef; + try + { + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + xRef = pResult; + pResult->openProcedures(m_bUseCatalog ? catalog : Any(),schemaPattern,procedureNamePattern); + } + catch(SQLException&) + { + xRef = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eProcedures); + } + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getVersionColumns( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + Reference< XResultSet > xRef; + bool bSuccess = false; + try + { + if ( !m_pConnection->preventGetVersionColumns() ) + { + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + xRef = pResult; + pResult->openVersionColumns(m_bUseCatalog ? catalog : Any(),schema,table); + bSuccess = true; + } + } + catch(SQLException&) + { + } + + if ( !bSuccess ) + { + xRef = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eVersionColumns); + } + + return xRef; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxBinaryLiteralLength( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_MAX_BINARY_LITERAL_LEN,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxRowSize( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_MAX_ROW_SIZE,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxCatalogNameLength( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_MAX_CATALOG_NAME_LEN,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxCharLiteralLength( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_MAX_CHAR_LITERAL_LEN,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnNameLength( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_MAX_COLUMN_NAME_LEN,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInIndex( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_MAX_COLUMNS_IN_INDEX,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxCursorNameLength( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_MAX_CURSOR_NAME_LEN,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxConnections( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_MAX_DRIVER_CONNECTIONS/*SQL_ACTIVE_CONNECTIONS*/,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInTable( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_MAX_COLUMNS_IN_TABLE,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxStatementLength( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_MAX_STATEMENT_LEN,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxTableNameLength( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_MAX_TABLE_NAME_LEN,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 ODatabaseMetaData::impl_getMaxTablesInSelect_throw( ) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_MAX_TABLES_IN_SELECT,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getExportedKeys( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + Reference< XResultSet > xRef; + try + { + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + xRef = pResult; + pResult->openExportedKeys(m_bUseCatalog ? catalog : Any(),schema,table); + } + catch(SQLException&) + { + xRef = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eExportedKeys); + } + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getImportedKeys( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + Reference< XResultSet > xRef; + try + { + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + xRef = pResult; + pResult->openImportedKeys(m_bUseCatalog ? catalog : Any(),schema,table); + } + catch(SQLException&) + { + xRef = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eImportedKeys); + } + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getPrimaryKeys( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + Reference< XResultSet > xRef; + try + { + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + xRef = pResult; + pResult->openPrimaryKeys(m_bUseCatalog ? catalog : Any(),schema,table); + } + catch(SQLException&) + { + xRef = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::ePrimaryKeys); + } + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getIndexInfo( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, + sal_Bool unique, sal_Bool approximate ) throw(SQLException, RuntimeException) +{ + Reference< XResultSet > xRef; + try + { + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + xRef = pResult; + pResult->openIndexInfo(m_bUseCatalog ? catalog : Any(),schema,table,unique,approximate); + } + catch(SQLException&) + { + xRef = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eIndexInfo); + } + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getBestRowIdentifier( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, sal_Int32 scope, + sal_Bool nullable ) throw(SQLException, RuntimeException) +{ + Reference< XResultSet > xRef; + try + { + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + xRef = pResult; + pResult->openBestRowIdentifier(m_bUseCatalog ? catalog : Any(),schema,table,scope,nullable); + } + catch(SQLException&) + { + xRef = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eBestRowIdentifier); + } + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges( + const Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& tableNamePattern ) throw(SQLException, RuntimeException) +{ + if ( m_pConnection->isIgnoreDriverPrivilegesEnabled() ) + { + return new OResultSetPrivileges(this,catalog,schemaPattern,tableNamePattern); + } + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + Reference< XResultSet > xRef = pResult; + pResult->openTablePrivileges(m_bUseCatalog ? catalog : Any(),schemaPattern,tableNamePattern); + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getCrossReference( + const Any& primaryCatalog, const ::rtl::OUString& primarySchema, + const ::rtl::OUString& primaryTable, const Any& foreignCatalog, + const ::rtl::OUString& foreignSchema, const ::rtl::OUString& foreignTable ) throw(SQLException, RuntimeException) +{ + Reference< XResultSet > xRef; + try + { + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + xRef = pResult; + pResult->openForeignKeys(m_bUseCatalog ? primaryCatalog : Any(),primarySchema.toChar() == '%' ? &primarySchema : NULL,&primaryTable, + m_bUseCatalog ? foreignCatalog : Any(), foreignSchema.toChar() == '%' ? &foreignSchema : NULL,&foreignTable); + } + catch(SQLException&) + { + xRef = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eCrossReference); + } + return xRef; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::doesMaxRowSizeIncludeBlobs( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aVal; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_MAX_ROW_SIZE_INCLUDES_LONG,aVal,*this,m_pConnection->getTextEncoding()); + return aVal.toChar() == 'Y'; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::storesLowerCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_QUOTED_IDENTIFIER_CASE,nValue,*this); + return nValue == SQL_IC_LOWER; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::storesLowerCaseIdentifiers( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_IDENTIFIER_CASE,nValue,*this); + return nValue == SQL_IC_LOWER; +} +// ------------------------------------------------------------------------- +sal_Bool ODatabaseMetaData::impl_storesMixedCaseQuotedIdentifiers_throw( ) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_QUOTED_IDENTIFIER_CASE,nValue,*this); + return nValue == SQL_IC_MIXED; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::storesMixedCaseIdentifiers( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_IDENTIFIER_CASE,nValue,*this); + return nValue == SQL_IC_MIXED; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::storesUpperCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_QUOTED_IDENTIFIER_CASE,nValue,*this); + return nValue == SQL_IC_UPPER; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::storesUpperCaseIdentifiers( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_IDENTIFIER_CASE,nValue,*this); + return nValue == SQL_IC_UPPER; +} +// ------------------------------------------------------------------------- +sal_Bool ODatabaseMetaData::impl_supportsAlterTableWithAddColumn_throw( ) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_ALTER_TABLE,nValue,*this); + return (nValue & SQL_AT_ADD_COLUMN) == SQL_AT_ADD_COLUMN; +} +// ------------------------------------------------------------------------- +sal_Bool ODatabaseMetaData::impl_supportsAlterTableWithDropColumn_throw( ) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_ALTER_TABLE,nValue,*this); + return ((nValue & SQL_AT_DROP_COLUMN) == SQL_AT_DROP_COLUMN) || + ((nValue & SQL_AT_DROP_COLUMN_CASCADE) == SQL_AT_DROP_COLUMN_CASCADE) || + ((nValue & SQL_AT_DROP_COLUMN_RESTRICT) == SQL_AT_DROP_COLUMN_RESTRICT); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxIndexLength( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_MAX_INDEX_SIZE,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsNonNullableColumns( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_NON_NULLABLE_COLUMNS,nValue,*this); + return nValue == SQL_NNC_NON_NULL; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getCatalogTerm( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aVal; + if(m_bUseCatalog) + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CATALOG_TERM,aVal,*this,m_pConnection->getTextEncoding()); + return aVal; +} +// ------------------------------------------------------------------------- +::rtl::OUString ODatabaseMetaData::impl_getIdentifierQuoteString_throw( ) +{ + ::rtl::OUString aVal; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_IDENTIFIER_QUOTE_CHAR,aVal,*this,m_pConnection->getTextEncoding()); + return aVal; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getExtraNameCharacters( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aVal; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_SPECIAL_CHARACTERS,aVal,*this,m_pConnection->getTextEncoding()); + return aVal; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsDifferentTableCorrelationNames( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CORRELATION_NAME,nValue,*this); + return nValue != SQL_CN_NONE; +} +// ------------------------------------------------------------------------- +sal_Bool ODatabaseMetaData::impl_isCatalogAtStart_throw( ) +{ + SQLUSMALLINT nValue=0; + if ( m_bUseCatalog ) + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CATALOG_LOCATION,nValue,*this); + return nValue == SQL_CL_START; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::dataDefinitionIgnoredInTransactions( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_TXN_CAPABLE,nValue,*this); + return nValue == SQL_TC_DDL_IGNORE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::dataDefinitionCausesTransactionCommit( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_TXN_CAPABLE,nValue,*this); + return nValue == SQL_TC_DDL_COMMIT; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsDataManipulationTransactionsOnly( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_TXN_CAPABLE,nValue,*this); + return nValue == SQL_TC_DML; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsDataDefinitionAndDataManipulationTransactions( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_TXN_CAPABLE,nValue,*this); + return nValue == SQL_TC_ALL; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsPositionedDelete( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_DYNAMIC_CURSOR_ATTRIBUTES1,nValue,*this); + return (nValue & SQL_CA1_POS_DELETE) == SQL_CA1_POS_DELETE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsPositionedUpdate( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_DYNAMIC_CURSOR_ATTRIBUTES1,nValue,*this); + return (nValue & SQL_CA1_POS_UPDATE) == SQL_CA1_POS_UPDATE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenStatementsAcrossRollback( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CURSOR_ROLLBACK_BEHAVIOR,nValue,*this); + return nValue == SQL_CB_PRESERVE || nValue == SQL_CB_CLOSE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenStatementsAcrossCommit( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CURSOR_COMMIT_BEHAVIOR,nValue,*this); + return nValue == SQL_CB_PRESERVE || nValue == SQL_CB_CLOSE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenCursorsAcrossCommit( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CURSOR_COMMIT_BEHAVIOR,nValue,*this); + return nValue == SQL_CB_PRESERVE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenCursorsAcrossRollback( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CURSOR_ROLLBACK_BEHAVIOR,nValue,*this); + return nValue == SQL_CB_PRESERVE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsTransactionIsolationLevel( sal_Int32 level ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_TXN_ISOLATION_OPTION,nValue,*this); + return (nValue & static_cast<SQLUINTEGER>(level)) == static_cast<SQLUINTEGER>(level); +} +// ------------------------------------------------------------------------- +sal_Bool ODatabaseMetaData::impl_supportsSchemasInDataManipulation_throw( ) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_SCHEMA_USAGE,nValue,*this); + return (nValue & SQL_SU_DML_STATEMENTS) == SQL_SU_DML_STATEMENTS; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsANSI92FullSQL( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_SQL_CONFORMANCE,nValue,*this); + return nValue == SQL_SC_SQL92_FULL; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsANSI92EntryLevelSQL( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_SQL_CONFORMANCE,nValue,*this); + return nValue == SQL_SC_SQL92_ENTRY; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsIntegrityEnhancementFacility( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aStr; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_INTEGRITY,aStr,*this,m_pConnection->getTextEncoding()); + return aStr.toChar() == 'Y'; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInIndexDefinitions( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_SCHEMA_USAGE,nValue,*this); + return (nValue & SQL_SU_INDEX_DEFINITION) == SQL_SU_INDEX_DEFINITION; +} +// ------------------------------------------------------------------------- +sal_Bool ODatabaseMetaData::impl_supportsSchemasInTableDefinitions_throw( ) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_SCHEMA_USAGE,nValue,*this); + return (nValue & SQL_SU_TABLE_DEFINITION) == SQL_SU_TABLE_DEFINITION; +} +// ------------------------------------------------------------------------- +sal_Bool ODatabaseMetaData::impl_supportsCatalogsInTableDefinitions_throw( ) +{ + SQLUINTEGER nValue=0; + if(m_bUseCatalog) + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CATALOG_USAGE,nValue,*this); + return (nValue & SQL_CU_TABLE_DEFINITION) == SQL_CU_TABLE_DEFINITION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInIndexDefinitions( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue=0; + if(m_bUseCatalog) + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CATALOG_USAGE,nValue,*this); + return (nValue & SQL_CU_INDEX_DEFINITION) == SQL_CU_INDEX_DEFINITION; +} +// ------------------------------------------------------------------------- +sal_Bool ODatabaseMetaData::impl_supportsCatalogsInDataManipulation_throw( ) +{ + SQLUINTEGER nValue=0; + if(m_bUseCatalog) + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CATALOG_USAGE,nValue,*this); + return (nValue & SQL_CU_DML_STATEMENTS) == SQL_CU_DML_STATEMENTS; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOuterJoins( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_OJ_CAPABILITIES,nValue,*this); + return ((nValue & (SQL_OJ_FULL|SQL_OJ_LEFT|SQL_OJ_RIGHT|SQL_OJ_NESTED|SQL_OJ_NOT_ORDERED|SQL_OJ_ALL_COMPARISON_OPS|SQL_OJ_INNER)) != 0); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTableTypes( ) throw(SQLException, RuntimeException) +{ + + // there exists no possibility to get table types so we have to check + static ::rtl::OUString sTableTypes[] = + { + ::rtl::OUString::createFromAscii("TABLE"), + ::rtl::OUString::createFromAscii("VIEW"), + ::rtl::OUString::createFromAscii("SYSTEM TABLE"), + ::rtl::OUString::createFromAscii("GLOBAL TEMPORARY"), + ::rtl::OUString::createFromAscii("LOCAL TEMPORARY"), + ::rtl::OUString::createFromAscii("ALIAS"), + ::rtl::OUString::createFromAscii("SYNONYM") + }; + sal_Int32 nSize = sizeof(sTableTypes) / sizeof(::rtl::OUString); + ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTableTypes); + Reference< XResultSet > xRef = pResult; + SQLUINTEGER nValue = 0; + try + { + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CREATE_VIEW,nValue,*this); + } + catch(const Exception&) + { + } + sal_Bool bViewsSupported = (nValue & SQL_CV_CREATE_VIEW) == SQL_CV_CREATE_VIEW; + + ::connectivity::ODatabaseMetaDataResultSet::ORows aRows; + for(sal_Int32 i=0;i < nSize;++i) + { + if( !bViewsSupported && i == 1) + continue; // no views supported + ::connectivity::ODatabaseMetaDataResultSet::ORow aRow; + aRow.push_back(::connectivity::ODatabaseMetaDataResultSet::getEmptyValue()); + aRow.push_back(new ::connectivity::ORowSetValueDecorator(sTableTypes[i])); + aRows.push_back(aRow); + } + pResult->setRows(aRows); + return xRef; +} +// ------------------------------------------------------------------------- +sal_Int32 ODatabaseMetaData::impl_getMaxStatements_throw( ) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_MAX_CONCURRENT_ACTIVITIES,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxProcedureNameLength( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_MAX_PROCEDURE_NAME_LEN,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxSchemaNameLength( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_MAX_SCHEMA_NAME_LEN,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsTransactions( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_TXN_CAPABLE,nValue,*this); + return nValue != SQL_TC_NONE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::allProceduresAreCallable( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_ACCESSIBLE_PROCEDURES,aValue,*this,m_pConnection->getTextEncoding()); + return aValue.toChar() == 'Y'; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsStoredProcedures( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_PROCEDURES,aValue,*this,m_pConnection->getTextEncoding()); + return aValue.toChar() == 'Y'; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSelectForUpdate( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_DYNAMIC_CURSOR_ATTRIBUTES1,nValue,*this); + return (nValue & SQL_CA1_POSITIONED_UPDATE) == SQL_CA1_POSITIONED_UPDATE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::allTablesAreSelectable( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_ACCESSIBLE_TABLES,aValue,*this,m_pConnection->getTextEncoding()); + return aValue.toChar() == 'Y'; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::isReadOnly( ) throw(SQLException, RuntimeException) +{ + return m_pConnection->isReadOnly(); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::usesLocalFiles( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_FILE_USAGE,nValue,*this); + return nValue == SQL_FILE_CATALOG; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::usesLocalFilePerTable( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_FILE_USAGE,nValue,*this); + return nValue == SQL_FILE_TABLE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsTypeConversion( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CONVERT_FUNCTIONS,nValue,*this); + return (nValue & SQL_FN_CVT_CONVERT) == SQL_FN_CVT_CONVERT; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::nullPlusNonNullIsNull( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CONCAT_NULL_BEHAVIOR,nValue,*this); + return nValue == SQL_CB_NULL; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsColumnAliasing( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_COLUMN_ALIAS,aValue,*this,m_pConnection->getTextEncoding()); + return aValue.toChar() == 'Y'; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsTableCorrelationNames( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CORRELATION_NAME,nValue,*this); + return nValue != SQL_CN_NONE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsConvert( sal_Int32 fromType, sal_Int32 toType ) throw(SQLException, RuntimeException) +{ + if(fromType == toType) + return sal_True; + + SQLUINTEGER nValue=0; + switch(fromType) + { + case DataType::BIT: + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CONVERT_BIT,nValue,*this); + break; + case DataType::TINYINT: + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CONVERT_TINYINT,nValue,*this); + break; + case DataType::SMALLINT: + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CONVERT_SMALLINT,nValue,*this); + break; + case DataType::INTEGER: + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CONVERT_INTEGER,nValue,*this); + break; + case DataType::BIGINT: + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CONVERT_BIGINT,nValue,*this); + break; + case DataType::FLOAT: + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CONVERT_FLOAT,nValue,*this); + break; + case DataType::REAL: + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CONVERT_REAL,nValue,*this); + break; + case DataType::DOUBLE: + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CONVERT_DOUBLE,nValue,*this); + break; + case DataType::NUMERIC: + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CONVERT_NUMERIC,nValue,*this); + break; + case DataType::DECIMAL: + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CONVERT_DECIMAL,nValue,*this); + break; + case DataType::CHAR: + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CONVERT_CHAR,nValue,*this); + break; + case DataType::VARCHAR: + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CONVERT_VARCHAR,nValue,*this); + break; + case DataType::LONGVARCHAR: + case DataType::CLOB: + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CONVERT_LONGVARCHAR,nValue,*this); + break; + case DataType::DATE: + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CONVERT_DATE,nValue,*this); + break; + case DataType::TIME: + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CONVERT_TIME,nValue,*this); + break; + case DataType::TIMESTAMP: + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CONVERT_TIMESTAMP,nValue,*this); + break; + case DataType::BINARY: + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CONVERT_BINARY,nValue,*this); + break; + case DataType::VARBINARY: + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CONVERT_VARBINARY,nValue,*this); + break; + case DataType::LONGVARBINARY: + case DataType::BLOB: + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CONVERT_LONGVARBINARY,nValue,*this); + break; + case DataType::SQLNULL: + // OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CORRELATION_NAME,nValue,*this); + break; + case DataType::OTHER: + // OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CORRELATION_NAME,nValue,*this); + break; + case DataType::OBJECT: + // OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CORRELATION_NAME,nValue,*this); + break; + case DataType::DISTINCT: + // OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CORRELATION_NAME,nValue,*this); + break; + case DataType::STRUCT: + // OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CORRELATION_NAME,nValue,*this); + break; + case DataType::ARRAY: + // OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CORRELATION_NAME,nValue,*this); + break; + case DataType::REF: + // OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CORRELATION_NAME,nValue,*this); + break; + } + sal_Bool bConvert = sal_False; + switch(toType) + { + case DataType::BIT: + bConvert = (nValue & SQL_CVT_BIT) == SQL_CVT_BIT; + break; + case DataType::TINYINT: + bConvert = (nValue & SQL_CVT_TINYINT) == SQL_CVT_TINYINT; + break; + case DataType::SMALLINT: + bConvert = (nValue & SQL_CVT_SMALLINT) == SQL_CVT_SMALLINT; + break; + case DataType::INTEGER: + bConvert = (nValue & SQL_CVT_INTEGER) == SQL_CVT_INTEGER; + break; + case DataType::BIGINT: + bConvert = (nValue & SQL_CVT_BIGINT) == SQL_CVT_BIGINT; + break; + case DataType::FLOAT: + bConvert = (nValue & SQL_CVT_FLOAT) == SQL_CVT_FLOAT; + break; + case DataType::REAL: + bConvert = (nValue & SQL_CVT_REAL) == SQL_CVT_REAL; + break; + case DataType::DOUBLE: + bConvert = (nValue & SQL_CVT_DOUBLE) == SQL_CVT_DOUBLE; + break; + case DataType::NUMERIC: + bConvert = (nValue & SQL_CVT_NUMERIC) == SQL_CVT_NUMERIC; + break; + case DataType::DECIMAL: + bConvert = (nValue & SQL_CVT_DECIMAL) == SQL_CVT_DECIMAL; + break; + case DataType::CHAR: + bConvert = (nValue & SQL_CVT_CHAR) == SQL_CVT_CHAR; + break; + case DataType::VARCHAR: + bConvert = (nValue & SQL_CVT_VARCHAR) == SQL_CVT_VARCHAR; + break; + case DataType::LONGVARCHAR: + case DataType::CLOB: + bConvert = (nValue & SQL_CVT_LONGVARCHAR) == SQL_CVT_LONGVARCHAR; + break; + case DataType::DATE: + bConvert = (nValue & SQL_CVT_DATE) == SQL_CVT_DATE; + break; + case DataType::TIME: + bConvert = (nValue & SQL_CVT_TIME) == SQL_CVT_TIME; + break; + case DataType::TIMESTAMP: + bConvert = (nValue & SQL_CVT_TIMESTAMP) == SQL_CVT_TIMESTAMP; + break; + case DataType::BINARY: + bConvert = (nValue & SQL_CVT_BINARY) == SQL_CVT_BINARY; + break; + case DataType::VARBINARY: + bConvert = (nValue & SQL_CVT_VARBINARY) == SQL_CVT_VARBINARY; + break; + case DataType::LONGVARBINARY: + case DataType::BLOB: + bConvert = (nValue & SQL_CVT_LONGVARBINARY) == SQL_CVT_LONGVARBINARY; + break; + } + + return bConvert; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsExpressionsInOrderBy( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_EXPRESSIONS_IN_ORDERBY,aValue,*this,m_pConnection->getTextEncoding()); + return aValue.toChar() == 'Y'; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsGroupBy( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_GROUP_BY,nValue,*this); + return nValue != SQL_GB_NOT_SUPPORTED; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsGroupByBeyondSelect( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_GROUP_BY,nValue,*this); + return nValue != SQL_GB_GROUP_BY_CONTAINS_SELECT; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsGroupByUnrelated( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_GROUP_BY,nValue,*this); + return nValue == SQL_GB_NO_RELATION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsMultipleTransactions( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_MULTIPLE_ACTIVE_TXN,aValue,*this,m_pConnection->getTextEncoding()); + return aValue.toChar() == 'Y'; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsMultipleResultSets( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_MULT_RESULT_SETS,aValue,*this,m_pConnection->getTextEncoding()); + return aValue.toChar() == 'Y'; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsLikeEscapeClause( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_LIKE_ESCAPE_CLAUSE,aValue,*this,m_pConnection->getTextEncoding()); + return aValue.toChar() == 'Y'; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOrderByUnrelated( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_ORDER_BY_COLUMNS_IN_SELECT,aValue,*this,m_pConnection->getTextEncoding()); + return aValue.toChar() == 'N'; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsUnion( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_UNION,nValue,*this); + return (nValue & SQL_U_UNION) == SQL_U_UNION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsUnionAll( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_UNION,nValue,*this); + return (nValue & SQL_U_UNION_ALL) == SQL_U_UNION_ALL; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsMixedCaseIdentifiers( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_IDENTIFIER_CASE,nValue,*this); + return nValue == SQL_IC_MIXED; +} +// ------------------------------------------------------------------------- +sal_Bool ODatabaseMetaData::impl_supportsMixedCaseQuotedIdentifiers_throw( ) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_QUOTED_IDENTIFIER_CASE,nValue,*this); + return nValue == SQL_IC_MIXED; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedAtEnd( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_NULL_COLLATION,nValue,*this); + return nValue == SQL_NC_END; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedAtStart( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_NULL_COLLATION,nValue,*this); + return nValue == SQL_NC_START; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedHigh( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_NULL_COLLATION,nValue,*this); + return nValue == SQL_NC_HIGH; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedLow( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_NULL_COLLATION,nValue,*this); + return nValue == SQL_NC_LOW; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInProcedureCalls( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_SCHEMA_USAGE,nValue,*this); + return (nValue & SQL_SU_PROCEDURE_INVOCATION) == SQL_SU_PROCEDURE_INVOCATION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInPrivilegeDefinitions( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_SCHEMA_USAGE,nValue,*this); + return (nValue & SQL_SU_PRIVILEGE_DEFINITION) == SQL_SU_PRIVILEGE_DEFINITION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInProcedureCalls( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue=0; + if(m_bUseCatalog) + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CATALOG_USAGE,nValue,*this); + return (nValue & SQL_CU_PROCEDURE_INVOCATION) == SQL_CU_PROCEDURE_INVOCATION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInPrivilegeDefinitions( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue=0; + if(m_bUseCatalog) + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CATALOG_USAGE,nValue,*this); + return (nValue & SQL_CU_PRIVILEGE_DEFINITION) == SQL_CU_PRIVILEGE_DEFINITION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCorrelatedSubqueries( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_SUBQUERIES,nValue,*this); + return (nValue & SQL_SQ_CORRELATED_SUBQUERIES) == SQL_SQ_CORRELATED_SUBQUERIES; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInComparisons( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_SUBQUERIES,nValue,*this); + return (nValue & SQL_SQ_COMPARISON) == SQL_SQ_COMPARISON; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInExists( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_SUBQUERIES,nValue,*this); + return (nValue & SQL_SQ_EXISTS) == SQL_SQ_EXISTS; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInIns( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_SUBQUERIES,nValue,*this); + return (nValue & SQL_SQ_IN) == SQL_SQ_IN; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInQuantifieds( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_SUBQUERIES,nValue,*this); + return (nValue & SQL_SQ_QUANTIFIED) == SQL_SQ_QUANTIFIED; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsANSI92IntermediateSQL( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_SQL_CONFORMANCE,nValue,*this); + return nValue == SQL_SC_SQL92_INTERMEDIATE; +} +// ----------------------------------------------------------------------------- +::rtl::OUString ODatabaseMetaData::getURLImpl() +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_DATA_SOURCE_NAME,aValue,*this,m_pConnection->getTextEncoding()); + return aValue; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getURL( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue = m_pConnection->getURL(); + if ( !aValue.getLength() ) + { + aValue = ::rtl::OUString::createFromAscii("sdbc:odbc:"); + aValue += getURLImpl(); + } + return aValue; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getUserName( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_USER_NAME,aValue,*this,m_pConnection->getTextEncoding()); + return aValue; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getDriverName( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_DRIVER_NAME,aValue,*this,m_pConnection->getTextEncoding()); + return aValue; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getDriverVersion() throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_DRIVER_ODBC_VER,aValue,*this,m_pConnection->getTextEncoding()); + return aValue; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getDatabaseProductVersion( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_DRIVER_VER,aValue,*this,m_pConnection->getTextEncoding()); + return aValue; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getDatabaseProductName( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_DBMS_NAME,aValue,*this,m_pConnection->getTextEncoding()); + return aValue; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getProcedureTerm( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_PROCEDURE_TERM,aValue,*this,m_pConnection->getTextEncoding()); + return aValue; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getSchemaTerm( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_SCHEMA_TERM,aValue,*this,m_pConnection->getTextEncoding()); + return aValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getDriverMajorVersion( ) throw(RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_DRIVER_VER,aValue,*this,m_pConnection->getTextEncoding()); + return aValue.copy(0,aValue.indexOf('.')).toInt32(); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getDefaultTransactionIsolation( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_SUBQUERIES,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getDriverMinorVersion( ) throw(RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_DRIVER_VER,aValue,*this,m_pConnection->getTextEncoding()); + return aValue.copy(0,aValue.lastIndexOf('.')).toInt32(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getSQLKeywords( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_KEYWORDS,aValue,*this,m_pConnection->getTextEncoding()); + return aValue; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getSearchStringEscape( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_SEARCH_PATTERN_ESCAPE,aValue,*this,m_pConnection->getTextEncoding()); + return aValue; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getStringFunctions( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + ::rtl::OUStringBuffer aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_STRING_FUNCTIONS,nValue,*this); + if(nValue & SQL_FN_STR_ASCII) + aValue.appendAscii("ASCII,"); + if(nValue & SQL_FN_STR_BIT_LENGTH) + aValue.appendAscii("BIT_LENGTH,"); + if(nValue & SQL_FN_STR_CHAR) + aValue.appendAscii("CHAR,"); + if(nValue & SQL_FN_STR_CHAR_LENGTH) + aValue.appendAscii("CHAR_LENGTH,"); + if(nValue & SQL_FN_STR_CHARACTER_LENGTH) + aValue.appendAscii("CHARACTER_LENGTH,"); + if(nValue & SQL_FN_STR_CONCAT) + aValue.appendAscii("CONCAT,"); + if(nValue & SQL_FN_STR_DIFFERENCE) + aValue.appendAscii("DIFFERENCE,"); + if(nValue & SQL_FN_STR_INSERT) + aValue.appendAscii("INSERT,"); + if(nValue & SQL_FN_STR_LCASE) + aValue.appendAscii("LCASE,"); + if(nValue & SQL_FN_STR_LEFT) + aValue.appendAscii("LEFT,"); + if(nValue & SQL_FN_STR_LENGTH) + aValue.appendAscii("LENGTH,"); + if(nValue & SQL_FN_STR_LOCATE) + aValue.appendAscii("LOCATE,"); + if(nValue & SQL_FN_STR_LOCATE_2) + aValue.appendAscii("LOCATE_2,"); + if(nValue & SQL_FN_STR_LTRIM) + aValue.appendAscii("LTRIM,"); + if(nValue & SQL_FN_STR_OCTET_LENGTH) + aValue.appendAscii("OCTET_LENGTH,"); + if(nValue & SQL_FN_STR_POSITION) + aValue.appendAscii("POSITION,"); + if(nValue & SQL_FN_STR_REPEAT) + aValue.appendAscii("REPEAT,"); + if(nValue & SQL_FN_STR_REPLACE) + aValue.appendAscii("REPLACE,"); + if(nValue & SQL_FN_STR_RIGHT) + aValue.appendAscii("RIGHT,"); + if(nValue & SQL_FN_STR_RTRIM) + aValue.appendAscii("RTRIM,"); + if(nValue & SQL_FN_STR_SOUNDEX) + aValue.appendAscii("SOUNDEX,"); + if(nValue & SQL_FN_STR_SPACE) + aValue.appendAscii("SPACE,"); + if(nValue & SQL_FN_STR_SUBSTRING) + aValue.appendAscii("SUBSTRING,"); + if(nValue & SQL_FN_STR_UCASE) + aValue.appendAscii("UCASE,"); + + + if ( aValue.getLength() ) + aValue.setLength(aValue.getLength()-1); + + return aValue.makeStringAndClear(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getTimeDateFunctions( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + ::rtl::OUStringBuffer aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_TIMEDATE_FUNCTIONS,nValue,*this); + + if(nValue & SQL_FN_TD_CURRENT_DATE) + aValue.appendAscii("CURRENT_DATE,"); + if(nValue & SQL_FN_TD_CURRENT_TIME) + aValue.appendAscii("CURRENT_TIME,"); + if(nValue & SQL_FN_TD_CURRENT_TIMESTAMP) + aValue.appendAscii("CURRENT_TIMESTAMP,"); + if(nValue & SQL_FN_TD_CURDATE) + aValue.appendAscii("CURDATE,"); + if(nValue & SQL_FN_TD_CURTIME) + aValue.appendAscii("CURTIME,"); + if(nValue & SQL_FN_TD_DAYNAME) + aValue.appendAscii("DAYNAME,"); + if(nValue & SQL_FN_TD_DAYOFMONTH) + aValue.appendAscii("DAYOFMONTH,"); + if(nValue & SQL_FN_TD_DAYOFWEEK) + aValue.appendAscii("DAYOFWEEK,"); + if(nValue & SQL_FN_TD_DAYOFYEAR) + aValue.appendAscii("DAYOFYEAR,"); + if(nValue & SQL_FN_TD_EXTRACT) + aValue.appendAscii("EXTRACT,"); + if(nValue & SQL_FN_TD_HOUR) + aValue.appendAscii("HOUR,"); + if(nValue & SQL_FN_TD_MINUTE) + aValue.appendAscii("MINUTE,"); + if(nValue & SQL_FN_TD_MONTH) + aValue.appendAscii("MONTH,"); + if(nValue & SQL_FN_TD_MONTHNAME) + aValue.appendAscii("MONTHNAME,"); + if(nValue & SQL_FN_TD_NOW) + aValue.appendAscii("NOW,"); + if(nValue & SQL_FN_TD_QUARTER) + aValue.appendAscii("QUARTER,"); + if(nValue & SQL_FN_TD_SECOND) + aValue.appendAscii("SECOND,"); + if(nValue & SQL_FN_TD_TIMESTAMPADD) + aValue.appendAscii("TIMESTAMPADD,"); + if(nValue & SQL_FN_TD_TIMESTAMPDIFF) + aValue.appendAscii("TIMESTAMPDIFF,"); + if(nValue & SQL_FN_TD_WEEK) + aValue.appendAscii("WEEK,"); + if(nValue & SQL_FN_TD_YEAR) + aValue.appendAscii("YEAR,"); + + if ( aValue.getLength() ) + aValue.setLength(aValue.getLength()-1); + + return aValue.makeStringAndClear(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getSystemFunctions( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + ::rtl::OUStringBuffer aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_SYSTEM_FUNCTIONS,nValue,*this); + + if(nValue & SQL_FN_SYS_DBNAME) + aValue.appendAscii("DBNAME,"); + if(nValue & SQL_FN_SYS_IFNULL) + aValue.appendAscii("IFNULL,"); + if(nValue & SQL_FN_SYS_USERNAME) + aValue.appendAscii("USERNAME,"); + + if ( aValue.getLength() ) + aValue.setLength(aValue.getLength()-1); + + return aValue.makeStringAndClear(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getNumericFunctions( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + ::rtl::OUStringBuffer aValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_NUMERIC_FUNCTIONS,nValue,*this); + + if(nValue & SQL_FN_NUM_ABS) + aValue.appendAscii("ABS,"); + if(nValue & SQL_FN_NUM_ACOS) + aValue.appendAscii("ACOS,"); + if(nValue & SQL_FN_NUM_ASIN) + aValue.appendAscii("ASIN,"); + if(nValue & SQL_FN_NUM_ATAN) + aValue.appendAscii("ATAN,"); + if(nValue & SQL_FN_NUM_ATAN2) + aValue.appendAscii("ATAN2,"); + if(nValue & SQL_FN_NUM_CEILING) + aValue.appendAscii("CEILING,"); + if(nValue & SQL_FN_NUM_COS) + aValue.appendAscii("COS,"); + if(nValue & SQL_FN_NUM_COT) + aValue.appendAscii("COT,"); + if(nValue & SQL_FN_NUM_DEGREES) + aValue.appendAscii("DEGREES,"); + if(nValue & SQL_FN_NUM_EXP) + aValue.appendAscii("EXP,"); + if(nValue & SQL_FN_NUM_FLOOR) + aValue.appendAscii("FLOOR,"); + if(nValue & SQL_FN_NUM_LOG) + aValue.appendAscii("LOGF,"); + if(nValue & SQL_FN_NUM_LOG10) + aValue.appendAscii("LOG10,"); + if(nValue & SQL_FN_NUM_MOD) + aValue.appendAscii("MOD,"); + if(nValue & SQL_FN_NUM_PI) + aValue.appendAscii("PI,"); + if(nValue & SQL_FN_NUM_POWER) + aValue.appendAscii("POWER,"); + if(nValue & SQL_FN_NUM_RADIANS) + aValue.appendAscii("RADIANS,"); + if(nValue & SQL_FN_NUM_RAND) + aValue.appendAscii("RAND,"); + if(nValue & SQL_FN_NUM_ROUND) + aValue.appendAscii("ROUND,"); + if(nValue & SQL_FN_NUM_SIGN) + aValue.appendAscii("SIGN,"); + if(nValue & SQL_FN_NUM_SIN) + aValue.appendAscii("SIN,"); + if(nValue & SQL_FN_NUM_SQRT) + aValue.appendAscii("SQRT,"); + if(nValue & SQL_FN_NUM_TAN) + aValue.appendAscii("TAN,"); + if(nValue & SQL_FN_NUM_TRUNCATE) + aValue.appendAscii("TRUNCATE,"); + + if ( aValue.getLength() ) + aValue.setLength(aValue.getLength()-1); + + return aValue.makeStringAndClear(); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsExtendedSQLGrammar( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + if(m_bOdbc3) + { + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_ODBC_INTERFACE_CONFORMANCE,nValue,*this); + return nValue == SQL_OIC_LEVEL2; + } + else + { + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_ODBC_INTERFACE_CONFORMANCE,nValue,*this); + return nValue == SQL_OAC_LEVEL2; + } +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCoreSQLGrammar( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + if(m_bOdbc3) + { + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_ODBC_INTERFACE_CONFORMANCE,nValue,*this); + return nValue == SQL_OIC_CORE || nValue == SQL_OIC_LEVEL2 || nValue == SQL_OIC_LEVEL1; + } + else + { + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_ODBC_SQL_CONFORMANCE,nValue,*this); + return nValue == SQL_OSC_CORE || nValue == SQL_OAC_LEVEL1 || nValue == SQL_OAC_LEVEL2; + } +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsMinimumSQLGrammar( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + if(m_bOdbc3) + { + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_ODBC_INTERFACE_CONFORMANCE,nValue,*this); + return nValue == SQL_OIC_LEVEL1 || nValue == SQL_OIC_LEVEL2; + } + else + { + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_ODBC_INTERFACE_CONFORMANCE,nValue,*this); + return nValue == SQL_OAC_LEVEL1 || nValue == SQL_OAC_LEVEL2; + } +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsFullOuterJoins( ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_OJ_CAPABILITIES,nValue,*this); + return (nValue & SQL_OJ_FULL) == SQL_OJ_FULL; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsLimitedOuterJoins( ) throw(SQLException, RuntimeException) +{ + return supportsFullOuterJoins( ); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInGroupBy( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_MAX_COLUMNS_IN_GROUP_BY,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInOrderBy( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_MAX_COLUMNS_IN_ORDER_BY,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInSelect( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_MAX_COLUMNS_IN_SELECT,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxUserNameLength( ) throw(SQLException, RuntimeException) +{ + SQLUSMALLINT nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_MAX_USER_NAME_LEN,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsResultSetType( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_CURSOR_SENSITIVITY,nValue,*this); + return (nValue & static_cast<SQLUINTEGER>(setType)) == static_cast<SQLUINTEGER>(setType); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsResultSetConcurrency( sal_Int32 setType, sal_Int32 concurrency ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + SQLUSMALLINT nAskFor( SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2 ); + switch(setType) + { + default: + case ResultSetType::FORWARD_ONLY: + nAskFor = SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2; + break; + case ResultSetType::SCROLL_INSENSITIVE: + nAskFor = SQL_STATIC_CURSOR_ATTRIBUTES2; + break; + case ResultSetType::SCROLL_SENSITIVE: + nAskFor = SQL_DYNAMIC_CURSOR_ATTRIBUTES2; + break; + } + + OTools::GetInfo(m_pConnection,m_aConnectionHandle,nAskFor,nValue,*this); + sal_Bool bRet = sal_False; + switch(concurrency) + { + case ResultSetConcurrency::READ_ONLY: + bRet = (nValue & SQL_CA2_READ_ONLY_CONCURRENCY) == SQL_CA2_READ_ONLY_CONCURRENCY; + break; + case ResultSetConcurrency::UPDATABLE: + bRet = (nValue & SQL_CA2_OPT_VALUES_CONCURRENCY) == SQL_CA2_OPT_VALUES_CONCURRENCY; + break; + } + return bRet; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::ownUpdatesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + SQLUSMALLINT nAskFor( SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2 ); + switch(setType) + { + default: + case ResultSetType::FORWARD_ONLY: + nAskFor = SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2; + break; + case ResultSetType::SCROLL_INSENSITIVE: + nAskFor = SQL_STATIC_CURSOR_ATTRIBUTES2; + break; + case ResultSetType::SCROLL_SENSITIVE: + nAskFor = SQL_DYNAMIC_CURSOR_ATTRIBUTES2; + break; + } + + OTools::GetInfo(m_pConnection,m_aConnectionHandle,nAskFor,nValue,*this); + return (nValue & SQL_CA2_SENSITIVITY_UPDATES) == SQL_CA2_SENSITIVITY_UPDATES; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::ownDeletesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + SQLUSMALLINT nAskFor( SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2 ); + switch(setType) + { + default: + case ResultSetType::FORWARD_ONLY: + nAskFor = SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2; + break; + case ResultSetType::SCROLL_INSENSITIVE: + nAskFor = SQL_STATIC_CURSOR_ATTRIBUTES2; + break; + case ResultSetType::SCROLL_SENSITIVE: + nAskFor = SQL_DYNAMIC_CURSOR_ATTRIBUTES2; + break; + } + + OTools::GetInfo(m_pConnection,m_aConnectionHandle,nAskFor,nValue,*this); + return (nValue & SQL_CA2_SENSITIVITY_DELETIONS) != SQL_CA2_SENSITIVITY_DELETIONS; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::ownInsertsAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + SQLUINTEGER nValue; + SQLUSMALLINT nAskFor( SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2 ); + switch(setType) + { + default: + case ResultSetType::FORWARD_ONLY: + nAskFor = SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2; + break; + case ResultSetType::SCROLL_INSENSITIVE: + nAskFor = SQL_STATIC_CURSOR_ATTRIBUTES2; + break; + case ResultSetType::SCROLL_SENSITIVE: + nAskFor = SQL_DYNAMIC_CURSOR_ATTRIBUTES2; + break; + } + + OTools::GetInfo(m_pConnection,m_aConnectionHandle,nAskFor,nValue,*this); + return (nValue & SQL_CA2_SENSITIVITY_ADDITIONS) == SQL_CA2_SENSITIVITY_ADDITIONS; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::othersUpdatesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + return ownUpdatesAreVisible(setType); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::othersDeletesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + return ownDeletesAreVisible(setType); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::othersInsertsAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + return ownInsertsAreVisible(setType); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::updatesAreDetected( sal_Int32 /*setType*/ ) throw(SQLException, RuntimeException) +{ + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::deletesAreDetected( sal_Int32 /*setType*/ ) throw(SQLException, RuntimeException) +{ + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::insertsAreDetected( sal_Int32 /*setType*/ ) throw(SQLException, RuntimeException) +{ + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsBatchUpdates( ) throw(SQLException, RuntimeException) +{ + return sal_False; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getUDTs( const Any& /*catalog*/, const ::rtl::OUString& /*schemaPattern*/, const ::rtl::OUString& /*typeNamePattern*/, const Sequence< sal_Int32 >& /*types*/ ) throw(SQLException, RuntimeException) +{ + return NULL; +} +// ----------------------------------------------------------------------------- diff --git a/connectivity/source/drivers/odbcbase/ODatabaseMetaDataResultSet.cxx b/connectivity/source/drivers/odbcbase/ODatabaseMetaDataResultSet.cxx new file mode 100644 index 000000000000..751ab7cf2988 --- /dev/null +++ b/connectivity/source/drivers/odbcbase/ODatabaseMetaDataResultSet.cxx @@ -0,0 +1,1323 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "TConnection.hxx" + +#ifndef _CONNECTIVITY_ADO_ADATABASEMETADATARESULTSET_HXX_ +#include "odbc/ODatabaseMetaDataResultSet.hxx" +#endif +#include <com/sun/star/sdbc/DataType.hpp> +#include <com/sun/star/sdbc/KeyRule.hpp> +#include <com/sun/star/sdbc/ProcedureResult.hpp> +#include <com/sun/star/sdbc/IndexType.hpp> +#include <comphelper/property.hxx> +#include <com/sun/star/lang/DisposedException.hpp> +#include <com/sun/star/sdbc/ResultSetConcurrency.hpp> +#include <com/sun/star/sdbc/ResultSetType.hpp> +#include <com/sun/star/sdbc/FetchDirection.hpp> +#include <cppuhelper/typeprovider.hxx> +#include <comphelper/sequence.hxx> +#include "odbc/OResultSetMetaData.hxx" +#include "odbc/OTools.hxx" +#include <comphelper/types.hxx> +#include "FDatabaseMetaDataResultSetMetaData.hxx" +#include <connectivity/dbexception.hxx> + +using namespace ::comphelper; + + +using namespace connectivity::odbc; +using namespace cppu; +//------------------------------------------------------------------------------ +using namespace ::com::sun::star::lang; +using namespace com::sun::star::uno; +using namespace com::sun::star::beans; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::util; + +// ------------------------------------------------------------------------- +ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet(OConnection* _pConnection) + :ODatabaseMetaDataResultSet_BASE(m_aMutex) + ,OPropertySetHelper(ODatabaseMetaDataResultSet_BASE::rBHelper) + + ,m_aStatementHandle(_pConnection->createStatementHandle()) + ,m_aStatement(NULL) + ,m_xMetaData(NULL) + ,m_pRowStatusArray(NULL) + ,m_pConnection(_pConnection) + ,m_nTextEncoding(_pConnection->getTextEncoding()) + ,m_nRowPos(-1) + ,m_nLastColumnPos(0) + ,m_nDriverColumnCount(0) + ,m_nCurrentFetchState(0) + ,m_bWasNull(sal_True) + ,m_bEOF(sal_False) + ,m_bFreeHandle(sal_False) +{ + OSL_ENSURE(m_pConnection,"ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet: No parent set!"); + osl_incrementInterlockedCount( &m_refCount ); + m_pConnection->acquire(); + m_pRowStatusArray = new SQLUSMALLINT[1]; // the default value + osl_decrementInterlockedCount( &m_refCount ); + // allocBuffer(); +} + +// ------------------------------------------------------------------------- +ODatabaseMetaDataResultSet::~ODatabaseMetaDataResultSet() +{ + OSL_ENSURE(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed,"Object wasn't disposed!"); + if(!ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + { + osl_incrementInterlockedCount( &m_refCount ); + dispose(); + } + delete [] m_pRowStatusArray; +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::disposing(void) +{ + OPropertySetHelper::disposing(); + + ::osl::MutexGuard aGuard(m_aMutex); + if(m_bFreeHandle) + m_pConnection->freeStatementHandle(m_aStatementHandle); + + m_aStatement = NULL; +m_xMetaData.clear(); + m_pConnection->release(); +} +// ------------------------------------------------------------------------- +Any SAL_CALL ODatabaseMetaDataResultSet::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = OPropertySetHelper::queryInterface(rType); + return aRet.hasValue() ? aRet : ODatabaseMetaDataResultSet_BASE::queryInterface(rType); +} +// ----------------------------------------------------------------------------- +Reference< XPropertySetInfo > SAL_CALL ODatabaseMetaDataResultSet::getPropertySetInfo( ) throw(RuntimeException) +{ + return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); +} +// ----------------------------------------------------------------------------- +void SAL_CALL ODatabaseMetaDataResultSet::acquire() throw() +{ + ODatabaseMetaDataResultSet_BASE::acquire(); +} +// ----------------------------------------------------------------------------- +void SAL_CALL ODatabaseMetaDataResultSet::release() throw() +{ + ODatabaseMetaDataResultSet_BASE::release(); +} +// ------------------------------------------------------------------------- +Sequence< Type > SAL_CALL ODatabaseMetaDataResultSet::getTypes( ) throw(RuntimeException) +{ + ::cppu::OTypeCollection aTypes( ::getCppuType( (const Reference< XMultiPropertySet > *)0 ), + ::getCppuType( (const Reference< XFastPropertySet > *)0 ), + ::getCppuType( (const Reference< XPropertySet > *)0 )); + + return ::comphelper::concatSequences(aTypes.getTypes(),ODatabaseMetaDataResultSet_BASE::getTypes()); +} +// ----------------------------------------------------------------------------- +sal_Int32 ODatabaseMetaDataResultSet::mapColumn (sal_Int32 column) +{ + sal_Int32 map = column; + + if (!m_aColMapping.empty()) + { + // Validate column number + map = m_aColMapping[column]; + } + + return map; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::findColumn( const ::rtl::OUString& columnName ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + Reference< XResultSetMetaData > xMeta = getMetaData(); + sal_Int32 nLen = xMeta->getColumnCount(); + sal_Int32 i = 1; + for(;i<=nLen;++i) + if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) : + columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i))) + break; + return i; +} +// ------------------------------------------------------------------------- +Reference< ::com::sun::star::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getBinaryStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException) +{ + ::dbtools::throwFunctionNotSupportedException( "XRow::getBinaryStream", *this ); + return NULL; +} +// ------------------------------------------------------------------------- +Reference< ::com::sun::star::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getCharacterStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException) +{ + ::dbtools::throwFunctionNotSupportedException( "XRow::getCharacterStream", *this ); + return NULL; +} + +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + columnIndex = mapColumn(columnIndex); + + sal_Bool bRet = sal_False; + if(columnIndex <= m_nDriverColumnCount) + { + sal_Int32 nType = getMetaData()->getColumnType(columnIndex); + switch(nType) + { + case DataType::BIT: + { + sal_Int8 nValue = 0; + OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_BIT,m_bWasNull,**this,&nValue,sizeof nValue); + bRet = nValue != 0; + } + break; + default: + bRet = getInt(columnIndex) != 0; + } + } + return bRet; +} +// ------------------------------------------------------------------------- + +sal_Int8 SAL_CALL ODatabaseMetaDataResultSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + columnIndex = mapColumn(columnIndex); + sal_Int8 nVal = 0; + if(columnIndex <= m_nDriverColumnCount) + { + OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_TINYINT,m_bWasNull,**this,&nVal,sizeof nVal); + + ::std::map<sal_Int32, ::connectivity::TInt2IntMap >::iterator aValueRangeIter; + if ( !m_aValueRange.empty() && (aValueRangeIter = m_aValueRange.find(columnIndex)) != m_aValueRange.end()) + return sal_Int8((*aValueRangeIter).second[(sal_Int32)nVal]); + } + else + m_bWasNull = sal_True; + return nVal; +} +// ------------------------------------------------------------------------- + +Sequence< sal_Int8 > SAL_CALL ODatabaseMetaDataResultSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + columnIndex = mapColumn(columnIndex); + if(columnIndex <= m_nDriverColumnCount) + { + sal_Int32 nType = getMetaData()->getColumnType(columnIndex); + switch(nType) + { + case DataType::VARCHAR: + case DataType::LONGVARCHAR: + { + ::rtl::OUString aRet = OTools::getStringValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_BINARY,m_bWasNull,**this,m_nTextEncoding); + return Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(aRet.getStr()),sizeof(sal_Unicode)*aRet.getLength()); + } + } + return OTools::getBytesValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_BINARY,m_bWasNull,**this); + } + else + m_bWasNull = sal_True; + return Sequence<sal_Int8>(); +} +// ------------------------------------------------------------------------- + +::com::sun::star::util::Date SAL_CALL ODatabaseMetaDataResultSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + columnIndex = mapColumn(columnIndex); + if(columnIndex <= m_nDriverColumnCount) + { + DATE_STRUCT aDate; + aDate.day = 0; + aDate.month = 0; + aDate.year = 0; + OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,m_pConnection->useOldDateFormat() ? SQL_C_DATE : SQL_C_TYPE_DATE,m_bWasNull,**this,&aDate,sizeof aDate); + return Date(aDate.day,aDate.month,aDate.year); + } + else + m_bWasNull = sal_True; + return Date(); +} +// ------------------------------------------------------------------------- + +double SAL_CALL ODatabaseMetaDataResultSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + columnIndex = mapColumn(columnIndex); + double nValue(0.0); + if(columnIndex <= m_nDriverColumnCount) + OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_DOUBLE,m_bWasNull,**this,&nValue,sizeof nValue); + else + m_bWasNull = sal_True; + return nValue; +} +// ------------------------------------------------------------------------- + +float SAL_CALL ODatabaseMetaDataResultSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + columnIndex = mapColumn(columnIndex); + float nVal(0); + if(columnIndex <= m_nDriverColumnCount) + OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_FLOAT,m_bWasNull,**this,&nVal,sizeof nVal); + else + m_bWasNull = sal_True; + return nVal; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + columnIndex = mapColumn(columnIndex); + sal_Int32 nVal = 0; + if(columnIndex <= m_nDriverColumnCount) + { + OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_LONG,m_bWasNull,**this,&nVal,sizeof nVal); + + ::std::map<sal_Int32, ::connectivity::TInt2IntMap >::iterator aValueRangeIter; + if ( !m_aValueRange.empty() && (aValueRangeIter = m_aValueRange.find(columnIndex)) != m_aValueRange.end()) + return (*aValueRangeIter).second[(sal_Int32)nVal]; + } + else + m_bWasNull = sal_True; + return nVal; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getRow( ) throw(SQLException, RuntimeException) +{ + return 0; +} +// ------------------------------------------------------------------------- + +sal_Int64 SAL_CALL ODatabaseMetaDataResultSet::getLong( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException) +{ + ::dbtools::throwFunctionNotSupportedException( "XRow::getLong", *this ); + return 0; +} +// ------------------------------------------------------------------------- + +Reference< XResultSetMetaData > SAL_CALL ODatabaseMetaDataResultSet::getMetaData( ) throw(SQLException, RuntimeException) +{ + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + return m_xMetaData.is() ? m_xMetaData : (m_xMetaData = new OResultSetMetaData(m_pConnection,m_aStatementHandle)); +} +// ------------------------------------------------------------------------- +Reference< XArray > SAL_CALL ODatabaseMetaDataResultSet::getArray( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException) +{ + ::dbtools::throwFunctionNotSupportedException( "XRow::getArray", *this ); + return NULL; +} +// ------------------------------------------------------------------------- +Reference< XClob > SAL_CALL ODatabaseMetaDataResultSet::getClob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException) +{ + ::dbtools::throwFunctionNotSupportedException( "XRow::getClob", *this ); + return NULL; +} +// ------------------------------------------------------------------------- +Reference< XBlob > SAL_CALL ODatabaseMetaDataResultSet::getBlob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException) +{ + ::dbtools::throwFunctionNotSupportedException( "XRow::getBlob", *this ); + return NULL; +} +// ------------------------------------------------------------------------- + +Reference< XRef > SAL_CALL ODatabaseMetaDataResultSet::getRef( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException) +{ + ::dbtools::throwFunctionNotSupportedException( "XRow::getRef", *this ); + return NULL; +} +// ------------------------------------------------------------------------- + +Any SAL_CALL ODatabaseMetaDataResultSet::getObject( sal_Int32 /*columnIndex*/, const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException) +{ + ::dbtools::throwFunctionNotSupportedException( "XRow::getObject", *this ); + return Any(); +} +// ------------------------------------------------------------------------- + +sal_Int16 SAL_CALL ODatabaseMetaDataResultSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + columnIndex = mapColumn(columnIndex); + sal_Int16 nVal = 0; + if(columnIndex <= m_nDriverColumnCount) + { + OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_SHORT,m_bWasNull,**this,&nVal,sizeof nVal); + + ::std::map<sal_Int32, ::connectivity::TInt2IntMap >::iterator aValueRangeIter; + if ( !m_aValueRange.empty() && (aValueRangeIter = m_aValueRange.find(columnIndex)) != m_aValueRange.end()) + return sal_Int16((*aValueRangeIter).second[(sal_Int32)nVal]); + } + else + m_bWasNull = sal_True; + return nVal; +} +// ------------------------------------------------------------------------- + +::rtl::OUString SAL_CALL ODatabaseMetaDataResultSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + columnIndex = mapColumn(columnIndex); + ::rtl::OUString aVal; + if(columnIndex <= m_nDriverColumnCount) + aVal = OTools::getStringValue(m_pConnection,m_aStatementHandle,columnIndex,impl_getColumnType_nothrow(columnIndex),m_bWasNull,**this,m_nTextEncoding); + else + m_bWasNull = sal_True; + + return aVal; +} + +// ------------------------------------------------------------------------- + + +::com::sun::star::util::Time SAL_CALL ODatabaseMetaDataResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + columnIndex = mapColumn(columnIndex); + TIME_STRUCT aTime={0,0,0}; + if(columnIndex <= m_nDriverColumnCount) + OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,m_pConnection->useOldDateFormat() ? SQL_C_TIME : SQL_C_TYPE_TIME,m_bWasNull,**this,&aTime,sizeof aTime); + else + m_bWasNull = sal_True; + return Time(0,aTime.second,aTime.minute,aTime.hour); +} +// ------------------------------------------------------------------------- + + +::com::sun::star::util::DateTime SAL_CALL ODatabaseMetaDataResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + columnIndex = mapColumn(columnIndex); + TIMESTAMP_STRUCT aTime={0,0,0,0,0,0,0}; + if(columnIndex <= m_nDriverColumnCount) + OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,m_pConnection->useOldDateFormat() ? SQL_C_TIMESTAMP : SQL_C_TYPE_TIMESTAMP,m_bWasNull,**this,&aTime,sizeof aTime); + else + m_bWasNull = sal_True; + return DateTime((sal_uInt16)aTime.fraction*1000,aTime.second,aTime.minute,aTime.hour,aTime.day,aTime.month,aTime.year); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isAfterLast( ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + return m_nCurrentFetchState == SQL_NO_DATA; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isFirst( ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + return m_nRowPos == 1; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isLast( ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + return m_bEOF && m_nCurrentFetchState != SQL_NO_DATA; +} +// ------------------------------------------------------------------------- +void SAL_CALL ODatabaseMetaDataResultSet::beforeFirst( ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + if(first()) + previous(); + m_nCurrentFetchState = SQL_SUCCESS; +} +// ------------------------------------------------------------------------- +void SAL_CALL ODatabaseMetaDataResultSet::afterLast( ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + if(last()) + next(); + m_bEOF = sal_True; +} +// ------------------------------------------------------------------------- + +void SAL_CALL ODatabaseMetaDataResultSet::close( ) throw(SQLException, RuntimeException) +{ + { + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + } + dispose(); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::first( ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_FIRST,0); + OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this); + sal_Bool bRet = ( m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO ); + if( bRet ) + m_nRowPos = 1; + return bRet; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::last( ) throw(SQLException, RuntimeException) +{ + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed ); + ::osl::MutexGuard aGuard( m_aMutex ); + + + m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_LAST,0); + OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this); + // here I know definitely that I stand on the last record + return (m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_ABSOLUTE,row); + OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this); + sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO; + if(bRet) + m_nRowPos = row; + return bRet; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::relative( sal_Int32 row ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_RELATIVE,row); + OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this); + sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO; + if(bRet) + m_nRowPos += row; + return bRet; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::previous( ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0); + OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this); + sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO; + if(bRet) + --m_nRowPos; + return bRet; +} +// ------------------------------------------------------------------------- +Reference< XInterface > SAL_CALL ODatabaseMetaDataResultSet::getStatement( ) throw(SQLException, RuntimeException) +{ + return NULL; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowDeleted( ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + return m_pRowStatusArray[0] == SQL_ROW_DELETED; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowInserted( ) throw(SQLException, RuntimeException) +{ + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + return m_pRowStatusArray[0] == SQL_ROW_ADDED; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowUpdated( ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + return m_pRowStatusArray[0] == SQL_ROW_UPDATED; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isBeforeFirst( ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + return m_nRowPos == 0; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::next( ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + // m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_NEXT,0); + m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle); + OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this); + return m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::wasNull( ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + return m_bWasNull; +} +// ------------------------------------------------------------------------- +void SAL_CALL ODatabaseMetaDataResultSet::refreshRow( ) throw(SQLException, RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + +} +// ------------------------------------------------------------------------- + +void SAL_CALL ODatabaseMetaDataResultSet::cancel( ) throw(RuntimeException) +{ + + checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + OTools::ThrowException(m_pConnection,N3SQLCancel(m_aStatementHandle),m_aStatementHandle,SQL_HANDLE_STMT,*this); +} +// ------------------------------------------------------------------------- +void SAL_CALL ODatabaseMetaDataResultSet::clearWarnings( ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- +Any SAL_CALL ODatabaseMetaDataResultSet::getWarnings( ) throw(SQLException, RuntimeException) +{ + return Any(); +} +//------------------------------------------------------------------------------ +sal_Int32 ODatabaseMetaDataResultSet::getResultSetConcurrency() const throw(SQLException, RuntimeException) +{ + return ResultSetConcurrency::READ_ONLY; +} +//------------------------------------------------------------------------------ +sal_Int32 ODatabaseMetaDataResultSet::getResultSetType() const throw(SQLException, RuntimeException) +{ + return ResultSetType::FORWARD_ONLY; +} +//------------------------------------------------------------------------------ +sal_Int32 ODatabaseMetaDataResultSet::getFetchDirection() const throw(SQLException, RuntimeException) +{ + return FetchDirection::FORWARD; +} +//------------------------------------------------------------------------------ +sal_Int32 ODatabaseMetaDataResultSet::getFetchSize() const throw(SQLException, RuntimeException) +{ + sal_Int32 nValue=1; + return nValue; +} +//------------------------------------------------------------------------------ +::rtl::OUString ODatabaseMetaDataResultSet::getCursorName() const throw(SQLException, RuntimeException) +{ + return ::rtl::OUString(); +} + +// ------------------------------------------------------------------------- +::cppu::IPropertyArrayHelper* ODatabaseMetaDataResultSet::createArrayHelper( ) const +{ + + Sequence< com::sun::star::beans::Property > aProps(5); + com::sun::star::beans::Property* pProperties = aProps.getArray(); + sal_Int32 nPos = 0; + DECL_PROP0(CURSORNAME, ::rtl::OUString); + DECL_PROP0(FETCHDIRECTION, sal_Int32); + DECL_PROP0(FETCHSIZE, sal_Int32); + DECL_PROP0(RESULTSETCONCURRENCY,sal_Int32); + DECL_PROP0(RESULTSETTYPE, sal_Int32); + + return new ::cppu::OPropertyArrayHelper(aProps); +} +// ------------------------------------------------------------------------- +::cppu::IPropertyArrayHelper & ODatabaseMetaDataResultSet::getInfoHelper() +{ + return *const_cast<ODatabaseMetaDataResultSet*>(this)->getArrayHelper(); +} +// ------------------------------------------------------------------------- +sal_Bool ODatabaseMetaDataResultSet::convertFastPropertyValue( + Any & rConvertedValue, + Any & rOldValue, + sal_Int32 nHandle, + const Any& rValue ) + throw (::com::sun::star::lang::IllegalArgumentException) +{ + switch(nHandle) + { + case PROPERTY_ID_CURSORNAME: + case PROPERTY_ID_RESULTSETCONCURRENCY: + case PROPERTY_ID_RESULTSETTYPE: + throw ::com::sun::star::lang::IllegalArgumentException(); + case PROPERTY_ID_FETCHDIRECTION: + return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection()); + case PROPERTY_ID_FETCHSIZE: + return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize()); + default: + ; + } + return sal_False; +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& /*rValue*/ ) throw (Exception) +{ + switch(nHandle) + { + case PROPERTY_ID_CURSORNAME: + case PROPERTY_ID_RESULTSETCONCURRENCY: + case PROPERTY_ID_RESULTSETTYPE: + case PROPERTY_ID_FETCHDIRECTION: + case PROPERTY_ID_FETCHSIZE: + throw Exception(); + default: + OSL_ENSURE(0,"setFastPropertyValue_NoBroadcast: Illegal handle value!"); + } +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const +{ + switch(nHandle) + { + case PROPERTY_ID_CURSORNAME: + rValue <<= getCursorName(); + break; + case PROPERTY_ID_RESULTSETCONCURRENCY: + rValue <<= getResultSetConcurrency(); + break; + case PROPERTY_ID_RESULTSETTYPE: + rValue <<= getResultSetType(); + break; + case PROPERTY_ID_FETCHDIRECTION: + rValue <<= getFetchDirection(); + break; + case PROPERTY_ID_FETCHSIZE: + rValue <<= getFetchSize(); + break; + } +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::openTypeInfo() throw(SQLException, RuntimeException) +{ + TInt2IntMap aMap; + aMap[SQL_BIT] = DataType::BIT; + aMap[SQL_TINYINT] = DataType::TINYINT; + aMap[SQL_SMALLINT] = DataType::SMALLINT; + aMap[SQL_INTEGER] = DataType::INTEGER; + aMap[SQL_FLOAT] = DataType::FLOAT; + aMap[SQL_REAL] = DataType::REAL; + aMap[SQL_DOUBLE] = DataType::DOUBLE; + aMap[SQL_BIGINT] = DataType::BIGINT; + + aMap[SQL_CHAR] = DataType::CHAR; + aMap[SQL_WCHAR] = DataType::CHAR; + aMap[SQL_VARCHAR] = DataType::VARCHAR; + aMap[SQL_WVARCHAR] = DataType::VARCHAR; + aMap[SQL_LONGVARCHAR] = DataType::LONGVARCHAR; + aMap[SQL_WLONGVARCHAR] = DataType::LONGVARCHAR; + + aMap[SQL_TYPE_DATE] = DataType::DATE; + aMap[SQL_DATE] = DataType::DATE; + aMap[SQL_TYPE_TIME] = DataType::TIME; + aMap[SQL_TIME] = DataType::TIME; + aMap[SQL_TYPE_TIMESTAMP] = DataType::TIMESTAMP; + aMap[SQL_TIMESTAMP] = DataType::TIMESTAMP; + + aMap[SQL_DECIMAL] = DataType::DECIMAL; + aMap[SQL_NUMERIC] = DataType::NUMERIC; + + aMap[SQL_BINARY] = DataType::BINARY; + aMap[SQL_VARBINARY] = DataType::VARBINARY; + aMap[SQL_LONGVARBINARY] = DataType::LONGVARBINARY; + + aMap[SQL_GUID] = DataType::VARBINARY; + + + m_aValueRange[2] = aMap; + + OTools::ThrowException(m_pConnection,N3SQLGetTypeInfo(m_aStatementHandle, SQL_ALL_TYPES),m_aStatementHandle,SQL_HANDLE_STMT,*this); + checkColumnCount(); +} +//----------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::openTables(const Any& catalog, const ::rtl::OUString& schemaPattern, + const ::rtl::OUString& tableNamePattern, + const Sequence< ::rtl::OUString >& types ) throw(SQLException, RuntimeException) +{ + m_bFreeHandle = sal_True; + ::rtl::OString aPKQ,aPKO,aPKN,aCOL; + const ::rtl::OUString *pSchemaPat = NULL; + + if(schemaPattern.toChar() != '%') + pSchemaPat = &schemaPattern; + else + pSchemaPat = NULL; + + if ( catalog.hasValue() ) + aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding); + aPKO = ::rtl::OUStringToOString(schemaPattern,m_nTextEncoding); + + const char *pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr() : NULL, + *pPKO = pSchemaPat && pSchemaPat->getLength() ? aPKO.getStr() : NULL, + *pPKN = aPKN = ::rtl::OUStringToOString(tableNamePattern,m_nTextEncoding).getStr(); + + + const char *pCOL = NULL; + const char* pComma = ","; + const ::rtl::OUString* pBegin = types.getConstArray(); + const ::rtl::OUString* pEnd = pBegin + types.getLength(); + for(;pBegin != pEnd;++pBegin) + { + aCOL += ::rtl::OUStringToOString(*pBegin,m_nTextEncoding); + aCOL += pComma; + } + if ( aCOL.getLength() ) + { + aCOL = aCOL.replaceAt(aCOL.getLength()-1,1,pComma); + pCOL = aCOL.getStr(); + } + else + pCOL = SQL_ALL_TABLE_TYPES; + + SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle, + (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pPKN, SQL_NTS, + (SDB_ODBC_CHAR *) pCOL, pCOL ? SQL_NTS : 0); + OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); + checkColumnCount(); + +} +//----------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::openTablesTypes( ) throw(SQLException, RuntimeException) +{ + m_bFreeHandle = sal_True; + SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle, + 0,0, + 0,0, + 0,0, + (SDB_ODBC_CHAR *) SQL_ALL_TABLE_TYPES,SQL_NTS); + OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); + + m_aColMapping.clear(); + m_aColMapping.push_back(-1); + m_aColMapping.push_back(4); + m_xMetaData = new OResultSetMetaData(m_pConnection,m_aStatementHandle,m_aColMapping); + checkColumnCount(); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::openCatalogs() throw(SQLException, RuntimeException) +{ + m_bFreeHandle = sal_True; + SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle, + (SDB_ODBC_CHAR *) SQL_ALL_CATALOGS,SQL_NTS, + (SDB_ODBC_CHAR *) "",SQL_NTS, + (SDB_ODBC_CHAR *) "",SQL_NTS, + (SDB_ODBC_CHAR *) "",SQL_NTS); + + OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); + + m_aColMapping.clear(); + m_aColMapping.push_back(-1); + m_aColMapping.push_back(1); + m_xMetaData = new OResultSetMetaData(m_pConnection,m_aStatementHandle,m_aColMapping); + checkColumnCount(); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::openSchemas() throw(SQLException, RuntimeException) +{ + m_bFreeHandle = sal_True; + SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle, + (SDB_ODBC_CHAR *) "",SQL_NTS, + (SDB_ODBC_CHAR *) SQL_ALL_SCHEMAS,SQL_NTS, + (SDB_ODBC_CHAR *) "",SQL_NTS, + (SDB_ODBC_CHAR *) "",SQL_NTS); + OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); + + m_aColMapping.clear(); + m_aColMapping.push_back(-1); + m_aColMapping.push_back(2); + m_xMetaData = new OResultSetMetaData(m_pConnection,m_aStatementHandle,m_aColMapping); + checkColumnCount(); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::openColumnPrivileges( const Any& catalog, const ::rtl::OUString& schema, + const ::rtl::OUString& table, const ::rtl::OUString& columnNamePattern ) + throw(SQLException, RuntimeException) +{ + const ::rtl::OUString *pSchemaPat = NULL; + + if(schema.toChar() != '%') + pSchemaPat = &schema; + else + pSchemaPat = NULL; + + m_bFreeHandle = sal_True; + ::rtl::OString aPKQ,aPKO,aPKN,aCOL; + + aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding); + aPKO = ::rtl::OUStringToOString(schema,m_nTextEncoding); + + const char *pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr() : NULL, + *pPKO = pSchemaPat && pSchemaPat->getLength() ? aPKO.getStr() : NULL, + *pPKN = aPKN = ::rtl::OUStringToOString(table,m_nTextEncoding).getStr(), + *pCOL = aCOL = ::rtl::OUStringToOString(columnNamePattern,m_nTextEncoding).getStr(); + + + SQLRETURN nRetcode = N3SQLColumnPrivileges(m_aStatementHandle, + (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 , + (SDB_ODBC_CHAR *) pPKN, SQL_NTS, + (SDB_ODBC_CHAR *) pCOL, SQL_NTS); + OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); + + checkColumnCount(); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::openColumns( const Any& catalog, const ::rtl::OUString& schemaPattern, + const ::rtl::OUString& tableNamePattern, const ::rtl::OUString& columnNamePattern ) + throw(SQLException, RuntimeException) +{ + const ::rtl::OUString *pSchemaPat = NULL; + + if(schemaPattern.toChar() != '%') + pSchemaPat = &schemaPattern; + else + pSchemaPat = NULL; + + m_bFreeHandle = sal_True; + ::rtl::OString aPKQ,aPKO,aPKN,aCOL; + aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding); + aPKO = ::rtl::OUStringToOString(schemaPattern,m_nTextEncoding); + + const char *pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr() : NULL, + *pPKO = pSchemaPat && pSchemaPat->getLength() && pSchemaPat->getLength() ? aPKO.getStr() : NULL, + *pPKN = aPKN = ::rtl::OUStringToOString(tableNamePattern,m_nTextEncoding).getStr(), + *pCOL = aCOL = ::rtl::OUStringToOString(columnNamePattern,m_nTextEncoding).getStr(); + + + SQLRETURN nRetcode = N3SQLColumns(m_aStatementHandle, + (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pPKN, SQL_NTS, + (SDB_ODBC_CHAR *) pCOL, SQL_NTS); + + OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); + TInt2IntMap aMap; + aMap[SQL_BIT] = DataType::BIT; + aMap[SQL_TINYINT] = DataType::TINYINT; + aMap[SQL_SMALLINT] = DataType::SMALLINT; + aMap[SQL_INTEGER] = DataType::INTEGER; + aMap[SQL_FLOAT] = DataType::FLOAT; + aMap[SQL_REAL] = DataType::REAL; + aMap[SQL_DOUBLE] = DataType::DOUBLE; + aMap[SQL_BIGINT] = DataType::BIGINT; + + aMap[SQL_CHAR] = DataType::CHAR; + aMap[SQL_WCHAR] = DataType::CHAR; + aMap[SQL_VARCHAR] = DataType::VARCHAR; + aMap[SQL_WVARCHAR] = DataType::VARCHAR; + aMap[SQL_LONGVARCHAR] = DataType::LONGVARCHAR; + aMap[SQL_WLONGVARCHAR] = DataType::LONGVARCHAR; + + aMap[SQL_TYPE_DATE] = DataType::DATE; + aMap[SQL_DATE] = DataType::DATE; + aMap[SQL_TYPE_TIME] = DataType::TIME; + aMap[SQL_TIME] = DataType::TIME; + aMap[SQL_TYPE_TIMESTAMP] = DataType::TIMESTAMP; + aMap[SQL_TIMESTAMP] = DataType::TIMESTAMP; + + aMap[SQL_DECIMAL] = DataType::DECIMAL; + aMap[SQL_NUMERIC] = DataType::NUMERIC; + + aMap[SQL_BINARY] = DataType::BINARY; + aMap[SQL_VARBINARY] = DataType::VARBINARY; + aMap[SQL_LONGVARBINARY] = DataType::LONGVARBINARY; + + aMap[SQL_GUID] = DataType::VARBINARY; + + m_aValueRange[5] = aMap; + checkColumnCount(); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::openProcedureColumns( const Any& catalog, const ::rtl::OUString& schemaPattern, + const ::rtl::OUString& procedureNamePattern,const ::rtl::OUString& columnNamePattern ) + throw(SQLException, RuntimeException) +{ + const ::rtl::OUString *pSchemaPat = NULL; + + if(schemaPattern.toChar() != '%') + pSchemaPat = &schemaPattern; + else + pSchemaPat = NULL; + + m_bFreeHandle = sal_True; + ::rtl::OString aPKQ,aPKO,aPKN,aCOL; + aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding); + aPKO = ::rtl::OUStringToOString(schemaPattern,m_nTextEncoding); + + const char *pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr() : NULL, + *pPKO = pSchemaPat && pSchemaPat->getLength() ? aPKO.getStr() : NULL, + *pPKN = aPKN = ::rtl::OUStringToOString(procedureNamePattern,m_nTextEncoding).getStr(), + *pCOL = aCOL = ::rtl::OUStringToOString(columnNamePattern,m_nTextEncoding).getStr(); + + + SQLRETURN nRetcode = N3SQLProcedureColumns(m_aStatementHandle, + (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 , + (SDB_ODBC_CHAR *) pPKN, SQL_NTS, + (SDB_ODBC_CHAR *) pCOL, SQL_NTS); + + OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); + checkColumnCount(); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::openProcedures(const Any& catalog, const ::rtl::OUString& schemaPattern, + const ::rtl::OUString& procedureNamePattern) + throw(SQLException, RuntimeException) +{ + const ::rtl::OUString *pSchemaPat = NULL; + + if(schemaPattern.toChar() != '%') + pSchemaPat = &schemaPattern; + else + pSchemaPat = NULL; + + m_bFreeHandle = sal_True; + ::rtl::OString aPKQ,aPKO,aPKN,aCOL; + + aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding); + aPKO = ::rtl::OUStringToOString(schemaPattern,m_nTextEncoding); + + const char *pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr() : NULL, + *pPKO = pSchemaPat && pSchemaPat->getLength() ? aPKO.getStr() : NULL, + *pPKN = aPKN = ::rtl::OUStringToOString(procedureNamePattern,m_nTextEncoding).getStr(); + + + SQLRETURN nRetcode = N3SQLProcedures(m_aStatementHandle, + (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 , + (SDB_ODBC_CHAR *) pPKN, SQL_NTS); + OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); + checkColumnCount(); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::openSpecialColumns(sal_Bool _bRowVer,const Any& catalog, const ::rtl::OUString& schema, + const ::rtl::OUString& table,sal_Int32 scope, sal_Bool nullable ) + throw(SQLException, RuntimeException) +{ + const ::rtl::OUString *pSchemaPat = NULL; + + if(schema.toChar() != '%') + pSchemaPat = &schema; + else + pSchemaPat = NULL; + + m_bFreeHandle = sal_True; + ::rtl::OString aPKQ,aPKO,aPKN,aCOL; + aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding); + aPKO = ::rtl::OUStringToOString(schema,m_nTextEncoding); + + const char *pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr() : NULL, + *pPKO = pSchemaPat && pSchemaPat->getLength() ? aPKO.getStr() : NULL, + *pPKN = aPKN = ::rtl::OUStringToOString(table,m_nTextEncoding).getStr(); + + + SQLRETURN nRetcode = N3SQLSpecialColumns(m_aStatementHandle,_bRowVer ? SQL_ROWVER : SQL_BEST_ROWID, + (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 , + (SDB_ODBC_CHAR *) pPKN, SQL_NTS, + (SQLSMALLINT)scope, + nullable ? SQL_NULLABLE : SQL_NO_NULLS); + OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); + checkColumnCount(); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::openVersionColumns(const Any& catalog, const ::rtl::OUString& schema, + const ::rtl::OUString& table) throw(SQLException, RuntimeException) +{ + openSpecialColumns(sal_True,catalog,schema,table,SQL_SCOPE_TRANSACTION,sal_False); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::openBestRowIdentifier( const Any& catalog, const ::rtl::OUString& schema, + const ::rtl::OUString& table,sal_Int32 scope,sal_Bool nullable ) throw(SQLException, RuntimeException) +{ + openSpecialColumns(sal_False,catalog,schema,table,scope,nullable); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::openForeignKeys( const Any& catalog, const ::rtl::OUString* schema, + const ::rtl::OUString* table, + const Any& catalog2, const ::rtl::OUString* schema2, + const ::rtl::OUString* table2) throw(SQLException, RuntimeException) +{ + m_bFreeHandle = sal_True; + + ::rtl::OString aPKQ,aPKO,aPKN, aFKQ, aFKO, aFKN; + if ( catalog.hasValue() ) + aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding); + if ( catalog2.hasValue() ) + aFKQ = ::rtl::OUStringToOString(comphelper::getString(catalog2),m_nTextEncoding); + + const char *pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr() : NULL, + *pPKO = schema && schema->getLength() ? ::rtl::OUStringToOString(*schema,m_nTextEncoding).getStr() : NULL, + *pPKN = table ? (aPKN = ::rtl::OUStringToOString(*table,m_nTextEncoding)).getStr(): NULL, + *pFKQ = catalog2.hasValue() && aFKQ.getLength() ? aFKQ.getStr() : NULL, + *pFKO = schema2 && schema2->getLength() ? (aFKO = ::rtl::OUStringToOString(*schema2,m_nTextEncoding)).getStr() : NULL, + *pFKN = table2 ? (aFKN = ::rtl::OUStringToOString(*table2,m_nTextEncoding)).getStr() : NULL; + + + SQLRETURN nRetcode = N3SQLForeignKeys(m_aStatementHandle, + (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pPKN, pPKN ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pFKQ, (catalog2.hasValue() && aFKQ.getLength()) ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pFKO, pFKO ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pFKN, SQL_NTS + ); + OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); + checkColumnCount(); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::openImportedKeys(const Any& catalog, const ::rtl::OUString& schema, + const ::rtl::OUString& table) throw(SQLException, RuntimeException) +{ + + openForeignKeys(Any(),NULL,NULL,catalog,!schema.compareToAscii("%") ? &schema : NULL,&table); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::openExportedKeys(const Any& catalog, const ::rtl::OUString& schema, + const ::rtl::OUString& table) throw(SQLException, RuntimeException) +{ + openForeignKeys(catalog,!schema.compareToAscii("%") ? &schema : NULL,&table,Any(),NULL,NULL); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::openPrimaryKeys(const Any& catalog, const ::rtl::OUString& schema, + const ::rtl::OUString& table) throw(SQLException, RuntimeException) +{ + const ::rtl::OUString *pSchemaPat = NULL; + + if(schema.toChar() != '%') + pSchemaPat = &schema; + else + pSchemaPat = NULL; + + m_bFreeHandle = sal_True; + ::rtl::OString aPKQ,aPKO,aPKN,aCOL; + + aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding); + aPKO = ::rtl::OUStringToOString(schema,m_nTextEncoding); + + const char *pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr() : NULL, + *pPKO = pSchemaPat && pSchemaPat->getLength() ? aPKO.getStr() : NULL, + *pPKN = (aPKN = ::rtl::OUStringToOString(table,m_nTextEncoding)).getStr(); + + + SQLRETURN nRetcode = N3SQLPrimaryKeys(m_aStatementHandle, + (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 , + (SDB_ODBC_CHAR *) pPKN, SQL_NTS); + OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); + checkColumnCount(); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::openTablePrivileges(const Any& catalog, const ::rtl::OUString& schemaPattern, + const ::rtl::OUString& tableNamePattern) throw(SQLException, RuntimeException) +{ + const ::rtl::OUString *pSchemaPat = NULL; + + if(schemaPattern.toChar() != '%') + pSchemaPat = &schemaPattern; + else + pSchemaPat = NULL; + + m_bFreeHandle = sal_True; + ::rtl::OString aPKQ,aPKO,aPKN; + + aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding); + aPKO = ::rtl::OUStringToOString(schemaPattern,m_nTextEncoding); + + const char *pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr() : NULL, + *pPKO = pSchemaPat && pSchemaPat->getLength() ? aPKO.getStr() : NULL, + *pPKN = (aPKN = ::rtl::OUStringToOString(tableNamePattern,m_nTextEncoding)).getStr(); + + + SQLRETURN nRetcode = N3SQLTablePrivileges(m_aStatementHandle, + (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 , + (SDB_ODBC_CHAR *) pPKN, SQL_NTS); + OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); + checkColumnCount(); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::openIndexInfo( const Any& catalog, const ::rtl::OUString& schema, + const ::rtl::OUString& table,sal_Bool unique,sal_Bool approximate ) + throw(SQLException, RuntimeException) +{ + const ::rtl::OUString *pSchemaPat = NULL; + + if(schema.toChar() != '%') + pSchemaPat = &schema; + else + pSchemaPat = NULL; + + m_bFreeHandle = sal_True; + ::rtl::OString aPKQ,aPKO,aPKN; + + aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding); + aPKO = ::rtl::OUStringToOString(schema,m_nTextEncoding); + + const char *pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr() : NULL, + *pPKO = pSchemaPat && pSchemaPat->getLength() ? aPKO.getStr() : NULL, + *pPKN = (aPKN = ::rtl::OUStringToOString(table,m_nTextEncoding)).getStr(); + + + SQLRETURN nRetcode = N3SQLStatistics(m_aStatementHandle, + (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 , + (SDB_ODBC_CHAR *) pPKN, SQL_NTS, + unique ? SQL_INDEX_UNIQUE : SQL_INDEX_ALL, + approximate); + OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); + checkColumnCount(); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::checkColumnCount() +{ + sal_Int16 nNumResultCols=0; + OTools::ThrowException(m_pConnection,N3SQLNumResultCols(m_aStatementHandle,&nNumResultCols),m_aStatementHandle,SQL_HANDLE_STMT,*this); + m_nDriverColumnCount = nNumResultCols; +} +// ----------------------------------------------------------------------------- + +SWORD ODatabaseMetaDataResultSet::impl_getColumnType_nothrow(sal_Int32 columnIndex) +{ + ::std::map<sal_Int32,SWORD>::iterator aFind = m_aODBCColumnTypes.find(columnIndex); + if ( aFind == m_aODBCColumnTypes.end() ) + aFind = m_aODBCColumnTypes.insert(::std::map<sal_Int32,SWORD>::value_type(columnIndex,OResultSetMetaData::getColumnODBCType(m_pConnection,m_aStatementHandle,*this,columnIndex))).first; + return aFind->second; +} + diff --git a/connectivity/source/drivers/odbcbase/ODriver.cxx b/connectivity/source/drivers/odbcbase/ODriver.cxx new file mode 100644 index 000000000000..015e63d960af --- /dev/null +++ b/connectivity/source/drivers/odbcbase/ODriver.cxx @@ -0,0 +1,229 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "odbc/ODriver.hxx" +#include "odbc/OConnection.hxx" +#include "odbc/OFunctions.hxx" +#include "odbc/OTools.hxx" +#include "connectivity/dbexception.hxx" +#include "resource/common_res.hrc" +#include "resource/sharedresources.hxx" + +using namespace connectivity::odbc; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::sdbc; +// -------------------------------------------------------------------------------- +ODBCDriver::ODBCDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) + :ODriver_BASE(m_aMutex) + ,m_xORB(_rxFactory) + ,m_pDriverHandle(SQL_NULL_HANDLE) +{ +} +// -------------------------------------------------------------------------------- +void ODBCDriver::disposing() +{ + ::osl::MutexGuard aGuard(m_aMutex); + + + for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i) + { + Reference< XComponent > xComp(i->get(), UNO_QUERY); + if (xComp.is()) + xComp->dispose(); + } + m_xConnections.clear(); + + ODriver_BASE::disposing(); +} + +// static ServiceInfo +//------------------------------------------------------------------------------ +rtl::OUString ODBCDriver::getImplementationName_Static( ) throw(RuntimeException) +{ + return rtl::OUString::createFromAscii("com.sun.star.comp.sdbc.ODBCDriver"); + // this name is referenced in the configuration and in the odbc.xml + // Please take care when changing it. +} + +typedef Sequence< ::rtl::OUString > SS; +//------------------------------------------------------------------------------ +SS ODBCDriver::getSupportedServiceNames_Static( ) throw (RuntimeException) +{ + SS aSNS( 1 ); + aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver"); + return aSNS; +} + +//------------------------------------------------------------------ +::rtl::OUString SAL_CALL ODBCDriver::getImplementationName( ) throw(RuntimeException) +{ + return getImplementationName_Static(); +} + +//------------------------------------------------------------------ +sal_Bool SAL_CALL ODBCDriver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException) +{ + SS aSupported(getSupportedServiceNames()); + const ::rtl::OUString* pSupported = aSupported.getConstArray(); + const ::rtl::OUString* pEnd = pSupported + aSupported.getLength(); + for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported) + ; + + return pSupported != pEnd; +} + +//------------------------------------------------------------------ +SS SAL_CALL ODBCDriver::getSupportedServiceNames( ) throw(RuntimeException) +{ + return getSupportedServiceNames_Static(); +} + +// -------------------------------------------------------------------------------- +Reference< XConnection > SAL_CALL ODBCDriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException) +{ + if ( ! acceptsURL(url) ) + return NULL; + + if(!m_pDriverHandle) + { + ::rtl::OUString aPath; + if(!EnvironmentHandle(aPath)) + throw SQLException(aPath,*this,::rtl::OUString(),1000,Any()); + } + OConnection* pCon = new OConnection(m_pDriverHandle,this); + Reference< XConnection > xCon = pCon; + pCon->Construct(url,info); + m_xConnections.push_back(WeakReferenceHelper(*pCon)); + + return xCon; +} +// -------------------------------------------------------------------------------- +sal_Bool SAL_CALL ODBCDriver::acceptsURL( const ::rtl::OUString& url ) + throw(SQLException, RuntimeException) +{ + return (!url.compareTo(::rtl::OUString::createFromAscii("sdbc:odbc:"),10)); +} +// -------------------------------------------------------------------------------- +Sequence< DriverPropertyInfo > SAL_CALL ODBCDriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException) +{ + if ( acceptsURL(url) ) + { + ::std::vector< DriverPropertyInfo > aDriverInfo; + + Sequence< ::rtl::OUString > aBooleanValues(2); + aBooleanValues[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) ); + aBooleanValues[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) ); + + aDriverInfo.push_back(DriverPropertyInfo( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet")) + ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet of the database.")) + ,sal_False + ,::rtl::OUString() + ,Sequence< ::rtl::OUString >()) + ); + aDriverInfo.push_back(DriverPropertyInfo( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseCatalog")) + ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Use catalog for file-based databases.")) + ,sal_False + ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) ) + ,aBooleanValues) + ); + aDriverInfo.push_back(DriverPropertyInfo( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SystemDriverSettings")) + ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Driver settings.")) + ,sal_False + ,::rtl::OUString() + ,Sequence< ::rtl::OUString >()) + ); + aDriverInfo.push_back(DriverPropertyInfo( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParameterNameSubstitution")) + ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Change named parameters with '?'.")) + ,sal_False + ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) ) + ,aBooleanValues) + ); + aDriverInfo.push_back(DriverPropertyInfo( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IgnoreDriverPrivileges")) + ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Ignore the privileges from the database driver.")) + ,sal_False + ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) ) + ,aBooleanValues) + ); + aDriverInfo.push_back(DriverPropertyInfo( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsAutoRetrievingEnabled")) + ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Retrieve generated values.")) + ,sal_False + ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) ) + ,aBooleanValues) + ); + aDriverInfo.push_back(DriverPropertyInfo( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AutoRetrievingStatement")) + ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Auto-increment statement.")) + ,sal_False + ,::rtl::OUString() + ,Sequence< ::rtl::OUString >()) + ); + aDriverInfo.push_back(DriverPropertyInfo( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GenerateASBeforeCorrelationName")) + ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Generate AS before table correlation names.")) + ,sal_False + ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) ) + ,aBooleanValues) + ); + aDriverInfo.push_back(DriverPropertyInfo( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EscapeDateTime")) + ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Escape date time format.")) + ,sal_False + ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) ) + ,aBooleanValues) + ); + + return Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size()); + } + ::connectivity::SharedResources aResources; + const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR); + ::dbtools::throwGenericSQLException(sMessage ,*this); + return Sequence< DriverPropertyInfo >(); +} +// -------------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODBCDriver::getMajorVersion( ) throw(RuntimeException) +{ + return 1; +} +// -------------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODBCDriver::getMinorVersion( ) throw(RuntimeException) +{ + return 0; +} +// -------------------------------------------------------------------------------- +//----------------------------------------------------------------------------- + + diff --git a/connectivity/source/drivers/odbcbase/OPreparedStatement.cxx b/connectivity/source/drivers/odbcbase/OPreparedStatement.cxx new file mode 100644 index 000000000000..758b2fb38def --- /dev/null +++ b/connectivity/source/drivers/odbcbase/OPreparedStatement.cxx @@ -0,0 +1,973 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" + +#include <stdio.h> +#include <string.h> +#include <osl/diagnose.h> +#include "odbc/OPreparedStatement.hxx" +#include "odbc/OBoundParam.hxx" +#include <com/sun/star/sdbc/DataType.hpp> +#include "odbc/OTools.hxx" +#include "odbc/ODriver.hxx" +#include "odbc/OResultSet.hxx" +#include "odbc/OResultSetMetaData.hxx" +#include <cppuhelper/typeprovider.hxx> +#include <comphelper/sequence.hxx> +#include <com/sun/star/lang/DisposedException.hpp> +#include "connectivity/dbtools.hxx" +#include <comphelper/types.hxx> +#include "connectivity/FValue.hxx" +#include "resource/common_res.hrc" +#include "connectivity/sqlparse.hxx" + +using namespace ::comphelper; +using namespace connectivity; +using namespace connectivity::odbc; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::sdbcx; +using namespace com::sun::star::container; +using namespace com::sun::star::io; +using namespace com::sun::star::util; + +IMPLEMENT_SERVICE_INFO(OPreparedStatement,"com.sun.star.sdbcx.OPreparedStatement","com.sun.star.sdbc.PreparedStatement"); + + +OPreparedStatement::OPreparedStatement( OConnection* _pConnection,const ::rtl::OUString& sql) + :OStatement_BASE2(_pConnection) + ,numParams(0) + ,boundParams(NULL) + ,m_bPrepared(sal_False) +{ + m_sSqlStatement = sql; + try + { + if(_pConnection->isParameterSubstitutionEnabled()) + { + OSQLParser aParser(_pConnection->getDriver()->getORB()); + ::rtl::OUString sErrorMessage; + ::rtl::OUString sNewSql; + ::std::auto_ptr<OSQLParseNode> pNode( aParser.parseTree(sErrorMessage,sql) ); + if ( pNode.get() ) + { // special handling for parameters + OSQLParseNode::substituteParameterNames(pNode.get()); + pNode->parseNodeToStr( sNewSql, _pConnection ); + m_sSqlStatement = sNewSql; + } + } + } + catch(Exception&) + { + } +} +// ----------------------------------------------------------------------------- +void SAL_CALL OPreparedStatement::acquire() throw() +{ + OStatement_BASE2::acquire(); +} +// ----------------------------------------------------------------------------- +void SAL_CALL OPreparedStatement::release() throw() +{ + OStatement_BASE2::release(); +} +// ----------------------------------------------------------------------------- +Any SAL_CALL OPreparedStatement::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = OStatement_BASE2::queryInterface(rType); + return aRet.hasValue() ? aRet : OPreparedStatement_BASE::queryInterface(rType); +} +// ------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OPreparedStatement::getTypes( ) throw(::com::sun::star::uno::RuntimeException) +{ + return ::comphelper::concatSequences(OPreparedStatement_BASE::getTypes(),OStatement_BASE2::getTypes()); +} +// ------------------------------------------------------------------------- + +Reference< XResultSetMetaData > SAL_CALL OPreparedStatement::getMetaData( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + + prepareStatement(); + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + if(!m_xMetaData.is()) + m_xMetaData = new OResultSetMetaData(getOwnConnection(),m_aStatementHandle); + return m_xMetaData; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::close( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + + // Close/clear our result set + clearMyResultSet (); + + // Reset last warning message + + try { + clearWarnings (); + OStatement_BASE2::close(); + FreeParams(); + } + catch (SQLException &) { + // If we get an error, ignore + } + + // Remove this Statement object from the Connection object's + // list +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OPreparedStatement::execute( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + + sal_Bool needData = sal_False; + + // Reset warnings + + clearWarnings (); + + // Reset the statement handle, warning and saved Resultset + + reset(); + + // Call SQLExecute + prepareStatement(); + + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + try + { + SQLRETURN nReturn = N3SQLExecute(m_aStatementHandle); + + OTools::ThrowException(m_pConnection,nReturn,m_aStatementHandle,SQL_HANDLE_STMT,*this); + needData = nReturn == SQL_NEED_DATA; + + // Now loop while more data is needed (i.e. a data-at- + // execution parameter was given). For each parameter + // that needs data, put the data from the input stream. + + while (needData) { + + // Get the parameter number that requires data + + sal_Int32* paramIndex = 0; + nReturn = N3SQLParamData(m_aStatementHandle,(SQLPOINTER*)¶mIndex); + + // If the parameter index is -1, there is no + // more data required + + if ( !paramIndex || ( *paramIndex == -1 ) ) + needData = sal_False; + else + { + // Now we have the proper parameter + // index, get the data from the input + // stream and do a SQLPutData + putParamData (*paramIndex); + } + } + + } + catch (const SQLWarning&) + { + } + + // Now loop while more data is needed (i.e. a data-at- + // execution parameter was given). For each parameter + // that needs data, put the data from the input stream. + + while (needData) { + + // Get the parameter number that requires data + + sal_Int32* paramIndex = 0; + N3SQLParamData (m_aStatementHandle,(SQLPOINTER*)¶mIndex); + + // If the parameter index is -1, there is no more + // data required + + if (*paramIndex == -1) { + needData = sal_False; + } + else { + // Now we have the proper parameter index, + // get the data from the input stream + // and do a SQLPutData + putParamData(*paramIndex); + } + } + + // Now determine if there is a result set associated with + // the SQL statement that was executed. Get the column + // count, and if it is not zero, there is a result set. + + + return getColumnCount() > 0; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OPreparedStatement::executeUpdate( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + sal_Int32 numRows = -1; + + prepareStatement(); + // Execute the statement. If execute returns sal_False, a + // row count exists. + + if (!execute()) + numRows = getUpdateCount (); + else + { + // No update count was produced (a ResultSet was). Raise + // an exception + m_pConnection->throwGenericSQLException(STR_NO_ROWCOUNT,*this); + } + return numRows; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setString( sal_Int32 parameterIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException) +{ + ::rtl::OString aString(::rtl::OUStringToOString(x,getOwnConnection()->getTextEncoding())); + setParameter(parameterIndex,DataType::CHAR,aString.getLength(),(void*)&x); +} +// ------------------------------------------------------------------------- + +Reference< XConnection > SAL_CALL OPreparedStatement::getConnection( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + return (Reference< XConnection >)m_pConnection; +} +// ------------------------------------------------------------------------- + +Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + Reference< XResultSet > rs = NULL; + + prepareStatement(); + + if (execute()) + rs = getResultSet(sal_False); + else + { + // No ResultSet was produced. Raise an exception + m_pConnection->throwGenericSQLException(STR_NO_RESULTSET,*this); + } + return rs; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setBoolean( sal_Int32 parameterIndex, sal_Bool x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + + sal_Int32 value = 0; + + // If the parameter is sal_True, set the value to 1 + if (x) { + value = 1; + } + + // Set the parameter as if it were an integer + setInt (parameterIndex, value); +} +// ------------------------------------------------------------------------- +void OPreparedStatement::setParameter(sal_Int32 parameterIndex,sal_Int32 _nType,sal_Int32 _nSize,void* _pData) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + prepareStatement(); + // Allocate a buffer to be used in binding. This will be + // a 'permanent' buffer that the bridge will fill in with + // the bound data in native format. + + + checkParameterIndex(parameterIndex); + sal_Int32 nRealSize = _nSize; + SQLSMALLINT fSqlType = static_cast<SQLSMALLINT>(OTools::jdbcTypeToOdbc(_nType)); + switch(fSqlType) + { + case SQL_CHAR: + case SQL_VARCHAR: + case SQL_DECIMAL: + case SQL_NUMERIC: + ++nRealSize; + break; + case SQL_BINARY: + case SQL_VARBINARY: + nRealSize=1; //dummy buffer, binary data isn't copied + break; + default: + break; + } + + sal_Int8* bindBuf = allocBindBuf(parameterIndex, nRealSize); + + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + OTools::bindParameter( m_pConnection, + m_aStatementHandle, + parameterIndex, + bindBuf, + getLengthBuf(parameterIndex), + fSqlType, + sal_False, + m_pConnection->useOldDateFormat(), + _pData, + (Reference <XInterface>)*this, + getOwnConnection()->getTextEncoding()); +} +// ----------------------------------------------------------------------------- +void SAL_CALL OPreparedStatement::setByte( sal_Int32 parameterIndex, sal_Int8 x ) throw(SQLException, RuntimeException) +{ + setParameter(parameterIndex,DataType::TINYINT,sizeof(sal_Int8),&x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setDate( sal_Int32 parameterIndex, const Date& aData ) throw(SQLException, RuntimeException) +{ + DATE_STRUCT x = OTools::DateToOdbcDate(aData); + setParameter(parameterIndex,DataType::DATE,sizeof(DATE_STRUCT),&x); +} +// ------------------------------------------------------------------------- + + +void SAL_CALL OPreparedStatement::setTime( sal_Int32 parameterIndex, const Time& aVal ) throw(SQLException, RuntimeException) +{ + TIME_STRUCT x = OTools::TimeToOdbcTime(aVal); + setParameter(parameterIndex,DataType::TIME,sizeof(TIME_STRUCT),&x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setTimestamp( sal_Int32 parameterIndex, const DateTime& aVal ) throw(SQLException, RuntimeException) +{ + TIMESTAMP_STRUCT x = OTools::DateTimeToTimestamp(aVal); + setParameter(parameterIndex,DataType::TIMESTAMP,sizeof(TIMESTAMP_STRUCT),&x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setDouble( sal_Int32 parameterIndex, double x ) throw(SQLException, RuntimeException) +{ + setParameter(parameterIndex,DataType::DOUBLE,sizeof(double),&x); +} + +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setFloat( sal_Int32 parameterIndex, float x ) throw(SQLException, RuntimeException) +{ + setParameter(parameterIndex,DataType::FLOAT,sizeof(float),&x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setInt( sal_Int32 parameterIndex, sal_Int32 x ) throw(SQLException, RuntimeException) +{ + setParameter(parameterIndex,DataType::INTEGER,sizeof(sal_Int32),&x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setLong( sal_Int32 parameterIndex, sal_Int64 x ) throw(SQLException, RuntimeException) +{ + try + { + setParameter(parameterIndex,DataType::BIGINT,sizeof(sal_Int64),&x); + } + catch(SQLException&) + { + setString(parameterIndex,ORowSetValue(x)); + } +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setNull( sal_Int32 parameterIndex, sal_Int32 sqlType ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + + prepareStatement(); + // Get the buffer needed for the length + checkParameterIndex(parameterIndex); + + sal_Int8* lenBuf = getLengthBuf (parameterIndex); + *(SQLLEN*)lenBuf = SQL_NULL_DATA; + + + SQLLEN prec = 0; + SQLULEN nColumnSize = 0; + if (sqlType == SQL_CHAR || sqlType == SQL_VARCHAR || sqlType == SQL_LONGVARCHAR) + { + prec = 1; + nColumnSize = 1; + } + + SQLSMALLINT fCType = 0; + SQLSMALLINT fSqlType = 0; + + SQLSMALLINT nDecimalDigits = 0; + OTools::getBindTypes( sal_False, + m_pConnection->useOldDateFormat(), + (SQLSMALLINT)sqlType, + fCType, + fSqlType); + + SQLRETURN nReturn = N3SQLBindParameter( m_aStatementHandle, + (SQLUSMALLINT)parameterIndex, + (SQLSMALLINT)SQL_PARAM_INPUT, + fCType, + fSqlType, + nColumnSize, + nDecimalDigits, + NULL, + prec, + (SQLLEN*)lenBuf + ); + OTools::ThrowException(m_pConnection,nReturn,m_aStatementHandle,SQL_HANDLE_STMT,*this); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setClob( sal_Int32 parameterIndex, const Reference< XClob >& x ) throw(SQLException, RuntimeException) +{ + if ( x.is() ) + setStream(parameterIndex, x->getCharacterStream(), (SQLLEN)x->length(), DataType::LONGVARCHAR); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setBlob( sal_Int32 parameterIndex, const Reference< XBlob >& x ) throw(SQLException, RuntimeException) +{ + if ( x.is() ) + setStream(parameterIndex, x->getBinaryStream(), (SQLLEN)x->length(), DataType::LONGVARCHAR); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setArray( sal_Int32 /*parameterIndex*/, const Reference< XArray >& /*x*/ ) throw(SQLException, RuntimeException) +{ + ::dbtools::throwFunctionNotSupportedException( "XParameters::setArray", *this ); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setRef( sal_Int32 /*parameterIndex*/, const Reference< XRef >& /*x*/ ) throw(SQLException, RuntimeException) +{ + ::dbtools::throwFunctionNotSupportedException( "XParameters::setRef", *this ); +} +// ------------------------------------------------------------------------- +void OPreparedStatement::setDecimal( sal_Int32 parameterIndex, const ::rtl::OUString& x ) +{ + ::rtl::OString aString(::rtl::OUStringToOString(x,getOwnConnection()->getTextEncoding())); + setParameter(parameterIndex,DataType::DECIMAL,aString.getLength(),(void*)&x); +} +// ------------------------------------------------------------------------- +void SAL_CALL OPreparedStatement::setObjectWithInfo( sal_Int32 parameterIndex, const Any& x, sal_Int32 sqlType, sal_Int32 scale ) throw(SQLException, RuntimeException) +{ + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + prepareStatement(); + // For each known SQL Type, call the appropriate + // set routine + + switch (sqlType) + { + case DataType::VARCHAR: + case DataType::LONGVARCHAR: + if(x.hasValue()) + { + ::rtl::OUString sStr; + x >>= sStr; + ::rtl::OString aString(::rtl::OUStringToOString(sStr,getOwnConnection()->getTextEncoding())); + setParameter(parameterIndex,sqlType,aString.getLength(),&aString); + } + else + setNull(parameterIndex,sqlType); + break; + case DataType::DECIMAL: + { + ORowSetValue aValue; + aValue.fill(x); + setDecimal(parameterIndex,aValue); + } + break; + case DataType::NUMERIC: + { + ORowSetValue aValue; + aValue.fill(x); + setString(parameterIndex,aValue); + } + break; + default: + ::dbtools::setObjectWithInfo(this,parameterIndex,x,sqlType,scale); + } +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setObjectNull( sal_Int32 parameterIndex, sal_Int32 sqlType, const ::rtl::OUString& /*typeName*/ ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + setNull(parameterIndex,sqlType); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setObject( sal_Int32 parameterIndex, const Any& x ) throw(SQLException, RuntimeException) +{ + if (!::dbtools::implSetObject(this, parameterIndex, x)) + { // there is no other setXXX call which can handle the value in x + throw SQLException(); + } +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setShort( sal_Int32 parameterIndex, sal_Int16 x ) throw(SQLException, RuntimeException) +{ + setParameter(parameterIndex,DataType::SMALLINT,sizeof(sal_Int16),&x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setBytes( sal_Int32 parameterIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException) +{ + setParameter(parameterIndex,DataType::BINARY,x.getLength(),(void*)&x); + boundParams[parameterIndex-1].setSequence(x); // this assures that the sequence stays alive +} +// ------------------------------------------------------------------------- + + +void SAL_CALL OPreparedStatement::setCharacterStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException) +{ + setStream(parameterIndex, x, length, DataType::LONGVARCHAR); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setBinaryStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException) +{ + setStream(parameterIndex, x, length, DataType::LONGVARBINARY); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::clearParameters( ) throw(SQLException, RuntimeException) +{ + prepareStatement(); + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + SQLRETURN nRet = N3SQLFreeStmt (m_aStatementHandle, SQL_RESET_PARAMS); + nRet = N3SQLFreeStmt (m_aStatementHandle, SQL_UNBIND); +} +// ------------------------------------------------------------------------- +void SAL_CALL OPreparedStatement::clearBatch( ) throw(SQLException, RuntimeException) +{ + // clearParameters( ); + // m_aBatchList.erase(); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::addBatch( ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- + +Sequence< sal_Int32 > SAL_CALL OPreparedStatement::executeBatch( ) throw(SQLException, RuntimeException) +{ + return Sequence< sal_Int32 > (); +} +// ------------------------------------------------------------------------- + +//==================================================================== +// methods +//==================================================================== + +//-------------------------------------------------------------------- +// initBoundParam +// Initialize the bound parameter objects +//-------------------------------------------------------------------- + +void OPreparedStatement::initBoundParam () throw(SQLException) +{ + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + // Get the number of parameters + numParams = 0; + N3SQLNumParams (m_aStatementHandle,&numParams); + + // There are parameter markers, allocate the bound + // parameter objects + + if (numParams > 0) + { + // Allocate an array of bound parameter objects + + boundParams = new OBoundParam[numParams]; + + // Allocate and initialize each bound parameter + + for (sal_Int32 i = 0; i < numParams; i++) + { + boundParams[i] = OBoundParam(); + boundParams[i].initialize (); + } + } +} +// ------------------------------------------------------------------------- + +//-------------------------------------------------------------------- +// allocBindBuf +// Allocate storage for the permanent data buffer for the bound +// parameter. +//-------------------------------------------------------------------- + +sal_Int8* OPreparedStatement::allocBindBuf( sal_Int32 index,sal_Int32 bufLen) +{ + sal_Int8* b = NULL; + + // Sanity check the parameter number + + if ((index >= 1) && + (index <= numParams) && bufLen > 0 ) + { + b = boundParams[index - 1].allocBindDataBuffer(bufLen); + } + + return b; +} +// ------------------------------------------------------------------------- + +//-------------------------------------------------------------------- +// getDataBuf +// Gets the data buffer for the given parameter index +//-------------------------------------------------------------------- + +sal_Int8* OPreparedStatement::getDataBuf (sal_Int32 index) +{ + sal_Int8* b = NULL; + + // Sanity check the parameter number + + if ((index >= 1) && + (index <= numParams)) + { + b = boundParams[index - 1].getBindDataBuffer (); + } + + return b; +} +// ------------------------------------------------------------------------- + +//-------------------------------------------------------------------- +// getLengthBuf +// Gets the length buffer for the given parameter index +//-------------------------------------------------------------------- + +sal_Int8* OPreparedStatement::getLengthBuf (sal_Int32 index) +{ + sal_Int8* b = NULL; + + // Sanity check the parameter number + + if ((index >= 1) && + (index <= numParams)) + { + b = boundParams[index - 1].getBindLengthBuffer (); + } + + return b; +} +// ------------------------------------------------------------------------- + +//-------------------------------------------------------------------- +// getParamLength +// Returns the length of the given parameter number. When each +// parameter was bound, a 4-sal_Int8 buffer was given to hold the +// length (stored in native format). Get the buffer, convert the +// buffer from native format, and return it. If the length is -1, +// the column is considered to be NULL. +//-------------------------------------------------------------------- + +sal_Int32 OPreparedStatement::getParamLength ( sal_Int32 index) +{ + sal_Int32 paramLen = SQL_NULL_DATA; + + // Sanity check the parameter number + + if ((index >= 1) && + (index <= numParams)) { + + // Now get the length of the parameter from the + // bound param array. -1 is returned if it is NULL. + long n = 0; + memcpy (&n, boundParams[index -1].getBindLengthBuffer (), sizeof (n)); + paramLen = n; + } + return paramLen; +} +// ------------------------------------------------------------------------- + +//-------------------------------------------------------------------- +// putParamData +// Puts parameter data from a previously bound input stream. The +// input stream was bound using SQL_LEN_DATA_AT_EXEC. +//-------------------------------------------------------------------- + +void OPreparedStatement::putParamData (sal_Int32 index) throw(SQLException) +{ + // Sanity check the parameter index + if ((index < 1) || + (index > numParams)) + { + return; + } + + // We'll transfer up to MAX_PUT_DATA_LENGTH at a time + Sequence< sal_Int8 > buf( MAX_PUT_DATA_LENGTH ); + + // Get the information about the input stream + + Reference< XInputStream> inputStream = boundParams[index - 1].getInputStream (); + if ( !inputStream.is() ) + { + ::connectivity::SharedResources aResources; + const ::rtl::OUString sError( aResources.getResourceString(STR_NO_INPUTSTREAM)); + throw SQLException (sError, *this,::rtl::OUString(),0,Any()); + } + + sal_Int32 maxBytesLeft = boundParams[index - 1].getInputStreamLen (); + + // Loop while more data from the input stream + sal_Int32 haveRead = 0; + try + { + + do + { + sal_Int32 toReadThisRound = ::std::min( MAX_PUT_DATA_LENGTH, maxBytesLeft ); + + // Read some data from the input stream + haveRead = inputStream->readBytes( buf, toReadThisRound ); + OSL_ENSURE( haveRead == buf.getLength(), "OPreparedStatement::putParamData: inconsistency!" ); + + if ( !haveRead ) + // no more data in the stream - the given stream length was a maximum which could not be + // fulfilled by the stream + break; + + // Put the data + OSL_ENSURE( m_aStatementHandle, "OPreparedStatement::putParamData: StatementHandle is null!" ); + N3SQLPutData ( m_aStatementHandle, buf.getArray(), buf.getLength() ); + + // decrement the number of bytes still needed + maxBytesLeft -= haveRead; + } + while ( maxBytesLeft > 0 ); + } + catch (const IOException& ex) + { + + // If an I/O exception was generated, turn + // it into a SQLException + + throw SQLException(ex.Message,*this,::rtl::OUString(),0,Any()); + } +} +// ------------------------------------------------------------------------- +//-------------------------------------------------------------------- +// getPrecision +// Given a SQL type, return the maximum precision for the column. +// Returns -1 if not known +//-------------------------------------------------------------------- + +sal_Int32 OPreparedStatement::getPrecision ( sal_Int32 sqlType) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + sal_Int32 prec = -1; + const TTypeInfoVector& rTypeInfo = m_pConnection->getTypeInfo(); + if ( !rTypeInfo.empty() ) + { + m_pConnection->buildTypeInfo(); + } + + if ( !rTypeInfo.empty() ) + { + OTypeInfo aInfo; + aInfo.nType = (sal_Int16)sqlType; + TTypeInfoVector::const_iterator aIter = ::std::find(rTypeInfo.begin(),rTypeInfo.end(),aInfo); + if(aIter != rTypeInfo.end()) + prec = (*aIter).nPrecision; + } + return prec; +} + +//-------------------------------------------------------------------- +// setStream +// Sets an input stream as a parameter, using the given SQL type +//-------------------------------------------------------------------- + +void OPreparedStatement::setStream( + sal_Int32 ParameterIndex, + const Reference< XInputStream>& x, + SQLLEN length, + sal_Int32 SQLtype) + throw(SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + + prepareStatement(); + + checkParameterIndex(ParameterIndex); + // Get the buffer needed for the length + + sal_Int8* lenBuf = getLengthBuf(ParameterIndex); + + // Allocate a new buffer for the parameter data. This buffer + // will be returned by SQLParamData (it is set to the parameter + // number, a 4-sal_Int8 integer) + + sal_Int8* dataBuf = allocBindBuf (ParameterIndex, 4); + + // Bind the parameter with SQL_LEN_DATA_AT_EXEC + SQLSMALLINT Ctype = SQL_C_CHAR; + SQLLEN atExec = SQL_LEN_DATA_AT_EXEC (length); + memcpy (dataBuf, &ParameterIndex, sizeof(ParameterIndex)); + memcpy (lenBuf, &atExec, sizeof (atExec)); + + if ((SQLtype == SQL_BINARY) || (SQLtype == SQL_VARBINARY) || (SQLtype == SQL_LONGVARBINARY)) + Ctype = SQL_C_BINARY; + + + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + N3SQLBindParameter(m_aStatementHandle, + (SQLUSMALLINT)ParameterIndex, + (SQLUSMALLINT)SQL_PARAM_INPUT, + Ctype, + (SQLSMALLINT)SQLtype, + (SQLULEN)length, + 0, + dataBuf, + sizeof(ParameterIndex), + (SQLLEN*)lenBuf); + + // Save the input stream + boundParams[ParameterIndex - 1].setInputStream (x, length); +} +// ------------------------------------------------------------------------- + +// ------------------------------------------------------------------------- + +void OPreparedStatement::FreeParams() +{ + numParams = 0; + delete [] boundParams; + boundParams = NULL; +} +// ------------------------------------------------------------------------- +void OPreparedStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception) +{ + try + { + switch(nHandle) + { + case PROPERTY_ID_RESULTSETCONCURRENCY: + if(!isPrepared()) + setResultSetConcurrency(comphelper::getINT32(rValue)); + break; + case PROPERTY_ID_RESULTSETTYPE: + if(!isPrepared()) + setResultSetType(comphelper::getINT32(rValue)); + break; + case PROPERTY_ID_FETCHDIRECTION: + if(!isPrepared()) + setFetchDirection(comphelper::getINT32(rValue)); + break; + case PROPERTY_ID_USEBOOKMARKS: + if(!isPrepared()) + setUsingBookmarks(comphelper::getBOOL(rValue)); + break; + default: + OStatement_Base::setFastPropertyValue_NoBroadcast(nHandle,rValue); + } + } + catch(const SQLException&) + { + // throw Exception(e.Message,*this); + } +} +// ----------------------------------------------------------------------------- +void OPreparedStatement::prepareStatement() +{ + if(!isPrepared()) + { + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + ::rtl::OString aSql(::rtl::OUStringToOString(m_sSqlStatement,getOwnConnection()->getTextEncoding())); + SQLRETURN nReturn = N3SQLPrepare(m_aStatementHandle,(SDB_ODBC_CHAR *) aSql.getStr(),aSql.getLength()); + OTools::ThrowException(m_pConnection,nReturn,m_aStatementHandle,SQL_HANDLE_STMT,*this); + m_bPrepared = sal_True; + initBoundParam(); + } +} +// ----------------------------------------------------------------------------- +void OPreparedStatement::checkParameterIndex(sal_Int32 _parameterIndex) +{ + if( !_parameterIndex || _parameterIndex > numParams) + { + ::connectivity::SharedResources aResources; + const ::rtl::OUString sError( aResources.getResourceStringWithSubstitution(STR_WRONG_PARAM_INDEX, + "$pos$", ::rtl::OUString::valueOf(_parameterIndex), + "$count$", ::rtl::OUString::valueOf((sal_Int32)numParams) + )); + SQLException aNext(sError,*this, ::rtl::OUString(),0,Any()); + + ::dbtools::throwInvalidIndexException(*this,makeAny(aNext)); + } +} +// ----------------------------------------------------------------------------- +OResultSet* OPreparedStatement::createResulSet() +{ + OResultSet* pReturn = new OResultSet(m_aStatementHandle,this); + pReturn->setMetaData(getMetaData()); + return pReturn; +} +// ----------------------------------------------------------------------------- diff --git a/connectivity/source/drivers/odbcbase/OResultSet.cxx b/connectivity/source/drivers/odbcbase/OResultSet.cxx new file mode 100644 index 000000000000..7055bd273370 --- /dev/null +++ b/connectivity/source/drivers/odbcbase/OResultSet.cxx @@ -0,0 +1,1755 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "odbc/OResultSet.hxx" +#include "odbc/OTools.hxx" +#include "odbc/OResultSetMetaData.hxx" +#include <com/sun/star/sdbc/DataType.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/sdbcx/CompareBookmark.hpp> +#include <com/sun/star/sdbc/ResultSetConcurrency.hpp> +#include <com/sun/star/sdbc/FetchDirection.hpp> +#include <com/sun/star/sdbc/ResultSetType.hpp> +#include <comphelper/property.hxx> +#include <comphelper/sequence.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <comphelper/extract.hxx> +#include <com/sun/star/lang/DisposedException.hpp> +#include <comphelper/types.hxx> +#include "connectivity/dbtools.hxx" +#include "connectivity/dbexception.hxx" +#include "diagnose_ex.h" +#include <rtl/logfile.hxx> + +using namespace ::comphelper; +using namespace connectivity; +using namespace connectivity::odbc; +using namespace cppu; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::sdbcx; +using namespace com::sun::star::container; +using namespace com::sun::star::io; +using namespace com::sun::star::util; + +#define ODBC_SQL_NOT_DEFINED 99UL + +//------------------------------------------------------------------------------ +// IMPLEMENT_SERVICE_INFO(OResultSet,"com.sun.star.sdbcx.OResultSet","com.sun.star.sdbc.ResultSet"); +::rtl::OUString SAL_CALL OResultSet::getImplementationName( ) throw ( RuntimeException) +{ + return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.odbc.ResultSet"); +} +// ------------------------------------------------------------------------- + Sequence< ::rtl::OUString > SAL_CALL OResultSet::getSupportedServiceNames( ) throw( RuntimeException) +{ + Sequence< ::rtl::OUString > aSupported(2); + aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.ResultSet"); + aSupported[1] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.ResultSet"); + return aSupported; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::supportsService( const ::rtl::OUString& _rServiceName ) throw( RuntimeException) +{ + Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); + const ::rtl::OUString* pSupported = aSupported.getConstArray(); + const ::rtl::OUString* pEnd = pSupported + aSupported.getLength(); + for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported) + ; + + return pSupported != pEnd; +} + +// ------------------------------------------------------------------------- +OResultSet::OResultSet(SQLHANDLE _pStatementHandle ,OStatement_Base* pStmt) : OResultSet_BASE(m_aMutex) + ,OPropertySetHelper(OResultSet_BASE::rBHelper) + ,m_aStatementHandle(_pStatementHandle) + ,m_aConnectionHandle(pStmt->getConnectionHandle()) + ,m_pStatement(pStmt) + ,m_pSkipDeletedSet(NULL) + ,m_xStatement(*pStmt) + ,m_xMetaData(NULL) + ,m_pRowStatusArray( NULL ) + ,m_nTextEncoding(pStmt->getOwnConnection()->getTextEncoding()) + ,m_nRowPos(0) + ,m_nLastColumnPos(0) + ,m_nUseBookmarks(ODBC_SQL_NOT_DEFINED) + ,m_nCurrentFetchState(0) + ,m_bWasNull(sal_True) + ,m_bEOF(sal_True) + ,m_bLastRecord(sal_False) + ,m_bFreeHandle(sal_False) + ,m_bInserting(sal_False) + ,m_bFetchData(sal_True) + ,m_bRowInserted(sal_False) + ,m_bRowDeleted(sal_False) + ,m_bUseFetchScroll(sal_False) +{ + osl_incrementInterlockedCount( &m_refCount ); + try + { + m_pRowStatusArray = new SQLUSMALLINT[1]; // the default value + N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_STATUS_PTR,m_pRowStatusArray,SQL_IS_POINTER); + } + catch(Exception&) + { // we don't want our result destroy here + } + SQLINTEGER nCurType = 0; + try + { + N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,&nCurType,SQL_IS_UINTEGER,0); + SQLUINTEGER nValueLen = m_pStatement->getCursorProperties(nCurType,sal_False); + if( (nValueLen & SQL_CA2_SENSITIVITY_DELETIONS) != SQL_CA2_SENSITIVITY_DELETIONS || + (nValueLen & SQL_CA2_CRC_EXACT) != SQL_CA2_CRC_EXACT) + m_pSkipDeletedSet = new OSkipDeletedSet(this); + } + catch(Exception&) + { // we don't want our result destroy here + } + try + { + SQLUINTEGER nValueLen = 0; + OTools::GetInfo(m_pStatement->getOwnConnection(),m_aConnectionHandle,SQL_GETDATA_EXTENSIONS,nValueLen,NULL); + m_bFetchData = !((SQL_GD_ANY_ORDER & nValueLen) == SQL_GD_ANY_ORDER && nCurType != SQL_CURSOR_FORWARD_ONLY); + } + catch(Exception&) + { // we don't want our result destroy here + m_bFetchData = sal_True; + } + try + { + if ( getOdbcFunction(ODBC3SQLGetFunctions) ) + { + SQLUSMALLINT nSupported = 0; + m_bUseFetchScroll = ( N3SQLGetFunctions(m_aConnectionHandle,SQL_API_SQLFETCHSCROLL,&nSupported) == SQL_SUCCESS && nSupported == 1 ); + } + } + catch(Exception&) + { + m_bUseFetchScroll = sal_False; + } + + osl_decrementInterlockedCount( &m_refCount ); +} +// ------------------------------------------------------------------------- +OResultSet::~OResultSet() +{ + delete [] m_pRowStatusArray; + delete m_pSkipDeletedSet; +} +// ----------------------------------------------------------------------------- +void OResultSet::construct() +{ + osl_incrementInterlockedCount( &m_refCount ); + allocBuffer(); + osl_decrementInterlockedCount( &m_refCount ); +} +// ------------------------------------------------------------------------- +void OResultSet::disposing(void) +{ + SQLRETURN nRet = N3SQLCloseCursor(m_aStatementHandle); + OSL_UNUSED( nRet ); + OPropertySetHelper::disposing(); + + ::osl::MutexGuard aGuard(m_aMutex); + if(!m_aBindVector.empty()) + releaseBuffer(); + if(m_bFreeHandle) + m_pStatement->getOwnConnection()->freeStatementHandle(m_aStatementHandle); + +m_xStatement.clear(); +m_xMetaData.clear(); +} +// ------------------------------------------------------------------------- +SQLRETURN OResultSet::unbind(sal_Bool _bUnbindHandle) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::unbind" ); + SQLRETURN nRet = 0; + if ( _bUnbindHandle ) + nRet = N3SQLFreeStmt(m_aStatementHandle,SQL_UNBIND); + + if ( m_aBindVector.size() > 1 ) + { + TVoidVector::iterator pValue = m_aBindVector.begin() + 1; + TVoidVector::iterator pEnd = m_aBindVector.end(); + for(; pValue != pEnd; ++pValue) + { + switch (pValue->second) + { + case DataType::CHAR: + case DataType::VARCHAR: + delete static_cast< ::rtl::OString* >(reinterpret_cast< void * >(pValue->first)); + break; + case DataType::BIGINT: + delete static_cast< sal_Int64* >(reinterpret_cast< void * >(pValue->first)); + break; + case DataType::DECIMAL: + case DataType::NUMERIC: + delete static_cast< ::rtl::OString* >(reinterpret_cast< void * >(pValue->first)); + break; + case DataType::REAL: + case DataType::DOUBLE: + delete static_cast< double* >(reinterpret_cast< void * >(pValue->first)); + break; + case DataType::LONGVARCHAR: + case DataType::CLOB: + delete [] static_cast< char* >(reinterpret_cast< void * >(pValue->first)); + break; + case DataType::LONGVARBINARY: + case DataType::BLOB: + delete [] static_cast< char* >(reinterpret_cast< void * >(pValue->first)); + break; + case DataType::DATE: + delete static_cast< DATE_STRUCT* >(reinterpret_cast< void * >(pValue->first)); + break; + case DataType::TIME: + delete static_cast< TIME_STRUCT* >(reinterpret_cast< void * >(pValue->first)); + break; + case DataType::TIMESTAMP: + delete static_cast< TIMESTAMP_STRUCT* >(reinterpret_cast< void * >(pValue->first)); + break; + case DataType::BIT: + case DataType::TINYINT: + delete static_cast< sal_Int8* >(reinterpret_cast< void * >(pValue->first)); + break; + case DataType::SMALLINT: + delete static_cast< sal_Int16* >(reinterpret_cast< void * >(pValue->first)); + break; + case DataType::INTEGER: + delete static_cast< sal_Int32* >(reinterpret_cast< void * >(pValue->first)); + break; + case DataType::FLOAT: + delete static_cast< float* >(reinterpret_cast< void * >(pValue->first)); + break; + case DataType::BINARY: + case DataType::VARBINARY: + delete static_cast< sal_Int8* >(reinterpret_cast< void * >(pValue->first)); + break; + } + } + m_aBindVector.clear(); + m_aBindVector.push_back(TVoidPtr(0,0)); // the first is reserved for the bookmark + } + return nRet; +} +// ------------------------------------------------------------------------- +TVoidPtr OResultSet::allocBindColumn(sal_Int32 _nType,sal_Int32 _nColumnIndex) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::allocBindColumn" ); + TVoidPtr aPair; + switch (_nType) + { + case DataType::CHAR: + case DataType::VARCHAR: + aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new ::rtl::OString()),_nType); + break; + case DataType::BIGINT: + aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new sal_Int64(0)),_nType); + break; + case DataType::DECIMAL: + case DataType::NUMERIC: + aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new ::rtl::OString()),_nType); + break; + case DataType::REAL: + case DataType::DOUBLE: + aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new double(0.0)),_nType); + break; + case DataType::LONGVARCHAR: + case DataType::CLOB: + aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new char[2]),_nType); // dient nur zum auffinden + break; + case DataType::LONGVARBINARY: + case DataType::BLOB: + aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new char[2]),_nType); // dient nur zum auffinden + break; + case DataType::DATE: + aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new DATE_STRUCT),_nType); + break; + case DataType::TIME: + aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new TIME_STRUCT),_nType); + break; + case DataType::TIMESTAMP: + aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new TIMESTAMP_STRUCT),_nType); + break; + case DataType::BIT: + case DataType::TINYINT: + aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new sal_Int8(0)),_nType); + break; + case DataType::SMALLINT: + aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new sal_Int16(0)),_nType); + break; + case DataType::INTEGER: + aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new sal_Int32(0)),_nType); + break; + case DataType::FLOAT: + aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new float(0)),_nType); + break; + case DataType::BINARY: + case DataType::VARBINARY: + aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new sal_Int8[m_aRow[_nColumnIndex].getSequence().getLength()]),_nType); + break; + default: + OSL_ENSURE(0,"Unknown type"); + aPair = TVoidPtr(0,_nType); + } + return aPair; +} +// ------------------------------------------------------------------------- +void OResultSet::allocBuffer() +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::allocBuffer" ); + Reference< XResultSetMetaData > xMeta = getMetaData(); + sal_Int32 nLen = xMeta->getColumnCount(); + + m_aBindVector.reserve(nLen+1); + m_aBindVector.push_back(TVoidPtr(0,0)); // the first is reserved for the bookmark + m_aRow.resize(nLen+1); + + for(sal_Int32 i = 1;i<=nLen;++i) + { + sal_Int32 nType = xMeta->getColumnType(i); + m_aRow[i].setTypeKind( nType ); + } + m_aLengthVector.resize(nLen + 1); +} +// ------------------------------------------------------------------------- +void OResultSet::releaseBuffer() +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::releaseBuffer" ); + unbind(sal_False); + m_aLengthVector.clear(); +} +// ------------------------------------------------------------------------- +Any SAL_CALL OResultSet::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = OPropertySetHelper::queryInterface(rType); + return aRet.hasValue() ? aRet : OResultSet_BASE::queryInterface(rType); +} +// ------------------------------------------------------------------------- + Sequence< Type > SAL_CALL OResultSet::getTypes( ) throw( RuntimeException) +{ + OTypeCollection aTypes( ::getCppuType( (const Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ), + ::getCppuType( (const Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ), + ::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet > *)0 )); + + return ::comphelper::concatSequences(aTypes.getTypes(),OResultSet_BASE::getTypes()); +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSet::findColumn( const ::rtl::OUString& columnName ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::findColumn" ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + + ::osl::MutexGuard aGuard( m_aMutex ); + + Reference< XResultSetMetaData > xMeta = getMetaData(); + sal_Int32 nLen = xMeta->getColumnCount(); + sal_Int32 i = 1; + for(;i<=nLen;++i) + if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) : + columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i))) + break; + return i; +} +// ------------------------------------------------------------------------- +Reference< XInputStream > SAL_CALL OResultSet::getBinaryStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + + // TODO use getBytes instead of + return NULL; +} +// ------------------------------------------------------------------------- +Reference< XInputStream > SAL_CALL OResultSet::getCharacterStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + + // TODO use getBytes instead of + return NULL; +} +// ----------------------------------------------------------------------------- +const ORowSetValue& OResultSet::getValue(sal_Int32 _nColumnIndex,SQLSMALLINT _nType,void* _pValue,SQLINTEGER _rSize) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getValue" ); + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + if(m_bFetchData) + { + if(_nColumnIndex > m_nLastColumnPos) + fillRow(_nColumnIndex); + return m_aRow[_nColumnIndex]; + } + else + OTools::getValue(m_pStatement->getOwnConnection(),m_aStatementHandle,_nColumnIndex,_nType,m_bWasNull,**this,_pValue,_rSize); + + return m_aEmptyValue; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + sal_Int8 nVal(0); + const ORowSetValue& aValue = getValue(columnIndex,SQL_C_BIT,&nVal,sizeof nVal); + return (&aValue == &m_aEmptyValue) ? (sal_Bool)nVal : (sal_Bool)aValue; +} +// ------------------------------------------------------------------------- + +sal_Int8 SAL_CALL OResultSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + sal_Int8 nRet(0); + const ORowSetValue& aValue = getValue(columnIndex,SQL_C_TINYINT,&nRet,sizeof nRet); + return (&aValue == &m_aEmptyValue) ? nRet : (sal_Int8)aValue; +} +// ------------------------------------------------------------------------- + +Sequence< sal_Int8 > SAL_CALL OResultSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getBytes" ); + + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + ::osl::MutexGuard aGuard( m_aMutex ); + + + if(m_bFetchData) + { + if(columnIndex > m_nLastColumnPos) + fillRow(columnIndex); + Sequence< sal_Int8 > nRet; + switch(m_aRow[columnIndex].getTypeKind()) + { + case DataType::BINARY: + case DataType::VARBINARY: + case DataType::LONGVARBINARY: + nRet = m_aRow[columnIndex]; + break; + default: + { + ::rtl::OUString sRet; + sRet = m_aRow[columnIndex].getString(); + nRet = Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(sRet.getStr()),sizeof(sal_Unicode)*sRet.getLength()); + } + } + return nRet; + } + + const SWORD nColumnType = impl_getColumnType_nothrow(columnIndex); + + switch(nColumnType) + { + case SQL_WVARCHAR: + case SQL_WCHAR: + case SQL_WLONGVARCHAR: + case SQL_VARCHAR: + case SQL_CHAR: + case SQL_LONGVARCHAR: + { + ::rtl::OUString aRet = OTools::getStringValue(m_pStatement->getOwnConnection(),m_aStatementHandle,columnIndex,nColumnType,m_bWasNull,**this,m_nTextEncoding); + return Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(aRet.getStr()),sizeof(sal_Unicode)*aRet.getLength()); + } + default: + ; + } + return OTools::getBytesValue(m_pStatement->getOwnConnection(),m_aStatementHandle,columnIndex,SQL_C_BINARY,m_bWasNull,**this); +} +// ------------------------------------------------------------------------- + +Date SAL_CALL OResultSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getDate" ); + DATE_STRUCT aDate; + aDate.day = 0; + aDate.month = 0; + aDate.year = 0; + + const ORowSetValue& aValue = getValue( columnIndex, + m_pStatement->getOwnConnection()->useOldDateFormat() ? SQL_C_DATE : SQL_C_TYPE_DATE, + &aDate,sizeof aDate); + return (&aValue == &m_aEmptyValue) ? Date(aDate.day,aDate.month,aDate.year) : (Date)aValue; +} +// ------------------------------------------------------------------------- + +double SAL_CALL OResultSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + double nRet(0); + const ORowSetValue& aValue = getValue(columnIndex,SQL_C_DOUBLE,&nRet,sizeof nRet); + return (&aValue == &m_aEmptyValue) ? nRet : (double)aValue; +} +// ------------------------------------------------------------------------- + +float SAL_CALL OResultSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + float nRet(0); + const ORowSetValue& aValue = getValue(columnIndex,SQL_C_FLOAT,&nRet,sizeof nRet); + return (&aValue == &m_aEmptyValue) ? nRet : (float)aValue; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + sal_Int32 nRet(0); + const ORowSetValue& aValue = getValue(columnIndex,SQL_C_LONG,&nRet,sizeof nRet); + return (&aValue == &m_aEmptyValue) ? nRet : (sal_Int32)aValue; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSet::getRow( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + return m_pSkipDeletedSet ? m_pSkipDeletedSet->getMappedPosition(getDriverPos()) : getDriverPos(); +} +// ------------------------------------------------------------------------- + +sal_Int64 SAL_CALL OResultSet::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + sal_Int64 nRet(0); + try + { + const ORowSetValue& aValue = getValue(columnIndex,SQL_C_SBIGINT,&nRet,sizeof nRet); + return (&aValue == &m_aEmptyValue) ? nRet : (sal_Int64)aValue; + } + catch(SQLException&) + { + nRet = getString(columnIndex).toInt64(); + } + return nRet; +} +// ------------------------------------------------------------------------- + +Reference< XResultSetMetaData > SAL_CALL OResultSet::getMetaData( ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getMetaData" ); + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + + if(!m_xMetaData.is()) + m_xMetaData = new OResultSetMetaData(m_pStatement->getOwnConnection(),m_aStatementHandle); + return m_xMetaData; +} +// ------------------------------------------------------------------------- +Reference< XArray > SAL_CALL OResultSet::getArray( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException) +{ + ::dbtools::throwFunctionNotSupportedException( "XRow::getArray", *this ); + return NULL; +} + +// ------------------------------------------------------------------------- + +Reference< XClob > SAL_CALL OResultSet::getClob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException) +{ + ::dbtools::throwFunctionNotSupportedException( "XRow::getClob", *this ); + return NULL; +} +// ------------------------------------------------------------------------- +Reference< XBlob > SAL_CALL OResultSet::getBlob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException) +{ + ::dbtools::throwFunctionNotSupportedException( "XRow::getBlob", *this ); + return NULL; +} +// ------------------------------------------------------------------------- + +Reference< XRef > SAL_CALL OResultSet::getRef( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException) +{ + ::dbtools::throwFunctionNotSupportedException( "XRow::getRef", *this ); + return NULL; +} +// ------------------------------------------------------------------------- + +Any SAL_CALL OResultSet::getObject( sal_Int32 columnIndex, const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getObject" ); + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + fillRow(columnIndex); + return m_aRow[columnIndex].makeAny(); +} +// ------------------------------------------------------------------------- + +sal_Int16 SAL_CALL OResultSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + sal_Int16 nRet(0); + const ORowSetValue& aValue = getValue(columnIndex,SQL_C_SHORT,&nRet,sizeof nRet); + return (&aValue == &m_aEmptyValue) ? nRet : (sal_Int16)aValue; +} +// ------------------------------------------------------------------------- + + +::rtl::OUString SAL_CALL OResultSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getString" ); + ::osl::MutexGuard aGuard( m_aMutex ); + + ::rtl::OUString nRet; + if ( m_bFetchData ) + nRet = getValue(columnIndex,0,NULL,0); + else + { + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + const SWORD nColumnType = impl_getColumnType_nothrow(columnIndex); + nRet = OTools::getStringValue(m_pStatement->getOwnConnection(),m_aStatementHandle,columnIndex,nColumnType,m_bWasNull,**this,m_nTextEncoding); + } + return nRet; +} +// ------------------------------------------------------------------------- + +Time SAL_CALL OResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getTime" ); + TIME_STRUCT aTime={0,0,0}; + const ORowSetValue& aValue = getValue(columnIndex, + m_pStatement->getOwnConnection()->useOldDateFormat() ? SQL_C_TIME : SQL_C_TYPE_TIME, + &aTime,sizeof aTime); + return (&aValue == &m_aEmptyValue) ? Time(0,aTime.second,aTime.minute,aTime.hour) : (Time)aValue; +} +// ------------------------------------------------------------------------- + + +DateTime SAL_CALL OResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getTimestamp" ); + TIMESTAMP_STRUCT aTime={0,0,0,0,0,0,0}; + const ORowSetValue& aValue = getValue(columnIndex, + m_pStatement->getOwnConnection()->useOldDateFormat() ? SQL_C_TIMESTAMP : SQL_C_TYPE_TIMESTAMP, + &aTime,sizeof aTime); + return (&aValue == &m_aEmptyValue) + ? + DateTime(static_cast<sal_uInt16>(aTime.fraction*1000),aTime.second,aTime.minute,aTime.hour,aTime.day,aTime.month,aTime.year) + : + (DateTime)aValue; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::isBeforeFirst( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + return m_nRowPos == 0; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::isAfterLast( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + return m_nRowPos != 0 && m_nCurrentFetchState == SQL_NO_DATA; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::isFirst( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + return m_nRowPos == 1; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::isLast( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + + return m_bEOF && m_nCurrentFetchState != SQL_NO_DATA; +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::beforeFirst( ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::beforeFirst" ); + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + + if(first()) + previous(); + m_nCurrentFetchState = SQL_SUCCESS; +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::afterLast( ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::afterLast" ); + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + if(last()) + next(); + m_bEOF = sal_True; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::close( ) throw(SQLException, RuntimeException) +{ + { + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + } + dispose(); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::first( ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::first" ); + return moveImpl(IResultSetHelper::FIRST,0,sal_True); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::last( ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::last" ); + return moveImpl(IResultSetHelper::LAST,0,sal_True); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::absolute" ); + return moveImpl(IResultSetHelper::ABSOLUTE,row,sal_True); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::relative( sal_Int32 row ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::relative" ); + return moveImpl(IResultSetHelper::RELATIVE,row,sal_True); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::previous( ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::previous" ); + return moveImpl(IResultSetHelper::PRIOR,0,sal_True); +} +// ------------------------------------------------------------------------- +Reference< XInterface > SAL_CALL OResultSet::getStatement( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + return m_xStatement; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::rowDeleted() throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::rowDeleted" ); + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + sal_Bool bRet = m_bRowDeleted; + m_bRowDeleted = sal_False; + + return bRet; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::rowInserted( ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::rowInserted" ); + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + sal_Bool bInserted = m_bRowInserted; + m_bRowInserted = sal_False; + + return bInserted; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::rowUpdated( ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::rowUpdated" ); + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + + return m_pRowStatusArray[0] == SQL_ROW_UPDATED; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::next( ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::next" ); + return moveImpl(IResultSetHelper::NEXT,1,sal_True); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::wasNull( ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::wasNull" ); + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + + return m_bFetchData ? m_aRow[m_nLastColumnPos].isNull() : m_bWasNull; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::cancel( ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + + OTools::ThrowException(m_pStatement->getOwnConnection(),N3SQLCancel(m_aStatementHandle),m_aStatementHandle,SQL_HANDLE_STMT,*this); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::clearWarnings( ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- +Any SAL_CALL OResultSet::getWarnings( ) throw(SQLException, RuntimeException) +{ + return Any(); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::insertRow( ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::insertRow" ); + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + + SQLLEN nMaxLen = 20; + SQLLEN nRealLen = 0; + Sequence<sal_Int8> aBookmark(nMaxLen); + + SQLRETURN nRet = N3SQLBindCol(m_aStatementHandle, + 0, + SQL_C_VARBOOKMARK, + aBookmark.getArray(), + nMaxLen, + &nRealLen + ); + // Sequence<sal_Int8> aRealBookmark(nMaxLen); + + sal_Bool bPositionByBookmark = ( NULL != getOdbcFunction( ODBC3SQLBulkOperations ) ); + if ( bPositionByBookmark ) + { + nRet = N3SQLBulkOperations( m_aStatementHandle, SQL_ADD ); + fillNeededData( nRet ); + } + else + { + if(isBeforeFirst()) + next(); // must be done + nRet = N3SQLSetPos( m_aStatementHandle, 1, SQL_ADD, SQL_LOCK_NO_CHANGE ); + fillNeededData( nRet ); + } + try + { + OTools::ThrowException(m_pStatement->getOwnConnection(),nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this); + } + catch(SQLException e) + { + nRet = unbind(); + throw; + } + + + if ( bPositionByBookmark ) + { + nRet = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_FETCH_BOOKMARK_PTR,aBookmark.getArray(),SQL_IS_POINTER); // SQL_LEN_BINARY_ATTR(aBookmark.getLength()) + + nRet = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_BOOKMARK,0); + } + else + nRet = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_RELATIVE,0); // OJ 06.03.2004 + // sometimes we got an error but we are not interested in anymore #106047# OJ + // OTools::ThrowException(m_pStatement->getOwnConnection(),nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this); + nRet = unbind(); + OTools::ThrowException(m_pStatement->getOwnConnection(),nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this); + + if(m_pSkipDeletedSet) + { + aBookmark.realloc(nRealLen); + if(moveToBookmark(makeAny(aBookmark))) + { + sal_Int32 nRowPos = getDriverPos(); + if ( -1 == m_nRowPos ) + { + nRowPos = m_aPosToBookmarks.size() + 1; + } + if ( nRowPos == m_nRowPos ) + ++nRowPos; + m_nRowPos = nRowPos; + m_pSkipDeletedSet->insertNewPosition(nRowPos); + m_aPosToBookmarks[aBookmark] = nRowPos; + } + } + m_bRowInserted = sal_True; + +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateRow( ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::updateRow" ); + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + SQLRETURN nRet; + + sal_Bool bPositionByBookmark = ( NULL != getOdbcFunction( ODBC3SQLBulkOperations ) ); + if ( bPositionByBookmark ) + { + SQLLEN nRealLen = 0; + nRet = N3SQLBindCol(m_aStatementHandle, + 0, + SQL_C_VARBOOKMARK, + m_aBookmark.getArray(), + m_aBookmark.getLength(), + &nRealLen + ); + fillNeededData(nRet = N3SQLBulkOperations(m_aStatementHandle, SQL_UPDATE_BY_BOOKMARK)); + } + else + fillNeededData(nRet = N3SQLSetPos(m_aStatementHandle,1,SQL_UPDATE,SQL_LOCK_NO_CHANGE)); + OTools::ThrowException(m_pStatement->getOwnConnection(),nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this); + // now unbind all columns so we can fetch all columns again with SQLGetData + nRet = unbind(); + OSL_ENSURE(nRet == SQL_SUCCESS,"Could not unbind the columns!"); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::deleteRow( ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::deleteRow" ); + SQLRETURN nRet = SQL_SUCCESS; + sal_Int32 nPos = getDriverPos(); + nRet = N3SQLSetPos(m_aStatementHandle,1,SQL_DELETE,SQL_LOCK_NO_CHANGE); + OTools::ThrowException(m_pStatement->getOwnConnection(),nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this); + + m_bRowDeleted = ( m_pRowStatusArray[0] == SQL_ROW_DELETED ); + if ( m_bRowDeleted ) + { + TBookmarkPosMap::iterator aIter = m_aPosToBookmarks.begin(); + TBookmarkPosMap::iterator aEnd = m_aPosToBookmarks.end(); + for (; aIter != aEnd; ++aIter) + { + if ( aIter->second == nPos ) + { + m_aPosToBookmarks.erase(aIter); + break; + } + } + } + if ( m_pSkipDeletedSet ) + m_pSkipDeletedSet->deletePosition(nPos); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::cancelRowUpdates( ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::moveToInsertRow( ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::moveToInsertRow" ); + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + + m_nLastColumnPos = 0; + // first unbound all columns + OSL_VERIFY_EQUALS( unbind(), SQL_SUCCESS, "Could not unbind columns!" ); + // SQLRETURN nRet = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE ,(SQLPOINTER)1,SQL_IS_INTEGER); + m_bInserting = sal_True; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::moveToCurrentRow( ) throw(SQLException, RuntimeException) +{ + m_nLastColumnPos = 0; +} +// ------------------------------------------------------------------------- +void OResultSet::updateValue(sal_Int32 columnIndex,SQLSMALLINT _nType,void* _pValue) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::updateValue" ); + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + m_aBindVector.push_back(allocBindColumn(OTools::MapOdbcType2Jdbc(_nType),columnIndex)); + void* pData = reinterpret_cast<void*>(m_aBindVector.rbegin()->first); + OSL_ENSURE(pData != NULL,"Data for update is NULL!"); + OTools::bindValue( m_pStatement->getOwnConnection(), + m_aStatementHandle, + columnIndex, + _nType, + 0, + _pValue, + pData, + &m_aLengthVector[columnIndex], + **this, + m_nTextEncoding, + m_pStatement->getOwnConnection()->useOldDateFormat()); +} +// ----------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateNull( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + m_aBindVector.push_back(allocBindColumn(DataType::CHAR,columnIndex)); + void* pData = reinterpret_cast<void*>(m_aBindVector.rbegin()->first); + OTools::bindValue(m_pStatement->getOwnConnection(),m_aStatementHandle,columnIndex,SQL_CHAR,0,(sal_Int8*)NULL,pData,&m_aLengthVector[columnIndex],**this,m_nTextEncoding,m_pStatement->getOwnConnection()->useOldDateFormat()); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateBoolean( sal_Int32 columnIndex, sal_Bool x ) throw(SQLException, RuntimeException) +{ + updateValue(columnIndex,SQL_BIT,&x); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateByte( sal_Int32 columnIndex, sal_Int8 x ) throw(SQLException, RuntimeException) +{ + updateValue(columnIndex,SQL_CHAR,&x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateShort( sal_Int32 columnIndex, sal_Int16 x ) throw(SQLException, RuntimeException) +{ + updateValue(columnIndex,SQL_TINYINT,&x); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateInt( sal_Int32 columnIndex, sal_Int32 x ) throw(SQLException, RuntimeException) +{ + updateValue(columnIndex,SQL_INTEGER,&x); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateLong( sal_Int32 /*columnIndex*/, sal_Int64 /*x*/ ) throw(SQLException, RuntimeException) +{ + ::dbtools::throwFunctionNotSupportedException( "XRowUpdate::updateLong", *this ); +} +// ----------------------------------------------------------------------- +void SAL_CALL OResultSet::updateFloat( sal_Int32 columnIndex, float x ) throw(SQLException, RuntimeException) +{ + updateValue(columnIndex,SQL_REAL,&x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateDouble( sal_Int32 columnIndex, double x ) throw(SQLException, RuntimeException) +{ + updateValue(columnIndex,SQL_DOUBLE,&x); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateString( sal_Int32 columnIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException) +{ + sal_Int32 nType = m_aRow[columnIndex].getTypeKind(); + SQLSMALLINT nOdbcType = static_cast<SQLSMALLINT>(OTools::jdbcTypeToOdbc(nType)); + m_aRow[columnIndex] = x; + m_aRow[columnIndex].setTypeKind(nType); // OJ: otherwise longvarchar will be recognized by fillNeededData + updateValue(columnIndex,nOdbcType,(void*)&x); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateBytes( sal_Int32 columnIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException) +{ + sal_Int32 nType = m_aRow[columnIndex].getTypeKind(); + SQLSMALLINT nOdbcType = static_cast<SQLSMALLINT>(OTools::jdbcTypeToOdbc(nType)); + m_aRow[columnIndex] = x; + m_aRow[columnIndex].setTypeKind(nType); // OJ: otherwise longvarbinary will be recognized by fillNeededData + updateValue(columnIndex,nOdbcType,(void*)&x); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateDate( sal_Int32 columnIndex, const Date& x ) throw(SQLException, RuntimeException) +{ + DATE_STRUCT aVal = OTools::DateToOdbcDate(x); + updateValue(columnIndex,SQL_DATE,&aVal); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateTime( sal_Int32 columnIndex, const Time& x ) throw(SQLException, RuntimeException) +{ + TIME_STRUCT aVal = OTools::TimeToOdbcTime(x); + updateValue(columnIndex,SQL_TIME,&aVal); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateTimestamp( sal_Int32 columnIndex, const DateTime& x ) throw(SQLException, RuntimeException) +{ + TIMESTAMP_STRUCT aVal = OTools::DateTimeToTimestamp(x); + updateValue(columnIndex,SQL_TIMESTAMP,&aVal); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateBinaryStream( sal_Int32 columnIndex, const Reference< XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException) +{ + if(!x.is()) + ::dbtools::throwFunctionSequenceException(*this); + + Sequence<sal_Int8> aSeq; + x->readBytes(aSeq,length); + updateBytes(columnIndex,aSeq); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateCharacterStream( sal_Int32 columnIndex, const Reference< XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException) +{ + updateBinaryStream(columnIndex,x,length); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::refreshRow( ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::refreshRow" ); + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + + // SQLRETURN nRet = N3SQLSetPos(m_aStatementHandle,1,SQL_REFRESH,SQL_LOCK_NO_CHANGE); + m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_RELATIVE,0); + OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateObject( sal_Int32 columnIndex, const Any& x ) throw(SQLException, RuntimeException) +{ + if (!::dbtools::implUpdateObject(this, columnIndex, x)) + throw SQLException(); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateNumericObject( sal_Int32 columnIndex, const Any& x, sal_Int32 /*scale*/ ) throw(SQLException, RuntimeException) +{ + if (!::dbtools::implUpdateObject(this, columnIndex, x)) + throw SQLException(); +} +// ------------------------------------------------------------------------- +// XRowLocate +Any SAL_CALL OResultSet::getBookmark( ) throw( SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getBookmark" ); + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + TBookmarkPosMap::iterator aFind = ::std::find_if(m_aPosToBookmarks.begin(),m_aPosToBookmarks.end(), + ::std::compose1(::std::bind2nd(::std::equal_to<sal_Int32>(),m_nRowPos),::std::select2nd<TBookmarkPosMap::value_type>())); + + if ( aFind == m_aPosToBookmarks.end() ) + { + if ( m_nUseBookmarks == ODBC_SQL_NOT_DEFINED ) + { + RTL_LOGFILE_CONTEXT_TRACE( aLogger, "SQLGetStmtAttr" ); + m_nUseBookmarks = SQL_UB_OFF; + SQLRETURN nRet = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_USE_BOOKMARKS,&m_nUseBookmarks,SQL_IS_UINTEGER,NULL); + OSL_UNUSED( nRet ); + } + if(m_nUseBookmarks == SQL_UB_OFF) + throw SQLException(); + + m_aBookmark = OTools::getBytesValue(m_pStatement->getOwnConnection(),m_aStatementHandle,0,SQL_C_VARBOOKMARK,m_bWasNull,**this); + m_aPosToBookmarks[m_aBookmark] = m_nRowPos; + OSL_ENSURE(m_aBookmark.getLength(),"Invalid bookmark from length 0!"); + } + else + m_aBookmark = aFind->first; + return makeAny(m_aBookmark); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::moveToBookmark( const Any& bookmark ) throw( SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::moveToBookmark" ); + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + m_nLastColumnPos = 0; + bookmark >>= m_aBookmark; + OSL_ENSURE(m_aBookmark.getLength(),"Invalid bookmark from length 0!"); + if(m_aBookmark.getLength()) + { + SQLRETURN nReturn = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_FETCH_BOOKMARK_PTR,m_aBookmark.getArray(),SQL_IS_POINTER); // SQL_LEN_BINARY_ATTR(aBookmark.getLength()) + OSL_UNUSED( nReturn ); + + if ( SQL_INVALID_HANDLE != nReturn && SQL_ERROR != nReturn ) + { + m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_BOOKMARK,0); + OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this); + TBookmarkPosMap::iterator aFind = m_aPosToBookmarks.find(m_aBookmark); + if(aFind != m_aPosToBookmarks.end()) + m_nRowPos = aFind->second; + else + m_nRowPos = -1; + return m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO; + } + } + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw( SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::moveRelativeToBookmark" ); + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + + m_nLastColumnPos = 0; + bookmark >>= m_aBookmark; + SQLRETURN nReturn = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_FETCH_BOOKMARK_PTR,m_aBookmark.getArray(),SQL_IS_POINTER); + OSL_UNUSED( nReturn ); + + m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_BOOKMARK,rows); + OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this); + return m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OResultSet::compareBookmarks( const Any& lhs, const Any& rhs ) throw( SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::compareBookmarks" ); + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + return (lhs == rhs) ? CompareBookmark::EQUAL : CompareBookmark::NOT_EQUAL; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::hasOrderedBookmarks( ) throw( SQLException, RuntimeException) +{ + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OResultSet::hashBookmark( const Any& /*bookmark*/ ) throw( SQLException, RuntimeException) +{ + ::dbtools::throwFunctionNotSupportedException( "XRowLocate::hashBookmark", *this ); + return 0; +} +// ------------------------------------------------------------------------- +// XDeleteRows +Sequence< sal_Int32 > SAL_CALL OResultSet::deleteRows( const Sequence< Any >& rows ) throw( SQLException, RuntimeException) +{ + Sequence< sal_Int32 > aRet(rows.getLength()); + sal_Int32 *pRet = aRet.getArray(); + + const Any *pBegin = rows.getConstArray(); + const Any *pEnd = pBegin + rows.getLength(); + + for(;pBegin != pEnd;++pBegin,++pRet) + { + try + { + if(moveToBookmark(*pBegin)) + { + deleteRow(); + *pRet = 1; + } + } + catch(SQLException&) + { + *pRet = 0; + } + } + return aRet; +} +//------------------------------------------------------------------------------ +sal_Int32 OResultSet::getResultSetConcurrency() const +{ + sal_uInt32 nValue = 0; + SQLRETURN nReturn = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CONCURRENCY,&nValue,SQL_IS_UINTEGER,0); + OSL_UNUSED( nReturn ); + if(SQL_CONCUR_READ_ONLY == nValue) + nValue = ResultSetConcurrency::READ_ONLY; + else + nValue = ResultSetConcurrency::UPDATABLE; + + return nValue; +} +//------------------------------------------------------------------------------ +sal_Int32 OResultSet::getResultSetType() const +{ + sal_uInt32 nValue = 0; + N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_SENSITIVITY,&nValue,SQL_IS_UINTEGER,0); + if(SQL_SENSITIVE == nValue) + nValue = ResultSetType::SCROLL_SENSITIVE; + else if(SQL_INSENSITIVE == nValue) + nValue = ResultSetType::SCROLL_INSENSITIVE; + else + { + SQLINTEGER nCurType = 0; + N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,&nCurType,SQL_IS_UINTEGER,0); + if(SQL_CURSOR_KEYSET_DRIVEN == nCurType) + nValue = ResultSetType::SCROLL_SENSITIVE; + else if(SQL_CURSOR_STATIC == nCurType) + nValue = ResultSetType::SCROLL_INSENSITIVE; + else if(SQL_CURSOR_FORWARD_ONLY == nCurType) + nValue = ResultSetType::FORWARD_ONLY; + else if(SQL_CURSOR_DYNAMIC == nCurType) + nValue = ResultSetType::SCROLL_SENSITIVE; + } + return nValue; +} +//------------------------------------------------------------------------------ +sal_Int32 OResultSet::getFetchDirection() const +{ + return FetchDirection::FORWARD; +} +//------------------------------------------------------------------------------ +sal_Int32 OResultSet::getFetchSize() const +{ + sal_uInt32 nValue = 0; + N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE,&nValue,SQL_IS_UINTEGER,0); + return nValue; +} +//------------------------------------------------------------------------------ +::rtl::OUString OResultSet::getCursorName() const +{ + SQLCHAR pName[258]; + SQLSMALLINT nRealLen = 0; + N3SQLGetCursorName(m_aStatementHandle,(SQLCHAR*)pName,256,&nRealLen); + return ::rtl::OUString::createFromAscii((const char*)pName); +} +// ------------------------------------------------------------------------- +sal_Bool OResultSet::isBookmarkable() const +{ + if(!m_aConnectionHandle) + return sal_False; + + sal_uInt32 nValue = 0; + N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,&nValue,SQL_IS_UINTEGER,0); + + sal_Int32 nAttr = 0; + try + { + switch(nValue) + { + case SQL_CURSOR_FORWARD_ONLY: + return sal_False; + case SQL_CURSOR_STATIC: + OTools::GetInfo(m_pStatement->getOwnConnection(),m_aConnectionHandle,SQL_STATIC_CURSOR_ATTRIBUTES1,nAttr,NULL); + break; + case SQL_CURSOR_KEYSET_DRIVEN: + OTools::GetInfo(m_pStatement->getOwnConnection(),m_aConnectionHandle,SQL_KEYSET_CURSOR_ATTRIBUTES1,nAttr,NULL); + break; + case SQL_CURSOR_DYNAMIC: + OTools::GetInfo(m_pStatement->getOwnConnection(),m_aConnectionHandle,SQL_DYNAMIC_CURSOR_ATTRIBUTES1,nAttr,NULL); + break; + } + } + catch(Exception&) + { + return sal_False; + } + + if ( m_nUseBookmarks == ODBC_SQL_NOT_DEFINED ) + { + m_nUseBookmarks = SQL_UB_OFF; + SQLRETURN nRet = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_USE_BOOKMARKS,&m_nUseBookmarks,SQL_IS_UINTEGER,NULL); + OSL_UNUSED( nRet ); + } + + return (m_nUseBookmarks != SQL_UB_OFF) && (nAttr & SQL_CA1_BOOKMARK) == SQL_CA1_BOOKMARK; +} +//------------------------------------------------------------------------------ +void OResultSet::setFetchDirection(sal_Int32 _par0) +{ + N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,(SQLPOINTER)_par0,SQL_IS_UINTEGER); +} +//------------------------------------------------------------------------------ +void OResultSet::setFetchSize(sal_Int32 _par0) +{ + N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE,(SQLPOINTER)_par0,SQL_IS_UINTEGER); + delete m_pRowStatusArray; + m_pRowStatusArray = new SQLUSMALLINT[_par0]; + N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_STATUS_PTR,m_pRowStatusArray,SQL_IS_POINTER); +} +// ------------------------------------------------------------------------- +IPropertyArrayHelper* OResultSet::createArrayHelper( ) const +{ + Sequence< Property > aProps(6); + Property* pProperties = aProps.getArray(); + sal_Int32 nPos = 0; + DECL_PROP1IMPL(CURSORNAME, ::rtl::OUString) PropertyAttribute::READONLY); + DECL_PROP0(FETCHDIRECTION, sal_Int32); + DECL_PROP0(FETCHSIZE, sal_Int32); + DECL_BOOL_PROP1IMPL(ISBOOKMARKABLE) PropertyAttribute::READONLY); + DECL_PROP1IMPL(RESULTSETCONCURRENCY,sal_Int32) PropertyAttribute::READONLY); + DECL_PROP1IMPL(RESULTSETTYPE, sal_Int32) PropertyAttribute::READONLY); + + return new OPropertyArrayHelper(aProps); +} +// ------------------------------------------------------------------------- +IPropertyArrayHelper & OResultSet::getInfoHelper() +{ + return *const_cast<OResultSet*>(this)->getArrayHelper(); +} +// ------------------------------------------------------------------------- +sal_Bool OResultSet::convertFastPropertyValue( + Any & rConvertedValue, + Any & rOldValue, + sal_Int32 nHandle, + const Any& rValue ) + throw (::com::sun::star::lang::IllegalArgumentException) +{ + switch(nHandle) + { + case PROPERTY_ID_ISBOOKMARKABLE: + case PROPERTY_ID_CURSORNAME: + case PROPERTY_ID_RESULTSETCONCURRENCY: + case PROPERTY_ID_RESULTSETTYPE: + throw ::com::sun::star::lang::IllegalArgumentException(); + case PROPERTY_ID_FETCHDIRECTION: + return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection()); + case PROPERTY_ID_FETCHSIZE: + return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize()); + default: + ; + } + return sal_False; +} +// ------------------------------------------------------------------------- +void OResultSet::setFastPropertyValue_NoBroadcast( + sal_Int32 nHandle, + const Any& rValue + ) + throw (Exception) +{ + switch(nHandle) + { + case PROPERTY_ID_ISBOOKMARKABLE: + case PROPERTY_ID_CURSORNAME: + case PROPERTY_ID_RESULTSETCONCURRENCY: + case PROPERTY_ID_RESULTSETTYPE: + throw Exception(); + case PROPERTY_ID_FETCHDIRECTION: + setFetchDirection(getINT32(rValue)); + break; + case PROPERTY_ID_FETCHSIZE: + setFetchSize(getINT32(rValue)); + break; + default: + ; + } +} +// ------------------------------------------------------------------------- +void OResultSet::getFastPropertyValue( + Any& rValue, + sal_Int32 nHandle + ) const +{ + switch(nHandle) + { + case PROPERTY_ID_ISBOOKMARKABLE: + rValue = bool2any(isBookmarkable()); + break; + case PROPERTY_ID_CURSORNAME: + rValue <<= getCursorName(); + break; + case PROPERTY_ID_RESULTSETCONCURRENCY: + rValue <<= getResultSetConcurrency(); + break; + case PROPERTY_ID_RESULTSETTYPE: + rValue <<= getResultSetType(); + break; + case PROPERTY_ID_FETCHDIRECTION: + rValue <<= getFetchDirection(); + break; + case PROPERTY_ID_FETCHSIZE: + rValue <<= getFetchSize(); + break; + } +} +// ------------------------------------------------------------------------- +void OResultSet::fillRow(sal_Int32 _nToColumn) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::fillRow" ); + if((sal_Int32)m_aRow.size() <= _nToColumn) + { + m_aRow.resize(_nToColumn+1); + m_aRow[_nToColumn].setBound(sal_True); + } + m_bFetchData = sal_False; + + sal_Int32 nColumn = m_nLastColumnPos + 1; + TDataRow::iterator pColumn = m_aRow.begin() + nColumn; + TDataRow::iterator pColumnEnd = m_aRow.begin() + _nToColumn + 1; + + for (; pColumn < pColumnEnd; ++nColumn, ++pColumn) + { + const sal_Int32 nType = pColumn->getTypeKind(); + switch (nType) + { + case DataType::CHAR: + case DataType::VARCHAR: + case DataType::DECIMAL: + case DataType::NUMERIC: + case DataType::LONGVARCHAR: + case DataType::CLOB: + { + const SWORD nColumnType = impl_getColumnType_nothrow(nColumn); + *pColumn = OTools::getStringValue(m_pStatement->getOwnConnection(),m_aStatementHandle,nColumn,nColumnType,m_bWasNull,**this,m_nTextEncoding); + } + break; + case DataType::BIGINT: + *pColumn = getLong(nColumn); + break; + case DataType::REAL: + case DataType::DOUBLE: + *pColumn = getDouble(nColumn); + break; + case DataType::LONGVARBINARY: + case DataType::BLOB: + *pColumn = getBytes(nColumn); + break; + case DataType::DATE: + *pColumn = getDate(nColumn); + break; + case DataType::TIME: + *pColumn = getTime(nColumn); + break; + case DataType::TIMESTAMP: + *pColumn = getTimestamp(nColumn); + break; + case DataType::BIT: + *pColumn = getBoolean(nColumn); + break; + case DataType::TINYINT: + *pColumn = getByte(nColumn); + break; + case DataType::SMALLINT: + *pColumn = getShort(nColumn); + break; + case DataType::INTEGER: + *pColumn = getInt(nColumn); + break; + case DataType::FLOAT: + *pColumn = getFloat(nColumn); + break; + case DataType::BINARY: + case DataType::VARBINARY: + *pColumn = getBytes(nColumn); + break; + } + + if ( m_bWasNull ) + pColumn->setNull(); + if(nType != pColumn->getTypeKind()) + { + pColumn->setTypeKind(nType); + } + } + m_nLastColumnPos = _nToColumn; + m_bFetchData = sal_True; +} +// ----------------------------------------------------------------------------- +void SAL_CALL OResultSet::acquire() throw() +{ + OResultSet_BASE::acquire(); +} +// ----------------------------------------------------------------------------- +void SAL_CALL OResultSet::release() throw() +{ + OResultSet_BASE::release(); +} +// ----------------------------------------------------------------------------- +::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OResultSet::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException) +{ + return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); +} +// ----------------------------------------------------------------------------- +sal_Bool OResultSet::move(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nOffset, sal_Bool /*_bRetrieveData*/) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::move" ); + SQLSMALLINT nFetchOrientation = SQL_FETCH_NEXT; + switch(_eCursorPosition) + { + case IResultSetHelper::NEXT: + nFetchOrientation = SQL_FETCH_NEXT; + break; + case IResultSetHelper::PRIOR: + nFetchOrientation = SQL_FETCH_PRIOR; + break; + case IResultSetHelper::FIRST: + nFetchOrientation = SQL_FETCH_FIRST; + break; + case IResultSetHelper::LAST: + nFetchOrientation = SQL_FETCH_LAST; + break; + case IResultSetHelper::RELATIVE: + nFetchOrientation = SQL_FETCH_RELATIVE; + break; + case IResultSetHelper::ABSOLUTE: + nFetchOrientation = SQL_FETCH_ABSOLUTE; + break; + case IResultSetHelper::BOOKMARK: // special case here because we are only called with position numbers + { + TBookmarkPosMap::iterator aIter = m_aPosToBookmarks.begin(); + TBookmarkPosMap::iterator aEnd = m_aPosToBookmarks.end(); + for (; aIter != aEnd; ++aIter) + { + if ( aIter->second == _nOffset ) + return moveToBookmark(makeAny(aIter->first)); + } + OSL_ENSURE(0,"Bookmark not found!"); + } + return sal_False; + } + + m_bEOF = sal_False; + m_nLastColumnPos = 0; + + SQLRETURN nOldFetchStatus = m_nCurrentFetchState; + if ( !m_bUseFetchScroll && _eCursorPosition == IResultSetHelper::NEXT ) + m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle); + else + m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,nFetchOrientation,_nOffset); + + OSL_TRACE( __FILE__": OSkipDeletedSet::OResultSet::move(%d,%d), FetchState = %d",nFetchOrientation,_nOffset,m_nCurrentFetchState); + OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this); + + const bool bSuccess = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO; + if ( bSuccess ) + { + switch(_eCursorPosition) + { + case IResultSetHelper::NEXT: + ++m_nRowPos; + break; + case IResultSetHelper::PRIOR: + --m_nRowPos; + break; + case IResultSetHelper::FIRST: + m_nRowPos = 1; + break; + case IResultSetHelper::LAST: + m_bEOF = sal_True; + break; + case IResultSetHelper::RELATIVE: + m_nRowPos += _nOffset; + break; + case IResultSetHelper::ABSOLUTE: + case IResultSetHelper::BOOKMARK: // special case here because we are only called with position numbers + m_nRowPos = _nOffset; + break; + } // switch(_eCursorPosition) + if ( m_nUseBookmarks == ODBC_SQL_NOT_DEFINED ) + { + RTL_LOGFILE_CONTEXT_TRACE( aLogger, "SQLGetStmtAttr" ); + m_nUseBookmarks = SQL_UB_OFF; + SQLRETURN nRet = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_USE_BOOKMARKS,&m_nUseBookmarks,SQL_IS_UINTEGER,NULL); + OSL_UNUSED( nRet ); + } + if ( m_nUseBookmarks != SQL_UB_OFF ) + { + RTL_LOGFILE_CONTEXT_TRACE( aLogger, "OTools::getBytesValue" ); + m_aBookmark = OTools::getBytesValue(m_pStatement->getOwnConnection(),m_aStatementHandle,0,SQL_C_VARBOOKMARK,m_bWasNull,**this); + m_aPosToBookmarks[m_aBookmark] = m_nRowPos; + OSL_ENSURE(m_aBookmark.getLength(),"Invalid bookmark from length 0!"); + } + } + else if ( IResultSetHelper::PRIOR == _eCursorPosition && m_nCurrentFetchState == SQL_NO_DATA ) + m_nRowPos = 0; + else if(IResultSetHelper::NEXT == _eCursorPosition && m_nCurrentFetchState == SQL_NO_DATA && nOldFetchStatus != SQL_NO_DATA) + ++m_nRowPos; + + return bSuccess; +} +// ----------------------------------------------------------------------------- +sal_Int32 OResultSet::getDriverPos() const +{ + sal_Int32 nValue = 0; + SQLRETURN nRet = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_NUMBER,&nValue,SQL_IS_UINTEGER,0); + OSL_UNUSED( nRet ); + OSL_TRACE( __FILE__": OResultSet::getDriverPos() = Ret = %d, RowNum = %d, RowPos = %d",nRet,nValue , m_nRowPos); + return nValue ? nValue : m_nRowPos; +} +// ----------------------------------------------------------------------------- +sal_Bool OResultSet::deletedVisible() const +{ + return sal_False; +} +// ----------------------------------------------------------------------------- +sal_Bool OResultSet::isRowDeleted() const +{ + return m_pRowStatusArray[0] == SQL_ROW_DELETED; +} +// ----------------------------------------------------------------------------- +sal_Bool OResultSet::moveImpl(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nOffset, sal_Bool _bRetrieveData) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + return (m_pSkipDeletedSet != NULL) + ? m_pSkipDeletedSet->skipDeleted(_eCursorPosition,_nOffset,_bRetrieveData) + : move(_eCursorPosition,_nOffset,_bRetrieveData); +} +// ----------------------------------------------------------------------------- +void OResultSet::fillNeededData(SQLRETURN _nRet) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::fillNeededData" ); + SQLRETURN nRet = _nRet; + if( nRet == SQL_NEED_DATA) + { + void* pColumnIndex = 0; + nRet = N3SQLParamData(m_aStatementHandle,&pColumnIndex); + + do + { + if (nRet != SQL_SUCCESS && nRet != SQL_SUCCESS_WITH_INFO && nRet != SQL_NEED_DATA) + break; + + sal_IntPtr nColumnIndex ( reinterpret_cast<sal_IntPtr>(pColumnIndex)); + Sequence< sal_Int8 > aSeq; + switch(m_aRow[nColumnIndex].getTypeKind()) + { + case DataType::BINARY: + case DataType::VARBINARY: + case DataType::LONGVARBINARY: + case DataType::BLOB: + aSeq = m_aRow[nColumnIndex]; + N3SQLPutData (m_aStatementHandle, aSeq.getArray(), aSeq.getLength()); + break; + case SQL_WLONGVARCHAR: + { + ::rtl::OUString sRet; + sRet = m_aRow[nColumnIndex].getString(); + nRet = N3SQLPutData (m_aStatementHandle, (SQLPOINTER)sRet.getStr(), sizeof(sal_Unicode)*sRet.getLength()); + break; + } + case DataType::LONGVARCHAR: + case DataType::CLOB: + { + ::rtl::OUString sRet; + sRet = m_aRow[nColumnIndex].getString(); + ::rtl::OString aString(::rtl::OUStringToOString(sRet,m_nTextEncoding)); + nRet = N3SQLPutData (m_aStatementHandle, (SQLPOINTER)aString.getStr(), aString.getLength()); + break; + } + default: + OSL_ENSURE(0,"Not supported at the moment!"); + } + nRet = N3SQLParamData(m_aStatementHandle,&pColumnIndex); + } + while (nRet == SQL_NEED_DATA); + } +} +// ----------------------------------------------------------------------------- +SWORD OResultSet::impl_getColumnType_nothrow(sal_Int32 columnIndex) +{ + ::std::map<sal_Int32,SWORD>::iterator aFind = m_aODBCColumnTypes.find(columnIndex); + if ( aFind == m_aODBCColumnTypes.end() ) + aFind = m_aODBCColumnTypes.insert(::std::map<sal_Int32,SWORD>::value_type(columnIndex,OResultSetMetaData::getColumnODBCType(m_pStatement->getOwnConnection(),m_aStatementHandle,*this,columnIndex))).first; + return aFind->second; +} + diff --git a/connectivity/source/drivers/odbcbase/OResultSetMetaData.cxx b/connectivity/source/drivers/odbcbase/OResultSetMetaData.cxx new file mode 100644 index 000000000000..db4538b76e10 --- /dev/null +++ b/connectivity/source/drivers/odbcbase/OResultSetMetaData.cxx @@ -0,0 +1,312 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "odbc/OResultSetMetaData.hxx" +#include "odbc/OTools.hxx" +#include <rtl/logfile.hxx> + +using namespace connectivity::odbc; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::sdbc; + +// ------------------------------------------------------------------------- +OResultSetMetaData::~OResultSetMetaData() +{ +} +// ------------------------------------------------------------------------- +::rtl::OUString OResultSetMetaData::getCharColAttrib(sal_Int32 _column,sal_Int32 ident) throw(SQLException, RuntimeException) +{ + sal_Int32 column = _column; + if(_column <(sal_Int32) m_vMapping.size()) // use mapping + column = m_vMapping[_column]; + + SQLSMALLINT BUFFER_LEN = 128; + char *pName = new char[BUFFER_LEN+1]; + SQLSMALLINT nRealLen=0; + SQLRETURN nRet = N3SQLColAttribute(m_aStatementHandle, + (SQLUSMALLINT)column, + (SQLUSMALLINT)ident, + (SQLPOINTER)pName, + BUFFER_LEN, + &nRealLen, + NULL + ); + ::rtl::OUString sValue; + if ( nRet == SQL_SUCCESS ) + sValue = ::rtl::OUString(pName,nRealLen,m_pConnection->getTextEncoding()); + delete [] pName; + OTools::ThrowException(m_pConnection,nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this); + if(nRealLen > BUFFER_LEN) + { + pName = new char[nRealLen+1]; + nRet = N3SQLColAttribute(m_aStatementHandle, + (SQLUSMALLINT)column, + (SQLUSMALLINT)ident, + (SQLPOINTER)pName, + nRealLen, + &nRealLen, + NULL + ); + if ( nRet == SQL_SUCCESS ) + sValue = ::rtl::OUString(pName,nRealLen,m_pConnection->getTextEncoding()); + delete [] pName; + OTools::ThrowException(m_pConnection,nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this); + } + + return sValue; +} +// ------------------------------------------------------------------------- +SQLLEN OResultSetMetaData::getNumColAttrib(OConnection* _pConnection + ,SQLHANDLE _aStatementHandle + ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface + ,sal_Int32 _column + ,sal_Int32 _ident) throw(SQLException, RuntimeException) +{ + SQLLEN nValue=0; + OTools::ThrowException(_pConnection,(*(T3SQLColAttribute)_pConnection->getOdbcFunction(ODBC3SQLColAttribute))(_aStatementHandle, + (SQLUSMALLINT)_column, + (SQLUSMALLINT)_ident, + NULL, + 0, + NULL, + &nValue),_aStatementHandle,SQL_HANDLE_STMT,_xInterface); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 OResultSetMetaData::getNumColAttrib(sal_Int32 _column,sal_Int32 ident) throw(SQLException, RuntimeException) +{ + sal_Int32 column = _column; + if(_column < (sal_Int32)m_vMapping.size()) // use mapping + column = m_vMapping[_column]; + + return getNumColAttrib(m_pConnection,m_aStatementHandle,*this,column,ident); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_DISPLAY_SIZE); +} +// ------------------------------------------------------------------------- +SQLSMALLINT OResultSetMetaData::getColumnODBCType(OConnection* _pConnection + ,SQLHANDLE _aStatementHandle + ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface + ,sal_Int32 column) + throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SQLSMALLINT nType = 0; + try + { + nType = (SQLSMALLINT)getNumColAttrib(_pConnection,_aStatementHandle,_xInterface,column,SQL_DESC_CONCISE_TYPE); + if(nType == SQL_UNKNOWN_TYPE) + nType = (SQLSMALLINT)getNumColAttrib(_pConnection,_aStatementHandle,_xInterface,column, SQL_DESC_TYPE); + } + catch(SQLException& ) // in this case we have an odbc 2.0 driver + { + nType = (SQLSMALLINT)getNumColAttrib(_pConnection,_aStatementHandle,_xInterface,column,SQL_DESC_CONCISE_TYPE ); + } + + return nType; +} +// ----------------------------------------------------------------------------- +sal_Int32 SAL_CALL OResultSetMetaData::getColumnType( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + ::std::map<sal_Int32,sal_Int32>::iterator aFind = m_aColumnTypes.find(column); + if ( aFind == m_aColumnTypes.end() ) + { + sal_Int32 nType = 0; + if(!m_bUseODBC2Types) + { + try + { + nType = getNumColAttrib(column,SQL_DESC_CONCISE_TYPE); + if(nType == SQL_UNKNOWN_TYPE) + nType = getNumColAttrib(column, SQL_DESC_TYPE); + nType = OTools::MapOdbcType2Jdbc(nType); + } + catch(SQLException& ) // in this case we have an odbc 2.0 driver + { + m_bUseODBC2Types = sal_True; + nType = OTools::MapOdbcType2Jdbc(getNumColAttrib(column,SQL_DESC_CONCISE_TYPE )); + } + } + else + nType = OTools::MapOdbcType2Jdbc(getNumColAttrib(column,SQL_DESC_CONCISE_TYPE )); + aFind = m_aColumnTypes.insert(::std::map<sal_Int32,sal_Int32>::value_type(column,nType)).first; + } + + + return aFind->second; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount( ) throw(SQLException, RuntimeException) +{ + if(m_nColCount != -1) + return m_nColCount; + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSetMetaData::getColumnCount" ); + sal_Int16 nNumResultCols=0; + OTools::ThrowException(m_pConnection,N3SQLNumResultCols(m_aStatementHandle,&nNumResultCols),m_aStatementHandle,SQL_HANDLE_STMT,*this); + return m_nColCount = nNumResultCols; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_CASE_SENSITIVE) == SQL_TRUE; +} +// ------------------------------------------------------------------------- + +::rtl::OUString SAL_CALL OResultSetMetaData::getSchemaName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getCharColAttrib(column,SQL_DESC_SCHEMA_NAME); +} +// ------------------------------------------------------------------------- + +::rtl::OUString SAL_CALL OResultSetMetaData::getColumnName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getCharColAttrib(column,SQL_DESC_NAME); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getTableName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getCharColAttrib(column,SQL_DESC_TABLE_NAME); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getCatalogName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getCharColAttrib(column,SQL_DESC_CATALOG_NAME); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getColumnTypeName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSetMetaData::getColumnTypeName" ); + return getCharColAttrib(column,SQL_DESC_TYPE_NAME); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getColumnLabel( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSetMetaData::getColumnLabel" ); + return getCharColAttrib(column,SQL_DESC_LABEL); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getColumnServiceName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSetMetaData::getColumnServiceName" ); + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isCurrency( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_FIXED_PREC_SCALE) == SQL_TRUE; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_AUTO_UNIQUE_VALUE) == SQL_TRUE; +} +// ------------------------------------------------------------------------- + + +sal_Bool SAL_CALL OResultSetMetaData::isSigned( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSetMetaData::isSigned" ); + return getNumColAttrib(column,SQL_DESC_UNSIGNED) == SQL_FALSE; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OResultSetMetaData::getPrecision( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSetMetaData::getPrecision" ); + sal_Int32 nType = 0; + try + { + nType = getNumColAttrib(column,SQL_DESC_PRECISION); + } + catch(const SQLException& ) // in this case we have an odbc 2.0 driver + { + m_bUseODBC2Types = sal_True; + nType = getNumColAttrib(column,SQL_COLUMN_PRECISION ); + } + return nType; +} +// ----------------------------------------------------------------------------- +sal_Int32 SAL_CALL OResultSetMetaData::getScale( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSetMetaData::getScale" ); + sal_Int32 nType = 0; + try + { + nType = getNumColAttrib(column,SQL_DESC_SCALE); + } + catch(const SQLException& ) // in this case we have an odbc 2.0 driver + { + m_bUseODBC2Types = sal_True; + nType = getNumColAttrib(column,SQL_COLUMN_SCALE ); + } + return nType; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSetMetaData::isNullable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSetMetaData::isNullable" ); + return getNumColAttrib(column,SQL_DESC_NULLABLE); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isSearchable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSetMetaData::isSearchable" ); + return getNumColAttrib(column,SQL_DESC_SEARCHABLE) != SQL_PRED_NONE; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isReadOnly( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSetMetaData::isReadOnly" ); + return getNumColAttrib(column,SQL_DESC_UPDATABLE) == SQL_ATTR_READONLY; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSetMetaData::isDefinitelyWritable" ); + return getNumColAttrib(column,SQL_DESC_UPDATABLE) == SQL_ATTR_WRITE; +; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSetMetaData::isWritable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSetMetaData::isWritable" ); + return getNumColAttrib(column,SQL_DESC_UPDATABLE) == SQL_ATTR_WRITE; +} +// ------------------------------------------------------------------------- + diff --git a/connectivity/source/drivers/odbcbase/OStatement.cxx b/connectivity/source/drivers/odbcbase/OStatement.cxx new file mode 100644 index 000000000000..874e24c20e75 --- /dev/null +++ b/connectivity/source/drivers/odbcbase/OStatement.cxx @@ -0,0 +1,1154 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" + +#include <stdio.h> +#include <osl/diagnose.h> +#include "odbc/OStatement.hxx" +#include "odbc/OConnection.hxx" +#include "odbc/OResultSet.hxx" +#include <comphelper/property.hxx> +#include "odbc/OTools.hxx" +#include <comphelper/uno3.hxx> +#include <osl/thread.h> +#include <com/sun/star/sdbc/ResultSetConcurrency.hpp> +#include <com/sun/star/sdbc/ResultSetType.hpp> +#include <com/sun/star/sdbc/FetchDirection.hpp> +#include <com/sun/star/lang/DisposedException.hpp> +#include <comphelper/sequence.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <comphelper/extract.hxx> +#include <comphelper/types.hxx> +#include "diagnose_ex.h" +#include <algorithm> +#include "resource/common_res.hrc" +#include "connectivity/dbexception.hxx" + +using namespace ::comphelper; + +#define THROW_SQL(x) \ + OTools::ThrowException(m_pConnection,x,m_aStatementHandle,SQL_HANDLE_STMT,*this) + +#if OSL_DEBUG_LEVEL > 1 +#define DEBUG_THROW \ + try \ + { \ + THROW_SQL(nRetCode); \ + } \ + catch(SQLException&) \ + { \ + OSL_ENSURE(0,"Exception in odbc catched"); \ + } +#endif + + + +using namespace connectivity::odbc; +//------------------------------------------------------------------------------ +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::sdbcx; +using namespace com::sun::star::container; +using namespace com::sun::star::io; +using namespace com::sun::star::util; +//------------------------------------------------------------------------------ +OStatement_Base::OStatement_Base(OConnection* _pConnection ) + :OStatement_BASE(m_aMutex) + ,OPropertySetHelper(OStatement_BASE::rBHelper) + ,m_pConnection(_pConnection) + ,m_aStatementHandle(SQL_NULL_HANDLE) + ,m_pRowStatusArray(0) + ,rBHelper(OStatement_BASE::rBHelper) +{ + osl_incrementInterlockedCount( &m_refCount ); + m_pConnection->acquire(); + m_aStatementHandle = m_pConnection->createStatementHandle(); + + //setMaxFieldSize(0); + // Don't do this. By ODBC spec, "0" is the default for the SQL_ATTR_MAX_LENGTH attribute. We once introduced + // this line since an PostgreSQL ODBC driver had a default other than 0. However, current drivers (at least 8.3 + // and later) have a proper default of 0, so there should be no need anymore. + // On the other hand, the NotesSQL driver (IBM's ODBC driver for the Lotus Notes series) wrongly interprets + // "0" as "0", whereas the ODBC spec says it should in fact mean "unlimited". + // So, removing this line seems to be the best option for now. + // If we ever again encounter a ODBC driver which needs this option, then we should introduce a data source + // setting for it, instead of unconditionally doing it. + + osl_decrementInterlockedCount( &m_refCount ); +} +// ----------------------------------------------------------------------------- +OStatement_Base::~OStatement_Base() +{ + OSL_ENSURE(!m_aStatementHandle,"Sohould ne null here!"); +} +//------------------------------------------------------------------------------ +void OStatement_Base::disposeResultSet() +{ + // free the cursor if alive + Reference< XComponent > xComp(m_xResultSet.get(), UNO_QUERY); + if (xComp.is()) + xComp->dispose(); + m_xResultSet = Reference< XResultSet>(); +} +// ----------------------------------------------------------------------------- +void SAL_CALL OStatement_Base::disposing(void) +{ + ::osl::MutexGuard aGuard(m_aMutex); + + disposeResultSet(); + ::comphelper::disposeComponent(m_xGeneratedStatement); + + OSL_ENSURE(m_aStatementHandle,"OStatement_BASE2::disposing: StatementHandle is null!"); + if (m_pConnection) + { + m_pConnection->freeStatementHandle(m_aStatementHandle); + m_pConnection->release(); + m_pConnection = NULL; + } + OSL_ENSURE(!m_aStatementHandle,"Sohould ne null here!"); + + OStatement_BASE::disposing(); +} +//------------------------------------------------------------------------------ +void OStatement_BASE2::disposing() +{ + ::osl::MutexGuard aGuard(m_aMutex); + + dispose_ChildImpl(); + OStatement_Base::disposing(); +} +//----------------------------------------------------------------------------- +void SAL_CALL OStatement_BASE2::release() throw() +{ + relase_ChildImpl(); +} +//----------------------------------------------------------------------------- +Any SAL_CALL OStatement_Base::queryInterface( const Type & rType ) throw(RuntimeException) +{ + if ( m_pConnection && !m_pConnection->isAutoRetrievingEnabled() && rType == ::getCppuType( (const Reference< XGeneratedResultSet > *)0 ) ) + return Any(); + Any aRet = OStatement_BASE::queryInterface(rType); + return aRet.hasValue() ? aRet : OPropertySetHelper::queryInterface(rType); +} +// ------------------------------------------------------------------------- +Sequence< Type > SAL_CALL OStatement_Base::getTypes( ) throw(RuntimeException) +{ + ::cppu::OTypeCollection aTypes( ::getCppuType( (const Reference< XMultiPropertySet > *)0 ), + ::getCppuType( (const Reference< XFastPropertySet > *)0 ), + ::getCppuType( (const Reference< XPropertySet > *)0 )); + Sequence< Type > aOldTypes = OStatement_BASE::getTypes(); + if ( m_pConnection && !m_pConnection->isAutoRetrievingEnabled() ) + { + ::std::remove(aOldTypes.getArray(),aOldTypes.getArray() + aOldTypes.getLength(), + ::getCppuType( (const Reference< XGeneratedResultSet > *)0 )); + aOldTypes.realloc(aOldTypes.getLength() - 1); + } + + return ::comphelper::concatSequences(aTypes.getTypes(),aOldTypes); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL OStatement_Base::getGeneratedValues( ) throw (SQLException, RuntimeException) +{ + OSL_ENSURE( m_pConnection && m_pConnection->isAutoRetrievingEnabled(),"Illegal call here. isAutoRetrievingEnabled is false!"); + Reference< XResultSet > xRes; + if ( m_pConnection ) + { + ::rtl::OUString sStmt = m_pConnection->getTransformedGeneratedStatement(m_sSqlStatement); + if ( sStmt.getLength() ) + { + ::comphelper::disposeComponent(m_xGeneratedStatement); + m_xGeneratedStatement = m_pConnection->createStatement(); + xRes = m_xGeneratedStatement->executeQuery(sStmt); + } + } + return xRes; +} +// ----------------------------------------------------------------------------- +void SAL_CALL OStatement_Base::cancel( ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + OTools::ThrowException(m_pConnection,N3SQLCancel(m_aStatementHandle),m_aStatementHandle,SQL_HANDLE_STMT,*this); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OStatement_Base::close( ) throw(SQLException, RuntimeException) +{ + { + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + } + dispose(); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OStatement::clearBatch( ) throw(SQLException, RuntimeException) +{ + +} +// ------------------------------------------------------------------------- + +void OStatement_Base::reset() throw (SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + + clearWarnings (); + + if (m_xResultSet.get().is()) + { + clearMyResultSet(); + } + if(m_aStatementHandle) + { + THROW_SQL(N3SQLFreeStmt(m_aStatementHandle, SQL_CLOSE)); + } +} +//-------------------------------------------------------------------- +// clearMyResultSet +// If a ResultSet was created for this Statement, close it +//-------------------------------------------------------------------- + +void OStatement_Base::clearMyResultSet () throw (SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + try + { + Reference<XCloseable> xCloseable; + if ( ::comphelper::query_interface( m_xResultSet.get(), xCloseable ) ) + xCloseable->close(); + } + catch( const DisposedException& ) { } + + m_xResultSet = Reference< XResultSet >(); +} +//-------------------------------------------------------------------- +SQLLEN OStatement_Base::getRowCount () throw( SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + + SQLLEN numRows = 0; + + try { + THROW_SQL(N3SQLRowCount(m_aStatementHandle,&numRows)); + } + catch (SQLException&) + { + } + return numRows; +} +//-------------------------------------------------------------------- +// lockIfNecessary +// If the given SQL statement contains a 'FOR UPDATE' clause, change +// the concurrency to lock so that the row can then be updated. Returns +// true if the concurrency has been changed +//-------------------------------------------------------------------- + +sal_Bool OStatement_Base::lockIfNecessary (const ::rtl::OUString& sql) throw( SQLException) +{ + sal_Bool rc = sal_False; + + // First, convert the statement to upper case + + ::rtl::OUString sqlStatement = sql.toAsciiUpperCase (); + + // Now, look for the FOR UPDATE keywords. If there is any extra white + // space between the FOR and UPDATE, this will fail. + + sal_Int32 index = sqlStatement.indexOf(::rtl::OUString::createFromAscii(" FOR UPDATE")); + + // We found it. Change our concurrency level to ensure that the + // row can be updated. + + if (index > 0) + { + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + try + { + SQLINTEGER nLock = SQL_CONCUR_LOCK; + THROW_SQL(N3SQLSetStmtAttr(m_aStatementHandle, SQL_CONCURRENCY,(SQLPOINTER)nLock,SQL_IS_UINTEGER)); + } + catch (SQLWarning& warn) + { + // Catch any warnings and place on the warning stack + setWarning (warn); + } + rc = sal_True; + } + + return rc; +} +//-------------------------------------------------------------------- +// setWarning +// Sets the warning +//-------------------------------------------------------------------- + +void OStatement_Base::setWarning (const SQLWarning &ex) throw( SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + + m_aLastWarning = ex; +} + +//-------------------------------------------------------------------- +// getColumnCount +// Return the number of columns in the ResultSet +//-------------------------------------------------------------------- + +sal_Int32 OStatement_Base::getColumnCount () throw( SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + + sal_Int16 numCols = 0; + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + + try { + THROW_SQL(N3SQLNumResultCols(m_aStatementHandle,&numCols)); + } + catch (SQLException&) + { + } + return numCols; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OStatement_Base::execute( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + m_sSqlStatement = sql; + + + ::rtl::OString aSql(::rtl::OUStringToOString(sql,getOwnConnection()->getTextEncoding())); + + sal_Bool hasResultSet = sal_False; + SQLWarning aWarning; + + // Reset the statement handle and warning + + reset(); + + // Check for a 'FOR UPDATE' statement. If present, change + // the concurrency to lock + + lockIfNecessary (sql); + + // Call SQLExecDirect + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + + try { + THROW_SQL(N3SQLExecDirect(m_aStatementHandle, (SDB_ODBC_CHAR*)aSql.getStr(),aSql.getLength())); + } + catch (SQLWarning& ex) { + + // Save pointer to warning and save with ResultSet + // object once it is created. + + aWarning = ex; + } + + // Now determine if there is a result set associated with + // the SQL statement that was executed. Get the column + // count, and if it is not zero, there is a result set. + + if (getColumnCount () > 0) + { + hasResultSet = sal_True; + } + + return hasResultSet; +} +//-------------------------------------------------------------------- +// getResultSet +// getResultSet returns the current result as a ResultSet. It +// returns NULL if the current result is not a ResultSet. +//-------------------------------------------------------------------- +Reference< XResultSet > OStatement_Base::getResultSet (sal_Bool checkCount) throw( SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + + if (m_xResultSet.get().is()) // if resultset already retrieved, + { + // throw exception to avoid sequence error + ::dbtools::throwFunctionSequenceException(*this,Any()); + } + + OResultSet* pRs = NULL; + sal_Int32 numCols = 1; + + // If we already know we have result columns, checkCount + // is false. This is an optimization to prevent unneeded + // calls to getColumnCount + + if (checkCount) + numCols = getColumnCount (); + + // Only return a result set if there are result columns + + if (numCols > 0) + { + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + pRs = createResulSet(); + pRs->construct(); + + // Save a copy of our last result set + // Changed to save copy at getResultSet. + //m_xResultSet = rs; + } + else + clearMyResultSet (); + + return pRs; +} +//-------------------------------------------------------------------- +// getStmtOption +// Invoke SQLGetStmtOption with the given option. +//-------------------------------------------------------------------- + +sal_Int32 OStatement_Base::getStmtOption (short fOption) const +{ + sal_Int32 result = 0; + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + N3SQLGetStmtAttr(m_aStatementHandle, fOption,&result,SQL_IS_INTEGER,NULL); + return result; +} +// ------------------------------------------------------------------------- + +Reference< XResultSet > SAL_CALL OStatement_Base::executeQuery( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + + Reference< XResultSet > xRS = NULL; + + // Execute the statement. If execute returns true, a result + // set exists. + + if (execute (sql)) + { + xRS = getResultSet (sal_False); + m_xResultSet = xRS; + } + else + { + // No ResultSet was produced. Raise an exception + m_pConnection->throwGenericSQLException(STR_NO_RESULTSET,*this); + } + return xRS; +} +// ------------------------------------------------------------------------- + +Reference< XConnection > SAL_CALL OStatement_Base::getConnection( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + return (Reference< XConnection >)m_pConnection; +} +// ------------------------------------------------------------------------- + +Any SAL_CALL OStatement::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = ::cppu::queryInterface(rType,static_cast< XBatchExecution*> (this)); + return aRet.hasValue() ? aRet : OStatement_Base::queryInterface(rType); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OStatement::addBatch( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + + m_aBatchList.push_back(sql); +} +// ------------------------------------------------------------------------- +Sequence< sal_Int32 > SAL_CALL OStatement::executeBatch( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + + ::rtl::OString aBatchSql; + sal_Int32 nLen = 0; + for(::std::list< ::rtl::OUString>::const_iterator i=m_aBatchList.begin();i != m_aBatchList.end();++i,++nLen) + { + aBatchSql += ::rtl::OUStringToOString(*i,getOwnConnection()->getTextEncoding()); + aBatchSql += ";"; + } + + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + THROW_SQL(N3SQLExecDirect(m_aStatementHandle, (SDB_ODBC_CHAR*)aBatchSql.getStr(),aBatchSql.getLength())); + + Sequence< sal_Int32 > aRet(nLen); + sal_Int32* pArray = aRet.getArray(); + for(sal_Int32 j=0;j<nLen;++j) + { + SQLRETURN nError = N3SQLMoreResults(m_aStatementHandle); + if(nError == SQL_SUCCESS) + { + SQLLEN nRowCount=0; + N3SQLRowCount(m_aStatementHandle,&nRowCount); + pArray[j] = nRowCount; + } + } + return aRet; +} +// ------------------------------------------------------------------------- + + +sal_Int32 SAL_CALL OStatement_Base::executeUpdate( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + + sal_Int32 numRows = -1; + + // Execute the statement. If execute returns false, a + // row count exists. + + if (!execute (sql)) { + numRows = getUpdateCount(); + } + else { + + // No update count was produced (a ResultSet was). Raise + // an exception + + ::connectivity::SharedResources aResources; + const ::rtl::OUString sError( aResources.getResourceString(STR_NO_ROWCOUNT)); + throw SQLException (sError, *this,::rtl::OUString(),0,Any()); + } + return numRows; + +} +// ------------------------------------------------------------------------- + +Reference< XResultSet > SAL_CALL OStatement_Base::getResultSet( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + + m_xResultSet = getResultSet(sal_True); + return m_xResultSet; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OStatement_Base::getUpdateCount( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + + sal_Int32 rowCount = -1; + + // Only return a row count for SQL statements that did not + // return a result set. + + if (getColumnCount () == 0) + rowCount = getRowCount (); + + return rowCount; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OStatement_Base::getMoreResults( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + + SQLWarning warning; + sal_Bool hasResultSet = sal_False; + + // clear previous warnings + + clearWarnings (); + + // Call SQLMoreResults + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + + try { + hasResultSet = N3SQLMoreResults(m_aStatementHandle) == SQL_SUCCESS; + } + catch (SQLWarning &ex) { + + // Save pointer to warning and save with ResultSet + // object once it is created. + + warning = ex; + } + + // There are more results (it may not be a result set, though) + + if (hasResultSet) + { + + // Now determine if there is a result set associated + // with the SQL statement that was executed. Get the + // column count, and if it is zero, there is not a + // result set. + + if (getColumnCount () == 0) + hasResultSet = sal_False; + } + + // Set the warning for the statement, if one was generated + + setWarning (warning); + + // Return the result set indicator + + return hasResultSet; +} +// ------------------------------------------------------------------------- + +// ------------------------------------------------------------------------- +Any SAL_CALL OStatement_Base::getWarnings( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + + return makeAny(m_aLastWarning); +} +// ------------------------------------------------------------------------- + +// ------------------------------------------------------------------------- +void SAL_CALL OStatement_Base::clearWarnings( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + + m_aLastWarning = SQLWarning(); +} +// ------------------------------------------------------------------------- +//------------------------------------------------------------------------------ +sal_Int32 OStatement_Base::getQueryTimeOut() const +{ + return getStmtOption(SQL_ATTR_QUERY_TIMEOUT); +} +//------------------------------------------------------------------------------ +sal_Int32 OStatement_Base::getMaxRows() const +{ + return getStmtOption(SQL_ATTR_MAX_ROWS); +} +//------------------------------------------------------------------------------ +sal_Int32 OStatement_Base::getResultSetConcurrency() const +{ + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + sal_uInt32 nValue; + SQLRETURN nRetCode = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CONCURRENCY,&nValue,SQL_IS_UINTEGER,0); + OSL_UNUSED( nRetCode ); + if(nValue == SQL_CONCUR_READ_ONLY) + nValue = ResultSetConcurrency::READ_ONLY; + else + nValue = ResultSetConcurrency::UPDATABLE; + return nValue; +} +//------------------------------------------------------------------------------ +sal_Int32 OStatement_Base::getResultSetType() const +{ + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + sal_uInt32 nValue = SQL_CURSOR_FORWARD_ONLY; + SQLRETURN nRetCode = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_SENSITIVITY,&nValue,SQL_IS_UINTEGER,0); + nRetCode = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,&nValue,SQL_IS_UINTEGER,0); + switch(nValue) + { + case SQL_CURSOR_FORWARD_ONLY: + nValue = ResultSetType::FORWARD_ONLY; + break; + case SQL_CURSOR_KEYSET_DRIVEN: + case SQL_CURSOR_STATIC: + nValue = ResultSetType::SCROLL_INSENSITIVE; + break; + case SQL_CURSOR_DYNAMIC: + nValue = ResultSetType::SCROLL_SENSITIVE; + break; + } + + return nValue; +} +//------------------------------------------------------------------------------ +sal_Int32 OStatement_Base::getFetchDirection() const +{ + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + sal_uInt32 nValue = 0; + SQLRETURN nRetCode = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_SCROLLABLE,&nValue,SQL_IS_UINTEGER,0); + OSL_UNUSED( nRetCode ); + + switch(nValue) + { + case SQL_SCROLLABLE: + nValue = FetchDirection::REVERSE; + break; + default: + nValue = FetchDirection::FORWARD; + break; + } + + return nValue; +} +//------------------------------------------------------------------------------ +sal_Int32 OStatement_Base::getFetchSize() const +{ + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + sal_uInt32 nValue; + SQLRETURN nRetCode = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE,&nValue,SQL_IS_UINTEGER,0); + OSL_UNUSED( nRetCode ); + return nValue; +} +//------------------------------------------------------------------------------ +sal_Int32 OStatement_Base::getMaxFieldSize() const +{ + return getStmtOption(SQL_ATTR_MAX_LENGTH); +} +//------------------------------------------------------------------------------ +::rtl::OUString OStatement_Base::getCursorName() const +{ + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + SQLCHAR pName[258]; + SQLSMALLINT nRealLen = 0; + SQLRETURN nRetCode = N3SQLGetCursorName(m_aStatementHandle,(SQLCHAR*)pName,256,&nRealLen); + OSL_UNUSED( nRetCode ); + return ::rtl::OUString::createFromAscii((const char*)pName); +} +//------------------------------------------------------------------------------ +void OStatement_Base::setQueryTimeOut(sal_Int32 seconds) +{ + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + SQLRETURN nRetCode = N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_QUERY_TIMEOUT,(SQLPOINTER)seconds,SQL_IS_UINTEGER); + OSL_UNUSED( nRetCode ); +} +//------------------------------------------------------------------------------ +void OStatement_Base::setMaxRows(sal_Int32 _par0) +{ + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + SQLRETURN nRetCode = N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_MAX_ROWS, (SQLPOINTER)_par0,SQL_IS_UINTEGER); + OSL_UNUSED( nRetCode ); +} +//------------------------------------------------------------------------------ +void OStatement_Base::setResultSetConcurrency(sal_Int32 _par0) +{ + SQLINTEGER nSet; + if(_par0 == ResultSetConcurrency::READ_ONLY) + nSet = SQL_CONCUR_READ_ONLY; + else + nSet = SQL_CONCUR_VALUES; + + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CONCURRENCY,(SQLPOINTER)nSet,SQL_IS_UINTEGER); + +} +//------------------------------------------------------------------------------ +void OStatement_Base::setResultSetType(sal_Int32 _par0) +{ + + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + SQLRETURN nRetCode = N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_ROW_BIND_TYPE,(SQLPOINTER)SQL_BIND_BY_COLUMN,SQL_IS_UINTEGER); + OSL_UNUSED( nRetCode ); + + sal_Bool bUseBookmark = isUsingBookmarks(); + SQLUINTEGER nSet( SQL_UNSPECIFIED ); + switch(_par0) + { + case ResultSetType::FORWARD_ONLY: + nSet = SQL_UNSPECIFIED; + break; + case ResultSetType::SCROLL_INSENSITIVE: + nSet = SQL_INSENSITIVE; + N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CURSOR_TYPE,(SQLPOINTER)SQL_CURSOR_KEYSET_DRIVEN,SQL_IS_UINTEGER); + break; + case ResultSetType::SCROLL_SENSITIVE: + if(bUseBookmark) + { + SQLUINTEGER nCurProp = getCursorProperties(SQL_CURSOR_DYNAMIC,sal_True); + if((nCurProp & SQL_CA1_BOOKMARK) != SQL_CA1_BOOKMARK) // check if bookmark for this type isn't supported + { // we have to test the next one + nCurProp = getCursorProperties(SQL_CURSOR_KEYSET_DRIVEN,sal_True); + sal_Bool bNotBookmarks = ((nCurProp & SQL_CA1_BOOKMARK) != SQL_CA1_BOOKMARK); + nCurProp = getCursorProperties(SQL_CURSOR_KEYSET_DRIVEN,sal_False); + nSet = SQL_CURSOR_KEYSET_DRIVEN; + if( bNotBookmarks || + ((nCurProp & SQL_CA2_SENSITIVITY_DELETIONS) != SQL_CA2_SENSITIVITY_DELETIONS) || + ((nCurProp & SQL_CA2_SENSITIVITY_ADDITIONS) != SQL_CA2_SENSITIVITY_ADDITIONS)) + { + // bookmarks for keyset isn't supported so reset bookmark setting + setUsingBookmarks(sal_False); + nSet = SQL_CURSOR_DYNAMIC; + } + } + else + nSet = SQL_CURSOR_DYNAMIC; + } + else + nSet = SQL_CURSOR_DYNAMIC; + if(N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CURSOR_TYPE,(SQLPOINTER)nSet,SQL_IS_UINTEGER) != SQL_SUCCESS) + { + nSet = SQL_CURSOR_KEYSET_DRIVEN; + N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CURSOR_TYPE,(SQLPOINTER)nSet,SQL_IS_UINTEGER); + } + nSet = SQL_SENSITIVE; + break; + default: + OSL_ENSURE( false, "OStatement_Base::setResultSetType: invalid result set type!" ); + break; + } + + + N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CURSOR_SENSITIVITY,(SQLPOINTER)nSet,SQL_IS_UINTEGER); +} +//------------------------------------------------------------------------------ +void OStatement_Base::setEscapeProcessing( const sal_Bool _bEscapeProc ) +{ + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + SQLUINTEGER nEscapeProc( _bEscapeProc ? SQL_NOSCAN_OFF : SQL_NOSCAN_ON ); + SQLRETURN nRetCode = N3SQLSetStmtAttr( m_aStatementHandle, SQL_ATTR_NOSCAN, (SQLPOINTER)nEscapeProc, SQL_IS_UINTEGER ); + (void)nRetCode; +} + +//------------------------------------------------------------------------------ +void OStatement_Base::setFetchDirection(sal_Int32 _par0) +{ + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + sal_Int32 nCursType = 0; + SQLRETURN nRetCode = SQL_SUCCESS; + if(_par0 == FetchDirection::FORWARD) + { + nCursType = SQL_NONSCROLLABLE; + nRetCode = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_SCROLLABLE,(SQLPOINTER)nCursType,SQL_IS_UINTEGER); + } + else if(_par0 == FetchDirection::REVERSE) + { + nCursType = SQL_SCROLLABLE; + nRetCode = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_SCROLLABLE,(SQLPOINTER)nCursType,SQL_IS_UINTEGER); + } + OSL_UNUSED( nRetCode ); +} +//------------------------------------------------------------------------------ +void OStatement_Base::setFetchSize(sal_Int32 _par0) +{ + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + + SQLRETURN nRetCode = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE,(SQLPOINTER)_par0,SQL_IS_UINTEGER); + + delete m_pRowStatusArray; + m_pRowStatusArray = new SQLUSMALLINT[_par0]; + nRetCode = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_STATUS_PTR,m_pRowStatusArray,SQL_IS_POINTER); +} +//------------------------------------------------------------------------------ +void OStatement_Base::setMaxFieldSize(sal_Int32 _par0) +{ + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_MAX_LENGTH,(SQLPOINTER)_par0,SQL_IS_UINTEGER); +} +//------------------------------------------------------------------------------ +void OStatement_Base::setCursorName(const ::rtl::OUString &_par0) +{ + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + ::rtl::OString aName(::rtl::OUStringToOString(_par0,getOwnConnection()->getTextEncoding())); + N3SQLSetCursorName(m_aStatementHandle,(SDB_ODBC_CHAR*)aName.getStr(),(SQLSMALLINT)aName.getLength()); +} +// ------------------------------------------------------------------------- +sal_Bool OStatement_Base::isUsingBookmarks() const +{ + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + sal_uInt32 nValue = SQL_UB_OFF; + SQLRETURN nRetCode = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_USE_BOOKMARKS,&nValue,SQL_IS_UINTEGER,NULL); + OSL_UNUSED( nRetCode ); + return nValue != SQL_UB_OFF; +} +// ------------------------------------------------------------------------- +sal_Bool OStatement_Base::getEscapeProcessing() const +{ + OSL_ENSURE( m_aStatementHandle, "StatementHandle is null!" ); + sal_uInt32 nValue = SQL_NOSCAN_OFF; + SQLRETURN nRetCode = N3SQLGetStmtAttr( m_aStatementHandle, SQL_ATTR_NOSCAN, &nValue, SQL_IS_UINTEGER, NULL ); + (void)nRetCode; + return nValue == SQL_NOSCAN_OFF; +} +// ------------------------------------------------------------------------- +void OStatement_Base::setUsingBookmarks(sal_Bool _bUseBookmark) +{ + OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); + sal_uInt32 nValue = _bUseBookmark ? SQL_UB_VARIABLE : SQL_UB_OFF; + SQLRETURN nRetCode = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_USE_BOOKMARKS,(SQLPOINTER)nValue,SQL_IS_UINTEGER); + OSL_UNUSED( nRetCode ); +} +// ------------------------------------------------------------------------- +::cppu::IPropertyArrayHelper* OStatement_Base::createArrayHelper( ) const +{ + Sequence< Property > aProps(10); + Property* pProperties = aProps.getArray(); + sal_Int32 nPos = 0; + DECL_PROP0(CURSORNAME, ::rtl::OUString); + DECL_BOOL_PROP0(ESCAPEPROCESSING); + DECL_PROP0(FETCHDIRECTION,sal_Int32); + DECL_PROP0(FETCHSIZE, sal_Int32); + DECL_PROP0(MAXFIELDSIZE,sal_Int32); + DECL_PROP0(MAXROWS, sal_Int32); + DECL_PROP0(QUERYTIMEOUT,sal_Int32); + DECL_PROP0(RESULTSETCONCURRENCY,sal_Int32); + DECL_PROP0(RESULTSETTYPE,sal_Int32); + DECL_BOOL_PROP0(USEBOOKMARKS); + + return new ::cppu::OPropertyArrayHelper(aProps); +} + +// ------------------------------------------------------------------------- +::cppu::IPropertyArrayHelper & OStatement_Base::getInfoHelper() +{ + return *const_cast<OStatement_Base*>(this)->getArrayHelper(); +} +// ------------------------------------------------------------------------- +sal_Bool OStatement_Base::convertFastPropertyValue( + Any & rConvertedValue, + Any & rOldValue, + sal_Int32 nHandle, + const Any& rValue ) + throw (::com::sun::star::lang::IllegalArgumentException) +{ + sal_Bool bConverted = sal_False; + try + { + switch(nHandle) + { + case PROPERTY_ID_QUERYTIMEOUT: + bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getQueryTimeOut()); + break; + + case PROPERTY_ID_MAXFIELDSIZE: + bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxFieldSize()); + break; + + case PROPERTY_ID_MAXROWS: + bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxRows()); + break; + + case PROPERTY_ID_CURSORNAME: + bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getCursorName()); + break; + + case PROPERTY_ID_RESULTSETCONCURRENCY: + bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetConcurrency()); + break; + + case PROPERTY_ID_RESULTSETTYPE: + bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetType()); + break; + + case PROPERTY_ID_FETCHDIRECTION: + bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection()); + break; + + case PROPERTY_ID_FETCHSIZE: + bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize()); + break; + + case PROPERTY_ID_USEBOOKMARKS: + bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, isUsingBookmarks()); + break; + + case PROPERTY_ID_ESCAPEPROCESSING: + bConverted = ::comphelper::tryPropertyValue( rConvertedValue, rOldValue, rValue, getEscapeProcessing() ); + break; + + } + } + catch(const SQLException&) + { + // throw Exception(e.Message,*this); + } + return bConverted; +} +// ------------------------------------------------------------------------- +void OStatement_Base::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception) +{ + try + { + switch(nHandle) + { + case PROPERTY_ID_QUERYTIMEOUT: + setQueryTimeOut(comphelper::getINT32(rValue)); + break; + case PROPERTY_ID_MAXFIELDSIZE: + setMaxFieldSize(comphelper::getINT32(rValue)); + break; + case PROPERTY_ID_MAXROWS: + setMaxRows(comphelper::getINT32(rValue)); + break; + case PROPERTY_ID_CURSORNAME: + setCursorName(comphelper::getString(rValue)); + break; + case PROPERTY_ID_RESULTSETCONCURRENCY: + setResultSetConcurrency(comphelper::getINT32(rValue)); + break; + case PROPERTY_ID_RESULTSETTYPE: + setResultSetType(comphelper::getINT32(rValue)); + break; + case PROPERTY_ID_FETCHDIRECTION: + setFetchDirection(comphelper::getINT32(rValue)); + break; + case PROPERTY_ID_FETCHSIZE: + setFetchSize(comphelper::getINT32(rValue)); + break; + case PROPERTY_ID_USEBOOKMARKS: + setUsingBookmarks(comphelper::getBOOL(rValue)); + break; + case PROPERTY_ID_ESCAPEPROCESSING: + setEscapeProcessing( ::comphelper::getBOOL( rValue ) ); + break; + default: + OSL_ENSURE( false, "OStatement_Base::setFastPropertyValue_NoBroadcast: what property?" ); + break; + } + } + catch(const SQLException& ) + { + // throw Exception(e.Message,*this); + } +} +// ------------------------------------------------------------------------- +void OStatement_Base::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const +{ + switch(nHandle) + { + case PROPERTY_ID_QUERYTIMEOUT: + rValue <<= getQueryTimeOut(); + break; + case PROPERTY_ID_MAXFIELDSIZE: + rValue <<= getMaxFieldSize(); + break; + case PROPERTY_ID_MAXROWS: + rValue <<= getMaxRows(); + break; + case PROPERTY_ID_CURSORNAME: + rValue <<= getCursorName(); + break; + case PROPERTY_ID_RESULTSETCONCURRENCY: + rValue <<= getResultSetConcurrency(); + break; + case PROPERTY_ID_RESULTSETTYPE: + rValue <<= getResultSetType(); + break; + case PROPERTY_ID_FETCHDIRECTION: + rValue <<= getFetchDirection(); + break; + case PROPERTY_ID_FETCHSIZE: + rValue <<= getFetchSize(); + break; + case PROPERTY_ID_USEBOOKMARKS: + rValue <<= isUsingBookmarks(); + break; + case PROPERTY_ID_ESCAPEPROCESSING: + rValue <<= getEscapeProcessing(); + break; + default: + OSL_ENSURE( false, "OStatement_Base::getFastPropertyValue: what property?" ); + break; + } +} +// ------------------------------------------------------------------------- +IMPLEMENT_SERVICE_INFO(OStatement,"com.sun.star.sdbcx.OStatement","com.sun.star.sdbc.Statement"); +// ----------------------------------------------------------------------------- +void SAL_CALL OStatement_Base::acquire() throw() +{ + OStatement_BASE::acquire(); +} +// ----------------------------------------------------------------------------- +void SAL_CALL OStatement_Base::release() throw() +{ + OStatement_BASE::release(); +} +// ----------------------------------------------------------------------------- +void SAL_CALL OStatement::acquire() throw() +{ + OStatement_BASE2::acquire(); +} +// ----------------------------------------------------------------------------- +void SAL_CALL OStatement::release() throw() +{ + OStatement_BASE2::release(); +} +// ----------------------------------------------------------------------------- +OResultSet* OStatement_Base::createResulSet() +{ + return new OResultSet(m_aStatementHandle,this); +} +// ----------------------------------------------------------------------------- +Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OStatement_Base::getPropertySetInfo( ) throw(RuntimeException) +{ + return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); +} +// ----------------------------------------------------------------------------- +SQLUINTEGER OStatement_Base::getCursorProperties(SQLINTEGER _nCursorType,sal_Bool bFirst) +{ + SQLUINTEGER nValueLen = 0; + try + { + SQLUSMALLINT nAskFor = SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2; + if(SQL_CURSOR_KEYSET_DRIVEN == _nCursorType) + nAskFor = bFirst ? SQL_KEYSET_CURSOR_ATTRIBUTES1 : SQL_KEYSET_CURSOR_ATTRIBUTES2; + else if(SQL_CURSOR_STATIC == _nCursorType) + nAskFor = bFirst ? SQL_STATIC_CURSOR_ATTRIBUTES1 : SQL_STATIC_CURSOR_ATTRIBUTES2; + else if(SQL_CURSOR_FORWARD_ONLY == _nCursorType) + nAskFor = bFirst ? SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES1 : SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2; + else if(SQL_CURSOR_DYNAMIC == _nCursorType) + nAskFor = bFirst ? SQL_DYNAMIC_CURSOR_ATTRIBUTES1 : SQL_DYNAMIC_CURSOR_ATTRIBUTES2; + + + OTools::GetInfo(getOwnConnection(),getConnectionHandle(),nAskFor,nValueLen,NULL); + } + catch(Exception&) + { // we don't want our result destroy here + nValueLen = 0; + } + return nValueLen; +} +// ----------------------------------------------------------------------------- diff --git a/connectivity/source/drivers/odbcbase/OTools.cxx b/connectivity/source/drivers/odbcbase/OTools.cxx new file mode 100644 index 000000000000..d598de8bc12d --- /dev/null +++ b/connectivity/source/drivers/odbcbase/OTools.cxx @@ -0,0 +1,946 @@ +/************************************************************************ + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "odbc/OTools.hxx" +#include "odbc/OFunctions.hxx" +#include <com/sun/star/sdbc/DataType.hpp> +#include <osl/diagnose.h> +#include "odbc/OConnection.hxx" +#include "diagnose_ex.h" +#include <rtl/logfile.hxx> +#include <rtl/ustrbuf.hxx> + + +#include <string.h> +#include <string> +#include <algorithm> + +using namespace connectivity::odbc; +using namespace com::sun::star::uno; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::util; + +void OTools::getValue( OConnection* _pConnection, + SQLHANDLE _aStatementHandle, + sal_Int32 columnIndex, + SQLSMALLINT _nType, + sal_Bool &_bWasNull, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface, + void* _pValue, + SQLLEN _nSize) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::getValue" ); + SQLLEN pcbValue = SQL_NULL_DATA; + OTools::ThrowException(_pConnection, + (*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(_aStatementHandle, + (SQLUSMALLINT)columnIndex, + _nType, + _pValue, + _nSize, + &pcbValue), + _aStatementHandle,SQL_HANDLE_STMT,_xInterface,sal_False); + _bWasNull = pcbValue == SQL_NULL_DATA; +} +// ----------------------------------------------------------------------------- +void OTools::bindParameter( OConnection* _pConnection, + SQLHANDLE _hStmt, + sal_Int32 nPos, + sal_Int8*& pDataBuffer, + sal_Int8* pLenBuffer, + SQLSMALLINT _nODBCtype, + sal_Bool _bUseWChar, + sal_Bool _bUseOldTimeDate, + const void* _pValue, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface, + rtl_TextEncoding _nTextEncoding) + throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::bindParameter" ); + SQLRETURN nRetcode; + SQLSMALLINT fSqlType; + SQLSMALLINT fCType; + SQLLEN nMaxLen = 0; + // void*& pData = pDataBuffer; + SQLLEN* pLen = (SQLLEN*)pLenBuffer; + SQLULEN nColumnSize=0; + SQLSMALLINT nDecimalDigits=0; + + OTools::getBindTypes(_bUseWChar,_bUseOldTimeDate,_nODBCtype,fCType,fSqlType); + + OTools::bindData(_nODBCtype,_bUseWChar,pDataBuffer,pLen,_pValue,_nTextEncoding,nColumnSize); + if ((nColumnSize == 0) && (fSqlType == SQL_CHAR || fSqlType == SQL_VARCHAR || fSqlType == SQL_LONGVARCHAR)) + nColumnSize = 1; + + if(fSqlType == SQL_LONGVARCHAR || fSqlType == SQL_LONGVARBINARY) + memcpy(pDataBuffer,&nPos,sizeof(nPos)); + + // 20.09.2001 OJ: Problems with mysql. mysql returns only CHAR as parameter type + // nRetcode = (*(T3SQLDescribeParam)_pConnection->getOdbcFunction(ODBC3SQLDescribeParam))(_hStmt,(SQLUSMALLINT)nPos,&fSqlType,&nColumnSize,&nDecimalDigits,&nNullable); + + nRetcode = (*(T3SQLBindParameter)_pConnection->getOdbcFunction(ODBC3SQLBindParameter))(_hStmt, + (SQLUSMALLINT)nPos, + SQL_PARAM_INPUT, + fCType, + fSqlType, + nColumnSize, + nDecimalDigits, + pDataBuffer, + nMaxLen, + pLen); + + OTools::ThrowException(_pConnection,nRetcode,_hStmt,SQL_HANDLE_STMT,_xInterface); +} +// ----------------------------------------------------------------------------- +void OTools::bindData( SQLSMALLINT _nOdbcType, + sal_Bool _bUseWChar, + sal_Int8 *&_pData, + SQLLEN*& pLen, + const void* _pValue, + rtl_TextEncoding _nTextEncoding, + SQLULEN& _nColumnSize) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::bindData" ); + _nColumnSize = 0; + + switch (_nOdbcType) + { + case SQL_CHAR: + case SQL_VARCHAR: + case SQL_DECIMAL: + if(_bUseWChar) + { + *pLen = SQL_NTS; + ::rtl::OUString sStr(*(::rtl::OUString*)_pValue); + _nColumnSize = sStr.getLength(); + *((rtl::OUString*)_pData) = sStr; + + // Zeiger auf Char* + _pData = (sal_Int8*)((rtl::OUString*)_pData)->getStr(); + } + else + { + ::rtl::OString aString(::rtl::OUStringToOString(*(::rtl::OUString*)_pValue,_nTextEncoding)); + *pLen = SQL_NTS; + _nColumnSize = aString.getLength(); + memcpy(_pData,aString.getStr(),aString.getLength()); + ((sal_Int8*)_pData)[aString.getLength()] = '\0'; + } + break; + + case SQL_BIGINT: + *((sal_Int64*)_pData) = *(sal_Int64*)_pValue; + *pLen = sizeof(sal_Int64); + _nColumnSize = *pLen; + break; + + case SQL_NUMERIC: + if(_bUseWChar) + { + ::rtl::OUString aString = rtl::OUString::valueOf(*(double*)_pValue); + _nColumnSize = aString.getLength(); + *pLen = _nColumnSize; + *((rtl::OUString*)_pData) = aString; + // Zeiger auf Char* + _pData = (sal_Int8*)((rtl::OUString*)_pData)->getStr(); + } + else + { + ::rtl::OString aString = ::rtl::OString::valueOf(*(double*)_pValue); + _nColumnSize = aString.getLength(); + *pLen = _nColumnSize; + memcpy(_pData,aString.getStr(),aString.getLength()); + ((sal_Int8*)_pData)[_nColumnSize] = '\0'; + } break; + case SQL_BIT: + case SQL_TINYINT: + *((sal_Int8*)_pData) = *(sal_Int8*)_pValue; + *pLen = sizeof(sal_Int8); + break; + + case SQL_SMALLINT: + *((sal_Int16*)_pData) = *(sal_Int16*)_pValue; + *pLen = sizeof(sal_Int16); + break; + case SQL_INTEGER: + *((sal_Int32*)_pData) = *(sal_Int32*)_pValue; + *pLen = sizeof(sal_Int32); + break; + case SQL_FLOAT: + *((float*)_pData) = *(float*)_pValue; + *pLen = sizeof(float); + break; + case SQL_REAL: + case SQL_DOUBLE: + *((double*)_pData) = *(double*)_pValue; + *pLen = sizeof(double); + break; + case SQL_BINARY: + case SQL_VARBINARY: + { + const ::com::sun::star::uno::Sequence< sal_Int8 >* pSeq = static_cast< const ::com::sun::star::uno::Sequence< sal_Int8 >* >(_pValue); + OSL_ENSURE(pSeq,"OTools::bindData: Sequence is null!"); + + if(pSeq) + { + _pData = (sal_Int8*)pSeq->getConstArray(); + *pLen = pSeq->getLength(); + } + } + break; + case SQL_LONGVARBINARY: + { + sal_Int32 nLen = 0; + nLen = ((const ::com::sun::star::uno::Sequence< sal_Int8 > *)_pValue)->getLength(); + *pLen = (SQLLEN)SQL_LEN_DATA_AT_EXEC(nLen); + } + break; + case SQL_LONGVARCHAR: + { + sal_Int32 nLen = 0; + if(_bUseWChar) + nLen = sizeof(sal_Unicode) * ((::rtl::OUString*)_pValue)->getLength(); + else + { + ::rtl::OString aString(::rtl::OUStringToOString(*(::rtl::OUString*)_pValue,_nTextEncoding)); + nLen = aString.getLength(); + } + *pLen = (SQLLEN)SQL_LEN_DATA_AT_EXEC(nLen); + } break; + case SQL_DATE: + *(DATE_STRUCT*)_pData = *(DATE_STRUCT*)_pValue; + *pLen = (SQLLEN)sizeof(DATE_STRUCT); + _nColumnSize = 10; + break; + case SQL_TIME: + *(TIME_STRUCT*)_pData = *(TIME_STRUCT*)_pValue; + *pLen = (SQLLEN)sizeof(TIME_STRUCT); + _nColumnSize = 8; + break; + case SQL_TIMESTAMP: + *(TIMESTAMP_STRUCT*)_pData = *(TIMESTAMP_STRUCT*)_pValue; + *pLen = (SQLLEN)sizeof(TIMESTAMP_STRUCT); + _nColumnSize = 19; + break; + } +} +// ------------------------------------------------------------------------- +void OTools::bindValue( OConnection* _pConnection, + SQLHANDLE _aStatementHandle, + sal_Int32 columnIndex, + SQLSMALLINT _nType, + SQLSMALLINT _nMaxLen, + const void* _pValue, + void* _pData, + SQLLEN *pLen, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface, + rtl_TextEncoding _nTextEncoding, + sal_Bool _bUseOldTimeDate) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::bindValue" ); + SQLRETURN nRetcode; + SQLSMALLINT fSqlType; + SQLSMALLINT fCType; + SQLLEN nMaxLen = _nMaxLen; + + OTools::getBindTypes( sal_False, + _bUseOldTimeDate, + _nType, + fCType, + fSqlType); + + if (columnIndex != 0 && !_pValue) + { + *pLen = SQL_NULL_DATA; + nRetcode = (*(T3SQLBindCol)_pConnection->getOdbcFunction(ODBC3SQLBindCol))(_aStatementHandle, + (SQLUSMALLINT)columnIndex, + fCType, + _pData, + nMaxLen, + pLen + ); + } + else + { + try + { + switch (_nType) + { + case SQL_CHAR: + case SQL_VARCHAR: + //if(GetODBCConnection()->m_bUserWChar) +// { +// _nMaxLen = rCol.GetPrecision(); +// *pLen = SQL_NTS; +// *((rtl::OUString*)pData) = (rtl::OUString)_aValue; +// +// // Zeiger auf Char* +// pData = (void*)((rtl::OUString*)pData)->getStr(); +// } +// else + { + ::rtl::OString aString(::rtl::OUStringToOString(*(::rtl::OUString*)_pValue,_nTextEncoding)); + *pLen = SQL_NTS; + *((::rtl::OString*)_pData) = aString; + _nMaxLen = (SQLSMALLINT)aString.getLength(); + + // Zeiger auf Char* + _pData = (void*)aString.getStr(); + } break; + case SQL_BIGINT: + *((sal_Int64*)_pData) = *(sal_Int64*)_pValue; + *pLen = sizeof(sal_Int64); + break; + case SQL_DECIMAL: + case SQL_NUMERIC: + //if(GetODBCConnection()->m_bUserWChar) +// { +// rtl::OUString aString(rtl::OUString(SdbTools::ToString(ODbTypeConversion::toDouble(*pVariable),rCol.GetScale()))); +// *pLen = _nMaxLen; +// *((rtl::OUString*)_pData) = aString; +// // Zeiger auf Char* +// _pData = (void*)((rtl::OUString*)_pData)->getStr(); +// } +// else + { + ::rtl::OString aString = ::rtl::OString::valueOf(*(double*)_pValue); + _nMaxLen = (SQLSMALLINT)aString.getLength(); + *pLen = _nMaxLen; + *((::rtl::OString*)_pData) = aString; + // Zeiger auf Char* + _pData = (void*)((::rtl::OString*)_pData)->getStr(); + } break; + case SQL_BIT: + case SQL_TINYINT: + *((sal_Int8*)_pData) = *(sal_Int8*)_pValue; + *pLen = sizeof(sal_Int8); + break; + + case SQL_SMALLINT: + *((sal_Int16*)_pData) = *(sal_Int16*)_pValue; + *pLen = sizeof(sal_Int16); + break; + case SQL_INTEGER: + *((sal_Int32*)_pData) = *(sal_Int32*)_pValue; + *pLen = sizeof(sal_Int32); + break; + case SQL_FLOAT: + *((float*)_pData) = *(float*)_pValue; + *pLen = sizeof(float); + break; + case SQL_REAL: + case SQL_DOUBLE: + *((double*)_pData) = *(double*)_pValue; + *pLen = sizeof(double); + break; + case SQL_BINARY: + case SQL_VARBINARY: + // if (_pValue == ::getCppuType((const ::com::sun::star::uno::Sequence< sal_Int8 > *)0)) + { + _pData = (void*)((const ::com::sun::star::uno::Sequence< sal_Int8 > *)_pValue)->getConstArray(); + *pLen = ((const ::com::sun::star::uno::Sequence< sal_Int8 > *)_pValue)->getLength(); + } break; + case SQL_LONGVARBINARY: + { + _pData = (void*)(columnIndex); + sal_Int32 nLen = 0; + nLen = ((const ::com::sun::star::uno::Sequence< sal_Int8 > *)_pValue)->getLength(); + *pLen = (SQLLEN)SQL_LEN_DATA_AT_EXEC(nLen); + } + break; + case SQL_LONGVARCHAR: + { + _pData = (void*)(columnIndex); + sal_Int32 nLen = 0; + nLen = ((::rtl::OUString*)_pValue)->getLength(); + *pLen = (SQLLEN)SQL_LEN_DATA_AT_EXEC(nLen); + } break; + case SQL_DATE: + *pLen = sizeof(DATE_STRUCT); + *((DATE_STRUCT*)_pData) = *(DATE_STRUCT*)_pValue; + break; + case SQL_TIME: + *pLen = sizeof(TIME_STRUCT); + *((TIME_STRUCT*)_pData) = *(TIME_STRUCT*)_pValue; + break; + case SQL_TIMESTAMP: + *pLen = sizeof(TIMESTAMP_STRUCT); + *((TIMESTAMP_STRUCT*)_pData) = *(TIMESTAMP_STRUCT*)_pValue; + break; + } + } + catch ( ... ) + { + } + + nRetcode = (*(T3SQLBindCol)_pConnection->getOdbcFunction(ODBC3SQLBindCol))(_aStatementHandle, + (SQLUSMALLINT)columnIndex, + fCType, + _pData, + nMaxLen, + pLen + ); + } + + OTools::ThrowException(_pConnection,nRetcode,_aStatementHandle,SQL_HANDLE_STMT,_xInterface); +} +// ----------------------------------------------------------------------------- +void OTools::ThrowException(OConnection* _pConnection, + SQLRETURN _rRetCode, + SQLHANDLE _pContext, + SQLSMALLINT _nHandleType, + const Reference< XInterface >& _xInterface, + sal_Bool _bNoFound, + rtl_TextEncoding _nTextEncoding) throw(SQLException) +{ + switch(_rRetCode) + { + case SQL_NEED_DATA: + case SQL_STILL_EXECUTING: + case SQL_SUCCESS: + + case SQL_SUCCESS_WITH_INFO: + return; + case SQL_NO_DATA_FOUND: + if(_bNoFound) + return; // no need to throw a exception + case SQL_ERROR: break; + + + case SQL_INVALID_HANDLE: OSL_ENSURE(0,"SdbODBC3_SetStatus: SQL_INVALID_HANDLE"); + throw SQLException(); + } + + + // Zusaetliche Informationen zum letzten ODBC-Funktionsaufruf vorhanden. + // SQLError liefert diese Informationen. + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::ThrowException" ); + + SDB_ODBC_CHAR szSqlState[5]; + SQLINTEGER pfNativeError; + SDB_ODBC_CHAR szErrorMessage[SQL_MAX_MESSAGE_LENGTH]; + szErrorMessage[0] = '\0'; + SQLSMALLINT pcbErrorMsg = 0; + + // Informationen zur letzten Operation: + // wenn hstmt != SQL_NULL_HSTMT ist (Benutzung von SetStatus in SdbCursor, SdbTable, ...), + // dann wird der Status des letzten Statements erfragt, sonst der Status des letzten + // Statements zu dieser Verbindung [was in unserem Fall wahrscheinlich gleichbedeutend ist, + // aber das Reference Manual drueckt sich da nicht so klar aus ...]. + // Entsprechend bei hdbc. + SQLRETURN n = (*(T3SQLGetDiagRec)_pConnection->getOdbcFunction(ODBC3SQLGetDiagRec))(_nHandleType,_pContext,1, + szSqlState, + &pfNativeError, + szErrorMessage,sizeof szErrorMessage - 1,&pcbErrorMsg); + OSL_UNUSED( n ); + OSL_ENSURE(n != SQL_INVALID_HANDLE,"SdbODBC3_SetStatus: SQLError returned SQL_INVALID_HANDLE"); + OSL_ENSURE(n == SQL_SUCCESS || n == SQL_SUCCESS_WITH_INFO || n == SQL_NO_DATA_FOUND || n == SQL_ERROR,"SdbODBC3_SetStatus: SQLError failed"); + + // Zum Return Code von SQLError siehe ODBC 2.0 Programmer's Reference Seite 287ff + throw SQLException( ::rtl::OUString((char *)szErrorMessage,pcbErrorMsg,_nTextEncoding), + _xInterface, + ::rtl::OUString((char *)szSqlState,5,_nTextEncoding), + pfNativeError, + Any() + ); + +} +// ------------------------------------------------------------------------- +Sequence<sal_Int8> OTools::getBytesValue(OConnection* _pConnection, + SQLHANDLE _aStatementHandle, + sal_Int32 columnIndex, + SQLSMALLINT _fSqlType, + sal_Bool &_bWasNull, + const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::getBytesValue" ); + char aCharArray[2048]; + // Erstmal versuchen, die Daten mit dem kleinen Puffer + // abzuholen: + SQLLEN nMaxLen = sizeof aCharArray - 1; + // GETDATA(SQL_C_CHAR,aCharArray,nMaxLen); + SQLLEN pcbValue = 0; + OTools::ThrowException(_pConnection,(*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(_aStatementHandle, + (SQLUSMALLINT)columnIndex, + _fSqlType, + (SQLPOINTER)aCharArray, + nMaxLen, + &pcbValue), + _aStatementHandle,SQL_HANDLE_STMT,_xInterface); + + _bWasNull = pcbValue == SQL_NULL_DATA; + if(_bWasNull) + return Sequence<sal_Int8>(); + + SQLINTEGER nBytes = pcbValue != SQL_NO_TOTAL ? std::min(pcbValue, nMaxLen) : nMaxLen; + if ( ((pcbValue == SQL_NO_TOTAL) || pcbValue > nMaxLen) && aCharArray[nBytes-1] == 0 && nBytes > 0 ) + --nBytes; + Sequence<sal_Int8> aData((sal_Int8*)aCharArray, nBytes); + + + // Es handelt sich um Binaerdaten, um einen String, der fuer + // StarView zu lang ist oder der Treiber kann die Laenge der + // Daten nicht im voraus bestimmen - also als MemoryStream + // speichern. + while ((pcbValue == SQL_NO_TOTAL) || pcbValue > nMaxLen) + { + // Bei Strings wird der Puffer nie ganz ausgenutzt + // (das letzte Byte ist immer ein NULL-Byte, das + // aber bei pcbValue nicht mitgezaehlt wird) + if (pcbValue != SQL_NO_TOTAL && (pcbValue - nMaxLen) < nMaxLen) + nBytes = pcbValue - nMaxLen; + else + nBytes = nMaxLen; + + // Solange eine "truncation"-Warnung vorliegt, weiter Daten abholen + // GETDATA(SQL_C_CHAR,aCharArray, nLen + 1); + OTools::ThrowException(_pConnection,(*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(_aStatementHandle, + (SQLUSMALLINT)columnIndex, + SQL_C_BINARY, + &aCharArray, + (SQLINTEGER)nBytes, + &pcbValue), + _aStatementHandle,SQL_HANDLE_STMT,_xInterface); + sal_Int32 nLen = aData.getLength(); + aData.realloc(nLen + nBytes); + memcpy(aData.getArray() + nLen, aCharArray, nBytes); + } + return aData; +} +// ------------------------------------------------------------------------- +::rtl::OUString OTools::getStringValue(OConnection* _pConnection, + SQLHANDLE _aStatementHandle, + sal_Int32 columnIndex, + SQLSMALLINT _fSqlType, + sal_Bool &_bWasNull, + const Reference< XInterface >& _xInterface, + rtl_TextEncoding _nTextEncoding) throw(SQLException, RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::getStringValue" ); + ::rtl::OUStringBuffer aData; + switch(_fSqlType) + { + case SQL_WVARCHAR: + case SQL_WCHAR: + case SQL_WLONGVARCHAR: + { + sal_Unicode waCharArray[2048]; + // read the unicode data + SQLLEN nMaxLen = (sizeof(waCharArray) / sizeof(sal_Unicode)) - 1; + // GETDATA(SQL_C_WCHAR, waCharArray, nMaxLen + sizeof(sal_Unicode)); + + SQLLEN pcbValue=0; + OTools::ThrowException(_pConnection,(*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(_aStatementHandle, + (SQLUSMALLINT)columnIndex, + SQL_C_WCHAR, + &waCharArray, + (SQLLEN)nMaxLen*sizeof(sal_Unicode), + &pcbValue), + _aStatementHandle,SQL_HANDLE_STMT,_xInterface); + _bWasNull = pcbValue == SQL_NULL_DATA; + if(_bWasNull) + return ::rtl::OUString(); + // Bei Fehler bricht der GETDATA-Makro mit return ab, + // bei NULL mit break! + SQLLEN nRealSize = 0; + if ( pcbValue > -1 ) + nRealSize = pcbValue / sizeof(sal_Unicode); + SQLLEN nLen = pcbValue != SQL_NO_TOTAL ? std::min(nRealSize, nMaxLen) : (nMaxLen-1); + waCharArray[nLen] = 0; + aData.append(waCharArray,nLen); + + // Es handelt sich um Binaerdaten, um einen String, der fuer + // StarView zu lang ist oder der Treiber kann die Laenge der + // Daten nicht im voraus bestimmen - also als MemoryStream + // speichern. + while ((pcbValue == SQL_NO_TOTAL ) || nLen > nMaxLen) + { + // Bei Strings wird der Puffer nie ganz ausgenutzt + // (das letzte Byte ist immer ein NULL-Byte, das + // aber bei pcbValue nicht mitgezaehlt wird) + if (pcbValue != SQL_NO_TOTAL && (pcbValue - nMaxLen) < nMaxLen) + nLen = pcbValue - nMaxLen; + else + nLen = nMaxLen; + + // Solange eine "truncation"-Warnung vorliegt, weiter Daten abholen + // GETDATA(SQL_C_CHAR,waCharArray, nLen + 1); + OTools::ThrowException(_pConnection,(*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(_aStatementHandle, + (SQLUSMALLINT)columnIndex, + SQL_C_WCHAR, + &waCharArray, + (SQLLEN)nLen+1, + &pcbValue), + _aStatementHandle,SQL_HANDLE_STMT,_xInterface); + nRealSize = 0; + if ( pcbValue > -1 ) + nRealSize = pcbValue / sizeof(sal_Unicode); + nLen = pcbValue != SQL_NO_TOTAL ? std::min(nRealSize, nMaxLen) : (nMaxLen-1); + waCharArray[nLen] = 0; + + aData.append(::rtl::OUString(waCharArray)); + } + } + break; + default: + { + char aCharArray[2048]; + // Erstmal versuchen, die Daten mit dem kleinen Puffer + // abzuholen: + SQLLEN nMaxLen = sizeof aCharArray - 1; + // GETDATA(SQL_C_CHAR,aCharArray,nMaxLen); + SQLLEN pcbValue = 0; + OTools::ThrowException(_pConnection,(*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(_aStatementHandle, + (SQLUSMALLINT)columnIndex, + SQL_C_CHAR, + &aCharArray, + nMaxLen, + &pcbValue), + _aStatementHandle,SQL_HANDLE_STMT,_xInterface); + _bWasNull = pcbValue == SQL_NULL_DATA; + if(_bWasNull) + return ::rtl::OUString(); + + SQLLEN nLen = pcbValue != SQL_NO_TOTAL ? std::min(pcbValue, nMaxLen) : (nMaxLen-1); + aCharArray[nLen] = 0; + if ( ((pcbValue == SQL_NO_TOTAL) || pcbValue > nMaxLen) && aCharArray[nLen-1] == 0 && nLen > 0 ) + --nLen; + aData.append(::rtl::OUString((const sal_Char*)aCharArray,nLen, _nTextEncoding)); + + // Es handelt sich um Binaerdaten, um einen String, der fuer + // StarView zu lang ist oder der Treiber kann die Laenge der + // Daten nicht im voraus bestimmen - also als MemoryStream + // speichern. + while ((pcbValue == SQL_NO_TOTAL) || pcbValue > nMaxLen) + { + // Solange eine "truncation"-Warnung vorliegt, weiter Daten abholen + // GETDATA(SQL_C_CHAR,aCharArray, nLen + 1); + OTools::ThrowException(_pConnection,(*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(_aStatementHandle, + (SQLUSMALLINT)columnIndex, + SQL_C_CHAR, + &aCharArray, + (SQLINTEGER)nMaxLen, + &pcbValue), + _aStatementHandle,SQL_HANDLE_STMT,_xInterface); + nLen = pcbValue != SQL_NO_TOTAL ? std::min(pcbValue, nMaxLen) : (nMaxLen-1); + if ( ((pcbValue == SQL_NO_TOTAL) || pcbValue > nMaxLen) && aCharArray[nLen-1] == 0 && nLen > 0 ) + --nLen; + aCharArray[nLen] = 0; + + aData.append(::rtl::OUString((const sal_Char*)aCharArray,nLen,_nTextEncoding)); + } + + // delete all blanks + // aData.EraseTrailingChars(); + } + } + + return aData.makeStringAndClear(); +} +// ------------------------------------------------------------------------- +void OTools::GetInfo(OConnection* _pConnection, + SQLHANDLE _aConnectionHandle, + SQLUSMALLINT _nInfo, + ::rtl::OUString &_rValue, + const Reference< XInterface >& _xInterface, + rtl_TextEncoding _nTextEncoding) throw(SQLException, RuntimeException) +{ + char aValue[512]; + SQLSMALLINT nValueLen=0; + OTools::ThrowException(_pConnection, + (*(T3SQLGetInfo)_pConnection->getOdbcFunction(ODBC3SQLGetInfo))(_aConnectionHandle,_nInfo,aValue,(sizeof aValue)-1,&nValueLen), + _aConnectionHandle,SQL_HANDLE_DBC,_xInterface); + + _rValue = ::rtl::OUString(aValue,nValueLen,_nTextEncoding); +} +// ------------------------------------------------------------------------- +void OTools::GetInfo(OConnection* _pConnection, + SQLHANDLE _aConnectionHandle, + SQLUSMALLINT _nInfo, + sal_Int32 &_rValue, + const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException) +{ + SQLSMALLINT nValueLen; + _rValue = 0; // in case the driver uses only 16 of the 32 bits (as it does, for example, for SQL_CATALOG_LOCATION) + OTools::ThrowException(_pConnection, + (*(T3SQLGetInfo)_pConnection->getOdbcFunction(ODBC3SQLGetInfo))(_aConnectionHandle,_nInfo,&_rValue,sizeof _rValue,&nValueLen), + _aConnectionHandle,SQL_HANDLE_DBC,_xInterface); +} +// ------------------------------------------------------------------------- +void OTools::GetInfo(OConnection* _pConnection, + SQLHANDLE _aConnectionHandle, + SQLUSMALLINT _nInfo, + SQLUINTEGER &_rValue, + const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException) +{ + SQLSMALLINT nValueLen; + _rValue = 0; // in case the driver uses only 16 of the 32 bits (as it does, for example, for SQL_CATALOG_LOCATION) + OTools::ThrowException(_pConnection, + (*(T3SQLGetInfo)_pConnection->getOdbcFunction(ODBC3SQLGetInfo))(_aConnectionHandle,_nInfo,&_rValue,sizeof _rValue,&nValueLen), + _aConnectionHandle,SQL_HANDLE_DBC,_xInterface); +} +// ------------------------------------------------------------------------- +void OTools::GetInfo(OConnection* _pConnection, + SQLHANDLE _aConnectionHandle, + SQLUSMALLINT _nInfo, + SQLUSMALLINT &_rValue, + const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException) +{ + SQLSMALLINT nValueLen; + _rValue = 0; // in case the driver uses only 16 of the 32 bits (as it does, for example, for SQL_CATALOG_LOCATION) + OTools::ThrowException(_pConnection, + (*(T3SQLGetInfo)_pConnection->getOdbcFunction(ODBC3SQLGetInfo))(_aConnectionHandle,_nInfo,&_rValue,sizeof _rValue,&nValueLen), + _aConnectionHandle,SQL_HANDLE_DBC,_xInterface); +} +// ------------------------------------------------------------------------- +void OTools::GetInfo(OConnection* _pConnection, + SQLHANDLE _aConnectionHandle, + SQLUSMALLINT _nInfo, + sal_Bool &_rValue, + const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException) +{ + SQLSMALLINT nValueLen; + OTools::ThrowException(_pConnection, + (*(T3SQLGetInfo)_pConnection->getOdbcFunction(ODBC3SQLGetInfo))(_aConnectionHandle,_nInfo,&_rValue,sizeof _rValue,&nValueLen), + _aConnectionHandle,SQL_HANDLE_DBC,_xInterface); +} +// ------------------------------------------------------------------------- +sal_Int32 OTools::MapOdbcType2Jdbc(sal_Int32 _nType) +{ + sal_Int32 nValue = DataType::VARCHAR; + switch(_nType) + { + case SQL_BIT: + nValue = DataType::BIT; + break; + case SQL_TINYINT: + nValue = DataType::TINYINT; + break; + case SQL_SMALLINT: + nValue = DataType::SMALLINT; + break; + case SQL_INTEGER: + nValue = DataType::INTEGER; + break; + case SQL_BIGINT: + nValue = DataType::BIGINT; + break; + case SQL_FLOAT: + nValue = DataType::FLOAT; + break; + case SQL_REAL: + nValue = DataType::REAL; + break; + case SQL_DOUBLE: + nValue = DataType::DOUBLE; + break; + case SQL_NUMERIC: + nValue = DataType::NUMERIC; + break; + case SQL_DECIMAL: + nValue = DataType::DECIMAL; + break; + case SQL_WCHAR: + case SQL_CHAR: + nValue = DataType::CHAR; + break; + case SQL_WVARCHAR: + case SQL_VARCHAR: + nValue = DataType::VARCHAR; + break; + case SQL_WLONGVARCHAR: + case SQL_LONGVARCHAR: + nValue = DataType::LONGVARCHAR; + break; + case SQL_TYPE_DATE: + case SQL_DATE: + nValue = DataType::DATE; + break; + case SQL_TYPE_TIME: + case SQL_TIME: + nValue = DataType::TIME; + break; + case SQL_TYPE_TIMESTAMP: + case SQL_TIMESTAMP: + nValue = DataType::TIMESTAMP; + break; + case SQL_BINARY: + nValue = DataType::BINARY; + break; + case SQL_VARBINARY: + case SQL_GUID: + nValue = DataType::VARBINARY; + break; + case SQL_LONGVARBINARY: + nValue = DataType::LONGVARBINARY; + break; + default: + OSL_ASSERT(!"Invalid type"); + } + return nValue; +} +//-------------------------------------------------------------------- +// jdbcTypeToOdbc +// Convert the JDBC SQL type to the correct ODBC type +//-------------------------------------------------------------------- +sal_Int32 OTools::jdbcTypeToOdbc(sal_Int32 jdbcType) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::jdbcTypeToOdbc" ); + // For the most part, JDBC types match ODBC types. We'll + // just convert the ones that we know are different + + sal_Int32 odbcType = jdbcType; + + switch (jdbcType) + { + case DataType::DATE: + odbcType = SQL_DATE; + break; + case DataType::TIME: + odbcType = SQL_TIME; + break; + case DataType::TIMESTAMP: + odbcType = SQL_TIMESTAMP; + break; + } + + return odbcType; +} +//----------------------------------------------------------------------------- +void OTools::getBindTypes(sal_Bool _bUseWChar, + sal_Bool _bUseOldTimeDate, + SQLSMALLINT _nOdbcType, + SQLSMALLINT& fCType, + SQLSMALLINT& fSqlType + ) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::getBindTypes" ); + switch(_nOdbcType) + { + case SQL_CHAR: if(_bUseWChar) + { + fCType = SQL_C_WCHAR; + fSqlType = SQL_WCHAR; + } + else + { + fCType = SQL_C_CHAR; + fSqlType = SQL_CHAR; + } + break; + case SQL_VARCHAR: if(_bUseWChar) + { + fCType = SQL_C_WCHAR; + fSqlType = SQL_WVARCHAR; + } + else + { + fCType = SQL_C_CHAR; + fSqlType = SQL_VARCHAR; + } + break; + case SQL_LONGVARCHAR: if(_bUseWChar) + { + fCType = SQL_C_WCHAR; + fSqlType = SQL_WLONGVARCHAR; + } + else + { + fCType = SQL_C_CHAR; + fSqlType = SQL_LONGVARCHAR; + } + break; + case SQL_DECIMAL: fCType = _bUseWChar ? SQL_C_WCHAR : SQL_C_CHAR; + fSqlType = SQL_DECIMAL; break; + case SQL_NUMERIC: fCType = _bUseWChar ? SQL_C_WCHAR : SQL_C_CHAR; + fSqlType = SQL_NUMERIC; break; + case SQL_BIT: fCType = SQL_C_TINYINT; + fSqlType = SQL_INTEGER; break; + case SQL_TINYINT: fCType = SQL_C_TINYINT; + fSqlType = SQL_TINYINT; break; + case SQL_SMALLINT: fCType = SQL_C_SHORT; + fSqlType = SQL_SMALLINT; break; + case SQL_INTEGER: fCType = SQL_C_LONG; + fSqlType = SQL_INTEGER; break; + case SQL_BIGINT: fCType = SQL_C_SBIGINT; + fSqlType = SQL_BIGINT; break; + case SQL_FLOAT: fCType = SQL_C_FLOAT; + fSqlType = SQL_FLOAT; break; + case SQL_REAL: fCType = SQL_C_DOUBLE; + fSqlType = SQL_REAL; break; + case SQL_DOUBLE: fCType = SQL_C_DOUBLE; + fSqlType = SQL_DOUBLE; break; + case SQL_BINARY: fCType = SQL_C_BINARY; + fSqlType = SQL_BINARY; break; + case SQL_VARBINARY: + fCType = SQL_C_BINARY; + fSqlType = SQL_VARBINARY; break; + case SQL_LONGVARBINARY: fCType = SQL_C_BINARY; + fSqlType = SQL_LONGVARBINARY; break; + case SQL_DATE: + if(_bUseOldTimeDate) + { + fCType = SQL_C_DATE; + fSqlType = SQL_DATE; + } + else + { + fCType = SQL_C_TYPE_DATE; + fSqlType = SQL_TYPE_DATE; + } + break; + case SQL_TIME: + if(_bUseOldTimeDate) + { + fCType = SQL_C_TIME; + fSqlType = SQL_TIME; + } + else + { + fCType = SQL_C_TYPE_TIME; + fSqlType = SQL_TYPE_TIME; + } + break; + case SQL_TIMESTAMP: + if(_bUseOldTimeDate) + { + fCType = SQL_C_TIMESTAMP; + fSqlType = SQL_TIMESTAMP; + } + else + { + fCType = SQL_C_TYPE_TIMESTAMP; + fSqlType = SQL_TYPE_TIMESTAMP; + } + break; + default: fCType = SQL_C_BINARY; + fSqlType = SQL_LONGVARBINARY; break; + } +} + + diff --git a/connectivity/source/drivers/odbcbase/makefile.mk b/connectivity/source/drivers/odbcbase/makefile.mk new file mode 100644 index 000000000000..798517c8f948 --- /dev/null +++ b/connectivity/source/drivers/odbcbase/makefile.mk @@ -0,0 +1,90 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. +PRJINC=..$/.. +PRJNAME=connectivity +TARGET=odbcbase + +ENABLE_EXCEPTIONS=TRUE +VISIBILITY_HIDDEN=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/version.mk + +CDEFS += -DOOO_DLLIMPLEMENTATION_ODBCBASE + +.IF "$(SYSTEM_ODBC_HEADERS)" == "YES" +CFLAGS+=-DSYSTEM_ODBC_HEADERS +.ENDIF + +# --- Files ------------------------------------- + +SLOFILES=\ + $(SLO)$/OPreparedStatement.obj \ + $(SLO)$/OStatement.obj \ + $(SLO)$/OResultSetMetaData.obj \ + $(SLO)$/OResultSet.obj \ + $(SLO)$/OTools.obj \ + $(SLO)$/ODatabaseMetaDataResultSet.obj \ + $(SLO)$/ODatabaseMetaData.obj \ + $(SLO)$/ODriver.obj \ + $(SLO)$/OConnection.obj + +# --- ODBC BASE Library ----------------------------------- + +SHL1TARGET= $(ODBC2_TARGET)$(DLLPOSTFIX) +SHL1OBJS=$(SLOFILES) +SHL1STDLIBS=\ + $(DBTOOLSLIB) \ + $(COMPHELPERLIB) \ + $(CPPUHELPERLIB) \ + $(CPPULIB) \ + $(VOSLIB) \ + $(SALLIB) + +SHL1DEPN= +SHL1IMPLIB= i$(ODBC2_TARGET) +SHL1USE_EXPORTS=name + +SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME= $(SHL1TARGET) +DEF1DEPN= $(MISC)$/$(SHL1TARGET).flt \ + $(SLB)$/$(TARGET).lib +DEFLIB1NAME=$(TARGET) + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + +# --- filter file ------------------------------ + +$(MISC)$/$(SHL1TARGET).flt: makefile.mk + @echo CLEAR_THE_FILE > $@ |