Exemplo n.º 1
0
    /// <summary>
    /// Returns the total number of pages in the source database associated
    /// with the specified backup object.
    /// </summary>
    /// <param name="backup">The backup object to check.</param>
    /// <returns>The total number of pages in the source database.</returns>
    internal override int PageCountBackup(
        SQLiteBackup backup
        )
    {
        if (backup == null)
            throw new ArgumentNullException("backup");

        SQLiteBackupHandle handle = backup._sqlite_backup;

        if (handle == null)
            throw new InvalidOperationException(
                "Backup object has an invalid handle.");

        IntPtr handlePtr = handle;

        if (handlePtr == IntPtr.Zero)
            throw new InvalidOperationException(
                "Backup object has an invalid handle pointer.");

        return UnsafeNativeMethods.sqlite3_backup_pagecount(handlePtr);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Destroys the backup object, rolling back any backup that may be in
    /// progess.
    /// </summary>
    /// <param name="backup">The backup object to destroy.</param>
    internal override void FinishBackup(
        SQLiteBackup backup
        )
    {
        if (backup == null)
            throw new ArgumentNullException("backup");

        SQLiteBackupHandle handle = backup._sqlite_backup;

        if (handle == null)
            throw new InvalidOperationException(
                "Backup object has an invalid handle.");

        IntPtr handlePtr = handle;

        if (handlePtr == IntPtr.Zero)
            throw new InvalidOperationException(
                "Backup object has an invalid handle pointer.");

#if !SQLITE_STANDARD
        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_backup_finish_interop(handlePtr);
#else
        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_backup_finish(handlePtr);
#endif
        handle.SetHandleAsInvalid();

#if COUNT_HANDLE
        if ((n == SQLiteErrorCode.Ok) || (n == backup._stepResult)) handle.WasReleasedOk();
#endif

        if ((n != SQLiteErrorCode.Ok) && (n != backup._stepResult))
            throw new SQLiteException(n, GetLastError());
    }
Exemplo n.º 3
0
    /// <summary>
    /// Copies up to N pages from the source database to the destination
    /// database associated with the specified backup object.
    /// </summary>
    /// <param name="backup">The backup object to use.</param>
    /// <param name="nPage">
    /// The number of pages to copy, negative to copy all remaining pages.
    /// </param>
    /// <param name="retry">
    /// Set to true if the operation needs to be retried due to database
    /// locking issues; otherwise, set to false.
    /// </param>
    /// <returns>
    /// True if there are more pages to be copied, false otherwise.
    /// </returns>
    internal override bool StepBackup(
        SQLiteBackup backup,
        int nPage,
        out bool retry
        )
    {
        retry = false;

        if (backup == null)
            throw new ArgumentNullException("backup");

        SQLiteBackupHandle handle = backup._sqlite_backup;

        if (handle == null)
            throw new InvalidOperationException(
                "Backup object has an invalid handle.");

        IntPtr handlePtr = handle;

        if (handlePtr == IntPtr.Zero)
            throw new InvalidOperationException(
                "Backup object has an invalid handle pointer.");

        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_backup_step(handlePtr, nPage);
        backup._stepResult = n; /* NOTE: Save for use by FinishBackup. */

        if (n == SQLiteErrorCode.Ok)
        {
            return true;
        }
        else if (n == SQLiteErrorCode.Busy)
        {
            retry = true;
            return true;
        }
        else if (n == SQLiteErrorCode.Locked)
        {
            retry = true;
            return true;
        }
        else if (n == SQLiteErrorCode.Done)
        {
            return false;
        }
        else
        {
            throw new SQLiteException(n, GetLastError());
        }
    }
Exemplo n.º 4
0
 /// <summary>
 /// Destroys the backup object, rolling back any backup that may be in
 /// progess.
 /// </summary>
 /// <param name="backup">The backup object to destroy.</param>
 internal abstract void FinishBackup(SQLiteBackup backup);
Exemplo n.º 5
0
 /// <summary>
 /// Returns the total number of pages in the source database associated
 /// with the specified backup object.
 /// </summary>
 /// <param name="backup">The backup object to check.</param>
 /// <returns>The total number of pages in the source database.</returns>
 internal abstract int PageCountBackup(SQLiteBackup backup);
Exemplo n.º 6
0
 /// <summary>
 /// Returns the number of pages remaining to be copied from the source
 /// database to the destination database associated with the specified
 /// backup object.
 /// </summary>
 /// <param name="backup">The backup object to check.</param>
 /// <returns>The number of pages remaining to be copied.</returns>
 internal abstract int RemainingBackup(SQLiteBackup backup);
Exemplo n.º 7
0
 /// <summary>
 /// Copies up to N pages from the source database to the destination
 /// database associated with the specified backup object.
 /// </summary>
 /// <param name="backup">The backup object to use.</param>
 /// <param name="nPage">
 /// The number of pages to copy or negative to copy all remaining pages.
 /// </param>
 /// <param name="retry">
 /// Set to true if the operation needs to be retried due to database
 /// locking issues.
 /// </param>
 /// <returns>
 /// True if there are more pages to be copied, false otherwise.
 /// </returns>
 internal abstract bool StepBackup(SQLiteBackup backup, int nPage, out bool retry);