1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//! MySQL implementation of `execute_raw_sql`.
//!
//! Executes one or more SQL statements against a MySQL database and returns
//! a [`Vec<SqlResult>`] — one entry per statement.
use TryStreamExt;
use ;
use Either;
use crateSqlResult;
/// Execute one or more SQL statements against a MySQL database.
///
/// Supports multiple statements separated by `;`.
/// Each statement that produces rows (SELECT, SHOW, EXPLAIN, etc.) is automatically
/// converted to JSON via [`crate::to_json::mysql::to_json`] and returned as a
/// [`SqlResult::Query`]. Statements that do not produce rows return a
/// [`SqlResult::Execute`] with the count of affected rows.
///
/// # Arguments
///
/// * `pool` - MySQL connection pool
/// * `sql` - SQL string; may contain multiple statements separated by `;`
///
/// # Returns
///
/// A [`Vec<SqlResult>`] with one entry per statement result, in execution order.
///
/// # Multi-statement Support
///
/// MySQL requires the `CLIENT_MULTI_STATEMENTS` flag to be enabled for multi-statement
/// execution. With `sqlx`, either append `?multi_statements=on` to your connection URL
/// or call [`sqlx::mysql::MySqlConnectOptions::multi_statements`]`(true)` when building
/// the pool options.
///
/// ```text
/// mysql://user:pass@host/db?multi_statements=on
/// ```
///
/// # Example
///
/// ```rust,no_run
/// # use sqlx::mysql::MySqlPool;
/// # async fn run(pool: &MySqlPool) -> anyhow::Result<()> {
/// let results = dbcli::execute::mysql::execute_raw_sql(
/// pool,
/// "INSERT INTO users(name) VALUES('alice'); SELECT * FROM users;",
/// ).await?;
///
/// for result in &results {
/// println!("{}", serde_json::to_string_pretty(result)?);
/// }
/// # Ok(())
/// # }
/// ```
pub async