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

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

Overview
Comment:Added LogMessage() to expose the sqlite3_log() interface.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d908d628e866f6c346cd76908eaba2a4c4004edf
User & Date: shaneh 2011-04-26 03:56:07
Context
2011-04-27
17:40
Line ending changes. check-in: 354f178d33 user: shaneh tags: trunk
2011-04-26
03:56
Added LogMessage() to expose the sqlite3_log() interface. check-in: d908d628e8 user: shaneh tags: trunk
2011-04-23
23:41
Removed the need for the sqlite3.def file. This should fix issue [e486f6be57]. check-in: c3a442319f user: shaneh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

872
873
874
875
876
877
878






879
880
881
882
883
884
885
      return UnsafeNativeMethods.sqlite3_errcode(_sql);
    }
    /// Gets the last SQLite extended error code
    internal override int ExtendedResultCode()
    {
      return UnsafeNativeMethods.sqlite3_extended_errcode(_sql);
    }







    internal override void SetPassword(byte[] passwordBytes)
    {
      int n = UnsafeNativeMethods.sqlite3_key(_sql, passwordBytes, passwordBytes.Length);
      if (n > 0) throw new SQLiteException(n, SQLiteLastError());
    }








>
>
>
>
>
>







872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
      return UnsafeNativeMethods.sqlite3_errcode(_sql);
    }
    /// Gets the last SQLite extended error code
    internal override int ExtendedResultCode()
    {
      return UnsafeNativeMethods.sqlite3_extended_errcode(_sql);
    }

    /// Add a log message via the SQLite sqlite3_log interface.
    internal override void LogMessage(int iErrCode, string zMessage)
    {
      UnsafeNativeMethods.sqlite3_log(iErrCode, ToUTF8(zMessage));
    }

    internal override void SetPassword(byte[] passwordBytes)
    {
      int n = UnsafeNativeMethods.sqlite3_key(_sql, passwordBytes, passwordBytes.Length);
      if (n > 0) throw new SQLiteException(n, SQLiteLastError());
    }

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

170
171
172
173
174
175
176










177
178
179
180
181
182
183
    /// <summary>
    /// Returns the extended numeric result code for the most recent failed SQLite API call 
    /// associated with the database connection. 
    /// </summary>
    /// <returns>Extended result code</returns>
    internal abstract int ExtendedResultCode();











    internal abstract void SetPassword(byte[] passwordBytes);
    internal abstract void ChangePassword(byte[] newPasswordBytes);

    internal abstract void SetUpdateHook(SQLiteUpdateCallback func);
    internal abstract void SetCommitHook(SQLiteCommitCallback func);
    internal abstract void SetTraceCallback(SQLiteTraceCallback func);
    internal abstract void SetRollbackHook(SQLiteRollbackCallback func);







>
>
>
>
>
>
>
>
>
>







170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
    /// <summary>
    /// Returns the extended numeric result code for the most recent failed SQLite API call 
    /// associated with the database connection. 
    /// </summary>
    /// <returns>Extended result code</returns>
    internal abstract int ExtendedResultCode();

    /// <summary>
    /// Add a log message via the SQLite sqlite3_log interface.
    /// </summary>
    /// <param name="iErrCode">Error code to be logged with the message.</param>
    /// <param name="zMessage">String to be logged.  Unlike the SQLite sqlite3_log() 
    /// interface, this should be pre-formatted.  Consider using the 
    /// String.Format() function.</param>
    /// <returns></returns>
    internal abstract void LogMessage(int iErrCode, string zMessage);

    internal abstract void SetPassword(byte[] passwordBytes);
    internal abstract void ChangePassword(byte[] newPasswordBytes);

    internal abstract void SetUpdateHook(SQLiteUpdateCallback func);
    internal abstract void SetCommitHook(SQLiteCommitCallback func);
    internal abstract void SetTraceCallback(SQLiteTraceCallback func);
    internal abstract void SetRollbackHook(SQLiteRollbackCallback func);

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

1028
1029
1030
1031
1032
1033
1034






1035
1036
1037
1038
1039
1040
1041
    /// Enables or disabled extended result codes returned by SQLite
    public int ExtendedResultCode()
    {
      if (_sql == null)
        throw new InvalidOperationException("Database connection not valid for getting extended result code.");
      return _sql.ExtendedResultCode();
    }







    /// <summary>
    /// Change the password (or assign a password) to an open database.
    /// </summary>
    /// <remarks>
    /// No readers or writers may be active for this process.  The database must already be open
    /// and if it already was password protected, the existing password must already have been supplied.







>
>
>
>
>
>







1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
    /// Enables or disabled extended result codes returned by SQLite
    public int ExtendedResultCode()
    {
      if (_sql == null)
        throw new InvalidOperationException("Database connection not valid for getting extended result code.");
      return _sql.ExtendedResultCode();
    }

    /// Add a log message via the SQLite sqlite3_log interface.
    public void LogMessage(int iErrCode, string zMessage)
    {
      _sql.LogMessage(iErrCode, zMessage);
    }

    /// <summary>
    /// Change the password (or assign a password) to an open database.
    /// </summary>
    /// <remarks>
    /// No readers or writers may be active for this process.  The database must already be open
    /// and if it already was password protected, the existing password must already have been supplied.

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

724
725
726
727
728
729
730









731
732
733
734
735
736
737
#if !PLATFORM_COMPACTFRAMEWORK
    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
#else
    [DllImport(SQLITE_DLL)]
#endif
    internal static extern int sqlite3_extended_errcode(IntPtr db);











    #endregion
  }

#if PLATFORM_COMPACTFRAMEWORK
  internal abstract class CriticalHandle : IDisposable
  {







>
>
>
>
>
>
>
>
>







724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
#if !PLATFORM_COMPACTFRAMEWORK
    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
#else
    [DllImport(SQLITE_DLL)]
#endif
    internal static extern int sqlite3_extended_errcode(IntPtr db);

    // Since sqlite3_log() takes a variable argument list, we have to overload declarations
    // for all possible calls.  For now, we are only exposing a single string, and 
    // depend on the caller to format the string.
#if !PLATFORM_COMPACTFRAMEWORK
    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
#else
    [DllImport(SQLITE_DLL)]
#endif
    internal static extern void sqlite3_log(int iErrCode, byte[] zFormat);

    #endregion
  }

#if PLATFORM_COMPACTFRAMEWORK
  internal abstract class CriticalHandle : IDisposable
  {

Changes to test/TestCases.cs.

9
10
11
12
13
14
15

16
17
18
19
20
21
22
....
1576
1577
1578
1579
1580
1581
1582

1583
1584
1585
1586
1587
1588
1589
....
1590
1591
1592
1593
1594
1595
1596

1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607

1608


1609
1610
1611
1612
1613
1614
1615

namespace test
{
  internal class TestCases : TestCaseBase
  {
    private List<string> droptables = new List<string>();
    private List<string> maydroptable = new List<string>();

    

    internal TestCases()
    {
    }

    internal TestCases(DbProviderFactory factory, string connectionString, string factoryString)
................................................................................
    }

    //Applying EventHandler
    public void OnLogEvent(object sender, LogEventArgs logEvent)
    {
        int err_code = logEvent.ErrorCode;
        string err_msg = logEvent.Message;

    }

    /// <summary>
    /// Tests SQLITE_CONFIG_LOG support.
    /// </summary>
    [Test]
    internal void SetLogCallbackTest()
................................................................................
    {
        if (_factstring.ToLower().Contains("sqlite"))
        {
            SQLiteConnection cnn = new SQLiteConnection(_cnnstring.ConnectionString);

            cnn.Shutdown();  // we need to shutdown so that we can change config options


            SQLiteLogEventHandler logHandler = new SQLiteLogEventHandler(OnLogEvent); 
            cnn.Log += logHandler;

            cnn.Open();

            maydroptable.Add("LogCallbackTest");
            if (cnn.State != ConnectionState.Open) cnn.Open();
            using (DbCommand cmd = cnn.CreateCommand())
            {
                cmd.CommandText = "CREATE TABLE LogCallbackTest(ID int primary key)";
                cmd.ExecuteNonQuery();

            }



            cnn.Close();

            cnn.Shutdown();  // we need to shutdown so that we can change config options

            // remove the log handler before the connection is closed.
            cnn.Log -= logHandler;







>







 







>







 







>





|
<
<
|
<
<
>
|
>
>







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
....
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
....
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605


1606


1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617

namespace test
{
  internal class TestCases : TestCaseBase
  {
    private List<string> droptables = new List<string>();
    private List<string> maydroptable = new List<string>();
    private long logevents = 0;
    

    internal TestCases()
    {
    }

    internal TestCases(DbProviderFactory factory, string connectionString, string factoryString)
................................................................................
    }

    //Applying EventHandler
    public void OnLogEvent(object sender, LogEventArgs logEvent)
    {
        int err_code = logEvent.ErrorCode;
        string err_msg = logEvent.Message;
        logevents++;
    }

    /// <summary>
    /// Tests SQLITE_CONFIG_LOG support.
    /// </summary>
    [Test]
    internal void SetLogCallbackTest()
................................................................................
    {
        if (_factstring.ToLower().Contains("sqlite"))
        {
            SQLiteConnection cnn = new SQLiteConnection(_cnnstring.ConnectionString);

            cnn.Shutdown();  // we need to shutdown so that we can change config options

            // create and add a log event handler
            SQLiteLogEventHandler logHandler = new SQLiteLogEventHandler(OnLogEvent); 
            cnn.Log += logHandler;

            cnn.Open();

            logevents = 0;





            cnn.LogMessage(1, "test log event");

            if (logevents != 1)
                throw new Exception("Log event count incorrect.");

            cnn.Close();

            cnn.Shutdown();  // we need to shutdown so that we can change config options

            // remove the log handler before the connection is closed.
            cnn.Log -= logHandler;