SQLitening Support Forum

Support Forums => You've got Questions? We've got Answers! => Topic started by: Fredrick Ughimi on August 12, 2017, 12:07:14 PM

Title: Saving Images Remotely
Post by: Fredrick Ughimi on August 12, 2017, 12:07:14 PM
Hello,

On a Client/Server arrangement I guess its ok to load images from a
sub directory of the client computer i. e C:\ClientFiles\Pictures
and saved on the remote SQlitening Database.

I get a error "-8 Access Denied" and sometimes I get "-9 - File does not exit"


m_sPixNamePath = Exe.Path$ & "Pictures\" & m_sPixName
slGetFile m_sPixNamePath, m_sPicture, "E1" '9216 bytes


Is there a way around this?
Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on August 13, 2017, 12:57:35 PM
Thanks CJ.

Tried out the codes in my program and I got a crash. Same thing happened when I ran it on the PB IDE.


#COMPILE EXE
#DIM ALL
#INCLUDE "sqlitening.inc"

FUNCTION PBMAIN () AS LONG
    LOCAL sServer AS STRING
    LOCAL sPort AS STRING
    LOCAL sErr AS STRING
    LOCAL Errorcode&

    sServer = "MegaNetSoftware"

    sPort = "Default"

    slConnect(sServer, VAL(sPort))

    sErr = slGetError
    IF VAL(sErr) <> 0 THEN
         MSGBOX sErr, %MB_TASKMODAL OR %MB_ICONINFORMATION, EXE.NAME$
         EXIT FUNCTION
    END IF

   slOpen ("CharkinERPDB.db3","C")

LOCAL m_sPixNamePath AS STRING
LOCAL m_sPixName     AS STRING
LOCAL m_sPicture     AS STRING

m_sPixnamePath = EXE.PATH$ & "Pictures\"
m_sPixName     = "Ughimi.jpg"
slSetProcessMods "L0"
slGetFile m_sPixnamePath & m_sPixName,m_sPicture,"E1"
IF slGetErrorNumber = 0 THEN ? USING$("image length #,",LEN(m_sPicture))
Errorcode& = slExeBind(slBuildInsertOrUpdate("tblDPRRegistration", "?"), _
slBuildBindDat(m_sPicture, ("B")))
END FUNCTION
                               

Title: Re: Saving Images Remotely
Post by: cj on August 15, 2017, 07:07:37 PM
Note: Switching between local mode (L0) and remote mode (L1) can be eliminated using GET or GET$ instead of slGetFile reading local .jpg files.

SQlite suggests storing images in a table rather than pointing to there location.
One article mentions that the opening and closing of individual files may take longer than accessing from the database!
I'm curious if attaching to a separate database might have some advantages, but haven't yet found any articles on doing it.
https://sqlite.org/intern-v-extern-blob.html
https://sqlite.org/fasterthanfs.html#read_performance_measurements

Others don't agree storing images in tables (at least the main table.)
https://www.quora.com/Is-it-a-bad-design-to-store-images-as-blobs-in-a-database

Example getting local files without using slSetProcessMods "L0" or slGetFile to stay in remote mode and sent files from local machine.
http://sqlitening.com/support/index.php?topic=9675.0

#INCLUDE "sqlitening.inc"
'-------------------------------------------------------------------------------------------------
FUNCTION PBMAIN () AS LONG 
LOCAL sServer,sPathName,sFilename,sBlob AS STRING
slSetProcessMods "E0"

sServer   = "ip_or_machinename"
sPathName = "my_local_pictures\"
sFileName = "my.jpg"

slconnect sServer
IF slGetErrorNumber THEN ? sServer,%MB_SYSTEMMODAL,"Connect Error":EXIT FUNCTION

slOpen ("mydatabase.db3","C")
slexe "create table if not exists PictureTable(filename unique,blob)"

slSetProcessMods "L0"                    'switch to local processing
slGetFile sPathname + sFilename,sBlob    'get .jpg into a string sBlob$ from local disk
IF slGetErrorNumber = 0 THEN             'if no error
  WriteBlobRemote sFileName,sBlob         'switches to remote processing in SUB and inserts or updates Sqlite table
  GetBlobRemote  sFileName                'just testing (not needed) switches to remote processing in SUB and gets from SQlite table
ELSE
  ? slGetError,,sFilename
END IF

slSetProcessMods "L1" 'prevent possible slDisconnect crash if not in remote mode
slDisconnect
END FUNCTION
'-------------------------------------------------------------------------------------------------
SUB WriteBlobRemote(sFileName AS STRING,sBlob AS STRING)
LOCAL NumberOfChanges AS LONG
slSetProcessMods "L1"
NumberOfChanges = slGetChangeCount("T")
slexeBind "replace into PictureTable 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 PictureTable 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
Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on August 15, 2017, 08:23:49 PM
Hello CJ,

