4 Replies Latest reply on Mar 31, 2009 11:45 AM by John Hall

    SQLite In-memory to File

    John Hall Level 4
      I have an application that works fine using VOs but the more I think of it, I might entertain using an in-memory SQLite DB and when the user saves, commit it to a file. If I create the DB in-memory, is it relatively easy to change it to save to file at the end if the user decides to save the DB?
        • 1. Re: SQLite In-memory to File
          Jeff Swartz Level 3
          SQLite databases in AIR are always stored as database files on the file system.
          • 2. Re: SQLite In-memory to File
            John Hall Level 4
            Thanks. To clarify, if I create the database in memory by dbConn.openAsync(null), I just am trying to find the most efficient way to save it to a true db file if the user decides to save it. I was wondering if one could take an in-memory DB and save it to file or if I have to always create a dummy file-based DB to switch to file-based at the end of the session.
            • 3. Re: SQLite In-memory to File
              Jeff Swartz Level 3
              John, please disregard my previous reply. AIR does indeed support in-memory databases.

              I think your best solution would be to base the database off of a temporary file (such as File.createTempFile() or File.applicationStorageDirectory.resolvePath(tempData.db)), and then either (a) delete the file if you don't need to save it (perhaps upon application shut-down), or (b) save the file as needed.

              You *could* recreate an in-memory database by recreating all the tables, views, triggers, and indexes in a file-based database. Which is perhaps a bit tedious, but possible.
              • 4. Re: SQLite In-memory to File
                John Hall Level 4
                I'll go with your first method, thanks.