summaryrefslogtreecommitdiff
path: root/connectivity
diff options
context:
space:
mode:
authorAndrzej J.R. Hunt <andrzej@ahunt.org>2013-09-11 21:40:41 +0100
committerFridrich Strba <fridrich@documentfoundation.org>2013-09-12 17:26:12 +0000
commit42165189826367937737861116e969a22e9db787 (patch)
tree69d8ec60869aee5981ecc4e5edbc1e3a89a625d7 /connectivity
parenta042cdd7eff15ed5f6cbd613588b3fca9509a85e (diff)
Update implementations of ColumnLocate::findColumn to throw on invalid column.
Change-Id: I7a9354ecd35a70a005c6c50e38d27de9b33332bd Reviewed-on: https://gerrit.libreoffice.org/5922 Reviewed-by: Fridrich Strba <fridrich@documentfoundation.org> Tested-by: Fridrich Strba <fridrich@documentfoundation.org>
Diffstat (limited to 'connectivity')
-rw-r--r--connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx10
-rw-r--r--connectivity/source/commontools/dbexception.cxx9
-rw-r--r--connectivity/source/drivers/ado/ADatabaseMetaDataResultSet.cxx10
-rw-r--r--connectivity/source/drivers/ado/AResultSet.cxx10
-rw-r--r--connectivity/source/drivers/evoab2/NResultSet.cxx10
-rw-r--r--connectivity/source/drivers/file/FResultSet.cxx12
-rw-r--r--connectivity/source/drivers/firebird/ResultSet.cxx12
-rw-r--r--connectivity/source/drivers/kab/KResultSet.cxx13
-rw-r--r--connectivity/source/drivers/macab/MacabResultSet.cxx14
-rw-r--r--connectivity/source/drivers/mork/MResultSet.cxx9
-rw-r--r--connectivity/source/drivers/mozab/MResultSet.cxx9
-rw-r--r--connectivity/source/drivers/odbcbase/ODatabaseMetaDataResultSet.cxx10
-rw-r--r--connectivity/source/drivers/odbcbase/OResultSet.cxx10
-rw-r--r--connectivity/source/drivers/postgresql/pq_resultset.cxx7
-rw-r--r--connectivity/source/drivers/postgresql/pq_sequenceresultset.cxx10
-rw-r--r--connectivity/source/sdbcx/VCollection.cxx8
16 files changed, 95 insertions, 68 deletions
diff --git a/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx b/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx
index 6217626af488..9373481eabdf 100644
--- a/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx
+++ b/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx
@@ -37,6 +37,7 @@
#include <cppuhelper/factory.hxx>
#include <cppuhelper/implementationentry.hxx>
#include "connectivity/dbexception.hxx"
+#include "resource/common_res.hrc"
#include "TConnection.hxx"
using namespace connectivity;
@@ -168,13 +169,16 @@ 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
}
// -----------------------------------------------------------------------------
void ODatabaseMetaDataResultSet::checkIndex(sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException)
diff --git a/connectivity/source/commontools/dbexception.cxx b/connectivity/source/commontools/dbexception.cxx
index 5dcac1bec49c..c33c1e063930 100644
--- a/connectivity/source/commontools/dbexception.cxx
+++ b/connectivity/source/commontools/dbexception.cxx
@@ -446,6 +446,15 @@ void throwFeatureNotImplementedException( const sal_Char* _pAsciiFeatureName, co
);
}
+void throwInvalidColumnException( const OUString& _rColumnName, const Reference< XInterface >& _rxContext)
+ throw (SQLException)
+{
+ ::connectivity::SharedResources aResources;
+ OUString sErrorMessage( aResources.getResourceStringWithSubstitution(
+ STR_INVALID_COLUMNNAME,
+ "$columnname$",_rColumnName) );
+ throwSQLException( sErrorMessage, SQL_COLUMN_NOT_FOUND, _rxContext );
+}
// -----------------------------------------------------------------------------
void throwSQLException( const sal_Char* _pAsciiMessage, const sal_Char* _pAsciiState,
const Reference< XInterface >& _rxContext, const sal_Int32 _nErrorCode, const Any* _pNextException ) throw (SQLException)
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 <connectivity/dbexception.hxx>
+
#include <com/sun/star/sdbc/FetchDirection.hpp>
#include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
#include <com/sun/star/sdbc/ResultSetType.hpp>
@@ -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 <connectivity/dbexception.hxx>
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
}
}
diff --git a/connectivity/source/sdbcx/VCollection.cxx b/connectivity/source/sdbcx/VCollection.cxx
index bbed1713d2ca..ebcc9538f118 100644
--- a/connectivity/source/sdbcx/VCollection.cxx
+++ b/connectivity/source/sdbcx/VCollection.cxx
@@ -444,12 +444,8 @@ sal_Int32 SAL_CALL OCollection::findColumn( const OUString& columnName ) throw(S
{
if ( !m_pElements->exists(columnName) )
{
- ::connectivity::SharedResources aResources;
- const OUString sError( aResources.getResourceStringWithSubstitution(
- STR_UNKNOWN_COLUMN_NAME,
- "$columnname$", columnName
- ) );
- ::dbtools::throwGenericSQLException(sError,static_cast< XIndexAccess*>(this));
+ ::dbtools::throwInvalidColumnException( columnName, static_cast< XIndexAccess*>(this) );
+ assert(false);
}
return m_pElements->findColumn(columnName) + 1; // because columns start at one