Check if a query is targeting pg_catalog and handle it
(query: &str, db: Arc<DbHandler>, session: Option<Arc<SessionState>>)
| 24 | impl CatalogInterceptor { |
| 25 | /// Check if a query is targeting pg_catalog and handle it |
| 26 | pub async fn intercept_query(query: &str, db: Arc<DbHandler>, session: Option<Arc<SessionState>>) -> Option<Result<DbResponse, PgSqliteError>> { |
| 27 | println!("INTERCEPT_QUERY: {}", query); |
| 28 | // Quick check to avoid parsing if not a catalog query |
| 29 | let lower_query = query.to_lowercase(); |
| 30 | println!("INTERCEPT: lower_query = {}", lower_query); |
| 31 | |
| 32 | // Check for cache status query |
| 33 | if lower_query.contains("select * from pgsqlite_cache_status") { |
| 34 | let (columns, rows) = crate::cache::format_cache_status_as_table(); |
| 35 | let rows_affected = rows.len(); |
| 36 | let response = DbResponse { |
| 37 | columns, |
| 38 | rows, |
| 39 | rows_affected, |
| 40 | }; |
| 41 | return Some(Ok(response)); |
| 42 | } |
| 43 | |
| 44 | // Special case: pg_catalog.version() should be handled by SQLite function, not catalog interceptor |
| 45 | if lower_query.trim() == "select pg_catalog.version()" || |
| 46 | lower_query.trim() == "select version()" { |
| 47 | return None; |
| 48 | } |
| 49 | |
| 50 | // Check for catalog tables |
| 51 | let has_catalog_tables = lower_query.contains("pg_catalog") || lower_query.contains("pg_type") || |
| 52 | lower_query.contains("pg_namespace") || lower_query.contains("pg_range") || |
| 53 | lower_query.contains("pg_tablespace") || |
| 54 | lower_query.contains("pg_class") || lower_query.contains("pg_attribute") || |
| 55 | lower_query.contains("pg_enum") || |
| 56 | lower_query.contains("pg_description") || lower_query.contains("pg_roles") || |
| 57 | lower_query.contains("pg_user") || lower_query.contains("pg_authid") || |
| 58 | lower_query.contains("pg_stats") || lower_query.contains("pg_constraint") || |
| 59 | lower_query.contains("pg_depend") || lower_query.contains("pg_sequence") || |
| 60 | lower_query.contains("pg_trigger") || lower_query.contains("pg_settings") || |
| 61 | lower_query.contains("pg_collation") || |
| 62 | lower_query.contains("pg_replication_slots") || |
| 63 | lower_query.contains("pg_shdepend") || |
| 64 | lower_query.contains("pg_statistic") || |
| 65 | lower_query.contains("information_schema") || |
| 66 | lower_query.contains("pg_stat_") || lower_query.contains("pg_database") || |
| 67 | lower_query.contains("pg_foreign_data_wrapper"); |
| 68 | |
| 69 | // Check for system functions |
| 70 | let has_system_functions = lower_query.contains("to_regtype") || |
| 71 | lower_query.contains("pg_get_constraintdef") || lower_query.contains("pg_table_is_visible") || |
| 72 | lower_query.contains("format_type") || lower_query.contains("pg_get_expr") || |
| 73 | lower_query.contains("pg_get_userbyid") || lower_query.contains("pg_get_indexdef") || |
| 74 | lower_query.contains("pg_size_pretty"); |
| 75 | |
| 76 | println!("INTERCEPT: has_catalog_tables = {}, has_system_functions = {}", has_catalog_tables, has_system_functions); |
| 77 | |
| 78 | if !has_catalog_tables && !has_system_functions { |
| 79 | println!("INTERCEPT: Returning None (no catalog tables or system functions)"); |
| 80 | return None; |
| 81 | } |
| 82 | |
| 83 | debug!("Intercepting catalog query: {}", query); |
nothing calls this directly
no test coverage detected