[Libreoffice-commits] .: 2 commits - connectivity/source

Lionel Elie Mamane lmamane at kemper.freedesktop.org
Sun Jan 29 10:01:23 PST 2012


 connectivity/source/drivers/odbcbase/ODatabaseMetaDataResultSet.cxx |   85 ++------
 connectivity/source/drivers/odbcbase/OResultSet.cxx                 |   75 +++----
 connectivity/source/drivers/odbcbase/OStatement.cxx                 |  100 +++-------
 connectivity/source/drivers/odbcbase/OTools.cxx                     |   93 +++++++++
 connectivity/source/inc/odbc/ODatabaseMetaDataResultSet.hxx         |    2 
 connectivity/source/inc/odbc/OResultSet.hxx                         |    2 
 connectivity/source/inc/odbc/OStatement.hxx                         |    3 
 7 files changed, 203 insertions(+), 157 deletions(-)

New commits:
commit 19ef5bcc8d9dbcf965f79495e1afd86ac0f22c31
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Tue Jan 24 22:21:41 2012 +0100

    use proper sizes for SQL(Get|Set)StmtAttr
    
    Fixes fdo#34432 (driver smashes our stack)
    
    Continuation of
    commit 9a466d9718cceeb4ace9e3352a173c7b62387eee
    Author: Lionel Elie Mamane <lionel at mamane.lu>
    Date:   Tue Nov 29 17:49:36 2011 +0100
    
        ODBC: use right integer length to get Statement Options

diff --git a/connectivity/source/drivers/odbcbase/OResultSet.cxx b/connectivity/source/drivers/odbcbase/OResultSet.cxx
index 1787744..a882c21 100644
--- a/connectivity/source/drivers/odbcbase/OResultSet.cxx
+++ b/connectivity/source/drivers/odbcbase/OResultSet.cxx
@@ -118,15 +118,15 @@ OResultSet::OResultSet(SQLHANDLE _pStatementHandle ,OStatement_Base* pStmt) :
     try
     {
         m_pRowStatusArray = new SQLUSMALLINT[1]; // the default value
-        N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_STATUS_PTR,m_pRowStatusArray,SQL_IS_POINTER);
+        setStmtOption<SQLUSMALLINT*, SQL_IS_POINTER>(SQL_ATTR_ROW_STATUS_PTR, m_pRowStatusArray);
     }
     catch(const Exception&)
     { // we don't want our result destroy here
     }
-    SQLINTEGER nCurType = 0;
+    SQLULEN nCurType = 0;
     try
     {
-        N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,&nCurType,SQL_IS_UINTEGER,0);
+        nCurType = getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CURSOR_TYPE);
         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)
@@ -841,9 +841,10 @@ void SAL_CALL OResultSet::insertRow(  ) throw(SQLException, RuntimeException)
     checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
 
 
-    SQLLEN nMaxLen = 20;
+    const SQLLEN nMaxLen = 20;
     SQLLEN nRealLen = 0;
     Sequence<sal_Int8> aBookmark(nMaxLen);
+    assert (static_cast<size_t>(nMaxLen) >= sizeof(SQLLEN));
 
     SQLRETURN nRet = N3SQLBindCol(m_aStatementHandle,
                                 0,
@@ -880,7 +881,7 @@ void SAL_CALL OResultSet::insertRow(  ) throw(SQLException, RuntimeException)
 
     if ( bPositionByBookmark )
     {
-        nRet = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_FETCH_BOOKMARK_PTR,aBookmark.getArray(),SQL_IS_POINTER); // SQL_LEN_BINARY_ATTR(aBookmark.getLength())
+        setStmtOption<SQLLEN*, SQL_IS_POINTER>(SQL_ATTR_FETCH_BOOKMARK_PTR, reinterpret_cast<SQLLEN*>(aBookmark.getArray()));
 
         nRet = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_BOOKMARK,0);
     }
@@ -1156,10 +1157,7 @@ Any SAL_CALL OResultSet::getBookmark(  ) throw( SQLException,  RuntimeException)
     {
         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 );
+            m_nUseBookmarks = getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_USE_BOOKMARKS, SQL_UB_OFF);
         }
         if(m_nUseBookmarks == SQL_UB_OFF)
             throw SQLException();
@@ -1184,8 +1182,7 @@ sal_Bool SAL_CALL OResultSet::moveToBookmark( const  Any& bookmark ) throw( SQLE
     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 );
+        SQLRETURN nReturn = setStmtOption<SQLLEN*, SQL_IS_POINTER>(SQL_ATTR_FETCH_BOOKMARK_PTR, reinterpret_cast<SQLLEN*>(m_aBookmark.getArray()));
 
         if ( SQL_INVALID_HANDLE != nReturn && SQL_ERROR != nReturn )
         {
@@ -1211,7 +1208,7 @@ sal_Bool SAL_CALL OResultSet::moveRelativeToBookmark( const  Any& bookmark, sal_
 
     m_nLastColumnPos = 0;
     bookmark >>= m_aBookmark;
-    SQLRETURN nReturn = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_FETCH_BOOKMARK_PTR,m_aBookmark.getArray(),SQL_IS_POINTER);
+    SQLRETURN nReturn = setStmtOption<SQLLEN*, SQL_IS_POINTER>(SQL_ATTR_FETCH_BOOKMARK_PTR, reinterpret_cast<SQLLEN*>(m_aBookmark.getArray()));
     OSL_UNUSED( nReturn );
 
     m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_BOOKMARK,rows);
@@ -1266,11 +1263,23 @@ Sequence< sal_Int32 > SAL_CALL OResultSet::deleteRows( const  Sequence<  Any >&
     return aRet;
 }
 //------------------------------------------------------------------------------
+template < typename T, SQLINTEGER BufferLength > T OResultSet::getStmtOption (SQLINTEGER fOption, T dflt) const
+{
+    T result (dflt);
+    OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
+    N3SQLGetStmtAttr(m_aStatementHandle, fOption, &result, BufferLength, NULL);
+    return result;
+}
+template < typename T, SQLINTEGER BufferLength > SQLRETURN OResultSet::setStmtOption (SQLINTEGER fOption, T value) const
+{
+    OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
+    SQLPOINTER sv = reinterpret_cast<SQLPOINTER>(value);
+    return N3SQLSetStmtAttr(m_aStatementHandle, fOption, sv, BufferLength);
+}
+//------------------------------------------------------------------------------
 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 );
+    sal_uInt32 nValue = getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CONCURRENCY);
     if(SQL_CONCUR_READ_ONLY == nValue)
         nValue = ResultSetConcurrency::READ_ONLY;
     else
@@ -1281,16 +1290,14 @@ sal_Int32 OResultSet::getResultSetConcurrency() const
 //------------------------------------------------------------------------------
 sal_Int32 OResultSet::getResultSetType() const
 {
-    sal_uInt32 nValue = 0;
-    N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_SENSITIVITY,&nValue,SQL_IS_UINTEGER,0);
+    sal_uInt32 nValue = getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CURSOR_SENSITIVITY);
     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);
+        SQLULEN nCurType = getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CURSOR_TYPE);
         if(SQL_CURSOR_KEYSET_DRIVEN == nCurType)
             nValue = ResultSetType::SCROLL_SENSITIVE;
         else if(SQL_CURSOR_STATIC  == nCurType)
@@ -1310,9 +1317,7 @@ sal_Int32 OResultSet::getFetchDirection() const
 //------------------------------------------------------------------------------
 sal_Int32 OResultSet::getFetchSize() const
 {
-    sal_uInt32 nValue = 0;
-    N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE,&nValue,SQL_IS_UINTEGER,0);
-    return nValue;
+    return getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_ROW_ARRAY_SIZE);
 }
 //------------------------------------------------------------------------------
 ::rtl::OUString OResultSet::getCursorName() const
@@ -1328,13 +1333,12 @@ 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);
+    const SQLULEN nCursorType = getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CURSOR_TYPE);
 
     sal_Int32 nAttr = 0;
     try
     {
-        switch(nValue)
+        switch(nCursorType)
         {
         case SQL_CURSOR_FORWARD_ONLY:
             return sal_False;
@@ -1356,9 +1360,7 @@ sal_Bool  OResultSet::isBookmarkable() const
 
     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 );
+        m_nUseBookmarks = getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_USE_BOOKMARKS, SQL_UB_OFF);
     }
 
     return (m_nUseBookmarks != SQL_UB_OFF) && (nAttr & SQL_CA1_BOOKMARK) == SQL_CA1_BOOKMARK;
