Execute simple query directly with minimal overhead
(
&self,
conn: &Connection,
query: &str,
plan: &CachedQueryPlan,
)
| 315 | |
| 316 | /// Execute simple query directly with minimal overhead |
| 317 | fn execute_simple_query_direct( |
| 318 | &self, |
| 319 | conn: &Connection, |
| 320 | query: &str, |
| 321 | plan: &CachedQueryPlan, |
| 322 | ) -> Result<Option<DbResponse>, rusqlite::Error> { |
| 323 | let mut stmt = conn.prepare(query)?; |
| 324 | let mut rows = Vec::new(); |
| 325 | |
| 326 | // Execute query with pre-cached column information |
| 327 | let result_rows = stmt.query_map([], |row| { |
| 328 | let mut values = Vec::new(); |
| 329 | for (i, col_type) in plan.column_types.iter().enumerate() { |
| 330 | match row.get_ref(i)? { |
| 331 | rusqlite::types::ValueRef::Null => values.push(None), |
| 332 | rusqlite::types::ValueRef::Integer(int_val) => { |
| 333 | // Use cached type information for conversion |
| 334 | if let Some(pg_type) = col_type { |
| 335 | match pg_type.to_lowercase().as_str() { |
| 336 | "boolean" | "bool" => { |
| 337 | let bool_str = if int_val == 0 { "f" } else { "t" }; |
| 338 | values.push(Some(bool_str.as_bytes().to_vec())); |
| 339 | } |
| 340 | "date" => { |
| 341 | use crate::types::datetime_utils::format_days_to_date_buf; |
| 342 | let mut buf = vec![0u8; 32]; |
| 343 | let len = format_days_to_date_buf(int_val as i32, &mut buf); |
| 344 | buf.truncate(len); |
| 345 | values.push(Some(buf)); |
| 346 | } |
| 347 | "time" | "timetz" => { |
| 348 | use crate::types::datetime_utils::format_microseconds_to_time_buf; |
| 349 | let mut buf = vec![0u8; 32]; |
| 350 | let len = format_microseconds_to_time_buf(int_val, &mut buf); |
| 351 | buf.truncate(len); |
| 352 | values.push(Some(buf)); |
| 353 | } |
| 354 | "timestamp" | "timestamptz" => { |
| 355 | use crate::types::datetime_utils::format_microseconds_to_timestamp_buf; |
| 356 | let mut buf = vec![0u8; 64]; |
| 357 | let len = format_microseconds_to_timestamp_buf(int_val, &mut buf); |
| 358 | buf.truncate(len); |
| 359 | values.push(Some(buf)); |
| 360 | } |
| 361 | _ => { |
| 362 | values.push(Some(int_val.to_string().into_bytes())); |
| 363 | } |
| 364 | } |
| 365 | } else { |
| 366 | values.push(Some(int_val.to_string().into_bytes())); |
| 367 | } |
| 368 | } |
| 369 | rusqlite::types::ValueRef::Real(f) => { |
| 370 | values.push(Some(f.to_string().into_bytes())); |
| 371 | } |
| 372 | rusqlite::types::ValueRef::Text(s) => { |
| 373 | values.push(Some(s.to_vec())); |
| 374 | } |
no test coverage detected