[Gambas-user] Retrieving jpegs from a MySQL database

Benoit Minisini gambas at ...1...
Wed Apr 2 10:22:37 CEST 2008


On mercredi 2 avril 2008, Lee McPherson wrote:
> I've been looking at the examples supplied with Gambas and I've tried to
> copy some of the code from the PictureDatabase example.  I know that my
> database is setup correctly and that the field names are correct.  I
> have some jpegs stored as BLOBs and they display correctly using the
> MySQL Query browser.
>
> However, this code will give me the error "Not an object" and I'm at a
> loss as to what I'm doing wrong.  Below is some of my code.  Basically I
> have two tables so far.  One contains all the ID3v2 info from an MP3
> with album names represented by numbers.  These numbers are referenced
> to the album name and album cover art in jpeg format as a BLOB in a
> second table.  I click on the file I want in my gridview table and it is
> supposed to display the album cover in a PictureBox next to it.  The
> selection works and I can get it to reference the actual album's name,
> but it stops at the tempPicture = $result["Pic"].Data line.
>
> PUBLIC SUB GridView1_Change()
>   DIM sQuery AS String
>   DIM curRow AS Integer
>   DIM tempFile AS String
>   DIM tempPicture AS String
>
>   tempFile = Temp() & ".jpg"
>   IF gridView1.Row <> -1
>     modDb.Connect()
>     curRow = gridView1.Row
>     DEBUG curRow
>     DEBUG gridView1[curRow, 4].Text
>     $result = modDb.$Con.Exec("SELECT * FROM Albums WHERE ID = '" &
> gridView1[curRow, 4].Text & "'")

Don't do that, but: 

$result = modDb.$Con.Exec("SELECT * FROM Albums WHERE ID = &1", 
gridView[curRow, 4].Text)

>     DEBUG $result["AlbumName"]
>     tempPicture = $result["Pic"].Data
>     IF tempPicture THEN
>       File.Save(tempf, tempPicture)
>       PictureBox1.Picture = Picture.Load(tempF)
>       PictureBox1.Resize(PictureBox1.Picture.Width,
> PictureBox1.Picture.Height)
>     ELSE
>        PictureBox1.Picture = NULL
>     END IF
>     IF Exist(tempFile) THEN KILL tempFile
> '      PictureBox1.picture = $result!Pic
>   ENDIF
>
> END
>

Did you create the database with the database manager? Are you sure that 
$result["pic"] returns a blob object? You know that with: 

PRINT $result.Fields["pic"].Type

-- 
Benoit Minisini




More information about the User mailing list