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

Function process_complex_query

src/query/unified_processor.rs:372–516  ·  view source on GitHub ↗

Process complex queries that need translation

(
    query: &'a str,
    conn: &Connection,
    schema_cache: &SchemaCache,
)

Source from the content-addressed store, hash-verified

370
371/// Process complex queries that need translation
372fn process_complex_query<'a>(
373 query: &'a str,
374 conn: &Connection,
375 schema_cache: &SchemaCache,
376) -> Result<Cow<'a, str>, rusqlite::Error> {
377 let processor = UnifiedProcessor::analyze(query);
378
379 // If no translations needed, return original
380 if processor.translations_needed.is_empty() {
381 return Ok(Cow::Borrowed(query));
382 }
383
384 let mut result = Cow::Borrowed(query);
385
386 // Apply translations in optimal order (destructive ones first)
387
388 // 1. Schema translation (changes table references)
389 if processor.needs_translation(TranslationFlags::SCHEMA) {
390 let translated = crate::translator::SchemaPrefixTranslator::translate_query(&result);
391 result = Cow::Owned(translated);
392 }
393
394 // 1.5. Session identifier translation (add parentheses to current_user, session_user)
395 if processor.needs_translation(TranslationFlags::SESSION_IDENTIFIER) {
396 let translated = crate::translator::SessionIdentifierTranslator::translate_query(&result);
397 result = Cow::Owned(translated);
398 }
399
400 // Note: CREATE TABLE translation is now handled directly in execute_with_session
401 // to ensure proper metadata storage
402
403 // 2. Numeric cast translation (must come before general cast)
404 if processor.needs_translation(TranslationFlags::NUMERIC) {
405 let translated = crate::translator::NumericCastTranslator::translate_query(&result, conn);
406 result = Cow::Owned(translated);
407 }
408
409 // 3. Cast translation
410 if processor.needs_translation(TranslationFlags::CAST) {
411 // Check translation cache first
412 if let Some(cached) = crate::cache::global_translation_cache().get(query) {
413 result = Cow::Owned(cached);
414 } else {
415 let translated = crate::translator::CastTranslator::translate_query(&result, Some(conn));
416
417 // Cache if it's the original query
418 if result.as_ref() == query {
419 crate::cache::global_translation_cache().insert(
420 query.to_string(),
421 translated.clone()
422 );
423 }
424 result = Cow::Owned(translated);
425 }
426 }
427
428 // 4. Regex translation
429 if processor.needs_translation(TranslationFlags::REGEX) {

Callers 1

process_queryFunction · 0.85

Calls 10

global_translation_cacheFunction · 0.85
extract_table_nameFunction · 0.85
has_decimal_columnsMethod · 0.80
is_emptyMethod · 0.45
needs_translationMethod · 0.45
getMethod · 0.45
insertMethod · 0.45
cloneMethod · 0.45
translateMethod · 0.45

Tested by

no test coverage detected