Skip to content

Commit a8c3937

Browse files
committed
[SF 2593784] SVN trunk RowIterator
1 parent 08efaa0 commit a8c3937

6 files changed

Lines changed: 44 additions & 10 deletions

File tree

‎Data/ODBC/testsuite/src/SQLExecutor.cpp‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3036,6 +3036,13 @@ void SQLExecutor::rowIterator()
30363036
v.push_back(Tuple<int, double, std::string>(3, 3.5f, "5"));
30373037
v.push_back(Tuple<int, double, std::string>(4, 4.5f, "6"));
30383038

3039+
try { session() << "DELETE FROM Vectors", now; }
3040+
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
3041+
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
3042+
3043+
RecordSet rset0(session(), "SELECT * FROM Vectors");
3044+
assert (rset0.begin() == rset0.end());
3045+
30393046
try { session() << "INSERT INTO Vectors VALUES (?,?,?)", use(v), now; }
30403047
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
30413048
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
@@ -3058,7 +3065,7 @@ void SQLExecutor::rowIterator()
30583065

30593066
RowFilter::Ptr pRF = new RowFilter(&rset);
30603067
assert (pRF->isEmpty());
3061-
pRF->add("str0", RowFilter::VALUE_EQUAL, 1);
3068+
pRF->add("str0", RowFilter::VALUE_EQUAL, "3");
30623069
assert (!pRF->isEmpty());
30633070
it = rset.begin();
30643071
end = rset.end();
@@ -3067,7 +3074,6 @@ void SQLExecutor::rowIterator()
30673074
assert (it->get(0) == i);
30683075
assert (1 == i);
30693076
}
3070-
30713077
}
30723078

30733079

‎Data/include/Poco/Data/RecordSet.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,7 @@ inline Data_API std::ostream& operator << (std::ostream &os, const RecordSet& rs
450450

451451
inline std::size_t RecordSet::totalRowCount() const
452452
{
453-
poco_assert (extractions().size());
454-
return extractions()[0].get()->numOfRowsHandled();
453+
return rowsExtracted();
455454
}
456455

457456

‎Data/include/Poco/Data/Statement.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ class Data_API Statement
369369
const std::string& getStorage() const;
370370
/// Returns the internal storage type for the stamement.
371371

372+
std::size_t rowsExtracted(int dataSet = -1) const;
373+
/// Returns the number of rows returned for current data set.
374+
/// Default value (-1) indicates current data set (if any).
375+
372376
std::size_t extractionCount() const;
373377
/// Returns the number of extraction storage buffers associated
374378
/// with the current data set.
@@ -701,6 +705,12 @@ inline std::size_t Statement::extractionCount() const
701705
}
702706

703707

708+
inline std::size_t Statement::rowsExtracted(int dataSet) const
709+
{
710+
return _pImpl->rowsExtracted(dataSet);
711+
}
712+
713+
704714
inline std::size_t Statement::dataSetCount() const
705715
{
706716
return _pImpl->dataSetCount();

‎Data/include/Poco/Data/StatementImpl.h‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,13 @@ class Data_API StatementImpl: public Poco::RefCountedObject
218218
virtual AbstractBinder& binder() = 0;
219219
/// Returns the concrete binder used by the statement.
220220

221-
int columnsExtracted() const;
221+
std::size_t columnsExtracted() const;
222222
/// Returns the number of columns that the extractors handle.
223223

224+
std::size_t rowsExtracted(int dataSet = -1) const;
225+
/// Returns the number of rows returned for current data set.
226+
/// Default value (-1) indicates current data set (if any).
227+
224228
const AbstractBindingVec& bindings() const;
225229
/// Returns the bindings.
226230

@@ -486,7 +490,7 @@ inline AbstractExtractionVec& StatementImpl::extractions()
486490
}
487491

488492

489-
inline int StatementImpl::columnsExtracted() const
493+
inline std::size_t StatementImpl::columnsExtracted() const
490494
{
491495
poco_assert (_curDataSet < _columnsExtracted.size());
492496
return _columnsExtracted[_curDataSet];

‎Data/src/RecordSet.cpp‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace Data {
5454
RecordSet::RecordSet(const Statement& rStatement):
5555
Statement(rStatement),
5656
_currentRow(0),
57-
_pBegin(new RowIterator(this, 0 == extractionCount())),
57+
_pBegin(new RowIterator(this, 0 == rowsExtracted())),
5858
_pEnd(new RowIterator(this, true)),
5959
_pFilter(0)
6060
{
@@ -66,7 +66,7 @@ RecordSet::RecordSet(Session& rSession,
6666
RowFormatter* pRowFormatter):
6767
Statement((rSession << query, now)),
6868
_currentRow(0),
69-
_pBegin(new RowIterator(this, 0 == extractionCount())),
69+
_pBegin(new RowIterator(this, 0 == rowsExtracted())),
7070
_pEnd(new RowIterator(this, true)),
7171
_pFilter(0)
7272
{
@@ -77,7 +77,7 @@ RecordSet::RecordSet(Session& rSession,
7777
RecordSet::RecordSet(const RecordSet& other):
7878
Statement(other.impl().duplicate()),
7979
_currentRow(other._currentRow),
80-
_pBegin(new RowIterator(this, 0 == extractionCount())),
80+
_pBegin(new RowIterator(this, 0 == rowsExtracted())),
8181
_pEnd(new RowIterator(this, true)),
8282
_pFilter(other._pFilter)
8383
{
@@ -161,7 +161,8 @@ Poco::Dynamic::Var RecordSet::value(const std::string& name, std::size_t row, bo
161161

162162
Row& RecordSet::row(std::size_t pos)
163163
{
164-
if (pos > rowCount() - 1)
164+
std::size_t rowCnt = rowCount();
165+
if (0 == rowCnt || pos > rowCnt - 1)
165166
throw RangeException("Invalid recordset row requested.");
166167

167168
RowMap::const_iterator it = _rowMap.find(pos);

‎Data/src/StatementImpl.cpp‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,20 @@ void StatementImpl::removeBind(const std::string& name)
394394
}
395395

396396

397+
std::size_t StatementImpl::rowsExtracted(int dataSet) const
398+
{
399+
if (-1 == dataSet) dataSet = _curDataSet;
400+
if (extractions().size() > 0)
401+
{
402+
poco_assert (dataSet >= 0);
403+
if (_extractors[dataSet].size() > 0)
404+
return _extractors[dataSet][0]->numOfRowsHandled();
405+
}
406+
407+
return 0;
408+
}
409+
410+
397411
void StatementImpl::formatSQL(std::vector<Any>& arguments)
398412
{
399413
std::string sql;

0 commit comments

Comments
 (0)