(
upper: &str,
parts: &[&str],
trimmed: &str,
)
| 30 | } |
| 31 | |
| 32 | pub(super) fn try_parse( |
| 33 | upper: &str, |
| 34 | parts: &[&str], |
| 35 | trimmed: &str, |
| 36 | ) -> Option<Result<NodedbStatement, SqlError>> { |
| 37 | (|| -> Result<Option<NodedbStatement>, SqlError> { |
| 38 | if upper.starts_with("CREATE SCHEDULE ") { |
| 39 | return Ok(Some(parse_create_schedule(upper, trimmed))); |
| 40 | } |
| 41 | if upper.starts_with("DROP SCHEDULE ") { |
| 42 | let if_exists = upper.contains("IF EXISTS"); |
| 43 | let name = match extract_name_after_if_exists(parts, "SCHEDULE") { |
| 44 | None => return Ok(None), |
| 45 | Some(r) => r?, |
| 46 | }; |
| 47 | return Ok(Some(NodedbStatement::Automation( |
| 48 | AutomationStmt::DropSchedule { name, if_exists }, |
| 49 | ))); |
| 50 | } |
| 51 | if upper.starts_with("ALTER SCHEDULE ") { |
| 52 | // ALTER SCHEDULE <name> ENABLE | DISABLE | SET CRON '<expr>' |
| 53 | let name = parts.get(2).map(|s| s.to_lowercase()).unwrap_or_default(); |
| 54 | let action = parts.get(3).map(|s| s.to_uppercase()).unwrap_or_default(); |
| 55 | // When action is "SET CRON", extract the quoted cron expression. |
| 56 | let cron_expr = if action == "SET" { |
| 57 | extract_quoted_cron(trimmed) |
| 58 | } else { |
| 59 | None |
| 60 | }; |
| 61 | return Ok(Some(NodedbStatement::Automation( |
| 62 | AutomationStmt::AlterSchedule { |
| 63 | name, |
| 64 | action, |
| 65 | cron_expr, |
| 66 | }, |
| 67 | ))); |
| 68 | } |
| 69 | if upper.starts_with("SHOW SCHEDULE HISTORY ") { |
| 70 | let name = match parts.get(3) { |
| 71 | None => return Ok(None), |
| 72 | Some(s) => s.to_string(), |
| 73 | }; |
| 74 | return Ok(Some(NodedbStatement::Automation( |
| 75 | AutomationStmt::ShowScheduleHistory { name }, |
| 76 | ))); |
| 77 | } |
| 78 | if upper == "SHOW SCHEDULES" || upper.starts_with("SHOW SCHEDULES") { |
| 79 | return Ok(Some(NodedbStatement::Automation( |
| 80 | AutomationStmt::ShowSchedules, |
| 81 | ))); |
| 82 | } |
| 83 | Ok(None) |
| 84 | })() |
| 85 | .transpose() |
| 86 | } |
| 87 | |
| 88 | /// Structural extraction for `CREATE SCHEDULE`. |
| 89 | /// |
nothing calls this directly
no test coverage detected