Quote
Keeping track of the images in a directory by using a pointer or storing in the database?
I can't decide, but if storing remotely they will still have to be accessed in the remote location and use slGetFile.
I think I would try just putting in another table and if it slows things down go the pointer route.
Storing in a table would seem simplier and more efficient to me.

Might as well continue on this part until I complete the project.  If the images slows things down later I would go the pointer route.

What advantages would it present if images are stored in a different table?

Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on August 15, 2017, 08:58:14 PM
CJ,

Quote
By the way, the picture table above is already a separate table.

Yeah. I am thinking of the best way to link the images table with the main table. Use the image name or an IDNo.
Title: Re: Saving Images Remotely
Post by: cj on August 16, 2017, 04:45:40 PM
Quote
Note: Switching between local mode (L0) and remote mode (L1) can be eliminated using GET or GET$ instead of slGetFile reading local .jpg files.

http://sqlitening.com/support/index.php?topic=9675.0
Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on August 16, 2017, 07:38:17 PM
Hello CJ,

I have been able to adapt your code to my project:

This worked great while I am saving the records.


  'Pictures
        m_sPixNamePath = Exe.Path$ & "Pictures\"
        m_sPixName = VD_GetText (hfrmDPRRegistrationForm, %ID_FRMDPRREGISTRATIONFORM_TXTPICTURENAME)
        slSetProcessMods "L0"
        slGetFile m_sPixnamePath + m_sPixName, m_sPicture,"E1"
        slSetProcessMods "L1" 'prevent slDisconnect failing if a local error occurred   


But I am still getting error -8 - Access Denied while reporting.

Title: Re: Saving Images Remotely
Post by: cj on August 16, 2017, 07:44:49 PM
Reporting, done locally?  Did you return to local mode using slSetProcessMods "L0" before reporting?
Does the server and the local machine use the same version of SQLite?

%SQLitening_AccessDenied =  -8 - Access denied
Title: Re: Saving Images Remotely
Post by: cj on August 16, 2017, 07:59:02 PM
Insufficent code to see where you connect and open database and get image


  'Pictures
        m_sPixNamePath = Exe.Path$ & "Pictures\"
        m_sPixName = VD_GetText (hfrmDPRRegistrationForm, %ID_FRMDPRREGISTRATIONFORM_TXTPICTURENAME)
        slSetProcessMods "L0"
        slGetFile m_sPixnamePath + m_sPixName, m_sPicture,"E1"
       
       
        GetBlobRemote(m_sPicture)
        slSetProcessMods "L0"
        'process locally

        'slSetProcessMods "L1"
         slDisconnect
Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on August 16, 2017, 08:02:39 PM
CJ,

Quote
Reporting, done locally?  Did you return to local mode using slSetProcessMods "L0" before reporting?
Does the server and the local machine use the same version of SQLite?

Reporting is done remotely.

Yes. I returned to local mode using slSetProcessMods "L0" before reporting. Sorry, I get  - error 21. See attached.


