System.Data.SQLite

Login
This project makes use of Eagle, provided by Mistachkin Systems.
Eagle: Secure Software Automation

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

Overview
Comment:Initial work on fully supporting the sqlite3_trace_v2 core library API. Pursuant to forum post https://sqlite.org/forum/forumpost/1c418d7edc.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 5ad580f5ecbd3ca72567d235a5f2cf717bc1411e
User & Date: mistachkin 2023-01-17 04:07:33
Context
2023-01-17
04:11
Work-in-progress corrections to the previous check-in. check-in: 1cad101163 user: mistachkin tags: trunk
04:07
Initial work on fully supporting the sqlite3_trace_v2 core library API. Pursuant to forum post https://sqlite.org/forum/forumpost/1c418d7edc. check-in: 5ad580f5ec user: mistachkin tags: trunk
2023-01-11
20:59
Add support for the (new) sqlite3_is_interrupted core library API. check-in: 5cf635b987 user: mistachkin tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
  }

  /// <summary>
  /// These constants are used with the sqlite3_trace_v2() API and the
  /// callbacks registered by it.
  /// </summary>
  [Flags()]
  internal enum SQLiteTraceFlags
  {
      SQLITE_TRACE_NONE = 0x0, // nil
      SQLITE_TRACE_STMT = 0x1, // pStmt, zSql
      SQLITE_TRACE_PROFILE = 0x2, // pStmt, piNsec64
      SQLITE_TRACE_ROW = 0x4, // pStmt
      SQLITE_TRACE_CLOSE = 0x8 // pDb
  }







|







1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
  }

  /// <summary>
  /// These constants are used with the sqlite3_trace_v2() API and the
  /// callbacks registered by it.
  /// </summary>
  [Flags()]
  public enum SQLiteTraceFlags
  {
      SQLITE_TRACE_NONE = 0x0, // nil
      SQLITE_TRACE_STMT = 0x1, // pStmt, zSql
      SQLITE_TRACE_PROFILE = 0x2, // pStmt, piNsec64
      SQLITE_TRACE_ROW = 0x4, // pStmt
      SQLITE_TRACE_CLOSE = 0x8 // pDb
  }

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

1621
1622
1623
1624
1625
1626
1627







1628
1629
1630
1631
1632
1633
1634
    /// <summary>
    /// The extra behavioral flags for this connection, if any.  See the
    /// <see cref="SQLiteConnectionFlags" /> enumeration for a list of
    /// possible values.
    /// </summary>
    private SQLiteConnectionFlags _flags;








    /// <summary>
    /// The cached values for all settings that have been fetched on behalf
    /// of this connection.  This cache may be cleared by calling the
    /// <see cref="ClearCachedSettings" /> method.
    /// </summary>
    private Dictionary<string, object> _cachedSettings;








>
>
>
>
>
>
>







1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
    /// <summary>
    /// The extra behavioral flags for this connection, if any.  See the
    /// <see cref="SQLiteConnectionFlags" /> enumeration for a list of
    /// possible values.
    /// </summary>
    private SQLiteConnectionFlags _flags;

    /// <summary>
    /// The mask of zero or more <see cref="SQLiteTraceFlags" /> values that
    /// determine which events may be raised from the <see cref="Trace2" />
    /// event.
    /// </summary>
    private SQLiteTraceFlags _traceFlags;

    /// <summary>
    /// The cached values for all settings that have been fetched on behalf
    /// of this connection.  This cache may be cleared by calling the
    /// <see cref="ClearCachedSettings" /> method.
    /// </summary>
    private Dictionary<string, object> _cachedSettings;

1704
1705
1706
1707
1708
1709
1710

1711
1712
1713
1714
1715
1716
1717
1718

