System.Data.SQLite
Check-in [6fbb8f60e9]
Not logged in

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

Overview
Comment:Refactor how logging flags and exception handling are performed.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6fbb8f60e9f1d27b5ec83d1cfa7c209c8c4455f3
User & Date: mistachkin 2017-10-10 21:40:50
Context
2017-10-10
21:45
Use the 'getTemporaryDirectory' helper procedure in the test suite. check-in: f4e188e696 user: mistachkin tags: trunk
21:41
Merge updates from trunk. check-in: 0b70bd2e0e user: mistachkin tags: sessions
21:40
Refactor how logging flags and exception handling are performed. check-in: 6fbb8f60e9 user: mistachkin tags: trunk
05:53
Pickup further release archive verification tool changes from upstream. check-in: 2ada6a698f user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

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

  1340   1340         SQLiteConnectionFlags flags =
  1341   1341             (cnn != null) ? cnn.Flags : SQLiteConnectionFlags.Default;
  1342   1342   
  1343   1343         if (
  1344   1344   #if !PLATFORM_COMPACTFRAMEWORK
  1345   1345             ForceLogPrepare() ||
  1346   1346   #endif
  1347         -          ((flags & SQLiteConnectionFlags.LogPrepare) == SQLiteConnectionFlags.LogPrepare))
         1347  +          HelperMethods.LogPrepare(flags))
  1348   1348         {
  1349   1349             if ((strSql == null) || (strSql.Length == 0) || (strSql.Trim().Length == 0))
  1350   1350                 SQLiteLog.LogMessage("Preparing {<nothing>}...");
  1351   1351             else
  1352   1352                 SQLiteLog.LogMessage(HelperMethods.StringFormat(
  1353   1353                     CultureInfo.CurrentCulture, "Preparing {{{0}}}...", strSql));
  1354   1354         }
................................................................................
  1608   1608               handleIntPtr, index, typeof(Byte[]), (value != null) ? ToHexadecimalString(value) : "<null>"));
  1609   1609       }
  1610   1610   
  1611   1611       internal override void Bind_Double(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, double value)
  1612   1612       {
  1613   1613           SQLiteStatementHandle handle = stmt._sqlite_stmt;
  1614   1614   
  1615         -        if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
         1615  +        if (HelperMethods.LogBind(flags))
  1616   1616           {
  1617   1617               LogBind(handle, index, value);
  1618   1618           }
  1619   1619   
  1620   1620   #if !PLATFORM_COMPACTFRAMEWORK
  1621   1621           SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_double(handle, index, value);
  1622   1622           if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
................................................................................
  1628   1628   #endif
  1629   1629       }
  1630   1630   
  1631   1631       internal override void Bind_Int32(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, int value)
  1632   1632       {
  1633   1633           SQLiteStatementHandle handle = stmt._sqlite_stmt;
  1634   1634   
  1635         -        if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
         1635  +        if (HelperMethods.LogBind(flags))
  1636   1636           {
  1637   1637               LogBind(handle, index, value);
  1638   1638           }
  1639   1639   
  1640   1640           SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int(handle, index, value);
  1641   1641           if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1642   1642       }
  1643   1643   
  1644   1644       internal override void Bind_UInt32(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, uint value)
  1645   1645       {
  1646   1646           SQLiteStatementHandle handle = stmt._sqlite_stmt;
  1647   1647   
  1648         -        if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
         1648  +        if (HelperMethods.LogBind(flags))
  1649   1649           {
  1650   1650               LogBind(handle, index, value);
  1651   1651           }
  1652   1652   
  1653   1653           SQLiteErrorCode n;
  1654   1654   
  1655   1655           if ((flags & SQLiteConnectionFlags.BindUInt32AsInt64) == SQLiteConnectionFlags.BindUInt32AsInt64)
................................................................................
  1671   1671           if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1672   1672       }
  1673   1673   
  1674   1674       internal override void Bind_Int64(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, long value)
  1675   1675       {
  1676   1676           SQLiteStatementHandle handle = stmt._sqlite_stmt;
  1677   1677   
  1678         -        if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
         1678  +        if (HelperMethods.LogBind(flags))
  1679   1679           {
  1680   1680               LogBind(handle, index, value);
  1681   1681           }
  1682   1682   
  1683   1683   #if !PLATFORM_COMPACTFRAMEWORK
  1684   1684           SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int64(handle, index, value);
  1685   1685           if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
................................................................................
  1691   1691   #endif
  1692   1692       }
  1693   1693   
  1694   1694       internal override void Bind_UInt64(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, ulong value)
  1695   1695       {
  1696   1696           SQLiteStatementHandle handle = stmt._sqlite_stmt;
  1697   1697   
  1698         -        if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
         1698  +        if (HelperMethods.LogBind(flags))
  1699   1699           {
  1700   1700               LogBind(handle, index, value);
  1701   1701           }
  1702   1702   
  1703   1703   #if !PLATFORM_COMPACTFRAMEWORK
  1704   1704           SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_uint64(handle, index, value);
  1705   1705           if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
................................................................................
  1711   1711   #endif
  1712   1712       }
  1713   1713   
  1714   1714       internal override void Bind_Boolean(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, bool value)
  1715   1715       {
  1716   1716           SQLiteStatementHandle handle = stmt._sqlite_stmt;
  1717   1717   
  1718         -        if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
         1718  +        if (HelperMethods.LogBind(flags))
  1719   1719           {
  1720   1720               LogBind(handle, index, value);
  1721   1721           }
  1722   1722   
  1723   1723           int value2 = value ? 1 : 0;
  1724   1724   
  1725   1725           SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int(handle, index, value2);
................................................................................
  1726   1726           if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1727   1727       }
  1728   1728   
  1729   1729       internal override void Bind_Text(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, string value)
  1730   1730       {
  1731   1731           SQLiteStatementHandle handle = stmt._sqlite_stmt;
  1732   1732   
  1733         -        if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
         1733  +        if (HelperMethods.LogBind(flags))
  1734   1734           {
  1735   1735               LogBind(handle, index, value);
  1736   1736           }
  1737   1737   
  1738   1738           byte[] b = ToUTF8(value);
  1739   1739   
  1740         -        if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
         1740  +        if (HelperMethods.LogBind(flags))
  1741   1741           {
  1742   1742               LogBind(handle, index, b);
  1743   1743           }
  1744   1744   
  1745   1745           SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_text(handle, index, b, b.Length - 1, (IntPtr)(-1));
  1746   1746           if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1747   1747       }
  1748   1748   
  1749   1749       internal override void Bind_DateTime(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, DateTime dt)
  1750   1750       {
  1751   1751           SQLiteStatementHandle handle = stmt._sqlite_stmt;
  1752   1752   
  1753         -        if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
         1753  +        if (HelperMethods.LogBind(flags))
  1754   1754           {
  1755   1755               LogBind(handle, index, dt);
  1756   1756           }
  1757   1757   
  1758   1758           if ((flags & SQLiteConnectionFlags.BindDateTimeWithKind) == SQLiteConnectionFlags.BindDateTimeWithKind)
  1759   1759           {
  1760   1760               if ((_datetimeKind != DateTimeKind.Unspecified) &&
................................................................................
  1770   1770   
  1771   1771           switch (_datetimeFormat)
  1772   1772           {
  1773   1773               case SQLiteDateFormats.Ticks:
  1774   1774                   {
  1775   1775                       long value = dt.Ticks;
  1776   1776   
  1777         -                    if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
         1777  +                    if (HelperMethods.LogBind(flags))
  1778   1778                       {
  1779   1779                           LogBind(handle, index, value);
  1780   1780                       }
  1781   1781   
  1782   1782   #if !PLATFORM_COMPACTFRAMEWORK
  1783   1783                       SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int64(handle, index, value);
  1784   1784                       if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
................................................................................
  1791   1791                       throw new NotImplementedException();
  1792   1792   #endif
  1793   1793                   }
  1794   1794               case SQLiteDateFormats.JulianDay:
  1795   1795                   {
  1796   1796                       double value = ToJulianDay(dt);
  1797   1797   
  1798         -                    if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
         1798  +                    if (HelperMethods.LogBind(flags))
  1799   1799                       {
  1800   1800                           LogBind(handle, index, value);
  1801   1801                       }
  1802   1802   
  1803   1803   #if !PLATFORM_COMPACTFRAMEWORK
  1804   1804                       SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_double(handle, index, value);
  1805   1805                       if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
................................................................................
  1812   1812                       throw new NotImplementedException();
  1813   1813   #endif
  1814   1814                   }
  1815   1815               case SQLiteDateFormats.UnixEpoch:
  1816   1816                   {
  1817   1817                       long value = Convert.ToInt64(dt.Subtract(UnixEpoch).TotalSeconds);
  1818   1818   
  1819         -                    if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
         1819  +                    if (HelperMethods.LogBind(flags))
  1820   1820                       {
  1821   1821                           LogBind(handle, index, value);
  1822   1822                       }
  1823   1823   
  1824   1824   #if !PLATFORM_COMPACTFRAMEWORK
  1825   1825                       SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int64(handle, index, value);
  1826   1826                       if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
................................................................................
  1833   1833                       throw new NotImplementedException();
  1834   1834   #endif
  1835   1835                   }
  1836   1836               default:
  1837   1837                   {
  1838   1838                       byte[] b = ToUTF8(dt);
  1839   1839   
  1840         -                    if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
         1840  +                    if (HelperMethods.LogBind(flags))
  1841   1841                       {
  1842   1842                           LogBind(handle, index, b);
  1843   1843                       }
  1844   1844   
  1845   1845                       SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_text(handle, index, b, b.Length - 1, (IntPtr)(-1));
  1846   1846                       if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1847   1847                       break;
................................................................................
  1849   1849           }
  1850   1850       }
  1851   1851   
  1852   1852       internal override void Bind_Blob(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, byte[] blobData)
  1853   1853       {
  1854   1854           SQLiteStatementHandle handle = stmt._sqlite_stmt;
  1855   1855   
  1856         -        if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
         1856  +        if (HelperMethods.LogBind(flags))
  1857   1857           {
  1858   1858               LogBind(handle, index, blobData);
  1859   1859           }
  1860   1860   
  1861   1861           SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_blob(handle, index, blobData, blobData.Length, (IntPtr)(-1));
  1862   1862           if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1863   1863       }
  1864   1864   
  1865   1865       internal override void Bind_Null(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index)
  1866   1866       {
  1867   1867           SQLiteStatementHandle handle = stmt._sqlite_stmt;
  1868   1868   
  1869         -        if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
         1869  +        if (HelperMethods.LogBind(flags))
  1870   1870           {
  1871   1871               LogBind(handle, index);
  1872   1872           }
  1873   1873   
  1874   1874           SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_null(handle, index);
  1875   1875           if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1876   1876       }
  1877   1877   
  1878   1878       internal override int Bind_ParamCount(SQLiteStatement stmt, SQLiteConnectionFlags flags)
  1879   1879       {
  1880   1880           SQLiteStatementHandle handle = stmt._sqlite_stmt;
  1881   1881           int value = UnsafeNativeMethods.sqlite3_bind_parameter_count(handle);
  1882   1882   
  1883         -        if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
         1883  +        if (HelperMethods.LogBind(flags))
  1884   1884           {
  1885   1885               IntPtr handleIntPtr = handle;
  1886   1886   
  1887   1887               SQLiteLog.LogMessage(HelperMethods.StringFormat(
  1888   1888                   CultureInfo.CurrentCulture,
  1889   1889                   "Statement {0} paramter count is {1}.",
  1890   1890                   handleIntPtr, value));
................................................................................
  1901   1901   #if !SQLITE_STANDARD
  1902   1902           int len = 0;
  1903   1903           name = UTF8ToString(UnsafeNativeMethods.sqlite3_bind_parameter_name_interop(handle, index, ref len), len);
  1904   1904   #else
  1905   1905           name = UTF8ToString(UnsafeNativeMethods.sqlite3_bind_parameter_name(handle, index), -1);
  1906   1906   #endif
  1907   1907   
  1908         -        if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
         1908  +        if (HelperMethods.LogBind(flags))
  1909   1909           {
  1910   1910               IntPtr handleIntPtr = handle;
  1911   1911   
  1912   1912               SQLiteLog.LogMessage(HelperMethods.StringFormat(
  1913   1913                   CultureInfo.CurrentCulture,
  1914   1914                   "Statement {0} paramter #{1} name is {{{2}}}.",
  1915   1915                   handleIntPtr, index, name));
................................................................................
  1919   1919       }
  1920   1920   
  1921   1921       internal override int Bind_ParamIndex(SQLiteStatement stmt, SQLiteConnectionFlags flags, string paramName)
  1922   1922       {
  1923   1923           SQLiteStatementHandle handle = stmt._sqlite_stmt;
  1924   1924           int index = UnsafeNativeMethods.sqlite3_bind_parameter_index(handle, ToUTF8(paramName));
  1925   1925   
  1926         -        if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
         1926  +        if (HelperMethods.LogBind(flags))
  1927   1927           {
  1928   1928               IntPtr handleIntPtr = handle;
  1929   1929   
  1930   1930               SQLiteLog.LogMessage(HelperMethods.StringFormat(
  1931   1931                   CultureInfo.CurrentCulture,
  1932   1932                   "Statement {0} paramter index of name {{{1}}} is #{2}.",
  1933   1933                   handleIntPtr, paramName, index));
................................................................................
  2535   2535       /// The flags for the associated <see cref="SQLiteConnection" /> object instance.
  2536   2536       /// </param>
  2537   2537       internal override void CreateModule(SQLiteModule module, SQLiteConnectionFlags flags)
  2538   2538       {
  2539   2539           if (module == null)
  2540   2540               throw new ArgumentNullException("module");
  2541   2541   
  2542         -        if ((flags & SQLiteConnectionFlags.NoLogModule) != SQLiteConnectionFlags.NoLogModule)
         2542  +        if (HelperMethods.NoLogModule(flags))
  2543   2543           {
  2544         -            module.LogErrors = ((flags & SQLiteConnectionFlags.LogModuleError) == SQLiteConnectionFlags.LogModuleError);
  2545         -            module.LogExceptions = ((flags & SQLiteConnectionFlags.LogModuleException) == SQLiteConnectionFlags.LogModuleException);
         2544  +            module.LogErrors = HelperMethods.LogModuleError(flags);
         2545  +            module.LogExceptions = HelperMethods.LogModuleException(flags);
  2546   2546           }
  2547   2547   
  2548   2548           if (_sql == null)
  2549   2549               throw new SQLiteException("connection has an invalid handle");
  2550   2550   
  2551   2551           bool isLoadNeeded = false;
  2552   2552           string fileName = GetShimExtensionFileName(ref isLoadNeeded);

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

   256    256                   {
   257    257                       base.Bind_DateTime(stmt, flags, index, dt);
   258    258                       break;
   259    259                   }
   260    260               default:
   261    261                   {
   262    262   #if !PLATFORM_COMPACTFRAMEWORK
   263         -                    if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
          263  +                    if (HelperMethods.LogBind(flags))
   264    264                       {
   265    265                           SQLiteStatementHandle handle =
   266    266                               (stmt != null) ? stmt._sqlite_stmt : null;
   267    267   
   268    268                           LogBind(handle, index, dt);
   269    269                       }
   270    270   #endif
................................................................................
   276    276       }
   277    277   
   278    278       internal override void Bind_Text(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, string value)
   279    279       {
   280    280           SQLiteStatementHandle handle = stmt._sqlite_stmt;
   281    281   
   282    282   #if !PLATFORM_COMPACTFRAMEWORK
   283         -        if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
          283  +        if (HelperMethods.LogBind(flags))
   284    284           {
   285    285               LogBind(handle, index, value);
   286    286           }
   287    287   #endif
   288    288   
   289    289           SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_text16(handle, index, value, value.Length * 2, (IntPtr)(-1));
   290    290           if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());

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

  1976   1976                   //
  1977   1977                   if (pages == 0)
  1978   1978                       break;
  1979   1979               }
  1980   1980           }
  1981   1981           catch (Exception e)
  1982   1982           {
  1983         -            if ((_flags & SQLiteConnectionFlags.LogBackup) == SQLiteConnectionFlags.LogBackup)
         1983  +            if (HelperMethods.LogBackup(_flags))
  1984   1984               {
  1985   1985                   SQLiteLog.LogMessage(HelperMethods.StringFormat(
  1986   1986                       CultureInfo.CurrentCulture,
  1987   1987                       "Caught exception while backing up database: {0}", e));
  1988   1988               }
  1989   1989   
  1990   1990               throw;
................................................................................
  6307   6307   
  6308   6308               return eventArgs.ReturnCode;
  6309   6309           }
  6310   6310           catch (Exception e) /* NOTE: Must catch ALL. */
  6311   6311           {
  6312   6312               try
  6313   6313               {
  6314         -                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
  6315         -                        SQLiteConnectionFlags.LogCallbackException)
         6314  +                if (HelperMethods.LogCallbackExceptions(_flags))
  6316   6315                   {
  6317   6316                       SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
  6318   6317                           HelperMethods.StringFormat(CultureInfo.CurrentCulture,
  6319         -                        "Caught exception in \"Progress\" method: {1}",
  6320         -                        e)); /* throw */
         6318  +                        UnsafeNativeMethods.ExceptionMessageFormat,
         6319  +                        "Progress", e)); /* throw */
  6321   6320                   }
  6322   6321               }
  6323   6322               catch
  6324   6323               {
  6325   6324                   // do nothing.
  6326   6325               }
  6327   6326           }
................................................................................
  6360   6359   
  6361   6360               return eventArgs.ReturnCode;
  6362   6361           }
  6363   6362           catch (Exception e) /* NOTE: Must catch ALL. */
  6364   6363           {
  6365   6364               try
  6366   6365               {
  6367         -                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
  6368         -                        SQLiteConnectionFlags.LogCallbackException)
         6366  +                if (HelperMethods.LogCallbackExceptions(_flags))
  6369   6367                   {
  6370   6368                       SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
  6371   6369                           HelperMethods.StringFormat(CultureInfo.CurrentCulture,
  6372         -                        "Caught exception in \"Authorize\" method: {1}",
  6373         -                        e)); /* throw */
         6370  +                        UnsafeNativeMethods.ExceptionMessageFormat,
         6371  +                        "Authorize", e)); /* throw */
  6374   6372                   }
  6375   6373               }
  6376   6374               catch
  6377   6375               {
  6378   6376                   // do nothing.
  6379   6377               }
  6380   6378           }
................................................................................
  6409   6407                 (UpdateEventType)type,
  6410   6408                 rowid));
  6411   6409           }
  6412   6410           catch (Exception e) /* NOTE: Must catch ALL. */
  6413   6411           {
  6414   6412               try
  6415   6413               {
  6416         -                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
  6417         -                        SQLiteConnectionFlags.LogCallbackException)
         6414  +                if (HelperMethods.LogCallbackExceptions(_flags))
  6418   6415                   {
  6419   6416                       SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
  6420   6417                           HelperMethods.StringFormat(CultureInfo.CurrentCulture,
  6421         -                        "Caught exception in \"Update\" method: {1}",
  6422         -                        e)); /* throw */
         6418  +                        UnsafeNativeMethods.ExceptionMessageFormat,
         6419  +                        "Update", e)); /* throw */
  6423   6420                   }
  6424   6421               }
  6425   6422               catch
  6426   6423               {
  6427   6424                   // do nothing.
  6428   6425               }
  6429   6426           }
................................................................................
  6500   6497                   _traceHandler(this, new TraceEventArgs(
  6501   6498                     SQLiteBase.UTF8ToString(statement, -1)));
  6502   6499           }
  6503   6500           catch (Exception e) /* NOTE: Must catch ALL. */
  6504   6501           {
  6505   6502               try
  6506   6503               {
  6507         -                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
  6508         -                        SQLiteConnectionFlags.LogCallbackException)
         6504  +                if (HelperMethods.LogCallbackExceptions(_flags))
  6509   6505                   {
  6510   6506                       SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
  6511   6507                           HelperMethods.StringFormat(CultureInfo.CurrentCulture,
  6512         -                        "Caught exception in \"Trace\" method: {1}",
  6513         -                        e)); /* throw */
         6508  +                        UnsafeNativeMethods.ExceptionMessageFormat,
         6509  +                        "Trace", e)); /* throw */
  6514   6510                   }
  6515   6511               }
  6516   6512               catch
  6517   6513               {
  6518   6514                   // do nothing.
  6519   6515               }
  6520   6516           }
................................................................................
  6562   6558   
  6563   6559               return (e.AbortTransaction == true) ? 1 : 0;
  6564   6560           }
  6565   6561           catch (Exception e) /* NOTE: Must catch ALL. */
  6566   6562           {
  6567   6563               try
  6568   6564               {
  6569         -                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
  6570         -                        SQLiteConnectionFlags.LogCallbackException)
         6565  +                if (HelperMethods.LogCallbackExceptions(_flags))
  6571   6566                   {
  6572   6567                       SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
  6573   6568                           HelperMethods.StringFormat(CultureInfo.CurrentCulture,
  6574         -                        "Caught exception in \"Commit\" method: {1}",
  6575         -                        e)); /* throw */
         6569  +                        UnsafeNativeMethods.ExceptionMessageFormat,
         6570  +                        "Commit", e)); /* throw */
  6576   6571                   }
  6577   6572               }
  6578   6573               catch
  6579   6574               {
  6580   6575                   // do nothing.
  6581   6576               }
  6582   6577           }
................................................................................
  6604   6599               if (_rollbackHandler != null)
  6605   6600                   _rollbackHandler(this, EventArgs.Empty);
  6606   6601           }
  6607   6602           catch (Exception e) /* NOTE: Must catch ALL. */
  6608   6603           {
  6609   6604               try
  6610   6605               {
  6611         -                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
  6612         -                        SQLiteConnectionFlags.LogCallbackException)
         6606  +                if (HelperMethods.LogCallbackExceptions(_flags))
  6613   6607                   {
  6614   6608                       SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
  6615   6609                           HelperMethods.StringFormat(CultureInfo.CurrentCulture,
  6616         -                        "Caught exception in \"Rollback\" method: {1}",
  6617         -                        e)); /* throw */
         6610  +                        UnsafeNativeMethods.ExceptionMessageFormat,
         6611  +                        "Rollback", e)); /* throw */
  6618   6612                   }
  6619   6613               }
  6620   6614               catch
  6621   6615               {
  6622   6616                   // do nothing.
  6623   6617               }
  6624   6618           }

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

   412    412               SetReturnValue(context,
   413    413                   Invoke(ConvertParams(nArgs, argsptr))); /* throw */
   414    414           }
   415    415           catch (Exception e) /* NOTE: Must catch ALL. */
   416    416           {
   417    417               try
   418    418               {
   419         -                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
   420         -                        SQLiteConnectionFlags.LogCallbackException)
          419  +                if (HelperMethods.LogCallbackExceptions(_flags))
   421    420                   {
   422    421                       SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
   423    422                           HelperMethods.StringFormat(CultureInfo.CurrentCulture,
   424         -                        "Caught exception in \"Invoke\" method: {0}",
   425         -                        e)); /* throw */
          423  +                        UnsafeNativeMethods.ExceptionMessageFormat,
          424  +                        "Invoke", e)); /* throw */
   426    425                   }
   427    426               }
   428    427               catch
   429    428               {
   430    429                   // do nothing.
   431    430               }
   432    431           }
