System.Data.SQLite
Check-in [5522052e80]
Not logged in

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

Overview
Comment:Fix semantics of backup handle finalization. Add tests.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | backupApi
Files: files | file ages | folders
SHA1: 5522052e803f3fb7039e90626a2b64811ff714e7
User & Date: mistachkin 2012-03-24 14:29:44
Context
2012-03-24
14:30
Cleanup test whitespace. check-in: 8140e97fc7 user: mistachkin tags: backupApi
14:29
Fix semantics of backup handle finalization. Add tests. check-in: 5522052e80 user: mistachkin tags: backupApi
12:47
More work on the backup API support. check-in: 6d5a1889b6 user: mistachkin tags: backupApi
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

1549
1550
1551
1552
1553
1554
1555

1556
1557
1558
1559
1560
1561
1562
        SQLiteBackupHandle handle = backup._sqlite_backup;

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

        int n = UnsafeNativeMethods.sqlite3_backup_finish(handle);


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

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








>







1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
        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, SQLiteLastError());
    }

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

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

349
350
351
352
353
354
355

356
357
358
359
360
361
362
    }

    internal static void FinishBackup(SQLiteBackupHandle backup)
    {
        lock (_lock)
        {
            int n = UnsafeNativeMethods.sqlite3_backup_finish(backup);

            if (n > 0) throw new SQLiteException(n, null);
        }
    }

    internal static void FinalizeStatement(SQLiteStatementHandle stmt)
    {
      lock (_lock)







>







349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
    }

    internal static void FinishBackup(SQLiteBackupHandle backup)
    {
        lock (_lock)
        {
            int n = UnsafeNativeMethods.sqlite3_backup_finish(backup);
            backup.SetHandleAsInvalid();
            if (n > 0) throw new SQLiteException(n, null);
        }
    }

    internal static void FinalizeStatement(SQLiteStatementHandle stmt)
    {
      lock (_lock)

Added Tests/backup.eagle.













































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
###############################################################################
#
# backup.eagle --
#
# Written by Joe Mistachkin.
# Released to the public domain, use at your own risk!
#
###############################################################################

package require Eagle
package require Eagle.Library
package require Eagle.Test

runTestPrologue

###############################################################################

package require System.Data.SQLite.Test
runSQLiteTestPrologue

###############################################################################

runTest {test backup-1.1 {BackupDatabase method, memory to disk} -setup {
  setupDb [set fileName(1) :memory:] "" "" "" "" "" false memDb
  setupDb [set fileName(2) backup-1.1.db]
} -body {
  set id [object invoke Interpreter.GetActive NextId]
  set dataSource [file join [getDatabaseDirectory] $fileName(2)]

  sql execute $memDb {
    CREATE TABLE t1(x TEXT);
  }

  for {set index 0} {$index < 10} {incr index} {
    sql execute $memDb [subst {
      INSERT INTO t1 (x) VALUES('[string repeat ! 1048576]');
    }]
  }

  set memSource [object invoke -flags +NonPublic -objectflags +NoDispose \
      Interpreter.GetActive.connections get_Item $memDb]

  unset -nocomplain results errors

  set code [compileCSharpWith [subst {
    using System.Data.SQLite;
    using System.Text;

    namespace _Dynamic${id}
    {
      public class Test${id}
      {
        public static string GetRows(
          SQLiteConnection source
          )
        {
          using (SQLiteConnection destination = new SQLiteConnection(
              "Data Source=${dataSource};"))
          {
            destination.Open();
            source.BackupDatabase(destination, "main", "main", -1, null, 0);

            using (SQLiteCommand command = new SQLiteCommand(
                "SELECT length(x) FROM t1;", destination))
            {
              using (SQLiteDataReader dataReader = command.ExecuteReader())
              {
                int rowCount = 0;
                StringBuilder builder = new StringBuilder();

                builder.Append(dataReader.FieldCount);
                builder.Append(' ');

                while (dataReader.Read())
                {
                  builder.Append(dataReader.GetInt64(0));
                  builder.Append(' ');
                  rowCount++;
                }

                builder.Append(rowCount);
                return builder.ToString();
              }
            }
          }
        }

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

        public static void Main()
        {
          // do nothing.
        }
      }
    }
  }] true true true results errors System.Data.SQLite.dll]

  list $code $results \
      [expr {[info exists errors] ? $errors : ""}] \
      [expr {$code eq "Ok" ? [catch {
        object invoke _Dynamic${id}.Test${id} GetRows $memSource
      } result] : [set result ""]}] $result
} -cleanup {
  cleanupDb $fileName(1)
  cleanupDb $fileName(2) memDb

  unset -nocomplain result results errors code index memSource dataSource id \
      memDb db fileName
} -constraints \
{eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} \
-match regexp -result {^Ok System#CodeDom#Compiler#CompilerResults#\d+ \{\} 0\
\{1 1048576 1048576 1048576 1048576 1048576 1048576 1048576 1048576 1048576\
1048576 10\}$}}

###############################################################################

runSQLiteTestEpilogue
runTestEpilogue