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

Method execute_select

src/query/executor.rs:963–1521  ·  view source on GitHub ↗
(
        framed: &mut Framed<T, crate::protocol::PostgresCodec>,
        db: &Arc<DbHandler>,
        session: &Arc<SessionState>,
        query: &str,
        translation_metadata: &crate::translato

Source from the content-addressed store, hash-verified

961 }
962
963 async fn execute_select<T>(
964 framed: &mut Framed<T, crate::protocol::PostgresCodec>,
965 db: &Arc<DbHandler>,
966 session: &Arc<SessionState>,
967 query: &str,
968 translation_metadata: &crate::translator::TranslationMetadata,
969 query_router: Option<&Arc<QueryRouter>>,
970 ) -> Result<(), PgSqliteError>
971 where
972 T: tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin + Send,
973 {
974 // debug!("execute_select (non-ultra-simple) called with query: {}", query);
975 // SQLAlchemy manages transactions explicitly - don't start implicit transactions
976 // debug!("=== EXECUTE_SELECT CALLED with query: {}", query);
977
978 // Check wire protocol cache first for cacheable queries
979 if crate::cache::is_cacheable_for_wire_protocol(query)
980 && let Some(cached_response) = crate::cache::WIRE_PROTOCOL_CACHE.get(query) {
981 debug!("Wire protocol cache hit for query: {}", query);
982
983 // Send cached row description
984 framed.send(BackendMessage::RowDescription(cached_response.row_description.clone())).await
985 .map_err(PgSqliteError::Io)?;
986
987 // Send cached data rows (already encoded)
988 for encoded_row in &cached_response.encoded_rows {
989 // Send pre-encoded data directly
990 framed.get_mut().write_all(encoded_row).await
991 .map_err(PgSqliteError::Io)?;
992 }
993
994 // Send command complete
995 let tag = format!("SELECT {}", cached_response.row_count);
996 framed.send(BackendMessage::CommandComplete { tag }).await
997 .map_err(PgSqliteError::Io)?;
998
999 return Ok(());
1000 }
1001
1002 // Check if this is a catalog query first
1003 println!("EXECUTOR: About to call catalog interceptor with query: '{}'", query);
1004 let response = if let Some(catalog_result) = crate::catalog::CatalogInterceptor::intercept_query(query, db.clone(), Some(session.clone())).await {
1005 info!("Query intercepted by catalog handler");
1006 println!("EXECUTOR: Got catalog result, about to unwrap");
1007 let unwrapped = catalog_result?;
1008 println!("EXECUTOR: Unwrapped catalog result, columns: {}, rows: {}", unwrapped.columns.len(), unwrapped.rows.len());
1009 unwrapped
1010 } else {
1011 // Route query through query router if available
1012 if let Some(router) = query_router {
1013 router.execute_query(query, session).await.map_err(|e| PgSqliteError::Protocol(e.to_string()))?
1014 } else {
1015 let cached_conn = Self::get_or_cache_connection(session, db).await;
1016 db.query_with_session_cached(query, &session.id, cached_conn.as_ref()).await?
1017 }
1018 };
1019
1020 // Extract table name from query to look up schema

Callers

nothing calls this directly

Tested by

no test coverage detected