Index: System.Data.SQLite/SQLiteModule.cs ================================================================== --- System.Data.SQLite/SQLiteModule.cs +++ System.Data.SQLite/SQLiteModule.cs @@ -4604,10 +4604,19 @@ /// private const bool DefaultLogErrors = true; /////////////////////////////////////////////////////////////////// + /// + /// This is the value that is always used for the "logExceptions" + /// parameter to the various static error handling methods provided + /// by the class. + /// + private const bool DefaultLogExceptions = true; + + /////////////////////////////////////////////////////////////////// + /// /// This is the error message text used when the contained /// object instance is not available /// for any reason. /// @@ -4661,11 +4670,11 @@ private static SQLiteErrorCode ModuleNotAvailableTableError( IntPtr pVtab ) { SetTableError(null, pVtab, DefaultLogErrors, - ModuleNotAvailableErrorMessage); + DefaultLogExceptions, ModuleNotAvailableErrorMessage); return SQLiteErrorCode.Error; } /////////////////////////////////////////////////////////////////// @@ -4684,11 +4693,11 @@ private static SQLiteErrorCode ModuleNotAvailableCursorError( IntPtr pCursor ) { SetCursorError(null, pCursor, DefaultLogErrors, - ModuleNotAvailableErrorMessage); + DefaultLogExceptions, ModuleNotAvailableErrorMessage); return SQLiteErrorCode.Error; } #endregion @@ -6159,10 +6168,14 @@ /// /// /// Non-zero if this error message should also be logged using the /// class. /// + /// + /// Non-zero if caught exceptions should be logged using the + /// class. + /// /// /// The error message. /// /// /// Non-zero upon success. @@ -6169,10 +6182,11 @@ /// private static bool SetTableError( SQLiteModule module, IntPtr pVtab, bool logErrors, + bool logExceptions, string error ) { try { @@ -6186,46 +6200,64 @@ catch { // do nothing. } - if (pVtab == IntPtr.Zero) - return false; - - int offset = 0; - - offset = SQLiteMarshal.NextOffsetOf(offset, IntPtr.Size, - sizeof(int)); - - offset = SQLiteMarshal.NextOffsetOf(offset, sizeof(int), - IntPtr.Size); - - IntPtr pError = SQLiteMarshal.ReadIntPtr(pVtab, offset); - - if (pError != IntPtr.Zero) - { - SQLiteMemory.Free(pError); pError = IntPtr.Zero; - SQLiteMarshal.WriteIntPtr(pVtab, offset, pError); - } - - if (error == null) - return true; - bool success = false; + IntPtr pNewError = IntPtr.Zero; try { - pError = SQLiteString.Utf8IntPtrFromString(error); - SQLiteMarshal.WriteIntPtr(pVtab, offset, pError); + if (pVtab == IntPtr.Zero) + return false; + + int offset = 0; + + offset = SQLiteMarshal.NextOffsetOf(offset, IntPtr.Size, + sizeof(int)); + + offset = SQLiteMarshal.NextOffsetOf(offset, sizeof(int), + IntPtr.Size); + + IntPtr pOldError = SQLiteMarshal.ReadIntPtr(pVtab, offset); + + if (pOldError != IntPtr.Zero) + { + SQLiteMemory.Free(pOldError); pOldError = IntPtr.Zero; + SQLiteMarshal.WriteIntPtr(pVtab, offset, pOldError); + } + + if (error == null) + return true; + + pNewError = SQLiteString.Utf8IntPtrFromString(error); + SQLiteMarshal.WriteIntPtr(pVtab, offset, pNewError); success = true; + } + catch (Exception e) /* NOTE: Must catch ALL. */ + { + try + { + if (logExceptions) + { + SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION, + String.Format(CultureInfo.CurrentCulture, + "Caught exception in \"SetTableError\" method: {0}", + e)); /* throw */ + } + } + catch + { + // do nothing. + } } finally { - if (!success && (pError != IntPtr.Zero)) + if (!success && (pNewError != IntPtr.Zero)) { - SQLiteMemory.Free(pError); - pError = IntPtr.Zero; + SQLiteMemory.Free(pNewError); + pNewError = IntPtr.Zero; } } return success; } @@ -6246,10 +6278,14 @@ /// /// /// Non-zero if this error message should also be logged using the /// class. /// + /// + /// Non-zero if caught exceptions should be logged using the + /// class. + /// /// /// The error message. /// /// /// Non-zero upon success. @@ -6256,10 +6292,11 @@ /// private static bool SetTableError( SQLiteModule module, SQLiteVirtualTable table, bool logErrors, + bool logExceptions, string error ) { if (table == null) return false; @@ -6267,11 +6304,12 @@ IntPtr pVtab = table.NativeHandle; if (pVtab == IntPtr.Zero) return false; - return SetTableError(module, pVtab, logErrors, error); + return SetTableError( + module, pVtab, logErrors, logExceptions, error); } /////////////////////////////////////////////////////////////////////// /// @@ -6289,10 +6327,14 @@ /// /// /// Non-zero if this error message should also be logged using the /// class. /// + /// + /// Non-zero if caught exceptions should be logged using the + /// class. + /// /// /// The error message. /// /// /// Non-zero upon success. @@ -6299,10 +6341,11 @@ /// private static bool SetCursorError( SQLiteModule module, IntPtr pCursor, bool logErrors, + bool logExceptions, string error ) { if (pCursor == IntPtr.Zero) return false; @@ -6310,11 +6353,12 @@ IntPtr pVtab = TableFromCursor(module, pCursor); if (pVtab == IntPtr.Zero) return false; - return SetTableError(module, pVtab, logErrors, error); + return SetTableError( + module, pVtab, logErrors, logExceptions, error); } /////////////////////////////////////////////////////////////////////// /// @@ -6331,10 +6375,14 @@ /// /// /// Non-zero if this error message should also be logged using the /// class. /// + /// + /// Non-zero if caught exceptions should be logged using the + /// class. + /// /// /// The error message. /// /// /// Non-zero upon success. @@ -6341,10 +6389,11 @@ /// private static bool SetCursorError( SQLiteModule module, SQLiteVirtualTableCursor cursor, bool logErrors, + bool logExceptions, string error ) { if (cursor == null) return false; @@ -6352,11 +6401,12 @@ IntPtr pCursor = cursor.NativeHandle; if (pCursor == IntPtr.Zero) return false; - return SetCursorError(module, pCursor, logErrors, error); + return SetCursorError( + module, pCursor, logErrors, logExceptions, error); } #endregion #endregion /////////////////////////////////////////////////////////////////////// @@ -6901,12 +6951,14 @@ private bool logExceptions; /// /// Returns or sets a boolean value indicating whether exceptions /// caught in the /// method, - /// method, and the - /// method should be logged using the + /// the method, + /// the method, + /// the method, + /// and the method should be logged using the /// class. /// protected virtual bool LogExceptionsNoThrow { get { return logExceptions; } @@ -6934,11 +6986,12 @@ protected virtual bool SetTableError( IntPtr pVtab, string error ) { - return SetTableError(this, pVtab, LogErrorsNoThrow, error); + return SetTableError( + this, pVtab, LogErrorsNoThrow, LogExceptionsNoThrow, error); } /////////////////////////////////////////////////////////////////////// /// @@ -6959,11 +7012,12 @@ protected virtual bool SetTableError( SQLiteVirtualTable table, string error ) { - return SetTableError(this, table, LogErrorsNoThrow, error); + return SetTableError( + this, table, LogErrorsNoThrow, LogExceptionsNoThrow, error); } /////////////////////////////////////////////////////////////////////// /// @@ -6984,11 +7038,12 @@ protected virtual bool SetCursorError( SQLiteVirtualTableCursor cursor, string error ) { - return SetCursorError(this, cursor, LogErrorsNoThrow, error); + return SetCursorError( + this, cursor, LogErrorsNoThrow, LogExceptionsNoThrow, error); } #endregion ///////////////////////////////////////////////////////////////////////