Splits a string which consists of multiple queries.
(sql: &str)
| 182 | |
| 183 | /// Splits a string which consists of multiple queries. |
| 184 | pub(crate) fn split_from_semicolon(sql: &str) -> Vec<String> { |
| 185 | let mut commands = Vec::new(); |
| 186 | let mut current_command = String::new(); |
| 187 | let mut in_single_quote = false; |
| 188 | let mut in_double_quote = false; |
| 189 | |
| 190 | for c in sql.chars() { |
| 191 | if c == '\'' && !in_double_quote { |
| 192 | in_single_quote = !in_single_quote; |
| 193 | } else if c == '"' && !in_single_quote { |
| 194 | in_double_quote = !in_double_quote; |
| 195 | } |
| 196 | |
| 197 | if c == ';' && !in_single_quote && !in_double_quote { |
| 198 | if !current_command.trim().is_empty() { |
| 199 | commands.push(format!("{};", current_command.trim())); |
| 200 | current_command.clear(); |
| 201 | } |
| 202 | } else { |
| 203 | current_command.push(c); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | if !current_command.trim().is_empty() { |
| 208 | commands.push(format!("{};", current_command.trim())); |
| 209 | } |
| 210 | |
| 211 | commands |
| 212 | } |
| 213 | |
| 214 | #[cfg(test)] |
| 215 | mod tests { |
no test coverage detected
searching dependent graphs…