@@ -1369,7 +1371,7 @@ void OResultSet::setFetchDirection(sal_Int32 _par0)
     OSL_ENSURE(_par0>0,"Illegal fetch direction!");
     if ( _par0 > 0 )
     {
-        N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,(SQLPOINTER)(sal_IntPtr)_par0,SQL_IS_UINTEGER);
+        setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CURSOR_TYPE, _par0);
     }
 }
 //------------------------------------------------------------------------------
@@ -1378,11 +1380,11 @@ void OResultSet::setFetchSize(sal_Int32 _par0)
     OSL_ENSURE(_par0>0,"Illegal fetch size!");
     if ( _par0 > 0 )
     {
-        N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE,(SQLPOINTER)(sal_IntPtr)_par0,SQL_IS_UINTEGER);
+        setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_ROW_ARRAY_SIZE, _par0);
         delete [] m_pRowStatusArray;
 
         m_pRowStatusArray = new SQLUSMALLINT[_par0];
-        N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_STATUS_PTR,m_pRowStatusArray,SQL_IS_POINTER);
+        setStmtOption<SQLUSMALLINT*, SQL_IS_POINTER>(SQL_ATTR_ROW_STATUS_PTR, m_pRowStatusArray);
     }
 }
 // -------------------------------------------------------------------------
@@ -1656,10 +1658,7 @@ sal_Bool OResultSet::move(IResultSetHelper::Movement _eCursorPosition, sal_Int32
         } // 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 );
+            m_nUseBookmarks = getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_USE_BOOKMARKS, SQL_UB_OFF);
         }
         if ( m_nUseBookmarks != SQL_UB_OFF )
         {
@@ -1679,10 +1678,8 @@ sal_Bool OResultSet::move(IResultSetHelper::Movement _eCursorPosition, sal_Int32
 // -----------------------------------------------------------------------------
 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);
+    sal_Int32 nValue = getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_ROW_NUMBER);
+    OSL_TRACE( __FILE__": OResultSet::getDriverPos() = RowNum = %d, RowPos = %d", nValue, m_nRowPos);
     return nValue ? nValue : m_nRowPos;
 }
 // -----------------------------------------------------------------------------
diff --git a/connectivity/source/drivers/odbcbase/OStatement.cxx b/connectivity/source/drivers/odbcbase/OStatement.cxx
index d268b2f..27eec15 100644
--- a/connectivity/source/drivers/odbcbase/OStatement.cxx
+++ b/connectivity/source/drivers/odbcbase/OStatement.cxx
@@ -300,8 +300,7 @@ sal_Bool OStatement_Base::lockIfNecessary (const ::rtl::OUString& sql) throw( SQ
         OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
         try
         {
-            SQLINTEGER nLock = SQL_CONCUR_LOCK;
-            THROW_SQL(N3SQLSetStmtAttr(m_aStatementHandle, SQL_CONCURRENCY,(SQLPOINTER)(sal_IntPtr)nLock,SQL_IS_UINTEGER));
+            THROW_SQL((setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CONCURRENCY, SQL_CONCUR_LOCK)));
         }
         catch (const SQLWarning& warn)
         {
@@ -446,13 +445,19 @@ Reference< XResultSet > OStatement_Base::getResultSet (sal_Bool checkCount) thro
 // Invoke SQLGetStmtOption with the given option.
 //--------------------------------------------------------------------
 
-template < typename T, SQLINTEGER BufferLength > T OStatement_Base::getStmtOption (short fOption) const
+template < typename T, SQLINTEGER BufferLength > T OStatement_Base::getStmtOption (SQLINTEGER fOption, T dflt) const
 {
-    T result = 0;
+    T result (dflt);
     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
     N3SQLGetStmtAttr(m_aStatementHandle, fOption, &result, BufferLength, NULL);
     return result;
 }
+template < typename T, SQLINTEGER BufferLength > SQLRETURN OStatement_Base::setStmtOption (SQLINTEGER fOption, T value) const
+{
+    OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
+    SQLPOINTER sv = reinterpret_cast<SQLPOINTER>(value);
+    return N3SQLSetStmtAttr(m_aStatementHandle, fOption, sv, BufferLength);
+}
 // -------------------------------------------------------------------------
 
 Reference< XResultSet > SAL_CALL OStatement_Base::executeQuery( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
@@ -676,16 +681,13 @@ sal_Int64 OStatement_Base::getQueryTimeOut() const
 //------------------------------------------------------------------------------
 sal_Int64 OStatement_Base::getMaxRows() const
 {
-    // How do I say I want a SQLULEN??
     return getStmtOption<SQLULEN, SQL_IS_UINTEGER>(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 );
+    SQLULEN nValue (getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CONCURRENCY));
     if(nValue == SQL_CONCUR_READ_ONLY)
         nValue = ResultSetConcurrency::READ_ONLY;
     else
@@ -696,10 +698,7 @@ sal_Int32 OStatement_Base::getResultSetConcurrency() const
 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);
-    OSL_UNUSED( nRetCode );
+    SQLULEN nValue (getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CURSOR_TYPE, SQL_CURSOR_FORWARD_ONLY));
     switch(nValue)
     {
         case SQL_CURSOR_FORWARD_ONLY:
@@ -712,6 +711,8 @@ sal_Int32 OStatement_Base::getResultSetType() const
         case SQL_CURSOR_DYNAMIC:
             nValue = ResultSetType::SCROLL_SENSITIVE;
             break;
+        default:
+            OSL_FAIL("Unknown ODBC Cursor Type");
     }
 
     return nValue;
@@ -720,10 +721,7 @@ sal_Int32 OStatement_Base::getResultSetType() const
 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 );
-
+    SQLULEN nValue (getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CURSOR_SCROLLABLE));
     switch(nValue)
     {
         case SQL_SCROLLABLE:
@@ -740,10 +738,7 @@ sal_Int32 OStatement_Base::getFetchDirection() const
 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;
+    return getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_ROW_ARRAY_SIZE);
 }
 //------------------------------------------------------------------------------
 sal_Int64 OStatement_Base::getMaxFieldSize() const
@@ -764,39 +759,35 @@ sal_Int64 OStatement_Base::getMaxFieldSize() const
 void OStatement_Base::setQueryTimeOut(sal_Int32 seconds)
 {
     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
-    SQLRETURN nRetCode = N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_QUERY_TIMEOUT,(SQLPOINTER)(sal_IntPtr)seconds,SQL_IS_UINTEGER);
-    OSL_UNUSED( nRetCode );
+    setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_QUERY_TIMEOUT,seconds);
 }
 //------------------------------------------------------------------------------
 void OStatement_Base::setMaxRows(sal_Int32 _par0)
 {
     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
-    SQLRETURN nRetCode = N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_MAX_ROWS, (SQLPOINTER)(sal_IntPtr)_par0,SQL_IS_UINTEGER);
-    OSL_UNUSED( nRetCode );
+    setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_MAX_ROWS, _par0);
 }
 //------------------------------------------------------------------------------
 void OStatement_Base::setResultSetConcurrency(sal_Int32 _par0)
 {
-    SQLINTEGER nSet;
+    SQLULEN 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)(sal_IntPtr)nSet,SQL_IS_UINTEGER);
-
+    setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CONCURRENCY, nSet);
 }
 //------------------------------------------------------------------------------
 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 );
+    setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_ROW_BIND_TYPE, SQL_BIND_BY_COLUMN);
 
     sal_Bool bUseBookmark = isUsingBookmarks();
-    SQLUINTEGER nSet( SQL_UNSPECIFIED );
+    SQLULEN nSet( SQL_UNSPECIFIED );
     switch(_par0)
     {
         case ResultSetType::FORWARD_ONLY:
@@ -804,7 +795,7 @@ void OStatement_Base::setResultSetType(sal_Int32 _par0)
             break;
         case ResultSetType::SCROLL_INSENSITIVE:
             nSet =  SQL_INSENSITIVE;
-            N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CURSOR_TYPE,(SQLPOINTER)SQL_CURSOR_KEYSET_DRIVEN,SQL_IS_UINTEGER);
+            setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CURSOR_TYPE, SQL_CURSOR_KEYSET_DRIVEN);
             break;
         case ResultSetType::SCROLL_SENSITIVE:
             if(bUseBookmark)
@@ -830,47 +821,41 @@ void OStatement_Base::setResultSetType(sal_Int32 _par0)
             }
             else
                 nSet = SQL_CURSOR_DYNAMIC;
-            if(N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CURSOR_TYPE,(SQLPOINTER)(sal_uIntPtr)nSet,SQL_IS_UINTEGER) != SQL_SUCCESS)
+            if( setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CURSOR_TYPE, nSet) != SQL_SUCCESS )
             {
-                nSet = SQL_CURSOR_KEYSET_DRIVEN;
-                N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CURSOR_TYPE,(SQLPOINTER)(sal_uIntPtr)nSet,SQL_IS_UINTEGER);
+                setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CURSOR_TYPE, SQL_CURSOR_KEYSET_DRIVEN);
             }
             nSet =  SQL_SENSITIVE;
             break;
         default:
+            fprintf(stderr, "_par0=%d\n", _par0);
             OSL_FAIL( "OStatement_Base::setResultSetType: invalid result set type!" );
             break;
     }
 
 
-    N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CURSOR_SENSITIVITY,(SQLPOINTER)(sal_uIntPtr)nSet,SQL_IS_UINTEGER);
+    setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CURSOR_SENSITIVITY, nSet);
 }
 //------------------------------------------------------------------------------
 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)(sal_uIntPtr)nEscapeProc, SQL_IS_UINTEGER );
-    (void)nRetCode;
+    SQLULEN nEscapeProc( _bEscapeProc ? SQL_NOSCAN_OFF : SQL_NOSCAN_ON );
+    setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_NOSCAN, nEscapeProc);
 }
 
 //------------------------------------------------------------------------------
 void OStatement_Base::setFetchDirection(sal_Int32 _par0)
 {
     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
-    sal_IntPtr 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);
+        setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CURSOR_SCROLLABLE, SQL_NONSCROLLABLE);
     }
     else if(_par0 == FetchDirection::REVERSE)
     {
-        nCursType = SQL_SCROLLABLE;
-        nRetCode = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_SCROLLABLE,(SQLPOINTER)nCursType,SQL_IS_UINTEGER);
+        setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CURSOR_SCROLLABLE, SQL_SCROLLABLE);
     }
-    OSL_UNUSED( nRetCode );
 }
 //------------------------------------------------------------------------------
 void OStatement_Base::setFetchSize(sal_Int32 _par0)
@@ -879,19 +864,19 @@ void OStatement_Base::setFetchSize(sal_Int32 _par0)
     OSL_ENSURE(_par0>0,"Illegal fetch size!");
     if ( _par0 > 0 )
     {
-        SQLRETURN nRetCode = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE,(SQLPOINTER)(sal_IntPtr)_par0,SQL_IS_UINTEGER);
+        setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_ROW_ARRAY_SIZE, _par0);
 
-        delete m_pRowStatusArray;
+        if (m_pRowStatusArray)
+            delete[] m_pRowStatusArray;
         m_pRowStatusArray = new SQLUSMALLINT[_par0];
-        nRetCode = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_STATUS_PTR,m_pRowStatusArray,SQL_IS_POINTER);
-        OSL_UNUSED( nRetCode );
+        setStmtOption<SQLUSMALLINT*, SQL_IS_POINTER>(SQL_ATTR_ROW_STATUS_PTR, m_pRowStatusArray);
     }
 }
 //------------------------------------------------------------------------------
 void OStatement_Base::setMaxFieldSize(sal_Int32 _par0)
 {
     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
-    N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_MAX_LENGTH,(SQLPOINTER)(sal_IntPtr)_par0,SQL_IS_UINTEGER);
+    setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_MAX_LENGTH, _par0);
 }
 //------------------------------------------------------------------------------
 void OStatement_Base::setCursorName(const ::rtl::OUString &_par0)
@@ -904,27 +889,20 @@ void OStatement_Base::setCursorName(const ::rtl::OUString &_par0)
 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;
+    return SQL_UB_OFF != getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_USE_BOOKMARKS, 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;
+    return SQL_NOSCAN_OFF == getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_USE_BOOKMARKS, SQL_NOSCAN_OFF);;
 }
 // -------------------------------------------------------------------------
 void OStatement_Base::setUsingBookmarks(sal_Bool _bUseBookmark)
 {
     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
-    sal_uIntPtr 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 );
+    SQLULEN nValue = _bUseBookmark ? SQL_UB_VARIABLE : SQL_UB_OFF;
+    setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_USE_BOOKMARKS, nValue);
 }
 // -------------------------------------------------------------------------
 ::cppu::IPropertyArrayHelper* OStatement_Base::createArrayHelper( ) const
diff --git a/connectivity/source/inc/odbc/OResultSet.hxx b/connectivity/source/inc/odbc/OResultSet.hxx
index bbb3920..e036225 100644
--- a/connectivity/source/inc/odbc/OResultSet.hxx
+++ b/connectivity/source/inc/odbc/OResultSet.hxx
@@ -160,9 +160,11 @@ namespace connectivity
             sal_Int32 getFetchDirection()       const;
             sal_Int32 getFetchSize()            const;
             ::rtl::OUString getCursorName()     const;
+            template < typename T, SQLINTEGER BufferLength > T getStmtOption (SQLINTEGER fOption, T dflt = 0) const;
 
             void setFetchDirection(sal_Int32 _par0);
             void setFetchSize(sal_Int32 _par0);
+            template < typename T, SQLINTEGER BufferLength > SQLRETURN setStmtOption (SQLINTEGER fOption, T value) const;
 
 
             void fillRow(sal_Int32 _nToColumn);
diff --git a/connectivity/source/inc/odbc/OStatement.hxx b/connectivity/source/inc/odbc/OStatement.hxx
index 2ad1a42..e0d4663 100644
--- a/connectivity/source/inc/odbc/OStatement.hxx
+++ b/connectivity/source/inc/odbc/OStatement.hxx
@@ -97,7 +97,7 @@ namespace connectivity
             ::rtl::OUString getCursorName()     const;
             sal_Bool isUsingBookmarks()         const;
             sal_Bool getEscapeProcessing()      const;
-            template < typename T, SQLINTEGER BufferLength > T getStmtOption (short fOption) const;
+            template < typename T, SQLINTEGER BufferLength > T getStmtOption (SQLINTEGER fOption, T dflt = 0) const;
 
             void setQueryTimeOut(sal_Int32 _par0)           ;
             void setMaxFieldSize(sal_Int32 _par0)           ;
@@ -106,6 +106,7 @@ namespace connectivity
             void setFetchSize(sal_Int32 _par0)              ;
             void setCursorName(const ::rtl::OUString &_par0);
             void setEscapeProcessing( const sal_Bool _bEscapeProc );
+            template < typename T, SQLINTEGER BufferLength > SQLRETURN setStmtOption (SQLINTEGER fOption, T value) const;
 
             virtual void setResultSetConcurrency(sal_Int32 _par0)   ;
             virtual void setResultSetType(sal_Int32 _par0)          ;
commit 63b6b1d6120d82c4baf5cb679d75dcc5427dbbc3
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Tue Jan 24 22:20:31 2012 +0100

    make OTools::getValue insanely safe, factorise get{Int,Long,Byte,...}

diff --git a/connectivity/source/drivers/odbcbase/ODatabaseMetaDataResultSet.cxx b/connectivity/source/drivers/odbcbase/ODatabaseMetaDataResultSet.cxx
index 59876bb..6dd7881 100644
--- a/connectivity/source/drivers/odbcbase/ODatabaseMetaDataResultSet.cxx
+++ b/connectivity/source/drivers/odbcbase/ODatabaseMetaDataResultSet.cxx
@@ -170,6 +170,30 @@ sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::findColumn( const ::rtl::OUString
             break;
     return i;
 }
+
+template < typename T, SQLSMALLINT sqlTypeId > T ODatabaseMetaDataResultSet::getInteger ( sal_Int32 columnIndex )
+{
+    checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
+    ::osl::MutexGuard aGuard( m_aMutex );
+
+    columnIndex = mapColumn(columnIndex);
+    T nVal = 0;
+    if(columnIndex <= m_nDriverColumnCount)
+    {
+        getValue<T>(m_pConnection, m_aStatementHandle, columnIndex, sqlTypeId, m_bWasNull, **this, nVal);
+
+        if ( !m_aValueRange.empty() )
+        {
+            ::std::map<sal_Int32, ::connectivity::TInt2IntMap >::iterator aValueRangeIter (m_aValueRange.find(columnIndex));
+            if ( aValueRangeIter != m_aValueRange.end() )
+                return static_cast<T>(aValueRangeIter->second[nVal]);
+        }
+    }
+    else
+        m_bWasNull = sal_True;
+    return nVal;
+}
+
 // -------------------------------------------------------------------------
 Reference< ::com::sun::star::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getBinaryStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
 {
@@ -215,24 +239,7 @@ sal_Bool SAL_CALL ODatabaseMetaDataResultSet::getBoolean( sal_Int32 columnIndex
 
 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;
+    return getInteger<sal_Int8, SQL_C_STINYINT>( columnIndex );
 }
 // -------------------------------------------------------------------------
 
@@ -322,24 +329,7 @@ float SAL_CALL ODatabaseMetaDataResultSet::getFloat( sal_Int32 columnIndex ) thr
 
 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;
+    return getInteger<sal_Int32, SQL_C_SLONG>( columnIndex );
 }
 // -------------------------------------------------------------------------
 
@@ -349,10 +339,9 @@ sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getRow(  ) throw(SQLException, Ru
 }
 // -------------------------------------------------------------------------
 
-sal_Int64 SAL_CALL ODatabaseMetaDataResultSet::getLong( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
+sal_Int64 SAL_CALL ODatabaseMetaDataResultSet::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
 {
-    ::dbtools::throwFunctionNotSupportedException( "XRow::getLong", *this );
-    return 0;
+    return getInteger<sal_Int64, SQL_C_SBIGINT>( columnIndex );
 }
 // -------------------------------------------------------------------------
 
@@ -398,23 +387,7 @@ Any SAL_CALL ODatabaseMetaDataResultSet::getObject( sal_Int32 /*columnIndex*/, c
 
 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;
+    return getInteger<sal_Int16, SQL_C_SSHORT>( columnIndex );
 }
 // -------------------------------------------------------------------------
 
diff --git a/connectivity/source/drivers/odbcbase/OTools.cxx b/connectivity/source/drivers/odbcbase/OTools.cxx
index 4da70ef..9e8714c 100644
--- a/connectivity/source/drivers/odbcbase/OTools.cxx
+++ b/connectivity/source/drivers/odbcbase/OTools.cxx
@@ -45,6 +45,82 @@ using namespace com::sun::star::uno;
 using namespace com::sun::star::sdbc;
 using namespace com::sun::star::util;
 
+namespace {
+size_t sqlTypeLen ( SQLSMALLINT _nType )
+{
+    switch (_nType)
+    {
+    case SQL_C_CHAR:
+        return sizeof(SQLCHAR *);
+    case SQL_C_WCHAR:
+        return sizeof(SQLWCHAR *);
+    case SQL_C_SSHORT:
+    case SQL_C_SHORT:
+        return sizeof(SQLSMALLINT);
+    case SQL_C_USHORT:
+        return sizeof(SQLUSMALLINT);
+    case SQL_C_SLONG:
+    case SQL_C_LONG:
+        return sizeof(SQLINTEGER);
+    case SQL_C_ULONG:
+        return sizeof(SQLUINTEGER);
+    case SQL_C_FLOAT:
+        return sizeof(SQLREAL);
+    case SQL_C_DOUBLE:
+        OSL_ENSURE(sizeof(SQLDOUBLE) == sizeof(SQLFLOAT), "SQLDOUBLE/SQLFLOAT confusion");
+        return sizeof(SQLDOUBLE);
+    case SQL_C_BIT:
+        return sizeof(SQLCHAR);
+    case SQL_C_STINYINT:
+    case SQL_C_TINYINT:
+        return sizeof(SQLSCHAR);
+    case SQL_C_UTINYINT:
+        return sizeof(SQLCHAR);
+    case SQL_C_SBIGINT:
+        return sizeof(SQLBIGINT);
+    case SQL_C_UBIGINT:
+        return sizeof(SQLUBIGINT);
+    /* UnixODBC gives this the same value as SQL_C_UBIGINT
+    case SQL_C_BOOKMARK:
+        return sizeof(BOOKMARK); */
+    case SQL_C_BINARY:
+    // UnixODBC gives these the same value
+    //case SQL_C_VARBOOKMARK:
+        return sizeof(SQLCHAR*);
+    case SQL_C_TYPE_DATE:
+    case SQL_C_DATE:
+        return sizeof(SQL_DATE_STRUCT);
+    case SQL_C_TYPE_TIME:
+    case SQL_C_TIME:
+        return sizeof(SQL_TIME_STRUCT);
+    case SQL_C_TYPE_TIMESTAMP:
+    case SQL_C_TIMESTAMP:
+        return sizeof(SQL_TIMESTAMP_STRUCT);
+    case SQL_C_NUMERIC:
+        return sizeof(SQL_NUMERIC_STRUCT);
+    case SQL_C_GUID:
+        return sizeof(SQLGUID);
+    case SQL_C_INTERVAL_YEAR:
+    case SQL_C_INTERVAL_MONTH:
+    case SQL_C_INTERVAL_DAY:
+    case SQL_C_INTERVAL_HOUR:
+    case SQL_C_INTERVAL_MINUTE:
+    case SQL_C_INTERVAL_SECOND:
+    case SQL_C_INTERVAL_YEAR_TO_MONTH:
+    case SQL_C_INTERVAL_DAY_TO_HOUR:
+    case SQL_C_INTERVAL_DAY_TO_MINUTE:
+    case SQL_C_INTERVAL_DAY_TO_SECOND:
+    case SQL_C_INTERVAL_HOUR_TO_MINUTE:
+    case SQL_C_INTERVAL_HOUR_TO_SECOND:
+    case SQL_C_INTERVAL_MINUTE_TO_SECOND:
+        return sizeof(SQL_INTERVAL_STRUCT);
+    default:
+        return static_cast<size_t>(-1);
+    }
+}
+}
+
+
 void OTools::getValue(  OConnection* _pConnection,
                         SQLHANDLE _aStatementHandle,
                         sal_Int32 columnIndex,
@@ -55,6 +131,23 @@ void OTools::getValue(  OConnection* _pConnection,
                         SQLLEN _nSize) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
 {
     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen at sun.com", "OTools::getValue" );
+    const size_t properSize = sqlTypeLen(_nType);
+    if ( properSize == static_cast<size_t>(-1) )
+        OSL_FAIL("connectivity::odbc::OTools::getValue: unknown SQL type - cannot check buffer size");
+    else
+    {
+        OSL_ENSURE(static_cast<size_t>(_nSize) == properSize, "connectivity::odbc::OTools::getValue got wrongly sized memory region to write result to");
+        if ( static_cast<size_t>(_nSize) > properSize )
+        {
+            OSL_FAIL("memory region is too big - trying to fudge it");
+            memset(_pValue, 0, _nSize);
+#ifdef OSL_BIGENDIAN
+            // This is skewed in favour of integer types
+            _pValue += _nSize - properSize;
+#endif
+        }
+    }
+    OSL_ENSURE(static_cast<size_t>(_nSize) >= properSize, "memory region is too small");
     SQLLEN pcbValue = SQL_NULL_DATA;
     OTools::ThrowException(_pConnection,
                             (*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(_aStatementHandle,
diff --git a/connectivity/source/inc/odbc/ODatabaseMetaDataResultSet.hxx b/connectivity/source/inc/odbc/ODatabaseMetaDataResultSet.hxx
index 1ae6042..7a17249 100644
--- a/connectivity/source/inc/odbc/ODatabaseMetaDataResultSet.hxx
+++ b/connectivity/source/inc/odbc/ODatabaseMetaDataResultSet.hxx
@@ -125,6 +125,8 @@ namespace connectivity
                                     sal_Int32 nHandle
                                          ) const;
             ~ODatabaseMetaDataResultSet();
+            template < typename T, SQLSMALLINT sqlTypeId > T getInteger ( sal_Int32 columnIndex );
+
         public:
             // ein Konstruktor, der fuer das Returnen des Objektes benoetigt wird:
             ODatabaseMetaDataResultSet(OConnection* _pConnection);


More information about the Libreoffice-commits mailing list