realbasic-plugins
[Top] [All Lists]

newbie question - how to store a file from the disk in the database

To: REALbasic Plugins <realbasic-plugins at lists dot realsoftware dot com>
Subject: newbie question - how to store a file from the disk in the database
From: Jeff Edwards <jeffedwa at gmail dot com>
Date: Wed, 26 Apr 2006 20:45:41 +0800
Delivered-to: realbasic-plugins at lists dot realsoftware dot com
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=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") = "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>


<Prev in Thread] Current Thread [Next in Thread>