MCPcopy Create free account
hub / github.com/erans/pgsqlite / extract_table_name_from_select

Function extract_table_name_from_select

src/query/extended.rs:6221–6244  ·  view source on GitHub ↗

Extract table name from SELECT query

(query: &str)

Source from the content-addressed store, hash-verified

6219
6220/// Extract table name from SELECT query
6221fn 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
6247fn extract_table_name_from_create(query: &str) -> Option<String> {

Callers 5

handle_parseMethod · 0.70
handle_executeMethod · 0.70
execute_selectMethod · 0.70
analyze_select_paramsMethod · 0.70

Calls 3

find_keyword_positionFunction · 0.85
lenMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected