Execute a fast SELECT query without decimal rewriting
(
conn: &Connection,
query: &str,
table_name: &str,
schema_cache: &SchemaCache,
)
| 724 | |
| 725 | /// Execute a fast SELECT query without decimal rewriting |
| 726 | fn execute_fast_select( |
| 727 | conn: &Connection, |
| 728 | query: &str, |
| 729 | table_name: &str, |
| 730 | schema_cache: &SchemaCache, |
| 731 | ) -> Result<Option<DbResponse>, rusqlite::Error> { |
| 732 | let mut stmt = conn.prepare(query)?; |
| 733 | let column_count = stmt.column_count(); |
| 734 | |
| 735 | // Get column names |
| 736 | let mut columns = Vec::new(); |
| 737 | for i in 0..column_count { |
| 738 | columns.push(sanitize_column_name(stmt.column_name(i)?).to_string()); |
| 739 | } |
| 740 | |
| 741 | // Check for boolean columns in the schema using cache |
| 742 | let mut column_types = Vec::new(); |
| 743 | if let Ok(table_schema) = schema_cache.get_or_load(conn, table_name) { |
| 744 | for col_name in &columns { |
| 745 | if let Some(col_info) = table_schema.column_map.get(&col_name.to_lowercase()) { |
| 746 | column_types.push(Some(col_info.pg_type.clone())); |
| 747 | } else { |
| 748 | column_types.push(None); |
| 749 | } |
| 750 | } |
| 751 | } else { |
| 752 | // Fallback to None for all columns |
| 753 | column_types.resize(columns.len(), None); |
| 754 | } |
| 755 | |
| 756 | // Get rows - with boolean type conversions |
| 757 | let mut rows = Vec::new(); |
| 758 | let result_rows = stmt.query_map([], |row| { |
| 759 | let mut values = Vec::new(); |
| 760 | for (i, _) in columns.iter().enumerate().take(column_count) { |
| 761 | match row.get_ref(i)? { |
| 762 | ValueRef::Null => values.push(None), |
| 763 | ValueRef::Integer(int_val) => { |
| 764 | // Get the column type |
| 765 | let pg_type = column_types.get(i) |
| 766 | .and_then(|opt| opt.as_ref()) |
| 767 | .map(|t| t.to_lowercase()); |
| 768 | |
| 769 | match pg_type.as_deref() { |
| 770 | Some("boolean") | Some("bool") => { |
| 771 | // Convert SQLite's 0/1 to PostgreSQL's f/t format |
| 772 | let bool_str = if int_val == 0 { "f" } else { "t" }; |
| 773 | values.push(Some(bool_str.as_bytes().to_vec())); |
| 774 | }, |
| 775 | Some("date") => { |
| 776 | // Convert INTEGER days to YYYY-MM-DD |
| 777 | use crate::types::datetime_utils::format_days_to_date_buf; |
| 778 | let mut buf = vec![0u8; 32]; |
| 779 | let len = format_days_to_date_buf(int_val as i32, &mut buf); |
| 780 | buf.truncate(len); |
| 781 | values.push(Some(buf)); |
| 782 | }, |
| 783 | Some("time") | Some("timetz") => { |
no test coverage detected