trouble showing image from database
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
trouble showing image from database
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
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...
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.
http://forums.runrev.com/phpBB2/viewtop ... se64decode
I dont really know the answer but maybe that post will help.
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
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
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Dear Tron621,
First, you need to find out in which format Access puts the images into the database.
Best,
Mark
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
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
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.
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.
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
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
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