| Subject |
Re: Copy an image field from one table to another |
| From |
roy price <royprice@royprice.name> |
| Date |
Fri, 16 Apr 2021 23:44:40 -0400 |
| Newsgroups |
dbase.getting-started |
Mervyn Bick Wrote:
> On 2021/04/16 11:18, roy price wrote:
> > Hello Again,
> > I was gaily adding additional photos to my file photos03, when I came across the message "Database engine fail" (not sure of the exact wording).
> > I presume that means a corrupted file
> > So I've gone back and copied a backup file, and wrote a small program to compare both files and add (the additional) records from the problem file to the backup file.
> > As in select 1, fields to memory, select 2, and copy memory items to appended records. Then I realised that I do not know how to copy the binary field that way .
> > Any suggestions?
> > Regards
> > Roy Price
> >
Thanks Mervyn,
I managed to get a non-corrupted version reconstructed with your help, starting with a backup from a while ago, the subsequent backups also had the same problem. The file mostly worked, hiding the problem, it was only when I tried to copy it to another name that the failure occurred.
Regards
Roy Price
>
> If the photos03 table is corrupted it may not be possible to use it. On
> the other hand, if you've been able to open the table by double-clicking
> on it in the Navigator then all may not be lost.
>
> One can't simply use replace a->fieldname with b->fieldname for a binary
> (non text) field. The only way to get an image from one table to
> another if one is not copying the entire table is to export the image to
> a file and then load that file into the new file.
>
> An added complication is if you have used an autoinc field as the id for
> the images. One can't save a value to an autoinc field. One has to
> append a blank record which will allow dBASE to assign a value to the
> field.
>
> Firstly, before you try anything you must only be working with copies of
> the old backup table and photo03.
>
> The following little program should do the job. Copy and paste it into
> a new program file. Before you use it you must make sure that the
> correct table names are used and that the correct number for the image
> field is used. Change anything that is incorrect.
>
> ******** Start of program ********
> cSource = 'photo03' //the damaged table which would not accept entries.
> cTarget = 'backup01' //the old backup table which doesn't include
> //the latest images
>
> //Edit the lines above to show the correct table names.
>
> //set up the damaged file which has images not previously saved
> //to a backup
> q = new query()
> q.sql = 'select * from ' + cSource
> q.active = true
> //set up target file i.e the old backup which does not have all the images
> q1 = new query()
> q1.sql = 'select * from ' + cTarget
> q1.active = true
> //go to the bottom of the target table and save ID value for the
> //last record. This will be used to find the corresponding record
> //in photo03.
> q1.rowset.last()
> nId = q1.rowset.fields['id'].value
> //Find that record in the source table
> q.rowset.applyLocate( "id = " + nId )
> //Goto the next record i.e the first record not already in the target
> // table
> q.rowset.next()
> do while not q.rowset.endofset
> q1.rowset.beginAppend() //add a blank record
> //we can't place a value in an auto inc field so skip 1st field
> for n = 2 to q.rowset.fields.size
> if n = 2 //the image field
> // Make sure you have the correct field here.
> if file('temp_image') //Note: No dot
> erase temp_image
> endif
> q.rowset.fields[n].copyToFile('temp_image.')
> //Note: Dot at end of name
> q1.rowset.fields[n].replaceFromFile('temp_image.')
> else
> q1.rowset.fields[n].value = q.rowset.fields[n].value
> endif
> next
> q1.rowset.save() // save the new record
> //go to the next record in the source table
> q.rowset.next()
> enddo
> q.active = false
> q1.active = false
> ******* End of program **********
>
> Mervyn.
>
>
>
>
>
>
>
>
|
|