From 8fd6cadaa5b10c949cd2abca2c3fc87dae5d97cb Mon Sep 17 00:00:00 2001 From: Glauber Costa Date: Sat, 30 Aug 2025 15:19:43 -0500 Subject: [PATCH] fix column count in ImmutableRow When we create an ImmutableRow::from_value(), we are always adding a null padding at the end. We didn't notice this before, because a SQLite file with an extra column is as valid as any. But that column of course should not be there. I traced this to column_count(), which is off by one. My understanding is that we should be returning based on serial_types, not offset. --- core/types.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/core/types.rs b/core/types.rs index 67fdbfdb8..9bb9e238c 100644 --- a/core/types.rs +++ b/core/types.rs @@ -1280,7 +1280,7 @@ impl ImmutableRecord { pub fn column_count(&self) -> usize { let mut cursor = RecordCursor::new(); cursor.parse_full_header(self).unwrap(); - cursor.offsets.len() + cursor.serial_types.len() } } @@ -3562,4 +3562,19 @@ mod tests { header_length + size_of::() + size_of::() + text.len() ); } + + #[test] + fn test_column_count_matches_values_written() { + // Test with different numbers of values + for num_values in 1..=10 { + let values: Vec = (0..num_values).map(|i| Value::Integer(i as i64)).collect(); + + let record = ImmutableRecord::from_values(&values, values.len()); + let cnt = record.column_count(); + assert_eq!( + cnt, num_values, + "column_count should be {num_values}, not {cnt}" + ); + } + } }