From f383e5566aead56bc9f0b3f0893fd01000306785 Mon Sep 17 00:00:00 2001 From: Ishan Jain Date: Tue, 26 Jul 2022 14:42:42 +0530 Subject: [PATCH] fixed bugs --- src/main.rs | 7 +++---- src/record.rs | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8f0938b..d11532d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -89,8 +89,7 @@ fn main() -> Result<()> { v => { let db_header = read_db_header(&database)?; - - if v.contains("count(*)") { + if v.to_lowercase().contains("count(*)") { count_rows_in_table(v, db_header, &database) } else { read_columns(v, db_header, &database) @@ -125,11 +124,11 @@ fn read_columns(query: &str, db_header: DBHeader, database: &[u8]) -> Result<(), let (_, offset) = parse_varint(stream); let (_, read_bytes) = parse_varint(&stream[offset..]); - parse_record(&stream[offset + read_bytes + 1..], 2).unwrap() + parse_record(&stream[offset + read_bytes..], 3).unwrap() }); for row in rows { - let cpos = *column_map.get(&columns[0]).unwrap() - 1; + let cpos = *column_map.get(&columns[0]).unwrap(); println!("{}", String::from_utf8_lossy(&row[cpos])); } diff --git a/src/record.rs b/src/record.rs index 029f60d..55d051b 100644 --- a/src/record.rs +++ b/src/record.rs @@ -28,6 +28,7 @@ pub fn parse_record(stream: &[u8], column_count: usize) -> Result>> fn parse_column_value(stream: &[u8], serial_type: usize) -> Result> { let column_value = match serial_type { + 0 => vec![], // 8 bit twos-complement integer 1 => vec![stream[0]], // Text encoding