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

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

Overview
Comment:Refactor core SQLite library return code handling to make use of the enumerated SQLiteErrorCode type. Initial work on supporting the sqlite3_errstr() API.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a6c16dc93b61edd947a9b4b5d8de4ea3edf66bae
User & Date: mistachkin 2012-09-11 08:05:27
Context
2012-09-11
08:15
Bump all versions to 1.0.83.0. check-in: 45b48f33af user: mistachkin tags: trunk
08:05
Refactor core SQLite library return code handling to make use of the enumerated SQLiteErrorCode type. Initial work on supporting the sqlite3_errstr() API. check-in: a6c16dc93b user: mistachkin tags: trunk
03:40
Show the MSBuild arguments when batch file variables are displayed. check-in: f46cda9f0a user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Doc/Extra/version.html.

    39     39             </td>
    40     40           </tr>
    41     41         </table>
    42     42       </div>
    43     43       <div id="mainSection">
    44     44       <div id="mainBody">
    45     45       <h1 class="heading">Version History</h1>
           46  +    <p><b>1.0.83.0 - November XX, 2012 <font color="red">(release scheduled)</font></b></p>
           47  +    <ul>
           48  +      <li>Updated to <a href="http://www.sqlite.org/releaselog/3_7_14.html">SQLite 3.7.14</a>.</li>
           49  +      <li>Add an overload of the SQLiteLog.LogMessage method that takes a single string argument.</li>
           50  +      <li>All applicable calls into the SQLite core library now return a SQLiteErrorCode instead of an integer error code.</li>
           51  +      <li>When available, the new sqlite3_errstr function from the core library is used to get the error message for a specific return code.</li>
           52  +      <li>The SetMemoryStatus, Shutdown, ResultCode, ExtendedResultCode, and SetAvRetry methods of the SQLiteConnection class now return a SQLiteErrorCode instead of an integer error code.&nbsp;<b>** Potentially Incompatible Change **</b></li>
           53  +      <li>The public constructor for the SQLiteException now takes a SQLiteErrorCode instead of an integer error code.&nbsp;<b>** Potentially Incompatible Change **</b></li>
           54  +      <li>The ErrorCode field of the LogEventArgs is now an object instead of an integer.&nbsp;<b>** Potentially Incompatible Change **</b></li>
           55  +      <li>The names and messages associated with the SQLiteErrorCode enumeration values have been normalized to match those in the SQLite core library.&nbsp;<b>** Potentially Incompatible Change **</b></li>
           56  +    </ul>
    46     57       <p><b>1.0.82.0 - September 3, 2012</b></p>
    47     58       <ul>
    48     59         <li>Updated to <a href="http://www.sqlite.org/releaselog/3_7_14.html">SQLite 3.7.14</a>.</li>
    49     60         <li>Properly handle quoted data source values in the connection string. Fix for <a href="http://system.data.sqlite.org/index.html/info/8c3bee31c8">[8c3bee31c8]</a>.</li>
    50     61         <li>The <a href="http://nuget.org/packages/System.Data.SQLite">primary NuGet package</a> now supports x86 / x64 and the .NET Framework 2.0 / 4.0 (i.e. in a single package).</li>
    51     62         <li>Change the default value for the Synchronous connection string property to Full to match the default used by the SQLite core library itself.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    52     63         <li>Add the ability to skip applying default connection settings to opened databases via the new SetDefaults connection string property.</li>

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

    14     14     using System.Diagnostics;
    15     15   #endif
    16     16   
    17     17     using System.Globalization;
    18     18     using System.Runtime.InteropServices;
    19     19     using System.Text;
    20     20   
           21  +  /// <summary>
           22  +  /// This is the method signature for the SQLite core library logging callback
           23  +  /// function for use with sqlite3_log() and the SQLITE_CONFIG_LOG.
           24  +  ///
           25  +  /// WARNING: This delegate is used more-or-less directly by native code, do
           26  +  ///          not modify its type signature.
           27  +  /// </summary>
           28  +  /// <param name="pUserData">
           29  +  /// The extra data associated with this message, if any.
           30  +  /// </param>
           31  +  /// <param name="errorCode">
           32  +  /// The error code associated with this message.
           33  +  /// </param>
           34  +  /// <param name="pMessage">
           35  +  /// The message string to be logged.
           36  +  /// </param>
    21     37   #if !PLATFORM_COMPACTFRAMEWORK
    22     38     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
    23     39   #endif
    24         -  internal delegate void SQLiteLogCallback(IntPtr puser, int err_code, IntPtr message);
           40  +  internal delegate void SQLiteLogCallback(IntPtr pUserData, int errorCode, IntPtr pMessage);
    25     41   
    26     42     /// <summary>
    27     43     /// This class implements SQLiteBase completely, and is the guts of the code that interop's SQLite with .NET
    28     44     /// </summary>
    29     45     internal class SQLite3 : SQLiteBase
    30     46     {
    31     47       private static object syncRoot = new object();
................................................................................
   227    243       {
   228    244         get
   229    245         {
   230    246           return UnsafeNativeMethods.sqlite3_memory_highwater(0);
   231    247         }
   232    248       }
   233    249   
   234         -    internal override int SetMemoryStatus(bool value)
          250  +    internal override SQLiteErrorCode SetMemoryStatus(bool value)
   235    251       {
   236    252           return StaticSetMemoryStatus(value);
   237    253       }
   238    254   
   239         -    internal static int StaticSetMemoryStatus(bool value)
          255  +    internal static SQLiteErrorCode StaticSetMemoryStatus(bool value)
   240    256       {
   241         -        int rc = UnsafeNativeMethods.sqlite3_config_int(
          257  +        SQLiteErrorCode rc = UnsafeNativeMethods.sqlite3_config_int(
   242    258               SQLiteConfigOpsEnum.SQLITE_CONFIG_MEMSTATUS, value ? 1 : 0);
   243    259   
   244    260           return rc;
   245    261       }
   246    262   
   247    263       /// <summary>
   248    264       /// Shutdown the SQLite engine so that it can be restarted with different config options.
   249    265       /// We depend on auto initialization to recover.
   250    266       /// </summary>
   251    267       /// <returns>Returns a result code</returns>
   252         -    internal override int Shutdown()
          268  +    internal override SQLiteErrorCode Shutdown()
   253    269       {
   254         -        int rc = UnsafeNativeMethods.sqlite3_shutdown();
          270  +        SQLiteErrorCode rc = UnsafeNativeMethods.sqlite3_shutdown();
   255    271           return rc;
   256    272       }
   257    273   
   258    274       internal override bool IsOpen()
   259    275       {
   260    276           return (_sql != null);
   261    277       }
................................................................................
   277    293         }
   278    294   
   279    295         if (_sql == null)
   280    296         {
   281    297           IntPtr db;
   282    298   
   283    299   #if !SQLITE_STANDARD
   284         -        int n = UnsafeNativeMethods.sqlite3_open_interop(ToUTF8(strFilename), (int)openFlags, out db);
          300  +        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_open_interop(ToUTF8(strFilename), (int)openFlags, out db);
   285    301   #else
   286         -        int n = UnsafeNativeMethods.sqlite3_open_v2(ToUTF8(strFilename), out db, (int)openFlags, IntPtr.Zero);
          302  +        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_open_v2(ToUTF8(strFilename), out db, (int)openFlags, IntPtr.Zero);
   287    303   #endif
   288    304   
   289    305   #if !NET_COMPACT_20 && TRACE_CONNECTION
   290    306           Trace.WriteLine(String.Format("Open: {0}", db));
   291    307   #endif
   292    308   
   293         -        if (n > 0) throw new SQLiteException(n, null);
          309  +        if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, null);
   294    310   
   295    311           _sql = new SQLiteConnectionHandle(db);
   296    312           lock (_sql) { /* HACK: Force the SyncBlock to be "created" now. */ }
   297    313         }
   298    314         // Bind functions to this connection.  If any previous functions of the same name
   299    315         // were already bound, then the new bindings replace the old.
   300    316         _functionsArray = SQLiteFunction.BindFunctions(this, connectionFlags);
................................................................................
   319    335               ref totalCount);
   320    336   
   321    337           return totalCount;
   322    338       }
   323    339   
   324    340       internal override void SetTimeout(int nTimeoutMS)
   325    341       {
   326         -      int n = UnsafeNativeMethods.sqlite3_busy_timeout(_sql, nTimeoutMS);
   327         -      if (n > 0) throw new SQLiteException(n, GetLastError());
          342  +      SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_busy_timeout(_sql, nTimeoutMS);
          343  +      if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
   328    344       }
   329    345   
   330    346       internal override bool Step(SQLiteStatement stmt)
   331    347       {
   332         -      int n;
          348  +      SQLiteErrorCode n;
   333    349         Random rnd = null;
   334    350         uint starttick = (uint)Environment.TickCount;
   335    351         uint timeout = (uint)(stmt._command._commandTimeout * 1000);
   336    352   
   337    353         while (true)
   338    354         {
   339    355           n = UnsafeNativeMethods.sqlite3_step(stmt._sqlite_stmt);
   340    356   
   341         -        if (n == 100) return true;
   342         -        if (n == 101) return false;
          357  +        if (n == SQLiteErrorCode.Row) return true;
          358  +        if (n == SQLiteErrorCode.Done) return false;
   343    359   
   344         -        if (n > 0)
          360  +        if (n != SQLiteErrorCode.Ok)
   345    361           {
   346         -          int r;
          362  +          SQLiteErrorCode r;
   347    363   
   348    364             // An error occurred, attempt to reset the statement.  If the reset worked because the
   349    365             // schema has changed, re-try the step again.  If it errored our because the database
   350    366             // is locked, then keep retrying until the command timeout occurs.
   351    367             r = Reset(stmt);
   352    368   
   353         -          if (r == 0)
          369  +          if (r == SQLiteErrorCode.Ok)
   354    370               throw new SQLiteException(n, GetLastError());
   355    371   
   356         -          else if ((r == 6 || r == 5) && stmt._command != null) // SQLITE_LOCKED || SQLITE_BUSY
          372  +          else if ((r == SQLiteErrorCode.Locked || r == SQLiteErrorCode.Busy) && stmt._command != null)
   357    373             {
   358    374               // Keep trying
   359    375               if (rnd == null) // First time we've encountered the lock
   360    376                 rnd = new Random();
   361    377   
   362    378               // If we've exceeded the command's timeout, give up and throw an error
   363    379               if ((uint)Environment.TickCount - starttick > timeout)
................................................................................
   370    386                 System.Threading.Thread.Sleep(rnd.Next(1, 150));
   371    387               }
   372    388             }
   373    389           }
   374    390         }
   375    391       }
   376    392   
   377         -    internal override int Reset(SQLiteStatement stmt)
          393  +    internal override SQLiteErrorCode Reset(SQLiteStatement stmt)
   378    394       {
   379         -      int n;
          395  +      SQLiteErrorCode n;
   380    396   
   381    397   #if !SQLITE_STANDARD
   382    398         n = UnsafeNativeMethods.sqlite3_reset_interop(stmt._sqlite_stmt);
   383    399   #else
   384    400         n = UnsafeNativeMethods.sqlite3_reset(stmt._sqlite_stmt);
   385    401   #endif
   386    402   
   387    403         // If the schema changed, try and re-prepare it
   388         -      if (n == 17) // SQLITE_SCHEMA
          404  +      if (n == SQLiteErrorCode.Schema)
   389    405         {
   390    406           // Recreate a dummy statement
   391    407           string str;
   392    408           using (SQLiteStatement tmp = Prepare(null, stmt._sqlStatement, null, (uint)(stmt._command._commandTimeout * 1000), out str))
   393    409           {
   394    410             // Finalize the existing statement
   395    411             stmt._sqlite_stmt.Dispose();
................................................................................
   396    412             // Reassign a new statement pointer to the old statement and clear the temporary one
   397    413             stmt._sqlite_stmt = tmp._sqlite_stmt;
   398    414             tmp._sqlite_stmt = null;
   399    415   
   400    416             // Reapply parameters
   401    417             stmt.BindParameters();
   402    418           }
   403         -        return -1; // Reset was OK, with schema change
          419  +        return (SQLiteErrorCode)(-1); // Reset was OK, with schema change
   404    420         }
   405         -      else if (n == 6 || n == 5) // SQLITE_LOCKED || SQLITE_BUSY
          421  +      else if (n == SQLiteErrorCode.Locked || n == SQLiteErrorCode.Busy)
   406    422           return n;
   407    423   
   408         -      if (n > 0)
          424  +      if (n != SQLiteErrorCode.Ok)
   409    425           throw new SQLiteException(n, GetLastError());
   410    426   
   411         -      return 0; // We reset OK, no schema changes
          427  +      return SQLiteErrorCode.Ok; // We reset OK, no schema changes
   412    428       }
   413    429   
   414    430       internal override string GetLastError()
   415    431       {
   416    432         return SQLiteBase.GetLastError(_sql, _sql);
   417    433       }
   418    434   
