From 8c204276a438c718bd2eed6c59189dcfb24032be Mon Sep 17 00:00:00 2001 From: "Andrzej J.R. Hunt" Date: Mon, 9 Sep 2013 08:48:56 +0100 Subject: Cleanup findColumn. (firebird-sdbc) Change-Id: I0458892d9688a8618789652caf67251a61cc63aa Reviewed-on: https://gerrit.libreoffice.org/5884 Reviewed-by: Andrzej J.R. Hunt Tested-by: Andrzej J.R. Hunt --- connectivity/source/drivers/firebird/ResultSet.cxx | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'connectivity/source') diff --git a/connectivity/source/drivers/firebird/ResultSet.cxx b/connectivity/source/drivers/firebird/ResultSet.cxx index a33460ba23a4..113ba5f5b0e9 100644 --- a/connectivity/source/drivers/firebird/ResultSet.cxx +++ b/connectivity/source/drivers/firebird/ResultSet.cxx @@ -311,7 +311,7 @@ Any SAL_CALL OResultSet::queryInterface( const Type & rType ) throw(RuntimeExcep return concatSequences(OPropertySetHelper::getTypes(), OResultSet_BASE::getTypes()); } // ---- XColumnLocate --------------------------------------------------------- -sal_Int32 SAL_CALL OResultSet::findColumn(const OUString& columnName) +sal_Int32 SAL_CALL OResultSet::findColumn(const OUString& rColumnName) throw(SQLException, RuntimeException) { MutexGuard aGuard(m_pConnection->getMutex()); @@ -325,15 +325,19 @@ sal_Int32 SAL_CALL OResultSet::findColumn(const OUString& columnName) { // We assume case sensitive, otherwise you'd have to test // xMeta->isCaseSensitive and use qualsIgnoreAsciiCase as needed. - if (columnName == xMeta->getColumnName(i)) - break; + if (rColumnName == xMeta->getColumnName(i)) + return i; } - // TODO: add appropriate error - if (i > nLen) - throw SQLException(); - - return i; + // The API documentation (XRowLocate) doesn't specify what should happen + // if the column name isn't found. The JDBC api specifies that an SQLException + // should be thrown. Most drivers return either -1 (some don't check for this + // case and just return nLen), however the JDBC specification seems more + // correct (in the case of the JDBC/HSQLDB drivers the SQLException is + // just propagated from the JDBC call, hence should be expected by any + // SDBC user too). + ::dbtools::throwSQLException("Invalid column name", SQL_COLUMN_NOT_FOUND, *this); + return -1; // Never reached } // ------------------------------------------------------------------------- uno::Reference< XInputStream > SAL_CALL OResultSet::getBinaryStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) -- cgit