• Welcome to SQLitening Support Forum.
 

News:

Welcome to the SQLitening support forums!

Main Menu

Saving Images Remotely

Started by Fredrick Ughimi, August 12, 2017, 12:07:14 PM

Previous topic - Next topic

cj

I don't understand the question since ecode& = GetLocalFile(sFilename as string, s as string) only reads.

Checked ecode& = 0  when calling GetLocalFile?
Checked ecode& = 0 when calling PutLocalFile?
Get rid of slSetProcessMods "L0" and "L1"?


Fredrick Ughimi

CJ

Quote
I don't understand the question since ecode& = GetLocalFile(sFilename as string, s as string) only reads.
Checked ecode& = 0  when calling GetLocalFile?
Checked ecode& = 0 when calling PutLocalFile?
Get rid of slSetProcessMods "L0" and "L1"?

All tested ok and I have long gotten rid of slSetProcessMods "L0" and "L1".

I noticed that having the Signature and Picture images in different directory is what seems to be causing the issue.
The issue goes away when they are Placed in the same directory. Don't know why this is.
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

Sounds like one of the ddoc routines isn't getting the complete path?

Fredrick Ughimi

Quote
Sounds like one of the ddoc routines isn't getting the complete path?

Its actually in my save routine and wasn't fully patted.

Works when fully patted.


m_sPixName = VD_GetText (hfrmDPRRegistrationForm, %ID_FRMDPRREGISTRATIONFORM_TXTPICTURENAME)
m_sPixNamePath = Exe.Path$ & "Pictures\" & m_sPixName
GetLocalFile(m_sPixNamePath, m_sPicture)
       
m_sSignatureName = VD_GetText (hfrmDPRRegistrationForm, %ID_FRMDPRREGISTRATIONFORM_TXTSIGNATURENAME)
m_sSignaturePath = Exe.Path$ & "Signatures\" & m_sSignatureName
GetLocalFile(m_sSignaturePath, m_sSignature)
       


This is beautiful. Thanks a lot, CJ!
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

When "REPLACE INTO" finds a duplicate unique key (other than rowid) the record is deleted.
A new ROWID is assigned and columns passed are insert.  Columns not named become NULL by default.

