change .dbf without losing data

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
tomtagaris
Posts: 71
Joined: Tue Aug 23, 2016 2:43 pm

change .dbf without losing data

Post by tomtagaris » Sat Aug 10, 2019 4:22 pm

I would like some help on how to add a type to a .dpf file without losing data through a program
tom Tagaris

edk
Posts: 503
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 137 times
Been thanked: 412 times

Post by edk » 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

User avatar
tomtagaris
Posts: 71
Joined: Tue Aug 23, 2016 2:43 pm

Post by tomtagaris » Sun Aug 11, 2019 9:05 am

thanks
tom

User avatar
Anand
Posts: 424
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF
Has thanked: 122 times
Been thanked: 60 times

Post by Anand » Sun Aug 11, 2019 9:52 am

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
Image

ROBROS
Posts: 186
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen
Has thanked: 56 times
Been thanked: 18 times

Post by ROBROS » Sun Aug 11, 2019 7:11 pm

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

User avatar
dragancesu
Posts: 714
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia
Has thanked: 24 times
Been thanked: 149 times

Post by dragancesu » Mon Aug 12, 2019 8:57 am

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
Attachments
change.zip
(15.91 KiB) Downloaded 28 times

Post Reply