................................................................................
   450    449               return Compare(SQLiteConvert.UTF8ToString(ptr1, len1),
   451    450                   SQLiteConvert.UTF8ToString(ptr2, len2)); /* throw */
   452    451           }
   453    452           catch (Exception e) /* NOTE: Must catch ALL. */
   454    453           {
   455    454               try
   456    455               {
   457         -                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
   458         -                        SQLiteConnectionFlags.LogCallbackException)
          456  +                if (HelperMethods.LogCallbackExceptions(_flags))
   459    457                   {
   460    458                       SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
   461    459                           HelperMethods.StringFormat(CultureInfo.CurrentCulture,
   462         -                        "Caught exception in \"Compare\" (UTF8) method: {0}",
   463         -                        e)); /* throw */
          460  +                        UnsafeNativeMethods.ExceptionMessageFormat,
          461  +                        "Compare", e)); /* throw */
   464    462                   }
   465    463               }
   466    464               catch
   467    465               {
   468    466                   // do nothing.
   469    467               }
   470    468           }
................................................................................
   497    495               return Compare(SQLite3_UTF16.UTF16ToString(ptr1, len1),
   498    496                   SQLite3_UTF16.UTF16ToString(ptr2, len2)); /* throw */
   499    497           }
   500    498           catch (Exception e) /* NOTE: Must catch ALL. */
   501    499           {
   502    500               try
   503    501               {
   504         -                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
   505         -                        SQLiteConnectionFlags.LogCallbackException)
          502  +                if (HelperMethods.LogCallbackExceptions(_flags))
   506    503                   {
   507    504                       SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
   508    505                           HelperMethods.StringFormat(CultureInfo.CurrentCulture,
   509         -                        "Caught exception in \"Compare\" (UTF16) method: {0}",
   510         -                        e)); /* throw */
          506  +                        UnsafeNativeMethods.ExceptionMessageFormat,
          507  +                        "Compare (UTF16)", e)); /* throw */
   511    508                   }
   512    509               }
   513    510               catch
   514    511               {
   515    512                   // do nothing.
   516    513               }
   517    514           }
