Bugfix - CLI show results despite errors in multistatement query. (#2040)
This commit is contained in:
parent
5e0e72def2
commit
33c35949b7
2 changed files with 56 additions and 2 deletions
|
@ -178,7 +178,10 @@ fn process(pretty: bool, res: surrealdb::Result<Response>) -> Result<String, Err
|
|||
let value = if num_statements > 1 {
|
||||
let mut output = Vec::<Value>::with_capacity(num_statements);
|
||||
for index in 0..num_statements {
|
||||
output.push(response.take(index)?);
|
||||
output.push(match response.take(index) {
|
||||
Ok(v) => v,
|
||||
Err(e) => e.to_string().into(),
|
||||
});
|
||||
}
|
||||
Value::from(output)
|
||||
} else {
|
||||
|
@ -209,7 +212,7 @@ impl Validator for InputValidator {
|
|||
let input = input.trim();
|
||||
// Process the input to check if we can send the query
|
||||
let result = if self.multi && !input.ends_with(';') {
|
||||
Incomplete // The line ends with a ; and we are in multi mode
|
||||
Incomplete // The line doesn't end with a ; and we are in multi mode
|
||||
} else if self.multi && input.is_empty() {
|
||||
Incomplete // The line was empty and we are in multi mode
|
||||
} else if input.ends_with('\\') {
|
||||
|
|
51
tests/cli.rs
51
tests/cli.rs
|
@ -174,6 +174,57 @@ mod cli_integration {
|
|||
// TODO: Once backups are functional, update this test.
|
||||
assert_eq!(fs::read_to_string(file).unwrap(), "Save");
|
||||
}
|
||||
|
||||
// Multi-statement (and multi-line) query including error(s) over WS
|
||||
{
|
||||
let args = format!(
|
||||
"sql --conn ws://{addr} --user root --pass {pass} --ns N3 --db D3 --multi --pretty"
|
||||
);
|
||||
let output = run(&args)
|
||||
.input(
|
||||
r#"CREATE thing:success; \
|
||||
CREATE thing:fail SET bad=rand('evil'); \
|
||||
SELECT * FROM sleep(10ms) TIMEOUT 1ms; \
|
||||
CREATE thing:also_success;
|
||||
"#,
|
||||
)
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
assert!(output.contains("thing:success"), "missing success in {output:?}");
|
||||
assert!(output.contains("rgument"), "missing argument error in {output:?}");
|
||||
assert!(
|
||||
output.contains("time") && output.contains("out"),
|
||||
"missing timeout error in {output:?}"
|
||||
);
|
||||
assert!(output.contains("thing:also_success"), "missing also_success in {output:?}")
|
||||
}
|
||||
|
||||
// Multi-statement (and multi-line) transaction including error(s) over WS
|
||||
{
|
||||
let args = format!(
|
||||
"sql --conn ws://{addr} --user root --pass {pass} --ns N4 --db D4 --multi --pretty"
|
||||
);
|
||||
let output = run(&args)
|
||||
.input(
|
||||
r#"BEGIN; \
|
||||
CREATE thing:success; \
|
||||
CREATE thing:fail SET bad=rand('evil'); \
|
||||
SELECT * FROM sleep(10ms) TIMEOUT 1ms; \
|
||||
CREATE thing:also_success; \
|
||||
COMMIT;
|
||||
"#,
|
||||
)
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
output.lines().filter(|s| s.contains("transaction")).count(),
|
||||
3,
|
||||
"missing failed txn errors in {output:?}"
|
||||
);
|
||||
assert!(output.contains("rgument"), "missing argument error in {output:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue