System.Data.SQLite

Check-in [29b506224a]
Login

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

Overview
Comment:Stop creating the CriticalHandle derived classes via implicit operator conversions. Simplify test case for ticket [996d13cd87].
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 29b506224a8dceb650e4ca3cfc5cb1836b86b23c
User & Date: mistachkin 2012-05-03 13:04:45.306
Context
2012-05-03
13:44
Do not attempt to reset a connection if it has been closed. Also, prevent any potential GC race while resetting a connection. Keep track of the total number of connections successfully opened and closed from any of the pools. Enhance test for ticket [996d13cd87] to make sure that at least one connection was opened and closed from a connection pool. check-in: 7b3fe92dcb user: mistachkin tags: trunk
13:04
Stop creating the CriticalHandle derived classes via implicit operator conversions. Simplify test case for ticket [996d13cd87]. check-in: 29b506224a user: mistachkin tags: trunk
2012-05-02
22:29
Update version history with all the latest changes. check-in: c063096071 user: mistachkin tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to System.Data.SQLite/SQLite3.cs.
272
273
274
275
276
277
278
279

280
281
282
283
284
285
286

#if DEBUG && !NET_COMPACT_20
        Trace.WriteLine(String.Format("Open: {0}", db));
#endif

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

        _sql = db;

      }
      // Bind functions to this connection.  If any previous functions of the same name
      // were already bound, then the new bindings replace the old.
      _functionsArray = SQLiteFunction.BindFunctions(this, connectionFlags);
      SetTimeout(0);
    }








|
>







272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287

#if DEBUG && !NET_COMPACT_20
        Trace.WriteLine(String.Format("Open: {0}", db));
#endif

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

        _sql = new SQLiteConnectionHandle(db);
        lock (_sql) { /* HACK: Force the SyncBlock to be "created" now. */ }
      }
      // Bind functions to this connection.  If any previous functions of the same name
      // were already bound, then the new bindings replace the old.
      _functionsArray = SQLiteFunction.BindFunctions(this, connectionFlags);
      SetTimeout(0);
    }

529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
          }
        }

        if (n > 0) throw new SQLiteException(n, GetLastError());

        strRemain = UTF8ToString(ptr, len);

        if (stmt != IntPtr.Zero) cmd = new SQLiteStatement(this, flags, stmt, strSql.Substring(0, strSql.Length - strRemain.Length), previous);

        return cmd;
      }
      finally
      {
        handle.Free();
      }







|







530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
          }
        }

        if (n > 0) throw new SQLiteException(n, GetLastError());

        strRemain = UTF8ToString(ptr, len);

        if (stmt != IntPtr.Zero) cmd = new SQLiteStatement(this, flags, new SQLiteStatementHandle(stmt), strSql.Substring(0, strSql.Length - strRemain.Length), previous);

        return cmd;
      }
      finally
      {
        handle.Free();
      }
1471
1472
1473
1474
1475
1476
1477

1478
1479
1480
1481
1482
1483
1484
1485
        IntPtr backup = UnsafeNativeMethods.sqlite3_backup_init(
            destHandle, zDestName, sourceHandle, zSourceName);

        if (backup == IntPtr.Zero)
            throw new SQLiteException(ResultCode(), GetLastError());

        return new SQLiteBackup(

            this, backup, destHandle, zDestName, sourceHandle, zSourceName);
    }

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







>
|







1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
        IntPtr backup = UnsafeNativeMethods.sqlite3_backup_init(
            destHandle, zDestName, sourceHandle, zSourceName);

        if (backup == IntPtr.Zero)
            throw new SQLiteException(ResultCode(), GetLastError());

        return new SQLiteBackup(
            this, new SQLiteBackupHandle(backup), destHandle, zDestName,
            sourceHandle, zSourceName);
    }

    /// <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>
Changes to System.Data.SQLite/SQLite3_UTF16.cs.
119
120
121
122
123
124
125
126

127
128
129
130
131
132
133

#if DEBUG && !NET_COMPACT_20
        Trace.WriteLine(String.Format("Open: {0}", db));
