FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Insert images in Mysql/Mariadb
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Insert images in Mysql/Mariadb
Posted: Fri May 26, 2017 09:33 PM

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 ?

Marc Venken

Using: FWH 23.08 with Harbour
Posts: 302
Joined: Fri Apr 23, 2010 04:30 AM
Re: Insert images in Mysql/Mariadb
Posted: Sat May 27, 2017 04:38 AM
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 (fw): Select all Collapse
//------------------------------------------------//

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
Nicanor Martinez M.
Auditoria y Sistemas Ltda.
MicroExpress Ltda.
FW + FWH + XHARBOUR + HARBOUR + PELLES C + XDEVSTUDIO + XEDIT + BCC + VC_X86 + VCC_X64 + MINGW + R&R Reports + FastReport + Tdolphin + ADO + MYSQL + MARIADB + ORACLE
nnicanor@yahoo.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Insert images in Mysql/Mariadb
Posted: Sat May 27, 2017 06:40 AM
Mr Venken

It is much simpler with FWH

Method (1)

Open the table as RowSet

Code (fw): Select all Collapse
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 (fw): Select all Collapse
oCn:Update( <tablename>, "foto", { MEMOREAD( filename) }, "id -= 99" )


if we want to add a new record with both member name and his photo
Code (fw): Select all Collapse
oCn:Insert( <tablename>, "name,foto", { "Mark Venken", MEMOREAD( "fotofilename" ) } )
Regards



G. N. Rao.

Hyderabad, India
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: Insert images in Mysql/Mariadb
Posted: Sat May 27, 2017 11:43 AM

Thanks. I gonna implement this into my program.

Marc Venken

Using: FWH 23.08 with Harbour
Posts: 811
Joined: Tue May 06, 2008 04:28 AM
Re: Insert images in Mysql/Mariadb
Posted: Fri May 11, 2018 02:54 AM

Hi Mr. Rao,

How about using SQL with blob for MariaDB?

Thanks,
Frances

Kind Regards,

Frances



Fivewin for xHarbour v18.07

xHarbour v1.2.3.x

BCC 7.3 + PellesC8 ( Resource Compiler only)

ADS 10.1 / MariaDB

Crystal Reports 8.5/9.23 DE

xMate v1.15
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Insert images in Mysql/Mariadb
Posted: Fri May 11, 2018 04:09 AM

Using FWH functions is a lot easier than preparing your own SQL statement.
The field has to be created as a BLOB field only.

Regards



G. N. Rao.

Hyderabad, India
Posts: 811
Joined: Tue May 06, 2008 04:28 AM
Re: Insert images in Mysql/Mariadb
Posted: Fri May 11, 2018 06:06 AM
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..
Kind Regards,

Frances



Fivewin for xHarbour v18.07

xHarbour v1.2.3.x

BCC 7.3 + PellesC8 ( Resource Compiler only)

ADS 10.1 / MariaDB

Crystal Reports 8.5/9.23 DE

xMate v1.15

Continue the discussion