Method ReportCertificateOfTrainingInAdvancedRiggingAndLiftingGearInspectionCourse(ByVal nCbHndl As Long) As Long
      Local LineSpacing!,iHandle%,Row!,TopMargin!,PageSize!,PageNumber&
      Local detailline As Asciiz * 200
      Local sBatchNo As String
      Local hpix As Long   
      Local sTempImageFile As String
      Local sTempSignatureFile As String
      Local hSignature As Long
      Local sBind As String
     
      LineSpacing = .2
      TopMargin   = 0
      PAGESIZE    = 11.4

      ihandle% = dpStartDoc(0,"Mega-Net CharkinERP - Print Certificate of Training in Advanced Rigging and Lifting Gear Inspection Course","",%DDOC_INCH, _
      %DDOC_PAPER_CUSTOM, %DDOC_PORTRAIT, %DDOC_SYSTEM_DEFAULT, %DDOC_BIN_AUTO Or %DDOC_ALLOWSMTP Or %DDOC_ALLOWSAVE Or %DDOC_ZOOMFIT)

      If ihandle < 1 Then
           MsgBox "Could not StartDoc. Error number" + Str$(Ihandle),%MB_TASKMODAL Or %MB_ICONINFORMATION,VD_App.Title
           Exit Method
      End If
     
      dpPaperSize ihandle%, 8.0,11.4
     
      ROW = PAGESIZE                            'force new heading
     
      ReportsInformation() 
           
     sBatchNo = VD_GetText(nCbHndl, %ID_FRMCERTIFICATEOFTRAININGINADVANCEDRIGGINGANDLIFTINGGEARINSPECTIONCOURSERPTDLG_TXTBATCHNO)
     
     slSetProcessMods "L0"

     slSEL "SELECT * FROM tblDPRRegistration WHERE BatchNo = '" + sBatchNo + "'" 
     
     Do While slGetRow()
        slSetProcessMods "L0"
        sTempImageFile=GuidTxt$(Guid$) + ".jpg"    'change 2
        slPutFile sTempImageFile, slFN("Picture"), "C"  '25th column 'change 3 
       
        sTempSignatureFile=GuidTxt$(Guid$) + ".jpg"    'change 2
        slPutFile sTempSignatureFile, slFN("Signature"), "C"  '27th column 'change 3
       
        If ROW => PAGESIZE Then
           If PageNumber Then      'If first page don't need a new page
              dpNewPage iHandle%, %DDOC_PAPER_CUSTOM, %DDOC_PORTRAIT, %DDOC_BIN_AUTO
           End If
           Incr PageNumber
           dpFont ihandle%, %DDOC_FONTNORMAL + %DDOC_FONTBOLD, 20, %vbBlack, "Arial" 
           dpText IHandle%, 3.1,2.0, %DDOC_LEFT, "" + slFN("CertificateNo")
           dpText IHandle%, 2.9, 3.5, %DDOC_LEFT, "" + slFN("FirstName") & " " & slFN("Surname")  & " " &  slFN("Othernames")
           dpFont ihandle%, %DDOC_FONTNORMAL + %DDOC_FONTBOLD, 12, %vbBlack, "Arial"
           dpText IHandle%, 3.0,4.35, %DDOC_LEFT, "" + NigeriaDate(slFN("BirthDate"))
           dpText IHandle%, 5.7,8.6, %DDOC_LEFT, "" + NigeriaDate(slFN("Signature"))
           dpText IHandle%, 2.6,8.3, %DDOC_LEFT, "" + NigeriaDate(slFN("CourseEndDate"))
           hpix = dpAddGraphic(ihandle%, sTempImageFile+$Nul)
           Kill sTempImageFile  'change 5
           If hpix Then
              dpDrawGraphic ihandle%, hpix,5.9,6.9,7.1,8.2
           Else
            ? "Picture not found",%MB_TASKMODAL Or %MB_ICONINFORMATION,Exe.Name$
           End If   
           
           hSignature = dpAddGraphic(ihandle%, sTempSignatureFile+$Nul)
           Kill sTempSignatureFile  'change 5
           If hSignature Then
              dpDrawGraphic ihandle%, hSignature,4.1,6.8,5.6,7.0
           Else
            ? "Signature not found",%MB_TASKMODAL Or %MB_ICONINFORMATION,Exe.Name$
           End If
           
           ROW =  ROW + LineSpacing * 2
        End If
        ROW = ROW + LineSpacing                    'increment line counter
      Loop
      'slSetProcessMods "L1"
   dpEndDoc iHandle%, %DDOC_END_VIEW + %DDOC_END_PRINT

End Method     







Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on August 16, 2017, 08:14:36 PM
Quote
Insufficent code to see where you connect and open database and get image

I still use PwrDev IDE, so my codes are not one place.


