connectivity/source/drivers/firebird/FResultSet.cxx | 218 ++++++-------------- connectivity/source/drivers/firebird/FResultSet.hxx | 31 +- connectivity/source/drivers/firebird/FStatement.cxx | 2 3 files changed, 90 insertions(+), 161 deletions(-)
New commits: commit 92750635f260175ae5e37eabfbe29974b29623e7 Author: Andrzej J.R. Hunt <andr...@ahunt.org> Date: Thu Jul 18 18:04:42 2013 +0200 Use ORowSetValue (FValue) for storage in FResultSet. Change-Id: I39b1f5ddf81a7e4cc881b17bf0567aadcbcb0d52 diff --git a/connectivity/source/drivers/firebird/FResultSet.cxx b/connectivity/source/drivers/firebird/FResultSet.cxx index 48bf0ab..7331913 100644 --- a/connectivity/source/drivers/firebird/FResultSet.cxx +++ b/connectivity/source/drivers/firebird/FResultSet.cxx @@ -48,6 +48,7 @@ #include <com/sun/star/sdbcx/CompareBookmark.hpp> using namespace ::comphelper; +using namespace ::connectivity; using namespace ::connectivity::firebird; using namespace ::cppu; using namespace ::osl; @@ -109,38 +110,38 @@ void OResultSet::ensureDataAvailable() throw (SQLException) { m_rowCount++; - TRow aRow(m_fieldCount); + m_sqlData.emplace_back(m_fieldCount); + TRow& rRow = m_sqlData.back(); + XSQLVAR* pVar = m_pSqlda->sqlvar; for (int i = 0; i < m_fieldCount; pVar++, i++) { -// if ((pVar->sqltype & 1) == 0) // Cannot contain NULL -// { -// } -// else // Can contain NULL -// { -// } -// switch (pVar->sqltype) -// { -// } - if ( pVar->sqltype == SQL_SHORT || - pVar->sqltype == SQL_SHORT + 1 || - pVar->sqltype == SQL_LONG || - pVar->sqltype == SQL_LONG + 1 || - pVar->sqltype == SQL_INT64 || - pVar->sqltype == SQL_INT64 + 1) + if ((pVar->sqltype & 1) == 0) // Means: Cannot contain NULL + { + // TODO: test for null here and set as appropriate + } + else // Means: Can contain NULL { - aRow[i] = OString::valueOf((sal_Int16) *pVar->sqldata); - fprintf(stderr, "N_" ); - // TODO: sqlscale here. + // otherwise we need to test for SQL_TYPE and SQL_TYPE+1 below + pVar->sqltype--; } - else + switch (pVar->sqltype) { - // For now store as string - aRow[i] = OString(pVar->sqldata, pVar->sqllen); + case SQL_SHORT: + rRow[i] = (sal_Int16) *pVar->sqldata; + break; + case SQL_LONG: + rRow[i] = (sal_Int32) *pVar->sqldata; + break; + case SQL_INT64: + rRow[i] = (sal_Int64) *pVar->sqldata; + break; + // TODO: remember sqlscale for decimal types + default: + rRow[i] = OUString(pVar->sqldata, pVar->sqllen, RTL_TEXTENCODING_UTF8); + break; } } - m_sqlData.push_back(aRow); - fprintf( stderr, "\n" ); } ISC_STATUS aErr = isc_dsql_free_statement(m_statusVector, @@ -162,7 +163,7 @@ void OResultSet::ensureDataAvailable() throw (SQLException) } } -const OString& OResultSet::getSqlData(sal_Int32 aRow, sal_Int32 aColumn) +const ORowSetValueDecorator& OResultSet::getSqlData(sal_Int32 aRow, sal_Int32 aColumn) throw(SQLException) { // Validate input (throws Exceptions as appropriate) @@ -457,114 +458,87 @@ uno::Reference< XInputStream > SAL_CALL OResultSet::getCharacterStream( sal_Int3 return NULL; } -sal_Bool SAL_CALL OResultSet::getBoolean(sal_Int32 columnIndex) - throw(SQLException, RuntimeException) +// ---- Simple Numerical types ----------------------------------------------- +const ORowSetValue& OResultSet::safelyRetrieveValue(sal_Int32 columnIndex) + throw(SQLException) { - MutexGuard aGuard( m_aMutex ); + MutexGuard aGuard(m_aMutex); checkDisposed(OResultSet_BASE::rBHelper.bDisposed); ensureDataAvailable(); - const OString& aData = getSqlData(m_currentRow,columnIndex); - - if(aData.getLength()) - { - switch(aData[0]) - { - case '1': - case 't': - case 'T': - case 'y': - case 'Y': - return sal_True; - } - } - return sal_False; + return getSqlData(m_currentRow,columnIndex).getValue(); } -// ------------------------------------------------------------------------- -sal_Int8 SAL_CALL OResultSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +sal_Bool SAL_CALL OResultSet::getBoolean(sal_Int32 columnIndex) + throw(SQLException, RuntimeException) { - (void) columnIndex; - MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - ensureDataAvailable(); - - - sal_Int8 nRet = 0; - return nRet; + return safelyRetrieveValue(columnIndex); } -// ------------------------------------------------------------------------- -Sequence< sal_Int8 > SAL_CALL OResultSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +sal_Int8 SAL_CALL OResultSet::getByte( sal_Int32 columnIndex ) + throw(SQLException, RuntimeException) { - (void) columnIndex; - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - ensureDataAvailable(); - MutexGuard aGuard( m_aMutex ); - - return Sequence< sal_Int8 >(); + return safelyRetrieveValue(columnIndex); } -// ------------------------------------------------------------------------- -Date SAL_CALL OResultSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +Sequence< sal_Int8 > SAL_CALL OResultSet::getBytes(sal_Int32 columnIndex) + throw(SQLException, RuntimeException) { - (void) columnIndex; - MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - ensureDataAvailable(); - + return safelyRetrieveValue(columnIndex); +} - Date nRet; - return nRet; +sal_Int16 SAL_CALL OResultSet::getShort(sal_Int32 columnIndex) + throw(SQLException, RuntimeException) +{ + return safelyRetrieveValue(columnIndex); } -double SAL_CALL OResultSet::getDouble(sal_Int32 columnIndex) +sal_Int32 SAL_CALL OResultSet::getInt(sal_Int32 columnIndex) throw(SQLException, RuntimeException) { - (void) columnIndex; - MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - ensureDataAvailable(); + return safelyRetrieveValue(columnIndex); +} - const OString& aData = getSqlData(m_currentRow,columnIndex); - return aData.toDouble(); +sal_Int64 SAL_CALL OResultSet::getLong(sal_Int32 columnIndex) + throw(SQLException, RuntimeException) +{ + return safelyRetrieveValue(columnIndex); } float SAL_CALL OResultSet::getFloat(sal_Int32 columnIndex) throw(SQLException, RuntimeException) { - MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - ensureDataAvailable(); + return safelyRetrieveValue(columnIndex); +} - const OString& aData = getSqlData(m_currentRow,columnIndex); - return aData.toFloat(); +double SAL_CALL OResultSet::getDouble(sal_Int32 columnIndex) + throw(SQLException, RuntimeException) +{ + return safelyRetrieveValue(columnIndex); } -sal_Int32 SAL_CALL OResultSet::getInt(sal_Int32 columnIndex) +// ---- More complex types --------------------------------------------------- +OUString SAL_CALL OResultSet::getString(sal_Int32 columnIndex) throw(SQLException, RuntimeException) { - MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - ensureDataAvailable(); + return safelyRetrieveValue(columnIndex); +} - // TODO: check in the sqlda somehow? - const OString& aData = getSqlData(m_currentRow,columnIndex); - return aData.toInt32(); +Time SAL_CALL OResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + return safelyRetrieveValue(columnIndex); } -sal_Int64 SAL_CALL OResultSet::getLong(sal_Int32 columnIndex) - throw(SQLException, RuntimeException) +DateTime SAL_CALL OResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { - MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - ensureDataAvailable(); + return safelyRetrieveValue(columnIndex); +} - const OString& aData = getSqlData(m_currentRow,columnIndex); - return aData.toInt64(); +Date SAL_CALL OResultSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + return safelyRetrieveValue(columnIndex); } // ------------------------------------------------------------------------- - uno::Reference< XResultSetMetaData > SAL_CALL OResultSet::getMetaData( ) throw(SQLException, RuntimeException) { MutexGuard aGuard( m_aMutex ); @@ -632,57 +606,7 @@ Any SAL_CALL OResultSet::getObject( sal_Int32 columnIndex, const uno::Reference< return Any(); } -sal_Int16 SAL_CALL OResultSet::getShort(sal_Int32 columnIndex) - throw(SQLException, RuntimeException) -{ - MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - ensureDataAvailable(); - - const OString& aData = getSqlData(m_currentRow,columnIndex); - return aData.toInt32(); -} - -OUString SAL_CALL OResultSet::getString(sal_Int32 columnIndex) - throw(SQLException, RuntimeException) -{ - MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - ensureDataAvailable(); - checkColumnIndex( columnIndex ); - checkRowIndex( sal_True /* must be on row */ ); - - return OStringToOUString(getSqlData(m_currentRow,columnIndex), - RTL_TEXTENCODING_UTF8); -} -// ------------------------------------------------------------------------- - -Time SAL_CALL OResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) -{ - (void) columnIndex; - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - ensureDataAvailable(); - - MutexGuard aGuard( m_aMutex ); - Time nRet; - return nRet; -} -// ------------------------------------------------------------------------- - - -DateTime SAL_CALL OResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) -{ - (void) columnIndex; - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - ensureDataAvailable(); - - - MutexGuard aGuard( m_aMutex ); - - DateTime nRet; - return nRet; -} // ------------------------------------------------------------------------- diff --git a/connectivity/source/drivers/firebird/FResultSet.hxx b/connectivity/source/drivers/firebird/FResultSet.hxx index 3b00fd7..3230186 100644 --- a/connectivity/source/drivers/firebird/FResultSet.hxx +++ b/connectivity/source/drivers/firebird/FResultSet.hxx @@ -36,30 +36,34 @@ #ifndef CONNECTIVITY_SRESULTSET_HXX #define CONNECTIVITY_SRESULTSET_HXX +#include "FStatement.hxx" + +#include <ibase.h> + +#include <connectivity/FValue.hxx> +#include <connectivity/OSubComponent.hxx> +#include <cppuhelper/compbase12.hxx> + +#include <com/sun/star/util/XCancellable.hpp> +#include <com/sun/star/sdbc/XCloseable.hpp> +#include <com/sun/star/sdbc/XColumnLocate.hpp> #include <com/sun/star/sdbc/XResultSet.hpp> #include <com/sun/star/sdbc/XRow.hpp> #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> -#include <com/sun/star/sdbc/XCloseable.hpp> -#include <com/sun/star/sdbc/XColumnLocate.hpp> -#include <com/sun/star/util/XCancellable.hpp> -#include <com/sun/star/sdbc/XWarningsSupplier.hpp> #include <com/sun/star/sdbc/XResultSetUpdate.hpp> #include <com/sun/star/sdbc/XRowUpdate.hpp> -#include <com/sun/star/sdbcx/XRowLocate.hpp> +#include <com/sun/star/sdbc/XWarningsSupplier.hpp> #include <com/sun/star/sdbcx/XDeleteRows.hpp> -#include <cppuhelper/compbase12.hxx> -#include "FStatement.hxx" -#include "connectivity/OSubComponent.hxx" +#include <com/sun/star/sdbcx/XRowLocate.hpp> -#include <ibase.h> namespace connectivity { namespace firebird { - typedef std::vector< ::rtl::OString > TRow; - typedef std::vector< TRow > TTable; + typedef ::std::vector< ::connectivity::ORowSetValueDecorator > TRow; + typedef ::std::vector< TRow > TTable; /* ** OResultSet @@ -101,9 +105,12 @@ namespace connectivity void ensureDataAvailable() throw (::com::sun::star::sdbc::SQLException); - const OString& getSqlData(sal_Int32 aRow, sal_Int32 aColumn) + const ORowSetValueDecorator& getSqlData(sal_Int32 aRow, sal_Int32 aColumn) throw (::com::sun::star::sdbc::SQLException); + const ::connectivity::ORowSetValue& safelyRetrieveValue(sal_Int32 columnIndex) + throw(::com::sun::star::sdbc::SQLException); + // OPropertyArrayUsageHelper virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const; // OPropertySetHelper diff --git a/connectivity/source/drivers/firebird/FStatement.cxx b/connectivity/source/drivers/firebird/FStatement.cxx index 728b9c8..ac14ac6 100644 --- a/connectivity/source/drivers/firebird/FStatement.cxx +++ b/connectivity/source/drivers/firebird/FStatement.cxx @@ -33,8 +33,6 @@ * *************************************************************************/ -#include <stdio.h> - #include "propertyids.hxx" #include "FStatement.hxx" #include "FConnection.hxx" _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits