You don't need a memory block, just do this:
rec.BlobColumn("theFile") = myBinaryStream.Read (FileLength)
---
Marco Bambini
http://www.sqlabs.net
http://www.sqlabs.net/blog/
On Apr 27, 2006, at 8:55 AM, Jeff Edwards wrote:
If I need to store a file from the disk into a database blob, how
do I do it?
Here is my try, but the file contains nulls, so the sqlite database
only reads the first few bytes instead of the entire BinaryStream
I am not sure how to get the actual file in memory to assign it to
the binary sqlite column of type binary.
Would someone be kind enough to paste a little bit of code?
The documentation on Binary Streams and Memory blocks is a little
confusing.
Thanks for any help.
Jeff Edwards
________________________________________________________________
Dim f as FolderItem
dim sql as string
f=GetFolderItem(kDatabaseName)
if (not(f.exists)) then
//create the database
Dim db as REALSQLdatabase
f= New FolderItem(kDatabaseName)
db= New REALSQLdatabase
db.databaseFile=f
If db.CreateDatabaseFile then
sql = "create table server (id integer, server_name varchar,
version varchar, theFile binary)"
db.SQLExecute(sql)
dim errormessage as string
errormessage = db.ErrorMessage
if (errormessage<>"") then
msgbox errormessage
end if
Dim rec as DatabaseRecord
rec= new Databaserecord
rec.IntegerColumn("id") = 1
rec.Column("server_name") = "the_name"
rec.Column("version") = "1.0.0"
Dim myFile as FolderItem
myFile=GetFolderItem("theFile.zip")
if (not(myFile.exists)) then
MsgBox "File specified does not exist"
else
Dim myBinaryStream as BinaryStream
myBinaryStream = myFile.OpenAsBinaryFile(False)
Dim FileLength as Integer
FileLength = myBinaryStream.length
Dim m as new MemoryBlock(FileLength)
m.StringValue (0, FileLength) = myBinaryStream.Read (50)
rec.Column("theFile") = myBinaryStream.Read (FileLength)
myBinaryStream.Close // close the stream (and the file)
end if
db.InsertRecord("server",rec)
db.Commit
errormessage = db.ErrorMessage
if (errormessage<>"") then
msgbox errormessage
end if
db.close
else
MsgBox "Database not created"
end if
end if
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>