• Welcome to SQLitening Support Forum.
 

News:

Welcome to the SQLitening support forums!

Main Menu

Writing Images

Started by Fredrick Ughimi, May 29, 2018, 10:17:39 AM

Previous topic - Next topic

Fredrick Ughimi

Hello,

I use the codes (from CJ) below for both inserting and updating an image on a client/server application.
It works fine when the images are on the same client machine. But issues arises when
updating from a different client machine that don't have the images stored on the hard drive, even
when the images are already saved in the table, it gets cleared out when updating.


eCode = GetLocalFile(m_sPixName, m_sPicture)
If eCode Then ? "GetLocalFile error" + Str$(eCode),%MB_SYSTEMMODAL,"GetLocalFile Error"

Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

Fredrick Ughimi

Hi CJ,

Thanks for your response.

When a record that already has an image stored is updated in another machine that don't have the image stored on the hard drive, the image would be removed from the table except the image is on the hard drive.

Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

Fredrick Ughimi

Hello CJ,

Quote
I do not understand the problem because I am thinking this:

Let me try again.

1. System A: I save data and image. System A has the scanned images on the hard driver
2. System B: I read data and image and I make changes to the data and UPDATE, in the process the image gets removed from the table. System B don't have the images on the hard drive

Note: If the UPDATE is done using System A, the image would not be lost.

 
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

Bern Ertl

It's hard to debug or troubleshoot a program when you can't see any code, so forgive me if this question covers obvious territory, but, is the UPDATE code executed from system B attempting to update the field in the database where the image is stored?  If so, why?  UPDATE only needs to update the fields that actually have new/changed data.


Fredrick Ughimi

Sorry CJ and Bern for the late response. I was hit by a very bad toothache this past days. I am feeling much better now.

The application runs on c/s. The thing is my client uses the application at random. One person could enter data without
inserting pictures on one system, while the second person would insert the pictures on another system by using update. Which
is fine because the pictures would be residing on the second persons system. Then a third person might want to edit data
and then update in the process it gets error 53 and clears the picture in the table already inserted by the second person,
since the third person don't have the pictures in his or system. Pictures are placed locally.

What it translates to is that data can't be updated successfully without having the pictures present on the local machine
even if the picture is already in the table.

Maybe I need to put some restrictions to the random usage.

Best regards.
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

Fredrick Ughimi

Hello,

I would appreciate it if you could repost the codes you posted earlier here. It might come in handy.

Thanks.
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

Bern Ertl

Could you post the SQL statement that is being used to update the table that "clears the picture"?

cj

#7
Would also like to see the update statement.
If there is no image on disk (error 53) the update statement should never update the image column.


This logic would update the image column only if the image is on disk and if successful delete it from disk.

create table t1(c1,c2) '2 columns in this example, c2 is image

eCode = GetLocalFile(sPixName,sPix)
IF ecode = 0 THEN 'image is on disk if ecode is 0 so update both columns
  sBind = slBuildBindDat(sPixName,"T") + _
          slBuildBindDat(sPix,"B")  'image
          slexeBind "update t1 set c1=?,c2=? where rowid ="+STR$(rowid),sBind
          IF slGetChangeCount then Kill sPixName  'might be a nice touch so image isn't continually updated

ELSE     'binding may not be needed, but many prefer to always bind.  Only update 1 column
          sBind = slBuildBindDat(sPixName,"T")
          slexeBind "update t1 set c1=? where rowid ="+STR$(rowid),sBind
END IF                                                         

Fredrick Ughimi

Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

I remember the images only need to be on local disk at time of display
Get image from table
Save image to disk file
Display disk file
Delete disk file

Did the update statement always update all columns, curious minds would like to know?
Did you get it working?


Fredrick Ughimi

Quote
Did the update statement always update all columns, curious minds would like to know? Did you get it working?

Yes the update statement always update all columns and it works fine if the images are on the local disk, just like the scenario I painted above (second user updating the pictures).

The thing is they are trying to update record without having the pictures on the local disk. I think its fine as it is.


Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

#11
QuoteYes the update statement always update all columns and it works fine if the images are on the local disk
The thing is they are trying to update record without having the pictures on the local disk. I think its fine as it is.

I disagree.
If there is no image on disk then updating all columns will wipe out the image column with nothing from disk.


How can it be fine if it is clearing the image column?

Fredrick Ughimi

Quote
I disagree.
If there is no image on disk then updating all columns will wipe out the image column with nothing from disk.

Ok. I could intercept the wiping out the image from the table with a message and exiting the module if image is not on disk.

If I decide to exclude the images while updating then they won't be able to insert images while updating even if they have the images on the local disk.

What would you suggest?
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

#13
If no image on disk do not update the image column unless they want to delete the image.

1. IF statement after checking if the image is on disk to execute one of two statements.
2. IF statement with 2 functions

Options: Ask the user what they want to do.  No question needed if they have no images.


What is wrong with this?

This logic would update the image column only if the image is on disk and if successful delete it from disk.

create table t1(c1,c2) '2 columns in this example, c2 is image

eCode = GetLocalFile(sPixName,sPix)
IF ecode = 0 THEN 'image is on disk if ecode is 0 so update both columns
  sBind = slBuildBindDat(sPixName,"T") + _
          slBuildBindDat(sPix,"B")  'image
          slexeBind "update t1 set c1=?,c2=? where rowid ="+STR$(rowid),sBind
          IF slGetChangeCount then Kill sPixName  'might be a nice touch so image isn't continually updated

ELSE     'binding may not be needed, but many prefer to always bind.  Only update 1 column
          sBind = slBuildBindDat(sPixName,"T")
          slexeBind "update t1 set c1=? where rowid ="+STR$(rowid),sBind
END IF