tmontaigu / dbase-rs

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

Feature Request: Change of field types #13

Open Infiziert90 opened 3 years ago

Infiziert90 commented 3 years ago

Is it possible to get support for changing the type of a field?

For example: The .dbf file has a "Numeric" field that would be changed into a "Character" field

tmontaigu commented 3 years ago

I'll try to look into that

michelk commented 3 years ago

In the csv-library it is possible to define the Record-type:

//tutorial-read-serde-03.rs
use std::collections::HashMap;

// This introduces a type alias so that we can conveniently reference our
// record type.
type Record = HashMap<String, String>;

fn run() -> Result<(), Box<Error>> {
    let mut rdr = csv::Reader::from_reader(io::stdin());
    for result in rdr.deserialize() {
        let record: Record = result?;
        println!("{:?}", record);
    }
    Ok(())
}

Maybe we can have something similar?

tmontaigu commented 3 years ago

There is already something close to this https://docs.rs/dbase/0.2.0/dbase/#deserialisation

I think the feature requested here is more about changing a filed type rather than that serialization.

Changing a field type should be doable by reading the file, changing the types in the Record and create the appropriate writer. The things is can it be made a bit simpler ?

Infiziert90 commented 3 years ago

Yeah that's exactly what I meant.

Where this idea comes from is easy.... In the company I work for we use the old DOS program "DBase" this program allows it you to edit .dbf files both header and body

So you have for example the field Name: XYZ Type: Character Length: 20 Precision: 0

And now you can go and change that "Type" to "Numeric" and the program would create a new dbf file with the correct header and changed body values