--If duplicate key found a new rowid is created and only columns passed are inserted;
drop table if exists junktable;
create table if not exists junktable(mykey unique);
replace into junktable values('one');
replace into junktable values('one'');
select rowid, * from junktable;

rowid   mykey
2         one


Fredrick Ughimi

Hello CJ,

Quote
When "REPLACE INTO" finds a duplicate unique key (other than rowid) the record is deleted.
A new ROWID is assigned and columns passed are insert.  Columns not named become NULL by default.

--If duplicate key found a new rowid is created and only columns passed are inserted;
drop table if exists junktable;
create table if not exists junktable(mykey unique);
replace into junktable values('one');
replace into junktable values('one'');
select rowid, * from junktable;

rowid   mykey
2         one

I always use named columns and I have read a bit of the REPLACE SQL Statement.

I think it suits my style of coding. I intend using it on forms that not heavily used by different users. For instance forms under my settings menu that are only used by Administrator of the application. I am finding ways to reduce my codes in some of my applications especially my Hospital Management Software and ERP. So heaving that they take over 15 minutes to compile.
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

Fredrick Ughimi

Hello CJ,

The image storing and retrieval project went to sleep for a while. The client recently brought it back to life.

I discovered that my save routine isn't saving anymore. Gone through our conversations here to see what I am

missing to no avail. I am thinking the link that you provided that is already removed could be the answer to problems. Not sure though.

In part here is what I have:



Sub WriteBlobRemote(sFileName As String,sBlob As String)
     Local NumberOfChanges As Long
     slSetProcessMods "L1"
     NumberOfChanges = slGetChangeCount("T")
     slexeBind "replace into tblOpitoRegistration values('" + sFileName + "',?)",slBuildBindDat(sBlob)
     If slGetErrorNumber Then
       ? slGetError,%MB_SYSTEMMODAL,"WriteBlobRemote"
       Exit Sub
     End If
     NumberOfChanges = slGetChangeCount("T") - NumberOfChanges
     If NumberOfChanges <> 1 Then ? "Picture could not be written"
End Sub       

Sub GetBlobRemote(sFileName As String)
     slSetProcessMods "L1"
     slSel "SELECT filename,blob from tblOpitoRegistration where filename ='"+sFilename + "'"
     If slGetErrorNumber Then
      ? slGetError,,"Show Blob Remote"
      Exit Sub
     End If
     If slGetRow Then
      ? Using$("&   #, bytes",slf(1),Len(slf(2))),%MB_SYSTEMMODAL,"Picture"
     Else
      ? sFileName,,"Remote Blob Not Found"
     End If
End Sub   

'Save Routine
slSetProcessMods "L0"
slGetFile m_sPixNamePath + sFilename,sBlob, "E0"
If slGetErrorNumber = 0 Then
   WriteBlobRemote sFileName,sBlob
   GetBlobRemote sFileName
Else
   ? slGetError,,sFilename
End If
slSetProcessMods "L1" 'prevent slDisconnect failing if a local error occurred


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

cj

It looks like you had it working in reply #27 by getting rid of "L0" and "L1" and using PowerBASIC GET and PUT routines.

cj

#38
Can you connect to my server?

#INCLUDE "sqlitening.inc"  'fredrick4.bas  as reference 3/20/18  6:13PM CST
'-------------------------------------------------------------------------------------------------
FUNCTION PBMAIN() AS LONG

LOCAL sLocalFileName,sLocalData,sData,sKey AS STRING, eCode AS LONG

'create local test file which will later be saved into a SQLitening blob column
sLocalFileName="test.txt"
OPEN sLocalFileName FOR OUTPUT AS #1:PRINT #1,"If you read this, it worked!!":CLOSE

slconnect "think.freemyip.com",47381   
slOpen    "Test.db3","C"                          'database to open
slexe     "create table if not exists PictureTable(blobkey unique,blobdata)"

'read local file
eCode = GetLocalFile(sLocalFileName,sLocalData)
IF eCode THEN ? "GetLocalFile error" + STR$(eCode),%MB_SYSTEMMODAL,"GetLocalFile Error"

'save data to server using key
sKey  = "Heidi Klum"                              'get and save key
eCode = PutBlob(sKey,sLocalData)
IF eCode THEN ? slGetError,%MB_SYSTEMMODAL,"WriteBlob"           :EXIT FUNCTION

'read data from server
eCode = GetBlob(sKey,sData)
IF eCode THEN ? slGetError,%MB_SYSTEMMODAL,"Getblob"             :EXIT FUNCTION
? sData,%MB_SYSTEMMODAL,"GetBlob"

slDisconnect

eCode = PutLocalFile("junk.txt",sData)            'write data to a local file
IF eCode THEN ? "PutLocalFile error" + STR$(eCode),%MB_SYSTEMMODAL,"PutLocalFile":EXIT FUNCTION

eCode = GetLocalFile("junk.txt",sLocalData)
IF eCode THEN ? "GetLocalFile error" + STR$(eCode),%MB_SYSTEMMODAL,"GetLocalFile Error"
? sData,%MB_SYSTEMMODAL,"GetLocalFile"

END FUNCTION
'-------------------------------------------------------------------------------------------------
FUNCTION PutBlob(sBlobKey AS STRING,sBlob AS STRING) THREADSAFE AS LONG

LOCAL NumberOfChanges AS LONG 'function returns 0 on success

NumberOfChanges = slGetChangeCount("T")
slexeBind "replace into PictureTable values('" + sBlobKey + "',?)",slBuildBindDat(sBlob)
IF slGetErrorNumber THEN
   FUNCTION = slGetErrorNumber
   EXIT FUNCTION
END IF
NumberOfChanges = slGetChangeCount("T") - NumberOfChanges
IF NumberOfChanges <> 1 THEN FUNCTION = -9999

END FUNCTION
'-------------------------------------------------------------------------------------------------
FUNCTION GetBlob(sBlobKey AS STRING,sBlobData AS STRING) THREADSAFE AS LONG

sBlobData = ""   'function returns 0 on success
slSel "select blobdata from PictureTable where blobkey ='"+sBlobKey + "'"
IF slGetErrorNumber THEN
  FUNCTION = slGetErrorNumber
  EXIT FUNCTION
END IF
IF slGetRow THEN sBlobData = slf(1)

END FUNCTION
'-------------------------------------------------------------------------------------------------
FUNCTION GetLocalFile(sFileName AS STRING, sData AS STRING) THREADSAFE AS LONG

sData = "" 'function returns 0 on success
LOCAL MaxRetry AS LONG
LOCAL hFile AS LONG

IF ISFALSE(ISFILE(sFileName)) THEN 'local file not found
  FUNCTION = 53                'set error 53, file not found
  EXIT FUNCTION                'exit function
END IF

hFile = FREEFILE              'file handle
FOR MaxRetry = 1 TO 10        'maximum 10 attempts to open
  ERRCLEAR                     'clear error
  OPEN sFileName FOR BINARY ACCESS READ LOCK WRITE AS #hFile 'block writers
  IF ERR THEN                  'open error
   SLEEP 500                   'wait
   ITERATE                     'retry open
  END IF
  GET$ #hFile,LOF(hFile),sData 'read data
  FUNCTION = ERR               '0 if success
  CLOSE #hFile                 'close file
  EXIT FOR
NEXT
FUNCTION = ERR                '10 attempts to open reached

END FUNCTION

FUNCTION PutLocalFile(sFileName AS STRING, sData AS STRING) THREADSAFE AS LONG

LOCAL MaxRetry AS LONG
LOCAL hFile AS LONG

hFile = FREEFILE              'file handle
FOR MaxRetry = 1 TO 10        'maximum 10 attempts to open
  ERRCLEAR                     'clear error
  OPEN sFileName FOR OUTPUT AS #hFile 'exclusive
  IF ERR THEN                  'open error
   SLEEP 500                   'wait
   ITERATE                     'retry open
  END IF
  PRINT #hFile, sData;         'write data
  FUNCTION = ERR               '0 if success
  CLOSE #hFile                 'close file
  EXIT FOR
NEXT
FUNCTION = ERR                '10 attempts to open reached

END FUNCTION

Fredrick Ughimi

Yes it seems. I would work on that route. Wonder why it wasn't there in the first place.
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet


Fredrick Ughimi

>>... Wonder why it wasn't there in the first place.

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

Fredrick Ughimi

Hi CJ,

Saving is good using:


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


Now I get PutLocalFile error 64 when reporting the image using:


eCode = PutLocalFile(slFN("Picture"), sData)            'write data to a local file
If eCode Then ? "PutLocalFile error" + Str$(eCode),%MB_SYSTEMMODAL,"PutLocalFile":Exit Method

hpix = dpAddGraphic(ihandle%, sData+$Nul)     
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

Fredrick Ughimi

I guess the invalid file name is referring to slFN("Picture") which quite valid. Would do some more testing.
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

Fredrick Ughimi

#44
Hi CJ,

Quote
'probably should be:
sData = slFN("Picture")
ecode = PutLocalFile(sFileName,sData)

Same error message.

I am running in C/S mode. Would that make any difference?
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet