Interface

# SQLiteBackupInterface

<div class="rst-class">

forsearch

</div>

Database

<div class="rst-class">

forsearch

</div>

SQLite

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Used to get progress and status of `SQLiteDatabase</api/databases/sqlitedatabase>` backups.

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                       | Parameters                                                                                                             | Returns                            | Shared |
|--------------------------------------------|------------------------------------------------------------------------------------------------------------------------|------------------------------------|--------|
| `Complete<sqlitebackupinterface.complete>` |                                                                                                                        |                                    |        |
| `Error<sqlitebackupinterface.error>`       | errorCode As `Integer</api/data_types/integer>`                                                                        | `Boolean</api/data_types/boolean>` |        |
| `Progress<sqlitebackupinterface.progress>` | percent As `Double</api/data_types/double>`, `ByRef</api/language/byref>` cancel As `Boolean</api/data_types/boolean>` |                                    |        |

## Method descriptions

<div id="sqlitebackupinterface.complete">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

SQLiteBackupInterface.Complete

**Complete**

> This method is called for you when the `SQLiteDatabase.Backup<sqlitedatabase.backup>` finishes.
>
> You can display a simple message in this method to indicate the back up complete:
>
> ``` xojo
> MessageBox("Backup is complete.")
> ```

<div id="sqlitebackupinterface.error">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

SQLiteBackupInterface.Error

**Error**(errorCode As `Integer</api/data_types/integer>`) As `Boolean</api/data_types/boolean>`

> This method is called for you when there was an error in the `SQLiteDatabase.Backup<sqlitedatabase.backup>`. The error is return in *errorCode*.
>
> These are the possible error codes:
>
> | Error code | Description                       |
> |------------|-----------------------------------|
> | 0          | No error                          |
> | 1          | Source database disconnected      |
> | 2          | Destination database disconnected |
>
> If an error occurs, display it:
>
> ``` xojo
> MessageBox("Backup error: " + errorCode.ToString)
> ```

<div id="sqlitebackupinterface.progress">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

SQLiteBackupInterface.Progress

**Progress**(percent As `Double</api/data_types/double>`, `ByRef</api/language/byref>` cancel As `Boolean</api/data_types/boolean>`)

> This method is called for you as the `SQLiteDatabase.Backup<sqlitedatabase.backup>` progresses, supplying the percent complete in *percent*. To cancel the backup, set *cancel* to `True</api/language/true>`.
>
> If your implementing class has a reference to a `ProgressBar</api/user_interface/desktop/desktopprogressbar>`, you can update it using the *percent* value:
>
> ``` xojo
> If BackupProgressBar <> Nil Then
> BackupProgressBar.MaximumValue = 100
> BackupProgressBar.Value = percent * 100
> End If
> ```

## Notes

This interface is used when you want to track the progress of an asynchronous backup of a `SQLiteDatabase</api/databases/sqlitedatabase>` using `SQLiteDatabase.Backup<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 <span class="title-ref">SQLiteBackupInterface</span>.

``` xojo
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.CreateDatabase 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 <span class="title-ref">SQLiteBackupInterface</span> and has code in these methods:

Complete:

``` xojo
MessageBox("Backup Complete.")
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Error:

``` xojo
MessageBox("There was an error during the backup: " + errorCode.ToString)
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Progress:

``` xojo
If BackupProgressBar <> Nil Then
  BackupProgressBar.MaximumValue = 100
  BackupProgressBar.Visible = True
  BackupProgressBar.Value = percent * 100
End If
```

## Compatibility

|                       |                               |
|-----------------------|-------------------------------|
| **Project Types**     | Console, Desktop, Mobile, Web |
| **Operating Systems** | iOS, Linux, macOS, Windows    |

<div class="seealso">

`SQLiteDatabase.Backup<sqlitedatabase.backup>`

</div>
