(
framed: &mut Framed<T, crate::protocol::PostgresCodec>,
db: &Arc<DbHandler>,
session: &Arc<SessionState>,
portal_name: &str,
query: &str,
max_rows: i3
| 4392 | } |
| 4393 | |
| 4394 | async fn execute_select<T>( |
| 4395 | framed: &mut Framed<T, crate::protocol::PostgresCodec>, |
| 4396 | db: &Arc<DbHandler>, |
| 4397 | session: &Arc<SessionState>, |
| 4398 | portal_name: &str, |
| 4399 | query: &str, |
| 4400 | max_rows: i32, |
| 4401 | ) -> Result<(), PgSqliteError> |
| 4402 | where |
| 4403 | T: tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin, |
| 4404 | { |
| 4405 | // Check if this is a catalog query first |
| 4406 | info!("execute_select: Checking if query is catalog query: {}", query); |
| 4407 | if query.contains("int_array_with_nulls") { |
| 4408 | info!("DEBUG: execute_select called with array null query: {}", query); |
| 4409 | } |
| 4410 | let response = if let Some(catalog_result) = CatalogInterceptor::intercept_query(query, db.clone(), Some(session.clone())).await { |
| 4411 | info!("execute_select: Query intercepted by catalog handler"); |
| 4412 | println!("EXTENDED: Got catalog result, about to unwrap"); |
| 4413 | let mut catalog_response = catalog_result?; |
| 4414 | println!("EXTENDED: Unwrapped catalog result, columns: {}, rows: {}", catalog_response.columns.len(), catalog_response.rows.len()); |
| 4415 | |
| 4416 | // For catalog queries with binary result formats, we need to ensure the data |
| 4417 | // is in the correct format for binary encoding |
| 4418 | let portals = session.portals.read().await; |
| 4419 | let portal = portals.get(portal_name).unwrap(); |
| 4420 | let has_binary_format = portal.result_formats.contains(&1); |
| 4421 | println!("EXTENDED: result_formats = {:?}, has_binary_format = {}", portal.result_formats, has_binary_format); |
| 4422 | drop(portals); |
| 4423 | |
| 4424 | if has_binary_format { |
| 4425 | if query.contains("pg_attribute") { |
| 4426 | info!("Converting catalog text data for binary encoding"); |
| 4427 | // pg_attribute specific handling - ensure numeric columns are properly formatted |
| 4428 | for row in &mut catalog_response.rows { |
| 4429 | // attnum is at index 5 |
| 4430 | if row.len() > 5 |
| 4431 | && let Some(Some(attnum_bytes)) = row.get_mut(5) |
| 4432 | && let Ok(attnum_str) = String::from_utf8(attnum_bytes.clone()) { |
| 4433 | // Ensure it's just the numeric value without extra formatting |
| 4434 | *attnum_bytes = attnum_str.trim().as_bytes().to_vec(); |
| 4435 | } |
| 4436 | } |
| 4437 | } else if query.contains("pg_database") { |
| 4438 | info!("Converting pg_database boolean data for binary encoding"); |
| 4439 | // pg_database has boolean columns that need special handling |
| 4440 | // They're stored as 'f'/'t' but need to be converted for binary format |
| 4441 | // No conversion needed here - the binary encoder will handle 'f'/'t' for Bool type |
| 4442 | println!("EXTENDED: pg_database binary format - boolean columns will be handled by encoder"); |
| 4443 | } else if query.contains("information_schema") { |
| 4444 | info!("Converting information_schema text data for binary encoding"); |
| 4445 | // For information_schema queries, the data is already in text format |
| 4446 | // which is what binary encoding expects for text columns |
| 4447 | // No additional conversion needed - the binary encoder will handle it |
| 4448 | println!("EXTENDED: information_schema binary format - no conversion needed"); |
| 4449 | } |
| 4450 | } |
| 4451 |
nothing calls this directly
no test coverage detected