................................................................................
   570    567                   data._count++;
   571    568               }
   572    569           }
   573    570           catch (Exception e) /* NOTE: Must catch ALL. */
   574    571           {
   575    572               try
   576    573               {
   577         -                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
   578         -                        SQLiteConnectionFlags.LogCallbackException)
          574  +                if (HelperMethods.LogCallbackExceptions(_flags))
   579    575                   {
   580    576                       SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
   581    577                           HelperMethods.StringFormat(CultureInfo.CurrentCulture,
   582         -                        "Caught exception in \"Step\" method: {1}",
   583         -                        e)); /* throw */
          578  +                        UnsafeNativeMethods.ExceptionMessageFormat,
          579  +                        "Step", e)); /* throw */
   584    580                   }
   585    581               }
   586    582               catch
   587    583               {
   588    584                   // do nothing.
   589    585               }
   590    586           }
................................................................................
   625    621                   if (disp != null) disp.Dispose(); /* throw */
   626    622               }
   627    623           }
   628    624           catch (Exception e) /* NOTE: Must catch ALL. */
   629    625           {
   630    626               try
   631    627               {
   632         -                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
   633         -                        SQLiteConnectionFlags.LogCallbackException)
          628  +                if (HelperMethods.LogCallbackExceptions(_flags))
   634    629                   {
   635    630                       SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
   636    631                           HelperMethods.StringFormat(CultureInfo.CurrentCulture,
   637         -                        "Caught exception in \"Final\" method: {1}",
   638         -                        e)); /* throw */
          632  +                        UnsafeNativeMethods.ExceptionMessageFormat,
          633  +                        "Final", e)); /* throw */
   639    634                   }
   640    635               }
   641    636               catch
   642    637               {
   643    638                   // do nothing.
   644    639               }
   645    640           }

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

  5585   5585                   {
  5586   5586                       if (LogExceptionsNoThrow)
  5587   5587                       {
  5588   5588                           /* throw */
  5589   5589                           SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
  5590   5590                               HelperMethods.StringFormat(
  5591   5591                               CultureInfo.CurrentCulture,
  5592         -                            "Caught exception in \"{0}\" method: {1}",
         5592  +                            UnsafeNativeMethods.ExceptionMessageFormat,
  5593   5593                               destroy ? "xDestroy" : "xDisconnect", e));
  5594   5594                       }
  5595   5595                   }
  5596   5596                   catch
  5597   5597                   {
  5598   5598                       // do nothing.
  5599   5599                   }
................................................................................
  5693   5693                   try
  5694   5694                   {
  5695   5695                       if (logExceptions)
  5696   5696                       {
  5697   5697                           SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
  5698   5698                               HelperMethods.StringFormat(
  5699   5699                               CultureInfo.CurrentCulture,
  5700         -                            "Caught exception in \"SetTableError\" method: {0}",
  5701         -                            e)); /* throw */
         5700  +                            UnsafeNativeMethods.ExceptionMessageFormat,
         5701  +                            "SetTableError", e)); /* throw */
  5702   5702                       }
  5703   5703                   }
  5704   5704                   catch
  5705   5705                   {
  5706   5706                       // do nothing.
  5707   5707                   }
  5708   5708               }
