tmontaigu / dbase-rs

Rust library to read & write dBase files.
MIT License
29 stars 30 forks source link

Running program results in unpredictable results #80

Closed zszep closed 9 months ago

zszep commented 9 months ago

Hi, I tried your software and something isn't working as expected. When running a small program repeatedly, I get different outputs. First time it shows correctly:

"NAZIV_GRAD" "POSTBR2" "POSTBR" "UNIO" "DATPR"

but on subsequent runs, the output varies, i.e.:

"UNIO" "NAZIV_GRAD" "POSTBR2" "DATPR" "POSTBR"

and other permutations of the fields.

The code i run is:

use dbase;
use std::io::{self, Write};

fn main() {
    list_records();
}

fn list_records() {
    let dbf_path = std::env::args().nth(1).expect("Path to file as first arg");
    let mut reader = dbase::Reader::from_path(dbf_path).unwrap();
    let mut names: Vec<String> = vec![];
    let mut values = vec![];
    for (_i, record_result) in reader.iter_records().enumerate() {
        if let Ok(record) = record_result {
            for (name, value) in record {
                names.push(name);
                values.push(value.field_type());
            }
        }
        break;
    }
    for name in names {
        println!("{:?}", name);
    }
}
tmontaigu commented 9 months ago

That's something that directly comes from dbase rust, but rather from rust's HashMap i believe

If you want to iteratate with the same order everytime (and the order of fields in the file) you would have to get the field names from for name in reader.fields().map(|info| info.name())

zszep commented 9 months ago

OK. Closing