I’m trying to create a Save As Sqlite copy renamed file and closed the keep the original Sqlite file. This code doesn’t work after I create a new name and try to save it. What completes the code to make it work.
[code] // Save As a new user files
Dim dlg As New SaveAsDialog
Dim dbFile As FolderItem
dbFile = GetSaveFolderItem(FileTypes1.sqliteType, "DB User Files")
If dbFile <> Nil Then
dim myNewDB as new SQLiteDatabase
myNewDB.DatabaseFile = dbfile
if myNewDB.CreateDatabaseFile() = TRUE then
// do something here
// some error occured
Copying a SQLite file can be easily done with FolderItem.CopyFile (I would do it after closing the database).
If however you want to version the database file you’ll want to use the in-memory feature and copy the existing tables into your in-memory database - and of course copy them back to the HDD on completion. Use attach & detach database functions to do this along with SELECT INTO SQL statements.
Sorry, I left out that the Sqlite database File has already been created, working and populated plus defined in FileTypes. I just want to be able create a Save As copy of that working file. Wayne I see FolderItem.CopyFileTo in the FolderItem Methods.
For me, it is saving a copy of the current document into a brand new file. So:
a. create a brand new sqlite file, (1)
b. add it the needed Table, (1)
c. populate the tables with the current document data. (2)
Now, you can follow a different path: duplicate the last saved .sqlite file.
(1) You already have the code to do that.
(2) Hint: you already have incomplete code to do that: the code you use to add a RecordSet into the Data Base / the code to read RecordSets from the Data Base. The idea here is to read a RecordSet from the old .sqlite and save it into the new .sqlite.
Thanks Guys for all your response & help. My intention Save As are unique user database profiles that can be saved from a default. I’m seeing there is a little more to it than I thought. Your pointing me in the right direction and I’ll do more research what’s best.
//Create and Save new Named File and close original named file and keep it
If dbFile <> Nil Then
Dim DBSaveAs As FolderItem = GetSaveFolderItem(FileTypes1.sqliteType, dbFile.DisplayName)
If DBSaveAs <> Nil Then
Dim DBNewFile As New SQLiteDatabase
DBNewFile.DatabaseFile = DBSaveAs
If DBNewFile.CreateDatabaseFile Then
db.BackUp(DBNewFile, Nil, -1)