1

I am actually using an old version of Realbasic (2008) and have been using VB Script to back up several small databases as Zip files.

I now find that thnis method doesn't work On Windows 8 and is also not cross-platform.

As I would like the backup to be in a single file so that it can be incremental, I though of using a large database to hold the copies of the smaller ones.

Is this possible?

I have no intention of buying a plug-in for this.

Alan McTavish
  • 121
  • 1
  • 8

3 Answers3

2

Similar to Pauls answer. You can read the binary data of the file you want to store into a MemoryBlock and then save the resulting string into the database. We've done this in several applications. Don't expect it to be speedy as all of that happens in RAM first and then gets written to the database.

Ideally, I think, you'd like to compress the file/string before saving. But there is no gzip built-in to Xojo so you'd have to result to using a 3rd party solution for compression or making an OS call via Declares.

BKeeney Software
  • 1,299
  • 6
  • 8
  • Hi there, I seem to remember that your name is Bob - please correct me if I'm wrong. As you have used this method before, can you give me a couple of pointers to the process as I am not familiar with memory blocks. Is it simply a case of reading in the database with a Binary Stream? All help welcome of course. Alan ... – Alan McTavish Nov 05 '13 at 18:39
  • Alan, a MemoryBlock is effectively the same as a String, only that is has no encoding and that you have other ways to access its contents. If you just want to store a blob of data, you can use either String or MemoryBlock. As a rule of thumb, use a String whenever you handle text, use a MemoryBlock when it's binary data. – Thomas Tempelmann Nov 06 '13 at 09:53
  • Hi Thomas, thanks for your input. I decided on a MemoryBlock because I imagine the RealSQLDatabase stores most of the data as binary ... although I read somewhere that everything is stored as a string. Regarding your other comment ... I realised afterwards that the code could be simplified and ended up using code very similar to your own so thanks again. I also now have methods to read and to write the data so my backup routines should now be cross-platform. – Alan McTavish Nov 06 '13 at 19:49
1

You can store anything as a BLOB in a SQLite table.

You might also consider a VirtualVolume and a BinaryStream to write the DB files into a single "container" file.

http://docs.xojo.com/index.php/VirtualVolume

Paul Lefebvre
  • 6,253
  • 3
  • 28
  • 36
  • The only problem with VirtualVolume is that they are extremely slow. – BKeeney Software Nov 05 '13 at 14:21
  • Hi Paul, Thanks for the idea. I have never used Virtual volumes before but it sounds like a handy 'tool'. I think I might look at BKeeneys suggestion which is, in fact, a thought I had yesterday. I'll have to work out the memory block idea though as I have no experience with that either. Alan ... – Alan McTavish Nov 05 '13 at 18:35
1

Thanks to Paul and BKeeney for their help. BKeeney came closest and, after some experimentation, I have succeeded!

Here is what I did ...

      //
      Dim l, p As Integer
      Dim ReadFromFile as BinaryStream
      Dim f as FolderItem

      f= GetFolderItem("Keyhoe.db3")

      If f <> Nil Then
        l = f.Length
        ReadFromFile=f.OpenAsBinaryFile( False)

        mb = New MemoryBlock(l)

        While Not ReadFromFile.EOF
          mb.byte(p) = ReadFromFile.ReadInt8
          p = p + 1
        wend

        ReadFromFile.close
      End If

      Dim dbFile as FolderItem
      Dim db as REALSQLdatabase
      db= New REALSQLdatabase
      Dim mydate as New Date
      Dim rec as DatabaseRecord

      dbFile = GetFolderItem("Backup.db3")
      db.DatabaseFile = dbFile
      If db.Connect Then
        rec = New DatabaseRecord

        rec.Column("Name") = "Keyhoe"
        rec.BlobColumn("Content") = mb.LeftB(l)
        db.InsertRecord("Databases",rec)
        db.Commit
      else
        MsgBox "Error: "+db.ErrorMessage
      End if

      msgbox "Done..."

Thanks again ... all I have to do now is figure out how to get the databases back out but there are several examples for that task.

Cheers,

Alan ...

Alan McTavish
  • 121
  • 1
  • 8
  • FYI: Upgrading to Xojo gets you access to the SQLiteDatabase class which has a way to load data in/out of a BLOB column incrementally. See http://docs.xojo.com/index.php/SQLiteDatabase.CreateBlob – Paul Lefebvre Nov 06 '13 at 02:05
  • Hi again Paul, I have looked at Xojo and previously at Real Studio and, quite frankly, can't see the benefit (to me) of upgrading. Mind you, the way Windows is 'developing', I don't doubt that at some point in the future I will have to succumb. My other annoyance is that, when I started with RB having moved over from VB6, I could simply sit and write a program. Now, however, it seems that I not only have to spend money on the Xojo software, but I also am almost compelled to buy Monkeybread. Not on I'm afraid. Thanks anyway, Alan ... – Alan McTavish Nov 06 '13 at 07:35
  • There is some superfluous code in your sample: The reading loop can be turned into a single line: "mb = ReadFromFile.Read(l)". You also do not need the "mb.LeftB(l)" further down, just "mb" is sufficient. – Thomas Tempelmann Nov 06 '13 at 09:51