'Connect/Open
sServer = "MegaNetSoftware"
   
    sPort = "Default"
   
    slConnect(sServer, Val(sPort))   
   
    sErr = slGetError
    If Val(sErr) <> 0 Then
         MsgBox sErr, %MB_TASKMODAL Or %MB_ICONINFORMATION, VD_App.Title
         Exit Function
    End If       
       
   slOpen ("CharkinERPDB.db3","C")

   Get Image:

        m_sPixNamePath = Exe.Path$ & "Pictures\"
        m_sPixName = VD_GetText (hfrmDPRRegistrationForm, %ID_FRMDPRREGISTRATIONFORM_TXTPICTURENAME)
        slSetProcessMods "L0"
        slGetFile m_sPixnamePath + m_sPixName, m_sPicture,"E1"
        slSetProcessMods "L1" 'prevent slDisconnect failing if a local error occurred   
       
        Errorcode& = slExeBind(slBuildInsertOrUpdate("tblDPRRegistration", "?" & $Nul & "?" & $Nul & "?" & $Nul & "?" & $Nul & _
        "?" & $Nul & "?" & $Nul & "?" & $Nul & "?" & $Nul & "?" & $Nul & "?" & $Nul & "?" & $Nul & "?" & $Nul & _
        "?" & $Nul & "?" & $Nul & "?" & $Nul & "?" & $Nul & "?" & $Nul & "?" & $Nul & "?" & $Nul & "?" & $Nul & _
        "?" & $Nul & "?" & $Nul & "?" & $Nul & "?" & $Nul & "?" & $Nul & "?" & $Nul & "?" & $Nul & "?"), _
          slBuildBindDat(SQLiteDate(m_sDate), "T") & _
          slBuildBindDat(m_sBatchNo, "T") & _ 
          slBuildBindDat(m_sIDMeans, "T") & _
          slBuildBindDat(m_sIDNo, "T") & _
          slBuildBindDat(m_sFirstName, "T") & _
          slBuildBindDat(m_sSurname, "T") & _   
          slBuildBindDat(m_sOthernames, "T") & _
          slBuildBindDat(SQLiteDate(m_sCourseStartDate), "T") & _   
          slBuildBindDat(SQLiteDate(m_sCourseEndDate), "T") & _
          slBuildBindDat(SQLiteDate(m_sExpiryDate), "T") & _   
          slBuildBindDat(m_sCourseCode, "T") & _     
          slBuildBindDat(m_sEmailAddress, "T") & _   
          slBuildBindDat(m_sCertificateNo, "T") & _
          slBuildBindDat(m_sCorrAddress, "T") & _ 
          slBuildBindDat(SQLiteDate(m_sBirthDate), "T") & _ 
          slBuildBindDat(m_sBirthPlace, "T") & _ 
          slBuildBindDat(m_sSponsor, "T") & _ 
          slBuildBindDat(m_sDepartment, "T") & _ 
          slBuildBindDat(m_sEmployeeIDNo, "T") & _ 
          slBuildBindDat(m_sNationality, "T") & _ 
          slBuildBindDat(m_sOccupation, "T") & _ 
          slBuildBindDat(m_sPhoneNo, "T") & _ 
          slBuildBindDat(m_sKinName, "T") & _
          slBuildBindDat(m_sKinPhoneNo, "T") & _   
          slBuildBindDat(m_sPixName, "T") & _
          slBuildBindDat(m_sPicture, ("B")) & _
               

Title: Re: Saving Images Remotely
Post by: cj on August 16, 2017, 08:55:54 PM
Quote
Reporting is done remotely.

Yes. I returned to local mode using slSetProcessMods "L0" before reporting. Sorry, I get  - error 21. See attached.

The data is on the server, but where do you get it?
You are in local mode.

Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on August 16, 2017, 09:08:38 PM
Quote
The data is on the server, but where do you get it?

Here:

slSEL "SELECT * FROM tblDPRRegistration WHERE BatchNo = '" + sBatchNo + "'"
Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on August 16, 2017, 09:13:44 PM
Quote
Is there a reason to keep requesting local routines?
slSetProcessMods "L0"

     slSEL "SELECT * FROM tblDPRRegistration WHERE BatchNo = '" + sBatchNo + "'" 
     
     Do While slGetRow()
        slSetProcessMods "L0"

I forgot to remove the second slSetProcessMods "L0". My mistake.

When I run the application with the correction made, I now get crash.


slSetProcessMods "L0"
slSEL "SELECT * FROM tblDPRRegistration WHERE BatchNo = '" + sBatchNo + "'"


Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on August 16, 2017, 09:15:44 PM
Quote
You are in local mode.

I am running the application on a remote mode.
Title: Re: Saving Images Remotely
Post by: cj on August 16, 2017, 09:23:54 PM
> I am running the application on a remote mode.

slSetProcessMods "L0" is local mode

Ln = Load either the local or remote processing lib and ruts. This along with push/pop database allows you to access both a local and remote database in the same running program. WARNING: The misuse of this may cause a GPF.
Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on August 16, 2017, 09:27:53 PM
Without the local mode placed before the SQL Select statement, I get error -8 Access Denied on the slPutFile Statement:


slPutFile sTempImageFile, slFN("Picture"), "C"
Title: Re: Saving Images Remotely
Post by: cj on August 16, 2017, 09:30:55 PM
Example getting local files without using slSetProcessMods "L0" or slGetFile to stay in remote mode and sent files from local machine.
http://sqlitening.com/support/index.php?topic=9675.0

You are always in local mode so server is never accessed.

I will add a local put to code in general forum so slSetProcessMods "L0"  and slSetProcessmods "L1" is never needed.
Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on August 16, 2017, 09:39:16 PM
Quote
You are always in local mode so server is never accessed.

Switching to remote mode or commenting all local mode statements, I get error -8 Access Denied on the slPutFile Statement:


slPutFile sTempImageFile, slFN("Picture"), "C"


Title: Re: Saving Images Remotely
Post by: cj on August 16, 2017, 09:41:41 PM
slPutFile doesn't work on server unless in FACT, but you are using ddoc locally so should be in local mode when doing slPutfile.
Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on August 16, 2017, 09:54:43 PM
Quote
slPutFile doesn't work on server unless in FACT, but you are using ddoc locally so should be in local mode when doing slPutfile.

You are right. But I am getting I getting error -8 Access Denied on the slPutFile Statement in local mode.

Let me check my SQLitening files.

Title: Re: Saving Images Remotely Helper functions
Post by: cj on August 16, 2017, 10:21:43 PM
Fredrick,

Please try running this code because it should help.
It allows staying in remote mode (no more slSetProcessMods L0 or L1)
Appreciate knowing you tested it.

http://sqlitening.com/support/index.php?topic=9676.0

4 Helper functions:
FUNCTION PutBlob(sBlobKey AS STRING,sBlob AS STRING) THREADSAFE AS LONG
FUNCTION GetBlob(sBlobKey AS STRING,sBlobData AS STRING) AS LONG
FUNCTION GetLocalFile(sFileName AS STRING, sData AS STRING) THREADSAFE AS LONG
FUNCTION PutLocalFile(sFileName AS STRING, sData AS STRING) THREADSAFE AS LONG


Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on August 17, 2017, 04:34:00 AM
Quote
Fredrick,

Please try running this code because it should help.
It allows staying in remote mode (no more slSetProcessMods L0 or L1)
Appreciate knowing you tested it.

http://sqlitening.com/support/index.php?topic=9676.0

4 Helper functions:
FUNCTION PutBlob(sBlobKey AS STRING,sBlob AS STRING) THREADSAFE AS LONG
FUNCTION GetBlob(sBlobKey AS STRING,sBlobData AS STRING) AS LONG
FUNCTION GetLocalFile(sFileName AS STRING, sData AS STRING) THREADSAFE AS LONG
FUNCTION PutLocalFile(sFileName AS STRING, sData AS STRING) THREADSAFE AS LONG

Sure. I would get right on it.

Thank you, CJ.
Title: Re: Saving Images Remotely Example
Post by: cj on August 17, 2017, 01:24:48 PM
#INCLUDE "sqlitening.inc"
$Server    = "192.168.0.2"
$DataBase  = "dummy.db3"
%ShowSteps = 0
%DropTable = 0
%Images = 9

FUNCTION PBMAIN() AS LONG
DIM sBlobArray(1 TO %Images) AS STRING
CreateTestFiles %Images       'dummy jpg files
ConnectRemote                 'connect remote database
UpdatePictureTable %Images    'update  remote images

GetImages %Images,sBlobArray()'get remote images
slDisconnect                  'disconnect
? JOIN$(sBlobArray(),$CR)     'show images
END FUNCTION

SUB CreateTestFiles(NumberOfImages AS LONG)
LOCAL x AS LONG, hFile AS LONG
LOCAL sJpgFileName AS STRING
FOR x = 1 TO NumberOfImages  'create dummy JPG files
  hFile = FREEFILE
  sJPGFileName= FORMAT$(x)+".tmp"
  OPEN sJPGFileName FOR OUTPUT AS #hFile
  PRINT #hFile, "Data in JPG file"+STR$(x);
  CLOSE hFile
NEXT
END SUB

SUB ConnectRemote
IF %ShowSteps THEN ? "1 connect",%MB_SYSTEMMODAL
slConnect $Server
slOpen $Database,"C"
IF %DropTable THEN slexe "drop table if exists PictureTable"
slexe  "create table if not exists PictureTable(blobkey unique,blobdata)"
END SUB

SUB UpdatePictureTable(NumberOfImages AS LONG)
LOCAL x AS LONG
LOCAL sJpgFileName,sBlob AS STRING
IF %ShowSteps THEN ? "2 write all JPG's",%MB_SYSTEMMODAL
FOR x = 1 TO NumberOfImages
  sJPGFileName= FORMAT$(x)+".tmp"
  GetLocalFile sJPGFileName,sBlob
  PutBlob "key"+FORMAT$(x),sBlob
NEXT
END SUB

SUB GetImages(NumberOfImages AS LONG,sBlobArray() AS STRING)
LOCAL x AS LONG
IF %ShowSteps THEN ? "3 get all JPG's",%MB_SYSTEMMODAL
REDIM sBlobArray(1 TO NumberOfImages) AS STRING
FOR x = 1 TO NumberOfImages
  GetBlob "key"+FORMAT$(x),sBlobArray(x)
NEXT
END SUB
'-------------------------------------------------------------------------------------------------

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

Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on August 17, 2017, 01:38:40 PM
CJ,

Both versions ran well. Its interesting.

Adopting it to my application is the tricky thing.

Still working on it.
Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on August 17, 2017, 02:52:54 PM
Not easy adapting your latest codes because I have not separated the image table from the rest of the data. I want all fields in one table together for the time being.

Edit: The REPLACE SQLite Statement is an interesting find.
Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on August 18, 2017, 09:17:02 AM
Hello CJ,

A couple of questions:

What is the difference

between:
FUNCTION PutBlob(sBlobKey AS STRING,sBlob AS STRING) THREADSAFE AS LONG
and:
FUNCTION PutLocalFile(sFileName AS STRING, sData AS STRING) THREADSAFE AS LONG

between:
FUNCTION GetBlob(sBlobKey AS STRING,sBlobData AS STRING) THREADSAFE AS LONG
and:
FUNCTION GetLocalFile(sFileName AS STRING, sData AS STRING) THREADSAFE AS LONG
and:
SUB GetImages(NumberOfImages AS LONG,sBlobArray() AS STRING)

Which of the functions should I use to replace:


slPutFile sTempImageFile, slFN("Picture"), "C"


Best regards,
Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on August 18, 2017, 11:34:40 AM
Cj,

My report works now. Using the PutLocalFile() function replacing slPutFile.


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             

PutLocalFile($TempImageFile, slFN("Picture"))
PutLocalFile($TempSignatureFile, slFN("Signature"))


Thanks a million.


Title: Re: Saving Images Remotely
Post by: cj on August 18, 2017, 12:43:15 PM
You are very welcome

Not usng slPutFile means application can stay in remote mode and write locally, great.
If slGetfile is ever used a switch back to local mode then remote mode will be required, bad.

GetLocalFile and PutLocalFile access local files on network so no SQL or SQLitening routines are loaded/reloaded.
This eliminates reloading local and remote routines using slSetProcessMods "L0" and slSetProcessMods "L1"

If in local mode the remote database was not available
If in remote mode the local files were not available using slGetFile or slPutFile
The  slSetProcessMods "L1" needed to be called before using remote routines
The  slSetProcessMods "L0" needed to be called if returning to access local .JPG files and temp file.

Note:
This application uses a single remote database.
If a local database was also needed, sllPushDatabase (save handle) and slPopDatabase (get handle)
would be needed to switch back and forth to use the handle of the current database.
Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on August 18, 2017, 03:12:18 PM
CJ,

I tried using the GetLocalFile() and I noticed that it only saves one image out of two images presented to it.
For instance I want to save a Picture and Signature images:


m_sPixName = Ughimi.jpg
GetLocalFile(m_sPixName, m_sPicture)
'--------------------------------------------'
m_sSignatureName = Signature1.jpg
GetLocalFile(m_sSignatureName, m_sSignature)


Only the Signature1.jpg would saved in its field. But if I comment out:


m_sPixName = "Ughimi.jpg"
GetLocalFile(m_sPixName, m_sPicture)
'--------------------------------------------'
'm_sSignatureName = "Signature1.jpg"
'GetLocalFile(m_sSignatureName, m_sSignature)


Ughimi.jpg would be saved in it's field.

How do I fix that?


     
Title: Re: Saving Images Remotely
Post by: cj on August 18, 2017, 04:21:05 PM
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"?

Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on August 18, 2017, 05:11:20 PM
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.
Title: Re: Saving Images Remotely
Post by: cj on August 18, 2017, 05:29:02 PM
Sounds like one of the ddoc routines isn't getting the complete path?
Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on August 18, 2017, 05:51:57 PM
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!
Title: REPLACE into when duplicate found
Post by: cj on August 20, 2017, 02:10:31 PM
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

Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on August 21, 2017, 09:08:23 PM
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.
Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on March 30, 2018, 07:00:53 PM
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


Title: Re: Saving Images Remotely
Post by: cj on March 30, 2018, 07:24:37 PM
It looks like you had it working in reply #27 by getting rid of "L0" and "L1" and using PowerBASIC GET and PUT routines.
Title: Re: Saving Images Remotely
Post by: cj on March 30, 2018, 08:40:37 PM
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
Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on March 30, 2018, 08:59:33 PM
Yes it seems. I would work on that route. Wonder why it wasn't there in the first place.
Title: Re: Saving Images Remotely
Post by: cj on March 30, 2018, 09:04:35 PM
http://sqlitening.com/support/index.php?topic=9676.0
Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on March 31, 2018, 04:12:39 PM
>>... Wonder why it wasn't there in the first place.

I meant in my codes.
Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on April 01, 2018, 01:39:23 PM
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)     
Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on April 01, 2018, 03:39:58 PM
I guess the invalid file name is referring to slFN("Picture") which quite valid. Would do some more testing.
Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on April 03, 2018, 12:20:48 PM
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?
Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on April 03, 2018, 01:27:59 PM
Hello CJ,

Quote
What is the value of sFileName?

sFileName = "ImageName.jpg"

Using the much improved slPutFileLocal I got access denied.


#COMPILE EXE
#DIM ALL
#INCLUDE "DDOC_P32.INC"
#INCLUDE "SQLitening.INC"

%vbBlack = &H0&
'%vbRed = &HFF&
'%vbGreen = &HFF00&
'%vbYellow = &HFFFF&
'%vbBlue = &HFF0000
'%vbMagenta = &HFF00FF
'%vbCyan = &HFFFF00
'%vbWhite = &HFFFFFF
'%vbGrey = &HC0C0C0
'%LIGHT_SHADE = &HE0E0E0

%AddClients=20
%TestMode = 0  'messagebox each time switch between local and server mode
%ClientServerFlag = 9999
THREADED ClientServer,CurrentMode AS LONG 'need to know when switching local/remote at all times

FUNCTION PBDate(sDate AS STRING) AS STRING
     'MM-dd-yyyy to dd-MM-yyyy

     FUNCTION = MID$(sDate,4,2) & "-" & MID$(sDate,1,2) & "-" & MID$(sDate,7,4)

END FUNCTION

FUNCTION NigeriaDate(sDate AS STRING) AS STRING
     'yyyy-MM-dd  to dd-MM-yyyy
     FUNCTION = MID$(sDate,9,2) & "-" & MID$(sDate,6,2) & "-" & MID$(sDate,1,4)

END FUNCTION

FUNCTION SQLiteDate(sDate AS STRING) AS STRING
     'From dd-MM-yyyy To yyyy-MM-dd

     FUNCTION = MID$(sDate,7,4) & "-" & MID$(sDate,4,2) & "-" & MID$(sDate,1,2)

END FUNCTION


FUNCTION PBMAIN () AS LONG
    LOCAL sServer, sPort, sErr AS STRING

    sServer = "Server"

    sPort = "Default"

    slConnect(sServer, VAL(sPort))

    sErr = slGetError
    IF VAL(sErr) <> 0 THEN
         MSGBOX sErr, %MB_TASKMODAL OR %MB_ICONINFORMATION, EXE.PATH$
         EXIT FUNCTION
    END IF

    slOpen ("CharkinPRNTDB.db3","C")

   'OpitoRegistration
   slExe BUILD$("Create Table If Not Exists tblOpitoRegistration(Date TEXT, BatchNo TEXT, IDMeans TEXT, IDNo TEXT, FirstName TEXT, Surname TEXT, Othernames TEXT, CourseStartDate TEXT,", _
   "CourseEndDate TEXT, ExpiryDate TEXT, CourseCode TEXT, EmailAddress TEXT, CertificateNo TEXT, CorrAddress TEXT, BirthDate TEXT, BirthPlace TEXT, Sponsor TEXT, Department TEXT,", _
   "EmployeeIDNo TEXT, Nationality TEXT, Occupation TEXT, PhoneNo TEXT, KinName TEXT, KinPhoneNo TEXT, PixName TEXT, Picture BLOB)")

   slExe "Create UNIQUE Index If Not Exists OpitoRegistrationndx1 ON tblOpitoRegistration(CertificateNo)"

   slExe "Create Index If Not Exists OpitoRegistrationndx2 ON tblOpitoRegistration(CourseCode, BatchNo)"

   ReportCertificate()


END FUNCTION

FUNCTION slPutFileLocal(sTempFile AS STRING,sBlob AS STRING) THREADSAFE AS LONG

LOCAL ModeBeforeHere,result AS LONG
ModeBeforeHere = CurrentMode
IF ModeBeforeHere <> 0 THEN SwitchLocal 'we must be local mode
FUNCTION = slPutFile(sTempFile,sBlob,"CT E0")
IF slGetErrorNumber THEN ? slGetError,,FUNCNAME$

IF ModeBeforeHere = %ClientServerFlag THEN SwitchRemote 'switch back to remote

END FUNCTION

'-------------------------------------------------------------------------------------------------
SUB SwitchLocal THREADSAFE

IF CurrentMode = 0 THEN EXIT SUB 'aleady in local mode
IF %TestMode THEN ? FUNCNAME$
slPushDatabase
slSetProcessMods "L0"
currentMode = 0

END SUB
'-------------------------------------------------------------------------------------------------
SUB SwitchRemote THREADSAFE

IF CurrentMode = %ClientServerFlag THEN EXIT SUB 'already in remote mode
IF %TestMode THEN ? FUNCNAME$
slPopDatabase
slSetProcessMods "L1"
CurrentMode = %ClientServerFlag

END SUB

FUNCTION ReportCertificate() AS LONG
      LOCAL LineSpacing!,iHandle&,Row!,TopMargin!,PageSize!,PageNumber&
      LOCAL detailline AS ASCIIZ * 200
      LOCAL sBatchNo AS STRING
      LOCAL hpix AS LONG
      LOCAL sData AS STRING
      'Dim zTemp As Asciiz * 300
      DIM iPrinted%
      DIM zText AS ASCIIZ * 2000
      DIM lh!
      LOCAL sFileName AS STRING
      LOCAL eCode AS LONG


      lh! = .17
      LineSpacing = .2
      TopMargin   = 0
      PAGESIZE    = 10

      ihandle = dpStartDoc(0,"Mega-Net CharkinPRNT - Print A50 Tropical Bosiet Travel Safely By Boat Certificate","",%DDOC_INCH, _
      %DDOC_PAPER_CUSTOM, %DDOC_PORTRAIT, %DDOC_SYSTEM_DEFAULT, %DDOC_BIN_AUTO OR %DDOC_ALLOWSMTP OR %DDOC_ALLOWSAVE OR %DDOC_ZOOMFIT)
      IF ihandle < 1 THEN
           MSGBOX "Could not StartDoc. Error number" + STR$(Ihandle),,FUNCNAME$
           EXIT FUNCTION
      END IF

      dpPaperSize iHandle, 8.2,11.7

      ROW = PAGESIZE                            'force new heading

      sBatchNo = "23"

     slSEL "SELECT * FROM tblOpitoRegistration WHERE BatchNo = '" + sBatchNo + "'"

     DO WHILE slGetRow()

        sData = slFN("Picture")
        eCode = slPutFileLocal(sFileName, sData)

        IF eCode THEN ? "PutLocalFile error" + STR$(eCode),%MB_SYSTEMMODAL,"PutLocalFile":EXIT FUNCTION

        IF ROW => PAGESIZE THEN
           IF PageNumber THEN      'If first page don't need a new page
              dpNewPage iHandle, %DDOC_PAPER_CUSTOM, %DDOC_PORTRAIT, %DDOC_BIN_AUTO
           END IF
           INCR PageNumber
           'dpText IHandle, 4.3,1.6, %DDOC_LEFT, "" + slFN("CertificateNo")
           dpFont ihandle, %DDOC_FONTNORMAL + %DDOC_FONTBOLD, 20, %vbBlack, "Arial"
           dpText IHandle, 2.0, 4.3, %DDOC_LEFT, "" + slFN("FirstName") & " " & slFN("Surname")  & " " &  slFN("Othernames")
           dpFont ihandle, %DDOC_FONTNORMAL + %DDOC_FONTBOLD, 12, %vbBlack, "Arial"
           dpText IHandle, 1.0, 8.9, %DDOC_LEFT, "" + NigeriaDate(slFN("CertificateNo"))
           dpText IHandle, 4.0,8.9, %DDOC_LEFT, "" + NigeriaDate(slFN("CourseStartDate"))
           dpText IHandle, 6.5,8.9, %DDOC_LEFT, "" + NigeriaDate(slFN("ExpiryDate"))

           hpix = dpAddGraphic(ihandle, sFileName+$NUL)

           ''Kill sFileName
           IF hpix THEN
              dpDrawGraphic ihandle, hpix,7.0,4.0,7.9,5.1
           ELSE
            ? "image not found",%MB_SYSTEMMODAL, EXE.NAME$
           END IF
           ROW =  ROW + LineSpacing * 2
        END IF

      zText = "The course covers modules on Helicopter Underwater "
      zText = zText + "Escape Training (HUET), Sea Survival, Fire Fighting & Self  "
      zText = zText + "Rescue, First Aid  & Hypothermia and Boat Transfers."

      iPrinted% = dpWrapText(IHandle, 1, 1, 3, 3, lh!, zText)

        ROW = ROW + LineSpacing                    'increment line counter
      LOOP

   dpEndDoc iHandle, %DDOC_END_VIEW + %DDOC_END_PRINT

  END FUNCTION


