Extract table name from SELECT query
(query: &str)
| 6219 | |
| 6220 | /// Extract table name from SELECT query |
| 6221 | fn extract_table_name_from_select(query: &str) -> Option<String> { |
| 6222 | // Look for FROM clause using case-insensitive search |
| 6223 | if let Some(from_pos) = find_keyword_position(query, " from ") { |
| 6224 | let after_from = &query[from_pos + 6..].trim(); |
| 6225 | |
| 6226 | // Find the end of table name (space, where, order by, etc.) |
| 6227 | let table_end = after_from.find(|c: char| { |
| 6228 | c.is_whitespace() || c == ',' || c == ';' || c == '(' |
| 6229 | }).unwrap_or(after_from.len()); |
| 6230 | |
| 6231 | let table_name = after_from[..table_end].trim(); |
| 6232 | |
| 6233 | // Remove quotes if present |
| 6234 | let table_name = table_name.trim_matches('"').trim_matches('\''); |
| 6235 | |
| 6236 | if !table_name.is_empty() { |
| 6237 | Some(table_name.to_string()) |
| 6238 | } else { |
| 6239 | None |
| 6240 | } |
| 6241 | } else { |
| 6242 | None |
| 6243 | } |
| 6244 | } |
| 6245 | |
| 6246 | /// Extract table name from CREATE TABLE statement |
| 6247 | fn extract_table_name_from_create(query: &str) -> Option<String> { |
no test coverage detected