Page 1 of 1

change .dbf without losing data

Posted: Sat Aug 10, 2019 4:22 pm
by tomtagaris
I would like some help on how to add a type to a .dpf file without losing data through a program
tom Tagaris

Re: change .dbf without losing data

Posted: Sun Aug 11, 2019 8:27 am
by edk
:idea:
1. Copy to _temp.dbf
2. Change structure of dbf
3. Append from _temp.dbf
4. Delete _temp.dbf

Re: change .dbf without losing data

Posted: Sun Aug 11, 2019 9:05 am
by tomtagaris
thanks
tom

Re: change .dbf without losing data

Posted: Sun Aug 11, 2019 9:52 am
by Anand
edk wrote: Sun Aug 11, 2019 8:27 am :idea:
1. Copy to _temp.dbf
2. Change structure of dbf
3. Append from _temp.dbf
4. Delete _temp.dbf
This is good when you are adding a new field or deleting a field.
But if you want to change 'type' of a field from say 'number' to 'character' then here you will lose data.
For this scenario I copy to SDF format and then append from this file.

Care should be taken NOT to add/delete field and change type at same time.

Regards,

Anand

Re: change .dbf without losing data

Posted: Sun Aug 11, 2019 7:11 pm
by ROBROS
My way to do this is:

First step:
add a new field to the table.

Second step:
eg: replace newfield with str(oldfield) or val(oldfield) depending on the datatype of new field.

You now can keep the oldfield as long as you like in your dbf.
Regards
Robert

Re: change .dbf without losing data

Posted: Mon Aug 12, 2019 8:57 am
by dragancesu
This is a problem that has torture me many times, so i wrote a program to help solve it

change1.prg - input of old and new structure
change2.prg - creates a change.prg program that solves the problem

old structure is test.dbf, new test2.dbf