Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sun Aug 09, 2020 12:29 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: RB 2010 and Binarystream
PostPosted: Wed Jan 27, 2010 4:51 pm 
Offline

Joined: Thu Apr 12, 2007 8:27 am
Posts: 31
In 2009 R4 i was able to read the contents of a blob from a database and recreate that file using binarystream, now in 2010 it doesn't work and I haven't been able to figure out how to do the same thing... Any ideas would be greatly appreciated...
Thanks in advance...
Kenny


Top
 Profile  
Reply with quote  
 Post subject: Re: RB 2010 and Binarystream
PostPosted: Wed Jan 27, 2010 5:01 pm 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
2010 as in the year... [ie.. it worked last month but not this month]
or are you infering RB2010r1? which I haven't even seen yet.

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: RB 2010 and Binarystream
PostPosted: Wed Jan 27, 2010 5:07 pm 
Offline

Joined: Thu Apr 12, 2007 8:27 am
Posts: 31
Sorry, I was talking about 2010FC1


Top
 Profile  
Reply with quote  
 Post subject: Re: RB 2010 and Binarystream
PostPosted: Wed Jan 27, 2010 5:09 pm 
Offline

Joined: Mon Aug 14, 2006 9:33 pm
Posts: 1774
Quote:
Sorry, I was talking about 2010FC1


Then you need to be discussing it on the Beta's list, not here.

_________________
Roger Clary
Class One Software
Educational Software for Lifelong Learning
http://www.classonesoftware.com


Top
 Profile  
Reply with quote  
 Post subject: Re: RB 2010 and Binarystream
PostPosted: Wed Jan 27, 2010 6:12 pm 
Offline

Joined: Thu Apr 12, 2007 8:27 am
Posts: 31
Yep, you're right sorry...


Top
 Profile  
Reply with quote  
 Post subject: Re: RB 2010 and Binarystream
PostPosted: Thu Mar 18, 2010 1:27 am 
Offline
User avatar

Joined: Tue Oct 13, 2009 11:05 am
Posts: 30
Location: Germany
well, now its final for a while and the problem still exists... due to other changes in the db on 2010 i can not go back without major work

any solutions?

_________________
My RealBasic project: Samanon


Top
 Profile  
Reply with quote  
 Post subject: Re: RB 2010 and Binarystream
PostPosted: Fri Mar 19, 2010 10:52 am 
Offline
User avatar

Joined: Sat Apr 19, 2008 12:44 pm
Posts: 442
Location: Dorset, UK
What do you mean 'it doesn't work?' I have an application that uses binarystream to read files, these are stored as blobs in a RealSQL Database. The files can then be read back from the database and recreated using binarystream - it works fine. (Mac 10.6.2, RB 2010 R1).

_________________
Simon Larkin
QiSQL Database Solutions

SQL Tutorial : http://qisql.com/qisql_sqlite_lessons.html


Top
 Profile  
Reply with quote  
 Post subject: Re: RB 2010 and Binarystream
PostPosted: Fri Mar 19, 2010 1:35 pm 
Offline
User avatar

Joined: Tue Oct 13, 2009 11:05 am
Posts: 30
Location: Germany
i have a column myblob as blob:

db.SQLExecute("create table tbl (id text, myblob blob)")


after writing a blob of about 10 megs to that table, the database file is about 10 megs bigger, so i assume the data is written.

it is written through a update (first select into recordset, change value, and RecordSet.Update it)

after reading with:

dim rs as RecordSet
rs=avail.SQLSelect("select * from tbl where id='"+ID+"'")


rs.Field("myblob").Value.Len (and LebB) deliver '4' which is much less than the 10 megs it should be

writing it with:

dim out as BinaryStream
out=BinaryStream.Create(f,true)
out.Write(rs.Field("myblob").Value)
out.Close


it is not writing the original 10 mb data, i guess its no wonder, as the value has len 4 and when outputting it with msgbox its just empty.

well, that's what i mean with 'it doesn't work' ;-)

actually i assume the problem is not the binarystream as stated in the topic, but the read from database

_________________
My RealBasic project: Samanon


Top
 Profile  
Reply with quote  
 Post subject: Re: RB 2010 and Binarystream
PostPosted: Fri Mar 19, 2010 1:40 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Did you do a Commit after the Update? Stupid question, I know, but that is one of the major changes recently. You used to be able to be more sloppy with your code.


Top
 Profile  
Reply with quote  
 Post subject: Re: RB 2010 and Binarystream
PostPosted: Sat Mar 20, 2010 4:51 am 
Offline
User avatar

Joined: Sat Apr 19, 2008 12:44 pm
Posts: 442
Location: Dorset, UK
Quote:
but the read from database
As Tim said - it's more likely to be the Write to the database (lack of commit?)

_________________
Simon Larkin
QiSQL Database Solutions

SQL Tutorial : http://qisql.com/qisql_sqlite_lessons.html


Top
 Profile  
Reply with quote  
 Post subject: Re: RB 2010 and Binarystream
PostPosted: Sat Mar 20, 2010 9:27 am 
Offline
User avatar

Joined: Tue Oct 13, 2009 11:05 am
Posts: 30
Location: Germany
yeah, commit was done, the filesize does increase so i think the data is written, actually i not only commit, i even commit and close after every access.

_________________
My RealBasic project: Samanon


Top
 Profile  
Reply with quote  
 Post subject: Re: RB 2010 and Binarystream
PostPosted: Sat Mar 20, 2010 11:05 am 
Offline
User avatar

