System.Data.SQLite
Check-in [fc724d683a]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Prevent possible race conditions involving the managed backup API methods.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: fc724d683a1604bc3fcb27c6ad62363f73165adb
User & Date: mistachkin 2012-06-02 00:54:41
Context
2012-06-05
03:19
Add SetMemoryStatus instance method to the SQLiteConnection class and the necessary internal infrastructure to support it. Also, fixup several doc comments and bump all versions to 1.0.82.0. check-in: 9ecb2876c2 user: mistachkin tags: trunk
2012-06-02
00:54
Prevent possible race conditions involving the managed backup API methods. check-in: fc724d683a user: mistachkin tags: trunk
00:14
Modify the native interop assembly to help prevent possible thread race conditions between sqlite3_close_interop and sqlite3_finalize_interop. check-in: 74a33d10da user: mistachkin tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to System.Data.SQLite/SQLite3.cs.

1512
1513
1514
1515
1516
1517
1518






1519
1520
1521
1522
1523
1524
1525
1526
....
1559
1560
1561
1562
1563
1564
1565






1566
1567
1568
1569
1570
1571
1572
1573
....
1581
1582
1583
1584
1585
1586
1587






1588
1589
1590
1591
1592
1593
1594
1595
....
1602
1603
1604
1605
1606
1607
1608






1609
1610
1611
1612
1613
1614
1615
1616

        SQLiteBackupHandle handle = backup._sqlite_backup;

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







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

        if (n == (int)SQLiteErrorCode.Ok)
        {
            return true;
        }
        else if (n == (int)SQLiteErrorCode.Busy)
................................................................................

        SQLiteBackupHandle handle = backup._sqlite_backup;

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







        return UnsafeNativeMethods.sqlite3_backup_remaining(handle);
    }

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

        SQLiteBackupHandle handle = backup._sqlite_backup;

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







        return UnsafeNativeMethods.sqlite3_backup_pagecount(handle);
    }

    /// <summary>
    /// Destroys the backup object, rolling back any backup that may be in
    /// progess.
    /// </summary>
    /// <param name="backup">The backup object to destroy.</param>
................................................................................

        SQLiteBackupHandle handle = backup._sqlite_backup;

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







        int n = UnsafeNativeMethods.sqlite3_backup_finish(handle);
        handle.SetHandleAsInvalid();

        if ((n > 0) && (n != backup._stepResult))
            throw new SQLiteException(n, GetLastError());
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////







>
>
>
>
>
>
|







 







>
>
>
>
>
>
|







 







>
>
>
>
>
>
|







 







>
>
>
>
>
>
|







1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
....
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
....
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
....
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640

        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.");

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

        if (n == (int)SQLiteErrorCode.Ok)
        {
            return true;
        }
        else if (n == (int)SQLiteErrorCode.Busy)
................................................................................

        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_remaining(handlePtr);
    }

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

        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);
    }

    /// <summary>
    /// Destroys the backup object, rolling back any backup that may be in
    /// progess.
    /// </summary>
    /// <param name="backup">The backup object to destroy.</param>
................................................................................

        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.");

        int n = UnsafeNativeMethods.sqlite3_backup_finish(handlePtr);
        handle.SetHandleAsInvalid();

        if ((n > 0) && (n != backup._stepResult))
            throw new SQLiteException(n, GetLastError());
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////