1719
1720
1721
1722
1723
1724
1725

    private event SQLiteBusyEventHandler _busyHandler;
    private event SQLiteProgressEventHandler _progressHandler;
    private event SQLiteAuthorizerEventHandler _authorizerHandler;
    private event SQLiteUpdateEventHandler _updateHandler;
    private event SQLiteCommitHandler _commitHandler;
    private event SQLiteTraceEventHandler _traceHandler;

    private event EventHandler _rollbackHandler;

    private SQLiteBusyCallback _busyCallback;
    private SQLiteProgressCallback _progressCallback;
    private SQLiteAuthorizerCallback _authorizerCallback;
    private SQLiteUpdateCallback _updateCallback;
    private SQLiteCommitCallback _commitCallback;
    private SQLiteTraceCallback _traceCallback;

    private SQLiteRollbackCallback _rollbackCallback;
    #endregion

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

    private static string GetDefaultCatalogName()
    {







>








>







1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734

    private event SQLiteBusyEventHandler _busyHandler;
    private event SQLiteProgressEventHandler _progressHandler;
    private event SQLiteAuthorizerEventHandler _authorizerHandler;
    private event SQLiteUpdateEventHandler _updateHandler;
    private event SQLiteCommitHandler _commitHandler;
    private event SQLiteTraceEventHandler _traceHandler;
    private event SQLiteTraceEventHandler _traceHandler2;
    private event EventHandler _rollbackHandler;

    private SQLiteBusyCallback _busyCallback;
    private SQLiteProgressCallback _progressCallback;
    private SQLiteAuthorizerCallback _authorizerCallback;
    private SQLiteUpdateCallback _updateCallback;
    private SQLiteCommitCallback _commitCallback;
    private SQLiteTraceCallback _traceCallback;
    private SQLiteTraceCallback2 _traceCallback2;
    private SQLiteRollbackCallback _rollbackCallback;
    #endregion

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

    private static string GetDefaultCatalogName()
    {
1812
1813
1814
1815
1816
1817
1818

1819
1820
1821
1822
1823
1824
1825
        : this()
    {
        _sql = new SQLite3(
            SQLiteDateFormats.Default, DateTimeKind.Unspecified, null,
            db, fileName, ownHandle);

        _flags = SQLiteConnectionFlags.None;


        _connectionState = (db != IntPtr.Zero) ?
            ConnectionState.Open : ConnectionState.Closed;

        _connectionString = null; /* unknown */

#if DEBUG







>







1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
        : this()
    {
        _sql = new SQLite3(
            SQLiteDateFormats.Default, DateTimeKind.Unspecified, null,
            db, fileName, ownHandle);

        _flags = SQLiteConnectionFlags.None;
        _traceFlags = SQLiteTraceFlags.SQLITE_TRACE_NONE;

        _connectionState = (db != IntPtr.Zero) ?
            ConnectionState.Open : ConnectionState.Closed;

        _connectionString = null; /* unknown */

#if DEBUG
7753
7754
7755
7756
7757
7758
7759










































7760
7761
7762
7763
7764
7765
7766
        if (_traceHandler == null)
        {
          if (_sql != null) _sql.SetTraceCallback(null);
            _traceCallback = null;
        }
      }
    }











































    private void TraceCallback(
        IntPtr puser, /* NOT USED */
        IntPtr statement
        )
    {
        try







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
        if (_traceHandler == null)
        {
          if (_sql != null) _sql.SetTraceCallback(null);
            _traceCallback = null;
        }
      }
    }

    /// <summary>
    /// This event is raised when events matching the configured mask are
    /// raised for this connection.
    /// </summary>
    public event SQLiteTraceEventHandler Trace2
    {
        add
        {
            CheckDisposed();

            if (_traceHandler2 == null)
            {
                if (_traceFlags == SQLiteTraceFlags.SQLITE_TRACE_NONE)
                {
                    throw new InvalidOperationException(
                        "cannot add trace2 event handler with no flags set");
                }

                _traceCallback2 = new SQLiteTraceCallback2(TraceCallback2);
                if (_sql != null) _sql.SetTraceCallback2(_traceFlags, _traceCallback2);
            }
            _traceHandler2 += value;
        }
        remove
        {
            CheckDisposed();

            _traceHandler2 -= value;
            if (_traceHandler2 == null)
            {
                if (_traceFlags == SQLiteTraceFlags.SQLITE_TRACE_NONE)
                {
                    throw new InvalidOperationException(
                        "cannot remove trace2 event handler with no flags set");
                }

                if (_sql != null) _sql.SetTraceCallback2(_traceFlags, null);
                _traceCallback2 = null;
            }
        }
    }

    private void TraceCallback(
        IntPtr puser, /* NOT USED */
        IntPtr statement
        )
    {
        try
7783
7784
7785
7786
7787
7788
7789






















































7790
7791
7792
7793
7794
7795
7796
            }
            catch
            {
                // do nothing.
            }
        }
    }























































    /// <summary>
    /// This event is raised whenever SQLite is rolling back a transaction.
    /// </summary>
    public event EventHandler RollBack
    {
      add







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
            }
            catch
            {
                // do nothing.
            }
        }
    }

    private void TraceCallback2(
        SQLiteTraceFlags flags,
        IntPtr pctx, /* NOT USED */
        IntPtr puser, /* NOT USED */
        IntPtr statement
        )
    {
        try
        {
            if (_traceHandler2 != null)
                _traceHandler2(this, new TraceEventArgs(flags,
                  SQLiteBase.UTF8ToString(statement, -1)));
        }
        catch (Exception e) /* NOTE: Must catch ALL. */
        {
            try
            {
                if (HelperMethods.LogCallbackExceptions(_flags))
                {
                    SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
                        HelperMethods.StringFormat(CultureInfo.CurrentCulture,
                        UnsafeNativeMethods.ExceptionMessageFormat,
                        "Trace2", e)); /* throw */
                }
            }
            catch
            {
                // do nothing.
            }
        }
    }

    /// <summary>
    /// This property is used to configure the set of events that may be raised
    /// from the <see cref="Trace2" /> event.  The value of this property cannot
    /// be changed while an event handler is registered.
    /// </summary>
    public SQLiteTraceFlags TraceFlags
    {
        get { CheckDisposed(); return _traceFlags; }
        set
        {
            CheckDisposed();

            if (_traceCallback2 != null)
            {
                throw new InvalidOperationException(
                    "cannot change trace flags while an event handler is registered");
            }

            _traceFlags = value;
        }
    }

    /// <summary>
    /// This event is raised whenever SQLite is rolling back a transaction.
    /// </summary>
    public event EventHandler RollBack
    {
      add
8349
8350
8351
8352
8353
8354
8355





8356
8357
8358
8359
8360
8361
8362
8363
8364
8365

8366


8367


  }

  /// <summary>
  /// Passed during an Trace callback, these event arguments contain the UTF-8 rendering of the SQL statement text
  /// </summary>
  public class TraceEventArgs : EventArgs
  {





    /// <summary>
    /// SQL statement text as the statement first begins executing
    /// </summary>
    public readonly string Statement;

    internal TraceEventArgs(string statement)
    {
      Statement = statement;
    }
  }




}









>
>
>
>
>









|
>
|
>
>
|
>
>
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
  }

  /// <summary>
  /// Passed during an Trace callback, these event arguments contain the UTF-8 rendering of the SQL statement text
  /// </summary>
  public class TraceEventArgs : EventArgs
  {
    /// <summary>
    /// The flags associated with this trace event.
    /// </summary>
    public readonly SQLiteTraceFlags? Flags;

    /// <summary>
    /// SQL statement text as the statement first begins executing
    /// </summary>
    public readonly string Statement;

    internal TraceEventArgs(string statement)
    {
      Statement = statement;
    }

    internal TraceEventArgs(SQLiteTraceFlags flags, string statement)
    {
      Flags = flags;
      Statement = statement;
    }
  }
}