From 42165189826367937737861116e969a22e9db787 Mon Sep 17 00:00:00 2001 From: "Andrzej J.R. Hunt" Date: Wed, 11 Sep 2013 21:40:41 +0100 Subject: Update implementations of ColumnLocate::findColumn to throw on invalid column. Change-Id: I7a9354ecd35a70a005c6c50e38d27de9b33332bd Reviewed-on: https://gerrit.libreoffice.org/5922 Reviewed-by: Fridrich Strba Tested-by: Fridrich Strba --- .../source/drivers/ado/ADatabaseMetaDataResultSet.cxx | 10 +++++++--- connectivity/source/drivers/ado/AResultSet.cxx | 10 +++++++--- connectivity/source/drivers/evoab2/NResultSet.cxx | 10 +++++++--- connectivity/source/drivers/file/FResultSet.cxx | 12 +++++++----- connectivity/source/drivers/firebird/ResultSet.cxx | 12 +++--------- connectivity/source/drivers/kab/KResultSet.cxx | 13 +++---------- connectivity/source/drivers/macab/MacabResultSet.cxx | 14 +++++--------- connectivity/source/drivers/mork/MResultSet.cxx | 9 ++++++--- connectivity/source/drivers/mozab/MResultSet.cxx | 9 ++++++--- .../source/drivers/odbcbase/ODatabaseMetaDataResultSet.cxx | 10 +++++++--- connectivity/source/drivers/odbcbase/OResultSet.cxx | 10 +++++++--- connectivity/source/drivers/postgresql/pq_resultset.cxx | 7 +++++++ .../source/drivers/postgresql/pq_sequenceresultset.cxx | 10 +++++----- 13 files changed, 77 insertions(+), 59 deletions(-) (limited to 'connectivity/source/drivers') diff --git a/connectivity/source/drivers/ado/ADatabaseMetaDataResultSet.cxx b/connectivity/source/drivers/ado/ADatabaseMetaDataResultSet.cxx index 63ffb198f08a..b1b6dfe47a7c 100644 --- a/connectivity/source/drivers/ado/ADatabaseMetaDataResultSet.cxx +++ b/connectivity/source/drivers/ado/ADatabaseMetaDataResultSet.cxx @@ -125,11 +125,15 @@ sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::findColumn( const OUString& colum 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; - /* FIXME: should throw in case of not found ? */ - return i; + return i; + } + + ::dbtools::throwInvalidColumnException( columnName, *this ); + assert(false); + return 0; // Never reached } #define BLOCK_SIZE 256 // ------------------------------------------------------------------------- diff --git a/connectivity/source/drivers/ado/AResultSet.cxx b/connectivity/source/drivers/ado/AResultSet.cxx index 46bcb2259883..3ae5f788a221 100644 --- a/connectivity/source/drivers/ado/AResultSet.cxx +++ b/connectivity/source/drivers/ado/AResultSet.cxx @@ -163,11 +163,15 @@ sal_Int32 SAL_CALL OResultSet::findColumn( const OUString& columnName ) throw(SQ 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; - /* FIXME: should throw in case of not found ? */ - return i; + return i; + } + + ::dbtools::throwInvalidColumnException( columnName, *this ); + assert(false); + return 0; // Never reached } #define BLOCK_SIZE 256 // ------------------------------------------------------------------------- diff --git a/connectivity/source/drivers/evoab2/NResultSet.cxx b/connectivity/source/drivers/evoab2/NResultSet.cxx index 78021bf3812b..414d90c7f96d 100644 --- a/connectivity/source/drivers/evoab2/NResultSet.cxx +++ b/connectivity/source/drivers/evoab2/NResultSet.cxx @@ -1122,11 +1122,15 @@ sal_Int32 SAL_CALL OEvoabResultSet::findColumn( const OUString& columnName ) thr 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; - /* FXIME ? should trow when not found no? */ - return i; + return i; + } + + ::dbtools::throwInvalidColumnException( columnName, *this ); + assert(false); + return 0; // Never reached } // ------------------------------------------------------------------------- //XColumnLocate interface ends diff --git a/connectivity/source/drivers/file/FResultSet.cxx b/connectivity/source/drivers/file/FResultSet.cxx index 0e71e23898bd..58aa81081b40 100644 --- a/connectivity/source/drivers/file/FResultSet.cxx +++ b/connectivity/source/drivers/file/FResultSet.cxx @@ -212,13 +212,15 @@ sal_Int32 SAL_CALL OResultSet::findColumn( const OUString& columnName ) throw(SQ 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; - /* FIXME ? should this check for non found. iow return i instead of break, and exception - * if we get out of the for loop - */ - return i; + return i; + } + + ::dbtools::throwInvalidColumnException( columnName, *this ); + assert(false); + return 0; // Never reached } // ----------------------------------------------------------------------------- const ORowSetValue& OResultSet::getValue(sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException) diff --git a/connectivity/source/drivers/firebird/ResultSet.cxx b/connectivity/source/drivers/firebird/ResultSet.cxx index cbbd4d58dac9..99051fe423c6 100644 --- a/connectivity/source/drivers/firebird/ResultSet.cxx +++ b/connectivity/source/drivers/firebird/ResultSet.cxx @@ -331,15 +331,9 @@ sal_Int32 SAL_CALL OResultSet::findColumn(const OUString& rColumnName) 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 + ::dbtools::throwInvalidColumnException(rColumnName, *this); + assert(false); + return 0; // Never reached } // ------------------------------------------------------------------------- uno::Reference< XInputStream > SAL_CALL OResultSet::getBinaryStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) diff --git a/connectivity/source/drivers/kab/KResultSet.cxx b/connectivity/source/drivers/kab/KResultSet.cxx index 043fce1f8b74..e797274fc143 100644 --- a/connectivity/source/drivers/kab/KResultSet.cxx +++ b/connectivity/source/drivers/kab/KResultSet.cxx @@ -164,16 +164,9 @@ sal_Int32 SAL_CALL KabResultSet::findColumn(const OUString& columnName) throw(SQ columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i))) return i; - ::connectivity::SharedResources aResources; - const OUString sError( aResources.getResourceStringWithSubstitution( - STR_INVALID_COLUMNNAME, - "$columnname$",columnName - ) ); - ::dbtools::throwGenericSQLException(sError,NULL); - - // Unreachable: - OSL_ASSERT(false); - return 0; + ::dbtools::throwInvalidColumnException( columnName, *this ); + assert(false); + return 0; // Never reached } // ------------------------------------------------------------------------- OUString SAL_CALL KabResultSet::getString(sal_Int32 columnIndex) throw(SQLException, RuntimeException) diff --git a/connectivity/source/drivers/macab/MacabResultSet.cxx b/connectivity/source/drivers/macab/MacabResultSet.cxx index 7a743742c733..c9f866e6b992 100644 --- a/connectivity/source/drivers/macab/MacabResultSet.cxx +++ b/connectivity/source/drivers/macab/MacabResultSet.cxx @@ -185,20 +185,16 @@ sal_Int32 SAL_CALL MacabResultSet::findColumn(const OUString& columnName) throw( sal_Int32 nLen = xMeta->getColumnCount(); for (sal_Int32 i = 1; i <= nLen; ++i) + { if (xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) : columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i))) return i; + } - ::connectivity::SharedResources aResources; - const OUString sError( aResources.getResourceStringWithSubstitution( - STR_NO_ELEMENT_NAME, - "$name$", columnName - ) ); - ::dbtools::throwGenericSQLException(sError , *this); - // Unreachable: - OSL_ASSERT(false); - return 0; + ::dbtools::throwInvalidColumnException( columnName, *this ); + assert(false); + return 0; // Never reached } // ------------------------------------------------------------------------- OUString SAL_CALL MacabResultSet::getString(sal_Int32 columnIndex) throw(SQLException, RuntimeException) diff --git a/connectivity/source/drivers/mork/MResultSet.cxx b/connectivity/source/drivers/mork/MResultSet.cxx index c439d05d5c9d..7561e727a022 100644 --- a/connectivity/source/drivers/mork/MResultSet.cxx +++ b/connectivity/source/drivers/mork/MResultSet.cxx @@ -177,12 +177,15 @@ sal_Int32 SAL_CALL OResultSet::findColumn( const OUString& columnName ) throw(SQ 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; - /* FIXME should throw in case of not found ? or at least return -1 */ + return i; + } - return i; + ::dbtools::throwInvalidColumnException( columnName, *this ); + assert(false); + return 0; // Never reached } // ------------------------------------------------------------------------- Reference< XInputStream > SAL_CALL OResultSet::getBinaryStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException) diff --git a/connectivity/source/drivers/mozab/MResultSet.cxx b/connectivity/source/drivers/mozab/MResultSet.cxx index a26891bdefb2..8c947e25ad2e 100644 --- a/connectivity/source/drivers/mozab/MResultSet.cxx +++ b/connectivity/source/drivers/mozab/MResultSet.cxx @@ -176,12 +176,15 @@ sal_Int32 SAL_CALL OResultSet::findColumn( const OUString& columnName ) throw(SQ 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; - /* FIXME should throw in case of not found ? or at least return -1 */ + return i; + } - return i; + ::dbtools::throwInvalidColumnException( columnName, *this ); + assert(false); + return 0; // Never reached } // ------------------------------------------------------------------------- Reference< XInputStream > SAL_CALL OResultSet::getBinaryStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException) diff --git a/connectivity/source/drivers/odbcbase/ODatabaseMetaDataResultSet.cxx b/connectivity/source/drivers/odbcbase/ODatabaseMetaDataResultSet.cxx index c7d0ddc44471..fec93c5b8955 100644 --- a/connectivity/source/drivers/odbcbase/ODatabaseMetaDataResultSet.cxx +++ b/connectivity/source/drivers/odbcbase/ODatabaseMetaDataResultSet.cxx @@ -157,11 +157,15 @@ sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::findColumn( const OUString& colum 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; - /* FIXME should throw in case of not found ? or at least return -1 */ - return i; + return i; + } + + ::dbtools::throwInvalidColumnException( columnName, *this ); + assert(false); + return 0; // Never reached } template < typename T, SQLSMALLINT sqlTypeId > T ODatabaseMetaDataResultSet::getInteger ( sal_Int32 columnIndex ) diff --git a/connectivity/source/drivers/odbcbase/OResultSet.cxx b/connectivity/source/drivers/odbcbase/OResultSet.cxx index 31fbbb01038a..2b58a03e14f7 100644 --- a/connectivity/source/drivers/odbcbase/OResultSet.cxx +++ b/connectivity/source/drivers/odbcbase/OResultSet.cxx @@ -392,11 +392,15 @@ sal_Int32 SAL_CALL OResultSet::findColumn( const OUString& columnName ) throw(SQ 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; - /* FIXME should throw in case of not found ? or at least return -1 */ - return i; + return i; + } + + ::dbtools::throwInvalidColumnException( columnName, *this ); + assert(false); + return 0; // Never reached } // ------------------------------------------------------------------------- void OResultSet::ensureCacheForColumn(sal_Int32 columnIndex) diff --git a/connectivity/source/drivers/postgresql/pq_resultset.cxx b/connectivity/source/drivers/postgresql/pq_resultset.cxx index b8e5d393a55b..f27f7040a4c2 100644 --- a/connectivity/source/drivers/postgresql/pq_resultset.cxx +++ b/connectivity/source/drivers/postgresql/pq_resultset.cxx @@ -37,6 +37,8 @@ #include "pq_resultset.hxx" #include "pq_resultsetmetadata.hxx" +#include + #include #include #include @@ -166,6 +168,11 @@ sal_Int32 ResultSet::findColumn( const OUString& columnName ) { res += 1; } + else + { + ::dbtools::throwInvalidColumnException( columnName, *this ); + assert(false); + } return res; } diff --git a/connectivity/source/drivers/postgresql/pq_sequenceresultset.cxx b/connectivity/source/drivers/postgresql/pq_sequenceresultset.cxx index 8fc73c46501c..76baaf06f75c 100644 --- a/connectivity/source/drivers/postgresql/pq_sequenceresultset.cxx +++ b/connectivity/source/drivers/postgresql/pq_sequenceresultset.cxx @@ -38,7 +38,7 @@ #include "pq_sequenceresultset.hxx" #include "pq_sequenceresultsetmetadata.hxx" - +#include using com::sun::star::sdbc::XResultSetMetaData; @@ -113,15 +113,15 @@ sal_Int32 SAL_CALL SequenceResultSet::findColumn( throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) { // no need to guard, as all members are readonly ! - sal_Int32 ret = -1; for( int i = 0 ;i < m_fieldCount ; i ++ ) { if( columnName == m_columnNames[i] ) { - ret = i+1; - break; + return i+1; } } - return ret; + ::dbtools::throwInvalidColumnException( columnName, *this ); + assert(false); + return 0; // Never reached } } -- cgit