Ensure foreach range is computed before iterating over (#2492)
This commit is contained in:
parent
ac35111833
commit
b1275ed565
2 changed files with 11 additions and 3 deletions
|
@ -35,7 +35,7 @@ impl ForeachStatement {
|
||||||
doc: Option<&CursorDoc<'_>>,
|
doc: Option<&CursorDoc<'_>>,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
// Check the loop data
|
// Check the loop data
|
||||||
match &self.range {
|
match &self.range.compute(ctx, opt, txn, doc).await? {
|
||||||
Value::Array(arr) => {
|
Value::Array(arr) => {
|
||||||
// Loop over the values
|
// Loop over the values
|
||||||
'foreach: for v in arr.iter() {
|
'foreach: for v in arr.iter() {
|
||||||
|
|
|
@ -16,13 +16,13 @@ async fn foreach() -> Result<(), Error> {
|
||||||
};
|
};
|
||||||
SELECT * FROM person;
|
SELECT * FROM person;
|
||||||
FOR $test in [4, 5, 6] {
|
FOR $test in [4, 5, 6] {
|
||||||
IF $test >= 5 {
|
IF $test == 5 {
|
||||||
CONTINUE;
|
CONTINUE;
|
||||||
};
|
};
|
||||||
UPDATE type::thing('person', $test) SET test = $test;
|
UPDATE type::thing('person', $test) SET test = $test;
|
||||||
};
|
};
|
||||||
SELECT * FROM person;
|
SELECT * FROM person;
|
||||||
FOR $test in [7, 8, 9] {
|
FOR $test in <future> { [7, 8, 9] } {
|
||||||
IF $test > 8 {
|
IF $test > 8 {
|
||||||
THROW 'This is an error';
|
THROW 'This is an error';
|
||||||
};
|
};
|
||||||
|
@ -63,6 +63,10 @@ async fn foreach() -> Result<(), Error> {
|
||||||
id: person:4,
|
id: person:4,
|
||||||
test: 4,
|
test: 4,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: person:6,
|
||||||
|
test: 6,
|
||||||
|
},
|
||||||
]",
|
]",
|
||||||
);
|
);
|
||||||
assert_eq!(tmp, val);
|
assert_eq!(tmp, val);
|
||||||
|
@ -81,6 +85,10 @@ async fn foreach() -> Result<(), Error> {
|
||||||
id: person:4,
|
id: person:4,
|
||||||
test: 4,
|
test: 4,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: person:6,
|
||||||
|
test: 6,
|
||||||
|
},
|
||||||
]",
|
]",
|
||||||
);
|
);
|
||||||
assert_eq!(tmp, val);
|
assert_eq!(tmp, val);
|
||||||
|
|
Loading…
Reference in a new issue