From 7dfbc4b8d12986f6a23b38c6d81b66b25f9ef882 Mon Sep 17 00:00:00 2001 From: gwenn Date: Wed, 22 Nov 2023 20:31:47 +0100 Subject: [PATCH 1/2] Show pathological cases --- src/row.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/row.rs b/src/row.rs index 2d25900..d9022b2 100644 --- a/src/row.rs +++ b/src/row.rs @@ -585,4 +585,24 @@ mod tests { // We don't test one bigger because it's unimplemented Ok(()) } + + #[test] + #[cfg(feature = "bundled")] + fn pathological_case() -> Result<()> { + let conn = Connection::open_in_memory()?; + conn.execute_batch( + "CREATE TABLE foo(x); + CREATE TRIGGER oops BEFORE INSERT ON foo BEGIN SELECT RAISE(FAIL, 'Boom'); END;", + )?; + let mut stmt = conn.prepare("INSERT INTO foo VALUES (0) RETURNING rowid;")?; + { + let n = stmt.query_map([], |_| Ok(()))?.count(); + assert_eq!(1, n); // should be 0 + } + { + let last = stmt.query_map([], |_| Ok(()))?.last(); + assert!(last.is_some()); // should be none + } + Ok(()) + } } From 50dca916988e20f6fb0462a65729b4564fb70607 Mon Sep 17 00:00:00 2001 From: gwenn Date: Fri, 24 Nov 2023 20:09:45 +0100 Subject: [PATCH 2/2] Standard iterator vs Fallible iterator --- src/row.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/row.rs b/src/row.rs index d9022b2..64873d1 100644 --- a/src/row.rs +++ b/src/row.rs @@ -596,12 +596,18 @@ mod tests { )?; let mut stmt = conn.prepare("INSERT INTO foo VALUES (0) RETURNING rowid;")?; { - let n = stmt.query_map([], |_| Ok(()))?.count(); - assert_eq!(1, n); // should be 0 + let iterator_count = stmt.query_map([], |_| Ok(()))?.count(); + assert_eq!(1, iterator_count); // should be 0 + use fallible_streaming_iterator::FallibleStreamingIterator; + let fallible_iterator_count = stmt.query([])?.count().unwrap_or(0); + assert_eq!(0, fallible_iterator_count); } { - let last = stmt.query_map([], |_| Ok(()))?.last(); - assert!(last.is_some()); // should be none + let iterator_last = stmt.query_map([], |_| Ok(()))?.last(); + assert!(iterator_last.is_some()); // should be none + use fallible_iterator::FallibleIterator; + let fallible_iterator_last = stmt.query([])?.map(|_| Ok(())).last(); + assert!(fallible_iterator_last.is_err()); } Ok(()) }