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

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

Overview
Comment:Handle parameter binding for boolean values using a new internal method. Consistently enable LogBind flag support for the .NET Compact Framework.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d38c8328d02398233975cd5c6ef2ede4143762a8
User & Date: mistachkin 2016-05-26 18:19:05
Context
2016-06-02
19:35
Add VerifyOnly method to the SQLiteCommand class. check-in: 36669ce629 user: mistachkin tags: trunk
2016-05-26
18:19
Handle parameter binding for boolean values using a new internal method. Consistently enable LogBind flag support for the .NET Compact Framework. check-in: d38c8328d0 user: mistachkin tags: trunk
2016-05-18
23:38
Update SQLite core library to the 3.13.0 release. check-in: a825f311a4 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

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

  1608   1608           if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1609   1609       }
  1610   1610   
  1611   1611       internal override void Bind_UInt32(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, uint value)
  1612   1612       {
  1613   1613           SQLiteStatementHandle handle = stmt._sqlite_stmt;
  1614   1614   
  1615         -#if !PLATFORM_COMPACTFRAMEWORK
  1616   1615           if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
  1617   1616           {
  1618   1617               LogBind(handle, index, value);
  1619   1618           }
  1620         -#endif
  1621   1619   
  1622   1620           SQLiteErrorCode n;
  1623   1621   
  1624   1622           if ((flags & SQLiteConnectionFlags.BindUInt32AsInt64) == SQLiteConnectionFlags.BindUInt32AsInt64)
  1625   1623           {
  1626   1624               long value2 = value;
  1627   1625   
................................................................................
  1640   1638           if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1641   1639       }
  1642   1640   
  1643   1641       internal override void Bind_Int64(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, long value)
  1644   1642       {
  1645   1643           SQLiteStatementHandle handle = stmt._sqlite_stmt;
  1646   1644   
  1647         -#if !PLATFORM_COMPACTFRAMEWORK
  1648   1645           if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
  1649   1646           {
  1650   1647               LogBind(handle, index, value);
  1651   1648           }
  1652   1649   
         1650  +#if !PLATFORM_COMPACTFRAMEWORK
  1653   1651           SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int64(handle, index, value);
  1654   1652           if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1655   1653   #elif !SQLITE_STANDARD
  1656   1654           SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int64_interop(handle, index, ref value);
  1657   1655           if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1658   1656   #else
  1659   1657           throw new NotImplementedException();
................................................................................
  1660   1658   #endif
  1661   1659       }
  1662   1660   
  1663   1661       internal override void Bind_UInt64(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, ulong value)
  1664   1662       {
  1665   1663           SQLiteStatementHandle handle = stmt._sqlite_stmt;
  1666   1664   
  1667         -#if !PLATFORM_COMPACTFRAMEWORK
  1668   1665           if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
  1669   1666           {
  1670   1667               LogBind(handle, index, value);
  1671   1668           }
  1672   1669   
         1670  +#if !PLATFORM_COMPACTFRAMEWORK
  1673   1671           SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_uint64(handle, index, value);
  1674   1672           if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1675   1673   #elif !SQLITE_STANDARD
  1676   1674           SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_uint64_interop(handle, index, ref value);
  1677   1675           if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1678   1676   #else
  1679   1677           throw new NotImplementedException();
  1680   1678   #endif
  1681   1679       }
         1680  +
         1681  +    internal override void Bind_Boolean(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, bool value)
         1682  +    {
         1683  +        SQLiteStatementHandle handle = stmt._sqlite_stmt;
         1684  +
         1685  +        if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
         1686  +        {
         1687  +            LogBind(handle, index, value);
         1688  +        }
         1689  +
         1690  +        int value2 = value ? 1 : 0;
         1691  +
         1692  +        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int(handle, index, value2);
         1693  +        if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
         1694  +    }
  1682   1695   
  1683   1696       internal override void Bind_Text(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, string value)
  1684   1697       {
  1685   1698           SQLiteStatementHandle handle = stmt._sqlite_stmt;
  1686   1699   
  1687         -#if !PLATFORM_COMPACTFRAMEWORK
  1688   1700           if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
  1689   1701           {
  1690   1702               LogBind(handle, index, value);
  1691   1703           }
  1692         -#endif
  1693   1704   
  1694   1705           byte[] b = ToUTF8(value);
  1695   1706   
  1696         -#if !PLATFORM_COMPACTFRAMEWORK
  1697   1707           if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
  1698   1708           {
  1699   1709               LogBind(handle, index, b);
  1700   1710           }
  1701         -#endif
  1702   1711   
  1703   1712           SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_text(handle, index, b, b.Length - 1, (IntPtr)(-1));
  1704   1713           if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1705   1714       }
  1706   1715   
  1707   1716       internal override void Bind_DateTime(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, DateTime dt)
  1708   1717       {
  1709   1718           SQLiteStatementHandle handle = stmt._sqlite_stmt;
  1710   1719   
  1711         -#if !PLATFORM_COMPACTFRAMEWORK
  1712   1720           if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
  1713   1721           {
  1714   1722               LogBind(handle, index, dt);
  1715   1723           }
  1716         -#endif
  1717   1724   
  1718   1725           if ((flags & SQLiteConnectionFlags.BindDateTimeWithKind) == SQLiteConnectionFlags.BindDateTimeWithKind)
  1719   1726           {
  1720   1727               if ((_datetimeKind != DateTimeKind.Unspecified) &&
  1721   1728                   (dt.Kind != DateTimeKind.Unspecified) &&
  1722   1729                   (dt.Kind != _datetimeKind))
  1723   1730               {
................................................................................
  1730   1737   
  1731   1738           switch (_datetimeFormat)
  1732   1739           {
  1733   1740               case SQLiteDateFormats.Ticks:
  1734   1741                   {
  1735   1742                       long value = dt.Ticks;
  1736   1743   
  1737         -#if !PLATFORM_COMPACTFRAMEWORK
  1738   1744                       if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
  1739   1745                       {
  1740   1746                           LogBind(handle, index, value);
  1741   1747                       }
  1742   1748   
         1749  +#if !PLATFORM_COMPACTFRAMEWORK
  1743   1750                       SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int64(handle, index, value);
  1744   1751                       if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1745   1752                       break;
  1746   1753   #elif !SQLITE_STANDARD
  1747   1754                       SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int64_interop(handle, index, ref value);
  1748   1755                       if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1749   1756                       break;
................................................................................
  1751   1758                       throw new NotImplementedException();
  1752   1759   #endif
  1753   1760                   }
  1754   1761               case SQLiteDateFormats.JulianDay:
  1755   1762                   {
  1756   1763                       double value = ToJulianDay(dt);
  1757   1764   
  1758         -#if !PLATFORM_COMPACTFRAMEWORK
  1759   1765                       if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
  1760   1766                       {
  1761   1767                           LogBind(handle, index, value);
  1762   1768                       }
  1763   1769   
         1770  +#if !PLATFORM_COMPACTFRAMEWORK
  1764   1771                       SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_double(handle, index, value);
  1765   1772                       if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1766   1773                       break;
  1767   1774   #elif !SQLITE_STANDARD
  1768   1775                       SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_double_interop(handle, index, ref value);
  1769   1776                       if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1770   1777                       break;
................................................................................
  1772   1779                       throw new NotImplementedException();
  1773   1780   #endif
  1774   1781                   }
  1775   1782               case SQLiteDateFormats.UnixEpoch:
  1776   1783                   {
  1777   1784                       long value = Convert.ToInt64(dt.Subtract(UnixEpoch).TotalSeconds);
  1778   1785   
  1779         -#if !PLATFORM_COMPACTFRAMEWORK
  1780   1786                       if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
  1781   1787                       {
  1782   1788                           LogBind(handle, index, value);
  1783   1789                       }
  1784   1790   
         1791  +#if !PLATFORM_COMPACTFRAMEWORK
  1785   1792                       SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int64(handle, index, value);
  1786   1793                       if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1787   1794                       break;
  1788   1795   #elif !SQLITE_STANDARD
  1789   1796                       SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int64_interop(handle, index, ref value);
  1790   1797                       if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1791   1798                       break;
................................................................................
  1793   1800                       throw new NotImplementedException();
  1794   1801   #endif
  1795   1802                   }
  1796   1803               default:
  1797   1804                   {
  1798   1805                       byte[] b = ToUTF8(dt);
  1799   1806   
  1800         -#if !PLATFORM_COMPACTFRAMEWORK
  1801   1807                       if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
  1802   1808                       {
  1803   1809                           LogBind(handle, index, b);
  1804   1810                       }
  1805         -#endif
  1806   1811   
  1807   1812                       SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_text(handle, index, b, b.Length - 1, (IntPtr)(-1));
  1808   1813                       if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1809   1814                       break;
  1810   1815                   }
  1811   1816           }
  1812   1817       }
  1813   1818   
  1814   1819       internal override void Bind_Blob(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, byte[] blobData)
  1815   1820       {
  1816   1821           SQLiteStatementHandle handle = stmt._sqlite_stmt;
  1817   1822   
  1818         -#if !PLATFORM_COMPACTFRAMEWORK
  1819   1823           if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
  1820   1824           {
  1821   1825               LogBind(handle, index, blobData);
  1822   1826           }
  1823         -#endif
  1824   1827   
  1825   1828           SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_blob(handle, index, blobData, blobData.Length, (IntPtr)(-1));
  1826   1829           if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1827   1830       }
  1828   1831   
  1829   1832       internal override void Bind_Null(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index)
  1830   1833       {
  1831   1834           SQLiteStatementHandle handle = stmt._sqlite_stmt;
  1832   1835   
  1833         -#if !PLATFORM_COMPACTFRAMEWORK
  1834   1836           if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
  1835   1837           {
  1836   1838               LogBind(handle, index);
  1837   1839           }
  1838         -#endif
  1839   1840   
  1840   1841           SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_null(handle, index);
  1841   1842           if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
  1842   1843       }
  1843   1844   
  1844   1845       internal override int Bind_ParamCount(SQLiteStatement stmt, SQLiteConnectionFlags flags)
  1845   1846       {

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

   229    229       internal abstract bool UnbindFunction(SQLiteFunctionAttribute functionAttribute, SQLiteConnectionFlags flags);
   230    230   
   231    231       internal abstract void Bind_Double(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, double value);
   232    232       internal abstract void Bind_Int32(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, Int32 value);
   233    233       internal abstract void Bind_UInt32(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, UInt32 value);
   234    234       internal abstract void Bind_Int64(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, Int64 value);
   235    235       internal abstract void Bind_UInt64(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, UInt64 value);
          236  +    internal abstract void Bind_Boolean(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, bool value);
   236    237       internal abstract void Bind_Text(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, string value);
   237    238       internal abstract void Bind_Blob(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, byte[] blobData);
   238    239       internal abstract void Bind_DateTime(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, DateTime dt);
   239    240       internal abstract void Bind_Null(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index);
   240    241   
   241    242       internal abstract int Bind_ParamCount(SQLiteStatement stmt, SQLiteConnectionFlags flags);
   242    243       internal abstract string Bind_ParamName(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index);

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

   304    304             // NOTE: The old method (commented below) does not honor the selected date format
   305    305             //       for the connection.
   306    306             // _sql.Bind_DateTime(this, index, Convert.ToDateTime(obj, cultureInfo));
   307    307               _sql.Bind_DateTime(this, _flags, index, (obj is string) ?
   308    308                 _sql.ToDateTime((string)obj) : Convert.ToDateTime(obj, cultureInfo));
   309    309             break;
   310    310           case DbType.Boolean:
   311         -          _sql.Bind_Int32(this, _flags, index, SQLiteConvert.ToBoolean(obj, cultureInfo, true) ? 1 : 0);
          311  +          _sql.Bind_Boolean(this, _flags, index, SQLiteConvert.ToBoolean(obj, cultureInfo, true));
   312    312             break;
   313    313           case DbType.SByte:
   314    314             _sql.Bind_Int32(this, _flags, index, Convert.ToSByte(obj, cultureInfo));
   315    315             break;
   316    316           case DbType.Int16:
   317    317             _sql.Bind_Int32(this, _flags, index, Convert.ToInt16(obj, cultureInfo));
   318    318             break;