Version History
1.0.83.0 - November XX, 2012 (release scheduled)
-
-
- Updated to SQLite 3.7.14. +
- Updated to SQLite 3.7.15.
- Add an overload of the SQLiteLog.LogMessage method that takes a single string argument.
- All applicable calls into the SQLite core library now return a SQLiteErrorCode instead of an integer error code.
- Make sure the error code of the SQLiteException class gets serialized.
- Make the test project for the .NET Compact Framework more flexible.
- When available, the new sqlite3_errstr function from the core library is used to get the error message for a specific return code. Index: SQLite.Interop/props/sqlite3.props ================================================================== --- SQLite.Interop/props/sqlite3.props +++ SQLite.Interop/props/sqlite3.props @@ -7,12 +7,12 @@ * Released to the public domain, use at your own risk! * -->
- mode: ^(The mode parameter may be set to either "ro", "rw",
** "rwc", or "memory". Attempting to set it to any other value is
** an error)^.
** ^If "ro" is specified, then the database is opened for read-only
** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
-** third argument to sqlite3_prepare_v2(). ^If the mode option is set to
+** third argument to sqlite3_open_v2(). ^If the mode option is set to
** "rw", then the database is opened for read-write (but not create)
** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
** been set. ^Value "rwc" is equivalent to setting both
** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is
** set to "memory" then a pure [in-memory database] that never reads
@@ -2749,10 +2749,15 @@
** text that describes the error, as either UTF-8 or UTF-16 respectively.
** ^(Memory to hold the error message string is managed internally.
** The application does not need to worry about freeing the result.
** However, the error string might be overwritten or deallocated by
** subsequent calls to other SQLite interface functions.)^
+**
+** ^The sqlite3_errstr() interface returns the English-language text
+** that describes the [result code], as UTF-8.
+** ^(Memory to hold the error message string is managed internally
+** and must not be freed by the application)^.
**
** When the serialized [threading mode] is in use, it might be the
** case that a second error occurs on a separate thread in between
** the time of the first error and the call to these interfaces.
** When that happens, the second error will be reported since these
@@ -2768,10 +2773,11 @@
*/
SQLITE_API int sqlite3_errcode(sqlite3 *db);
SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
SQLITE_API const char *sqlite3_errmsg(sqlite3*);
SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
+SQLITE_API const char *sqlite3_errstr(int);
/*
** CAPI3REF: SQL Statement Object
** KEYWORDS: {prepared statement} {prepared statements}
**
Index: System.Data.SQLite/SQLiteBase.cs
==================================================================
--- System.Data.SQLite/SQLiteBase.cs
+++ System.Data.SQLite/SQLiteBase.cs
@@ -6,11 +6,14 @@
********************************************************/
namespace System.Data.SQLite
{
using System;
- // using System.Runtime.InteropServices;
+
+#if !PLATFORM_COMPACTFRAMEWORK
+ using System.Runtime.InteropServices;
+#endif
///
/// This internal class provides the foundation of SQLite support. It defines all the abstract members needed to implement /// a SQLite data provider, and inherits from SQLiteConvert which allows for simple translations of string to and from SQLite. /// @@ -390,15 +393,21 @@ /* SQLITE_MISUSE */ "library routine called out of sequence", /* SQLITE_NOLFS */ "large file support is disabled", /* SQLITE_AUTH */ "authorization denied", /* SQLITE_FORMAT */ "auxiliary database format error", /* SQLITE_RANGE */ "bind or column index out of range", - /* SQLITE_NOTADB */ "file is encrypted or is not a database", + /* SQLITE_NOTADB */ "file is encrypted or is not a database" }; /////////////////////////////////////////////////////////////////////////////////////////////// + ///+ /// Returns the error message for the specified SQLite return code using + /// the internal static lookup table. + /// + /// The SQLite return code. + ///The error message or null if it cannot be found. private static string FallbackGetErrorString(SQLiteErrorCode rc) { if (_errorMessages == null) return null; @@ -408,23 +417,36 @@ index = (int)SQLiteErrorCode.Error; /* Make into generic error. */ return _errorMessages[index]; } + ///+ /// Returns the error message for the specified SQLite return code using + /// the sqlite3_errstr() function, falling back to the internal lookup + /// table if necessary. + /// + /// The SQLite return code. + ///The error message or null if it cannot be found. internal static string GetErrorString(SQLiteErrorCode rc) { - //try - //{ - // IntPtr ptr = UnsafeNativeMethods.sqlite3_errstr(rc); - // - // if (ptr != IntPtr.Zero) - // return Marshal.PtrToStringAnsi(ptr); - //} - //catch (EntryPointNotFoundException) - //{ - // // do nothing. - //} + try + { + IntPtr ptr = UnsafeNativeMethods.sqlite3_errstr(rc); + + if (ptr != IntPtr.Zero) + { +#if !PLATFORM_COMPACTFRAMEWORK + return Marshal.PtrToStringAnsi(ptr); +#else + return UTF8ToString(ptr, -1); +#endif + } + } + catch (EntryPointNotFoundException) + { + // do nothing. + } return FallbackGetErrorString(rc); } internal static string GetLastError(SQLiteConnectionHandle hdl, IntPtr db) Index: System.Data.SQLite/SQLiteException.cs ================================================================== --- System.Data.SQLite/SQLiteException.cs +++ System.Data.SQLite/SQLiteException.cs @@ -9,10 +9,11 @@ { using System; using System.Data.Common; #if !PLATFORM_COMPACTFRAMEWORK + using System.Reflection; using System.Runtime.Serialization; using System.Security.Permissions; #endif ///@@ -122,10 +123,39 @@ public SQLiteErrorCode ErrorCode #endif { get { return _errorCode; } } + + /// + /// Returns the error message for the specified SQLite return code. + /// + /// The SQLite return code. + ///The error message or null if it cannot be found. + private static string GetErrorString( + SQLiteErrorCode errorCode + ) + { +#if !PLATFORM_COMPACTFRAMEWORK + // + // HACK: This must be done via reflection in order to prevent + // the RuntimeHelpers.PrepareDelegate method from over- + // eagerly attempting to locate the new (and optional) + // sqlite3_errstr() function in the SQLite core library + // because it happens to be in the static call graph for + // the AppDomain.DomainUnload event handler registered + // by the SQLiteLog class. + // + BindingFlags flags = BindingFlags.Static | + BindingFlags.NonPublic | BindingFlags.InvokeMethod; + + return typeof(SQLiteBase).InvokeMember("GetErrorString", + flags, null, null, new object[] { errorCode }) as string; +#else + return SQLiteBase.GetErrorString(errorCode); +#endif + } ////// Returns the composite error message based on the SQLite return code /// and the optional detailed error message. /// @@ -136,11 +166,11 @@ SQLiteErrorCode errorCode, string message ) { return String.Format("{0}{1}{2}", - SQLiteBase.GetErrorString(errorCode), + GetErrorString(errorCode), Environment.NewLine, message).Trim(); } } ///Index: System.Data.SQLite/UnsafeNativeMethods.cs ================================================================== --- System.Data.SQLite/UnsafeNativeMethods.cs +++ System.Data.SQLite/UnsafeNativeMethods.cs @@ -609,11 +609,11 @@ #if !PLATFORM_COMPACTFRAMEWORK [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)] #else [DllImport(SQLITE_DLL)] #endif - internal static extern SQLiteErrorCode sqlite3_close_v2(IntPtr db); + internal static extern SQLiteErrorCode sqlite3_close_v2(IntPtr db); /* 3.7.14+ */ #if !PLATFORM_COMPACTFRAMEWORK [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)] #else [DllImport(SQLITE_DLL)] @@ -1292,16 +1292,16 @@ #else [DllImport(SQLITE_DLL)] #endif internal static extern SQLiteErrorCode sqlite3_extended_errcode(IntPtr db); -//#if !PLATFORM_COMPACTFRAMEWORK -// [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)] -//#else -// [DllImport(SQLITE_DLL)] -//#endif -// internal static extern IntPtr sqlite3_errstr(SQLiteErrorCode rc); /* 3.7.15+ */ +#if !PLATFORM_COMPACTFRAMEWORK + [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)] +#else + [DllImport(SQLITE_DLL)] +#endif + internal static extern IntPtr sqlite3_errstr(SQLiteErrorCode rc); /* 3.7.15+ */ // 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 Index: readme.htm ================================================================== --- readme.htm +++ readme.htm @@ -4,11 +4,11 @@ ADO.NET SQLite Data Provider
Version 1.0.83.0 November XX, 2012 (release scheduled)
-Using SQLite 3.7.14
+Using SQLite 3.7.15
Originally written by Robert Simpson
Released to the public domain, use at your own risk!
Official provider website: http://system.data.sqlite.org/
Legacy versions: http://sqlite.phxsoftware.com/
@@ -188,11 +188,11 @@1.0.83.0 - November XX, 2012
-
-
- Updated to SQLite 3.7.14. +
- Updated to SQLite 3.7.15.
- Add an overload of the SQLiteLog.LogMessage method that takes a single string argument.
- All applicable calls into the SQLite core library now return a SQLiteErrorCode instead of an integer error code.
- Make sure the error code of the SQLiteException class gets serialized.
- Make the test project for the .NET Compact Framework more flexible.
- When available, the new sqlite3_errstr function from the core library is used to get the error message for a specific return code. Index: www/news.wiki ================================================================== --- www/news.wiki +++ www/news.wiki @@ -4,11 +4,11 @@
- Updated to [http://www.sqlite.org/releaselog/3_7_14.html|SQLite 3.7.14]. +
- Updated to [http://www.sqlite.org/src/info/trunk|SQLite 3.7.15].
- Add an overload of the SQLiteLog.LogMessage method that takes a single string argument.
- All applicable calls into the SQLite core library now return a SQLiteErrorCode instead of an integer error code.
- Make sure the error code of the SQLiteException class gets serialized.
- Make the test project for the .NET Compact Framework more flexible.
- When available, the new sqlite3_errstr function from the core library is used to get the error message for a specific return code.
1.0.83.0 - November XX, 2012 (release scheduled)
-
-