SQLitening Support Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Welcome to the SQLitening support forums!

Author Topic: Writing Images  (Read 558 times)

Fredrick Ughimi

  • Master Geek
  • ****
  • Posts: 601
    • View Profile
    • Software Development Company
Writing Images
« on: May 29, 2018, 07:47:39 AM »

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.

Code: [Select]
eCode = GetLocalFile(m_sPixName, m_sPicture)
If eCode Then ? "GetLocalFile error" + Str$(eCode),%MB_SYSTEMMODAL,"GetLocalFile Error"
Logged
Fredrick O. Ughimi

fughimi@yahoo.com
- Freedom lies in being bold -- Robert Frost, Poet

Fredrick Ughimi

  • Master Geek
  • ****
  • Posts: 601
    • View Profile
    • Software Development Company
Re: Writing Images
« Reply #1 on: May 29, 2018, 01:06:38 PM »

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.

Logged
Fredrick O. Ughimi

fughimi@yahoo.com
- Freedom lies in being bold -- Robert Frost, Poet

Fredrick Ughimi

  • Master Geek
  • ****
  • Posts: 601
    • View Profile
    • Software Development Company
Re: Writing Images
« Reply #2 on: May 30, 2018, 06:13:25 AM »

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.

 
Logged
Fredrick O. Ughimi

fughimi@yahoo.com
- Freedom lies in being bold -- Robert Frost, Poet

Bern Ertl

  • Master Geek
  • ****
  • Posts: 496
  • Excellent
    • View Profile
    • InterPlan Systems
Re: Writing Images
« Reply #3 on: May 30, 2018, 07:53:16 AM »

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

  • Master Geek
  • ****
  • Posts: 601
    • View Profile
    • Software Development Company
Re: Writing Images
« Reply #4 on: June 01, 2018, 06:06:33 AM »

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.
Logged
Fredrick O. Ughimi

fughimi@yahoo.com
- Freedom lies in being bold -- Robert Frost, Poet

Fredrick Ughimi

  • Master Geek
  • ****
  • Posts: 601
    • View Profile
    • Software Development Company
Re: Writing Images
« Reply #5 on: June 01, 2018, 10:34:23 AM »

Hello,

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

Thanks.
Logged
Fredrick O. Ughimi

fughimi@yahoo.com
- Freedom lies in being bold -- Robert Frost, Poet

Bern Ertl

  • Master Geek
  • ****
  • Posts: 496
  • Excellent
    • View Profile
    • InterPlan Systems
Re: Writing Images
« Reply #6 on: June 01, 2018, 10:46:08 AM »

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

cj

  • Master Geek
  • ****
  • Posts: 696
    • View Profile
Re: Writing Images - reposted
« Reply #7 on: June 01, 2018, 11:17:55 AM »

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                                                         
« Last Edit: June 01, 2018, 11:26:53 AM by cj »
Logged
CJ

Fredrick Ughimi

  • Master Geek
  • ****
  • Posts: 601
    • View Profile
    • Software Development Company
Re: Writing Images
« Reply #8 on: June 01, 2018, 11:26:40 AM »

Thanks.
Logged
Fredrick O. Ughimi

fughimi@yahoo.com
- Freedom lies in being bold -- Robert Frost, Poet

cj

  • Master Geek
  • ****
  • Posts: 696
    • View Profile
Re: Writing Images - Need to see update statement?
« Reply #9 on: June 01, 2018, 11:35:33 AM »

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?

« Last Edit: June 01, 2018, 11:46:53 AM by cj »
Logged
CJ

Fredrick Ughimi

  • Master Geek
  • ****
  • Posts: 601
    • View Profile
    • Software Development Company
Re: Writing Images
« Reply #10 on: June 01, 2018, 01:17:12 PM »

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.


Logged
Fredrick O. Ughimi

fughimi@yahoo.com
- Freedom lies in being bold -- Robert Frost, Poet

cj

  • Master Geek
  • ****
  • Posts: 696
    • View Profile
Re: Writing Images
« Reply #11 on: June 01, 2018, 01:18:32 PM »

Quote
Yes 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?
« Last Edit: June 01, 2018, 01:25:29 PM by cj »
Logged
CJ

Fredrick Ughimi

  • Master Geek
  • ****
  • Posts: 601
    • View Profile
    • Software Development Company
Re: Writing Images
« Reply #12 on: June 01, 2018, 01:34:39 PM »

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?
Logged
Fredrick O. Ughimi

fughimi@yahoo.com
- Freedom lies in being bold -- Robert Frost, Poet

cj

  • Master Geek
  • ****
  • Posts: 696
    • View Profile
Re: Writing Images
« Reply #13 on: June 01, 2018, 01:46:37 PM »

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           
 


« Last Edit: June 01, 2018, 01:48:09 PM by cj »
Logged
CJ