Joined: Sat Apr 19, 2008 12:44 pm
Posts: 442
Location: Dorset, UK
Well, the code you have posted should work if there is a record with an Id value of ID (is the value of ID the record you want to read??) and there is data in the myblob field. As I said in my earlier post I regularly store files ( all types and sizes )using Binarystream in a database and recreate them using Binarystream and have had no problems with recent versions of RB - How about posting your Update code?

_________________
Simon Larkin
QiSQL Database Solutions

SQL Tutorial : http://qisql.com/qisql_sqlite_lessons.html


Top
 Profile  
Reply with quote  
 Post subject: Re: RB 2010 and Binarystream
PostPosted: Mon Mar 22, 2010 1:22 am 
Offline
User avatar

Joined: Tue Oct 13, 2009 11:05 am
Posts: 30
Location: Germany
well, i now went back to 2009r5 and it works, so the code should be ok:

dim rs as RecordSet
rs=db.SQLSelect("select * from tbl where id='"+ID+"'")
rs.Edit
rs.Field("myblob").StringValue=content
rs.Update
db.Commit
rs.Close

_________________
My RealBasic project: Samanon


Top
 Profile  
Reply with quote  
 Post subject: Re: RB 2010 and Binarystream
PostPosted: Tue Mar 23, 2010 5:06 am 
Offline
User avatar

Joined: Sat Apr 19, 2008 12:44 pm
Posts: 442
Location: Dorset, UK
OK so this is a bit odd! I've played around with some of my working code to to resemble your code and create a self contained test method. Does this work for you?

//Create a Database Record, Update the record by adding a JPEG or PDF File , read it back into the Temporary Folder and launch it (to make sure it worked!)

//Create A Temporary Test Database (or connect to existing DB)
dim dbf , f as FolderItem
dbf=SpecialFolder.Documents.child("test.rsd")
dim db as new REALSQLDatabase
dim sql as string
db.DatabaseFile=dbf
if not dbf.exists then
if not db.CreateDatabaseFile then
msgbox "DB NOT Created"
return
end
end
if not db.connect then
msgbox "No Connection"
return
end

//Create or Recreate linked_filesTable
db.SQLExecute ("drop table if exists test_linked_files" )
db.SQLExecute ("create table test_linked_files ( id integer primary key ,file_name text , file_data blob )")
db.commit

//Create A New Record and Save it to the database
dim rec as new DatabaseRecord
rec.column("file_name")= "Temporary File Name"
db.InsertRecord ("test_linked_files" , rec )
dim retid as integer =db.lastRowID()
if db.Error then
msgbox "Insert Failed - " + db.ErrorMessage
return
else
db.commit
end if

//Read The Data Back so we can Update it with a file read by BinaryStream
sql= "select * from test_linked_files where id = " + "'" +str ( retid ) + "'"
dim rs as recordset = db.SQLSelect ( sql )
if rs=nil then
msgbox "Oh Dear this should not happen!!!"
return
end

//Set up JPG & PDF File Types so we can Open a file (OK so we wouldn't normally do this here but it keeps this method self contained.)
Dim jpgFile as New FileType
jpgFile.Name = "image/jpeg"
jpgFile.MacType = "JPEG"
jpgFile.Extensions="jpg;jpeg"

Dim pdfFile as New FileType
pdfFile.Name = "File/pdf"
pdfFile.MacType = "PDF"
pdfFile.Extensions="pdf"

//Open A JPEG or PDF File
Dim dlg as OpenDialog
dlg=New OpenDialog
dlg.InitialDirectory=SpecialFolder.Documents
dlg.Title="Select a JPG or PDF file to bung in the Database"
dlg.Filter=jpgFile + pdfFile
f=dlg.ShowModal()
If f = Nil then
msgbox "No File selected to store in database"
return
End if

// Read The File Using BinaryStream
Dim bs as BinaryStream
dim data as string
bs=BinaryStream.Open(f,False)
If bs <> Nil Then
data=bs.Read(bs.Length)
else
msgbox "Error Reading File"
return
End If
bs.close

//Now Update the database - add the File name and Data
rs.edit
rs.field("file_name").StringValue=f.name
rs.field("file_data").stringvalue=data
rs.update
rs.close
if db.Error then
msgbox "Update Failed - " + db.ErrorMessage
return
else
db.commit
end if

//Now Read the Updated Database record
rs = db.SQLSelect ( sql )
if rs=nil then
msgbox "Oh Dear this should not happen -this is an error in our SQL, it does NOT mean zero records!!!!!!!"
return
end

//Create File in Temporary folder
dim t as folderitem
t=SpecialFolder.Temporary.Child(rs.field("file_name").getstring)
dim out as BinaryStream
out=BinaryStream.Create( t , true)
if not t.exists then
msgbox "Temporary File NOT Created!"
return
end

//Write to the file
out.Write(rs.Field("file_data").Value)
out.Close

if t.exists then
//You can Launch it if you want!
t.launch
else
msgbox "No File Exists In Temp Folder!!!"
end


This code works fine for me. I select a JPG or PDF file which is saved into the database, I then read it back into the temporary folder and then launch it.

_________________
Simon Larkin
QiSQL Database Solutions

SQL Tutorial : http://qisql.com/qisql_sqlite_lessons.html


Top
 Profile  
Reply with quote  
 Post subject: Re: RB 2010 and Binarystream
PostPosted: Fri Mar 26, 2010 12:11 am 
Offline
User avatar

Joined: Tue Oct 13, 2009 11:05 am
Posts: 30
Location: Germany
thank you very much, your code works fine, but actually i don't see any difference to mine. Anyway, it works with 2009r5, it doesn't with 2010r1, maybe i just wait for the next update.

_________________
My RealBasic project: Samanon


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group