First, please try this sample as it is. This sample uses the MySql Demo server provided by FWH.
This sample demonstrates inserting directly into the table using oCn:Insert(...) syntax and also inserting into the RowSet using oRs:Append(...), if a RowSet is opened.
Please ensure that the blob field is not minblob or mediumblob. largeblob is safer. Creating tables with FWH's oCn:CreateTable(...) is safe and avoids any possible problems in future.
Code: Select all
#include "fivewin.ch"
function Main()
local oCn, oRs
local oDlg, oFont, oBold, oImage, oBrw
oCn := FW_DemoDB()
if !oCn:TableExists( "images" )
oCn:CreateTable( "images", { { "name", "C", 20, 0 }, { "image", "m", 10, 0 } } )
endif
oRs := oCn:RowSet( "images" )
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
DEFINE FONT oBold NAME "TAHOMA" SIZE 0,-14 BOLD
DEFINE DIALOG oDlg SIZE 900,700 PIXEL TRUEPIXEL FONT oFont
@ 20, 20 XIMAGE oImage FILE "c:\fwh\bitmaps\olga1.jpg" SIZE 300,400 OF oDlg
oImage:lCanPaste := .t.
@ 20,340 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
DATASOURCE oRs COLUMNS "ID", "NAME", "IMAGE" ;
CELL LINES NOBORDER
WITH OBJECT oBrw
:lCanPaste := .t.
:Image:cDataType := "P"
:Image:nDataBmpAlign := AL_CENTER
:nRowHeight := 100
:nStretchCol := 3
//
:CreateFromCode()
END
@ 450, 20 BUTTON "INSERT IMAGE INTO TABLE" SIZE 300,30 PIXEL OF oDlg FONT oBold ;
ACTION ( ;
oCn:Insert( "images", "name,image", { TIME(), BmpToStr( oImage:GetHBitmap() ) } ), ;
oRs:ReQuery(), ;
oBrw:GoBottom(), ;
oBrw:Refresh() )
@ 500, 20 BUTTON "INSERT IMAGE INTO ROWSET" SIZE 300,30 PIXEL OF oDlg FONT oBold ;
ACTION ( ;
oRs:Append( "name,image", { TIME(), BmpToStr( oImage:GetHBitmap() ) } ), ;
oBrw:Refresh() )
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont, oBold
oRs:Close()
oCn:Close()
return nil
//----------------------------------------------------------------------------//
Step-1: Please copy this sample to \fwh\samples folder. Change image file path "c:\fwh\bitmaps\olga1.jpg" to your fwh path, if necessary.
Build with buildh.bat or buildx.bat.
Step-2: Change oCn := FW_DemoDB() with your connection to your server and try again.
Step-3: Please check for differences between your "imagen" table and this "images" table and the exact code you have used in your program.