diff --git a/lib/DBDish/SQLite/StatementHandle.pm6 b/lib/DBDish/SQLite/StatementHandle.pm6 index f52304ee..14d05d62 100644 --- a/lib/DBDish/SQLite/StatementHandle.pm6 +++ b/lib/DBDish/SQLite/StatementHandle.pm6 @@ -12,6 +12,8 @@ has $!statement_handle; has $!param-count; has Int $!row_status; has $!field_count; +has Bool $!warn-on-inaccurate-rows = True; +has Bool $!rows-is-accurate = False; method !handle-error(Int $status) { unless $status == SQLITE_OK { @@ -46,6 +48,16 @@ method execute(*@params is raw --> DBDish::StatementHandle) { self!set-err($!row_status, sqlite3_errmsg($!conn)); } } +my role IntTrue { method Bool { self.defined } }; + +# Override DBDish::StatementHandle to throw this error +method rows() { + if (not $!rows-is-accurate and $!warn-on-inaccurate-rows) { + warn "SQLite rows result may not be accurate. " + } + + self._rows(); +} method _row() { my $list = (); @@ -71,6 +83,8 @@ method _row() { $!affected_rows++; self.reset-err; if ($!row_status = sqlite3_step($!statement_handle)) == SQLITE_DONE { + # Only after retrieving the final record is the rows value considered accurate. + $!rows-is-accurate = True; self.finish; } } diff --git a/lib/DBDish/StatementHandle.pm6 b/lib/DBDish/StatementHandle.pm6 index d9be67b4..6c65ff1b 100644 --- a/lib/DBDish/StatementHandle.pm6 +++ b/lib/DBDish/StatementHandle.pm6 @@ -71,7 +71,9 @@ submethod DESTROY() { self.dispose; } -method rows { +method rows() {self._rows} + +method _rows { my constant TRUE_ZERO = 0 but IntTrue; $!affected_rows.defined ?? $!affected_rows || TRUE_ZERO