summaryrefslogtreecommitdiff
path: root/connectivity
diff options
context:
space:
mode:
authorAndrzej J.R. Hunt <andrzej@ahunt.org>2013-07-19 10:55:14 +0200
committerAndrzej J.R. Hunt <andrzej@ahunt.org>2013-07-19 15:23:20 +0200
commit00d533e34c25eb5699fb19aba6b16007c1cc07c1 (patch)
treee07c6be5a29cc581026aad7e1b00a20e1629372b /connectivity
parent3858ec8a621f2a6c867381b14a8f53fc5bcbef8f (diff)
Remove internal caching in FResultSet. (Breaks firebird-sdbc for now.)
Change-Id: I99d764b1464c264d70c777ff212eaa4e8eba7c71
Diffstat (limited to 'connectivity')
-rw-r--r--connectivity/source/drivers/firebird/FResultSet.cxx317
-rw-r--r--connectivity/source/drivers/firebird/FResultSet.hxx22
2 files changed, 137 insertions, 202 deletions
diff --git a/connectivity/source/drivers/firebird/FResultSet.cxx b/connectivity/source/drivers/firebird/FResultSet.cxx
index d587c858fea4..26f0371b4ab2 100644
--- a/connectivity/source/drivers/firebird/FResultSet.cxx
+++ b/connectivity/source/drivers/firebird/FResultSet.cxx
@@ -76,10 +76,9 @@ OResultSet::OResultSet(OConnection* pConnection,
, m_xMetaData(NULL)
, m_pSqlda(pSqlda)
, m_statementHandle(aStatementHandle)
- , m_bIsPopulated(sal_False)
- , m_bWasNull(sal_True)
+ , m_bWasNull(false)
, m_currentRow(0)
- , m_rowCount(0)
+ , m_bIsAfterLastRow(false)
, m_fieldCount(pSqlda? pSqlda->sqld : 0)
{
SAL_INFO("connectivity.firebird", "OResultSet().");
@@ -93,89 +92,33 @@ OResultSet::~OResultSet()
{
}
-void OResultSet::ensureDataAvailable() throw (SQLException)
-{
- MutexGuard aGuard(m_pConnection->getMutex());
- checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
-
- if (!m_bIsPopulated)
- {
- SAL_INFO("connectivity.firebird", "Iterating over data cursor");
- ISC_STATUS fetchStat;
-
- // Firebird doesn't support scrollable cursors so we have to load everything
- // into memory. Can't really be done on demand as we need to determine the
- // number of rows which can only be done by iterating over the XSQLDA
- while ( 0 == (fetchStat = isc_dsql_fetch(m_statusVector,
- &m_statementHandle,
- 1,
- m_pSqlda)))
- {
- m_rowCount++;
-
- TRow aRow(m_fieldCount);
- m_sqlData.push_back(aRow);
- TRow& rRow = m_sqlData.back();
-
- XSQLVAR* pVar = m_pSqlda->sqlvar;
- for (int i = 0; i < m_fieldCount; pVar++, i++)
- {
- if ((pVar->sqltype & 1) == 0) // Means: Cannot contain NULL
- {
- // TODO: test for null here and set as appropriate
- }
- else // Means: Can contain NULL
- {
- // otherwise we need to test for SQL_TYPE and SQL_TYPE+1 below
- pVar->sqltype--;
- }
- switch (pVar->sqltype)
- {
- case SQL_SHORT:
- rRow[i] = (sal_Int16) *pVar->sqldata;
- break;
- case SQL_LONG:
- rRow[i] = (sal_Int32) *pVar->sqldata;
- break;
- case SQL_INT64:
- rRow[i] = (sal_Int64) *pVar->sqldata;
- break;
- // TODO: remember sqlscale for decimal types
- default:
- rRow[i] = OUString(pVar->sqldata, pVar->sqllen, RTL_TEXTENCODING_UTF8);
- break;
- }
- }
- }
-
- ISC_STATUS aErr = isc_dsql_free_statement(m_statusVector,
- &m_statementHandle,
- DSQL_drop);
- // TODO: cleanup the XSQLDA, probably in the destructor?
-
- // fetchstat == 100L if fetching of data completed successfully.
- if ((fetchStat != 100L) || aErr)
- {
- SAL_WARN("connectivity.firebird", "Error when populating data");
- OConnection::evaluateStatusVector(m_statusVector,
- "isc_dsql_free_statement",
- *this);
- }
-
- SAL_INFO("connectivity.firebird", "Populated dataset with " << m_rowCount << " rows.");
- m_bIsPopulated = true;
- }
-}
-
-const ORowSetValue& OResultSet::getSqlData(sal_Int32 aRow, sal_Int32 aColumn)
- throw(SQLException)
-{
- // Validate input (throws Exceptions as appropriate)
- checkRowIndex(aRow);
- checkColumnIndex(aColumn);
+// void OResultSet::ensureDataAvailable() throw (SQLException)
+// {
+// MutexGuard aGuard(m_pConnection->getMutex());
+// checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
+//
+// if (!m_bIsPopulated)
+// {
+//
+// ISC_STATUS aErr = isc_dsql_free_statement(m_statusVector,
+// &m_statementHandle,
+// DSQL_drop);
+// // TODO: cleanup the XSQLDA, probably in the destructor?
+//
+// // fetchstat == 100L if fetching of data completed successfully.
+// if ((fetchStat != 100L) || aErr)
+// {
+// SAL_WARN("connectivity.firebird", "Error when populating data");
+// OConnection::evaluateStatusVector(m_statusVector,
+// "isc_dsql_free_statement",
+// *this);
+// }
+//
+// SAL_INFO("connectivity.firebird", "Populated dataset with " << m_rowCount << " rows.");
+// m_bIsPopulated = true;
+// }
+// }
- return m_sqlData[aRow-1][aColumn-1];
-}
// ---- XResultSet -- Row retrieval methods ------------------------------------
sal_Int32 SAL_CALL OResultSet::getRow() throw(SQLException, RuntimeException)
@@ -190,34 +133,81 @@ sal_Bool SAL_CALL OResultSet::next() throw(SQLException, RuntimeException)
{
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
- ensureDataAvailable();
- if (m_currentRow < m_rowCount)
+ SAL_INFO("connectivity.firebird", "Fetching row from cursor");
+
+ m_currentRow++;
+
+ ISC_STATUS fetchStat = isc_dsql_fetch(m_statusVector,
+ &m_statementHandle,
+ 1,
+ m_pSqlda);
+ if (fetchStat == 0) // SUCCESSFUL
{
- m_currentRow++;
return sal_True;
}
+ else if (fetchStat == 100L) // END OF DATASET
+ {
+ // TODO: shut the statement
+ return sal_False;
+ }
else
{
+ SAL_WARN("connectivity.firebird", "Error when populating data");
+ // Throws sql exception as appropriate
+ OConnection::evaluateStatusVector(m_statusVector,
+ "isc_dsql_fetch",
+ *this);
return sal_False;
}
+
+ // {
+// m_rowCount++;
+//
+// TRow aRow(m_fieldCount);
+// m_sqlData.push_back(aRow);
+// TRow& rRow = m_sqlData.back();
+//
+// XSQLVAR* pVar = m_pSqlda->sqlvar;
+// for (int i = 0; i < m_fieldCount; pVar++, i++)
+// {
+// if ((pVar->sqltype & 1) == 0) // Means: Cannot contain NULL
+// {
+// // TODO: test for null here and set as appropriate
+// }
+// else // Means: Can contain NULL
+// {
+// // otherwise we need to test for SQL_TYPE and SQL_TYPE+1 below
+// pVar->sqltype--;
+// }
+// switch (pVar->sqltype)
+// {
+// case SQL_SHORT:
+// rRow[i] = (sal_Int16) *pVar->sqldata;
+// break;
+// case SQL_LONG:
+// rRow[i] = (sal_Int32) *pVar->sqldata;
+// break;
+// case SQL_INT64:
+// rRow[i] = (sal_Int64) *pVar->sqldata;
+// break;
+// // TODO: remember sqlscale for decimal types
+// default:
+// rRow[i] = OUString(pVar->sqldata, pVar->sqllen, RTL_TEXTENCODING_UTF8);
+// break;
+// }
+// }
+// }
}
sal_Bool SAL_CALL OResultSet::previous() throw(SQLException, RuntimeException)
{
- MutexGuard aGuard(m_pConnection->getMutex());
- checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
- ensureDataAvailable();
+ throw SQLException("Firebird doesn't support previous()", *this, OUString(), 0, Any());
+}
- if (m_currentRow > 0)
- {
- m_currentRow--;
- return sal_True;
- }
- else
- {
- return sal_False;
- }
+sal_Bool SAL_CALL OResultSet::isLast() throw(SQLException, RuntimeException)
+{
+ throw SQLException("Firebird doesn't support isLast()", *this, OUString(), 0, Any());
}
sal_Bool SAL_CALL OResultSet::isBeforeFirst() throw(SQLException, RuntimeException)
@@ -232,27 +222,16 @@ sal_Bool SAL_CALL OResultSet::isAfterLast() throw(SQLException, RuntimeException
{
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
- ensureDataAvailable();
- return m_currentRow > m_rowCount;
+ return m_bIsAfterLastRow;
}
sal_Bool SAL_CALL OResultSet::isFirst() throw(SQLException, RuntimeException)
{
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
- ensureDataAvailable();
- return m_currentRow == 1 && m_rowCount;
-}
-
-sal_Bool SAL_CALL OResultSet::isLast() throw(SQLException, RuntimeException)
-{
- MutexGuard aGuard(m_pConnection->getMutex());
- checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
- ensureDataAvailable();
-
- return (m_currentRow > 0) && (m_currentRow == m_rowCount);
+ return m_currentRow == 1 && !m_bIsAfterLastRow;
}
// Move to front
@@ -261,77 +240,59 @@ void SAL_CALL OResultSet::beforeFirst() throw(SQLException, RuntimeException)
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
- m_currentRow = 0;
+ if (m_currentRow != 0)
+ throw SQLException("Firebird doesn't support beforeFirst()", *this, OUString(), 0, Any());
}
// Move to back
void SAL_CALL OResultSet::afterLast() throw(SQLException, RuntimeException)
{
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
- ensureDataAvailable();
- m_currentRow = m_rowCount + 1;
+ if (!m_bIsAfterLastRow)
+ throw SQLException("Firebird doesn't support afterLast()", *this, OUString(), 0, Any());
}
sal_Bool SAL_CALL OResultSet::first() throw(SQLException, RuntimeException)
{
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
- ensureDataAvailable();
- if (m_rowCount > 0)
+ if (m_currentRow == 0)
{
- m_currentRow = 1;
- return sal_True;
+ return next();
+ }
+ else if (m_currentRow == 1 && !m_bIsAfterLastRow)
+ {
+ return true;
}
else
{
- return sal_False;
+ throw SQLException("Firebird doesn't support first()", *this, OUString(), 0, Any());
}
}
sal_Bool SAL_CALL OResultSet::last() throw(SQLException, RuntimeException)
{
- MutexGuard aGuard(m_pConnection->getMutex());
- checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
- ensureDataAvailable();
-
- if (m_rowCount > 0)
- {
- m_currentRow = m_rowCount;
- return sal_True;
- }
- else
- {
- return sal_False;
- }
+ // We need to iterate past the last row to know when we've passed the last
+ // row, so we can't actually move to last.
+ throw SQLException("Firebird doesn't support last()", *this, OUString(), 0, Any());
}
sal_Bool SAL_CALL OResultSet::absolute(sal_Int32 aRow) throw(SQLException, RuntimeException)
{
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
- ensureDataAvailable();
- if (m_rowCount > 0)
+ if (aRow > m_currentRow)
{
- if( aRow > 0 )
- {
- m_currentRow = aRow;
- if( m_currentRow > m_rowCount )
- m_currentRow = m_rowCount + 1;
- }
- else
- {
- m_currentRow = m_rowCount + 1 + aRow;
- if( m_currentRow < 0 )
- m_currentRow = 0;
- }
- return sal_True;
+ sal_Int32 aIterations = aRow - m_currentRow;
+ return relative(aIterations);
}
else
{
- return sal_False;
+ throw SQLException("Firebird doesn't support retrieval of rows before the current row",
+ *this, OUString(), 0, Any());
}
}
@@ -339,26 +300,25 @@ sal_Bool SAL_CALL OResultSet::relative(sal_Int32 row) throw(SQLException, Runtim
{
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
- ensureDataAvailable();
- if (m_rowCount > 0)
+ if (row > 0)
{
- m_currentRow += row;
-
- if( m_currentRow > m_rowCount )
- m_currentRow = m_rowCount + 1;
- else if ( m_currentRow < -1 )
- m_currentRow = -1;
-
+ while (row--)
+ {
+ if (!next())
+ return sal_False;
+ }
return sal_True;
}
else
{
- return false;
+ throw SQLException("Firebird doesn't support relative() for a negative offset",
+ *this, OUString(), 0, Any());
}
}
-void SAL_CALL OResultSet::checkColumnIndex(sal_Int32 index ) throw ( SQLException, RuntimeException )
+void SAL_CALL OResultSet::checkColumnIndex(sal_Int32 index)
+ throw (SQLException, RuntimeException)
{
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
@@ -369,25 +329,15 @@ void SAL_CALL OResultSet::checkColumnIndex(sal_Int32 index ) throw ( SQLExceptio
}
}
-void SAL_CALL OResultSet::checkRowIndex(sal_Bool mustBeOnValidRow)
+void SAL_CALL OResultSet::checkRowIndex()
+ throw (SQLException)
{
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
- ensureDataAvailable();
- if(mustBeOnValidRow)
+ if((m_currentRow < 1) || m_bIsAfterLastRow)
{
- if((m_currentRow < 1) || (m_currentRow > m_rowCount))
- {
- throw SQLException( "Row index is out of valid range.", *this, OUString(),1, Any() );
- }
- }
- else
- {
- if((m_currentRow < 0) || (m_currentRow > 1 + m_rowCount))
- {
- throw SQLException( "Row index is invalid", *this, OUString(),1, Any() );
- }
+ throw SQLException( "Row index is out of valid range.", *this, OUString(),1, Any() );
}
}
// -------------------------------------------------------------------------
@@ -445,8 +395,6 @@ uno::Reference< XInputStream > SAL_CALL OResultSet::getBinaryStream( sal_Int32 c
(void) columnIndex;
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
- ensureDataAvailable();
-
return NULL;
}
@@ -456,8 +404,6 @@ uno::Reference< XInputStream > SAL_CALL OResultSet::getCharacterStream( sal_Int3
(void) columnIndex;
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
- ensureDataAvailable();
-
return NULL;
}
@@ -466,11 +412,11 @@ uno::Reference< XInputStream > SAL_CALL OResultSet::getCharacterStream( sal_Int3
const ORowSetValue& OResultSet::safelyRetrieveValue(sal_Int32 columnIndex)
throw(SQLException)
{
+ (void) columnIndex;
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
- ensureDataAvailable();
-
- return getSqlData(m_currentRow,columnIndex);
+ throw SQLException(); // Temporary until we've reimplemented everythign
+// return getSqlData(m_currentRow,columnIndex);
}
sal_Bool SAL_CALL OResultSet::getBoolean(sal_Int32 columnIndex)
@@ -547,8 +493,6 @@ uno::Reference< XResultSetMetaData > SAL_CALL OResultSet::getMetaData( ) throw(
{
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
- ensureDataAvailable();
-
if(!m_xMetaData.is())
m_xMetaData = new OResultSetMetaData(m_xStatement->getConnection());
@@ -560,7 +504,6 @@ uno::Reference< XArray > SAL_CALL OResultSet::getArray( sal_Int32 columnIndex )
(void) columnIndex;
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
- ensureDataAvailable();
return NULL;
}
@@ -572,7 +515,6 @@ uno::Reference< XClob > SAL_CALL OResultSet::getClob( sal_Int32 columnIndex ) th
(void) columnIndex;
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
- ensureDataAvailable();
return NULL;
}
@@ -582,7 +524,6 @@ uno::Reference< XBlob > SAL_CALL OResultSet::getBlob( sal_Int32 columnIndex ) th
(void) columnIndex;
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
- ensureDataAvailable();
return NULL;
}
@@ -593,7 +534,6 @@ uno::Reference< XRef > SAL_CALL OResultSet::getRef( sal_Int32 columnIndex ) thro
(void) columnIndex;
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
- ensureDataAvailable();
return NULL;
}
@@ -605,7 +545,6 @@ Any SAL_CALL OResultSet::getObject( sal_Int32 columnIndex, const uno::Reference<
(void) typeMap;
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
- ensureDataAvailable();
return Any();
}
diff --git a/connectivity/source/drivers/firebird/FResultSet.hxx b/connectivity/source/drivers/firebird/FResultSet.hxx
index b79b6c7e7112..b98b4ba1a2f9 100644
--- a/connectivity/source/drivers/firebird/FResultSet.hxx
+++ b/connectivity/source/drivers/firebird/FResultSet.hxx
@@ -61,10 +61,6 @@ namespace connectivity
{
namespace firebird
{
-
- typedef ::std::vector< ::connectivity::ORowSetValue > TRow;
- typedef ::std::vector< TRow > TTable;
-
/*
** OResultSet
*/
@@ -93,20 +89,19 @@ namespace connectivity
XSQLDA* m_pSqlda;
isc_stmt_handle m_statementHandle;
- sal_Bool m_bIsPopulated;
- sal_Bool m_bWasNull;
+ bool m_bWasNull;
// Row numbering starts with 0 for "in front of first row"
sal_Int32 m_currentRow;
- sal_Int32 m_rowCount;
+ bool m_bIsAfterLastRow;
+
const sal_Int32 m_fieldCount;
- TTable m_sqlData;
ISC_STATUS_ARRAY m_statusVector;
- void ensureDataAvailable()
- throw (::com::sun::star::sdbc::SQLException);
- const ::connectivity::ORowSetValue& getSqlData(sal_Int32 aRow, sal_Int32 aColumn)
- throw (::com::sun::star::sdbc::SQLException);
+// void ensureDataAvailable()
+// throw (::com::sun::star::sdbc::SQLException);
+// const ::connectivity::ORowSetValue& getSqlData(sal_Int32 aRow, sal_Int32 aColumn)
+// throw (::com::sun::star::sdbc::SQLException);
const ::connectivity::ORowSetValue& safelyRetrieveValue(sal_Int32 columnIndex)
throw(::com::sun::star::sdbc::SQLException);
@@ -135,7 +130,8 @@ namespace connectivity
virtual void SAL_CALL checkColumnIndex( sal_Int32 index )
throw ( com::sun::star::sdbc::SQLException, com::sun::star::uno::RuntimeException );
- virtual void SAL_CALL checkRowIndex( sal_Bool mustBeOnValidRow );
+ virtual void SAL_CALL checkRowIndex()
+ throw ( com::sun::star::sdbc::SQLException);
// you can't delete objects of this type
virtual ~OResultSet();