[Gambas-user] Retrieving jpegs from a MySQL database

Lee McPherson leemcpherson at ...626...
Thu Apr 3 01:32:14 CEST 2008


Benoit Minisini wrote:
> On jeudi 3 avril 2008, Lee McPherson wrote:
>   
>> Benoit Minisini wrote:
>>     
>>> 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
>>>       
>> I added that line of code and it returned type 9... which seems like
>> it's reading it as a type String (or text for MySQL).  The db.blob
>> constant is -2.  I'm not sure what to do about this, as that field (Pic)
>> in the table Albums is configured to be of type BLOB in the MySQL
>> administrator app.
>>
>> Any clues?  I'm far from proficient using MySQL but it seems like
>> everything is correct.
>>
>> -Lee
>>
>>     
>
> You must use the LONGBLOB datatype if you want Gambas to see your field as a 
> blob. For an explanation, see: http://gambasdoc.org/help/doc/db-type-mapping
>
>
>   
That worked beautifully after I reloaded my tables!  Thank you very much!
-Lee




More information about the User mailing list