#endif

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

        _sql = db;

      }
      _functionsArray = SQLiteFunction.BindFunctions(this, connectionFlags);
      SetTimeout(0);
    }

    internal override void Bind_DateTime(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, DateTime dt)
    {







|
>







119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134

#if DEBUG && !NET_COMPACT_20
        Trace.WriteLine(String.Format("Open: {0}", db));
#endif

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

        _sql = new SQLiteConnectionHandle(db);
        lock (_sql) { /* HACK: Force the SyncBlock to be "created" now. */ }
      }
      _functionsArray = SQLiteFunction.BindFunctions(this, connectionFlags);
      SetTimeout(0);
    }

    internal override void Bind_DateTime(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, DateTime dt)
    {
Changes to System.Data.SQLite/UnsafeNativeMethods.cs.
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
  internal class SQLiteConnectionHandle : CriticalHandle
  {
    public static implicit operator IntPtr(SQLiteConnectionHandle db)
    {
      return (db != null) ? db.handle : IntPtr.Zero;
    }

    public static implicit operator SQLiteConnectionHandle(IntPtr db)
    {
      return new SQLiteConnectionHandle(db);
    }

    private SQLiteConnectionHandle(IntPtr db)
      : this()
    {
      SetHandle(db);
    }

    internal SQLiteConnectionHandle()
      : base(IntPtr.Zero)
    {
    }

    protected override bool ReleaseHandle()
    {
      try







<
<
<
<
<
|





|







1364
1365
1366
1367
1368
1369
1370





1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
  internal class SQLiteConnectionHandle : CriticalHandle
  {
    public static implicit operator IntPtr(SQLiteConnectionHandle db)
    {
      return (db != null) ? db.handle : IntPtr.Zero;
    }






    internal SQLiteConnectionHandle(IntPtr db)
      : this()
    {
      SetHandle(db);
    }

    private SQLiteConnectionHandle()
      : base(IntPtr.Zero)
    {
    }

    protected override bool ReleaseHandle()
    {
      try
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
  internal class SQLiteStatementHandle : CriticalHandle
  {
    public static implicit operator IntPtr(SQLiteStatementHandle stmt)
    {
      return (stmt != null) ? stmt.handle : IntPtr.Zero;
    }

    public static implicit operator SQLiteStatementHandle(IntPtr stmt)
    {
      return new SQLiteStatementHandle(stmt);
    }

    private SQLiteStatementHandle(IntPtr stmt)
      : this()
    {
      SetHandle(stmt);
    }

    internal SQLiteStatementHandle()
      : base(IntPtr.Zero)
    {
    }

    protected override bool ReleaseHandle()
    {
      try







<
<
<
<
<
|





|







1458
1459
1460
1461
1462
1463
1464





1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
  internal class SQLiteStatementHandle : CriticalHandle
  {
    public static implicit operator IntPtr(SQLiteStatementHandle stmt)
    {
      return (stmt != null) ? stmt.handle : IntPtr.Zero;
    }






    internal SQLiteStatementHandle(IntPtr stmt)
      : this()
    {
      SetHandle(stmt);
    }

    private SQLiteStatementHandle()
      : base(IntPtr.Zero)
    {
    }

    protected override bool ReleaseHandle()
    {
      try
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
  internal class SQLiteBackupHandle : CriticalHandle
  {
      public static implicit operator IntPtr(SQLiteBackupHandle backup)
      {
          return (backup != null) ? backup.handle : IntPtr.Zero;
      }

      public static implicit operator SQLiteBackupHandle(IntPtr backup)
      {
          return new SQLiteBackupHandle(backup);
      }

      private SQLiteBackupHandle(IntPtr backup)
          : this()
      {
          SetHandle(backup);
      }

      internal SQLiteBackupHandle()
          : base(IntPtr.Zero)
      {
      }

      protected override bool ReleaseHandle()
      {
          try







<
<
<
<
<
|





|







1552
1553
1554
1555
1556
1557
1558





1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
  internal class SQLiteBackupHandle : CriticalHandle
  {
      public static implicit operator IntPtr(SQLiteBackupHandle backup)
      {
          return (backup != null) ? backup.handle : IntPtr.Zero;
      }






      internal SQLiteBackupHandle(IntPtr backup)
          : this()
      {
          SetHandle(backup);
      }

      private SQLiteBackupHandle()
          : base(IntPtr.Zero)
      {
      }

      protected override bool ReleaseHandle()
      {
          try
Changes to Tests/tkt-996d13cd87.eagle.
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  set fileName tkt-996d13cd87-1.1.db
} -body {
  set id [object invoke Interpreter.GetActive NextId]
  set dataSource [file join [getDatabaseDirectory] $fileName]

  set sql { \
    CREATE TABLE t1(x TEXT); \
    INSERT INTO t1 (x) VALUES(HEX(RANDOMBLOB(1000))); \
  }

  unset -nocomplain results errors

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







|







24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  set fileName tkt-996d13cd87-1.1.db
} -body {
  set id [object invoke Interpreter.GetActive NextId]
  set dataSource [file join [getDatabaseDirectory] $fileName]

  set sql { \
    CREATE TABLE t1(x TEXT); \
    INSERT INTO t1 (x) VALUES(RANDOMBLOB(1000)); \
  }

  unset -nocomplain results errors

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