Query with session-specific connection
(&self, query: &str, session_id: &Uuid)
| 1274 | |
| 1275 | /// Query with session-specific connection |
| 1276 | pub async fn query_with_session(&self, query: &str, session_id: &Uuid) -> Result<DbResponse, PgSqliteError> { |
| 1277 | eprintln!("🔍 query_with_session called with query: {}", query); |
| 1278 | // Check if this is a catalog query that should be intercepted |
| 1279 | // We need to do this before applying translations |
| 1280 | let lower_query = query.to_lowercase(); |
| 1281 | |
| 1282 | // Handle special system function queries |
| 1283 | if lower_query.trim() == "select current_user()" { |
| 1284 | return Ok(DbResponse { |
| 1285 | columns: vec!["current_user".to_string()], |
| 1286 | rows: vec![vec![Some("postgres".to_string().into_bytes())]], |
| 1287 | rows_affected: 1, |
| 1288 | }); |
| 1289 | } |
| 1290 | |
| 1291 | // Handle pg_tablespace queries |
| 1292 | if lower_query.contains("pg_tablespace") || lower_query.contains("pg_catalog.pg_tablespace") { |
| 1293 | use crate::catalog::query_interceptor::CatalogInterceptor; |
| 1294 | let parsed_query = sqlparser::parser::Parser::parse_sql(&sqlparser::dialect::PostgreSqlDialect {}, query); |
| 1295 | if let Ok(mut statements) = parsed_query |
| 1296 | && let Some(sqlparser::ast::Statement::Query(query_ast)) = statements.pop() |
| 1297 | && let Some(select) = query_ast.body.as_select() { |
| 1298 | return Ok(CatalogInterceptor::handle_pg_tablespace_query(select)); |
| 1299 | } |
| 1300 | // Fallback to empty response if parsing fails |
| 1301 | return Ok(DbResponse { |
| 1302 | columns: vec!["oid".to_string(), "spcname".to_string(), "spcowner".to_string()], |
| 1303 | rows: vec![], |
| 1304 | rows_affected: 0, |
| 1305 | }); |
| 1306 | } |
| 1307 | |
| 1308 | // Handle pg_collation queries |
| 1309 | if lower_query.contains("pg_collation") || lower_query.contains("pg_catalog.pg_collation") { |
| 1310 | use crate::catalog::query_interceptor::CatalogInterceptor; |
| 1311 | let parsed_query = sqlparser::parser::Parser::parse_sql(&sqlparser::dialect::PostgreSqlDialect {}, query); |
| 1312 | if let Ok(mut statements) = parsed_query |
| 1313 | && let Some(sqlparser::ast::Statement::Query(query_ast)) = statements.pop() |
| 1314 | && let Some(select) = query_ast.body.as_select() { |
| 1315 | return Ok(CatalogInterceptor::handle_pg_collation_query(select)); |
| 1316 | } |
| 1317 | // Fallback to empty response if parsing fails |
| 1318 | return Ok(DbResponse { |
| 1319 | columns: vec!["oid".to_string(), "collname".to_string()], |
| 1320 | rows: vec![], |
| 1321 | rows_affected: 0, |
| 1322 | }); |
| 1323 | } |
| 1324 | |
| 1325 | // Handle pg_replication_slots queries (always empty - SQLite has no replication) |
| 1326 | if lower_query.contains("pg_replication_slots") || lower_query.contains("pg_catalog.pg_replication_slots") { |
| 1327 | use crate::catalog::query_interceptor::CatalogInterceptor; |
| 1328 | let parsed_query = sqlparser::parser::Parser::parse_sql(&sqlparser::dialect::PostgreSqlDialect {}, query); |
| 1329 | if let Ok(mut statements) = parsed_query |
| 1330 | && let Some(sqlparser::ast::Statement::Query(query_ast)) = statements.pop() |
| 1331 | && let Some(select) = query_ast.body.as_select() { |
| 1332 | return Ok(CatalogInterceptor::handle_pg_replication_slots_query(select)); |
| 1333 | } |