diff --git a/lib/src/sql/statements/foreach.rs b/lib/src/sql/statements/foreach.rs index 1d1ec698..85b227a0 100644 --- a/lib/src/sql/statements/foreach.rs +++ b/lib/src/sql/statements/foreach.rs @@ -35,7 +35,7 @@ impl ForeachStatement { doc: Option<&CursorDoc<'_>>, ) -> Result { // Check the loop data - match &self.range { + match &self.range.compute(ctx, opt, txn, doc).await? { Value::Array(arr) => { // Loop over the values 'foreach: for v in arr.iter() { diff --git a/lib/tests/foreach.rs b/lib/tests/foreach.rs index 2526c56a..439356d2 100644 --- a/lib/tests/foreach.rs +++ b/lib/tests/foreach.rs @@ -16,13 +16,13 @@ async fn foreach() -> Result<(), Error> { }; SELECT * FROM person; FOR $test in [4, 5, 6] { - IF $test >= 5 { + IF $test == 5 { CONTINUE; }; UPDATE type::thing('person', $test) SET test = $test; }; SELECT * FROM person; - FOR $test in [7, 8, 9] { + FOR $test in { [7, 8, 9] } { IF $test > 8 { THROW 'This is an error'; }; @@ -63,6 +63,10 @@ async fn foreach() -> Result<(), Error> { id: person:4, test: 4, }, + { + id: person:6, + test: 6, + }, ]", ); assert_eq!(tmp, val); @@ -81,6 +85,10 @@ async fn foreach() -> Result<(), Error> { id: person:4, test: 4, }, + { + id: person:6, + test: 6, + }, ]", ); assert_eq!(tmp, val);