Save As to save a new Sqlite Files

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

dlg.Title = “Save User File”
dlg.SuggestedFileName = "DBUser File "
dlg.Filter = FileTypes1.sqliteType

dbFile = dlg.ShowModal

If dbFile <> Nil Then
dbFile = GetSaveFolderItem(FileTypes1.sqliteType, “DB User Files”)

//Create and Save new Named File and close original named file and keep it 

End If[/code]

What is the returned error ?

Where is the code to create the Tables and populate them ?

The code in the if block looks strange to me.

What is the code used to save the original sqlite File ?
Take that code, and change the file name.

From the Language Reference:

The following example creates a new SQLite database:

[code]Dim f As FolderItem
f = New FolderItem(“MyDB.sqlite”)

Dim db As New SQLiteDatabase
db.DatabaseFile = f
If db.CreateDatabaseFile Then
//proceed with database operations…
Else
MsgBox("Database not created. Error: " + db.ErrorMessage)
End If[/code]

Then you have to create the Tables, etc. and store the data from the “old” data base.

Hello,
from the top of my head I usually do:

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 else // some error occured end if end If

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.

You could also use the SQLite backup feature to create a copy. Example here:

Examples/Database/SQLite/SQLiteBackup

Define what you meany by Save As…

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.

Using the advice (above), you will get a brand new .sqlite file: no need to “compress” it (I forgot / do not found the SQLite name for this feature).

Edit:
Click in Post a Reply is like releasing software: some minutes (seconds / days) after you realized you had a problem / found a solution.

The feature name is VACUUM.

Description here , at sqlite.com.

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.
Thanks

I did some trail and error and finally got some code that worked. I took Paul’s suggestion of Backup. Thanks all of you for your help.

[code]// Save As a new user files
Dim dlg As New SaveAsDialog
Dim dbFile As FolderItem

dlg.Title = “Save User File”
dlg.SuggestedFileName = "DBUser File "
dlg.Filter = FileTypes1.sqliteType

dbFile = dlg.ShowModal

//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)
winSaveAs.Hide
End If
End If
End If[/code]