trouble showing image from database

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Tron621
Posts: 4
Joined: Tue Jul 31, 2007 5:29 pm
Contact:

trouble showing image from database

Post by Tron621 » Thu Oct 08, 2009 7:11 am

I am new to this language, decided to build a database app as my first foray into the language. I created an Access database on retriving the data everything but the image (.bmp)file associated with the records show. what am I doing wrong... here is the code for the connect and get button.
put revdb_connect("odbc","db1",,,) into tConnectionID
-- check if we could connect; if not, show an error
if tConnectionID is not a number then
answer error tConnectionID
else
-- we're connected; execute some query
put "SELECT * FROM main WHERE pID = 2 " into tQuery
put 123456789 into tID

put revdb_querylist(tab,return,tConnectionID,tQuery) into tQueryList
put revQueryDatabase(tConnectionId, tQuery, "tID") into tResultSetId

-- close the connection
#get revdb_disconnect(tConnectionID)
end if
put empty into field "FirstName"
answer tQueryList
#answer tResultSetId
#get first column from tQueryList
put revDatabaseColumnNamed(tResultSetId, "pID") into field "tID"
put revDatabaseColumnNamed(tResultSetId, "pFirstName") into field "FirstName"
put revDatabaseColumnNamed(tResultSetId, "pLastName") into field "LastName"
put revDatabaseColumnNamed(tResultSetId, "pAddress") into field "Address"
put revDatabaseColumnNamed(tResultSetId, "pCity") into field "City"
put revDatabaseColumnNamed(tResultSetId, "pState") into field "State"
put revDatabaseColumnNamed(tResultSetId, "pPhone") into field "Phone"
put revDatabaseColumnNamed(tResultSetId, "pSkills") into field "Skills"
put revDatabaseColumnNamed(tResultSetId, "pFeatures") into field "Features"
put revDatabaseColumnNamed(tResultSetId, "pAge") into field "Age"
put revDatabaseColumnNamed(tResultSetId, "pnal") into nalvar
if nalvar is "1" then
set the hilite of button "Check1" to true
end if

put revDatabaseColumnNamed(tResultSetId, "pwallow") into wallowvar
if wallowvar is "1" then
set the hilite of button "Check2" to true
end if
# the get image part of the querry
put revDatabaseColumnNamed(tResultSetId, "pPhoto") into myimage

put revDatabaseColumnNamed(tResultSetId, "pPhoto") into field "tImage"

put base64encode (url("binfile:" & myimage)) into image tImage



-- close the connection
get revdb_disconnect(tConnectionID)
end mouseUp
if 6 was 9 then...

Paul D
Posts: 116
Joined: Mon May 21, 2007 6:58 pm

Post by Paul D » Thu Oct 08, 2009 2:41 pm

are you encoding the image before you put it into the database? Jan wrote something about this a little bit ago...

http://forums.runrev.com/phpBB2/viewtop ... se64decode

I dont really know the answer but maybe that post will help.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Thu Oct 08, 2009 4:33 pm

Dear Tron621,

Probably, you need to use base64decode instead of base64encode.

Are you sure that the image is base64encoded? If not, the data might be binary and I am not fully sure that you can retrieve this data with revDatabaseColumnNamed. You might need to do another query and use revQueryDatabase (or maybe revQueryDatabaseBlob) instead. For binary data, you will need to add the suffix *b to you variable name.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Tron621
Posts: 4
Joined: Tue Jul 31, 2007 5:29 pm
Contact:

Post by Tron621 » Thu Oct 08, 2009 5:17 pm

I put the images directly into the database from within access so they are not base64encoded you are right. looking for a querry that would retrieve that image if anyone knows of one.
if 6 was 9 then...

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Thu Oct 08, 2009 5:24 pm

Dear Tron621,

First, you need to find out in which format Access puts the images into the database.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Post by trevordevore » Fri Oct 09, 2009 5:33 pm

Tron621,

The way to extract binary data from a database is to use the holderVariable parameter of revDatabaseColumnNamed or revDatabaseColumnNumbered (don't worry about revQueryDatabase and revQueryDatabaseBlog, they are the same now). Revolution externals, of which RevDB is one, cannot pass binary data so the RevDB external has to explicitly assign binary data from the databae into a variable.

Code: Select all

put revDatabaseColumnNamed(theDBCursor, "pPhoto", "theBinaryData") into theError
As Mark said you need to know how Access stores the image as that will determine whether or not you can assign the data to a Revolution image object.

There is also the possibility that the ODBC driver could have trouble with binary data. I've seen that in some tests I've done while working on SQL Yoga. Try the holder variable approach with revDatabaseColumnNamed though as that is the first step.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

Post Reply