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

Function extract_table_name_from_create

src/query/extended.rs:6247–6277  ·  view source on GitHub ↗

Extract table name from CREATE TABLE statement

(query: &str)

Source from the content-addressed store, hash-verified

6245
6246/// Extract table name from CREATE TABLE statement
6247fn extract_table_name_from_create(query: &str) -> Option<String> {
6248 // Look for CREATE TABLE pattern
6249 if let Some(table_pos) = find_keyword_position(query, "CREATE TABLE") {
6250 let after_create = &query[table_pos + 12..].trim();
6251
6252 // Skip IF NOT EXISTS if present
6253 let after_create = if query_starts_with_ignore_case(after_create, "IF NOT EXISTS") {
6254 &after_create[13..].trim()
6255 } else {
6256 after_create
6257 };
6258
6259 // Find the end of table name
6260 let table_end = after_create.find(|c: char| {
6261 c.is_whitespace() || c == '('
6262 }).unwrap_or(after_create.len());
6263
6264 let table_name = after_create[..table_end].trim();
6265
6266 // Remove quotes if present
6267 let table_name = table_name.trim_matches('"').trim_matches('\'');
6268
6269 if !table_name.is_empty() {
6270 Some(table_name.to_string())
6271 } else {
6272 None
6273 }
6274 } else {
6275 None
6276 }
6277}

Callers 1

execute_ddlMethod · 0.70

Calls 4

find_keyword_positionFunction · 0.85
lenMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected