change .dbf without losing data

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

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

change .dbf without losing data

Post 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
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: change .dbf without losing data

Post by edk »

:idea:
1. Copy to _temp.dbf
2. Change structure of dbf
3. Append from _temp.dbf
4. Delete _temp.dbf
User avatar
tomtagaris
Posts: 107
Joined: Tue Aug 23, 2016 2:43 pm

Re: change .dbf without losing data

Post by tomtagaris »

thanks
tom
User avatar
Anand
Posts: 595
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF

Re: change .dbf without losing data

Post 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
Regards,

Anand

Image
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Re: change .dbf without losing data

Post 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
User avatar
dragancesu
Posts: 920
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: change .dbf without losing data

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