................................................................................
   443    459         SQLiteConnectionFlags flags =
   444    460             (cnn != null) ? cnn.Flags : SQLiteConnectionFlags.Default;
   445    461   
   446    462   #if !PLATFORM_COMPACTFRAMEWORK
   447    463         if ((flags & SQLiteConnectionFlags.LogPrepare) == SQLiteConnectionFlags.LogPrepare)
   448    464         {
   449    465             if ((strSql == null) || (strSql.Length == 0) || (strSql.Trim().Length == 0))
   450         -              SQLiteLog.LogMessage(0, "Preparing {<nothing>}...");
          466  +              SQLiteLog.LogMessage("Preparing {<nothing>}...");
   451    467             else
   452         -              SQLiteLog.LogMessage(0, String.Format(
          468  +              SQLiteLog.LogMessage(String.Format(
   453    469                     CultureInfo.CurrentCulture, "Preparing {{{0}}}...", strSql));
   454    470         }
   455    471   #endif
   456    472   
   457    473         IntPtr stmt = IntPtr.Zero;
   458    474         IntPtr ptr = IntPtr.Zero;
   459    475         int len = 0;
   460         -      int n = 17;
          476  +      SQLiteErrorCode n = SQLiteErrorCode.Schema;
   461    477         int retries = 0;
   462    478         byte[] b = ToUTF8(strSql);
   463    479         string typedefs = null;
   464    480         SQLiteStatement cmd = null;
   465    481         Random rnd = null;
   466    482         uint starttick = (uint)Environment.TickCount;
   467    483   
   468    484         GCHandle handle = GCHandle.Alloc(b, GCHandleType.Pinned);
   469    485         IntPtr psql = handle.AddrOfPinnedObject();
   470    486         try
   471    487         {
   472         -        while ((n == 17 || n == 6 || n == 5) && retries < 3)
          488  +        while ((n == SQLiteErrorCode.Schema || n == SQLiteErrorCode.Locked || n == SQLiteErrorCode.Busy) && retries < 3)
   473    489           {
   474    490   #if !SQLITE_STANDARD
   475    491             n = UnsafeNativeMethods.sqlite3_prepare_interop(_sql, psql, b.Length - 1, out stmt, out ptr, out len);
   476    492   #else
   477    493             n = UnsafeNativeMethods.sqlite3_prepare(_sql, psql, b.Length - 1, out stmt, out ptr);
   478    494             len = -1;
   479    495   #endif
   480    496   
   481    497   #if !NET_COMPACT_20 && TRACE_STATEMENT
   482    498             Trace.WriteLine(String.Format("Prepare ({0}): {1}", n, stmt));
   483    499   #endif
   484    500   
   485         -          if (n == 17)
          501  +          if (n == SQLiteErrorCode.Schema)
   486    502               retries++;
   487         -          else if (n == 1)
          503  +          else if (n == SQLiteErrorCode.Error)
   488    504             {
   489    505               if (String.Compare(GetLastError(), "near \"TYPES\": syntax error", StringComparison.OrdinalIgnoreCase) == 0)
   490    506               {
   491    507                 int pos = strSql.IndexOf(';');
   492    508                 if (pos == -1) pos = strSql.Length - 1;
   493    509   
   494    510                 typedefs = strSql.Substring(0, pos + 1);
................................................................................
   530    546                 finally
   531    547                 {
   532    548                   _buildingSchema = false;
   533    549                 }
   534    550               }
   535    551   #endif
   536    552             }
   537         -          else if (n == 6 || n == 5) // Locked -- delay a small amount before retrying
          553  +          else if (n == SQLiteErrorCode.Locked || n == SQLiteErrorCode.Busy) // Locked -- delay a small amount before retrying
   538    554             {
   539    555               // Keep trying
   540    556               if (rnd == null) // First time we've encountered the lock
   541    557                 rnd = new Random();
   542    558   
   543    559               // If we've exceeded the command's timeout, give up and throw an error
   544    560               if ((uint)Environment.TickCount - starttick > timeoutMS)
................................................................................
   549    565               {
   550    566                 // Otherwise sleep for a random amount of time up to 150ms
   551    567                 System.Threading.Thread.Sleep(rnd.Next(1, 150));
   552    568               }
   553    569             }
   554    570           }
   555    571   
   556         -        if (n > 0) throw new SQLiteException(n, GetLastError());
          572  +        if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
   557    573   
   558    574           strRemain = UTF8ToString(ptr, len);
   559    575   
   560    576           if (stmt != IntPtr.Zero) cmd = new SQLiteStatement(this, flags, new SQLiteStatementHandle(_sql, stmt), strSql.Substring(0, strSql.Length - strRemain.Length), previous);
   561    577   
   562    578           return cmd;
   563    579         }
................................................................................
   568    584       }
   569    585   
   570    586   #if !PLATFORM_COMPACTFRAMEWORK
   571    587       protected static void LogBind(SQLiteStatementHandle handle, int index)
   572    588       {
   573    589           IntPtr handleIntPtr = handle;
   574    590   
   575         -        SQLiteLog.LogMessage(0, String.Format(
          591  +        SQLiteLog.LogMessage(String.Format(
   576    592               "Binding statement {0} paramter #{1} as NULL...",
   577    593               handleIntPtr, index));
   578    594       }
   579    595   
   580    596       protected static void LogBind(SQLiteStatementHandle handle, int index, ValueType value)
   581    597       {
   582    598           IntPtr handleIntPtr = handle;
   583    599   
   584         -        SQLiteLog.LogMessage(0, String.Format(
          600  +        SQLiteLog.LogMessage(String.Format(
   585    601               "Binding statement {0} paramter #{1} as type {2} with value {{{3}}}...",
   586    602               handleIntPtr, index, value.GetType(), value));
   587    603       }
   588    604   
   589    605       private static string FormatDateTime(DateTime value)
   590    606       {
   591    607           StringBuilder result = new StringBuilder();
................................................................................
   599    615           return result.ToString();
   600    616       }
   601    617   
   602    618       protected static void LogBind(SQLiteStatementHandle handle, int index, DateTime value)
   603    619       {
   604    620           IntPtr handleIntPtr = handle;
   605    621   
   606         -        SQLiteLog.LogMessage(0, String.Format(
          622  +        SQLiteLog.LogMessage(String.Format(
   607    623               "Binding statement {0} paramter #{1} as type {2} with value {{{3}}}...",
   608    624               handleIntPtr, index, typeof(DateTime), FormatDateTime(value)));
   609    625       }
   610    626   
   611    627       protected static void LogBind(SQLiteStatementHandle handle, int index, string value)
   612    628       {
   613    629           IntPtr handleIntPtr = handle;
   614    630   
   615         -        SQLiteLog.LogMessage(0, String.Format(
          631  +        SQLiteLog.LogMessage(String.Format(
   616    632               "Binding statement {0} paramter #{1} as type {2} with value {{{3}}}...",
   617    633               handleIntPtr, index, typeof(String), (value != null) ? value : "<null>"));
   618    634       }
   619    635   
   620    636       private static string ToHexadecimalString(
   621    637           byte[] array
   622    638           )
................................................................................
   634    650           return result.ToString();
   635    651       }
   636    652   
   637    653       protected static void LogBind(SQLiteStatementHandle handle, int index, byte[] value)
   638    654       {
   639    655           IntPtr handleIntPtr = handle;
   640    656   
   641         -        SQLiteLog.LogMessage(0, String.Format(
          657  +        SQLiteLog.LogMessage(String.Format(
   642    658               "Binding statement {0} paramter #{1} as type {2} with value {{{3}}}...",
   643    659               handleIntPtr, index, typeof(Byte[]), (value != null) ? ToHexadecimalString(value) : "<null>"));
   644    660       }
   645    661   #endif
   646    662   
   647    663       internal override void Bind_Double(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, double value)
   648    664       {
................................................................................
   650    666   
   651    667   #if !PLATFORM_COMPACTFRAMEWORK
   652    668           if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
   653    669           {
   654    670               LogBind(handle, index, value);
   655    671           }
   656    672   
   657         -        int n = UnsafeNativeMethods.sqlite3_bind_double(handle, index, value);
          673  +        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_double(handle, index, value);
   658    674   #else
   659         -        int n = UnsafeNativeMethods.sqlite3_bind_double_interop(handle, index, ref value);
          675  +        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_double_interop(handle, index, ref value);
   660    676   #endif
   661         -        if (n > 0) throw new SQLiteException(n, GetLastError());
          677  +        if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
   662    678       }
   663    679   
   664    680       internal override void Bind_Int32(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, int value)
   665    681       {
   666    682           SQLiteStatementHandle handle = stmt._sqlite_stmt;
   667    683   
   668    684   #if !PLATFORM_COMPACTFRAMEWORK
   669    685           if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
   670    686           {
   671    687               LogBind(handle, index, value);
   672    688           }
   673    689   #endif
   674    690   
   675         -        int n = UnsafeNativeMethods.sqlite3_bind_int(handle, index, value);
   676         -        if (n > 0) throw new SQLiteException(n, GetLastError());
          691  +        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int(handle, index, value);
          692  +        if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
   677    693       }
   678    694   
   679    695       internal override void Bind_UInt32(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, uint value)
   680    696       {
   681    697           SQLiteStatementHandle handle = stmt._sqlite_stmt;
   682    698   
   683    699   #if !PLATFORM_COMPACTFRAMEWORK
   684    700           if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
   685    701           {
   686    702               LogBind(handle, index, value);
   687    703           }
   688    704   #endif
   689    705   
   690         -        int n = UnsafeNativeMethods.sqlite3_bind_uint(handle, index, value);
   691         -        if (n > 0) throw new SQLiteException(n, GetLastError());
          706  +        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_uint(handle, index, value);
          707  +        if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
   692    708       }
   693    709   
   694    710       internal override void Bind_Int64(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, long value)
   695    711       {
   696    712           SQLiteStatementHandle handle = stmt._sqlite_stmt;
   697    713   
   698    714   #if !PLATFORM_COMPACTFRAMEWORK
   699    715           if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
   700    716           {
   701    717               LogBind(handle, index, value);
   702    718           }
   703    719   
   704         -        int n = UnsafeNativeMethods.sqlite3_bind_int64(handle, index, value);
          720  +        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int64(handle, index, value);
   705    721   #else
   706         -        int n = UnsafeNativeMethods.sqlite3_bind_int64_interop(handle, index, ref value);
          722  +        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int64_interop(handle, index, ref value);
   707    723   #endif
   708         -        if (n > 0) throw new SQLiteException(n, GetLastError());
          724  +        if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
   709    725       }
   710    726   
   711    727       internal override void Bind_UInt64(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, ulong value)
   712    728       {
   713    729           SQLiteStatementHandle handle = stmt._sqlite_stmt;
   714    730   
   715    731   #if !PLATFORM_COMPACTFRAMEWORK
   716    732           if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
   717    733           {
   718    734               LogBind(handle, index, value);
   719    735           }
   720    736   
   721         -        int n = UnsafeNativeMethods.sqlite3_bind_uint64(handle, index, value);
          737  +        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_uint64(handle, index, value);
   722    738   #else
   723         -        int n = UnsafeNativeMethods.sqlite3_bind_uint64_interop(handle, index, ref value);
          739  +        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_uint64_interop(handle, index, ref value);
   724    740   #endif
   725         -        if (n > 0) throw new SQLiteException(n, GetLastError());
          741  +        if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
   726    742       }
   727    743   
   728    744       internal override void Bind_Text(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, string value)
   729    745       {
   730    746           SQLiteStatementHandle handle = stmt._sqlite_stmt;
   731    747   
   732    748   #if !PLATFORM_COMPACTFRAMEWORK
................................................................................
   741    757   #if !PLATFORM_COMPACTFRAMEWORK
   742    758           if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
   743    759           {
   744    760               LogBind(handle, index, b);
   745    761           }
   746    762   #endif
   747    763   
   748         -        int n = UnsafeNativeMethods.sqlite3_bind_text(handle, index, b, b.Length - 1, (IntPtr)(-1));
   749         -        if (n > 0) throw new SQLiteException(n, GetLastError());
          764  +        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_text(handle, index, b, b.Length - 1, (IntPtr)(-1));
          765  +        if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
   750    766       }
   751    767   
   752    768       internal override void Bind_DateTime(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, DateTime dt)
   753    769       {
   754    770           SQLiteStatementHandle handle = stmt._sqlite_stmt;
   755    771   
   756    772   #if !PLATFORM_COMPACTFRAMEWORK
................................................................................
   768    784   
   769    785   #if !PLATFORM_COMPACTFRAMEWORK
   770    786                       if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
   771    787                       {
   772    788                           LogBind(handle, index, value);
   773    789                       }
   774    790   
   775         -                    int n = UnsafeNativeMethods.sqlite3_bind_int64(handle, index, value);
          791  +                    SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int64(handle, index, value);
   776    792   #else
   777         -                    int n = UnsafeNativeMethods.sqlite3_bind_int64_interop(handle, index, ref value);
          793  +                    SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int64_interop(handle, index, ref value);
   778    794   #endif
   779         -                    if (n > 0) throw new SQLiteException(n, GetLastError());
          795  +                    if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
   780    796                       break;
   781    797                   }
   782    798               case SQLiteDateFormats.JulianDay:
   783    799                   {
   784    800                       double value = ToJulianDay(dt);
   785    801   
   786    802   #if !PLATFORM_COMPACTFRAMEWORK
   787    803                       if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
   788    804                       {
   789    805                           LogBind(handle, index, value);
   790    806                       }
   791    807   
   792         -                    int n = UnsafeNativeMethods.sqlite3_bind_double(handle, index, value);
          808  +                    SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_double(handle, index, value);
   793    809   #else
   794         -                    int n = UnsafeNativeMethods.sqlite3_bind_double_interop(handle, index, ref value);
          810  +                    SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_double_interop(handle, index, ref value);
   795    811   #endif
   796         -                    if (n > 0) throw new SQLiteException(n, GetLastError());
          812  +                    if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
   797    813                       break;
   798    814                   }
   799    815               case SQLiteDateFormats.UnixEpoch:
   800    816                   {
   801    817                       long value = Convert.ToInt64(dt.Subtract(UnixEpoch).TotalSeconds);
   802    818   
   803    819   #if !PLATFORM_COMPACTFRAMEWORK
   804    820                       if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
   805    821                       {
   806    822                           LogBind(handle, index, value);
   807    823                       }
   808    824   
   809         -                    int n = UnsafeNativeMethods.sqlite3_bind_int64(handle, index, value);
          825  +                    SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int64(handle, index, value);
   810    826   #else
   811         -                    int n = UnsafeNativeMethods.sqlite3_bind_int64_interop(handle, index, ref value);
          827  +                    SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int64_interop(handle, index, ref value);
   812    828   #endif
   813         -                    if (n > 0) throw new SQLiteException(n, GetLastError());
          829  +                    if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
   814    830                       break;
   815    831                   }
   816    832               default:
   817    833                   {
   818    834                       byte[] b = ToUTF8(dt);
   819    835   
   820    836   #if !PLATFORM_COMPACTFRAMEWORK
   821    837                       if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
   822    838                       {
   823    839                           LogBind(handle, index, b);
   824    840                       }
   825    841   #endif
   826    842   
   827         -                    int n = UnsafeNativeMethods.sqlite3_bind_text(handle, index, b, b.Length - 1, (IntPtr)(-1));
   828         -                    if (n > 0) throw new SQLiteException(n, GetLastError());
          843  +                    SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_text(handle, index, b, b.Length - 1, (IntPtr)(-1));
          844  +                    if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
   829    845                       break;
   830    846                   }
   831    847           }
   832    848       }
   833    849   
   834    850       internal override void Bind_Blob(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, byte[] blobData)
   835    851       {
................................................................................
   838    854   #if !PLATFORM_COMPACTFRAMEWORK
   839    855           if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
   840    856           {
   841    857               LogBind(handle, index, blobData);
   842    858           }
   843    859   #endif
   844    860   
   845         -        int n = UnsafeNativeMethods.sqlite3_bind_blob(handle, index, blobData, blobData.Length, (IntPtr)(-1));
   846         -        if (n > 0) throw new SQLiteException(n, GetLastError());
          861  +        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_blob(handle, index, blobData, blobData.Length, (IntPtr)(-1));
          862  +        if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
   847    863       }
   848    864   
   849    865       internal override void Bind_Null(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index)
   850    866       {
   851    867           SQLiteStatementHandle handle = stmt._sqlite_stmt;
   852    868   
   853    869   #if !PLATFORM_COMPACTFRAMEWORK
   854    870           if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
   855    871           {
   856    872               LogBind(handle, index);
   857    873           }
   858    874   #endif
   859    875   
   860         -        int n = UnsafeNativeMethods.sqlite3_bind_null(handle, index);
   861         -        if (n > 0) throw new SQLiteException(n, GetLastError());
          876  +        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_null(handle, index);
          877  +        if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
   862    878       }
   863    879   
   864    880       internal override int Bind_ParamCount(SQLiteStatement stmt, SQLiteConnectionFlags flags)
   865    881       {
   866    882           SQLiteStatementHandle handle = stmt._sqlite_stmt;
   867    883           int value = UnsafeNativeMethods.sqlite3_bind_parameter_count(handle);
   868    884   
   869    885   #if !PLATFORM_COMPACTFRAMEWORK
   870    886           if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
   871    887           {
   872    888               IntPtr handleIntPtr = handle;
   873    889   
   874         -            SQLiteLog.LogMessage(0, String.Format(
          890  +            SQLiteLog.LogMessage(String.Format(
   875    891                   "Statement {0} paramter count is {1}.",
   876    892                   handleIntPtr, value));
   877    893           }
   878    894   #endif
   879    895   
   880    896           return value;
   881    897       }
................................................................................
   893    909   #endif
   894    910   
   895    911   #if !PLATFORM_COMPACTFRAMEWORK
   896    912           if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
   897    913           {
   898    914               IntPtr handleIntPtr = handle;
   899    915   
   900         -            SQLiteLog.LogMessage(0, String.Format(
          916  +            SQLiteLog.LogMessage(String.Format(
   901    917                   "Statement {0} paramter #{1} name is {{{2}}}.",
   902    918                   handleIntPtr, index, name));
   903    919           }
   904    920   #endif
   905    921   
   906    922           return name;
   907    923       }
................................................................................
   912    928           int index = UnsafeNativeMethods.sqlite3_bind_parameter_index(handle, ToUTF8(paramName));
   913    929   
   914    930   #if !PLATFORM_COMPACTFRAMEWORK
   915    931           if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
   916    932           {
   917    933               IntPtr handleIntPtr = handle;
   918    934   
   919         -            SQLiteLog.LogMessage(0, String.Format(
          935  +            SQLiteLog.LogMessage(String.Format(
   920    936                   "Statement {0} paramter index of name {{{1}}} is #{2}.",
   921    937                   handleIntPtr, paramName, index));
   922    938           }
   923    939   #endif
   924    940   
   925    941           return index;
   926    942       }
................................................................................
  1026   1042       internal override void ColumnMetaData(string dataBase, string table, string column, out string dataType, out string collateSequence, out bool notNull, out bool primaryKey, out bool autoIncrement)
  1027   1043       {
  1028   1044         IntPtr dataTypePtr;
  1029   1045         IntPtr collSeqPtr;
  1030   1046         int nnotNull;
  1031   1047         int nprimaryKey;
  1032   1048         int nautoInc;
  1033         -      int n;
         1049  +      SQLiteErrorCode n;
  1034   1050         int dtLen;
  1035   1051         int csLen;
  1036   1052   
  1037   1053   #if !SQLITE_STANDARD
  1038   1054         n = UnsafeNativeMethods.sqlite3_table_column_metadata_interop(_sql, ToUTF8(dataBase), ToUTF8(table), ToUTF8(column), out dataTypePtr, out collSeqPtr, out nnotNull, out nprimaryKey, out nautoInc, out dtLen, out csLen);
  1039   1055   #else
  1040   1056         dtLen = -1;
  1041   1057         csLen = -1;
  1042   1058   
  1043   1059         n = UnsafeNativeMethods.sqlite3_table_column_metadata(_sql, ToUTF8(dataBase), ToUTF8(table), ToUTF8(column), out dataTypePtr, out collSeqPtr, out nnotNull, out nprimaryKey, out nautoInc);
  1044   1060   #endif
  1045         -      if (n > 0) throw new SQLiteException(n, GetLastError());
         1061  +      if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1046   1062   
  1047   1063         dataType = UTF8ToString(dataTypePtr, dtLen);
  1048   1064         collateSequence = UTF8ToString(collSeqPtr, csLen);
  1049   1065   
  1050   1066         notNull = (nnotNull == 1);
  1051   1067         primaryKey = (nprimaryKey == 1);
  1052   1068         autoIncrement = (nautoInc == 1);
................................................................................
  1153   1169       internal override int AggregateCount(IntPtr context)
  1154   1170       {
  1155   1171         return UnsafeNativeMethods.sqlite3_aggregate_count(context);
  1156   1172       }
  1157   1173   
  1158   1174       internal override void CreateFunction(string strFunction, int nArgs, bool needCollSeq, SQLiteCallback func, SQLiteCallback funcstep, SQLiteFinalCallback funcfinal)
  1159   1175       {
  1160         -      int n;
         1176  +      SQLiteErrorCode n;
  1161   1177   
  1162   1178   #if !SQLITE_STANDARD
  1163   1179         n = UnsafeNativeMethods.sqlite3_create_function_interop(_sql, ToUTF8(strFunction), nArgs, 4, IntPtr.Zero, func, funcstep, funcfinal, (needCollSeq == true) ? 1 : 0);
  1164         -      if (n == 0) n = UnsafeNativeMethods.sqlite3_create_function_interop(_sql, ToUTF8(strFunction), nArgs, 1, IntPtr.Zero, func, funcstep, funcfinal, (needCollSeq == true) ? 1 : 0);
         1180  +      if (n == SQLiteErrorCode.Ok) n = UnsafeNativeMethods.sqlite3_create_function_interop(_sql, ToUTF8(strFunction), nArgs, 1, IntPtr.Zero, func, funcstep, funcfinal, (needCollSeq == true) ? 1 : 0);
  1165   1181   #else
  1166   1182         n = UnsafeNativeMethods.sqlite3_create_function(_sql, ToUTF8(strFunction), nArgs, 4, IntPtr.Zero, func, funcstep, funcfinal);
  1167         -      if (n == 0) n = UnsafeNativeMethods.sqlite3_create_function(_sql, ToUTF8(strFunction), nArgs, 1, IntPtr.Zero, func, funcstep, funcfinal);
         1183  +      if (n == SQLiteErrorCode.Ok) n = UnsafeNativeMethods.sqlite3_create_function(_sql, ToUTF8(strFunction), nArgs, 1, IntPtr.Zero, func, funcstep, funcfinal);
  1168   1184   #endif
  1169         -      if (n > 0) throw new SQLiteException(n, GetLastError());
         1185  +      if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1170   1186       }
  1171   1187   
  1172   1188       internal override void CreateCollation(string strCollation, SQLiteCollation func, SQLiteCollation func16)
  1173   1189       {
  1174         -      int n = UnsafeNativeMethods.sqlite3_create_collation(_sql, ToUTF8(strCollation), 2, IntPtr.Zero, func16);
  1175         -      if (n == 0) n = UnsafeNativeMethods.sqlite3_create_collation(_sql, ToUTF8(strCollation), 1, IntPtr.Zero, func);
  1176         -      if (n > 0) throw new SQLiteException(n, GetLastError());
         1190  +      SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_create_collation(_sql, ToUTF8(strCollation), 2, IntPtr.Zero, func16);
         1191  +      if (n == SQLiteErrorCode.Ok) n = UnsafeNativeMethods.sqlite3_create_collation(_sql, ToUTF8(strCollation), 1, IntPtr.Zero, func);
         1192  +      if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1177   1193       }
  1178   1194   
  1179   1195       internal override int ContextCollateCompare(CollationEncodingEnum enc, IntPtr context, string s1, string s2)
  1180   1196       {
  1181   1197   #if !SQLITE_STANDARD
  1182   1198         byte[] b1;
  1183   1199         byte[] b2;
................................................................................
  1373   1389   
  1374   1390       /// Enables or disabled extended result codes returned by SQLite
  1375   1391       internal override void SetExtendedResultCodes(bool bOnOff)
  1376   1392       {
  1377   1393         UnsafeNativeMethods.sqlite3_extended_result_codes(_sql, (bOnOff ? -1 : 0));
  1378   1394       }
  1379   1395       /// Gets the last SQLite error code
  1380         -    internal override int ResultCode()
         1396  +    internal override SQLiteErrorCode ResultCode()
  1381   1397       {
  1382   1398         return UnsafeNativeMethods.sqlite3_errcode(_sql);
  1383   1399       }
  1384   1400       /// Gets the last SQLite extended error code
  1385         -    internal override int ExtendedResultCode()
         1401  +    internal override SQLiteErrorCode ExtendedResultCode()
  1386   1402       {
  1387   1403         return UnsafeNativeMethods.sqlite3_extended_errcode(_sql);
  1388   1404       }
  1389   1405   
  1390   1406       /// Add a log message via the SQLite sqlite3_log interface.
  1391   1407       internal override void LogMessage(int iErrCode, string zMessage)
  1392   1408       {
  1393   1409         UnsafeNativeMethods.sqlite3_log(iErrCode, ToUTF8(zMessage));
  1394   1410       }
  1395   1411   
  1396   1412   #if INTEROP_CODEC
  1397   1413       internal override void SetPassword(byte[] passwordBytes)
  1398   1414       {
  1399         -      int n = UnsafeNativeMethods.sqlite3_key(_sql, passwordBytes, passwordBytes.Length);
  1400         -      if (n > 0) throw new SQLiteException(n, GetLastError());
         1415  +      SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_key(_sql, passwordBytes, passwordBytes.Length);
         1416  +      if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1401   1417       }
  1402   1418   
  1403   1419       internal override void ChangePassword(byte[] newPasswordBytes)
  1404   1420       {
  1405         -      int n = UnsafeNativeMethods.sqlite3_rekey(_sql, newPasswordBytes, (newPasswordBytes == null) ? 0 : newPasswordBytes.Length);
  1406         -      if (n > 0) throw new SQLiteException(n, GetLastError());
         1421  +      SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_rekey(_sql, newPasswordBytes, (newPasswordBytes == null) ? 0 : newPasswordBytes.Length);
         1422  +      if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1407   1423       }
  1408   1424   #endif
  1409   1425   
  1410   1426       internal override void SetUpdateHook(SQLiteUpdateCallback func)
  1411   1427       {
  1412   1428         UnsafeNativeMethods.sqlite3_update_hook(_sql, func, IntPtr.Zero);
  1413   1429       }
................................................................................
  1430   1446       /// <summary>
  1431   1447       /// Allows the setting of a logging callback invoked by SQLite when a
  1432   1448       /// log event occurs.  Only one callback may be set.  If NULL is passed,
  1433   1449       /// the logging callback is unregistered.
  1434   1450       /// </summary>
  1435   1451       /// <param name="func">The callback function to invoke.</param>
  1436   1452       /// <returns>Returns a result code</returns>
  1437         -    internal override int SetLogCallback(SQLiteLogCallback func)
         1453  +    internal override SQLiteErrorCode SetLogCallback(SQLiteLogCallback func)
  1438   1454       {
  1439         -        int rc = UnsafeNativeMethods.sqlite3_config_log(
  1440         -            SQLiteConfigOpsEnum.SQLITE_CONFIG_LOG, func, (IntPtr)0);
         1455  +        SQLiteErrorCode rc = UnsafeNativeMethods.sqlite3_config_log(
         1456  +            SQLiteConfigOpsEnum.SQLITE_CONFIG_LOG, func, IntPtr.Zero);
  1441   1457   
  1442   1458           return rc;
  1443   1459       }
  1444   1460   
  1445   1461       ///////////////////////////////////////////////////////////////////////////////////////////////
  1446   1462   
  1447   1463       /// <summary>
................................................................................
  1537   1553   
  1538   1554           IntPtr handlePtr = handle;
  1539   1555   
  1540   1556           if (handlePtr == IntPtr.Zero)
  1541   1557               throw new InvalidOperationException(
  1542   1558                   "Backup object has an invalid handle pointer.");
  1543   1559   
  1544         -        int n = UnsafeNativeMethods.sqlite3_backup_step(handlePtr, nPage);
         1560  +        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_backup_step(handlePtr, nPage);
  1545   1561           backup._stepResult = n; /* NOTE: Save for use by FinishBackup. */
  1546   1562   
  1547         -        if (n == (int)SQLiteErrorCode.Ok)
         1563  +        if (n == SQLiteErrorCode.Ok)
         1564  +        {
         1565  +            return true;
         1566  +        }
         1567  +        else if (n == SQLiteErrorCode.Busy)
  1548   1568           {
         1569  +            retry = true;
  1549   1570               return true;
  1550   1571           }
  1551         -        else if (n == (int)SQLiteErrorCode.Busy)
         1572  +        else if (n == SQLiteErrorCode.Locked)
  1552   1573           {
  1553   1574               retry = true;
  1554   1575               return true;
  1555   1576           }
  1556         -        else if (n == (int)SQLiteErrorCode.Locked)
  1557         -        {
  1558         -            retry = true;
  1559         -            return true;
  1560         -        }
  1561         -        else if (n == (int)SQLiteErrorCode.Done)
         1577  +        else if (n == SQLiteErrorCode.Done)
  1562   1578           {
  1563   1579               return false;
  1564   1580           }
  1565   1581           else
  1566   1582           {
  1567   1583               throw new SQLiteException(n, GetLastError());
  1568   1584           }
................................................................................
  1645   1661   
  1646   1662           IntPtr handlePtr = handle;
  1647   1663   
  1648   1664           if (handlePtr == IntPtr.Zero)
  1649   1665               throw new InvalidOperationException(
  1650   1666                   "Backup object has an invalid handle pointer.");
  1651   1667   
  1652         -        int n = UnsafeNativeMethods.sqlite3_backup_finish(handlePtr);
         1668  +        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_backup_finish(handlePtr);
  1653   1669           handle.SetHandleAsInvalid();
  1654   1670   
  1655         -        if ((n > 0) && (n != backup._stepResult))
         1671  +        if ((n != SQLiteErrorCode.Ok) && (n != backup._stepResult))
  1656   1672               throw new SQLiteException(n, GetLastError());
  1657   1673       }
  1658   1674   
  1659   1675       ///////////////////////////////////////////////////////////////////////////////////////////////
  1660   1676   
  1661   1677       /// <summary>
  1662   1678       /// Determines if the SQLite core library has been initialized for the
................................................................................
  1700   1716   #endif
  1701   1717                   //
  1702   1718                   // NOTE: This method [ab]uses the fact that SQLite will always
  1703   1719                   //       return SQLITE_ERROR for any unknown configuration option
  1704   1720                   //       *unless* the SQLite library has already been initialized.
  1705   1721                   //       In that case it will always return SQLITE_MISUSE.
  1706   1722                   //
  1707         -                int rc = UnsafeNativeMethods.sqlite3_config_none(
         1723  +                SQLiteErrorCode rc = UnsafeNativeMethods.sqlite3_config_none(
  1708   1724                       SQLiteConfigOpsEnum.SQLITE_CONFIG_NONE);
  1709   1725   
  1710         -                return (rc == /* SQLITE_MISUSE */ 21);
         1726  +                return (rc == SQLiteErrorCode.Misuse);
  1711   1727   #if !PLATFORM_COMPACTFRAMEWORK
  1712   1728               }
  1713   1729               finally
  1714   1730               {
  1715   1731                   SQLiteLog.Enabled = savedEnabled;
  1716   1732               }
  1717   1733   #endif
................................................................................
  1775   1791   #endif
  1776   1792       }
  1777   1793   
  1778   1794       internal override long GetRowIdForCursor(SQLiteStatement stmt, int cursor)
  1779   1795       {
  1780   1796   #if !SQLITE_STANDARD
  1781   1797         long rowid;
  1782         -      int rc = UnsafeNativeMethods.sqlite3_cursor_rowid(stmt._sqlite_stmt, cursor, out rowid);
  1783         -      if (rc == 0) return rowid;
         1798  +      SQLiteErrorCode rc = UnsafeNativeMethods.sqlite3_cursor_rowid(stmt._sqlite_stmt, cursor, out rowid);
         1799  +      if (rc == SQLiteErrorCode.Ok) return rowid;
  1784   1800   
  1785   1801         return 0;
  1786   1802   #else
  1787   1803         return 0;
  1788   1804   #endif
  1789   1805       }
  1790   1806   
  1791   1807       internal override void GetIndexColumnExtendedInfo(string database, string index, string column, out int sortMode, out int onError, out string collationSequence)
  1792   1808       {
  1793   1809   #if !SQLITE_STANDARD
  1794   1810         IntPtr coll;
  1795   1811         int colllen;
  1796         -      int rc;
         1812  +      SQLiteErrorCode rc;
  1797   1813   
  1798   1814         rc = UnsafeNativeMethods.sqlite3_index_column_info_interop(_sql, ToUTF8(database), ToUTF8(index), ToUTF8(column), out sortMode, out onError, out coll, out colllen);
  1799         -      if (rc != 0) throw new SQLiteException(rc, "");
         1815  +      if (rc != SQLiteErrorCode.Ok) throw new SQLiteException(rc, null);
  1800   1816   
  1801   1817         collationSequence = UTF8ToString(coll, colllen);
  1802   1818   #else
  1803   1819         sortMode = 0;
  1804   1820         onError = 2;
  1805   1821         collationSequence = "BINARY";
  1806   1822   #endif
  1807   1823       }
  1808   1824   
  1809         -    internal override int FileControl(string zDbName, int op, IntPtr pArg)
         1825  +    internal override SQLiteErrorCode FileControl(string zDbName, int op, IntPtr pArg)
  1810   1826       {
  1811   1827         return UnsafeNativeMethods.sqlite3_file_control(_sql, (zDbName != null) ? ToUTF8(zDbName) : null, op, pArg);
  1812   1828       }
  1813   1829     }
  1814   1830   }

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

   107    107         }
   108    108   
   109    109         if (_sql == null)
   110    110         {
   111    111           IntPtr db;
   112    112   
   113    113   #if !SQLITE_STANDARD
   114         -        int n = UnsafeNativeMethods.sqlite3_open16_interop(ToUTF8(strFilename), (int)openFlags, out db);
          114  +        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_open16_interop(ToUTF8(strFilename), (int)openFlags, out db);
   115    115   #else
   116    116           if ((openFlags & SQLiteOpenFlagsEnum.Create) == 0 && System.IO.File.Exists(strFilename) == false)
   117    117             throw new SQLiteException((int)SQLiteErrorCode.CantOpen, strFilename);
   118    118   
   119         -        int n = UnsafeNativeMethods.sqlite3_open16(strFilename, out db);
          119  +        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_open16(strFilename, out db);
   120    120   #endif
   121    121   
   122    122   #if !NET_COMPACT_20 && TRACE_CONNECTION
   123    123           Trace.WriteLine(String.Format("Open: {0}", db));
   124    124   #endif
   125    125   
   126         -        if (n > 0) throw new SQLiteException(n, null);
          126  +        if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, null);
   127    127   
   128    128           _sql = new SQLiteConnectionHandle(db);
   129    129           lock (_sql) { /* HACK: Force the SyncBlock to be "created" now. */ }
   130    130         }
   131    131         _functionsArray = SQLiteFunction.BindFunctions(this, connectionFlags);
   132    132         SetTimeout(0);
   133    133         GC.KeepAlive(_sql);
................................................................................
   169    169   #if !PLATFORM_COMPACTFRAMEWORK
   170    170           if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
   171    171           {
   172    172               LogBind(handle, index, value);
   173    173           }
   174    174   #endif
   175    175   
   176         -        int n = UnsafeNativeMethods.sqlite3_bind_text16(handle, index, value, value.Length * 2, (IntPtr)(-1));
   177         -        if (n > 0) throw new SQLiteException(n, GetLastError());
          176  +        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_text16(handle, index, value, value.Length * 2, (IntPtr)(-1));
          177  +        if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
   178    178       }
   179    179   
   180    180       internal override DateTime GetDateTime(SQLiteStatement stmt, int index)
   181    181       {
   182    182         return ToDateTime(GetText(stmt, index));
   183    183       }
   184    184   

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

    46     46   
    47     47           /// <summary>
    48     48           /// The last result from the StepBackup method of the SQLite3 class.
    49     49           /// This is used to determine if the call to the FinishBackup method of
    50     50           /// the SQLite3 class should throw an exception when it receives a non-Ok
    51     51           /// return code from the core SQLite library.
    52     52           /// </summary>
    53         -        internal int _stepResult;
           53  +        internal SQLiteErrorCode _stepResult;
    54     54   
    55     55           /// <summary>
    56     56           /// Initializes the backup.
    57     57           /// </summary>
    58     58           /// <param name="sqlbase">The base SQLite object.</param>
    59     59           /// <param name="backup">The backup handle.</param>
    60     60           /// <param name="destDb">The destination database for the backup.</param>

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

     4      4    * 
     5      5    * Released to the public domain, use at your own risk!
     6      6    ********************************************************/
     7      7   
     8      8   namespace System.Data.SQLite
     9      9   {
    10     10     using System;
           11  +  // using System.Runtime.InteropServices;
    11     12   
    12     13     /// <summary>
    13     14     /// This internal class provides the foundation of SQLite support.  It defines all the abstract members needed to implement
    14     15     /// a SQLite data provider, and inherits from SQLiteConvert which allows for simple translations of string to and from SQLite.
    15     16     /// </summary>
    16     17     internal abstract class SQLiteBase : SQLiteConvert, IDisposable
    17     18     {
................................................................................
    43     44       /// <summary>
    44     45       /// Sets the status of the memory usage tracking subsystem in the SQLite core library.  By default, this is enabled.
    45     46       /// If this is disabled, memory usage tracking will not be performed.  This is not really a per-connection value, it is
    46     47       /// global to the process.
    47     48       /// </summary>
    48     49       /// <param name="value">Non-zero to enable memory usage tracking, zero otherwise.</param>
    49     50       /// <returns>A standard SQLite return code (i.e. zero for success and non-zero for failure).</returns>
    50         -    internal abstract int SetMemoryStatus(bool value);
           51  +    internal abstract SQLiteErrorCode SetMemoryStatus(bool value);
    51     52       /// <summary>
    52     53       /// Shutdown the SQLite engine so that it can be restarted with different config options.
    53     54       /// We depend on auto initialization to recover.
    54     55       /// </summary>
    55         -    internal abstract int Shutdown();
           56  +    internal abstract SQLiteErrorCode Shutdown();
    56     57       /// <summary>
    57     58       /// Returns non-zero if a database connection is open.
    58     59       /// </summary>
    59     60       /// <returns></returns>
    60     61       internal abstract bool IsOpen();
    61     62       /// <summary>
    62     63       /// Opens a database.
................................................................................
   121    122       internal abstract bool Step(SQLiteStatement stmt);
   122    123       /// <summary>
   123    124       /// Resets a prepared statement so it can be executed again.  If the error returned is SQLITE_SCHEMA, 
   124    125       /// transparently attempt to rebuild the SQL statement and throw an error if that was not possible.
   125    126       /// </summary>
   126    127       /// <param name="stmt">The statement to reset</param>
   127    128       /// <returns>Returns -1 if the schema changed while resetting, 0 if the reset was sucessful or 6 (SQLITE_LOCKED) if the reset failed due to a lock</returns>
   128         -    internal abstract int Reset(SQLiteStatement stmt);
          129  +    internal abstract SQLiteErrorCode Reset(SQLiteStatement stmt);
   129    130       internal abstract void Cancel();
   130    131   
   131    132       internal abstract void Bind_Double(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, double value);
   132    133       internal abstract void Bind_Int32(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, Int32 value);
   133    134       internal abstract void Bind_UInt32(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, UInt32 value);
   134    135       internal abstract void Bind_Int64(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, Int64 value);
   135    136       internal abstract void Bind_UInt64(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, UInt64 value);
................................................................................
   193    194       /// <returns></returns>
   194    195       internal abstract void SetExtendedResultCodes(bool bOnOff);
   195    196       /// <summary>
   196    197       /// Returns the numeric result code for the most recent failed SQLite API call 
   197    198       /// associated with the database connection. 
   198    199       /// </summary>
   199    200       /// <returns>Result code</returns>
   200         -    internal abstract int ResultCode();
          201  +    internal abstract SQLiteErrorCode ResultCode();
   201    202       /// <summary>
   202    203       /// Returns the extended numeric result code for the most recent failed SQLite API call 
   203    204       /// associated with the database connection. 
   204    205       /// </summary>
   205    206       /// <returns>Extended result code</returns>
   206         -    internal abstract int ExtendedResultCode();
          207  +    internal abstract SQLiteErrorCode ExtendedResultCode();
   207    208   
   208    209       /// <summary>
   209    210       /// Add a log message via the SQLite sqlite3_log interface.
   210    211       /// </summary>
   211    212       /// <param name="iErrCode">Error code to be logged with the message.</param>
   212    213       /// <param name="zMessage">String to be logged.  Unlike the SQLite sqlite3_log() 
   213    214       /// interface, this should be pre-formatted.  Consider using the 
................................................................................
   220    221       internal abstract void ChangePassword(byte[] newPasswordBytes);
   221    222   #endif
   222    223   
   223    224       internal abstract void SetUpdateHook(SQLiteUpdateCallback func);
   224    225       internal abstract void SetCommitHook(SQLiteCommitCallback func);
   225    226       internal abstract void SetTraceCallback(SQLiteTraceCallback func);
   226    227       internal abstract void SetRollbackHook(SQLiteRollbackCallback func);
   227         -    internal abstract int SetLogCallback(SQLiteLogCallback func);
          228  +    internal abstract SQLiteErrorCode SetLogCallback(SQLiteLogCallback func);
   228    229   
   229    230       /// <summary>
   230    231       /// Checks if the SQLite core library has been initialized in the current process.
   231    232       /// </summary>
   232    233       /// <returns>
   233    234       /// Non-zero if the SQLite core library has been initialized in the current process,
   234    235       /// zero otherwise.
................................................................................
   241    242       internal abstract object GetValue(SQLiteStatement stmt, int index, SQLiteType typ);
   242    243   
   243    244       internal abstract bool AutoCommit
   244    245       {
   245    246         get;
   246    247       }
   247    248   
   248         -    internal abstract int FileControl(string zDbName, int op, IntPtr pArg);
          249  +    internal abstract SQLiteErrorCode FileControl(string zDbName, int op, IntPtr pArg);
   249    250   
   250    251       /// <summary>
   251    252       /// Creates a new SQLite backup object based on the provided destination
   252    253       /// database connection.  The source database connection is the one
   253    254       /// associated with this object.  The source and destination database
   254    255       /// connections cannot be the same.
   255    256       /// </summary>
................................................................................
   357    358   
   358    359       ///////////////////////////////////////////////////////////////////////////////////////////////
   359    360   
   360    361       // These statics are here for lack of a better place to put them.
   361    362       // They exist here because they are called during the finalization of
   362    363       // a SQLiteStatementHandle, SQLiteConnectionHandle, and SQLiteFunctionCookieHandle.
   363    364       // Therefore these functions have to be static, and have to be low-level.
          365  +
          366  +    ///////////////////////////////////////////////////////////////////////////////////////////////
          367  +
          368  +    private static string[] _errorMessages = {
          369  +        /* SQLITE_OK          */ "not an error",
          370  +        /* SQLITE_ERROR       */ "SQL logic error or missing database",
          371  +        /* SQLITE_INTERNAL    */ "internal logic error",
          372  +        /* SQLITE_PERM        */ "access permission denied",
          373  +        /* SQLITE_ABORT       */ "callback requested query abort",
          374  +        /* SQLITE_BUSY        */ "database is locked",
          375  +        /* SQLITE_LOCKED      */ "database table is locked",
          376  +        /* SQLITE_NOMEM       */ "out of memory",
          377  +        /* SQLITE_READONLY    */ "attempt to write a readonly database",
          378  +        /* SQLITE_INTERRUPT   */ "interrupted",
          379  +        /* SQLITE_IOERR       */ "disk I/O error",
          380  +        /* SQLITE_CORRUPT     */ "database disk image is malformed",
          381  +        /* SQLITE_NOTFOUND    */ "unknown operation",
          382  +        /* SQLITE_FULL        */ "database or disk is full",
          383  +        /* SQLITE_CANTOPEN    */ "unable to open database file",
          384  +        /* SQLITE_PROTOCOL    */ "locking protocol",
          385  +        /* SQLITE_EMPTY       */ "table contains no data",
          386  +        /* SQLITE_SCHEMA      */ "database schema has changed",
          387  +        /* SQLITE_TOOBIG      */ "string or blob too big",
          388  +        /* SQLITE_CONSTRAINT  */ "constraint failed",
          389  +        /* SQLITE_MISMATCH    */ "datatype mismatch",
          390  +        /* SQLITE_MISUSE      */ "library routine called out of sequence",
          391  +        /* SQLITE_NOLFS       */ "large file support is disabled",
          392  +        /* SQLITE_AUTH        */ "authorization denied",
          393  +        /* SQLITE_FORMAT      */ "auxiliary database format error",
          394  +        /* SQLITE_RANGE       */ "bind or column index out of range",
          395  +        /* SQLITE_NOTADB      */ "file is encrypted or is not a database",
          396  +    };
          397  +
          398  +    ///////////////////////////////////////////////////////////////////////////////////////////////
          399  +
          400  +    private static string FallbackGetErrorString(SQLiteErrorCode rc)
          401  +    {
          402  +        if (_errorMessages == null)
          403  +            return null;
          404  +
          405  +        int index = (int)rc;
          406  +
          407  +        if ((index < 0) || (index >= _errorMessages.Length))
          408  +            index = (int)SQLiteErrorCode.Error; /* Make into generic error. */
          409  +
          410  +        return _errorMessages[index];
          411  +    }
          412  +
          413  +    internal static string GetErrorString(SQLiteErrorCode rc)
          414  +    {
          415  +        //try
          416  +        //{
          417  +        //    IntPtr ptr = UnsafeNativeMethods.sqlite3_errstr(rc);
          418  +        //
          419  +        //    if (ptr != IntPtr.Zero)
          420  +        //        return Marshal.PtrToStringAnsi(ptr);
          421  +        //}
          422  +        //catch (EntryPointNotFoundException)
          423  +        //{
          424  +        //    // do nothing.
          425  +        //}
          426  +
          427  +        return FallbackGetErrorString(rc);
          428  +    }
   364    429   
   365    430       internal static string GetLastError(SQLiteConnectionHandle hdl, IntPtr db)
   366    431       {
   367    432           if ((hdl == null) || (db == IntPtr.Zero))
   368    433               return "null connection or database handle";
   369    434   
   370    435           lock (hdl)
................................................................................
   386    451       }
   387    452   
   388    453       internal static void FinishBackup(SQLiteConnectionHandle hdl, IntPtr backup)
   389    454       {
   390    455           if ((hdl == null) || (backup == IntPtr.Zero)) return;
   391    456           lock (hdl)
   392    457           {
   393         -            int n = UnsafeNativeMethods.sqlite3_backup_finish(backup);
   394         -            if (n > 0) throw new SQLiteException(n, null);
          458  +            SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_backup_finish(backup);
          459  +            if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, null);
   395    460           }
   396    461       }
   397    462   
   398    463       internal static void FinalizeStatement(SQLiteConnectionHandle hdl, IntPtr stmt)
   399    464       {
   400    465           if ((hdl == null) || (stmt == IntPtr.Zero)) return;
   401    466           lock (hdl)
   402    467           {
   403    468   #if !SQLITE_STANDARD
   404         -            int n = UnsafeNativeMethods.sqlite3_finalize_interop(stmt);
          469  +            SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_finalize_interop(stmt);
   405    470   #else
   406         -            int n = UnsafeNativeMethods.sqlite3_finalize(stmt);
          471  +            SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_finalize(stmt);
   407    472   #endif
   408         -            if (n > 0) throw new SQLiteException(n, null);
          473  +            if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, null);
   409    474           }
   410    475       }
   411    476   
   412    477       internal static void CloseConnection(SQLiteConnectionHandle hdl, IntPtr db)
   413    478       {
   414    479           if ((hdl == null) || (db == IntPtr.Zero)) return;
   415    480           lock (hdl)
   416    481           {
   417    482   #if !SQLITE_STANDARD
   418         -            int n = UnsafeNativeMethods.sqlite3_close_interop(db);
          483  +            SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_close_interop(db);
   419    484   #else
   420    485               ResetConnection(hdl, db);
   421    486   
   422         -            int n;
          487  +            SQLiteErrorCode n;
   423    488   
   424    489               try
   425    490               {
   426    491                   n = UnsafeNativeMethods.sqlite3_close_v2(db);
   427    492               }
   428    493               catch (EntryPointNotFoundException)
   429    494               {
   430    495                   n = UnsafeNativeMethods.sqlite3_close(db);
   431    496               }
   432    497   #endif
   433         -            if (n > 0) throw new SQLiteException(n, GetLastError(hdl, db));
          498  +            if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError(hdl, db));
   434    499           }
   435    500       }
   436    501   
   437    502       internal static void ResetConnection(SQLiteConnectionHandle hdl, IntPtr db)
   438    503       {
   439    504           if ((hdl == null) || (db == IntPtr.Zero)) return;
   440    505           if (hdl.IsClosed || hdl.IsInvalid) return;
   441    506           lock (hdl)
   442    507           {
   443    508               IntPtr stmt = IntPtr.Zero;
   444         -            int n;
          509  +            SQLiteErrorCode n;
   445    510               do
   446    511               {
   447    512                   stmt = UnsafeNativeMethods.sqlite3_next_stmt(db, stmt);
   448    513                   if (stmt != IntPtr.Zero)
   449    514                   {
   450    515   #if !SQLITE_STANDARD
   451    516                       n = UnsafeNativeMethods.sqlite3_reset_interop(stmt);
................................................................................
   454    519   #endif
   455    520                   }
   456    521               } while (stmt != IntPtr.Zero);
   457    522   
   458    523               if (IsAutocommit(hdl, db) == false) // a transaction is pending on the connection
   459    524               {
   460    525                   n = UnsafeNativeMethods.sqlite3_exec(db, ToUTF8("ROLLBACK"), IntPtr.Zero, IntPtr.Zero, out stmt);
   461         -                if (n > 0) throw new SQLiteException(n, GetLastError(hdl, db));
          526  +                if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError(hdl, db));
   462    527               }
   463    528           }
   464    529           GC.KeepAlive(hdl);
   465    530       }
   466    531   
   467    532       internal static bool IsAutocommit(SQLiteConnectionHandle hdl, IntPtr db)
   468    533       {

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

   486    486               }
   487    487           }
   488    488   #if !PLATFORM_COMPACTFRAMEWORK
   489    489           catch (Exception e)
   490    490           {
   491    491               if ((_flags & SQLiteConnectionFlags.LogBackup) == SQLiteConnectionFlags.LogBackup)
   492    492               {
   493         -                SQLiteLog.LogMessage(0, String.Format(
          493  +                SQLiteLog.LogMessage(String.Format(
   494    494                       CultureInfo.CurrentCulture,
   495    495                       "Caught exception while backing up database: {0}", e));
   496    496               }
   497    497   
   498    498               throw;
   499    499           }
   500    500   #endif
................................................................................
  1535   1535       /// <summary>
  1536   1536       /// Sets the status of the memory usage tracking subsystem in the SQLite core library.  By default, this is enabled.
  1537   1537       /// If this is disabled, memory usage tracking will not be performed.  This is not really a per-connection value, it is
  1538   1538       /// global to the process.
  1539   1539       /// </summary>
  1540   1540       /// <param name="value">Non-zero to enable memory usage tracking, zero otherwise.</param>
  1541   1541       /// <returns>A standard SQLite return code (i.e. zero for success and non-zero for failure).</returns>
  1542         -    public static int SetMemoryStatus(bool value)
         1542  +    public static SQLiteErrorCode SetMemoryStatus(bool value)
  1543   1543       {
  1544   1544           return SQLite3.StaticSetMemoryStatus(value);
  1545   1545       }
  1546   1546   
  1547   1547       /// <summary>
  1548   1548       /// Returns a string containing the define constants (i.e. compile-time
  1549   1549       /// options) used to compile the core managed assembly, delimited with
................................................................................
  1584   1584         {
  1585   1585           CheckDisposed();
  1586   1586           return _connectionState;
  1587   1587         }
  1588   1588       }
  1589   1589   
  1590   1590       /// Passes a shutdown request off to SQLite.
  1591         -    public int Shutdown()
         1591  +    public SQLiteErrorCode Shutdown()
  1592   1592       {
  1593   1593           CheckDisposed();
  1594   1594   
  1595   1595           // make sure we have an instance of the base class
  1596   1596           if (_sql == null)
  1597   1597           {
  1598   1598               SortedList<string, string> opts = ParseConnectionString(_connectionString);
................................................................................
  1632   1632       public void SetExtendedResultCodes(bool bOnOff)
  1633   1633       {
  1634   1634         CheckDisposed();
  1635   1635   
  1636   1636         if (_sql != null) _sql.SetExtendedResultCodes(bOnOff);
  1637   1637       }
  1638   1638       /// Enables or disabled extended result codes returned by SQLite
  1639         -    public int ResultCode()
         1639  +    public SQLiteErrorCode ResultCode()
  1640   1640       {
  1641   1641         CheckDisposed();
  1642   1642   
  1643   1643         if (_sql == null)
  1644   1644           throw new InvalidOperationException("Database connection not valid for getting result code.");
  1645   1645         return _sql.ResultCode();
  1646   1646       }
  1647   1647       /// Enables or disabled extended result codes returned by SQLite
  1648         -    public int ExtendedResultCode()
         1648  +    public SQLiteErrorCode ExtendedResultCode()
  1649   1649       {
  1650   1650         CheckDisposed();
  1651   1651   
  1652   1652         if (_sql == null)
  1653   1653           throw new InvalidOperationException("Database connection not valid for getting extended result code.");
  1654   1654         return _sql.ExtendedResultCode();
  1655   1655       }
................................................................................
  1737   1737       /// <param name="count">The number of times to retry the I/O operation.  A negative value
  1738   1738       /// will cause the current count to be queried and replace that negative value.</param>
  1739   1739       /// <param name="interval">The number of milliseconds to wait before retrying the I/O
  1740   1740       /// operation.  This number is multiplied by the number of retry attempts so far to come
  1741   1741       /// up with the final number of milliseconds to wait.  A negative value will cause the
  1742   1742       /// current interval to be queried and replace that negative value.</param>
  1743   1743       /// <returns>Zero for success, non-zero for error.</returns>
  1744         -    public int SetAvRetry(ref int count, ref int interval)
         1744  +    public SQLiteErrorCode SetAvRetry(ref int count, ref int interval)
  1745   1745       {
  1746   1746           CheckDisposed();
  1747   1747   
  1748   1748           if (_connectionState != ConnectionState.Open)
  1749   1749               throw new InvalidOperationException(
  1750   1750                   "Database must be opened before changing the AV retry parameters.");
  1751   1751   
  1752         -        int rc;
         1752  +        SQLiteErrorCode rc;
  1753   1753           IntPtr pArg = IntPtr.Zero;
  1754   1754   
  1755   1755           try
  1756   1756           {
  1757   1757               pArg = Marshal.AllocHGlobal(sizeof(int) * 2);
  1758   1758   
  1759   1759               Marshal.WriteInt32(pArg, 0, count);

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

   227    227         if (!_throwOnDisposed)
   228    228           return;
   229    229   
   230    230         if (_command == null)
   231    231           throw new InvalidOperationException("DataReader has been closed");
   232    232   
   233    233         if (_version == 0)
   234         -        throw new SQLiteException((int)SQLiteErrorCode.Abort, "Execution was aborted by the user");
          234  +        throw new SQLiteException(SQLiteErrorCode.Abort, "Execution was aborted by the user");
   235    235   
   236    236         if (_command.Connection.State != ConnectionState.Open || _command.Connection._version != _version)
   237    237           throw new InvalidOperationException("Connection was closed, statement was terminated");
   238    238       }
   239    239   
   240    240       /// <summary>
   241    241       /// Throw an error if a row is not loaded

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

    33     33       }
    34     34   #endif
    35     35   
    36     36       /// <summary>
    37     37       /// Public constructor for generating a SQLite error given the base error code
    38     38       /// </summary>
    39     39       /// <param name="errorCode">The SQLite error code to report</param>
    40         -    /// <param name="extendedInformation">Extra text to go along with the error message text</param>
    41         -    public SQLiteException(int errorCode, string extendedInformation)
    42         -      : base(GetStockErrorMessage(errorCode, extendedInformation))
           40  +    /// <param name="message">Extra text to go along with the error message text</param>
           41  +    public SQLiteException(SQLiteErrorCode errorCode, string message)
           42  +      : base(GetStockErrorMessage(errorCode, message))
    43     43       {
    44         -      _errorCode = (SQLiteErrorCode)errorCode;
           44  +      _errorCode = errorCode;
    45     45       }
    46     46   
    47     47       /// <summary>
    48     48       /// Various public constructors that just pass along to the base Exception
    49     49       /// </summary>
    50     50       /// <param name="message">Passed verbatim to Exception</param>
    51     51       public SQLiteException(string message)
................................................................................
    82     82         get { return _errorCode; }
    83     83       }
    84     84   
    85     85       /// <summary>
    86     86       /// Initializes the exception class with the SQLite error code.
    87     87       /// </summary>
    88     88       /// <param name="errorCode">The SQLite error code</param>
    89         -    /// <param name="errorMessage">A detailed error message</param>
           89  +    /// <param name="message">A detailed error message</param>
    90     90       /// <returns>An error message string</returns>
    91         -    private static string GetStockErrorMessage(int errorCode, string errorMessage)
           91  +    private static string GetStockErrorMessage(
           92  +        SQLiteErrorCode errorCode,
           93  +        string message
           94  +        )
    92     95       {
    93         -      if (errorMessage == null) errorMessage = "";
    94         -
    95         -      if (errorMessage.Length > 0)
    96         -        errorMessage = "\r\n" + errorMessage;
    97         -
    98         -      if (errorCode < 0 || errorCode >= _errorMessages.Length)
    99         -        errorCode = 1;
   100         -
   101         -      return _errorMessages[errorCode] + errorMessage;
           96  +        return String.Format("{0}{1}{2}",
           97  +            SQLiteBase.GetErrorString(errorCode),
           98  +            Environment.NewLine, message).Trim();
   102     99       }
   103         -
   104         -    private static string[] _errorMessages = {
   105         -      "SQLite OK",
   106         -      "SQLite error",
   107         -      "An internal logic error in SQLite",
   108         -      "Access permission denied",
   109         -      "Callback routine requested an abort",
   110         -      "The database file is locked",
   111         -      "A table in the database is locked",
   112         -      "malloc() failed",
   113         -      "Attempt to write a read-only database",
   114         -      "Operation terminated by sqlite3_interrupt()",
   115         -      "Some kind of disk I/O error occurred",
   116         -      "The database disk image is malformed",
   117         -      "Table or record not found",
   118         -      "Insertion failed because the database is full",
   119         -      "Unable to open the database file",
   120         -      "Database lock protocol error",
   121         -      "Database is empty",
   122         -      "The database schema changed",
   123         -      "Too much data for one row of a table",
   124         -      "Abort due to constraint violation",
   125         -      "Data type mismatch",
   126         -      "Library used incorrectly",
   127         -      "Uses OS features not supported on host",
   128         -      "Authorization denied",
   129         -      "Auxiliary database format error",
   130         -      "2nd parameter to sqlite3_bind() out of range",
   131         -      "File opened that is not a database file",
   132         -    };
   133    100     }
   134    101   
   135    102     /// <summary>
   136         -  /// SQLite error codes
          103  +  /// SQLite error codes.  Actually, this enumeration represents a return code,
          104  +  /// which may also indicate success in one of several ways (e.g. SQLITE_OK,
          105  +  /// SQLITE_ROW, and SQLITE_DONE).  Therefore, the name of this enumeration is
          106  +  /// something of a misnomer.
   137    107     /// </summary>
   138    108     public enum SQLiteErrorCode
   139    109     {
   140    110       /// <summary>
   141         -    /// Success
          111  +    /// Successful result
   142    112       /// </summary>
   143         -    Ok = 0,
          113  +    Ok /* 0 */,
   144    114       /// <summary>
   145    115       /// SQL error or missing database
   146    116       /// </summary>
   147         -    Error,
          117  +    Error /* 1 */,
   148    118       /// <summary>
   149    119       /// Internal logic error in SQLite
   150    120       /// </summary>
   151         -    Internal,
          121  +    Internal /* 2 */,
   152    122       /// <summary>
   153    123       /// Access permission denied
   154    124       /// </summary>
   155         -    Perm,
          125  +    Perm /* 3 */,
   156    126       /// <summary>
   157    127       /// Callback routine requested an abort
   158    128       /// </summary>
   159         -    Abort,
          129  +    Abort /* 4 */,
   160    130       /// <summary>
   161    131       /// The database file is locked
   162    132       /// </summary>
   163         -    Busy,
          133  +    Busy /* 5 */,
   164    134       /// <summary>
   165    135       /// A table in the database is locked
   166    136       /// </summary>
   167         -    Locked,
          137  +    Locked /* 6 */,
   168    138       /// <summary>
   169         -    /// malloc() failed
          139  +    /// A malloc() failed
   170    140       /// </summary>
   171         -    NoMem,
          141  +    NoMem /* 7 */,
   172    142       /// <summary>
   173         -    /// Attempt to write a read-only database
          143  +    /// Attempt to write a readonly database
   174    144       /// </summary>
   175         -    ReadOnly,
          145  +    ReadOnly /* 8 */,
   176    146       /// <summary>
   177    147       /// Operation terminated by sqlite3_interrupt()
   178    148       /// </summary>
   179         -    Interrupt,
          149  +    Interrupt /* 9 */,
   180    150       /// <summary>
   181    151       /// Some kind of disk I/O error occurred
   182    152       /// </summary>
   183         -    IOErr,
          153  +    IoErr /* 10 */,
   184    154       /// <summary>
   185    155       /// The database disk image is malformed
   186    156       /// </summary>
   187         -    Corrupt,
          157  +    Corrupt /* 11 */,
   188    158       /// <summary>
   189         -    /// Table or record not found
          159  +    /// Unknown opcode in sqlite3_file_control()
   190    160       /// </summary>
   191         -    NotFound,
          161  +    NotFound /* 12 */,
   192    162       /// <summary>
   193    163       /// Insertion failed because database is full
   194    164       /// </summary>
   195         -    Full,
          165  +    Full /* 13 */,
   196    166       /// <summary>
   197    167       /// Unable to open the database file
   198    168       /// </summary>
   199         -    CantOpen,
          169  +    CantOpen /* 14 */,
   200    170       /// <summary>
   201    171       /// Database lock protocol error
   202    172       /// </summary>
   203         -    Protocol,
          173  +    Protocol /* 15 */,
   204    174       /// <summary>
   205    175       /// Database is empty
   206    176       /// </summary>
   207         -    Empty,
          177  +    Empty /* 16 */,
   208    178       /// <summary>
   209    179       /// The database schema changed
   210    180       /// </summary>
   211         -    Schema,
          181  +    Schema /* 17 */,
   212    182       /// <summary>
   213         -    /// Too much data for one row of a table
          183  +    /// String or BLOB exceeds size limit
   214    184       /// </summary>
   215         -    TooBig,
          185  +    TooBig /* 18 */,
   216    186       /// <summary>
   217    187       /// Abort due to constraint violation
   218    188       /// </summary>
   219         -    Constraint,
          189  +    Constraint /* 19 */,
   220    190       /// <summary>
   221    191       /// Data type mismatch
   222    192       /// </summary>
   223         -    Mismatch,
          193  +    Mismatch /* 20 */,
   224    194       /// <summary>
   225    195       /// Library used incorrectly
   226    196       /// </summary>
   227         -    Misuse,
          197  +    Misuse /* 21 */,
   228    198       /// <summary>
   229    199       /// Uses OS features not supported on host
   230    200       /// </summary>
   231         -    NOLFS,
          201  +    NoLfs /* 22 */,
   232    202       /// <summary>
   233    203       /// Authorization denied
   234    204       /// </summary>
   235         -    Auth,
          205  +    Auth /* 23 */,
   236    206       /// <summary>
   237    207       /// Auxiliary database format error
   238    208       /// </summary>
   239         -    Format,
          209  +    Format /* 24 */,
   240    210       /// <summary>
   241    211       /// 2nd parameter to sqlite3_bind out of range
   242    212       /// </summary>
   243         -    Range,
          213  +    Range /* 25 */,
   244    214       /// <summary>
   245    215       /// File opened that is not a database file
   246    216       /// </summary>
   247         -    NotADatabase,
          217  +    NotADb /* 26 */,
   248    218       /// <summary>
   249    219       /// sqlite3_step() has another row ready
   250    220       /// </summary>
   251    221       Row = 100,
   252    222       /// <summary>
   253    223       /// sqlite3_step() has finished executing
   254    224       /// </summary>
   255         -    Done = 101,
          225  +    Done /* 101 */
   256    226     }
   257    227   }

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

     8      8   namespace System.Data.SQLite
     9      9   {
    10     10       using System;
    11     11       using System.Data.Common;
    12     12       using System.Diagnostics;
    13     13   
    14     14       /// <summary>
    15         -    /// Passed during an Log callback
           15  +    /// Event data for logging event handlers.
    16     16       /// </summary>
    17     17       public class LogEventArgs : EventArgs
    18     18       {
    19     19           /// <summary>
    20         -        /// The error code.
           20  +        /// The error code.  The type of this object value should be
           21  +        /// System.Int32 or SQLiteErrorCode.
    21     22           /// </summary>
    22         -        public readonly int ErrorCode;
           23  +        public readonly object ErrorCode;
    23     24   
    24     25           /// <summary>
    25     26           /// SQL statement text as the statement first begins executing
    26     27           /// </summary>
    27     28           public readonly string Message;
    28     29   
    29     30           /// <summary>
................................................................................
    31     32           /// </summary>
    32     33           public readonly object Data;
    33     34   
    34     35           /// <summary>
    35     36           /// Constructs the LogEventArgs object.
    36     37           /// </summary>
    37     38           /// <param name="pUserData">Should be null.</param>
    38         -        /// <param name="errorCode">The SQLite error code.</param>
           39  +        /// <param name="errorCode">
           40  +        /// The error code.  The type of this object value should be
           41  +        /// System.Int32 or SQLiteErrorCode.
           42  +        /// </param>
    39     43           /// <param name="message">The error message, if any.</param>
    40     44           /// <param name="data">The extra data, if any.</param>
    41     45           internal LogEventArgs(
    42     46               IntPtr pUserData,
    43         -            int errorCode,
           47  +            object errorCode,
    44     48               string message,
    45     49               object data
    46     50               )
    47     51           {
    48     52               ErrorCode = errorCode;
    49     53               Message = message;
    50     54               Data = data;
................................................................................
   165    169                   //       event on to any registered handler.  We only want to
   166    170                   //       do this once.
   167    171                   //
   168    172                   if (_callback == null)
   169    173                   {
   170    174                       _callback = new SQLiteLogCallback(LogCallback);
   171    175   
   172         -                    int rc = _sql.SetLogCallback(_callback);
          176  +                    SQLiteErrorCode rc = _sql.SetLogCallback(_callback);
   173    177   
   174         -                    if (rc != 0)
          178  +                    if (rc != SQLiteErrorCode.Ok)
   175    179                           throw new SQLiteException(rc,
   176    180                               "Failed to initialize logging.");
   177    181                   }
   178    182   
   179    183                   //
   180    184                   // NOTE: Logging is enabled by default.
   181    185                   //
................................................................................
   187    191                   AddDefaultHandler();
   188    192               }
   189    193           }
   190    194   
   191    195           /// <summary>
   192    196           /// Handles the AppDomain being unloaded.
   193    197           /// </summary>
   194         -        /// <param name="sender"></param>
   195         -        /// <param name="e"></param>
          198  +        /// <param name="sender">Should be null.</param>
          199  +        /// <param name="e">The data associated with this event.</param>
   196    200           private static void DomainUnload(
   197    201               object sender,
   198    202               EventArgs e
   199    203               )
   200    204           {
   201    205               lock (syncRoot)
   202    206               {
................................................................................
   214    218                   //
   215    219                   // BUGBUG: This will cause serious problems if other AppDomains
   216    220                   //         have any open SQLite connections; however, there is
   217    221                   //         currently no way around this limitation.
   218    222                   //
   219    223                   if (_sql != null)
   220    224                   {
   221         -                    int rc = _sql.Shutdown();
          225  +                    SQLiteErrorCode rc = _sql.Shutdown();
   222    226   
   223         -                    if (rc != 0)
          227  +                    if (rc != SQLiteErrorCode.Ok)
   224    228                           throw new SQLiteException(rc,
   225    229                               "Failed to shutdown interface.");
   226    230   
   227    231                       rc = _sql.SetLogCallback(null);
   228    232   
   229         -                    if (rc != 0)
          233  +                    if (rc != SQLiteErrorCode.Ok)
   230    234                           throw new SQLiteException(rc,
   231    235                               "Failed to shutdown logging.");
   232    236                   }
   233    237   
   234    238                   //
   235    239                   // BUGFIX: Make sure to reset the callback for next time.  This
   236    240                   //         must be done after it has been succesfully removed
................................................................................
   294    298               set { lock (syncRoot) { _enabled = value; } }
   295    299           }
   296    300   
   297    301           /// <summary>
   298    302           /// Log a message to all the registered log event handlers without going
   299    303           /// through the SQLite library.
   300    304           /// </summary>
   301         -        /// <param name="errorCode">The error code or zero for success.</param>
          305  +        /// <param name="message">The message to be logged.</param>
          306  +        public static void LogMessage(
          307  +            string message
          308  +            )
          309  +        {
          310  +            LogMessage(null, message);
          311  +        }
          312  +
          313  +        /// <summary>
          314  +        /// Log a message to all the registered log event handlers without going
          315  +        /// through the SQLite library.
          316  +        /// </summary>
          317  +        /// <param name="errorCode">The SQLite error code.</param>
          318  +        /// <param name="message">The message to be logged.</param>
          319  +        public static void LogMessage(
          320  +            SQLiteErrorCode errorCode,
          321  +            string message
          322  +            )
          323  +        {
          324  +            LogMessage((object)errorCode, message);
          325  +        }
          326  +
          327  +        /// <summary>
          328  +        /// Log a message to all the registered log event handlers without going
          329  +        /// through the SQLite library.
          330  +        /// </summary>
          331  +        /// <param name="errorCode">The integer error code.</param>
   302    332           /// <param name="message">The message to be logged.</param>
   303    333           public static void LogMessage(
   304    334               int errorCode,
   305    335               string message
   306    336               )
          337  +        {
          338  +            LogMessage((object)errorCode, message);
          339  +        }
          340  +
          341  +        /// <summary>
          342  +        /// Log a message to all the registered log event handlers without going
          343  +        /// through the SQLite library.
          344  +        /// </summary>
          345  +        /// <param name="errorCode">
          346  +        /// The error code.  The type of this object value should be
          347  +        /// System.Int32 or SQLiteErrorCode.
          348  +        /// </param>
          349  +        /// <param name="message">The message to be logged.</param>
          350  +        private static void LogMessage(
          351  +            object errorCode,
          352  +            string message
          353  +            )
   307    354           {
   308    355               bool enabled;
   309    356               SQLiteLogEventHandler handlers;
   310    357   
   311    358               lock (syncRoot)
   312    359               {
   313    360                   enabled = _enabled;
................................................................................
   348    395               InitializeDefaultHandler();
   349    396               Log -= _defaultHandler;
   350    397           }
   351    398   
   352    399           /// <summary>
   353    400           /// Internal proxy function that calls any registered application log
   354    401           /// event handlers.
          402  +        ///
          403  +        /// WARNING: This method is used more-or-less directly by native code,
          404  +        ///          do not modify its type signature.
   355    405           /// </summary>
          406  +        /// <param name="pUserData">
          407  +        /// The extra data associated with this message, if any.
          408  +        /// </param>
          409  +        /// <param name="errorCode">
          410  +        /// The error code associated with this message.
          411  +        /// </param>
          412  +        /// <param name="pMessage">
          413  +        /// The message string to be logged.
          414  +        /// </param>
   356    415           private static void LogCallback(
   357    416               IntPtr pUserData,
   358    417               int errorCode,
   359    418               IntPtr pMessage
   360    419               )
   361    420           {
   362    421               bool enabled;
................................................................................
   401    460               {
   402    461                   message = message.Trim();
   403    462   
   404    463                   if (message.Length == 0)
   405    464                       message = "<empty>";
   406    465               }
   407    466   
   408         -            int errorCode = e.ErrorCode;
          467  +            object errorCode = e.ErrorCode;
          468  +            bool success = false;
          469  +
          470  +            if (errorCode is SQLiteErrorCode)
          471  +                success = ((SQLiteErrorCode)errorCode == SQLiteErrorCode.Ok);
          472  +            else if (errorCode is int)
          473  +                success = ((int)errorCode == 0);
   409    474   
   410         -            Trace.WriteLine(String.Format(
   411         -                "SQLite {0} ({1}): {2}", errorCode == 0 ?
   412         -                "message" : "error", errorCode, message));
          475  +            Trace.WriteLine(String.Format("SQLite {0} ({1}): {2}",
          476  +                success ? "message" : "error", errorCode, message));
   413    477           }
   414    478       }
   415    479   #endif
   416    480   }

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

   252    252               case TypeCode.Double:
   253    253                   return ((double)obj) != (double)0.0 ? true : false;
   254    254               case TypeCode.Decimal:
   255    255                   return ((decimal)obj) != Decimal.Zero ? true : false;
   256    256               case TypeCode.String:
   257    257                   return Convert.ToBoolean(obj, provider);
   258    258               default:
   259         -                throw new SQLiteException((int)SQLiteErrorCode.Error,
          259  +                throw new SQLiteException(SQLiteErrorCode.Error,
   260    260                       String.Format(CultureInfo.CurrentCulture,
   261    261                       "Cannot convert type {0} to boolean", typeCode));
   262    262           }
   263    263       }
   264    264   
   265    265       /// <summary>
   266    266       /// Perform the bind operation for an individual parameter
   267    267       /// </summary>
   268    268       /// <param name="index">The index of the parameter to bind</param>
   269    269       /// <param name="param">The parameter we're binding</param>
   270    270       private void BindParameter(int index, SQLiteParameter param)
   271    271       {
   272    272         if (param == null)
   273         -        throw new SQLiteException((int)SQLiteErrorCode.Error, "Insufficient parameters supplied to the command");
          273  +        throw new SQLiteException(SQLiteErrorCode.Error, "Insufficient parameters supplied to the command");
   274    274   
   275    275         object obj = param.Value;
   276    276         DbType objType = param.DbType;
   277    277   
   278    278         if ((obj != null) && (objType == DbType.Object))
   279    279             objType = SQLiteConvert.TypeToDbType(obj.GetType());
   280    280   
   281    281   #if !PLATFORM_COMPACTFRAMEWORK
   282    282         if ((_flags & SQLiteConnectionFlags.LogPreBind) == SQLiteConnectionFlags.LogPreBind)
   283    283         {
   284    284             IntPtr handle = _sqlite_stmt;
   285    285   
   286         -          SQLiteLog.LogMessage(0, String.Format(
          286  +          SQLiteLog.LogMessage(String.Format(
   287    287                 "Binding statement {0} paramter #{1} with database type {2} and raw value {{{3}}}...",
   288    288                 handle, index, objType, obj));
   289    289         }
   290    290   #endif
   291    291   
   292    292         if ((obj == null) || Convert.IsDBNull(obj))
   293    293         {

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

   195    195         {
   196    196           if (throwError == true) throw new ArgumentNullException("No connection associated with this transaction");
   197    197           else return false;
   198    198         }
   199    199   
   200    200         if (_cnn._version != _version)
   201    201         {
   202         -        if (throwError == true) throw new SQLiteException((int)SQLiteErrorCode.Misuse, "The connection was closed and re-opened, changes were already rolled back");
          202  +        if (throwError == true) throw new SQLiteException(SQLiteErrorCode.Misuse, "The connection was closed and re-opened, changes were already rolled back");
   203    203           else return false;
   204    204         }
   205    205         if (_cnn.State != ConnectionState.Open)
   206    206         {
   207         -        if (throwError == true) throw new SQLiteException((int)SQLiteErrorCode.Misuse, "Connection was closed");
          207  +        if (throwError == true) throw new SQLiteException(SQLiteErrorCode.Misuse, "Connection was closed");
   208    208           else return false;
   209    209         }
   210    210   
   211    211         if (_cnn._transactionLevel == 0 || _cnn._sql.AutoCommit == true)
   212    212         {
   213    213           _cnn._transactionLevel = 0; // Make sure the transaction level is reset before returning
   214         -        if (throwError == true) throw new SQLiteException((int)SQLiteErrorCode.Misuse, "No transaction is active on this connection");
          214  +        if (throwError == true) throw new SQLiteException(SQLiteErrorCode.Misuse, "No transaction is active on this connection");
   215    215           else return false;
   216    216         }
   217    217   
   218    218         return true;
   219    219       }
   220    220     }
   221    221   }

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

   545    545       [DllImport(SQLITE_DLL)]
   546    546       internal static extern IntPtr sqlite3_column_text16_interop(IntPtr stmt, int index, out int len);
   547    547   
   548    548       [DllImport(SQLITE_DLL)]
   549    549       internal static extern IntPtr sqlite3_errmsg_interop(IntPtr db, out int len);
   550    550   
   551    551       [DllImport(SQLITE_DLL)]
   552         -    internal static extern int sqlite3_prepare_interop(IntPtr db, IntPtr pSql, int nBytes, out IntPtr stmt, out IntPtr ptrRemain, out int nRemain);
          552  +    internal static extern SQLiteErrorCode sqlite3_prepare_interop(IntPtr db, IntPtr pSql, int nBytes, out IntPtr stmt, out IntPtr ptrRemain, out int nRemain);
   553    553   
   554    554       [DllImport(SQLITE_DLL)]
   555         -    internal static extern int sqlite3_table_column_metadata_interop(IntPtr db, byte[] dbName, byte[] tblName, byte[] colName, out IntPtr ptrDataType, out IntPtr ptrCollSeq, out int notNull, out int primaryKey, out int autoInc, out int dtLen, out int csLen);
          555  +    internal static extern SQLiteErrorCode sqlite3_table_column_metadata_interop(IntPtr db, byte[] dbName, byte[] tblName, byte[] colName, out IntPtr ptrDataType, out IntPtr ptrCollSeq, out int notNull, out int primaryKey, out int autoInc, out int dtLen, out int csLen);
   556    556   
   557    557       [DllImport(SQLITE_DLL)]
   558    558       internal static extern IntPtr sqlite3_value_text_interop(IntPtr p, out int len);
   559    559   
   560    560       [DllImport(SQLITE_DLL)]
   561    561       internal static extern IntPtr sqlite3_value_text16_interop(IntPtr p, out int len);
   562    562   
................................................................................
   568    568       // These functions add existing functionality on top of SQLite and require a little effort to
   569    569       // get working when using the standard SQLite library.
   570    570       #region interop added functionality
   571    571   
   572    572   #if !SQLITE_STANDARD
   573    573   
   574    574       [DllImport(SQLITE_DLL)]
   575         -    internal static extern int sqlite3_close_interop(IntPtr db);
          575  +    internal static extern SQLiteErrorCode sqlite3_close_interop(IntPtr db);
   576    576   
   577    577       [DllImport(SQLITE_DLL)]
   578         -    internal static extern int sqlite3_create_function_interop(IntPtr db, byte[] strName, int nArgs, int nType, IntPtr pvUser, SQLiteCallback func, SQLiteCallback fstep, SQLiteFinalCallback ffinal, int needCollSeq);
          578  +    internal static extern SQLiteErrorCode sqlite3_create_function_interop(IntPtr db, byte[] strName, int nArgs, int nType, IntPtr pvUser, SQLiteCallback func, SQLiteCallback fstep, SQLiteFinalCallback ffinal, int needCollSeq);
   579    579   
   580    580       [DllImport(SQLITE_DLL)]
   581         -    internal static extern int sqlite3_finalize_interop(IntPtr stmt);
          581  +    internal static extern SQLiteErrorCode sqlite3_finalize_interop(IntPtr stmt);
   582    582   
   583    583       [DllImport(SQLITE_DLL)]
   584         -    internal static extern int sqlite3_open_interop(byte[] utf8Filename, int flags, out IntPtr db);
          584  +    internal static extern SQLiteErrorCode sqlite3_open_interop(byte[] utf8Filename, int flags, out IntPtr db);
   585    585   
   586    586       [DllImport(SQLITE_DLL)]
   587         -    internal static extern int sqlite3_open16_interop(byte[] utf8Filename, int flags, out IntPtr db);
          587  +    internal static extern SQLiteErrorCode sqlite3_open16_interop(byte[] utf8Filename, int flags, out IntPtr db);
   588    588   
   589    589       [DllImport(SQLITE_DLL)]
   590         -    internal static extern int sqlite3_reset_interop(IntPtr stmt);
          590  +    internal static extern SQLiteErrorCode sqlite3_reset_interop(IntPtr stmt);
   591    591   
   592    592   #endif
   593    593   // !SQLITE_STANDARD
   594    594   
   595    595       #endregion
   596    596   
   597    597       // The standard api call equivalents of the above interop calls
................................................................................
   600    600   #if SQLITE_STANDARD
   601    601   
   602    602   #if !PLATFORM_COMPACTFRAMEWORK
   603    603       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
   604    604   #else
   605    605       [DllImport(SQLITE_DLL)]
   606    606   #endif
   607         -    internal static extern int sqlite3_close(IntPtr db);
   608         -
   609         -#if !PLATFORM_COMPACTFRAMEWORK
   610         -    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
   611         -#else
   612         -    [DllImport(SQLITE_DLL)]
   613         -#endif
   614         -    internal static extern int sqlite3_close_v2(IntPtr db);
   615         -
   616         -#if !PLATFORM_COMPACTFRAMEWORK
   617         -    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
   618         -#else
   619         -    [DllImport(SQLITE_DLL)]
   620         -#endif
   621         -    internal static extern int sqlite3_create_function(IntPtr db, byte[] strName, int nArgs, int nType, IntPtr pvUser, SQLiteCallback func, SQLiteCallback fstep, SQLiteFinalCallback ffinal);
   622         -
   623         -#if !PLATFORM_COMPACTFRAMEWORK
   624         -    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
   625         -#else
   626         -    [DllImport(SQLITE_DLL)]
   627         -#endif
   628         -    internal static extern int sqlite3_finalize(IntPtr stmt);
   629         -
   630         -#if !PLATFORM_COMPACTFRAMEWORK
   631         -    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
   632         -#else
   633         -    [DllImport(SQLITE_DLL)]
   634         -#endif
   635         -    internal static extern int sqlite3_open_v2(byte[] utf8Filename, out IntPtr db, int flags, IntPtr vfs);
          607  +    internal static extern SQLiteErrorCode sqlite3_close(IntPtr db);
          608  +
          609  +#if !PLATFORM_COMPACTFRAMEWORK
          610  +    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
          611  +#else
          612  +    [DllImport(SQLITE_DLL)]
          613  +#endif
          614  +    internal static extern SQLiteErrorCode sqlite3_close_v2(IntPtr db);
          615  +
          616  +#if !PLATFORM_COMPACTFRAMEWORK
          617  +    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
          618  +#else
          619  +    [DllImport(SQLITE_DLL)]
          620  +#endif
          621  +    internal static extern SQLiteErrorCode sqlite3_create_function(IntPtr db, byte[] strName, int nArgs, int nType, IntPtr pvUser, SQLiteCallback func, SQLiteCallback fstep, SQLiteFinalCallback ffinal);
          622  +
          623  +#if !PLATFORM_COMPACTFRAMEWORK
          624  +    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
          625  +#else
          626  +    [DllImport(SQLITE_DLL)]
          627  +#endif
          628  +    internal static extern SQLiteErrorCode sqlite3_finalize(IntPtr stmt);
          629  +
          630  +#if !PLATFORM_COMPACTFRAMEWORK
          631  +    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
          632  +#else
          633  +    [DllImport(SQLITE_DLL)]
          634  +#endif
          635  +    internal static extern SQLiteErrorCode sqlite3_open_v2(byte[] utf8Filename, out IntPtr db, int flags, IntPtr vfs);
   636    636   
   637    637   #if !PLATFORM_COMPACTFRAMEWORK
   638    638       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
   639    639   #else
   640    640       [DllImport(SQLITE_DLL, CharSet = CharSet.Unicode)]
   641    641   #endif
   642         -    internal static extern int sqlite3_open16(string fileName, out IntPtr db);
          642  +    internal static extern SQLiteErrorCode sqlite3_open16(string fileName, out IntPtr db);
   643    643   
   644    644   #if !PLATFORM_COMPACTFRAMEWORK
   645    645       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
   646    646   #else
   647    647       [DllImport(SQLITE_DLL)]
   648    648   #endif
   649         -    internal static extern int sqlite3_reset(IntPtr stmt);
          649  +    internal static extern SQLiteErrorCode sqlite3_reset(IntPtr stmt);
   650    650   
   651    651   #if !PLATFORM_COMPACTFRAMEWORK
   652    652       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
   653    653   #else
   654    654       [DllImport(SQLITE_DLL)]
   655    655   #endif
   656    656       internal static extern IntPtr sqlite3_bind_parameter_name(IntPtr stmt, int index);
................................................................................
   747    747       internal static extern IntPtr sqlite3_errmsg(IntPtr db);
   748    748   
   749    749   #if !PLATFORM_COMPACTFRAMEWORK
   750    750       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
   751    751   #else
   752    752       [DllImport(SQLITE_DLL)]
   753    753   #endif
   754         -    internal static extern int sqlite3_prepare(IntPtr db, IntPtr pSql, int nBytes, out IntPtr stmt, out IntPtr ptrRemain);
          754  +    internal static extern SQLiteErrorCode sqlite3_prepare(IntPtr db, IntPtr pSql, int nBytes, out IntPtr stmt, out IntPtr ptrRemain);
   755    755   
   756    756   #if !PLATFORM_COMPACTFRAMEWORK
   757    757       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
   758    758   #else
   759    759       [DllImport(SQLITE_DLL)]
   760    760   #endif
   761         -    internal static extern int sqlite3_table_column_metadata(IntPtr db, byte[] dbName, byte[] tblName, byte[] colName, out IntPtr ptrDataType, out IntPtr ptrCollSeq, out int notNull, out int primaryKey, out int autoInc);
          761  +    internal static extern SQLiteErrorCode sqlite3_table_column_metadata(IntPtr db, byte[] dbName, byte[] tblName, byte[] colName, out IntPtr ptrDataType, out IntPtr ptrCollSeq, out int notNull, out int primaryKey, out int autoInc);
   762    762   
   763    763   #if !PLATFORM_COMPACTFRAMEWORK
   764    764       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
   765    765   #else
   766    766       [DllImport(SQLITE_DLL)]
   767    767   #endif
   768    768       internal static extern IntPtr sqlite3_value_text(IntPtr p);
................................................................................
   788    788       [DllImport(SQLITE_DLL)]
   789    789       internal static extern IntPtr sqlite3_context_collseq(IntPtr context, out int type, out int enc, out int len);
   790    790   
   791    791       [DllImport(SQLITE_DLL)]
   792    792       internal static extern int sqlite3_context_collcompare(IntPtr context, byte[] p1, int p1len, byte[] p2, int p2len);
   793    793   
   794    794       [DllImport(SQLITE_DLL)]
   795         -    internal static extern int sqlite3_cursor_rowid(IntPtr stmt, int cursor, out long rowid);
          795  +    internal static extern SQLiteErrorCode sqlite3_cursor_rowid(IntPtr stmt, int cursor, out long rowid);
   796    796   
   797    797       [DllImport(SQLITE_DLL)]
   798         -    internal static extern int sqlite3_index_column_info_interop(IntPtr db, byte[] catalog, byte[] IndexName, byte[] ColumnName, out int sortOrder, out int onError, out IntPtr Collation, out int colllen);
          798  +    internal static extern SQLiteErrorCode sqlite3_index_column_info_interop(IntPtr db, byte[] catalog, byte[] IndexName, byte[] ColumnName, out int sortOrder, out int onError, out IntPtr Collation, out int colllen);
   799    799   
   800    800       [DllImport(SQLITE_DLL)]
   801    801       internal static extern void sqlite3_resetall_interop(IntPtr db);
   802    802   
   803    803       [DllImport(SQLITE_DLL)]
   804    804       internal static extern int sqlite3_table_cursor(IntPtr stmt, int db, int tableRootPage);
   805    805   
................................................................................
   812    812       // scattered in here, but they are only active when PLATFORM_COMPACTFRAMEWORK is declared.
   813    813       #region standard sqlite api calls
   814    814   #if !PLATFORM_COMPACTFRAMEWORK
   815    815       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
   816    816   #else
   817    817       [DllImport(SQLITE_DLL, CharSet = CharSet.Unicode)]
   818    818   #endif
   819         -    internal static extern int sqlite3_win32_set_directory(uint type, string value);
          819  +    internal static extern SQLiteErrorCode sqlite3_win32_set_directory(uint type, string value);
   820    820   
   821    821   #if !PLATFORM_COMPACTFRAMEWORK
   822    822       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
   823    823   #else
   824    824       [DllImport(SQLITE_DLL)]
   825    825   #endif
   826    826       internal static extern IntPtr sqlite3_libversion();
................................................................................
   889    889       internal static extern long sqlite3_memory_highwater(int resetFlag);
   890    890   
   891    891   #if !PLATFORM_COMPACTFRAMEWORK
   892    892       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
   893    893   #else
   894    894       [DllImport(SQLITE_DLL)]
   895    895   #endif
   896         -    internal static extern int sqlite3_shutdown();
   897         -
   898         -#if !PLATFORM_COMPACTFRAMEWORK
   899         -    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
   900         -#else
   901         -    [DllImport(SQLITE_DLL)]
   902         -#endif
   903         -    internal static extern int sqlite3_busy_timeout(IntPtr db, int ms);
   904         -
   905         -#if !PLATFORM_COMPACTFRAMEWORK
   906         -    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
   907         -#else
   908         -    [DllImport(SQLITE_DLL)]
   909         -#endif
   910         -    internal static extern int sqlite3_bind_blob(IntPtr stmt, int index, Byte[] value, int nSize, IntPtr nTransient);
   911         -
   912         -#if !PLATFORM_COMPACTFRAMEWORK
   913         -    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
   914         -    internal static extern int sqlite3_bind_double(IntPtr stmt, int index, double value);
   915         -#else
   916         -    [DllImport(SQLITE_DLL)]
   917         -    internal static extern int sqlite3_bind_double_interop(IntPtr stmt, int index, ref double value);
   918         -#endif
   919         -
   920         -#if !PLATFORM_COMPACTFRAMEWORK
   921         -    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
   922         -#else
   923         -    [DllImport(SQLITE_DLL)]
   924         -#endif
   925         -    internal static extern int sqlite3_bind_int(IntPtr stmt, int index, int value);
          896  +    internal static extern SQLiteErrorCode sqlite3_shutdown();
          897  +
          898  +#if !PLATFORM_COMPACTFRAMEWORK
          899  +    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
          900  +#else
          901  +    [DllImport(SQLITE_DLL)]
          902  +#endif
          903  +    internal static extern SQLiteErrorCode sqlite3_busy_timeout(IntPtr db, int ms);
          904  +
          905  +#if !PLATFORM_COMPACTFRAMEWORK
          906  +    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
          907  +#else
          908  +    [DllImport(SQLITE_DLL)]
          909  +#endif
          910  +    internal static extern SQLiteErrorCode sqlite3_bind_blob(IntPtr stmt, int index, Byte[] value, int nSize, IntPtr nTransient);
          911  +
          912  +#if !PLATFORM_COMPACTFRAMEWORK
          913  +    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
          914  +    internal static extern SQLiteErrorCode sqlite3_bind_double(IntPtr stmt, int index, double value);
          915  +#else
          916  +    [DllImport(SQLITE_DLL)]
          917  +    internal static extern SQLiteErrorCode sqlite3_bind_double_interop(IntPtr stmt, int index, ref double value);
          918  +#endif
          919  +
          920  +#if !PLATFORM_COMPACTFRAMEWORK
          921  +    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
          922  +#else
          923  +    [DllImport(SQLITE_DLL)]
          924  +#endif
          925  +    internal static extern SQLiteErrorCode sqlite3_bind_int(IntPtr stmt, int index, int value);
   926    926   
   927    927       //
   928    928       // NOTE: This really just calls "sqlite3_bind_int"; however, it has the
   929    929       //       correct type signature for an unsigned (32-bit) integer.
   930    930       //
   931    931   #if !PLATFORM_COMPACTFRAMEWORK
   932    932       [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_bind_int", CallingConvention = CallingConvention.Cdecl)]
   933    933   #else
   934    934       [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_bind_int")]
   935    935   #endif
   936         -    internal static extern int sqlite3_bind_uint(IntPtr stmt, int index, uint value);
          936  +    internal static extern SQLiteErrorCode sqlite3_bind_uint(IntPtr stmt, int index, uint value);
   937    937   
   938    938   #if !PLATFORM_COMPACTFRAMEWORK
   939    939       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
   940         -    internal static extern int sqlite3_bind_int64(IntPtr stmt, int index, long value);
          940  +    internal static extern SQLiteErrorCode sqlite3_bind_int64(IntPtr stmt, int index, long value);
   941    941   #else
   942    942       [DllImport(SQLITE_DLL)]
   943         -    internal static extern int sqlite3_bind_int64_interop(IntPtr stmt, int index, ref long value);
          943  +    internal static extern SQLiteErrorCode sqlite3_bind_int64_interop(IntPtr stmt, int index, ref long value);
   944    944   #endif
   945    945   
   946    946       //
   947    947       // NOTE: This really just calls "sqlite3_bind_int64"; however, it has the
   948    948       //       correct type signature for an unsigned long (64-bit) integer.
   949    949       //
   950    950   #if !PLATFORM_COMPACTFRAMEWORK
   951    951       [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_bind_int64", CallingConvention = CallingConvention.Cdecl)]
   952         -    internal static extern int sqlite3_bind_uint64(IntPtr stmt, int index, ulong value);
          952  +    internal static extern SQLiteErrorCode sqlite3_bind_uint64(IntPtr stmt, int index, ulong value);
   953    953   #else
   954    954       [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_bind_int64_interop")]
   955         -    internal static extern int sqlite3_bind_uint64_interop(IntPtr stmt, int index, ref ulong value);
          955  +    internal static extern SQLiteErrorCode sqlite3_bind_uint64_interop(IntPtr stmt, int index, ref ulong value);
   956    956   #endif
   957    957   
   958    958   #if !PLATFORM_COMPACTFRAMEWORK
   959    959       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
   960    960   #else
   961    961       [DllImport(SQLITE_DLL)]
   962    962   #endif
   963         -    internal static extern int sqlite3_bind_null(IntPtr stmt, int index);
          963  +    internal static extern SQLiteErrorCode sqlite3_bind_null(IntPtr stmt, int index);
   964    964   
   965    965   #if !PLATFORM_COMPACTFRAMEWORK
   966    966       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
   967    967   #else
   968    968       [DllImport(SQLITE_DLL)]
   969    969   #endif
   970         -    internal static extern int sqlite3_bind_text(IntPtr stmt, int index, byte[] value, int nlen, IntPtr pvReserved);
          970  +    internal static extern SQLiteErrorCode sqlite3_bind_text(IntPtr stmt, int index, byte[] value, int nlen, IntPtr pvReserved);
   971    971   
   972    972   #if !PLATFORM_COMPACTFRAMEWORK
   973    973       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
   974    974   #else
   975    975       [DllImport(SQLITE_DLL)]
   976    976   #endif
   977    977       internal static extern int sqlite3_bind_parameter_count(IntPtr stmt);
................................................................................
   991    991       internal static extern int sqlite3_column_count(IntPtr stmt);
   992    992   
   993    993   #if !PLATFORM_COMPACTFRAMEWORK
   994    994       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
   995    995   #else
   996    996       [DllImport(SQLITE_DLL)]
   997    997   #endif
   998         -    internal static extern int sqlite3_step(IntPtr stmt);
          998  +    internal static extern SQLiteErrorCode sqlite3_step(IntPtr stmt);
   999    999   
  1000   1000   #if !PLATFORM_COMPACTFRAMEWORK
  1001   1001       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
  1002   1002       internal static extern double sqlite3_column_double(IntPtr stmt, int index);
  1003   1003   #else
  1004   1004       [DllImport(SQLITE_DLL)]
  1005   1005       internal static extern void sqlite3_column_double_interop(IntPtr stmt, int index, out double value);
................................................................................
  1042   1042       internal static extern TypeAffinity sqlite3_column_type(IntPtr stmt, int index);
  1043   1043   
  1044   1044   #if !PLATFORM_COMPACTFRAMEWORK
  1045   1045       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
  1046   1046   #else
  1047   1047       [DllImport(SQLITE_DLL)]
  1048   1048   #endif
  1049         -    internal static extern int sqlite3_create_collation(IntPtr db, byte[] strName, int nType, IntPtr pvUser, SQLiteCollation func);
         1049  +    internal static extern SQLiteErrorCode sqlite3_create_collation(IntPtr db, byte[] strName, int nType, IntPtr pvUser, SQLiteCollation func);
  1050   1050   
  1051   1051   #if !PLATFORM_COMPACTFRAMEWORK
  1052   1052       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
  1053   1053   #else
  1054   1054       [DllImport(SQLITE_DLL)]
  1055   1055   #endif
  1056   1056       internal static extern int sqlite3_aggregate_count(IntPtr context);
................................................................................
  1158   1158       internal static extern IntPtr sqlite3_aggregate_context(IntPtr context, int nBytes);
  1159   1159   
  1160   1160   #if !PLATFORM_COMPACTFRAMEWORK
  1161   1161       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
  1162   1162   #else
  1163   1163       [DllImport(SQLITE_DLL, CharSet = CharSet.Unicode)]
  1164   1164   #endif
  1165         -    internal static extern int sqlite3_bind_text16(IntPtr stmt, int index, string value, int nlen, IntPtr pvReserved);
         1165  +    internal static extern SQLiteErrorCode sqlite3_bind_text16(IntPtr stmt, int index, string value, int nlen, IntPtr pvReserved);
  1166   1166   
  1167   1167   #if !PLATFORM_COMPACTFRAMEWORK
  1168   1168       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
  1169   1169   #else
  1170   1170       [DllImport(SQLITE_DLL, CharSet = CharSet.Unicode)]
  1171   1171   #endif
  1172   1172       internal static extern void sqlite3_result_error16(IntPtr context, string strName, int nLen);
................................................................................
  1180   1180   
  1181   1181   #if INTEROP_CODEC
  1182   1182   #if !PLATFORM_COMPACTFRAMEWORK
  1183   1183       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
  1184   1184   #else
  1185   1185       [DllImport(SQLITE_DLL)]
  1186   1186   #endif
  1187         -    internal static extern int sqlite3_key(IntPtr db, byte[] key, int keylen);
         1187  +    internal static extern SQLiteErrorCode sqlite3_key(IntPtr db, byte[] key, int keylen);
  1188   1188   
  1189   1189   #if !PLATFORM_COMPACTFRAMEWORK
  1190   1190       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
  1191   1191   #else
  1192   1192       [DllImport(SQLITE_DLL)]
  1193   1193   #endif
  1194         -    internal static extern int sqlite3_rekey(IntPtr db, byte[] key, int keylen);
         1194  +    internal static extern SQLiteErrorCode sqlite3_rekey(IntPtr db, byte[] key, int keylen);
  1195   1195   #endif
  1196   1196   
  1197   1197   #if !PLATFORM_COMPACTFRAMEWORK
  1198   1198       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
  1199   1199   #else
  1200   1200       [DllImport(SQLITE_DLL)]
  1201   1201   #endif
................................................................................
  1218   1218       // Since sqlite3_config() takes a variable argument list, we have to overload declarations
  1219   1219       // for all possible calls that we want to use.
  1220   1220   #if !PLATFORM_COMPACTFRAMEWORK
  1221   1221       [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_config", CallingConvention = CallingConvention.Cdecl)]
  1222   1222   #else
  1223   1223       [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_config")]
  1224   1224   #endif
  1225         -    internal static extern int sqlite3_config_none(SQLiteConfigOpsEnum op);
         1225  +    internal static extern SQLiteErrorCode sqlite3_config_none(SQLiteConfigOpsEnum op);
  1226   1226   
  1227   1227   #if !PLATFORM_COMPACTFRAMEWORK
  1228   1228       [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_config", CallingConvention = CallingConvention.Cdecl)]
  1229   1229   #else
  1230   1230       [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_config")]
  1231   1231   #endif
  1232         -    internal static extern int sqlite3_config_int(SQLiteConfigOpsEnum op, int value);
         1232  +    internal static extern SQLiteErrorCode sqlite3_config_int(SQLiteConfigOpsEnum op, int value);
  1233   1233   
  1234   1234   #if !PLATFORM_COMPACTFRAMEWORK
  1235   1235       [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_config", CallingConvention = CallingConvention.Cdecl)]
  1236   1236   #else
  1237   1237       [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_config")]
  1238   1238   #endif
  1239         -    internal static extern int sqlite3_config_log(SQLiteConfigOpsEnum op, SQLiteLogCallback func, IntPtr pvUser);
         1239  +    internal static extern SQLiteErrorCode sqlite3_config_log(SQLiteConfigOpsEnum op, SQLiteLogCallback func, IntPtr pvUser);
  1240   1240   
  1241   1241   #if !PLATFORM_COMPACTFRAMEWORK
  1242   1242       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
  1243   1243   #else
  1244   1244       [DllImport(SQLITE_DLL)]
  1245   1245   #endif
  1246   1246       internal static extern IntPtr sqlite3_rollback_hook(IntPtr db, SQLiteRollbackCallback func, IntPtr pvUser);
................................................................................
  1260   1260       internal static extern IntPtr sqlite3_next_stmt(IntPtr db, IntPtr stmt);
  1261   1261   
  1262   1262   #if !PLATFORM_COMPACTFRAMEWORK
  1263   1263       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
  1264   1264   #else
  1265   1265       [DllImport(SQLITE_DLL)]
  1266   1266   #endif
  1267         -    internal static extern int sqlite3_exec(IntPtr db, byte[] strSql, IntPtr pvCallback, IntPtr pvParam, out IntPtr errMsg);
         1267  +    internal static extern SQLiteErrorCode sqlite3_exec(IntPtr db, byte[] strSql, IntPtr pvCallback, IntPtr pvParam, out IntPtr errMsg);
  1268   1268   
  1269   1269   #if !PLATFORM_COMPACTFRAMEWORK
  1270   1270       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
  1271   1271   #else
  1272   1272       [DllImport(SQLITE_DLL)]
  1273   1273   #endif
  1274   1274       internal static extern int sqlite3_get_autocommit(IntPtr db);
  1275   1275   
  1276   1276   #if !PLATFORM_COMPACTFRAMEWORK
  1277   1277       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
  1278   1278   #else
  1279   1279       [DllImport(SQLITE_DLL)]
  1280   1280   #endif
  1281         -    internal static extern int sqlite3_extended_result_codes(IntPtr db, int onoff);
         1281  +    internal static extern SQLiteErrorCode sqlite3_extended_result_codes(IntPtr db, int onoff);
  1282   1282   
  1283   1283   #if !PLATFORM_COMPACTFRAMEWORK
  1284   1284       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
  1285   1285   #else
  1286   1286       [DllImport(SQLITE_DLL)]
  1287   1287   #endif
  1288         -    internal static extern int sqlite3_errcode(IntPtr db);
         1288  +    internal static extern SQLiteErrorCode sqlite3_errcode(IntPtr db);
  1289   1289   
  1290   1290   #if !PLATFORM_COMPACTFRAMEWORK
  1291   1291       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
  1292   1292   #else
  1293   1293       [DllImport(SQLITE_DLL)]
  1294   1294   #endif
  1295         -    internal static extern int sqlite3_extended_errcode(IntPtr db);
         1295  +    internal static extern SQLiteErrorCode sqlite3_extended_errcode(IntPtr db);
         1296  +
         1297  +//#if !PLATFORM_COMPACTFRAMEWORK
         1298  +//    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
         1299  +//#else
         1300  +//    [DllImport(SQLITE_DLL)]
         1301  +//#endif
         1302  +//    internal static extern IntPtr sqlite3_errstr(SQLiteErrorCode rc); /* 3.7.15+ */
  1296   1303   
  1297   1304       // Since sqlite3_log() takes a variable argument list, we have to overload declarations
  1298   1305       // for all possible calls.  For now, we are only exposing a single string, and 
  1299   1306       // depend on the caller to format the string.
  1300   1307   #if !PLATFORM_COMPACTFRAMEWORK
  1301   1308       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
  1302   1309   #else
................................................................................
  1305   1312       internal static extern void sqlite3_log(int iErrCode, byte[] zFormat);
  1306   1313   
  1307   1314   #if !PLATFORM_COMPACTFRAMEWORK
  1308   1315       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
  1309   1316   #else
  1310   1317       [DllImport(SQLITE_DLL)]
  1311   1318   #endif
  1312         -    internal static extern int sqlite3_file_control(IntPtr db, byte[] zDbName, int op, IntPtr pArg);
         1319  +    internal static extern SQLiteErrorCode sqlite3_file_control(IntPtr db, byte[] zDbName, int op, IntPtr pArg);
  1313   1320   
  1314   1321   #if !PLATFORM_COMPACTFRAMEWORK
  1315   1322       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
  1316   1323   #else
  1317   1324       [DllImport(SQLITE_DLL)]
  1318   1325   #endif
  1319   1326       internal static extern IntPtr sqlite3_backup_init(IntPtr destDb, byte[] zDestName, IntPtr sourceDb, byte[] zSourceName);
  1320   1327   
  1321   1328   #if !PLATFORM_COMPACTFRAMEWORK
  1322   1329       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
  1323   1330   #else
  1324   1331       [DllImport(SQLITE_DLL)]
  1325   1332   #endif
  1326         -    internal static extern int sqlite3_backup_step(IntPtr backup, int nPage);
         1333  +    internal static extern SQLiteErrorCode sqlite3_backup_step(IntPtr backup, int nPage);
  1327   1334   
  1328   1335   #if !PLATFORM_COMPACTFRAMEWORK
  1329   1336       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
  1330   1337   #else
  1331   1338       [DllImport(SQLITE_DLL)]
  1332   1339   #endif
  1333         -    internal static extern int sqlite3_backup_finish(IntPtr backup);
         1340  +    internal static extern SQLiteErrorCode sqlite3_backup_finish(IntPtr backup);
  1334   1341   
  1335   1342   #if !PLATFORM_COMPACTFRAMEWORK
  1336   1343       [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
  1337   1344   #else
  1338   1345       [DllImport(SQLITE_DLL)]
  1339   1346   #endif
  1340   1347       internal static extern int sqlite3_backup_remaining(IntPtr backup);

Changes to Tests/backup.eagle.

    31     31   set params(results) [list \
    32     32       "0 \\{1 1048576 1048576 1048576 1048576 1048576 1048576 1048576 1048576\
    33     33       1048576 1048576 10\\} 0\$" \
    34     34       "0 \\{1 1048576 1048576 1048576 1048576 1048576 1048576 1048576 1048576\
    35     35       1048576 1048576 10\\} 0\$" \
    36     36       "1 \\{System\\.Reflection\\.TargetInvocationException: Exception has been\
    37     37       thrown by the target of an invocation\\. --->\
    38         -    System\\.Data\\.SQLite\\.SQLiteException: SQLite error\\r\\nno such table:\
    39         -    t1\\r\\n.*?" \
           38  +    System\\.Data\\.SQLite\\.SQLiteException: SQL logic error or missing\
           39  +    database\\r\\nno such table: t1\\r\\n.*?" \
    40     40       "1 \\{System\\.Reflection\\.TargetInvocationException: Exception has been\
    41     41       thrown by the target of an invocation\\. --->\
    42         -    System\\.Data\\.SQLite\\.SQLiteException: SQLite error\\r\\nno such table:\
    43         -    t1\\r\\n.*?" \
           42  +    System\\.Data\\.SQLite\\.SQLiteException: SQL logic error or missing\
           43  +    database\\r\\nno such table: t1\\r\\n.*?" \
    44     44       "0 \\{1 1048576 1048576 1048576 1048576 1048576 1048576 1048576 1048576\
    45     45       1048576 1048576 10\\} 0\$" \
    46     46       "0 \\{1 1048576 1048576 1048576 1048576 1048576 1048576 1048576 1048576\
    47     47       1048576 1048576 10\\} 10283\$" \
    48     48       "0 \\{1 1048576 1048576 1048576 1048576 1048576 1048576 1048576 1048576\
    49     49       1048576 1048576 10\\} 0\$" \
    50     50       "1 \\{System\\.Reflection\\.TargetInvocationException: Exception has been\
    51     51       thrown by the target of an invocation\\. --->\
    52         -    System\\.Data\\.SQLite\\.SQLiteException: SQLite error\\r\\nno such table:\
    53         -    t1\\r\\n.*?" \
           52  +    System\\.Data\\.SQLite\\.SQLiteException: SQL logic error or missing\
           53  +    database\\r\\nno such table: t1\\r\\n.*?" \
    54     54       "0 \\{1 1048576 1048576 1048576 1048576 1048576 1048576 1048576 1048576\
    55     55       1048576 1048576 10\\} \\{\\}\$" \
    56     56       "0 \\{1 1048576 1048576 1048576 1048576 1048576 1048576 1048576 1048576\
    57     57       1048576 1048576 10\\} \\{System\\.Data\\.SQLite\\.SQLiteConnection main\
    58     58       System\\.Data\\.SQLite\\.SQLiteConnection main 1000 9284 10284 False\
    59     59       System\\.Data\\.SQLite\\.SQLiteConnection main\
    60     60       System\\.Data\\.SQLite\\.SQLiteConnection main 1000 8284 10284 False\

Changes to Tests/basic.eagle.

  1257   1257   
  1258   1258     unset -nocomplain result results errors code sql dataSource id db fileName
  1259   1259   } -constraints \
  1260   1260   {eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -match \
  1261   1261   regexp -result {^Ok System#CodeDom#Compiler#CompilerResults#\d+ \{\} 1\
  1262   1262   \{System\.Reflection\.TargetInvocationException: Exception has been thrown by\
  1263   1263   the target of an invocation\. ---> System\.Data\.SQLite\.SQLiteException:\
  1264         -Operation terminated by sqlite3_interrupt\(\).*$}}
         1264  +interrupted.*$}}
  1265   1265   
  1266   1266   ###############################################################################
  1267   1267   
  1268   1268   runTest {test data-1.23 {LINQ SQL_CONSTRAINTCOLUMNS resource} -body {
  1269   1269     object invoke -flags +NonPublic System.Data.SQLite.Properties.Resources \
  1270   1270         SQL_CONSTRAINTCOLUMNS
  1271   1271   } -constraints {eagle System.Data.SQLite System.Data.SQLite.Linq} -result {
................................................................................
  1512   1512       object invoke -flags +NonPublic System.Data.SQLite.UnsafeNativeMethods \
  1513   1513           sqlite3_config_int SQLITE_CONFIG_MEMSTATUS 1
  1514   1514     }
  1515   1515   
  1516   1516     unset -nocomplain result sqlite3
  1517   1517   } -constraints \
  1518   1518   {eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -match \
  1519         -regexp -result {^0 21 0 0 System#IntPtr#\d+ System#IntPtr#\d+ \d+ \d+ \d+ \d+\
  1520         -\d+ True True True True True True$}}
         1519  +regexp -result {^Ok Misuse Ok Ok System#IntPtr#\d+ System#IntPtr#\d+ \d+ \d+ \d+\
         1520  +\d+ \d+ True True True True True True$}}
  1521   1521   
  1522   1522   ###############################################################################
  1523   1523   
  1524   1524   runTest {test data-1.29 {SQLiteConnection.Open with SetDefaults=False} -setup {
  1525   1525     setupDb [set fileName data-1.29.db] "" "" "" "" SetDefaults=False
  1526   1526   } -body {
  1527   1527     set result [list]
................................................................................
  1755   1755   
  1756   1756     catch {object removecallback threadStart}
  1757   1757   
  1758   1758     unset -nocomplain t found i db fileName result directory
  1759   1759   
  1760   1760     rename threadStart ""
  1761   1761   } -constraints {eagle windows monoBug28 command.sql compile.DATA SQLite\
  1762         -System.Data.SQLite sqlite3_win32_set_directory} -result {0 0 True True}}
         1762  +System.Data.SQLite sqlite3_win32_set_directory} -result {Ok Ok True True}}
  1763   1763   
  1764   1764   ###############################################################################
  1765   1765   
  1766   1766   unset -nocomplain systemDataSQLiteDllFile systemDataSQLiteLinqDllFile \
  1767   1767       testExeFile testLinqExeFile northwindEfDbFile testLinqOutFile
  1768   1768   
  1769   1769   ###############################################################################
  1770   1770   
  1771   1771   runSQLiteTestEpilogue
  1772   1772   runTestEpilogue

Changes to Tests/tkt-ccfa69fc32.eagle.

    80     80   
    81     81     set result
    82     82   } -cleanup {
    83     83     unset -nocomplain code output error result add
    84     84   } -constraints {eagle monoToDo SQLite file_System.Data.SQLite.dll\
    85     85   file_System.Data.SQLite.Linq.dll file_testlinq.exe file_northwindEF.db} -match \
    86     86   glob -result {0 {1581 1730 1833 2116 2139} 0 {System.Data.UpdateException: *\
    87         ----> System.Data.SQLite.SQLiteException: Abort due to constraint violation
           87  +---> System.Data.SQLite.SQLiteException: constraint failed
    88     88   PRIMARY KEY must be unique
    89     89   *} 0 {1 2 3 4 5 6 7 8 9 10 1576 1577 1578 1579 1580 1581 1730 1833 2116 2139}}}
    90     90   
    91     91   ###############################################################################
    92     92   
    93     93   unset -nocomplain systemDataSQLiteDllFile systemDataSQLiteLinqDllFile \
    94     94       testLinqExeFile northwindEfDbFile
    95     95   
    96     96   ###############################################################################
    97     97   
    98     98   runSQLiteTestEpilogue
    99     99   runTestEpilogue

Changes to readme.htm.

     1      1   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
     2      2   <html>
     3      3   <head>
     4      4   <title></title>
     5      5   </head>
     6      6   <body>
     7      7   ADO.NET SQLite Data Provider<br />
     8         -Version 1.0.82.0 September 3, 2012<br />
            8  +Version 1.0.83.0 November XX, 2012 <font color="red">(release scheduled)</font><br />
     9      9   Using <a href="http://www.sqlite.org/releaselog/3_7_14.html">SQLite 3.7.14</a><br />
    10     10   Originally written by Robert Simpson<br />
    11     11   Released to the public domain, use at your own risk!<br />
    12     12   Official provider website:&nbsp;<a href="http://system.data.sqlite.org/">http://system.data.sqlite.org/</a><br />
    13     13   Legacy versions:&nbsp;<a href="http://sqlite.phxsoftware.com/">http://sqlite.phxsoftware.com/</a><br />
    14     14   <br />
    15     15   The current development version can be downloaded from <a href="http://system.data.sqlite.org/index.html/timeline?y=ci">
................................................................................
   182    182   at the sqlite.org website.&nbsp; Several additional pieces are compiled on top of
   183    183   it to extend its functionality, but the core engine's source is not changed.</p>
   184    184   <p>
   185    185   </p>
   186    186   
   187    187   <h2><b>Version History</b></h2>
   188    188   
          189  +<p>
          190  +    <b>1.0.83.0 - November XX, 2012</b>
          191  +</p>
          192  +<ul>
          193  +    <li>Updated to <a href="http://www.sqlite.org/releaselog/3_7_14.html">SQLite 3.7.14</a>.</li>
          194  +    <li>Add an overload of the SQLiteLog.LogMessage method that takes a single string argument.</li>
          195  +    <li>All applicable calls into the SQLite core library now return a SQLiteErrorCode instead of an integer error code.</li>
          196  +    <li>When available, the new sqlite3_errstr function from the core library is used to get the error message for a specific return code.</li>
          197  +    <li>The SetMemoryStatus, Shutdown, ResultCode, ExtendedResultCode, and SetAvRetry methods of the SQLiteConnection class now return a SQLiteErrorCode instead of an integer error code.&nbsp;<b>** Potentially Incompatible Change **</b></li>
          198  +    <li>The public constructor for the SQLiteException now takes a SQLiteErrorCode instead of an integer error code.&nbsp;<b>** Potentially Incompatible Change **</b></li>
          199  +    <li>The ErrorCode field of the LogEventArgs is now an object instead of an integer.&nbsp;<b>** Potentially Incompatible Change **</b></li>
          200  +    <li>The names and messages associated with the SQLiteErrorCode enumeration values have been normalized to match those in the SQLite core library.&nbsp;<b>** Potentially Incompatible Change **</b></li>
          201  +</ul>
   189    202   <p>
   190    203       <b>1.0.82.0 - September 3, 2012</b>
   191    204   </p>
   192    205   <ul>
   193    206       <li>Updated to <a href="http://www.sqlite.org/releaselog/3_7_14.html">SQLite 3.7.14</a>.</li>
   194    207       <li>Properly handle quoted data source values in the connection string. Fix for [8c3bee31c8].</li>
   195    208       <li>The <a href="http://nuget.org/packages/System.Data.SQLite">primary NuGet package</a> now supports x86 / x64 and the .NET Framework 2.0 / 4.0 (i.e. in a single package).</li>

Changes to test/TestCases.cs.

  1618   1618           SQLiteConnection cnn = new SQLiteConnection(_cnnstring.ConnectionString);
  1619   1619   
  1620   1620           cnn.Open();
  1621   1621   
  1622   1622           // Turn on extended result codes
  1623   1623           cnn.SetExtendedResultCodes(true);
  1624   1624   
  1625         -        int rc = cnn.ResultCode();
  1626         -        int xrc = cnn.ExtendedResultCode();
         1625  +        SQLiteErrorCode rc = cnn.ResultCode();
         1626  +        SQLiteErrorCode xrc = cnn.ExtendedResultCode();
  1627   1627   
  1628   1628           cnn.Close();
  1629   1629         }
  1630   1630       }
  1631   1631   
  1632   1632       //Logging EventHandler
  1633   1633       public void OnLogEvent(object sender, LogEventArgs logEvent)
  1634   1634       {
  1635         -        int err_code = logEvent.ErrorCode;
         1635  +        object errorCode = logEvent.ErrorCode;
  1636   1636           string err_msg = logEvent.Message;
  1637   1637           logevents++;
  1638   1638       }
  1639   1639   
  1640   1640       /// <summary>
  1641   1641       /// Tests SQLITE_CONFIG_LOG support.
  1642   1642       /// </summary>

Changes to www/news.wiki.

     1      1   <title>News</title>
     2      2   
     3      3   <b>Version History</b>
     4      4   
            5  +<p>
            6  +    <b>1.0.83.0 - November XX, 2012 <font color="red">(release scheduled)</font></b>
            7  +</p>
            8  +<ul>
            9  +    <li>Updated to [http://www.sqlite.org/releaselog/3_7_14.html|SQLite 3.7.14].</li>
           10  +    <li>Add an overload of the SQLiteLog.LogMessage method that takes a single string argument.</li>
           11  +    <li>All applicable calls into the SQLite core library now return a SQLiteErrorCode instead of an integer error code.</li>
           12  +    <li>When available, the new sqlite3_errstr function from the core library is used to get the error message for a specific return code.</li>
           13  +    <li>The SetMemoryStatus, Shutdown, ResultCode, ExtendedResultCode, and SetAvRetry methods of the SQLiteConnection class now return a SQLiteErrorCode instead of an integer error code.&nbsp;<b>** Potentially Incompatible Change **</b></li>
           14  +    <li>The public constructor for the SQLiteException now takes a SQLiteErrorCode instead of an integer error code.&nbsp;<b>** Potentially Incompatible Change **</b></li>
           15  +    <li>The ErrorCode field of the LogEventArgs is now an object instead of an integer.&nbsp;<b>** Potentially Incompatible Change **</b></li>
           16  +    <li>The names and messages associated with the SQLiteErrorCode enumeration values have been normalized to match those in the SQLite core library.&nbsp;<b>** Potentially Incompatible Change **</b></li>
           17  +</ul>
     5     18   <p>
     6     19       <b>1.0.82.0 - September 3, 2012</b>
     7     20   </p>
     8     21   <ul>
     9     22       <li>Updated to [http://www.sqlite.org/releaselog/3_7_14.html|SQLite 3.7.14].</li>
    10     23       <li>Properly handle quoted data source values in the connection string. Fix for [8c3bee31c8].</li>
    11     24       <li>The [http://nuget.org/packages/System.Data.SQLite|primary NuGet package] now supports x86 / x64 and the .NET Framework 2.0 / 4.0 (i.e. in a single package).</li>