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

Method query_with_session_cached

src/session/db_handler.rs:923–1273  ·  view source on GitHub ↗

Query with session-specific connection (with optional cached connection)

(
        &self, 
        query: &str, 
        session_id: &Uuid,
        cached_conn: Option<&Arc<parking_lot::Mutex<rusqlite::Connection>>>
    )

Source from the content-addressed store, hash-verified

921
922 /// Query with session-specific connection (with optional cached connection)
923 pub async fn query_with_session_cached(
924 &self,
925 query: &str,
926 session_id: &Uuid,
927 cached_conn: Option<&Arc<parking_lot::Mutex<rusqlite::Connection>>>
928 ) -> Result<DbResponse, PgSqliteError> {
929 // Check if this is a catalog query that should be intercepted
930 // We need to do this before applying translations
931 let lower_query = query.to_lowercase();
932
933 // We'll rewrite the query just before execution if needed
934
935 // Handle special system function queries
936 if lower_query.trim() == "select current_user()" {
937 return Ok(DbResponse {
938 columns: vec!["current_user".to_string()],
939 rows: vec![vec![Some("postgres".to_string().into_bytes())]],
940 rows_affected: 1,
941 });
942 }
943
944 // Handle pg_tablespace queries
945 if lower_query.contains("pg_tablespace") || lower_query.contains("pg_catalog.pg_tablespace") {
946 use crate::catalog::query_interceptor::CatalogInterceptor;
947 let parsed_query = sqlparser::parser::Parser::parse_sql(&sqlparser::dialect::PostgreSqlDialect {}, query);
948 if let Ok(mut statements) = parsed_query
949 && let Some(sqlparser::ast::Statement::Query(query_ast)) = statements.pop()
950 && let Some(select) = query_ast.body.as_select() {
951 return Ok(CatalogInterceptor::handle_pg_tablespace_query(select));
952 }
953 // Fallback to empty response if parsing fails
954 return Ok(DbResponse {
955 columns: vec!["oid".to_string(), "spcname".to_string(), "spcowner".to_string()],
956 rows: vec![],
957 rows_affected: 0,
958 });
959 }
960
961 // Handle pg_collation queries
962 if lower_query.contains("pg_collation") || lower_query.contains("pg_catalog.pg_collation") {
963 use crate::catalog::query_interceptor::CatalogInterceptor;
964 let parsed_query = sqlparser::parser::Parser::parse_sql(&sqlparser::dialect::PostgreSqlDialect {}, query);
965 if let Ok(mut statements) = parsed_query
966 && let Some(sqlparser::ast::Statement::Query(query_ast)) = statements.pop()
967 && let Some(select) = query_ast.body.as_select() {
968 return Ok(CatalogInterceptor::handle_pg_collation_query(select));
969 }
970 // Fallback to empty response if parsing fails
971 return Ok(DbResponse {
972 columns: vec!["oid".to_string(), "collname".to_string()],
973 rows: vec![],
974 rows_affected: 0,
975 });
976 }
977
978 // Handle pg_replication_slots queries (always empty - SQLite has no replication)
979 if lower_query.contains("pg_replication_slots") || lower_query.contains("pg_catalog.pg_replication_slots") {
980 use crate::catalog::query_interceptor::CatalogInterceptor;

Callers 6

execute_selectMethod · 0.80
handle_parseMethod · 0.80
execute_selectMethod · 0.80

Calls 7

sanitize_column_nameFunction · 0.85
query_with_sessionMethod · 0.80
process_queryFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected