Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
MySQL
Message
From
01/11/2003 09:50:22
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
01/11/2003 06:56:04
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Re: MySQL
Miscellaneous
Thread ID:
00845333
Message ID:
00845345
Views:
29
>Hi,
>I'am trying to do an application in VFP 8.0 that uses MySQL as a database server.
>One of the tasks is to manipulate pictures (jpg files).
>For example:
>- in MySQL I've created a database ("database1") and a table ("table1") with 2 fields:
> name char(20)
> picture blob
>
> In the table "table1" I have 1 record with name="jean" and the picture is about 34 kb (a jpg file)
>
>
>- in VFP I connect to MySQL through an ODBC driver ("testdbf") and in the command window I do the followings:
> x=SQLCONNECT("testdbf")
> SQLEXEC(x," select name, picture from table1 ","_cursor")
> browse
>
>The browse window looks like this:
> _____________________
> | Name | Picture |
> |________|__________|
> |jean | Gen |
> |________|__________|
>
>The problem is that when I double click on Gen I get the following error:
> "OLE object is invalid or corrupted"
>I've tried to store in a file the content of the Gen field with STRTOFILE(picture,"picture.jpg") but I get an error too.
> There is no problem with MySQL because I've tested it with a PHP script and it goes right (shows the picture).
>
>So please help me with some ideas how can I send and manipulate binary files between VFP and MySQL and viceversa.
>
>Thanks.
>
>

StrToFile() wouldn't work with a general field but memo.
select _cursor

Copy fields picture to tmpPics
lnHandle = Fopen('tmpPics.dbf',12)
Fseek(lnHandle,43,0)
Fwrite(lnHandle,'M',1) && Changing General to Memo
Fclose(lnHandle)
Select 0
USE tmpPics
Scan
    StrToFile(picture, 'Picture'+Ltrim(Str(Recno()))+'.jpg')
EndScan
Use
Erase ('tmpPics.*')

oForm = CreateObject('myForm')
oForm.Show
Read events

Define Class myForm as Form
    Height = 200
    Width = 500
    DoCreate= .t.
    
     Add Object myGrid as Grid with height = 200, width=200

    Add Object picview as Image with ;
    height = 100, width=200, left = 220
    
     Procedure MyGrid.Init
         this.Recordsource = '_cursor'
         this.Columncount = 1
    EndProc
    Procedure MyGrid.AfterRowColChange
         Lparameters nIndex
         thisform.picview.picture = 'Picture'+Ltrim(Str(Recno()))+'.jpg'
    EndProc
    Procedure QueryUnload
    Clear events
    endproc
enddefine
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform