mz_testdrive/action/sql_server/
execute.rs1use anyhow::{Context, anyhow};
11use mz_ore::str::StrExt;
12
13use crate::action::{ControlFlow, State};
14use crate::parser::BuiltinCommand;
15
16pub async fn run_execute(
17 mut cmd: BuiltinCommand,
18 state: &mut State,
19) -> Result<ControlFlow, anyhow::Error> {
20 let name = cmd.args.string("name")?;
21 let split_lines = cmd.args.opt_bool("split-lines")?.unwrap_or(true);
22 cmd.args.done()?;
23
24 let client = state
25 .sql_server_clients
26 .get_mut(&name)
27 .ok_or_else(|| anyhow!("connection {} not found", name.quoted()))?;
28
29 if split_lines {
30 for query in cmd.input {
31 println!(">> {}", query);
32 client
33 .simple_query(query)
34 .await
35 .context("executing SQL Server query")?;
36 }
37 } else {
38 let query = cmd.input.join("\n");
39 println!(">> {}", query);
40 client
43 .simple_query(query)
44 .await
45 .context("executing SQL Server query")?;
46 }
47
48 Ok(ControlFlow::Continue)
49}