(
parts: &[&str],
original: &str,
)
| 8 | use super::with_options::parse_with_options; |
| 9 | |
| 10 | pub(super) fn parse_create_database( |
| 11 | parts: &[&str], |
| 12 | original: &str, |
| 13 | ) -> Result<NodedbStatement, SqlError> { |
| 14 | let mut idx = 2usize; // skip CREATE DATABASE |
| 15 | let if_not_exists = if parts.get(idx).map(|w| w.to_uppercase()).as_deref() == Some("IF") |
| 16 | && parts.get(idx + 1).map(|w| w.to_uppercase()).as_deref() == Some("NOT") |
| 17 | && parts.get(idx + 2).map(|w| w.to_uppercase()).as_deref() == Some("EXISTS") |
| 18 | { |
| 19 | idx += 3; |
| 20 | true |
| 21 | } else { |
| 22 | false |
| 23 | }; |
| 24 | |
| 25 | let name = parts |
| 26 | .get(idx) |
| 27 | .copied() |
| 28 | .ok_or_else(|| SqlError::Parse { |
| 29 | detail: "CREATE DATABASE requires a name".into(), |
| 30 | })? |
| 31 | .to_string(); |
| 32 | let name = name.trim_matches('"').to_string(); |
| 33 | |
| 34 | let options = parse_with_options(original); |
| 35 | |
| 36 | Ok(NodedbStatement::Database(DatabaseStmt::CreateDatabase { |
| 37 | name, |
| 38 | if_not_exists, |
| 39 | options, |
| 40 | })) |
| 41 | } |
| 42 | |
| 43 | #[cfg(test)] |
| 44 | mod tests { |
no test coverage detected