MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / run_execute

Function run_execute

src/testdrive/src/action/sql_server/execute.rs:68–122  ·  view source on GitHub ↗
(
    mut cmd: BuiltinCommand,
    state: &mut State,
)

Source from the content-addressed store, hash-verified

66}
67
68pub async fn run_execute(
69 mut cmd: BuiltinCommand,
70 state: &mut State,
71) -> Result<ControlFlow, anyhow::Error> {
72 let name = cmd.args.string("name")?;
73 let split_lines = cmd.args.opt_bool("split-lines")?.unwrap_or(true);
74 // When set, wraps the SQL in a Transaction and then drops it without
75 // calling commit or rollback. Used to test that Transaction::drop sends
76 // ROLLBACK correctly.
77 let abandon_txn = cmd.args.opt_bool("abandon-txn")?.unwrap_or(false);
78 cmd.args.done()?;
79
80 let client = state
81 .sql_server_clients
82 .get_mut(&name)
83 .ok_or_else(|| anyhow!("connection {} not found", name.quoted()))?;
84
85 if abandon_txn {
86 let mut txn = client
87 .transaction()
88 .await
89 .context("begin transaction for abandon-txn")?;
90 if split_lines {
91 for query in &cmd.input {
92 println!(">> (abandon-txn) {}", query);
93 txn.simple_query(query.to_string())
94 .await
95 .context("executing SQL Server query in transaction")?;
96 }
97 } else {
98 let query = cmd.input.join("\n");
99 println!(">> (abandon-txn) {}", query);
100 txn.simple_query(query)
101 .await
102 .context("executing SQL Server query in transaction")?;
103 }
104 // Transaction dropped here without commit or rollback.
105 // If Drop is correct, a ROLLBACK is sent via the channel.
106 } else {
107 if split_lines {
108 for query in &cmd.input {
109 println!(">> {}", query);
110 execute_with_retry(client, query).await?;
111 }
112 } else {
113 let query = cmd.input.join("\n");
114 println!(">> {}", query);
115 // execute uses prepared statements, which will fail for CREATE FUNCTION/PROCEDURE etc, see
116 // https://github.com/prisma/tiberius/issues/236, so using simple_query instead
117 execute_with_retry(client, &query).await?;
118 }
119 }
120
121 Ok(ControlFlow::Continue)
122}

Callers

nothing calls this directly

Calls 10

execute_with_retryFunction · 0.85
opt_boolMethod · 0.80
stringMethod · 0.45
doneMethod · 0.45
get_mutMethod · 0.45
contextMethod · 0.45
transactionMethod · 0.45
simple_queryMethod · 0.45
to_stringMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected