use proper sizes for SQL(Get|Set)StmtAttr

Fixes fdo#34432 (driver smashes our stack)

Continuation of
commit 9a466d9718
Author: Lionel Elie Mamane <lionel@mamane.lu>
Date:   Tue Nov 29 17:49:36 2011 +0100

    ODBC: use right integer length to get Statement Options
This commit is contained in:
Lionel Elie Mamane
2012-01-24 22:21:41 +01:00
parent 63b6b1d612
commit 19ef5bcc8d
4 changed files with 79 additions and 101 deletions

View File

@@ -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;
}
// -----------------------------------------------------------------------------

View File

@@ -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

View File

@@ -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);

View File

@@ -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) ;