Page 1 of 1

Insert images in Mysql/Mariadb

Posted: Fri May 26, 2017 9:33 pm
by Marc Venken
Hello,

Looking into the posts, i didn't find my solution for the folowing problem.

All members of my soccer club will give me the pictures of each player to put into a online member system.
I put a field by MyAdmin into the database with folowing data :

Name "foto" and type "MEDIUM BLOB"

I see that I get a upload buttom from Phpmyadmin, and that Xbrowse is showing the picture afther I upload

I Use Xbrowse for all screens, but how do I put the files, that I have on disk into each row of Xbrowse for the online database ?
In a normal dbf structure, I always put a link (c:\foto\image1212) to a file on disk and show it that way, but with SQL/Maria it will go into the BLOB database ?

How do I proceed ?

Maybe the online invoice sample can be expanded with product foto's show into the xbrowse and insert from files on disk ?

Re: Insert images in Mysql/Mariadb

Posted: Sat May 27, 2017 4:38 am
by nnicanor
Hi Marc,

When you upload an image file into database you can use directly using Image object through :LoadFromMemory( oQry:Picture ) method of image class
if want to save to disk you can use this example oQry is a query from table with flowing columns finename and file blob field

Code: Select all


//------------------------------------------------//

Function SaveToDisk( oQry )

   LOCAL nHandle
   LOCAL cDir := cGetDir( "Select Folder",;
                          CurDrive() + ":\" + GetCurDir() + "\" )
   LOCAL oQryFind

   IF ! Empty( cDir )

       cursorwait()

      oQryFind = TDolphinQry():New( "select file from files where id=" + ClipValue2Sql( oQry:Id ), oQry:oServer )

      nHandle := FCreate( cDir + "\" + AllTrim( oQry:filename ) )

      IF FError() # 0
         MsgInfo( "Error Saving File " + cDir + "\" + AllTrim( oQry:filename ) )
         RETURN
      ENDIF

      FWrite( nHandle, oQryFind:file, Len( oQryFind:file ) )
      FClose( nHandle )

      cursorarrow()
        
      cFilename := alltrim(oQry:filename)
        
      MsgInfo( "File Saved in Folder: " + cDir )

      oQryFind:End()

      if Msgyesno("Do you Want to Open File ?")
        
               ShellExecute(,"Open",'"'+cDir+"\"+cFilename+'"',,,3)
        
      endif

   ENDIF

RETURN



Re: Insert images in Mysql/Mariadb

Posted: Sat May 27, 2017 6:40 am
by nageswaragunupudi
Mr Venken

It is much simpler with FWH

Method (1)

Open the table as RowSet

Code: Select all

oRs := oCn:Rowset( "tablename" )
// position the row on the member 
oRs:foto := MEMOREAD( <fotofilename> )
oRs:Save()
 
METHOD (2)

Without opening the table.

Assume the ID of the member is 99 and the member is already in the database

Code: Select all

oCn:Update( <tablename>, "foto", { MEMOREAD( filename) }, "id -= 99" )
 
if we want to add a new record with both member name and his photo

Code: Select all

oCn:Insert( <tablename>, "name,foto", { "Mark Venken", MEMOREAD( "fotofilename" ) } )
 

Re: Insert images in Mysql/Mariadb

Posted: Sat May 27, 2017 11:43 am
by Marc Venken
Thanks. I gonna implement this into my program.

Re: Insert images in Mysql/Mariadb

Posted: Fri May 11, 2018 2:54 am
by fraxzi
Hi Mr. Rao,

How about using SQL with blob for MariaDB?

Thanks,
Frances

Re: Insert images in Mysql/Mariadb

Posted: Fri May 11, 2018 4:09 am
by nageswaragunupudi
Using FWH functions is a lot easier than preparing your own SQL statement.
The field has to be created as a BLOB field only.

Re: Insert images in Mysql/Mariadb

Posted: Fri May 11, 2018 6:06 am
by fraxzi
nageswaragunupudi wrote:Using FWH functions is a lot easier than preparing your own SQL statement.
The field has to be created as a BLOB field only.

I got it. Based on MariaDB Wiki, it is very much simple.
Soon, I'll get my hands on my FWH upgrade..