Ensure foreach range is computed before iterating over (#2492)

This commit is contained in:
Tobie Morgan Hitchcock 2023-08-22 17:45:22 +01:00 committed by GitHub
parent ac35111833
commit b1275ed565
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View file

@ -35,7 +35,7 @@ impl ForeachStatement {
doc: Option<&CursorDoc<'_>>,
) -> Result<Value, Error> {
// 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() {

View file

@ -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 <future> { [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);