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

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

Overview
Comment:Acquire and hold a static data lock while checking if the native SQLite library has been initialized to prevent superfluous error messages. Fix for ticket [72905c9a77].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: fb22170bc8b5033bc85977f91f511c2466091e4e
User & Date: mistachkin 2012-02-28 15:07:56
References
2012-02-28
15:08 Ticket [72905c9a77] SQLite error (21): misuse at line 112492 of [ebd01a8def] status still Open with 2 other changes artifact: 33945d6ab6 user: mistachkin
Context
2012-02-28
17:35
Stop using the 'StringComparison.InvariantCulture*' values. check-in: 3137eacf49 user: mistachkin tags: trunk
15:07
Acquire and hold a static data lock while checking if the native SQLite library has been initialized to prevent superfluous error messages. Fix for ticket [72905c9a77]. check-in: fb22170bc8 user: mistachkin tags: trunk
2012-02-24
16:10
Revise previous commit, add parenthesis to make the MSBuild conditional correct in all cases. check-in: 700ca65faa user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

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

    20     20     internal delegate void SQLiteLogCallback(IntPtr puser, int err_code, IntPtr message);
    21     21   
    22     22     /// <summary>
    23     23     /// This class implements SQLiteBase completely, and is the guts of the code that interop's SQLite with .NET
    24     24     /// </summary>
    25     25     internal class SQLite3 : SQLiteBase
    26     26     {
           27  +    private static object syncRoot = new object();
           28  +
    27     29       //
    28     30       // NOTE: This is the public key for the System.Data.SQLite assembly.  If you change the
    29     31       //       SNK file, you will need to change this as well.
    30     32       //
    31     33       internal const string PublicKey =
    32     34           "002400000480000094000000060200000024000052534131000400000100010005a288de5687c4e1" +
    33     35           "b621ddff5d844727418956997f475eb829429e411aff3e93f97b70de698b972640925bdd44280df0" +
................................................................................
  1387   1389       /// </summary>
  1388   1390       /// <returns>
  1389   1391       /// A boolean indicating whether or not the SQLite core library has been
  1390   1392       /// initialized for the current process.
  1391   1393       /// </returns>
  1392   1394       internal static bool StaticIsInitialized()
  1393   1395       {
  1394         -#if !PLATFORM_COMPACTFRAMEWORK
  1395   1396           //
  1396         -        // NOTE: Save the state of the logging class and then restore it
  1397         -        //       after we are done to avoid logging too many false errors.
         1397  +        // BUGFIX: Prevent races with other threads for this entire block, due
         1398  +        //         to the try/finally semantics.  See ticket [72905c9a77].
  1398   1399           //
  1399         -        bool savedEnabled = SQLiteLog.Enabled;
  1400         -        SQLiteLog.Enabled = false;
  1401         -
  1402         -        try
         1400  +        lock (syncRoot)
  1403   1401           {
  1404         -#endif
         1402  +#if !PLATFORM_COMPACTFRAMEWORK
         1403  +            //
         1404  +            // NOTE: Save the state of the logging class and then restore it
         1405  +            //       after we are done to avoid logging too many false errors.
  1405   1406               //
  1406         -            // NOTE: This method [ab]uses the fact that SQLite will always
  1407         -            //       return SQLITE_ERROR for any unknown configuration option
  1408         -            //       *unless* the SQLite library has already been initialized.
  1409         -            //       In that case it will always return SQLITE_MISUSE.
  1410         -            //
  1411         -            int rc = UnsafeNativeMethods.sqlite3_config(
  1412         -                (int)SQLiteConfigOpsEnum.SQLITE_CONFIG_NONE, null, (IntPtr)0);
         1407  +            bool savedEnabled = SQLiteLog.Enabled;
         1408  +            SQLiteLog.Enabled = false;
  1413   1409   
  1414         -            return (rc == /* SQLITE_MISUSE */ 21);
         1410  +            try
         1411  +            {
         1412  +#endif
         1413  +                //
         1414  +                // NOTE: This method [ab]uses the fact that SQLite will always
         1415  +                //       return SQLITE_ERROR for any unknown configuration option
         1416  +                //       *unless* the SQLite library has already been initialized.
         1417  +                //       In that case it will always return SQLITE_MISUSE.
         1418  +                //
         1419  +                int rc = UnsafeNativeMethods.sqlite3_config(
         1420  +                    (int)SQLiteConfigOpsEnum.SQLITE_CONFIG_NONE, null, (IntPtr)0);
         1421  +
         1422  +                return (rc == /* SQLITE_MISUSE */ 21);
  1415   1423   #if !PLATFORM_COMPACTFRAMEWORK
  1416         -        }
  1417         -        finally
  1418         -        {
  1419         -            SQLiteLog.Enabled = savedEnabled;
  1420         -        }
         1424  +            }
         1425  +            finally
         1426  +            {
         1427  +                SQLiteLog.Enabled = savedEnabled;
         1428  +            }
  1421   1429   #endif
         1430  +        }
  1422   1431       }
  1423   1432   
  1424   1433       /// <summary>
  1425   1434       /// Helper function to retrieve a column of data from an active statement.
  1426   1435       /// </summary>
  1427   1436       /// <param name="stmt">The statement being step()'d through</param>
  1428   1437       /// <param name="index">The column index to retrieve</param>