(
row: &[Option<Vec<u8>>],
result_formats: &[i16],
field_types: &[i32],
)
| 3778 | } |
| 3779 | |
| 3780 | fn encode_row( |
| 3781 | row: &[Option<Vec<u8>>], |
| 3782 | result_formats: &[i16], |
| 3783 | field_types: &[i32], |
| 3784 | ) -> Result<Vec<Option<Vec<u8>>>, PgSqliteError> { |
| 3785 | info!("encode_row called with {} fields, {} result_formats, {} field_types", |
| 3786 | row.len(), result_formats.len(), field_types.len()); |
| 3787 | info!(" result_formats: {:?}", result_formats); |
| 3788 | info!(" field_types: {:?}", field_types); |
| 3789 | |
| 3790 | // Log the first few values for debugging |
| 3791 | for (i, value) in row.iter().take(3).enumerate() { |
| 3792 | if let Some(bytes) = value { |
| 3793 | if let Ok(s) = std::str::from_utf8(bytes) { |
| 3794 | debug!(" Field {}: '{}' (type OID {})", i, s, field_types.get(i).unwrap_or(&0)); |
| 3795 | // Extra debug for array types |
| 3796 | if field_types.get(i).copied().unwrap_or(0) == 1007 { |
| 3797 | info!(" DEBUG: Encoding INT4Array field {} with value '{}'", i, s); |
| 3798 | } |
| 3799 | } else { |
| 3800 | debug!(" Field {}: <binary data> (type OID {})", i, field_types.get(i).unwrap_or(&0)); |
| 3801 | } |
| 3802 | } else { |
| 3803 | debug!(" Field {}: NULL (type OID {})", i, field_types.get(i).unwrap_or(&0)); |
| 3804 | } |
| 3805 | } |
| 3806 | |
| 3807 | let mut encoded_row = Vec::new(); |
| 3808 | |
| 3809 | for (i, value) in row.iter().enumerate() { |
| 3810 | // If result_formats has only one element, it applies to all columns |
| 3811 | let format = if result_formats.len() == 1 { |
| 3812 | result_formats[0] |
| 3813 | } else { |
| 3814 | result_formats.get(i).copied().unwrap_or(0) |
| 3815 | }; |
| 3816 | let type_oid = field_types.get(i).copied().unwrap_or(PgType::Text.to_oid()); |
| 3817 | |
| 3818 | |
| 3819 | let encoded_value = match value { |
| 3820 | None => None, |
| 3821 | Some(bytes) => { |
| 3822 | if format == 1 { |
| 3823 | // Binary format requested |
| 3824 | match type_oid { |
| 3825 | t if t == PgType::Bool.to_oid() => { |
| 3826 | // bool - convert text to binary |
| 3827 | if let Ok(s) = String::from_utf8(bytes.clone()) { |
| 3828 | let val = match s.trim() { |
| 3829 | "1" | "t" | "true" | "TRUE" | "T" => 1u8, |
| 3830 | "0" | "f" | "false" | "FALSE" | "F" => 0u8, |
| 3831 | _ => { |
| 3832 | // Invalid boolean, keep as text |
| 3833 | encoded_row.push(Some(bytes.clone())); |
| 3834 | continue; |
| 3835 | } |
| 3836 | }; |
| 3837 | Some(vec![val]) |
nothing calls this directly
no test coverage detected