Returns Some(intent) if the SQL is one of the recognised wire-COPY shapes. Tokenisation is whitespace-only and case-insensitive on keywords.
(sql: &str)
| 16 | /// Returns Some(intent) if the SQL is one of the recognised wire-COPY shapes. |
| 17 | /// Tokenisation is whitespace-only and case-insensitive on keywords. |
| 18 | pub fn detect(sql: &str) -> Option<CopyIntent> { |
| 19 | let trimmed = sql.trim().trim_end_matches(';').trim(); |
| 20 | let upper = trimmed.to_ascii_uppercase(); |
| 21 | |
| 22 | // Quick reject: every recognised shape starts with COPY. |
| 23 | if !upper.starts_with("COPY ") && !upper.starts_with("COPY\t") { |
| 24 | return None; |
| 25 | } |
| 26 | |
| 27 | if let Some(intent) = match_backup(trimmed, &upper) { |
| 28 | return Some(intent); |
| 29 | } |
| 30 | if let Some(intent) = match_restore(trimmed, &upper) { |
| 31 | return Some(intent); |
| 32 | } |
| 33 | None |
| 34 | } |
| 35 | |
| 36 | fn match_backup(sql: &str, upper: &str) -> Option<CopyIntent> { |
| 37 | // Pattern: COPY ( BACKUP TENANT <id> ) TO STDOUT |