SQLiteCpp icon indicating copy to clipboard operation
SQLiteCpp copied to clipboard

Row: New class with iterators (WIP)

Open Kacperos155 opened this issue 3 years ago • 3 comments

What I'm trying to implement:

  • Iterators
  • Class Row with methods to get:
    • [x] Row number (from 0 to n)
    • [x] Column object
    • [x] Column ID from name
  • Internal code changes:
    • [x] Split row execution from SQLite::Statement - smaller files, better readability
    • [x] Better structure for weak_ptr with sqlite3_stmt
    • [x] Better enforcement of Column usage safety
  • Other:
    • [x] Fix SQLite::Statement move constructor (and re-enable this test)
    • [x] Documenting comments for all new changes
    • [x] Tests coverage for changes and new functionality
    • [x] Many, many small changes...

Examples:

SQLite::Statement query(database, queryStr);

for(const auto& row : query)
{
    for(const auto& column : row)
    {
        std::cout << column.getName() << ": ";
        std::cout << column.getText() << "\t";
    }
    std::cout << '\n';
}
SQLite::Statement query(database, queryStr);

for (auto it = query.begin(); it != query.end(); std::advance(it, 2))
{
    std::cout << "Table row: " << it->getRowNumber() << '\n';
}

std::for_each(query.begin(), query.end(), [](const SQLite::Row& row)
{
    std::cout << row.getColumn(0).getText() << '\n';
});

Kacperos155 avatar Jul 24 '22 16:07 Kacperos155

@SRombauts What do you think about this changes? Should this PR be separeted to smaller ones?

Kacperos155 avatar Jul 25 '22 12:07 Kacperos155

Ironically, I'd just done a simple iterator this morning before I saw yours. Mine was no where near as ambitious as yours, just basically a 80 line (mostly boiler-plate) wrapper around Statement.

dougnazar avatar Jul 25 '22 15:07 dougnazar

Iterator functionality is now working 😄 I am sure there isn't any API break excluding undefined behavior of Column class after destruction of Statement. Because of the scale of changes, I require code review to keep working on this. Also, this needs more test coverage, benchmarking and feedback, but I think any improvements to this should be in next PRs.

Kacperos155 avatar Aug 02 '22 01:08 Kacperos155