Title: Re: Saving Images Remotely
Post by: cj on April 03, 2018, 02:44:51 PM
PutFileLocal replaced slPutFileLocal which was removed from this BBS.
PutFileLocal eliminates the need to switch modes.
Title: Re: Saving Images Remotely
Post by: Fredrick Ughimi on April 04, 2018, 07:07:29 AM
Hello CJ,

Thanks alot! It works now. I used PutFileLocal and I noticed it was fast. I wonder why it not work earlier on. Greatful!
Title: Re: Saving Images Remotely
Post by: cj on April 04, 2018, 11:59:22 AM
Yes it is fast.
Cache reading back "temp.jpg" into ddoc and no loading/unloading DLL's switching modes.


Note:
I didn't check for the possibility of an error using PutLocalFile

'get picture
slsel "select picture from picturetable where picturekey = 'heidi'"
IF slGetErrorNumber = 0 AND slGetRow THEN
   sdata = slfn("picture")
   result = PutLocalFile($tempfile,sdata)
   IF result THEN
     ? USING$("PutLocalFile error #",result),%MB_ICONERROR,FUNCNAME$
   ELSE
    ShellExecute (0, "OPEN", $tempfile+$NUL, BYVAL 0, CURDIR$, %SW_SHOWNORMAL)
   END IF
END IF