Skip to content

Commit

Permalink
Fix at() and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Jan 13, 2021
1 parent a717bc7 commit d3bed16
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/qgsabstractdatabaseproviderconnection.cpp
Expand Up @@ -477,9 +477,9 @@ QList<QVariant> QgsAbstractDatabaseProviderConnection::QueryResult::at( qlonglon
if ( index < 0 )
return QList<QVariant>();
// Fetch rows until the index
if ( index > mRows.count( ) )
if ( index >= mRows.count( ) )
{
while ( mResultIterator && ( mRowCount < 0 || mRows.count() < mRowCount ) && index < mRows.count() )
while ( mResultIterator && ( mRowCount < 0 || mRows.count() < mRowCount ) && index >= mRows.count() )
{
const QVariantList row { mResultIterator->nextRow() };
if ( row.isEmpty() )
Expand Down
10 changes: 10 additions & 0 deletions tests/src/python/test_qgsproviderconnection_base.py
Expand Up @@ -260,6 +260,16 @@ def _test_operations(self, md, conn):
# But we still have access to rows:
self.assertEqual(rows, res.rows())

# Test iterator at
self.assertEqual(res.at(0), rows[0])

res = conn.execSql(sql)
self.assertEqual(res.at(0), rows[0])

self.assertEqual(res.at(-1), [])
self.assertEqual(res.at(10000), [])

# Test time_t
sql = "SELECT \"time_t\" FROM %s" % table
res = conn.executeSql(sql)

Expand Down

0 comments on commit d3bed16

Please sign in to comment.