newbie question - how to store a file from the disk in the database (Real Studio Plugins Mailinglist archive)

Back to the thread list
Previous thread: Storing global data (was Callbacks and events on Windows)
Next thread: Callbacks and events on Windows


macosx and unix paths   -   GOLD
  newbie question - how to store a file from the disk in the database   -   Jeff Edwards
   Re: newbie question - how to store a file from the disk in the database   -   Hans-Georg
   Re: newbie question - how to store a file from the disk in the database   -   Hans-Georg
   Re: newbie question - how to store a file from the disk in the database   -   Jeff Edwards

newbie question - how to store a file from the disk in the database
Date: 26.04.06 13:45 (Wed, 26 Apr 2006 20:45:41 +0800)
From: Jeff Edwards
If I need to store a file from the disk into a database blob, how do
I do it?

Here is my try, but I of course get an error when trying to assign
the folderitem to the database record column.

I am not sure how to get the actual file in memory to assign it to
the binary sqlite column.

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ð 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") = "a_name"
rec.Column("version") = "1.0.0"

Dim myFile, myFileCopy as FolderItem
myFile=GetFolderItem("MyFile.zip")
myFileCopy = new folderItem(myFile)
rec.Column("theFile") = myFileCopy // THIS IS THE
OFFENDING LINE

db.InsertRecord("server",rec)
db.Commit

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>

Re: newbie question - how to store a file from the disk in the database
Date: 26.04.06 14:26 (Wed, 26 Apr 2006 15:26:30 +0200)
From: Hans-Georg
Am 26.04.2006 um 14:45 schrieb Jeff Edwards:

> If I need to store a file from the disk into a database blob, how
> do I do it?

Before Marco or Will will come by a first hint : A folderitem is a
reference to the file but doesn't contain the content of this file.
The blobcolumn of a databaserecord expects a string (and not a
folderitem), in your case a string with the content of your file. So
you have to read all the content probably in a memoryblock and then
store the stringvalue in the blobcolumn. And I guess there is lot to
think about when storing a file (restoring creation/mod. date,
type ,creatot etc)

Hans-Georg

_______________________________________________
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>

Re: newbie question - how to store a file from the disk in the database
Date: 26.04.06 14:31 (Wed, 26 Apr 2006 15:31:19 +0200)
From: Hans-Georg
Am 26.04.2006 um 15:26 schrieb Hans-Georg:

> Before Marco or Will will come by a first hint :

And seeing my first post in the plugin list: That is definitely a
question for the NUG list.

Hans-Georg

_______________________________________________
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>

Re: newbie question - how to store a file from the disk in the database
Date: 27.04.06 05:52 (Thu, 27 Apr 2006 12:52:42 +0800)
From: Jeff Edwards
Would someone be kind enough to paste a little bit of code to show me
how to get the file into a string so that I can assign it to the
binary field in the database?

The documentation on Binary Streams and Memory blocks is a little
confusing.


On 26/04/2006, at 9:26 PM, Hans-Georg wrote:

> Am 26.04.2006 um 14:45 schrieb Jeff Edwards:
>
>> If I need to store a file from the disk into a database blob, how
>> do I do it?
>
> Before Marco or Will will come by a first hint : A folderitem is a
> reference to the file but doesn't contain the content of this file.
> The blobcolumn of a databaserecord expects a string (and not a
> folderitem), in your case a string with the content of your file.
> So you have to read all the content probably in a memoryblock and
> then store the stringvalue in the blobcolumn. And I guess there is
> lot to think about when storing a file (restoring creation/mod.
> date, type ,creatot etc)
_______________________________________________
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>