Skip to content

Commit

Permalink
fix count
Browse files Browse the repository at this point in the history
Signed-off-by: xxchan <[email protected]>
  • Loading branch information
xxchan committed Nov 16, 2024
1 parent 1d6542d commit d48f7c4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- runner: Previously, `query` returning 0 rows will become `statement ok`. Now it returns `statement count 0`.
- bin: Now `--override` will not change the type chars of `query <types>`, since in practice
it becomes `?`s which might cause confusion.
* runner: `statement count <n>` is incorrectly handled when the result is a `query`.

## [0.22.1] - 2024-11-11

Expand Down
24 changes: 21 additions & 3 deletions sqllogictest/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,9 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {
Record::Statement {
sql, expected, loc, ..
},
RecordOutput::Query { error: None, .. },
RecordOutput::Query {
error: None, rows, ..
},
) => {
if let StatementExpect::Error(_) = expected {
return Err(TestErrorKind::Ok {
Expand All @@ -858,6 +860,16 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {
}
.at(loc));
}
if let StatementExpect::Count(expected_count) = expected {
if expected_count != rows.len() as u64 {
return Err(TestErrorKind::StatementResultMismatch {
sql,
expected: expected_count,
actual: format!("returned {} rows", rows.len()),
}
.at(loc));
}
}
}
(
Record::Query {
Expand Down Expand Up @@ -1383,9 +1395,11 @@ pub fn update_record_with_output<T: ColumnType>(
loc,
conditions,
connection,
expected: expected @ (StatementExpect::Ok | StatementExpect::Count(_)),
expected: mut expected @ (StatementExpect::Ok | StatementExpect::Count(_)),
},
RecordOutput::Query {
error: None, rows, ..
},
RecordOutput::Query { error: None, .. },
) => {
// statement ok
// SELECT ...
Expand All @@ -1394,6 +1408,10 @@ pub fn update_record_with_output<T: ColumnType>(
// but don't care about the output.
// DuckDB has a few of these.

if let StatementExpect::Count(expected_count) = &mut expected {
*expected_count = rows.len() as u64;
}

Some(Record::Statement {
sql,
loc,
Expand Down

0 comments on commit d48f7c4

Please sign in to comment.