................................................................................
  8149   8149                       try
  8150   8150                       {
  8151   8151                           if (LogExceptionsNoThrow)
  8152   8152                           {
  8153   8153                               SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
  8154   8154                                   HelperMethods.StringFormat(
  8155   8155                                   CultureInfo.CurrentCulture,
  8156         -                                "Caught exception in \"Dispose\" method: {0}",
  8157         -                                e)); /* throw */
         8156  +                                UnsafeNativeMethods.ExceptionMessageFormat,
         8157  +                                "Dispose", e)); /* throw */
  8158   8158                           }
  8159   8159                       }
  8160   8160                       catch
  8161   8161                       {
  8162   8162                           // do nothing.
  8163   8163                       }
  8164   8164                   }

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

   395    395   
   396    396         object obj = param.Value;
   397    397         DbType objType = param.DbType;
   398    398   
   399    399         if ((obj != null) && (objType == DbType.Object))
   400    400             objType = SQLiteConvert.TypeToDbType(obj.GetType());
   401    401   
   402         -      if ((_flags & SQLiteConnectionFlags.LogPreBind) == SQLiteConnectionFlags.LogPreBind)
          402  +      if (HelperMethods.LogPreBind(_flags))
   403    403         {
   404    404             IntPtr handle = _sqlite_stmt;
   405    405   
   406    406             SQLiteLog.LogMessage(HelperMethods.StringFormat(
   407    407                 CultureInfo.CurrentCulture,
   408    408                 "Binding statement {0} paramter #{1} with database type {2} and raw value {{{3}}}...",
   409    409                 handle, index, objType, obj));

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

   281    281         }
   282    282         #endregion
   283    283   
   284    284         /////////////////////////////////////////////////////////////////////////
   285    285   
   286    286         #region Internal Methods
   287    287         /// <summary>
          288  +      /// Determines if preparing a query should be logged.
          289  +      /// </summary>
          290  +      /// <param name="flags">
          291  +      /// The flags associated with the parent connection object.
          292  +      /// </param>
          293  +      /// <returns>
          294  +      /// Non-zero if the query preparation should be logged; otherwise, zero.
          295  +      /// </returns>
          296  +      internal static bool LogPrepare(
          297  +          SQLiteConnectionFlags flags
          298  +          )
          299  +      {
          300  +          flags &= SQLiteConnectionFlags.LogPrepare;
          301  +          return (flags == SQLiteConnectionFlags.LogPrepare);
          302  +      }
          303  +
          304  +      /////////////////////////////////////////////////////////////////////////
          305  +      /// <summary>
          306  +      /// Determines if pre-parameter binding should be logged.
          307  +      /// </summary>
          308  +      /// <param name="flags">
          309  +      /// The flags associated with the parent connection object.
          310  +      /// </param>
          311  +      /// <returns>
          312  +      /// Non-zero if the pre-parameter binding should be logged; otherwise,
          313  +      /// zero.
          314  +      /// </returns>
          315  +      internal static bool LogPreBind(
          316  +          SQLiteConnectionFlags flags
          317  +          )
          318  +      {
          319  +          flags &= SQLiteConnectionFlags.LogPreBind;
          320  +          return (flags == SQLiteConnectionFlags.LogPreBind);
          321  +      }
          322  +
          323  +      /////////////////////////////////////////////////////////////////////////
          324  +      /// <summary>
          325  +      /// Determines if parameter binding should be logged.
          326  +      /// </summary>
          327  +      /// <param name="flags">
          328  +      /// The flags associated with the parent connection object.
          329  +      /// </param>
          330  +      /// <returns>
          331  +      /// Non-zero if the parameter binding should be logged; otherwise, zero.
          332  +      /// </returns>
          333  +      internal static bool LogBind(
          334  +          SQLiteConnectionFlags flags
          335  +          )
          336  +      {
          337  +          flags &= SQLiteConnectionFlags.LogBind;
          338  +          return (flags == SQLiteConnectionFlags.LogBind);
          339  +      }
          340  +
          341  +      /////////////////////////////////////////////////////////////////////////
          342  +      /// <summary>
          343  +      /// Determines if an exception in a native callback should be logged.
          344  +      /// </summary>
          345  +      /// <param name="flags">
          346  +      /// The flags associated with the parent connection object.
          347  +      /// </param>
          348  +      /// <returns>
          349  +      /// Non-zero if the exception should be logged; otherwise, zero.
          350  +      /// </returns>
          351  +      internal static bool LogCallbackExceptions(
          352  +          SQLiteConnectionFlags flags
          353  +          )
          354  +      {
          355  +          flags &= SQLiteConnectionFlags.LogCallbackException;
          356  +          return (flags == SQLiteConnectionFlags.LogCallbackException);
          357  +      }
          358  +
          359  +      /////////////////////////////////////////////////////////////////////////
          360  +      /// <summary>
          361  +      /// Determines if backup API errors should be logged.
          362  +      /// </summary>
          363  +      /// <param name="flags">
          364  +      /// The flags associated with the parent connection object.
          365  +      /// </param>
          366  +      /// <returns>
          367  +      /// Non-zero if the backup API error should be logged; otherwise, zero.
          368  +      /// </returns>
          369  +      internal static bool LogBackup(
          370  +          SQLiteConnectionFlags flags
          371  +          )
          372  +      {
          373  +          flags &= SQLiteConnectionFlags.LogBackup;
          374  +          return (flags == SQLiteConnectionFlags.LogBackup);
          375  +      }
          376  +
          377  +#if INTEROP_VIRTUAL_TABLE
          378  +      /////////////////////////////////////////////////////////////////////////
          379  +      /// <summary>
          380  +      /// Determines if logging for the <see cref="SQLiteModule" /> class is
          381  +      /// disabled.
          382  +      /// </summary>
          383  +      /// <param name="flags">
          384  +      /// The flags associated with the parent connection object.
          385  +      /// </param>
          386  +      /// <returns>
          387  +      /// Non-zero if logging for the <see cref="SQLiteModule" /> class is
          388  +      /// disabled; otherwise, zero.
          389  +      /// </returns>
          390  +      internal static bool NoLogModule(
          391  +          SQLiteConnectionFlags flags
          392  +          )
          393  +      {
          394  +          flags &= SQLiteConnectionFlags.NoLogModule;
          395  +          return (flags == SQLiteConnectionFlags.NoLogModule);
          396  +      }
          397  +
          398  +      /////////////////////////////////////////////////////////////////////////
          399  +      /// <summary>
          400  +      /// Determines if <see cref="SQLiteModule" /> errors should be logged.
          401  +      /// </summary>
          402  +      /// <param name="flags">
          403  +      /// The flags associated with the parent connection object.
          404  +      /// </param>
          405  +      /// <returns>
          406  +      /// Non-zero if the <see cref="SQLiteModule" /> error should be logged;
          407  +      /// otherwise, zero.
          408  +      /// </returns>
          409  +      internal static bool LogModuleError(
          410  +          SQLiteConnectionFlags flags
          411  +          )
          412  +      {
          413  +          flags &= SQLiteConnectionFlags.LogModuleError;
          414  +          return (flags == SQLiteConnectionFlags.LogModuleError);
          415  +      }
          416  +
          417  +      /////////////////////////////////////////////////////////////////////////
          418  +      /// <summary>
          419  +      /// Determines if <see cref="SQLiteModule" /> exceptions should be
          420  +      /// logged.
          421  +      /// </summary>
          422  +      /// <param name="flags">
          423  +      /// The flags associated with the parent connection object.
          424  +      /// </param>
          425  +      /// <returns>
          426  +      /// Non-zero if the <see cref="SQLiteModule" /> exception should be
          427  +      /// logged; otherwise, zero.
          428  +      /// </returns>
          429  +      internal static bool LogModuleException(
          430  +          SQLiteConnectionFlags flags
          431  +          )
          432  +      {
          433  +          flags &= SQLiteConnectionFlags.LogModuleException;
          434  +          return (flags == SQLiteConnectionFlags.LogModuleException);
          435  +      }
          436  +#endif
          437  +
          438  +      /////////////////////////////////////////////////////////////////////////
          439  +      /// <summary>
   288    440         /// Determines if the current process is running on one of the Windows
   289    441         /// [sub-]platforms.
   290    442         /// </summary>
   291    443         /// <returns>
   292    444         /// Non-zero when running on Windows; otherwise, zero.
   293    445         /// </returns>
   294    446         internal static bool IsWindows()
................................................................................
   604    756     /// This class declares P/Invoke methods to call native SQLite APIs.
   605    757     /// </summary>
   606    758   #if !PLATFORM_COMPACTFRAMEWORK
   607    759     [SuppressUnmanagedCodeSecurity]
   608    760   #endif
   609    761     internal static class UnsafeNativeMethods
   610    762     {
          763  +      public const string ExceptionMessageFormat =
          764  +          "Caught exception in \"{0}\" method: {1}";
          765  +
          766  +      /////////////////////////////////////////////////////////////////////////
          767  +
   611    768         #region Shared Native SQLite Library Pre-Loading Code
   612    769         #region Private Constants
   613    770         /// <summary>
   614    771         /// The file extension used for dynamic link libraries.
   615    772         /// </summary>
   616    773         private static readonly string DllFileExtension = ".dll";
   617    774