Extract table name from CREATE TABLE statement
(query: &str)
| 2679 | |
| 2680 | /// Extract table name from CREATE TABLE statement |
| 2681 | pub fn extract_table_name_from_create(query: &str) -> Option<String> { |
| 2682 | // Look for CREATE TABLE pattern with case-insensitive search |
| 2683 | let create_table_pos = query.as_bytes().windows(12) |
| 2684 | .position(|window| window.eq_ignore_ascii_case(b"CREATE TABLE"))?; |
| 2685 | |
| 2686 | let after_create = &query[create_table_pos + 12..].trim(); |
| 2687 | |
| 2688 | // Skip IF NOT EXISTS if present |
| 2689 | let after_create = if after_create.len() >= 13 && after_create[..13].eq_ignore_ascii_case("IF NOT EXISTS") { |
| 2690 | &after_create[13..].trim() |
| 2691 | } else { |
| 2692 | after_create |
| 2693 | }; |
| 2694 | |
| 2695 | // Find the end of table name |
| 2696 | let table_end = after_create.find(|c: char| { |
| 2697 | c.is_whitespace() || c == '(' |
| 2698 | }).unwrap_or(after_create.len()); |
| 2699 | |
| 2700 | let table_name = after_create[..table_end].trim(); |
| 2701 | |
| 2702 | // Remove quotes if present |
| 2703 | let table_name = table_name.trim_matches('"').trim_matches('\''); |
| 2704 | |
| 2705 | if !table_name.is_empty() { |
| 2706 | Some(table_name.to_string()) |
| 2707 | } else { |
| 2708 | None |
| 2709 | } |
| 2710 | } |
| 2711 | |
| 2712 | /// Extract table name from INSERT statement |
| 2713 | fn extract_table_name_from_insert(query: &str) -> Option<String> { |
no test coverage detected