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

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

Overview
Comment:Work in progress on exerpimental method to reset the statements associated with a SQLiteCommand.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | cmdReset
Files: files | file ages | folders
SHA1: f12609cfe94cc45b318e7976a950a10c46d2b88a
User & Date: mistachkin 2015-08-28 20:26:51
Context
2015-08-28
22:16
Fix implementation and tests for SQLiteCommand.Reset method. Remove (now) superfluous new code. Closed-Leaf check-in: 6fa1fe8314 user: mistachkin tags: cmdReset
20:26
Work in progress on exerpimental method to reset the statements associated with a SQLiteCommand. check-in: f12609cfe9 user: mistachkin tags: cmdReset
2015-08-25
21:16
Remove duplicate (and incorrect for Visual Studio 2015) link from the download page. check-in: 463bcfb351 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

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

   946    946             CommandBehavior.SingleRow | CommandBehavior.SingleResult))
   947    947         {
   948    948           if (reader.Read())
   949    949             return reader[0];
   950    950         }
   951    951         return null;
   952    952       }
          953  +
          954  +    /// <summary>
          955  +    /// This method resets all the prepared statements held by this instance
          956  +    /// back to their initial states, ready to be re-executed.
          957  +    /// </summary>
          958  +    public void Reset()
          959  +    {
          960  +        CheckDisposed();
          961  +        SQLiteConnection.Check(_cnn);
          962  +
          963  +        Reset(true, false);
          964  +    }
          965  +
          966  +    /// <summary>
          967  +    /// This method resets all the prepared statements held by this instance
          968  +    /// back to their initial states, ready to be re-executed.
          969  +    /// </summary>
          970  +    /// <param name="clearBindings">
          971  +    /// Non-zero if the parameter bindings should be cleared as well.
          972  +    /// </param>
          973  +    /// <param name="ignoreErrors">
          974  +    /// If this is zero, a <see cref="SQLiteException" /> may be thrown for
          975  +    /// any unsuccessful return codes from the native library; otherwise, a
          976  +    /// <see cref="SQLiteException" /> will only be thrown if the connection
          977  +    /// or its state is invalid.
          978  +    /// </param>
          979  +    public void Reset(
          980  +        bool clearBindings,
          981  +        bool ignoreErrors
          982  +        )
          983  +    {
          984  +        CheckDisposed();
          985  +        SQLiteConnection.Check(_cnn);
          986  +
          987  +        if (clearBindings && (_parameterCollection != null))
          988  +            _parameterCollection.Unbind();
          989  +
          990  +        if (_statementList == null)
          991  +            return;
          992  +
          993  +        SQLiteBase sqlBase = _cnn._sql;
          994  +        SQLiteErrorCode rc;
          995  +
          996  +        foreach (SQLiteStatement item in _statementList)
          997  +        {
          998  +            if (item == null)
          999  +                continue;
         1000  +
         1001  +            SQLiteStatementHandle stmt = item._sqlite_stmt;
         1002  +
         1003  +            if (stmt == null)
         1004  +                continue;
         1005  +
         1006  +            rc = sqlBase.Reset(item);
         1007  +
         1008  +            if ((rc == SQLiteErrorCode.Ok) && clearBindings &&
         1009  +                (SQLite3.SQLiteVersionNumber >= 3003007))
         1010  +            {
         1011  +                rc = UnsafeNativeMethods.sqlite3_clear_bindings(stmt);
         1012  +            }
         1013  +
         1014  +            if (!ignoreErrors && (rc != SQLiteErrorCode.Ok))
         1015  +                throw new SQLiteException(rc, sqlBase.GetLastError());
         1016  +        }
         1017  +    }
   953   1018   
   954   1019       /// <summary>
   955   1020       /// Does nothing.  Commands are prepared as they are executed the first time, and kept in prepared state afterwards.
   956   1021       /// </summary>
   957   1022       public override void Prepare()
   958   1023       {
   959   1024         CheckDisposed();

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

  1544   1544           {
  1545   1545               typ.Affinity = _activeStatement._sql.ColumnAffinity(
  1546   1546                   _activeStatement, i);
  1547   1547           }
  1548   1548   
  1549   1549           return typ;
  1550   1550       }
         1551  +
         1552  +    /// <summary>
         1553  +    /// This method resets all the prepared statements referenced by this
         1554  +    /// instance back to their initial states, ready to be re-executed.
         1555  +    /// </summary>
         1556  +    public void Reset()
         1557  +    {
         1558  +        CheckDisposed();
         1559  +        CheckClosed();
         1560  +
         1561  +        if (_command == null)
         1562  +            return;
         1563  +
         1564  +        _command.Reset();
         1565  +    }
         1566  +
         1567  +    /// <summary>
         1568  +    /// This method resets all the prepared statements referenced by this
         1569  +    /// instance back to their initial states, ready to be re-executed.
         1570  +    /// </summary>
         1571  +    /// <param name="clearBindings">
         1572  +    /// Non-zero if the parameter bindings should be cleared as well.
         1573  +    /// </param>
         1574  +    /// <param name="ignoreErrors">
         1575  +    /// If this is zero, a <see cref="SQLiteException" /> may be thrown for
         1576  +    /// any unsuccessful return codes from the native library; otherwise, a
         1577  +    /// <see cref="SQLiteException" /> will only be thrown if the connection
         1578  +    /// or its state is invalid.
         1579  +    /// </param>
         1580  +    public void Reset(
         1581  +        bool clearBindings,
         1582  +        bool ignoreErrors
         1583  +        )
         1584  +    {
         1585  +        CheckDisposed();
         1586  +        CheckClosed();
         1587  +
         1588  +        if (_command == null)
         1589  +            return;
         1590  +
         1591  +        _command.Reset(clearBindings, ignoreErrors);
         1592  +    }
  1551   1593   
  1552   1594       /// <summary>
  1553   1595       /// Reads the next row from the resultset
  1554   1596       /// </summary>
  1555   1597       /// <returns>True if a new row was successfully loaded and is ready for processing</returns>
  1556   1598       public override bool Read()
  1557   1599       {

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

  1859   1859   #if !PLATFORM_COMPACTFRAMEWORK
  1860   1860       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
  1861   1861   #else
  1862   1862       [DllImport(SQLITE_DLL)]
  1863   1863   #endif
  1864   1864       internal static extern SQLiteErrorCode sqlite3_busy_timeout(IntPtr db, int ms);
  1865   1865   
         1866  +#if !PLATFORM_COMPACTFRAMEWORK
         1867  +    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
         1868  +#else
         1869  +    [DllImport(SQLITE_DLL)]
         1870  +#endif
         1871  +    internal static extern SQLiteErrorCode sqlite3_clear_bindings(IntPtr stmt);
         1872  +
  1866   1873   #if !PLATFORM_COMPACTFRAMEWORK
  1867   1874       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
  1868   1875   #else
  1869   1876       [DllImport(SQLITE_DLL)]
  1870   1877   #endif
  1871   1878       internal static extern SQLiteErrorCode sqlite3_bind_blob(IntPtr stmt, int index, Byte[] value, int nSize, IntPtr nTransient);
  1872   1879   

Changes to Tests/basic.eagle.

  3850   3850     rename hashManagedArray ""
  3851   3851     rename getHashCode ""
  3852   3852     rename getMyFuncArgs ""
  3853   3853   } -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
  3854   3854   System.Data.SQLite} -match regexp -result {^0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 \{1\
  3855   3855   2 3 A a M m Z z\} True 1 True 1 True 1 True 1 True 1 True 1 True 1 True 1\
  3856   3856   \{(?:-)?\d+ (?:-)?\d+\}$}}
         3857  +
         3858  +###############################################################################
         3859  +
         3860  +runTest {test data-1.75 {Reset method} -setup {
         3861  +  setupDb [set fileName data-1.75.db]
         3862  +} -body {
         3863  +  set connection [getDbConnection]
         3864  +
         3865  +  set result [list]
         3866  +
         3867  +  sql execute $db {
         3868  +    CREATE TABLE t1(x);
         3869  +    INSERT INTO t1 (x) VALUES(1);
         3870  +    INSERT INTO t1 (x) VALUES(2);
         3871  +    INSERT INTO t1 (x) VALUES(3);
         3872  +    INSERT INTO t1 (x) VALUES(4);
         3873  +  }
         3874  +
         3875  +  set dataReader [sql execute -execute reader -format datareader \
         3876  +      -alias $db "SELECT x FROM t1 WHERE x < ? ORDER BY x;" \
         3877  +      [list param1 Int32 4]]
         3878  +
         3879  +  $dataReader Read; lappend result [$dataReader Item x]
         3880  +  $dataReader Read; lappend result [$dataReader Item x]
         3881  +
         3882  +  $dataReader Reset; $dataReader NextResult; # TODO: Fix me.
         3883  +  $dataReader Read; lappend result [$dataReader Item x]
         3884  +  $dataReader Read; lappend result [$dataReader Item x]
         3885  +
         3886  +  $dataReader Reset; $dataReader NextResult; # TODO: Fix me.
         3887  +  $dataReader Read; lappend result [$dataReader Item x]
         3888  +  $dataReader Read; lappend result [$dataReader Item x]
         3889  +
         3890  +  set result
         3891  +} -cleanup {
         3892  +  cleanupDb $fileName
         3893  +
         3894  +  freeDbConnection
         3895  +
         3896  +  unset -nocomplain result connection db fileName
         3897  +} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
         3898  +System.Data.SQLite} -result {1 2 1 2 1 2}}
  3857   3899   
  3858   3900   ###############################################################################
  3859   3901   
  3860   3902   reportSQLiteResources $test_channel
  3861   3903   
  3862   3904   ###############################################################################
  3863   3905   
  3864   3906   runSQLiteTestFilesEpilogue
  3865   3907   runSQLiteTestEpilogue
  3866   3908   runTestEpilogue