fixed bugs
This commit is contained in:
parent
4b4c691ebf
commit
f383e5566a
|
@ -89,8 +89,7 @@ fn main() -> Result<()> {
|
||||||
|
|
||||||
v => {
|
v => {
|
||||||
let db_header = read_db_header(&database)?;
|
let db_header = read_db_header(&database)?;
|
||||||
|
if v.to_lowercase().contains("count(*)") {
|
||||||
if v.contains("count(*)") {
|
|
||||||
count_rows_in_table(v, db_header, &database)
|
count_rows_in_table(v, db_header, &database)
|
||||||
} else {
|
} else {
|
||||||
read_columns(v, db_header, &database)
|
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 (_, offset) = parse_varint(stream);
|
||||||
let (_, read_bytes) = parse_varint(&stream[offset..]);
|
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 {
|
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]));
|
println!("{}", String::from_utf8_lossy(&row[cpos]));
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ pub fn parse_record(stream: &[u8], column_count: usize) -> Result<Vec<Vec<u8>>>
|
||||||
|
|
||||||
fn parse_column_value(stream: &[u8], serial_type: usize) -> Result<Vec<u8>> {
|
fn parse_column_value(stream: &[u8], serial_type: usize) -> Result<Vec<u8>> {
|
||||||
let column_value = match serial_type {
|
let column_value = match serial_type {
|
||||||
|
0 => vec![],
|
||||||
// 8 bit twos-complement integer
|
// 8 bit twos-complement integer
|
||||||
1 => vec![stream[0]],
|
1 => vec![stream[0]],
|
||||||
// Text encoding
|
// Text encoding
|
||||||
|
|
Loading…
Reference in New Issue
Block a user