Difference between revisions of "SQLiteBackupInterface"

From Xojo Documentation

(Created page with '<ShowIf version=2013r1> {{InterfaceBox | name=SQLiteBackupInterface | platform=all }} {{Description |text = Used to get progress and status of SQLiteDatabase backups. }} <d…')
 
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<ShowIf version=2013r1>
 
 
{{InterfaceBox
 
{{InterfaceBox
 
| name=SQLiteBackupInterface
 
| name=SQLiteBackupInterface
Line 6: Line 5:
 
{{Description
 
{{Description
 
|text = Used to get progress and status of [[SQLiteDatabase]] backups. }}
 
|text = Used to get progress and status of [[SQLiteDatabase]] backups. }}
 
  
 
<dynamicTable id="Methods" class="methodTable" title="Methods" columns="2">
 
<dynamicTable id="Methods" class="methodTable" title="Methods" columns="2">
{{Method | name=Progress | description=Call periodically as the backup progresses. }}
+
{{Method | name=Progress | description=Progress()&#x0A;Call periodically as the backup progresses. }}
{{Method | name=Complete | description=Called when the backup has finished.  }}
+
{{Method | name=Complete | description=Complete()&#x0A;Called when the backup has finished.  }}
{{Method | name=Error | returntype=[[Boolean]]| description=Called when a backup error is encountered.  }}
+
{{Method | name=Error | returntype=[[Boolean]]| description=Error() as Boolean&#x0A;Called when a backup error is encountered.  }}
 
</dynamicTable>
 
</dynamicTable>
 
  
 
==Notes==
 
==Notes==
Line 20: Line 17:
 
You create a class that implements this interface and then add code to the methods. The methods are called as the backup progresses.
 
You create a class that implements this interface and then add code to the methods. The methods are called as the backup progresses.
  
 +
The class must remain in scope while the backup is running.
 +
 +
== Sample Code ==
 +
Backing up the database asynchronously requires the use of a separate class that implements SQLiteBackupInterface.
 +
<rbcode>
 +
Var backupFile As Folderitem
 +
backupFile = FolderItem.ShowSaveFileDialog("", "backup.sqlite")
 +
 
 +
If backupFile Is Nil Then Return
 +
 
 +
// This is a property on the Window so that it stays in scope when the method exits
 +
mBackupDB = New SQLiteDatabase
 +
mBackupDB.DatabaseFile = backupFile
 +
If mBackupDB.CreateDatabaseFile Then
 +
// This is a property on the Window so that it stays in scope when the method exits
 +
  mBackupHandler = New BackupHandler
 +
 +
// The window has a progress bar that is updated as the backup progresses
 +
  mBackupHandler.BackupProgressBar = BackupProgress
 +
  mDB.BackUp(mBackupDB, mBackupHandler)
 +
End If
 +
</rbcode>
 +
 +
A class called BackupHandler implements [[SQLiteBackupInterface]] and has code in these methods:
 +
 +
Complete:
 +
<rbcode>
 +
MessageBox("Backup Complete.")
 +
</rbcode>
 +
 +
Error:
 +
<rbcode>
 +
MessageBox("There was an error during the backup: " + Str(errorCode))
 +
</rbcode>
 +
 +
Progress:
 +
<rbcode>
 +
If BackupProgressBar <> Nil Then
 +
  BackupProgressBar.Maximum = 100
 +
  BackupProgressBar.Visible = True
 +
  BackupProgressBar.Value = percent*100
 +
End If
 +
</rbcode>
 +
 +
In addition, it has a public property for the progress bar:
 +
<rbcode>BackupProgressBar As ProgressBar</rbcode>
 +
 +
== Example Project ==
 +
/Example Projects/Database/SQLite/SQLiteBackup
  
 
==See Also==
 
==See Also==
 
[[SQLiteDatabase.Backup]]
 
[[SQLiteDatabase.Backup]]
  
 
+
[[Category:Database_Data_Sources]]
[[Category:Database]]
+
[[Category:SQLite]]
</ShowIf>
 

Latest revision as of 21:21, 2 February 2021

Interface


Used to get progress and status of SQLiteDatabase backups.

Methods
Complete Progress
Error

Notes

This interface is used when you want to track the progress of an asynchronous backup of a SQLiteDatabase using SQLiteDatabase.Backup.

You create a class that implements this interface and then add code to the methods. The methods are called as the backup progresses.

The class must remain in scope while the backup is running.

Sample Code

Backing up the database asynchronously requires the use of a separate class that implements SQLiteBackupInterface.

Var backupFile As Folderitem
backupFile = FolderItem.ShowSaveFileDialog("", "backup.sqlite")

If backupFile Is Nil Then Return

// This is a property on the Window so that it stays in scope when the method exits
mBackupDB = New SQLiteDatabase
mBackupDB.DatabaseFile = backupFile
If mBackupDB.CreateDatabaseFile Then
// This is a property on the Window so that it stays in scope when the method exits
mBackupHandler = New BackupHandler

// The window has a progress bar that is updated as the backup progresses
mBackupHandler.BackupProgressBar = BackupProgress
mDB.BackUp(mBackupDB, mBackupHandler)
End If

A class called BackupHandler implements SQLiteBackupInterface and has code in these methods:

Complete:

MessageBox("Backup Complete.")

Error:

MessageBox("There was an error during the backup: " + Str(errorCode))

Progress:

If BackupProgressBar <> Nil Then
BackupProgressBar.Maximum = 100
BackupProgressBar.Visible = True
BackupProgressBar.Value = percent*100
End If

In addition, it has a public property for the progress bar:

BackupProgressBar As ProgressBar

Example Project

/Example Projects/Database/SQLite/SQLiteBackup

See Also

SQLiteDatabase.Backup