| | @@ -1,8 +1,8 @@ |
| 1 | 1 | /****************************************************************************** |
| 2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | | -** version 3.8.8. By combining all the individual C code files into this |
| 3 | +** version 3.8.7.2. By combining all the individual C code files into this |
| 4 | 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | 8 | ** translation unit. |
| | @@ -179,11 +179,11 @@ |
| 179 | 179 | |
| 180 | 180 | |
| 181 | 181 | /* |
| 182 | 182 | ** These no-op macros are used in front of interfaces to mark those |
| 183 | 183 | ** interfaces as either deprecated or experimental. New applications |
| 184 | | -** should not use deprecated interfaces - they are supported for backwards |
| 184 | +** should not use deprecated interfaces - they are support for backwards |
| 185 | 185 | ** compatibility only. Application writers should be aware that |
| 186 | 186 | ** experimental interfaces are subject to change in point releases. |
| 187 | 187 | ** |
| 188 | 188 | ** These macros used to resolve to various kinds of compiler magic that |
| 189 | 189 | ** would generate warning messages when they were used. But that |
| | @@ -229,13 +229,13 @@ |
| 229 | 229 | ** |
| 230 | 230 | ** See also: [sqlite3_libversion()], |
| 231 | 231 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 232 | 232 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 233 | 233 | */ |
| 234 | | -#define SQLITE_VERSION "3.8.8" |
| 235 | | -#define SQLITE_VERSION_NUMBER 3008008 |
| 236 | | -#define SQLITE_SOURCE_ID "2014-11-11 19:07:56 1412fcc480799ecbd68d44dd18d5bad40e20ccf1" |
| 234 | +#define SQLITE_VERSION "3.8.7.2" |
| 235 | +#define SQLITE_VERSION_NUMBER 3008007 |
| 236 | +#define SQLITE_SOURCE_ID "2014-11-18 12:28:52 945a9e687fdfee5f7103d85d131024e85d594ac3" |
| 237 | 237 | |
| 238 | 238 | /* |
| 239 | 239 | ** CAPI3REF: Run-Time Library Version Numbers |
| 240 | 240 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 241 | 241 | ** |
| | @@ -1626,31 +1626,29 @@ |
| 1626 | 1626 | ** it is not possible to set the Serialized [threading mode] and |
| 1627 | 1627 | ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
| 1628 | 1628 | ** SQLITE_CONFIG_SERIALIZED configuration option.</dd> |
| 1629 | 1629 | ** |
| 1630 | 1630 | ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt> |
| 1631 | | -** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is |
| 1632 | | -** a pointer to an instance of the [sqlite3_mem_methods] structure. |
| 1633 | | -** The argument specifies |
| 1631 | +** <dd> ^(This option takes a single argument which is a pointer to an |
| 1632 | +** instance of the [sqlite3_mem_methods] structure. The argument specifies |
| 1634 | 1633 | ** alternative low-level memory allocation routines to be used in place of |
| 1635 | 1634 | ** the memory allocation routines built into SQLite.)^ ^SQLite makes |
| 1636 | 1635 | ** its own private copy of the content of the [sqlite3_mem_methods] structure |
| 1637 | 1636 | ** before the [sqlite3_config()] call returns.</dd> |
| 1638 | 1637 | ** |
| 1639 | 1638 | ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt> |
| 1640 | | -** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which |
| 1641 | | -** is a pointer to an instance of the [sqlite3_mem_methods] structure. |
| 1642 | | -** The [sqlite3_mem_methods] |
| 1639 | +** <dd> ^(This option takes a single argument which is a pointer to an |
| 1640 | +** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods] |
| 1643 | 1641 | ** structure is filled with the currently defined memory allocation routines.)^ |
| 1644 | 1642 | ** This option can be used to overload the default memory allocation |
| 1645 | 1643 | ** routines with a wrapper that simulations memory allocation failure or |
| 1646 | 1644 | ** tracks memory usage, for example. </dd> |
| 1647 | 1645 | ** |
| 1648 | 1646 | ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> |
| 1649 | | -** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int, |
| 1650 | | -** interpreted as a boolean, which enables or disables the collection of |
| 1651 | | -** memory allocation statistics. ^(When memory allocation statistics are disabled, the |
| 1647 | +** <dd> ^This option takes single argument of type int, interpreted as a |
| 1648 | +** boolean, which enables or disables the collection of memory allocation |
| 1649 | +** statistics. ^(When memory allocation statistics are disabled, the |
| 1652 | 1650 | ** following SQLite interfaces become non-operational: |
| 1653 | 1651 | ** <ul> |
| 1654 | 1652 | ** <li> [sqlite3_memory_used()] |
| 1655 | 1653 | ** <li> [sqlite3_memory_highwater()] |
| 1656 | 1654 | ** <li> [sqlite3_soft_heap_limit64()] |
| | @@ -1660,90 +1658,78 @@ |
| 1660 | 1658 | ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory |
| 1661 | 1659 | ** allocation statistics are disabled by default. |
| 1662 | 1660 | ** </dd> |
| 1663 | 1661 | ** |
| 1664 | 1662 | ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt> |
| 1665 | | -** <dd> ^The SQLITE_CONFIG_SCRATCH option specifies a static memory buffer |
| 1666 | | -** that SQLite can use for scratch memory. ^(There are three arguments |
| 1667 | | -** to SQLITE_CONFIG_SCRATCH: A pointer an 8-byte |
| 1663 | +** <dd> ^This option specifies a static memory buffer that SQLite can use for |
| 1664 | +** scratch memory. There are three arguments: A pointer an 8-byte |
| 1668 | 1665 | ** aligned memory buffer from which the scratch allocations will be |
| 1669 | 1666 | ** drawn, the size of each scratch allocation (sz), |
| 1670 | | -** and the maximum number of scratch allocations (N).)^ |
| 1667 | +** and the maximum number of scratch allocations (N). The sz |
| 1668 | +** argument must be a multiple of 16. |
| 1671 | 1669 | ** The first argument must be a pointer to an 8-byte aligned buffer |
| 1672 | 1670 | ** of at least sz*N bytes of memory. |
| 1673 | | -** ^SQLite will not use more than one scratch buffers per thread. |
| 1674 | | -** ^SQLite will never request a scratch buffer that is more than 6 |
| 1675 | | -** times the database page size. |
| 1676 | | -** ^If SQLite needs needs additional |
| 1671 | +** ^SQLite will use no more than two scratch buffers per thread. So |
| 1672 | +** N should be set to twice the expected maximum number of threads. |
| 1673 | +** ^SQLite will never require a scratch buffer that is more than 6 |
| 1674 | +** times the database page size. ^If SQLite needs needs additional |
| 1677 | 1675 | ** scratch memory beyond what is provided by this configuration option, then |
| 1678 | | -** [sqlite3_malloc()] will be used to obtain the memory needed.<p> |
| 1679 | | -** ^When the application provides any amount of scratch memory using |
| 1680 | | -** SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary large |
| 1681 | | -** [sqlite3_malloc|heap allocations]. |
| 1682 | | -** This can help [Robson proof|prevent memory allocation failures] due to heap |
| 1683 | | -** fragmentation in low-memory embedded systems. |
| 1684 | | -** </dd> |
| 1676 | +** [sqlite3_malloc()] will be used to obtain the memory needed.</dd> |
| 1685 | 1677 | ** |
| 1686 | 1678 | ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt> |
| 1687 | | -** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a static memory buffer |
| 1688 | | -** that SQLite can use for the database page cache with the default page |
| 1689 | | -** cache implementation. |
| 1679 | +** <dd> ^This option specifies a static memory buffer that SQLite can use for |
| 1680 | +** the database page cache with the default page cache implementation. |
| 1690 | 1681 | ** This configuration should not be used if an application-define page |
| 1691 | | -** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2] |
| 1692 | | -** configuration option. |
| 1693 | | -** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned |
| 1682 | +** cache implementation is loaded using the SQLITE_CONFIG_PCACHE2 option. |
| 1683 | +** There are three arguments to this option: A pointer to 8-byte aligned |
| 1694 | 1684 | ** memory, the size of each page buffer (sz), and the number of pages (N). |
| 1695 | 1685 | ** The sz argument should be the size of the largest database page |
| 1696 | | -** (a power of two between 512 and 32768) plus some extra bytes for each |
| 1697 | | -** page header. ^The number of extra bytes needed by the page header |
| 1698 | | -** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option |
| 1699 | | -** to [sqlite3_config()]. |
| 1700 | | -** ^It is harmless, apart from the wasted memory, |
| 1701 | | -** for the sz parameter to be larger than necessary. The first |
| 1702 | | -** argument should pointer to an 8-byte aligned block of memory that |
| 1703 | | -** is at least sz*N bytes of memory, otherwise subsequent behavior is |
| 1704 | | -** undefined. |
| 1686 | +** (a power of two between 512 and 32768) plus a little extra for each |
| 1687 | +** page header. ^The page header size is 20 to 40 bytes depending on |
| 1688 | +** the host architecture. ^It is harmless, apart from the wasted memory, |
| 1689 | +** to make sz a little too large. The first |
| 1690 | +** argument should point to an allocation of at least sz*N bytes of memory. |
| 1705 | 1691 | ** ^SQLite will use the memory provided by the first argument to satisfy its |
| 1706 | 1692 | ** memory needs for the first N pages that it adds to cache. ^If additional |
| 1707 | 1693 | ** page cache memory is needed beyond what is provided by this option, then |
| 1708 | | -** SQLite goes to [sqlite3_malloc()] for the additional storage space.</dd> |
| 1694 | +** SQLite goes to [sqlite3_malloc()] for the additional storage space. |
| 1695 | +** The pointer in the first argument must |
| 1696 | +** be aligned to an 8-byte boundary or subsequent behavior of SQLite |
| 1697 | +** will be undefined.</dd> |
| 1709 | 1698 | ** |
| 1710 | 1699 | ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> |
| 1711 | | -** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer |
| 1712 | | -** that SQLite will use for all of its dynamic memory allocation needs |
| 1713 | | -** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. |
| 1714 | | -** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled |
| 1715 | | -** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns |
| 1716 | | -** [SQLITE_ERROR] if invoked otherwise. |
| 1717 | | -** ^There are three arguments to SQLITE_CONFIG_HEAP: |
| 1718 | | -** An 8-byte aligned pointer to the memory, |
| 1700 | +** <dd> ^This option specifies a static memory buffer that SQLite will use |
| 1701 | +** for all of its dynamic memory allocation needs beyond those provided |
| 1702 | +** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. |
| 1703 | +** There are three arguments: An 8-byte aligned pointer to the memory, |
| 1719 | 1704 | ** the number of bytes in the memory buffer, and the minimum allocation size. |
| 1720 | 1705 | ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts |
| 1721 | 1706 | ** to using its default memory allocator (the system malloc() implementation), |
| 1722 | 1707 | ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the |
| 1723 | | -** memory pointer is not NULL then the alternative memory |
| 1708 | +** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or |
| 1709 | +** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory |
| 1724 | 1710 | ** allocator is engaged to handle all of SQLites memory allocation needs. |
| 1725 | 1711 | ** The first pointer (the memory pointer) must be aligned to an 8-byte |
| 1726 | 1712 | ** boundary or subsequent behavior of SQLite will be undefined. |
| 1727 | 1713 | ** The minimum allocation size is capped at 2**12. Reasonable values |
| 1728 | 1714 | ** for the minimum allocation size are 2**5 through 2**8.</dd> |
| 1729 | 1715 | ** |
| 1730 | 1716 | ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt> |
| 1731 | | -** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a |
| 1732 | | -** pointer to an instance of the [sqlite3_mutex_methods] structure. |
| 1733 | | -** The argument specifies alternative low-level mutex routines to be used in place |
| 1717 | +** <dd> ^(This option takes a single argument which is a pointer to an |
| 1718 | +** instance of the [sqlite3_mutex_methods] structure. The argument specifies |
| 1719 | +** alternative low-level mutex routines to be used in place |
| 1734 | 1720 | ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the |
| 1735 | 1721 | ** content of the [sqlite3_mutex_methods] structure before the call to |
| 1736 | 1722 | ** [sqlite3_config()] returns. ^If SQLite is compiled with |
| 1737 | 1723 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1738 | 1724 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1739 | 1725 | ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will |
| 1740 | 1726 | ** return [SQLITE_ERROR].</dd> |
| 1741 | 1727 | ** |
| 1742 | 1728 | ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt> |
| 1743 | | -** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which |
| 1744 | | -** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The |
| 1729 | +** <dd> ^(This option takes a single argument which is a pointer to an |
| 1730 | +** instance of the [sqlite3_mutex_methods] structure. The |
| 1745 | 1731 | ** [sqlite3_mutex_methods] |
| 1746 | 1732 | ** structure is filled with the currently defined mutex routines.)^ |
| 1747 | 1733 | ** This option can be used to overload the default mutex allocation |
| 1748 | 1734 | ** routines with a wrapper used to track mutex usage for performance |
| 1749 | 1735 | ** profiling or testing, for example. ^If SQLite is compiled with |
| | @@ -1751,28 +1737,28 @@ |
| 1751 | 1737 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1752 | 1738 | ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will |
| 1753 | 1739 | ** return [SQLITE_ERROR].</dd> |
| 1754 | 1740 | ** |
| 1755 | 1741 | ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt> |
| 1756 | | -** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine |
| 1757 | | -** the default size of lookaside memory on each [database connection]. |
| 1758 | | -** The first argument is the |
| 1742 | +** <dd> ^(This option takes two arguments that determine the default |
| 1743 | +** memory allocation for the lookaside memory allocator on each |
| 1744 | +** [database connection]. The first argument is the |
| 1759 | 1745 | ** size of each lookaside buffer slot and the second is the number of |
| 1760 | | -** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE |
| 1761 | | -** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] |
| 1762 | | -** option to [sqlite3_db_config()] can be used to change the lookaside |
| 1746 | +** slots allocated to each database connection.)^ ^(This option sets the |
| 1747 | +** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] |
| 1748 | +** verb to [sqlite3_db_config()] can be used to change the lookaside |
| 1763 | 1749 | ** configuration on individual connections.)^ </dd> |
| 1764 | 1750 | ** |
| 1765 | 1751 | ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt> |
| 1766 | | -** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is |
| 1767 | | -** a pointer to an [sqlite3_pcache_methods2] object. This object specifies |
| 1768 | | -** the interface to a custom page cache implementation.)^ |
| 1769 | | -** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd> |
| 1752 | +** <dd> ^(This option takes a single argument which is a pointer to |
| 1753 | +** an [sqlite3_pcache_methods2] object. This object specifies the interface |
| 1754 | +** to a custom page cache implementation.)^ ^SQLite makes a copy of the |
| 1755 | +** object and uses it for page cache memory allocations.</dd> |
| 1770 | 1756 | ** |
| 1771 | 1757 | ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt> |
| 1772 | | -** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which |
| 1773 | | -** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of the current |
| 1758 | +** <dd> ^(This option takes a single argument which is a pointer to an |
| 1759 | +** [sqlite3_pcache_methods2] object. SQLite copies of the current |
| 1774 | 1760 | ** page cache implementation into that object.)^ </dd> |
| 1775 | 1761 | ** |
| 1776 | 1762 | ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> |
| 1777 | 1763 | ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite |
| 1778 | 1764 | ** global [error log]. |
| | @@ -1792,27 +1778,26 @@ |
| 1792 | 1778 | ** supplied by the application must not invoke any SQLite interface. |
| 1793 | 1779 | ** In a multi-threaded application, the application-defined logger |
| 1794 | 1780 | ** function must be threadsafe. </dd> |
| 1795 | 1781 | ** |
| 1796 | 1782 | ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI |
| 1797 | | -** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int. |
| 1798 | | -** If non-zero, then URI handling is globally enabled. If the parameter is zero, |
| 1799 | | -** then URI handling is globally disabled.)^ ^If URI handling is globally enabled, |
| 1800 | | -** all filenames passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or |
| 1783 | +** <dd>^(This option takes a single argument of type int. If non-zero, then |
| 1784 | +** URI handling is globally enabled. If the parameter is zero, then URI handling |
| 1785 | +** is globally disabled.)^ ^If URI handling is globally enabled, all filenames |
| 1786 | +** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or |
| 1801 | 1787 | ** specified as part of [ATTACH] commands are interpreted as URIs, regardless |
| 1802 | 1788 | ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database |
| 1803 | 1789 | ** connection is opened. ^If it is globally disabled, filenames are |
| 1804 | 1790 | ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the |
| 1805 | 1791 | ** database connection is opened. ^(By default, URI handling is globally |
| 1806 | 1792 | ** disabled. The default value may be changed by compiling with the |
| 1807 | 1793 | ** [SQLITE_USE_URI] symbol defined.)^ |
| 1808 | 1794 | ** |
| 1809 | 1795 | ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN |
| 1810 | | -** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer |
| 1811 | | -** argument which is interpreted as a boolean in order to enable or disable |
| 1812 | | -** the use of covering indices for full table scans in the query optimizer. |
| 1813 | | -** ^The default setting is determined |
| 1796 | +** <dd>^This option takes a single integer argument which is interpreted as |
| 1797 | +** a boolean in order to enable or disable the use of covering indices for |
| 1798 | +** full table scans in the query optimizer. ^The default setting is determined |
| 1814 | 1799 | ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on" |
| 1815 | 1800 | ** if that compile-time option is omitted. |
| 1816 | 1801 | ** The ability to disable the use of covering indices for full table scans |
| 1817 | 1802 | ** is because some incorrectly coded legacy applications might malfunction |
| 1818 | 1803 | ** when the optimization is enabled. Providing the ability to |
| | @@ -1848,32 +1833,23 @@ |
| 1848 | 1833 | ** that are the default mmap size limit (the default setting for |
| 1849 | 1834 | ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit. |
| 1850 | 1835 | ** ^The default setting can be overridden by each database connection using |
| 1851 | 1836 | ** either the [PRAGMA mmap_size] command, or by using the |
| 1852 | 1837 | ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size |
| 1853 | | -** will be silently truncated if necessary so that it does not exceed the |
| 1854 | | -** compile-time maximum mmap size set by the |
| 1838 | +** cannot be changed at run-time. Nor may the maximum allowed mmap size |
| 1839 | +** exceed the compile-time maximum mmap size set by the |
| 1855 | 1840 | ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^ |
| 1856 | 1841 | ** ^If either argument to this option is negative, then that argument is |
| 1857 | 1842 | ** changed to its compile-time default. |
| 1858 | 1843 | ** |
| 1859 | 1844 | ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]] |
| 1860 | 1845 | ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE |
| 1861 | | -** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is |
| 1862 | | -** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro defined. |
| 1863 | | -** ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value |
| 1846 | +** <dd>^This option is only available if SQLite is compiled for Windows |
| 1847 | +** with the [SQLITE_WIN32_MALLOC] pre-processor macro defined. |
| 1848 | +** SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value |
| 1864 | 1849 | ** that specifies the maximum size of the created heap. |
| 1865 | 1850 | ** </dl> |
| 1866 | | -** |
| 1867 | | -** [[SQLITE_CONFIG_PCACHE_HDRSZ]] |
| 1868 | | -** <dt>SQLITE_CONFIG_PCACHE_HDRSZ |
| 1869 | | -** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which |
| 1870 | | -** is a pointer to an integer and writes into that integer the number of extra |
| 1871 | | -** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE]. The amount of |
| 1872 | | -** extra space required can change depending on the compiler, |
| 1873 | | -** target platform, and SQLite version. |
| 1874 | | -** </dl> |
| 1875 | 1851 | */ |
| 1876 | 1852 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1877 | 1853 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 1878 | 1854 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| 1879 | 1855 | #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ |
| | @@ -1894,11 +1870,10 @@ |
| 1894 | 1870 | #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */ |
| 1895 | 1871 | #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */ |
| 1896 | 1872 | #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */ |
| 1897 | 1873 | #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */ |
| 1898 | 1874 | #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */ |
| 1899 | | -#define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */ |
| 1900 | 1875 | |
| 1901 | 1876 | /* |
| 1902 | 1877 | ** CAPI3REF: Database Connection Configuration Options |
| 1903 | 1878 | ** |
| 1904 | 1879 | ** These constants are the available integer configuration options that |
| | @@ -2022,49 +1997,51 @@ |
| 2022 | 1997 | SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); |
| 2023 | 1998 | |
| 2024 | 1999 | /* |
| 2025 | 2000 | ** CAPI3REF: Count The Number Of Rows Modified |
| 2026 | 2001 | ** |
| 2027 | | -** ^This function returns the number of rows modified, inserted or |
| 2028 | | -** deleted by the most recently completed INSERT, UPDATE or DELETE |
| 2029 | | -** statement on the database connection specified by the only parameter. |
| 2030 | | -** ^Executing any other type of SQL statement does not modify the value |
| 2031 | | -** returned by this function. |
| 2032 | | -** |
| 2033 | | -** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are |
| 2034 | | -** considered - auxiliary changes caused by [CREATE TRIGGER | triggers], |
| 2035 | | -** [foreign key actions] or [REPLACE] constraint resolution are not counted. |
| 2036 | | -** |
| 2037 | | -** Changes to a view that are intercepted by |
| 2038 | | -** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value |
| 2039 | | -** returned by sqlite3_changes() immediately after an INSERT, UPDATE or |
| 2040 | | -** DELETE statement run on a view is always zero. Only changes made to real |
| 2041 | | -** tables are counted. |
| 2042 | | -** |
| 2043 | | -** Things are more complicated if the sqlite3_changes() function is |
| 2044 | | -** executed while a trigger program is running. This may happen if the |
| 2045 | | -** program uses the [changes() SQL function], or if some other callback |
| 2046 | | -** function invokes sqlite3_changes() directly. Essentially: |
| 2047 | | -** |
| 2048 | | -** <ul> |
| 2049 | | -** <li> ^(Before entering a trigger program the value returned by |
| 2050 | | -** sqlite3_changes() function is saved. After the trigger program |
| 2051 | | -** has finished, the original value is restored.)^ |
| 2052 | | -** |
| 2053 | | -** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE |
| 2054 | | -** statement sets the value returned by sqlite3_changes() |
| 2055 | | -** upon completion as normal. Of course, this value will not include |
| 2056 | | -** any changes performed by sub-triggers, as the sqlite3_changes() |
| 2057 | | -** value will be saved and restored after each sub-trigger has run.)^ |
| 2058 | | -** </ul> |
| 2059 | | -** |
| 2060 | | -** ^This means that if the changes() SQL function (or similar) is used |
| 2061 | | -** by the first INSERT, UPDATE or DELETE statement within a trigger, it |
| 2062 | | -** returns the value as set when the calling statement began executing. |
| 2063 | | -** ^If it is used by the second or subsequent such statement within a trigger |
| 2064 | | -** program, the value returned reflects the number of rows modified by the |
| 2065 | | -** previous INSERT, UPDATE or DELETE statement within the same trigger. |
| 2002 | +** ^This function returns the number of database rows that were changed |
| 2003 | +** or inserted or deleted by the most recently completed SQL statement |
| 2004 | +** on the [database connection] specified by the first parameter. |
| 2005 | +** ^(Only changes that are directly specified by the [INSERT], [UPDATE], |
| 2006 | +** or [DELETE] statement are counted. Auxiliary changes caused by |
| 2007 | +** triggers or [foreign key actions] are not counted.)^ Use the |
| 2008 | +** [sqlite3_total_changes()] function to find the total number of changes |
| 2009 | +** including changes caused by triggers and foreign key actions. |
| 2010 | +** |
| 2011 | +** ^Changes to a view that are simulated by an [INSTEAD OF trigger] |
| 2012 | +** are not counted. Only real table changes are counted. |
| 2013 | +** |
| 2014 | +** ^(A "row change" is a change to a single row of a single table |
| 2015 | +** caused by an INSERT, DELETE, or UPDATE statement. Rows that |
| 2016 | +** are changed as side effects of [REPLACE] constraint resolution, |
| 2017 | +** rollback, ABORT processing, [DROP TABLE], or by any other |
| 2018 | +** mechanisms do not count as direct row changes.)^ |
| 2019 | +** |
| 2020 | +** A "trigger context" is a scope of execution that begins and |
| 2021 | +** ends with the script of a [CREATE TRIGGER | trigger]. |
| 2022 | +** Most SQL statements are |
| 2023 | +** evaluated outside of any trigger. This is the "top level" |
| 2024 | +** trigger context. If a trigger fires from the top level, a |
| 2025 | +** new trigger context is entered for the duration of that one |
| 2026 | +** trigger. Subtriggers create subcontexts for their duration. |
| 2027 | +** |
| 2028 | +** ^Calling [sqlite3_exec()] or [sqlite3_step()] recursively does |
| 2029 | +** not create a new trigger context. |
| 2030 | +** |
| 2031 | +** ^This function returns the number of direct row changes in the |
| 2032 | +** most recent INSERT, UPDATE, or DELETE statement within the same |
| 2033 | +** trigger context. |
| 2034 | +** |
| 2035 | +** ^Thus, when called from the top level, this function returns the |
| 2036 | +** number of changes in the most recent INSERT, UPDATE, or DELETE |
| 2037 | +** that also occurred at the top level. ^(Within the body of a trigger, |
| 2038 | +** the sqlite3_changes() interface can be called to find the number of |
| 2039 | +** changes in the most recently completed INSERT, UPDATE, or DELETE |
| 2040 | +** statement within the body of the same trigger. |
| 2041 | +** However, the number returned does not include changes |
| 2042 | +** caused by subtriggers since those have their own context.)^ |
| 2066 | 2043 | ** |
| 2067 | 2044 | ** See also the [sqlite3_total_changes()] interface, the |
| 2068 | 2045 | ** [count_changes pragma], and the [changes() SQL function]. |
| 2069 | 2046 | ** |
| 2070 | 2047 | ** If a separate thread makes changes on the same database connection |
| | @@ -2074,21 +2051,24 @@ |
| 2074 | 2051 | SQLITE_API int sqlite3_changes(sqlite3*); |
| 2075 | 2052 | |
| 2076 | 2053 | /* |
| 2077 | 2054 | ** CAPI3REF: Total Number Of Rows Modified |
| 2078 | 2055 | ** |
| 2079 | | -** ^This function returns the total number of rows inserted, modified or |
| 2080 | | -** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed |
| 2081 | | -** since the database connection was opened, including those executed as |
| 2082 | | -** part of trigger programs. ^Executing any other type of SQL statement |
| 2083 | | -** does not affect the value returned by sqlite3_total_changes(). |
| 2084 | | -** |
| 2085 | | -** ^Changes made as part of [foreign key actions] are included in the |
| 2086 | | -** count, but those made as part of REPLACE constraint resolution are |
| 2087 | | -** not. ^Changes to a view that are intercepted by INSTEAD OF triggers |
| 2088 | | -** are not counted. |
| 2089 | | -** |
| 2056 | +** ^This function returns the number of row changes caused by [INSERT], |
| 2057 | +** [UPDATE] or [DELETE] statements since the [database connection] was opened. |
| 2058 | +** ^(The count returned by sqlite3_total_changes() includes all changes |
| 2059 | +** from all [CREATE TRIGGER | trigger] contexts and changes made by |
| 2060 | +** [foreign key actions]. However, |
| 2061 | +** the count does not include changes used to implement [REPLACE] constraints, |
| 2062 | +** do rollbacks or ABORT processing, or [DROP TABLE] processing. The |
| 2063 | +** count does not include rows of views that fire an [INSTEAD OF trigger], |
| 2064 | +** though if the INSTEAD OF trigger makes changes of its own, those changes |
| 2065 | +** are counted.)^ |
| 2066 | +** ^The sqlite3_total_changes() function counts the changes as soon as |
| 2067 | +** the statement that makes them is completed (when the statement handle |
| 2068 | +** is passed to [sqlite3_reset()] or [sqlite3_finalize()]). |
| 2069 | +** |
| 2090 | 2070 | ** See also the [sqlite3_changes()] interface, the |
| 2091 | 2071 | ** [count_changes pragma], and the [total_changes() SQL function]. |
| 2092 | 2072 | ** |
| 2093 | 2073 | ** If a separate thread makes changes on the same database connection |
| 2094 | 2074 | ** while [sqlite3_total_changes()] is running then the value |
| | @@ -2562,18 +2542,17 @@ |
| 2562 | 2542 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2563 | 2543 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2564 | 2544 | ** applications to access the same PRNG for other purposes. |
| 2565 | 2545 | ** |
| 2566 | 2546 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2567 | | -** ^The P parameter can be a NULL pointer. |
| 2547 | +** ^If N is less than one, then P can be a NULL pointer. |
| 2568 | 2548 | ** |
| 2569 | 2549 | ** ^If this routine has not been previously called or if the previous |
| 2570 | | -** call had N less than one or a NULL pointer for P, then the PRNG is |
| 2571 | | -** seeded using randomness obtained from the xRandomness method of |
| 2572 | | -** the default [sqlite3_vfs] object. |
| 2573 | | -** ^If the previous call to this routine had an N of 1 or more and a |
| 2574 | | -** non-NULL P then the pseudo-randomness is generated |
| 2550 | +** call had N less than one, then the PRNG is seeded using randomness |
| 2551 | +** obtained from the xRandomness method of the default [sqlite3_vfs] object. |
| 2552 | +** ^If the previous call to this routine had an N of 1 or more then |
| 2553 | +** the pseudo-randomness is generated |
| 2575 | 2554 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2576 | 2555 | ** method. |
| 2577 | 2556 | */ |
| 2578 | 2557 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2579 | 2558 | |
| | @@ -5784,46 +5763,30 @@ |
| 5784 | 5763 | ** |
| 5785 | 5764 | ** <pre> |
| 5786 | 5765 | ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow; |
| 5787 | 5766 | ** </pre>)^ |
| 5788 | 5767 | ** |
| 5789 | | -** ^(Parameter zDb is not the filename that contains the database, but |
| 5790 | | -** rather the symbolic name of the database. For attached databases, this is |
| 5791 | | -** the name that appears after the AS keyword in the [ATTACH] statement. |
| 5792 | | -** For the main database file, the database name is "main". For TEMP |
| 5793 | | -** tables, the database name is "temp".)^ |
| 5794 | | -** |
| 5795 | 5768 | ** ^If the flags parameter is non-zero, then the BLOB is opened for read |
| 5796 | | -** and write access. ^If the flags parameter is zero, the BLOB is opened for |
| 5797 | | -** read-only access. |
| 5798 | | -** |
| 5799 | | -** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored |
| 5800 | | -** in *ppBlob. Otherwise an [error code] is returned and, unless the error |
| 5801 | | -** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided |
| 5802 | | -** the API is not misused, it is always safe to call [sqlite3_blob_close()] |
| 5803 | | -** on *ppBlob after this function it returns. |
| 5804 | | -** |
| 5805 | | -** This function fails with SQLITE_ERROR if any of the following are true: |
| 5806 | | -** <ul> |
| 5807 | | -** <li> ^(Database zDb does not exist)^, |
| 5808 | | -** <li> ^(Table zTable does not exist within database zDb)^, |
| 5809 | | -** <li> ^(Table zTable is a WITHOUT ROWID table)^, |
| 5810 | | -** <li> ^(Column zColumn does not exist)^, |
| 5811 | | -** <li> ^(Row iRow is not present in the table)^, |
| 5812 | | -** <li> ^(The specified column of row iRow contains a value that is not |
| 5813 | | -** a TEXT or BLOB value)^, |
| 5814 | | -** <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE |
| 5815 | | -** constraint and the blob is being opened for read/write access)^, |
| 5816 | | -** <li> ^([foreign key constraints | Foreign key constraints] are enabled, |
| 5817 | | -** column zColumn is part of a [child key] definition and the blob is |
| 5818 | | -** being opened for read/write access)^. |
| 5819 | | -** </ul> |
| 5820 | | -** |
| 5821 | | -** ^Unless it returns SQLITE_MISUSE, this function sets the |
| 5822 | | -** [database connection] error code and message accessible via |
| 5823 | | -** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. |
| 5824 | | -** |
| 5769 | +** and write access. ^If it is zero, the BLOB is opened for read access. |
| 5770 | +** ^It is not possible to open a column that is part of an index or primary |
| 5771 | +** key for writing. ^If [foreign key constraints] are enabled, it is |
| 5772 | +** not possible to open a column that is part of a [child key] for writing. |
| 5773 | +** |
| 5774 | +** ^Note that the database name is not the filename that contains |
| 5775 | +** the database but rather the symbolic name of the database that |
| 5776 | +** appears after the AS keyword when the database is connected using [ATTACH]. |
| 5777 | +** ^For the main database file, the database name is "main". |
| 5778 | +** ^For TEMP tables, the database name is "temp". |
| 5779 | +** |
| 5780 | +** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is written |
| 5781 | +** to *ppBlob. Otherwise an [error code] is returned and *ppBlob is set |
| 5782 | +** to be a null pointer.)^ |
| 5783 | +** ^This function sets the [database connection] error code and message |
| 5784 | +** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()] and related |
| 5785 | +** functions. ^Note that the *ppBlob variable is always initialized in a |
| 5786 | +** way that makes it safe to invoke [sqlite3_blob_close()] on *ppBlob |
| 5787 | +** regardless of the success or failure of this routine. |
| 5825 | 5788 | ** |
| 5826 | 5789 | ** ^(If the row that a BLOB handle points to is modified by an |
| 5827 | 5790 | ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects |
| 5828 | 5791 | ** then the BLOB handle is marked as "expired". |
| 5829 | 5792 | ** This is true if any column of the row is changed, even a column |
| | @@ -5837,13 +5800,17 @@ |
| 5837 | 5800 | ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of |
| 5838 | 5801 | ** the opened blob. ^The size of a blob may not be changed by this |
| 5839 | 5802 | ** interface. Use the [UPDATE] SQL command to change the size of a |
| 5840 | 5803 | ** blob. |
| 5841 | 5804 | ** |
| 5805 | +** ^The [sqlite3_blob_open()] interface will fail for a [WITHOUT ROWID] |
| 5806 | +** table. Incremental BLOB I/O is not possible on [WITHOUT ROWID] tables. |
| 5807 | +** |
| 5842 | 5808 | ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces |
| 5843 | | -** and the built-in [zeroblob] SQL function may be used to create a |
| 5844 | | -** zero-filled blob to read or write using the incremental-blob interface. |
| 5809 | +** and the built-in [zeroblob] SQL function can be used, if desired, |
| 5810 | +** to create an empty, zero-filled blob in which to read or write using |
| 5811 | +** this interface. |
| 5845 | 5812 | ** |
| 5846 | 5813 | ** To avoid a resource leak, every open [BLOB handle] should eventually |
| 5847 | 5814 | ** be released by a call to [sqlite3_blob_close()]. |
| 5848 | 5815 | */ |
| 5849 | 5816 | SQLITE_API int sqlite3_blob_open( |
| | @@ -5881,26 +5848,28 @@ |
| 5881 | 5848 | SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); |
| 5882 | 5849 | |
| 5883 | 5850 | /* |
| 5884 | 5851 | ** CAPI3REF: Close A BLOB Handle |
| 5885 | 5852 | ** |
| 5886 | | -** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed |
| 5887 | | -** unconditionally. Even if this routine returns an error code, the |
| 5888 | | -** handle is still closed.)^ |
| 5889 | | -** |
| 5890 | | -** ^If the blob handle being closed was opened for read-write access, and if |
| 5891 | | -** the database is in auto-commit mode and there are no other open read-write |
| 5892 | | -** blob handles or active write statements, the current transaction is |
| 5893 | | -** committed. ^If an error occurs while committing the transaction, an error |
| 5894 | | -** code is returned and the transaction rolled back. |
| 5895 | | -** |
| 5896 | | -** Calling this function with an argument that is not a NULL pointer or an |
| 5897 | | -** open blob handle results in undefined behaviour. ^Calling this routine |
| 5898 | | -** with a null pointer (such as would be returned by a failed call to |
| 5899 | | -** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function |
| 5900 | | -** is passed a valid open blob handle, the values returned by the |
| 5901 | | -** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning. |
| 5853 | +** ^Closes an open [BLOB handle]. |
| 5854 | +** |
| 5855 | +** ^Closing a BLOB shall cause the current transaction to commit |
| 5856 | +** if there are no other BLOBs, no pending prepared statements, and the |
| 5857 | +** database connection is in [autocommit mode]. |
| 5858 | +** ^If any writes were made to the BLOB, they might be held in cache |
| 5859 | +** until the close operation if they will fit. |
| 5860 | +** |
| 5861 | +** ^(Closing the BLOB often forces the changes |
| 5862 | +** out to disk and so if any I/O errors occur, they will likely occur |
| 5863 | +** at the time when the BLOB is closed. Any errors that occur during |
| 5864 | +** closing are reported as a non-zero return value.)^ |
| 5865 | +** |
| 5866 | +** ^(The BLOB is closed unconditionally. Even if this routine returns |
| 5867 | +** an error code, the BLOB is still closed.)^ |
| 5868 | +** |
| 5869 | +** ^Calling this routine with a null pointer (such as would be returned |
| 5870 | +** by a failed call to [sqlite3_blob_open()]) is a harmless no-op. |
| 5902 | 5871 | */ |
| 5903 | 5872 | SQLITE_API int sqlite3_blob_close(sqlite3_blob *); |
| 5904 | 5873 | |
| 5905 | 5874 | /* |
| 5906 | 5875 | ** CAPI3REF: Return The Size Of An Open BLOB |
| | @@ -5946,39 +5915,36 @@ |
| 5946 | 5915 | SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); |
| 5947 | 5916 | |
| 5948 | 5917 | /* |
| 5949 | 5918 | ** CAPI3REF: Write Data Into A BLOB Incrementally |
| 5950 | 5919 | ** |
| 5951 | | -** ^(This function is used to write data into an open [BLOB handle] from a |
| 5952 | | -** caller-supplied buffer. N bytes of data are copied from the buffer Z |
| 5953 | | -** into the open BLOB, starting at offset iOffset.)^ |
| 5954 | | -** |
| 5955 | | -** ^(On success, sqlite3_blob_write() returns SQLITE_OK. |
| 5956 | | -** Otherwise, an [error code] or an [extended error code] is returned.)^ |
| 5957 | | -** ^Unless SQLITE_MISUSE is returned, this function sets the |
| 5958 | | -** [database connection] error code and message accessible via |
| 5959 | | -** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. |
| 5920 | +** ^This function is used to write data into an open [BLOB handle] from a |
| 5921 | +** caller-supplied buffer. ^N bytes of data are copied from the buffer Z |
| 5922 | +** into the open BLOB, starting at offset iOffset. |
| 5960 | 5923 | ** |
| 5961 | 5924 | ** ^If the [BLOB handle] passed as the first argument was not opened for |
| 5962 | 5925 | ** writing (the flags parameter to [sqlite3_blob_open()] was zero), |
| 5963 | 5926 | ** this function returns [SQLITE_READONLY]. |
| 5964 | 5927 | ** |
| 5965 | | -** This function may only modify the contents of the BLOB; it is |
| 5928 | +** ^This function may only modify the contents of the BLOB; it is |
| 5966 | 5929 | ** not possible to increase the size of a BLOB using this API. |
| 5967 | 5930 | ** ^If offset iOffset is less than N bytes from the end of the BLOB, |
| 5968 | | -** [SQLITE_ERROR] is returned and no data is written. The size of the |
| 5969 | | -** BLOB (and hence the maximum value of N+iOffset) can be determined |
| 5970 | | -** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less |
| 5971 | | -** than zero [SQLITE_ERROR] is returned and no data is written. |
| 5931 | +** [SQLITE_ERROR] is returned and no data is written. ^If N is |
| 5932 | +** less than zero [SQLITE_ERROR] is returned and no data is written. |
| 5933 | +** The size of the BLOB (and hence the maximum value of N+iOffset) |
| 5934 | +** can be determined using the [sqlite3_blob_bytes()] interface. |
| 5972 | 5935 | ** |
| 5973 | 5936 | ** ^An attempt to write to an expired [BLOB handle] fails with an |
| 5974 | 5937 | ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred |
| 5975 | 5938 | ** before the [BLOB handle] expired are not rolled back by the |
| 5976 | 5939 | ** expiration of the handle, though of course those changes might |
| 5977 | 5940 | ** have been overwritten by the statement that expired the BLOB handle |
| 5978 | 5941 | ** or by other independent statements. |
| 5979 | 5942 | ** |
| 5943 | +** ^(On success, sqlite3_blob_write() returns SQLITE_OK. |
| 5944 | +** Otherwise, an [error code] or an [extended error code] is returned.)^ |
| 5945 | +** |
| 5980 | 5946 | ** This routine only works on a [BLOB handle] which has been created |
| 5981 | 5947 | ** by a prior successful call to [sqlite3_blob_open()] and which has not |
| 5982 | 5948 | ** been closed by [sqlite3_blob_close()]. Passing any other pointer in |
| 5983 | 5949 | ** to this routine results in undefined and probably undesirable behavior. |
| 5984 | 5950 | ** |
| | @@ -7567,102 +7533,10 @@ |
| 7567 | 7533 | /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */ |
| 7568 | 7534 | #define SQLITE_FAIL 3 |
| 7569 | 7535 | /* #define SQLITE_ABORT 4 // Also an error code */ |
| 7570 | 7536 | #define SQLITE_REPLACE 5 |
| 7571 | 7537 | |
| 7572 | | -/* |
| 7573 | | -** CAPI3REF: Prepared Statement Scan Status Opcodes |
| 7574 | | -** KEYWORDS: {scanstatus options} |
| 7575 | | -** |
| 7576 | | -** The following constants can be used for the T parameter to the |
| 7577 | | -** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a |
| 7578 | | -** different metric for sqlite3_stmt_scanstatus() to return. |
| 7579 | | -** |
| 7580 | | -** <dl> |
| 7581 | | -** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt> |
| 7582 | | -** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the |
| 7583 | | -** total number of times that the X-th loop has run.</dd> |
| 7584 | | -** |
| 7585 | | -** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt> |
| 7586 | | -** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the |
| 7587 | | -** total number of rows examined by all iterations of the X-th loop.</dd> |
| 7588 | | -** |
| 7589 | | -** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt> |
| 7590 | | -** <dd>^The "double" variable pointed to by the T parameter will be set to the |
| 7591 | | -** query planner's estimate for the average number of rows output from each |
| 7592 | | -** iteration of the X-th loop. If the query planner's estimates was accurate, |
| 7593 | | -** then this value will approximate the quotient NVISIT/NLOOP and the |
| 7594 | | -** product of this value for all prior loops with the same SELECTID will |
| 7595 | | -** be the NLOOP value for the current loop. |
| 7596 | | -** |
| 7597 | | -** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt> |
| 7598 | | -** <dd>^The "const char *" variable pointed to by the T parameter will be set to |
| 7599 | | -** a zero-terminated UTF-8 string containing the name of the index or table used |
| 7600 | | -** for the X-th loop. |
| 7601 | | -** |
| 7602 | | -** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt> |
| 7603 | | -** <dd>^The "const char *" variable pointed to by the T parameter will be set to |
| 7604 | | -** a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN] description |
| 7605 | | -** for the X-th loop. |
| 7606 | | -** |
| 7607 | | -** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt> |
| 7608 | | -** <dd>^The "int" variable pointed to by the T parameter will be set to the |
| 7609 | | -** "select-id" for the X-th loop. The select-id identifies which query or |
| 7610 | | -** subquery the loop is part of. The main query has a select-id of zero. |
| 7611 | | -** The select-id is the same value as is output in the first column |
| 7612 | | -** of an [EXPLAIN QUERY PLAN] query. |
| 7613 | | -** </dl> |
| 7614 | | -*/ |
| 7615 | | -#define SQLITE_SCANSTAT_NLOOP 0 |
| 7616 | | -#define SQLITE_SCANSTAT_NVISIT 1 |
| 7617 | | -#define SQLITE_SCANSTAT_EST 2 |
| 7618 | | -#define SQLITE_SCANSTAT_NAME 3 |
| 7619 | | -#define SQLITE_SCANSTAT_EXPLAIN 4 |
| 7620 | | -#define SQLITE_SCANSTAT_SELECTID 5 |
| 7621 | | - |
| 7622 | | -/* |
| 7623 | | -** CAPI3REF: Prepared Statement Scan Status |
| 7624 | | -** |
| 7625 | | -** Return status data for a single loop within query pStmt. |
| 7626 | | -** |
| 7627 | | -** The "iScanStatusOp" parameter determines which status information to return. |
| 7628 | | -** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior of |
| 7629 | | -** this interface is undefined. |
| 7630 | | -** ^The requested measurement is written into a variable pointed to by |
| 7631 | | -** the "pOut" parameter. |
| 7632 | | -** Parameter "idx" identifies the specific loop to retrieve statistics for. |
| 7633 | | -** Loops are numbered starting from zero. ^If idx is out of range - less than |
| 7634 | | -** zero or greater than or equal to the total number of loops used to implement |
| 7635 | | -** the statement - a non-zero value is returned and the variable that pOut |
| 7636 | | -** points to is unchanged. |
| 7637 | | -** |
| 7638 | | -** ^Statistics might not be available for all loops in all statements. ^In cases |
| 7639 | | -** where there exist loops with no available statistics, this function behaves |
| 7640 | | -** as if the loop did not exist - it returns non-zero and leave the variable |
| 7641 | | -** that pOut points to unchanged. |
| 7642 | | -** |
| 7643 | | -** This API is only available if the library is built with pre-processor |
| 7644 | | -** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. |
| 7645 | | -** |
| 7646 | | -** See also: [sqlite3_stmt_scanstatus_reset()] |
| 7647 | | -*/ |
| 7648 | | -SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus( |
| 7649 | | - sqlite3_stmt *pStmt, /* Prepared statement for which info desired */ |
| 7650 | | - int idx, /* Index of loop to report on */ |
| 7651 | | - int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */ |
| 7652 | | - void *pOut /* Result written here */ |
| 7653 | | -); |
| 7654 | | - |
| 7655 | | -/* |
| 7656 | | -** CAPI3REF: Zero Scan-Status Counters |
| 7657 | | -** |
| 7658 | | -** ^Zero all [sqlite3_stmt_scanstatus()] related event counters. |
| 7659 | | -** |
| 7660 | | -** This API is only available if the library is built with pre-processor |
| 7661 | | -** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. |
| 7662 | | -*/ |
| 7663 | | -SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*); |
| 7664 | 7538 | |
| 7665 | 7539 | |
| 7666 | 7540 | /* |
| 7667 | 7541 | ** Undo the hack that converts floating point types to integer for |
| 7668 | 7542 | ** builds on processors without floating point support. |
| | @@ -8104,13 +7978,14 @@ |
| 8104 | 7978 | #ifndef SQLITE_POWERSAFE_OVERWRITE |
| 8105 | 7979 | # define SQLITE_POWERSAFE_OVERWRITE 1 |
| 8106 | 7980 | #endif |
| 8107 | 7981 | |
| 8108 | 7982 | /* |
| 8109 | | -** EVIDENCE-OF: R-25715-37072 Memory allocation statistics are enabled by |
| 8110 | | -** default unless SQLite is compiled with SQLITE_DEFAULT_MEMSTATUS=0 in |
| 8111 | | -** which case memory allocation statistics are disabled by default. |
| 7983 | +** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1. |
| 7984 | +** It determines whether or not the features related to |
| 7985 | +** SQLITE_CONFIG_MEMSTATUS are available by default or not. This value can |
| 7986 | +** be overridden at runtime using the sqlite3_config() API. |
| 8112 | 7987 | */ |
| 8113 | 7988 | #if !defined(SQLITE_DEFAULT_MEMSTATUS) |
| 8114 | 7989 | # define SQLITE_DEFAULT_MEMSTATUS 1 |
| 8115 | 7990 | #endif |
| 8116 | 7991 | |
| | @@ -8736,11 +8611,11 @@ |
| 8736 | 8611 | ** Estimated quantities used for query planning are stored as 16-bit |
| 8737 | 8612 | ** logarithms. For quantity X, the value stored is 10*log2(X). This |
| 8738 | 8613 | ** gives a possible range of values of approximately 1.0e986 to 1e-986. |
| 8739 | 8614 | ** But the allowed values are "grainy". Not every value is representable. |
| 8740 | 8615 | ** For example, quantities 16 and 17 are both represented by a LogEst |
| 8741 | | -** of 40. However, since LogEst quantities are suppose to be estimates, |
| 8616 | +** of 40. However, since LogEst quantaties are suppose to be estimates, |
| 8742 | 8617 | ** not exact values, this imprecision is not a problem. |
| 8743 | 8618 | ** |
| 8744 | 8619 | ** "LogEst" is short for "Logarithmic Estimate". |
| 8745 | 8620 | ** |
| 8746 | 8621 | ** Examples: |
| | @@ -9169,11 +9044,11 @@ |
| 9169 | 9044 | #define BTREE_BLOBKEY 2 /* Table has keys only - no data */ |
| 9170 | 9045 | |
| 9171 | 9046 | SQLITE_PRIVATE int sqlite3BtreeDropTable(Btree*, int, int*); |
| 9172 | 9047 | SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree*, int, int*); |
| 9173 | 9048 | SQLITE_PRIVATE int sqlite3BtreeClearTableOfCursor(BtCursor*); |
| 9174 | | -SQLITE_PRIVATE void sqlite3BtreeTripAllCursors(Btree*, int, int); |
| 9049 | +SQLITE_PRIVATE int sqlite3BtreeTripAllCursors(Btree*, int, int); |
| 9175 | 9050 | |
| 9176 | 9051 | SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *pBtree, int idx, u32 *pValue); |
| 9177 | 9052 | SQLITE_PRIVATE int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value); |
| 9178 | 9053 | |
| 9179 | 9054 | SQLITE_PRIVATE int sqlite3BtreeNewDb(Btree *p); |
| | @@ -9249,11 +9124,10 @@ |
| 9249 | 9124 | SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *); |
| 9250 | 9125 | SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *); |
| 9251 | 9126 | SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion); |
| 9252 | 9127 | SQLITE_PRIVATE void sqlite3BtreeCursorHints(BtCursor *, unsigned int mask); |
| 9253 | 9128 | SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *pBt); |
| 9254 | | -SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void); |
| 9255 | 9129 | |
| 9256 | 9130 | #ifndef NDEBUG |
| 9257 | 9131 | SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*); |
| 9258 | 9132 | #endif |
| 9259 | 9133 | |
| | @@ -9792,16 +9666,10 @@ |
| 9792 | 9666 | # define VdbeCoverageAlwaysTaken(v) |
| 9793 | 9667 | # define VdbeCoverageNeverTaken(v) |
| 9794 | 9668 | # define VDBE_OFFSET_LINENO(x) 0 |
| 9795 | 9669 | #endif |
| 9796 | 9670 | |
| 9797 | | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 9798 | | -SQLITE_PRIVATE void sqlite3VdbeScanStatus(Vdbe*, int, int, int, LogEst, const char*); |
| 9799 | | -#else |
| 9800 | | -# define sqlite3VdbeScanStatus(a,b,c,d,e) |
| 9801 | | -#endif |
| 9802 | | - |
| 9803 | 9671 | #endif |
| 9804 | 9672 | |
| 9805 | 9673 | /************** End of vdbe.h ************************************************/ |
| 9806 | 9674 | /************** Continuing where we left off in sqliteInt.h ******************/ |
| 9807 | 9675 | /************** Include pager.h in the middle of sqliteInt.h *****************/ |
| | @@ -9994,12 +9862,10 @@ |
| 9994 | 9862 | SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *); |
| 9995 | 9863 | |
| 9996 | 9864 | /* Functions used to truncate the database file. */ |
| 9997 | 9865 | SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno); |
| 9998 | 9866 | |
| 9999 | | -SQLITE_PRIVATE void sqlite3PagerRekey(DbPage*, Pgno, u16); |
| 10000 | | - |
| 10001 | 9867 | #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_WAL) |
| 10002 | 9868 | SQLITE_PRIVATE void *sqlite3PagerCodec(DbPage *); |
| 10003 | 9869 | #endif |
| 10004 | 9870 | |
| 10005 | 9871 | /* Functions to support testing and debugging. */ |
| | @@ -10183,14 +10049,10 @@ |
| 10183 | 10049 | SQLITE_PRIVATE void sqlite3PcacheStats(int*,int*,int*,int*); |
| 10184 | 10050 | #endif |
| 10185 | 10051 | |
| 10186 | 10052 | SQLITE_PRIVATE void sqlite3PCacheSetDefault(void); |
| 10187 | 10053 | |
| 10188 | | -/* Return the header size */ |
| 10189 | | -SQLITE_PRIVATE int sqlite3HeaderSizePcache(void); |
| 10190 | | -SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void); |
| 10191 | | - |
| 10192 | 10054 | #endif /* _PCACHE_H_ */ |
| 10193 | 10055 | |
| 10194 | 10056 | /************** End of pcache.h **********************************************/ |
| 10195 | 10057 | /************** Continuing where we left off in sqliteInt.h ******************/ |
| 10196 | 10058 | |
| | @@ -10873,11 +10735,11 @@ |
| 10873 | 10735 | #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */ |
| 10874 | 10736 | #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */ |
| 10875 | 10737 | #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */ |
| 10876 | 10738 | #define SQLITE_Transitive 0x0200 /* Transitive constraints */ |
| 10877 | 10739 | #define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */ |
| 10878 | | -#define SQLITE_Stat34 0x0800 /* Use STAT3 or STAT4 data */ |
| 10740 | +#define SQLITE_Stat3 0x0800 /* Use the SQLITE_STAT3 table */ |
| 10879 | 10741 | #define SQLITE_AllOpts 0xffff /* All optimizations */ |
| 10880 | 10742 | |
| 10881 | 10743 | /* |
| 10882 | 10744 | ** Macros for testing whether or not optimizations are enabled or disabled. |
| 10883 | 10745 | */ |
| | @@ -11460,12 +11322,11 @@ |
| 11460 | 11322 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 11461 | 11323 | int nSample; /* Number of elements in aSample[] */ |
| 11462 | 11324 | int nSampleCol; /* Size of IndexSample.anEq[] and so on */ |
| 11463 | 11325 | tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */ |
| 11464 | 11326 | IndexSample *aSample; /* Samples of the left-most key */ |
| 11465 | | - tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this index */ |
| 11466 | | - tRowcnt nRowEst0; /* Non-logarithmic number of rows in the index */ |
| 11327 | + tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this table */ |
| 11467 | 11328 | #endif |
| 11468 | 11329 | }; |
| 11469 | 11330 | |
| 11470 | 11331 | /* |
| 11471 | 11332 | ** Allowed values for Index.idxType |
| | @@ -11659,11 +11520,11 @@ |
| 11659 | 11520 | int nHeight; /* Height of the tree headed by this node */ |
| 11660 | 11521 | #endif |
| 11661 | 11522 | int iTable; /* TK_COLUMN: cursor number of table holding column |
| 11662 | 11523 | ** TK_REGISTER: register number |
| 11663 | 11524 | ** TK_TRIGGER: 1 -> new, 0 -> old |
| 11664 | | - ** EP_Unlikely: 134217728 times likelihood */ |
| 11525 | + ** EP_Unlikely: 1000 times likelihood */ |
| 11665 | 11526 | ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid. |
| 11666 | 11527 | ** TK_VARIABLE: variable number (always >= 1). */ |
| 11667 | 11528 | i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */ |
| 11668 | 11529 | i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */ |
| 11669 | 11530 | u8 op2; /* TK_REGISTER: original value of Expr.op |
| | @@ -12551,15 +12412,13 @@ |
| 12551 | 12412 | int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */ |
| 12552 | 12413 | int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */ |
| 12553 | 12414 | void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */ |
| 12554 | 12415 | Parse *pParse; /* Parser context. */ |
| 12555 | 12416 | int walkerDepth; /* Number of subqueries */ |
| 12556 | | - u8 eCode; /* A small processing code */ |
| 12557 | 12417 | union { /* Extra data for callback */ |
| 12558 | 12418 | NameContext *pNC; /* Naming context */ |
| 12559 | | - int n; /* A counter */ |
| 12560 | | - int iCur; /* A cursor number */ |
| 12419 | + int i; /* Integer value */ |
| 12561 | 12420 | SrcList *pSrcList; /* FROM clause */ |
| 12562 | 12421 | struct SrcCount *pSrcCount; /* Counting column references */ |
| 12563 | 12422 | } u; |
| 12564 | 12423 | }; |
| 12565 | 12424 | |
| | @@ -12956,11 +12815,10 @@ |
| 12956 | 12815 | SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *); |
| 12957 | 12816 | SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*); |
| 12958 | 12817 | SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*); |
| 12959 | 12818 | SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*); |
| 12960 | 12819 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8); |
| 12961 | | -SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int); |
| 12962 | 12820 | SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*); |
| 12963 | 12821 | SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*); |
| 12964 | 12822 | SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char); |
| 12965 | 12823 | SQLITE_PRIVATE int sqlite3IsRowid(const char*); |
| 12966 | 12824 | SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8); |
| | @@ -13614,23 +13472,15 @@ |
| 13614 | 13472 | ** compatibility for legacy applications, the URI filename capability is |
| 13615 | 13473 | ** disabled by default. |
| 13616 | 13474 | ** |
| 13617 | 13475 | ** EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled |
| 13618 | 13476 | ** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options. |
| 13619 | | -** |
| 13620 | | -** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally |
| 13621 | | -** disabled. The default value may be changed by compiling with the |
| 13622 | | -** SQLITE_USE_URI symbol defined. |
| 13623 | 13477 | */ |
| 13624 | 13478 | #ifndef SQLITE_USE_URI |
| 13625 | 13479 | # define SQLITE_USE_URI 0 |
| 13626 | 13480 | #endif |
| 13627 | 13481 | |
| 13628 | | -/* EVIDENCE-OF: R-38720-18127 The default setting is determined by the |
| 13629 | | -** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if |
| 13630 | | -** that compile-time option is omitted. |
| 13631 | | -*/ |
| 13632 | 13482 | #ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN |
| 13633 | 13483 | # define SQLITE_ALLOW_COVERING_INDEX_SCAN 1 |
| 13634 | 13484 | #endif |
| 13635 | 13485 | |
| 13636 | 13486 | /* |
| | @@ -13716,12 +13566,12 @@ |
| 13716 | 13566 | ** than 1 GiB. The sqlite3_test_control() interface can be used to |
| 13717 | 13567 | ** move the pending byte. |
| 13718 | 13568 | ** |
| 13719 | 13569 | ** IMPORTANT: Changing the pending byte to any value other than |
| 13720 | 13570 | ** 0x40000000 results in an incompatible database file format! |
| 13721 | | -** Changing the pending byte during operation will result in undefined |
| 13722 | | -** and incorrect behavior. |
| 13571 | +** Changing the pending byte during operating results in undefined |
| 13572 | +** and dileterious behavior. |
| 13723 | 13573 | */ |
| 13724 | 13574 | #ifndef SQLITE_OMIT_WSD |
| 13725 | 13575 | SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000; |
| 13726 | 13576 | #endif |
| 13727 | 13577 | |
| | @@ -13797,13 +13647,10 @@ |
| 13797 | 13647 | "DISABLE_DIRSYNC", |
| 13798 | 13648 | #endif |
| 13799 | 13649 | #ifdef SQLITE_DISABLE_LFS |
| 13800 | 13650 | "DISABLE_LFS", |
| 13801 | 13651 | #endif |
| 13802 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 13803 | | - "ENABLE_API_ARMOR", |
| 13804 | | -#endif |
| 13805 | 13652 | #ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 13806 | 13653 | "ENABLE_ATOMIC_WRITE", |
| 13807 | 13654 | #endif |
| 13808 | 13655 | #ifdef SQLITE_ENABLE_CEROD |
| 13809 | 13656 | "ENABLE_CEROD", |
| | @@ -14125,17 +13972,10 @@ |
| 14125 | 13972 | ** The name can optionally begin with "SQLITE_" but the "SQLITE_" prefix |
| 14126 | 13973 | ** is not required for a match. |
| 14127 | 13974 | */ |
| 14128 | 13975 | SQLITE_API int sqlite3_compileoption_used(const char *zOptName){ |
| 14129 | 13976 | int i, n; |
| 14130 | | - |
| 14131 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 14132 | | - if( zOptName==0 ){ |
| 14133 | | - (void)SQLITE_MISUSE_BKPT; |
| 14134 | | - return 0; |
| 14135 | | - } |
| 14136 | | -#endif |
| 14137 | 13977 | if( sqlite3StrNICmp(zOptName, "SQLITE_", 7)==0 ) zOptName += 7; |
| 14138 | 13978 | n = sqlite3Strlen30(zOptName); |
| 14139 | 13979 | |
| 14140 | 13980 | /* Since ArraySize(azCompileOpt) is normally in single digits, a |
| 14141 | 13981 | ** linear search is adequate. No need for a binary search. */ |
| | @@ -14313,11 +14153,10 @@ |
| 14313 | 14153 | typedef struct VdbeFrame VdbeFrame; |
| 14314 | 14154 | struct VdbeFrame { |
| 14315 | 14155 | Vdbe *v; /* VM this frame belongs to */ |
| 14316 | 14156 | VdbeFrame *pParent; /* Parent of this frame, or NULL if parent is main */ |
| 14317 | 14157 | Op *aOp; /* Program instructions for parent frame */ |
| 14318 | | - i64 *anExec; /* Event counters from parent frame */ |
| 14319 | 14158 | Mem *aMem; /* Array of memory cells for parent frame */ |
| 14320 | 14159 | u8 *aOnceFlag; /* Array of OP_Once flags for parent frame */ |
| 14321 | 14160 | VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */ |
| 14322 | 14161 | void *token; /* Copy of SubProgram.token */ |
| 14323 | 14162 | i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */ |
| | @@ -14326,12 +14165,11 @@ |
| 14326 | 14165 | int nOp; /* Size of aOp array */ |
| 14327 | 14166 | int nMem; /* Number of entries in aMem */ |
| 14328 | 14167 | int nOnceFlag; /* Number of entries in aOnceFlag */ |
| 14329 | 14168 | int nChildMem; /* Number of memory cells for child frame */ |
| 14330 | 14169 | int nChildCsr; /* Number of cursors for child frame */ |
| 14331 | | - int nChange; /* Statement changes (Vdbe.nChange) */ |
| 14332 | | - int nDbChange; /* Value of db->nChange */ |
| 14170 | + int nChange; /* Statement changes (Vdbe.nChanges) */ |
| 14333 | 14171 | }; |
| 14334 | 14172 | |
| 14335 | 14173 | #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))]) |
| 14336 | 14174 | |
| 14337 | 14175 | /* |
| | @@ -14478,20 +14316,10 @@ |
| 14478 | 14316 | /* A bitfield type for use inside of structures. Always follow with :N where |
| 14479 | 14317 | ** N is the number of bits. |
| 14480 | 14318 | */ |
| 14481 | 14319 | typedef unsigned bft; /* Bit Field Type */ |
| 14482 | 14320 | |
| 14483 | | -typedef struct ScanStatus ScanStatus; |
| 14484 | | -struct ScanStatus { |
| 14485 | | - int addrExplain; /* OP_Explain for loop */ |
| 14486 | | - int addrLoop; /* Address of "loops" counter */ |
| 14487 | | - int addrVisit; /* Address of "rows visited" counter */ |
| 14488 | | - int iSelectID; /* The "Select-ID" for this loop */ |
| 14489 | | - LogEst nEst; /* Estimated output rows per loop */ |
| 14490 | | - char *zName; /* Name of table or index */ |
| 14491 | | -}; |
| 14492 | | - |
| 14493 | 14321 | /* |
| 14494 | 14322 | ** An instance of the virtual machine. This structure contains the complete |
| 14495 | 14323 | ** state of the virtual machine. |
| 14496 | 14324 | ** |
| 14497 | 14325 | ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare() |
| | @@ -14560,15 +14388,10 @@ |
| 14560 | 14388 | u32 expmask; /* Binding to these vars invalidates VM */ |
| 14561 | 14389 | SubProgram *pProgram; /* Linked list of all sub-programs used by VM */ |
| 14562 | 14390 | int nOnceFlag; /* Size of array aOnceFlag[] */ |
| 14563 | 14391 | u8 *aOnceFlag; /* Flags for OP_Once */ |
| 14564 | 14392 | AuxData *pAuxData; /* Linked list of auxdata allocations */ |
| 14565 | | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 14566 | | - i64 *anExec; /* Number of times each op has been executed */ |
| 14567 | | - int nScan; /* Entries in aScan[] */ |
| 14568 | | - ScanStatus *aScan; /* Scan definitions for sqlite3_stmt_scanstatus() */ |
| 14569 | | -#endif |
| 14570 | 14393 | }; |
| 14571 | 14394 | |
| 14572 | 14395 | /* |
| 14573 | 14396 | ** The following are allowed values for Vdbe.magic |
| 14574 | 14397 | */ |
| | @@ -14754,13 +14577,10 @@ |
| 14754 | 14577 | SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){ |
| 14755 | 14578 | wsdStatInit; |
| 14756 | 14579 | if( op<0 || op>=ArraySize(wsdStat.nowValue) ){ |
| 14757 | 14580 | return SQLITE_MISUSE_BKPT; |
| 14758 | 14581 | } |
| 14759 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 14760 | | - if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT; |
| 14761 | | -#endif |
| 14762 | 14582 | *pCurrent = wsdStat.nowValue[op]; |
| 14763 | 14583 | *pHighwater = wsdStat.mxValue[op]; |
| 14764 | 14584 | if( resetFlag ){ |
| 14765 | 14585 | wsdStat.mxValue[op] = wsdStat.nowValue[op]; |
| 14766 | 14586 | } |
| | @@ -14776,15 +14596,10 @@ |
| 14776 | 14596 | int *pCurrent, /* Write current value here */ |
| 14777 | 14597 | int *pHighwater, /* Write high-water mark here */ |
| 14778 | 14598 | int resetFlag /* Reset high-water mark if true */ |
| 14779 | 14599 | ){ |
| 14780 | 14600 | int rc = SQLITE_OK; /* Return code */ |
| 14781 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 14782 | | - if( !sqlite3SafetyCheckOk(db) || pCurrent==0|| pHighwater==0 ){ |
| 14783 | | - return SQLITE_MISUSE_BKPT; |
| 14784 | | - } |
| 14785 | | -#endif |
| 14786 | 14601 | sqlite3_mutex_enter(db->mutex); |
| 14787 | 14602 | switch( op ){ |
| 14788 | 14603 | case SQLITE_DBSTATUS_LOOKASIDE_USED: { |
| 14789 | 14604 | *pCurrent = db->lookaside.nOut; |
| 14790 | 14605 | *pHighwater = db->lookaside.mxOut; |
| | @@ -14959,11 +14774,11 @@ |
| 14959 | 14774 | ** |
| 14960 | 14775 | ** There is only one exported symbol in this file - the function |
| 14961 | 14776 | ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file. |
| 14962 | 14777 | ** All other code has file scope. |
| 14963 | 14778 | ** |
| 14964 | | -** SQLite processes all times and dates as julian day numbers. The |
| 14779 | +** SQLite processes all times and dates as Julian Day numbers. The |
| 14965 | 14780 | ** dates and times are stored as the number of days since noon |
| 14966 | 14781 | ** in Greenwich on November 24, 4714 B.C. according to the Gregorian |
| 14967 | 14782 | ** calendar system. |
| 14968 | 14783 | ** |
| 14969 | 14784 | ** 1970-01-01 00:00:00 is JD 2440587.5 |
| | @@ -14974,11 +14789,11 @@ |
| 14974 | 14789 | ** be represented, even though julian day numbers allow a much wider |
| 14975 | 14790 | ** range of dates. |
| 14976 | 14791 | ** |
| 14977 | 14792 | ** The Gregorian calendar system is used for all dates and times, |
| 14978 | 14793 | ** even those that predate the Gregorian calendar. Historians usually |
| 14979 | | -** use the julian calendar for dates prior to 1582-10-15 and for some |
| 14794 | +** use the Julian calendar for dates prior to 1582-10-15 and for some |
| 14980 | 14795 | ** dates afterwards, depending on locale. Beware of this difference. |
| 14981 | 14796 | ** |
| 14982 | 14797 | ** The conversion algorithms are implemented based on descriptions |
| 14983 | 14798 | ** in the following text: |
| 14984 | 14799 | ** |
| | @@ -15246,11 +15061,11 @@ |
| 15246 | 15061 | return 1; |
| 15247 | 15062 | } |
| 15248 | 15063 | } |
| 15249 | 15064 | |
| 15250 | 15065 | /* |
| 15251 | | -** Attempt to parse the given string into a julian day number. Return |
| 15066 | +** Attempt to parse the given string into a Julian Day Number. Return |
| 15252 | 15067 | ** the number of errors. |
| 15253 | 15068 | ** |
| 15254 | 15069 | ** The following are acceptable forms for the input string: |
| 15255 | 15070 | ** |
| 15256 | 15071 | ** YYYY-MM-DD HH:MM:SS.FFF +/-HH:MM |
| | @@ -15817,11 +15632,11 @@ |
| 15817 | 15632 | ** |
| 15818 | 15633 | ** %d day of month |
| 15819 | 15634 | ** %f ** fractional seconds SS.SSS |
| 15820 | 15635 | ** %H hour 00-24 |
| 15821 | 15636 | ** %j day of year 000-366 |
| 15822 | | -** %J ** julian day number |
| 15637 | +** %J ** Julian day number |
| 15823 | 15638 | ** %m month 01-12 |
| 15824 | 15639 | ** %M minute 00-59 |
| 15825 | 15640 | ** %s seconds since 1970-01-01 |
| 15826 | 15641 | ** %S seconds 00-59 |
| 15827 | 15642 | ** %w day of week 0-6 sunday==0 |
| | @@ -16442,14 +16257,10 @@ |
| 16442 | 16257 | MUTEX_LOGIC(sqlite3_mutex *mutex;) |
| 16443 | 16258 | #ifndef SQLITE_OMIT_AUTOINIT |
| 16444 | 16259 | int rc = sqlite3_initialize(); |
| 16445 | 16260 | if( rc ) return rc; |
| 16446 | 16261 | #endif |
| 16447 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 16448 | | - if( pVfs==0 ) return SQLITE_MISUSE_BKPT; |
| 16449 | | -#endif |
| 16450 | | - |
| 16451 | 16262 | MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); ) |
| 16452 | 16263 | sqlite3_mutex_enter(mutex); |
| 16453 | 16264 | vfsUnlink(pVfs); |
| 16454 | 16265 | if( makeDflt || vfsList==0 ){ |
| 16455 | 16266 | pVfs->pNext = vfsList; |
| | @@ -18803,11 +18614,10 @@ |
| 18803 | 18614 | ** Retrieve a pointer to a static mutex or allocate a new dynamic one. |
| 18804 | 18615 | */ |
| 18805 | 18616 | SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int id){ |
| 18806 | 18617 | #ifndef SQLITE_OMIT_AUTOINIT |
| 18807 | 18618 | if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0; |
| 18808 | | - if( id>SQLITE_MUTEX_RECURSIVE && sqlite3MutexInit() ) return 0; |
| 18809 | 18619 | #endif |
| 18810 | 18620 | return sqlite3GlobalConfig.mutex.xMutexAlloc(id); |
| 18811 | 18621 | } |
| 18812 | 18622 | |
| 18813 | 18623 | SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int id){ |
| | @@ -19260,16 +19070,12 @@ |
| 19260 | 19070 | pthread_mutex_init(&p->mutex, 0); |
| 19261 | 19071 | } |
| 19262 | 19072 | break; |
| 19263 | 19073 | } |
| 19264 | 19074 | default: { |
| 19265 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 19266 | | - if( iType-2<0 || iType-2>=ArraySize(staticMutexes) ){ |
| 19267 | | - (void)SQLITE_MISUSE_BKPT; |
| 19268 | | - return 0; |
| 19269 | | - } |
| 19270 | | -#endif |
| 19075 | + assert( iType-2 >= 0 ); |
| 19076 | + assert( iType-2 < ArraySize(staticMutexes) ); |
| 19271 | 19077 | p = &staticMutexes[iType-2]; |
| 19272 | 19078 | #if SQLITE_MUTEX_NREF |
| 19273 | 19079 | p->id = iType; |
| 19274 | 19080 | #endif |
| 19275 | 19081 | break; |
| | @@ -20487,16 +20293,15 @@ |
| 20487 | 20293 | } |
| 20488 | 20294 | assert( sqlite3_mutex_notheld(mem0.mutex) ); |
| 20489 | 20295 | |
| 20490 | 20296 | |
| 20491 | 20297 | #if SQLITE_THREADSAFE==0 && !defined(NDEBUG) |
| 20492 | | - /* EVIDENCE-OF: R-12970-05880 SQLite will not use more than one scratch |
| 20493 | | - ** buffers per thread. |
| 20494 | | - ** |
| 20495 | | - ** This can only be checked in single-threaded mode. |
| 20496 | | - */ |
| 20497 | | - assert( scratchAllocOut==0 ); |
| 20298 | + /* Verify that no more than two scratch allocations per thread |
| 20299 | + ** are outstanding at one time. (This is only checked in the |
| 20300 | + ** single-threaded case since checking in the multi-threaded case |
| 20301 | + ** would be much more complicated.) */ |
| 20302 | + assert( scratchAllocOut<=1 ); |
| 20498 | 20303 | if( p ) scratchAllocOut++; |
| 20499 | 20304 | #endif |
| 20500 | 20305 | |
| 20501 | 20306 | return p; |
| 20502 | 20307 | } |
| | @@ -21151,17 +20956,10 @@ |
| 21151 | 20956 | etByte flag_rtz; /* True if trailing zeros should be removed */ |
| 21152 | 20957 | #endif |
| 21153 | 20958 | PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */ |
| 21154 | 20959 | char buf[etBUFSIZE]; /* Conversion buffer */ |
| 21155 | 20960 | |
| 21156 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 21157 | | - if( ap==0 ){ |
| 21158 | | - (void)SQLITE_MISUSE_BKPT; |
| 21159 | | - sqlite3StrAccumReset(pAccum); |
| 21160 | | - return; |
| 21161 | | - } |
| 21162 | | -#endif |
| 21163 | 20961 | bufpt = 0; |
| 21164 | 20962 | if( bFlags ){ |
| 21165 | 20963 | if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){ |
| 21166 | 20964 | pArgList = va_arg(ap, PrintfArguments*); |
| 21167 | 20965 | } |
| | @@ -21698,15 +21496,10 @@ |
| 21698 | 21496 | return N; |
| 21699 | 21497 | }else{ |
| 21700 | 21498 | char *zOld = (p->zText==p->zBase ? 0 : p->zText); |
| 21701 | 21499 | i64 szNew = p->nChar; |
| 21702 | 21500 | szNew += N + 1; |
| 21703 | | - if( szNew+p->nChar<=p->mxAlloc ){ |
| 21704 | | - /* Force exponential buffer size growth as long as it does not overflow, |
| 21705 | | - ** to avoid having to call this routine too often */ |
| 21706 | | - szNew += p->nChar; |
| 21707 | | - } |
| 21708 | 21501 | if( szNew > p->mxAlloc ){ |
| 21709 | 21502 | sqlite3StrAccumReset(p); |
| 21710 | 21503 | setStrAccumError(p, STRACCUM_TOOBIG); |
| 21711 | 21504 | return 0; |
| 21712 | 21505 | }else{ |
| | @@ -21719,11 +21512,10 @@ |
| 21719 | 21512 | } |
| 21720 | 21513 | if( zNew ){ |
| 21721 | 21514 | assert( p->zText!=0 || p->nChar==0 ); |
| 21722 | 21515 | if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); |
| 21723 | 21516 | p->zText = zNew; |
| 21724 | | - p->nAlloc = sqlite3DbMallocSize(p->db, zNew); |
| 21725 | 21517 | }else{ |
| 21726 | 21518 | sqlite3StrAccumReset(p); |
| 21727 | 21519 | setStrAccumError(p, STRACCUM_NOMEM); |
| 21728 | 21520 | return 0; |
| 21729 | 21521 | } |
| | @@ -21889,17 +21681,10 @@ |
| 21889 | 21681 | */ |
| 21890 | 21682 | SQLITE_API char *sqlite3_vmprintf(const char *zFormat, va_list ap){ |
| 21891 | 21683 | char *z; |
| 21892 | 21684 | char zBase[SQLITE_PRINT_BUF_SIZE]; |
| 21893 | 21685 | StrAccum acc; |
| 21894 | | - |
| 21895 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 21896 | | - if( zFormat==0 ){ |
| 21897 | | - (void)SQLITE_MISUSE_BKPT; |
| 21898 | | - return 0; |
| 21899 | | - } |
| 21900 | | -#endif |
| 21901 | 21686 | #ifndef SQLITE_OMIT_AUTOINIT |
| 21902 | 21687 | if( sqlite3_initialize() ) return 0; |
| 21903 | 21688 | #endif |
| 21904 | 21689 | sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH); |
| 21905 | 21690 | acc.useMalloc = 2; |
| | @@ -21938,17 +21723,10 @@ |
| 21938 | 21723 | ** sqlite3_vsnprintf() is the varargs version. |
| 21939 | 21724 | */ |
| 21940 | 21725 | SQLITE_API char *sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){ |
| 21941 | 21726 | StrAccum acc; |
| 21942 | 21727 | if( n<=0 ) return zBuf; |
| 21943 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 21944 | | - if( zBuf==0 || zFormat==0 ) { |
| 21945 | | - (void)SQLITE_MISUSE_BKPT; |
| 21946 | | - if( zBuf && n>0 ) zBuf[0] = 0; |
| 21947 | | - return zBuf; |
| 21948 | | - } |
| 21949 | | -#endif |
| 21950 | 21728 | sqlite3StrAccumInit(&acc, zBuf, n, 0); |
| 21951 | 21729 | acc.useMalloc = 0; |
| 21952 | 21730 | sqlite3VXPrintf(&acc, 0, zFormat, ap); |
| 21953 | 21731 | return sqlite3StrAccumFinish(&acc); |
| 21954 | 21732 | } |
| | @@ -22136,23 +21914,15 @@ |
| 22136 | 21914 | #else |
| 22137 | 21915 | # define wsdPrng sqlite3Prng |
| 22138 | 21916 | #endif |
| 22139 | 21917 | |
| 22140 | 21918 | #if SQLITE_THREADSAFE |
| 22141 | | - sqlite3_mutex *mutex; |
| 22142 | | -#endif |
| 22143 | | - |
| 22144 | | -#ifndef SQLITE_OMIT_AUTOINIT |
| 22145 | | - if( sqlite3_initialize() ) return; |
| 22146 | | -#endif |
| 22147 | | - |
| 22148 | | -#if SQLITE_THREADSAFE |
| 22149 | | - mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG); |
| 22150 | | -#endif |
| 22151 | | - |
| 21919 | + sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG); |
| 22152 | 21920 | sqlite3_mutex_enter(mutex); |
| 22153 | | - if( N<=0 || pBuf==0 ){ |
| 21921 | +#endif |
| 21922 | + |
| 21923 | + if( N<=0 ){ |
| 22154 | 21924 | wsdPrng.isInit = 0; |
| 22155 | 21925 | sqlite3_mutex_leave(mutex); |
| 22156 | 21926 | return; |
| 22157 | 21927 | } |
| 22158 | 21928 | |
| | @@ -23270,27 +23040,17 @@ |
| 23270 | 23040 | ** case-independent fashion, using the same definition of "case |
| 23271 | 23041 | ** independence" that SQLite uses internally when comparing identifiers. |
| 23272 | 23042 | */ |
| 23273 | 23043 | SQLITE_API int sqlite3_stricmp(const char *zLeft, const char *zRight){ |
| 23274 | 23044 | register unsigned char *a, *b; |
| 23275 | | - if( zLeft==0 ){ |
| 23276 | | - return zRight ? -1 : 0; |
| 23277 | | - }else if( zRight==0 ){ |
| 23278 | | - return 1; |
| 23279 | | - } |
| 23280 | 23045 | a = (unsigned char *)zLeft; |
| 23281 | 23046 | b = (unsigned char *)zRight; |
| 23282 | 23047 | while( *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; } |
| 23283 | 23048 | return UpperToLower[*a] - UpperToLower[*b]; |
| 23284 | 23049 | } |
| 23285 | 23050 | SQLITE_API int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){ |
| 23286 | 23051 | register unsigned char *a, *b; |
| 23287 | | - if( zLeft==0 ){ |
| 23288 | | - return zRight ? -1 : 0; |
| 23289 | | - }else if( zRight==0 ){ |
| 23290 | | - return 1; |
| 23291 | | - } |
| 23292 | 23052 | a = (unsigned char *)zLeft; |
| 23293 | 23053 | b = (unsigned char *)zRight; |
| 23294 | 23054 | while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; } |
| 23295 | 23055 | return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b]; |
| 23296 | 23056 | } |
| | @@ -32819,15 +32579,10 @@ |
| 32819 | 32579 | #if !SQLITE_OS_WINNT && !defined(SQLITE_OMIT_WAL) |
| 32820 | 32580 | # error "WAL mode requires support from the Windows NT kernel, compile\ |
| 32821 | 32581 | with SQLITE_OMIT_WAL." |
| 32822 | 32582 | #endif |
| 32823 | 32583 | |
| 32824 | | -#if !SQLITE_OS_WINNT && SQLITE_MAX_MMAP_SIZE>0 |
| 32825 | | -# error "Memory mapped files require support from the Windows NT kernel,\ |
| 32826 | | - compile with SQLITE_MAX_MMAP_SIZE=0." |
| 32827 | | -#endif |
| 32828 | | - |
| 32829 | 32584 | /* |
| 32830 | 32585 | ** Are most of the Win32 ANSI APIs available (i.e. with certain exceptions |
| 32831 | 32586 | ** based on the sub-platform)? |
| 32832 | 32587 | */ |
| 32833 | 32588 | #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(SQLITE_WIN32_NO_ANSI) |
| | @@ -32953,15 +32708,14 @@ |
| 32953 | 32708 | # define winGetDirSep() '\\' |
| 32954 | 32709 | #endif |
| 32955 | 32710 | |
| 32956 | 32711 | /* |
| 32957 | 32712 | ** Do we need to manually define the Win32 file mapping APIs for use with WAL |
| 32958 | | -** mode or memory mapped files (e.g. these APIs are available in the Windows |
| 32959 | | -** CE SDK; however, they are not present in the header file)? |
| 32713 | +** mode (e.g. these APIs are available in the Windows CE SDK; however, they |
| 32714 | +** are not present in the header file)? |
| 32960 | 32715 | */ |
| 32961 | | -#if SQLITE_WIN32_FILEMAPPING_API && \ |
| 32962 | | - (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) |
| 32716 | +#if SQLITE_WIN32_FILEMAPPING_API && !defined(SQLITE_OMIT_WAL) |
| 32963 | 32717 | /* |
| 32964 | 32718 | ** Two of the file mapping APIs are different under WinRT. Figure out which |
| 32965 | 32719 | ** set we need. |
| 32966 | 32720 | */ |
| 32967 | 32721 | #if SQLITE_OS_WINRT |
| | @@ -32985,11 +32739,11 @@ |
| 32985 | 32739 | |
| 32986 | 32740 | /* |
| 32987 | 32741 | ** This file mapping API is common to both Win32 and WinRT. |
| 32988 | 32742 | */ |
| 32989 | 32743 | WINBASEAPI BOOL WINAPI UnmapViewOfFile(LPCVOID); |
| 32990 | | -#endif /* SQLITE_WIN32_FILEMAPPING_API */ |
| 32744 | +#endif /* SQLITE_WIN32_FILEMAPPING_API && !defined(SQLITE_OMIT_WAL) */ |
| 32991 | 32745 | |
| 32992 | 32746 | /* |
| 32993 | 32747 | ** Some Microsoft compilers lack this definition. |
| 32994 | 32748 | */ |
| 32995 | 32749 | #ifndef INVALID_FILE_ATTRIBUTES |
| | @@ -33278,21 +33032,21 @@ |
| 33278 | 33032 | |
| 33279 | 33033 | #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \ |
| 33280 | 33034 | LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent) |
| 33281 | 33035 | |
| 33282 | 33036 | #if (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_ANSI) && \ |
| 33283 | | - (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)) |
| 33037 | + !defined(SQLITE_OMIT_WAL)) |
| 33284 | 33038 | { "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 }, |
| 33285 | 33039 | #else |
| 33286 | 33040 | { "CreateFileMappingA", (SYSCALL)0, 0 }, |
| 33287 | 33041 | #endif |
| 33288 | 33042 | |
| 33289 | 33043 | #define osCreateFileMappingA ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \ |
| 33290 | 33044 | DWORD,DWORD,DWORD,LPCSTR))aSyscall[6].pCurrent) |
| 33291 | 33045 | |
| 33292 | 33046 | #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \ |
| 33293 | | - (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)) |
| 33047 | + !defined(SQLITE_OMIT_WAL)) |
| 33294 | 33048 | { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 }, |
| 33295 | 33049 | #else |
| 33296 | 33050 | { "CreateFileMappingW", (SYSCALL)0, 0 }, |
| 33297 | 33051 | #endif |
| 33298 | 33052 | |
| | @@ -33628,12 +33382,11 @@ |
| 33628 | 33382 | #ifndef osLockFileEx |
| 33629 | 33383 | #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \ |
| 33630 | 33384 | LPOVERLAPPED))aSyscall[48].pCurrent) |
| 33631 | 33385 | #endif |
| 33632 | 33386 | |
| 33633 | | -#if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && \ |
| 33634 | | - (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)) |
| 33387 | +#if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)) |
| 33635 | 33388 | { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 }, |
| 33636 | 33389 | #else |
| 33637 | 33390 | { "MapViewOfFile", (SYSCALL)0, 0 }, |
| 33638 | 33391 | #endif |
| 33639 | 33392 | |
| | @@ -33699,11 +33452,11 @@ |
| 33699 | 33452 | #endif |
| 33700 | 33453 | |
| 33701 | 33454 | #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ |
| 33702 | 33455 | LPOVERLAPPED))aSyscall[58].pCurrent) |
| 33703 | 33456 | |
| 33704 | | -#if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 |
| 33457 | +#if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL) |
| 33705 | 33458 | { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 }, |
| 33706 | 33459 | #else |
| 33707 | 33460 | { "UnmapViewOfFile", (SYSCALL)0, 0 }, |
| 33708 | 33461 | #endif |
| 33709 | 33462 | |
| | @@ -33762,11 +33515,11 @@ |
| 33762 | 33515 | #endif |
| 33763 | 33516 | |
| 33764 | 33517 | #define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \ |
| 33765 | 33518 | FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[66].pCurrent) |
| 33766 | 33519 | |
| 33767 | | -#if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) |
| 33520 | +#if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL) |
| 33768 | 33521 | { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 }, |
| 33769 | 33522 | #else |
| 33770 | 33523 | { "MapViewOfFileFromApp", (SYSCALL)0, 0 }, |
| 33771 | 33524 | #endif |
| 33772 | 33525 | |
| | @@ -33826,11 +33579,11 @@ |
| 33826 | 33579 | |
| 33827 | 33580 | { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 }, |
| 33828 | 33581 | |
| 33829 | 33582 | #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[74].pCurrent) |
| 33830 | 33583 | |
| 33831 | | -#if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) |
| 33584 | +#if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL) |
| 33832 | 33585 | { "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 }, |
| 33833 | 33586 | #else |
| 33834 | 33587 | { "CreateFileMappingFromApp", (SYSCALL)0, 0 }, |
| 33835 | 33588 | #endif |
| 33836 | 33589 | |
| | @@ -39402,17 +39155,10 @@ |
| 39402 | 39155 | */ |
| 39403 | 39156 | SQLITE_PRIVATE void sqlite3PcacheShrink(PCache *pCache){ |
| 39404 | 39157 | assert( pCache->pCache!=0 ); |
| 39405 | 39158 | sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache); |
| 39406 | 39159 | } |
| 39407 | | - |
| 39408 | | -/* |
| 39409 | | -** Return the size of the header added by this middleware layer |
| 39410 | | -** in the page-cache hierarchy. |
| 39411 | | -*/ |
| 39412 | | -SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return sizeof(PgHdr); } |
| 39413 | | - |
| 39414 | 39160 | |
| 39415 | 39161 | #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG) |
| 39416 | 39162 | /* |
| 39417 | 39163 | ** For all dirty pages currently in the cache, invoke the specified |
| 39418 | 39164 | ** callback. This is only used if the SQLITE_CHECK_PAGES macro is |
| | @@ -40408,15 +40154,10 @@ |
| 40408 | 40154 | pcache1Shrink /* xShrink */ |
| 40409 | 40155 | }; |
| 40410 | 40156 | sqlite3_config(SQLITE_CONFIG_PCACHE2, &defaultMethods); |
| 40411 | 40157 | } |
| 40412 | 40158 | |
| 40413 | | -/* |
| 40414 | | -** Return the size of the header on each page of this PCACHE implementation. |
| 40415 | | -*/ |
| 40416 | | -SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void){ return sizeof(PgHdr1); } |
| 40417 | | - |
| 40418 | 40159 | #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 40419 | 40160 | /* |
| 40420 | 40161 | ** This function is called to free superfluous dynamically allocated memory |
| 40421 | 40162 | ** held by the pager system. Memory in use by any SQLite pager allocated |
| 40422 | 40163 | ** by the current thread may be sqlite3_free()ed. |
| | @@ -47970,22 +47711,10 @@ |
| 47970 | 47711 | |
| 47971 | 47712 | return SQLITE_OK; |
| 47972 | 47713 | } |
| 47973 | 47714 | #endif |
| 47974 | 47715 | |
| 47975 | | -/* |
| 47976 | | -** The page handle passed as the first argument refers to a dirty page |
| 47977 | | -** with a page number other than iNew. This function changes the page's |
| 47978 | | -** page number to iNew and sets the value of the PgHdr.flags field to |
| 47979 | | -** the value passed as the third parameter. |
| 47980 | | -*/ |
| 47981 | | -SQLITE_PRIVATE void sqlite3PagerRekey(DbPage *pPg, Pgno iNew, u16 flags){ |
| 47982 | | - assert( pPg->pgno!=iNew ); |
| 47983 | | - pPg->flags = flags; |
| 47984 | | - sqlite3PcacheMove(pPg, iNew); |
| 47985 | | -} |
| 47986 | | - |
| 47987 | 47716 | /* |
| 47988 | 47717 | ** Return a pointer to the data for the specified page. |
| 47989 | 47718 | */ |
| 47990 | 47719 | SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *pPg){ |
| 47991 | 47720 | assert( pPg->nRef>0 || pPg->pPager->memDb ); |
| | @@ -48379,11 +48108,10 @@ |
| 48379 | 48108 | SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager){ |
| 48380 | 48109 | assert( pPager->eState>=PAGER_READER ); |
| 48381 | 48110 | return sqlite3WalFramesize(pPager->pWal); |
| 48382 | 48111 | } |
| 48383 | 48112 | #endif |
| 48384 | | - |
| 48385 | 48113 | |
| 48386 | 48114 | #endif /* SQLITE_OMIT_DISKIO */ |
| 48387 | 48115 | |
| 48388 | 48116 | /************** End of pager.c ***********************************************/ |
| 48389 | 48117 | /************** Begin file wal.c *********************************************/ |
| | @@ -49890,11 +49618,11 @@ |
| 49890 | 49618 | |
| 49891 | 49619 | /* |
| 49892 | 49620 | ** Free an iterator allocated by walIteratorInit(). |
| 49893 | 49621 | */ |
| 49894 | 49622 | static void walIteratorFree(WalIterator *p){ |
| 49895 | | - sqlite3_free(p); |
| 49623 | + sqlite3ScratchFree(p); |
| 49896 | 49624 | } |
| 49897 | 49625 | |
| 49898 | 49626 | /* |
| 49899 | 49627 | ** Construct a WalInterator object that can be used to loop over all |
| 49900 | 49628 | ** pages in the WAL in ascending order. The caller must hold the checkpoint |
| | @@ -49925,21 +49653,21 @@ |
| 49925 | 49653 | /* Allocate space for the WalIterator object. */ |
| 49926 | 49654 | nSegment = walFramePage(iLast) + 1; |
| 49927 | 49655 | nByte = sizeof(WalIterator) |
| 49928 | 49656 | + (nSegment-1)*sizeof(struct WalSegment) |
| 49929 | 49657 | + iLast*sizeof(ht_slot); |
| 49930 | | - p = (WalIterator *)sqlite3_malloc(nByte); |
| 49658 | + p = (WalIterator *)sqlite3ScratchMalloc(nByte); |
| 49931 | 49659 | if( !p ){ |
| 49932 | 49660 | return SQLITE_NOMEM; |
| 49933 | 49661 | } |
| 49934 | 49662 | memset(p, 0, nByte); |
| 49935 | 49663 | p->nSegment = nSegment; |
| 49936 | 49664 | |
| 49937 | 49665 | /* Allocate temporary space used by the merge-sort routine. This block |
| 49938 | 49666 | ** of memory will be freed before this function returns. |
| 49939 | 49667 | */ |
| 49940 | | - aTmp = (ht_slot *)sqlite3_malloc( |
| 49668 | + aTmp = (ht_slot *)sqlite3ScratchMalloc( |
| 49941 | 49669 | sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast) |
| 49942 | 49670 | ); |
| 49943 | 49671 | if( !aTmp ){ |
| 49944 | 49672 | rc = SQLITE_NOMEM; |
| 49945 | 49673 | } |
| | @@ -49972,11 +49700,11 @@ |
| 49972 | 49700 | p->aSegment[i].nEntry = nEntry; |
| 49973 | 49701 | p->aSegment[i].aIndex = aIndex; |
| 49974 | 49702 | p->aSegment[i].aPgno = (u32 *)aPgno; |
| 49975 | 49703 | } |
| 49976 | 49704 | } |
| 49977 | | - sqlite3_free(aTmp); |
| 49705 | + sqlite3ScratchFree(aTmp); |
| 49978 | 49706 | |
| 49979 | 49707 | if( rc!=SQLITE_OK ){ |
| 49980 | 49708 | walIteratorFree(p); |
| 49981 | 49709 | } |
| 49982 | 49710 | *pp = p; |
| | @@ -50892,11 +50620,11 @@ |
| 50892 | 50620 | ** was in before the client began writing to the database. |
| 50893 | 50621 | */ |
| 50894 | 50622 | memcpy(&pWal->hdr, (void *)walIndexHdr(pWal), sizeof(WalIndexHdr)); |
| 50895 | 50623 | |
| 50896 | 50624 | for(iFrame=pWal->hdr.mxFrame+1; |
| 50897 | | - rc==SQLITE_OK && iFrame<=iMax; |
| 50625 | + ALWAYS(rc==SQLITE_OK) && iFrame<=iMax; |
| 50898 | 50626 | iFrame++ |
| 50899 | 50627 | ){ |
| 50900 | 50628 | /* This call cannot fail. Unless the page for which the page number |
| 50901 | 50629 | ** is passed as the second argument is (a) in the cache and |
| 50902 | 50630 | ** (b) has an outstanding reference, then xUndo is either a no-op |
| | @@ -51989,10 +51717,15 @@ |
| 51989 | 51717 | ** but cursors cannot be shared. Each cursor is associated with a |
| 51990 | 51718 | ** particular database connection identified BtCursor.pBtree.db. |
| 51991 | 51719 | ** |
| 51992 | 51720 | ** Fields in this structure are accessed under the BtShared.mutex |
| 51993 | 51721 | ** found at self->pBt->mutex. |
| 51722 | +** |
| 51723 | +** skipNext meaning: |
| 51724 | +** eState==SKIPNEXT && skipNext>0: Next sqlite3BtreeNext() is no-op. |
| 51725 | +** eState==SKIPNEXT && skipNext<0: Next sqlite3BtreePrevious() is no-op. |
| 51726 | +** eState==FAULT: Cursor fault with skipNext as error code. |
| 51994 | 51727 | */ |
| 51995 | 51728 | struct BtCursor { |
| 51996 | 51729 | Btree *pBtree; /* The Btree to which this cursor belongs */ |
| 51997 | 51730 | BtShared *pBt; /* The BtShared this cursor points to */ |
| 51998 | 51731 | BtCursor *pNext, *pPrev; /* Forms a linked list of all cursors */ |
| | @@ -52001,11 +51734,12 @@ |
| 52001 | 51734 | CellInfo info; /* A parse of the cell we are pointing at */ |
| 52002 | 51735 | i64 nKey; /* Size of pKey, or last integer key */ |
| 52003 | 51736 | void *pKey; /* Saved key that was cursor last known position */ |
| 52004 | 51737 | Pgno pgnoRoot; /* The root page of this tree */ |
| 52005 | 51738 | int nOvflAlloc; /* Allocated size of aOverflow[] array */ |
| 52006 | | - int skipNext; /* Prev() is noop if negative. Next() is noop if positive */ |
| 51739 | + int skipNext; /* Prev() is noop if negative. Next() is noop if positive. |
| 51740 | + ** Error code if eState==CURSOR_FAULT */ |
| 52007 | 51741 | u8 curFlags; /* zero or more BTCF_* flags defined below */ |
| 52008 | 51742 | u8 eState; /* One of the CURSOR_XXX constants (see below) */ |
| 52009 | 51743 | u8 hints; /* As configured by CursorSetHints() */ |
| 52010 | 51744 | i16 iPage; /* Index of current page in apPage */ |
| 52011 | 51745 | u16 aiIdx[BTCURSOR_MAX_DEPTH]; /* Current index in apPage[i] */ |
| | @@ -52047,11 +51781,11 @@ |
| 52047 | 51781 | ** CURSOR_FAULT: |
| 52048 | 51782 | ** An unrecoverable error (an I/O error or a malloc failure) has occurred |
| 52049 | 51783 | ** on a different connection that shares the BtShared cache with this |
| 52050 | 51784 | ** cursor. The error has left the cache in an inconsistent state. |
| 52051 | 51785 | ** Do nothing else with this cursor. Any attempt to use the cursor |
| 52052 | | -** should return the error code stored in BtCursor.skip |
| 51786 | +** should return the error code stored in BtCursor.skipNext |
| 52053 | 51787 | */ |
| 52054 | 51788 | #define CURSOR_INVALID 0 |
| 52055 | 51789 | #define CURSOR_VALID 1 |
| 52056 | 51790 | #define CURSOR_SKIPNEXT 2 |
| 52057 | 51791 | #define CURSOR_REQUIRESEEK 3 |
| | @@ -53609,27 +53343,28 @@ |
| 53609 | 53343 | int cellOffset; /* Offset to the cell pointer array */ |
| 53610 | 53344 | int cbrk; /* Offset to the cell content area */ |
| 53611 | 53345 | int nCell; /* Number of cells on the page */ |
| 53612 | 53346 | unsigned char *data; /* The page data */ |
| 53613 | 53347 | unsigned char *temp; /* Temp area for cell content */ |
| 53614 | | - unsigned char *src; /* Source of content */ |
| 53615 | 53348 | int iCellFirst; /* First allowable cell index */ |
| 53616 | 53349 | int iCellLast; /* Last possible cell index */ |
| 53617 | 53350 | |
| 53618 | 53351 | |
| 53619 | 53352 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 53620 | 53353 | assert( pPage->pBt!=0 ); |
| 53621 | 53354 | assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE ); |
| 53622 | 53355 | assert( pPage->nOverflow==0 ); |
| 53623 | 53356 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 53624 | | - temp = 0; |
| 53625 | | - src = data = pPage->aData; |
| 53357 | + temp = sqlite3PagerTempSpace(pPage->pBt->pPager); |
| 53358 | + data = pPage->aData; |
| 53626 | 53359 | hdr = pPage->hdrOffset; |
| 53627 | 53360 | cellOffset = pPage->cellOffset; |
| 53628 | 53361 | nCell = pPage->nCell; |
| 53629 | 53362 | assert( nCell==get2byte(&data[hdr+3]) ); |
| 53630 | 53363 | usableSize = pPage->pBt->usableSize; |
| 53364 | + cbrk = get2byte(&data[hdr+5]); |
| 53365 | + memcpy(&temp[cbrk], &data[cbrk], usableSize - cbrk); |
| 53631 | 53366 | cbrk = usableSize; |
| 53632 | 53367 | iCellFirst = cellOffset + 2*nCell; |
| 53633 | 53368 | iCellLast = usableSize - 4; |
| 53634 | 53369 | for(i=0; i<nCell; i++){ |
| 53635 | 53370 | u8 *pAddr; /* The i-th cell pointer */ |
| | @@ -53644,11 +53379,11 @@ |
| 53644 | 53379 | if( pc<iCellFirst || pc>iCellLast ){ |
| 53645 | 53380 | return SQLITE_CORRUPT_BKPT; |
| 53646 | 53381 | } |
| 53647 | 53382 | #endif |
| 53648 | 53383 | assert( pc>=iCellFirst && pc<=iCellLast ); |
| 53649 | | - size = cellSizePtr(pPage, &src[pc]); |
| 53384 | + size = cellSizePtr(pPage, &temp[pc]); |
| 53650 | 53385 | cbrk -= size; |
| 53651 | 53386 | #if defined(SQLITE_ENABLE_OVERSIZE_CELL_CHECK) |
| 53652 | 53387 | if( cbrk<iCellFirst ){ |
| 53653 | 53388 | return SQLITE_CORRUPT_BKPT; |
| 53654 | 53389 | } |
| | @@ -53658,20 +53393,12 @@ |
| 53658 | 53393 | } |
| 53659 | 53394 | #endif |
| 53660 | 53395 | assert( cbrk+size<=usableSize && cbrk>=iCellFirst ); |
| 53661 | 53396 | testcase( cbrk+size==usableSize ); |
| 53662 | 53397 | testcase( pc+size==usableSize ); |
| 53398 | + memcpy(&data[cbrk], &temp[pc], size); |
| 53663 | 53399 | put2byte(pAddr, cbrk); |
| 53664 | | - if( temp==0 ){ |
| 53665 | | - int x; |
| 53666 | | - if( cbrk==pc ) continue; |
| 53667 | | - temp = sqlite3PagerTempSpace(pPage->pBt->pPager); |
| 53668 | | - x = get2byte(&data[hdr+5]); |
| 53669 | | - memcpy(&temp[x], &data[x], (cbrk+size) - x); |
| 53670 | | - src = temp; |
| 53671 | | - } |
| 53672 | | - memcpy(&data[cbrk], &src[pc], size); |
| 53673 | 53400 | } |
| 53674 | 53401 | assert( cbrk>=iCellFirst ); |
| 53675 | 53402 | put2byte(&data[hdr+5], cbrk); |
| 53676 | 53403 | data[hdr+1] = 0; |
| 53677 | 53404 | data[hdr+2] = 0; |
| | @@ -53682,66 +53409,10 @@ |
| 53682 | 53409 | return SQLITE_CORRUPT_BKPT; |
| 53683 | 53410 | } |
| 53684 | 53411 | return SQLITE_OK; |
| 53685 | 53412 | } |
| 53686 | 53413 | |
| 53687 | | -/* |
| 53688 | | -** Search the free-list on page pPg for space to store a cell nByte bytes in |
| 53689 | | -** size. If one can be found, return a pointer to the space and remove it |
| 53690 | | -** from the free-list. |
| 53691 | | -** |
| 53692 | | -** If no suitable space can be found on the free-list, return NULL. |
| 53693 | | -** |
| 53694 | | -** This function may detect corruption within pPg. If corruption is |
| 53695 | | -** detected then *pRc is set to SQLITE_CORRUPT and NULL is returned. |
| 53696 | | -** |
| 53697 | | -** If a slot of at least nByte bytes is found but cannot be used because |
| 53698 | | -** there are already at least 60 fragmented bytes on the page, return NULL. |
| 53699 | | -** In this case, if pbDefrag parameter is not NULL, set *pbDefrag to true. |
| 53700 | | -*/ |
| 53701 | | -static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc, int *pbDefrag){ |
| 53702 | | - const int hdr = pPg->hdrOffset; |
| 53703 | | - u8 * const aData = pPg->aData; |
| 53704 | | - int iAddr; |
| 53705 | | - int pc; |
| 53706 | | - int usableSize = pPg->pBt->usableSize; |
| 53707 | | - |
| 53708 | | - for(iAddr=hdr+1; (pc = get2byte(&aData[iAddr]))>0; iAddr=pc){ |
| 53709 | | - int size; /* Size of the free slot */ |
| 53710 | | - if( pc>usableSize-4 || pc<iAddr+4 ){ |
| 53711 | | - *pRc = SQLITE_CORRUPT_BKPT; |
| 53712 | | - return 0; |
| 53713 | | - } |
| 53714 | | - size = get2byte(&aData[pc+2]); |
| 53715 | | - if( size>=nByte ){ |
| 53716 | | - int x = size - nByte; |
| 53717 | | - testcase( x==4 ); |
| 53718 | | - testcase( x==3 ); |
| 53719 | | - if( x<4 ){ |
| 53720 | | - if( aData[hdr+7]>=60 ){ |
| 53721 | | - if( pbDefrag ) *pbDefrag = 1; |
| 53722 | | - return 0; |
| 53723 | | - } |
| 53724 | | - /* Remove the slot from the free-list. Update the number of |
| 53725 | | - ** fragmented bytes within the page. */ |
| 53726 | | - memcpy(&aData[iAddr], &aData[pc], 2); |
| 53727 | | - aData[hdr+7] += (u8)x; |
| 53728 | | - }else if( size+pc > usableSize ){ |
| 53729 | | - *pRc = SQLITE_CORRUPT_BKPT; |
| 53730 | | - return 0; |
| 53731 | | - }else{ |
| 53732 | | - /* The slot remains on the free-list. Reduce its size to account |
| 53733 | | - ** for the portion used by the new allocation. */ |
| 53734 | | - put2byte(&aData[pc+2], x); |
| 53735 | | - } |
| 53736 | | - return &aData[pc + x]; |
| 53737 | | - } |
| 53738 | | - } |
| 53739 | | - |
| 53740 | | - return 0; |
| 53741 | | -} |
| 53742 | | - |
| 53743 | 53414 | /* |
| 53744 | 53415 | ** Allocate nByte bytes of space from within the B-Tree page passed |
| 53745 | 53416 | ** as the first argument. Write into *pIdx the index into pPage->aData[] |
| 53746 | 53417 | ** of the first byte of allocated space. Return either SQLITE_OK or |
| 53747 | 53418 | ** an error code (usually SQLITE_CORRUPT). |
| | @@ -53755,20 +53426,22 @@ |
| 53755 | 53426 | */ |
| 53756 | 53427 | static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ |
| 53757 | 53428 | const int hdr = pPage->hdrOffset; /* Local cache of pPage->hdrOffset */ |
| 53758 | 53429 | u8 * const data = pPage->aData; /* Local cache of pPage->aData */ |
| 53759 | 53430 | int top; /* First byte of cell content area */ |
| 53760 | | - int rc = SQLITE_OK; /* Integer return code */ |
| 53761 | 53431 | int gap; /* First byte of gap between cell pointers and cell content */ |
| 53432 | + int rc; /* Integer return code */ |
| 53433 | + int usableSize; /* Usable size of the page */ |
| 53762 | 53434 | |
| 53763 | 53435 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 53764 | 53436 | assert( pPage->pBt ); |
| 53765 | 53437 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 53766 | 53438 | assert( nByte>=0 ); /* Minimum cell size is 4 */ |
| 53767 | 53439 | assert( pPage->nFree>=nByte ); |
| 53768 | 53440 | assert( pPage->nOverflow==0 ); |
| 53769 | | - assert( nByte < (int)(pPage->pBt->usableSize-8) ); |
| 53441 | + usableSize = pPage->pBt->usableSize; |
| 53442 | + assert( nByte < usableSize-8 ); |
| 53770 | 53443 | |
| 53771 | 53444 | assert( pPage->cellOffset == hdr + 12 - 4*pPage->leaf ); |
| 53772 | 53445 | gap = pPage->cellOffset + 2*pPage->nCell; |
| 53773 | 53446 | assert( gap<=65536 ); |
| 53774 | 53447 | top = get2byte(&data[hdr+5]); |
| | @@ -53786,27 +53459,46 @@ |
| 53786 | 53459 | */ |
| 53787 | 53460 | testcase( gap+2==top ); |
| 53788 | 53461 | testcase( gap+1==top ); |
| 53789 | 53462 | testcase( gap==top ); |
| 53790 | 53463 | if( gap+2<=top && (data[hdr+1] || data[hdr+2]) ){ |
| 53791 | | - int bDefrag = 0; |
| 53792 | | - u8 *pSpace = pageFindSlot(pPage, nByte, &rc, &bDefrag); |
| 53793 | | - if( rc ) return rc; |
| 53794 | | - if( bDefrag ) goto defragment_page; |
| 53795 | | - if( pSpace ){ |
| 53796 | | - assert( pSpace>=data && (pSpace - data)<65536 ); |
| 53797 | | - *pIdx = (int)(pSpace - data); |
| 53798 | | - return SQLITE_OK; |
| 53464 | + int pc, addr; |
| 53465 | + for(addr=hdr+1; (pc = get2byte(&data[addr]))>0; addr=pc){ |
| 53466 | + int size; /* Size of the free slot */ |
| 53467 | + if( pc>usableSize-4 || pc<addr+4 ){ |
| 53468 | + return SQLITE_CORRUPT_BKPT; |
| 53469 | + } |
| 53470 | + size = get2byte(&data[pc+2]); |
| 53471 | + if( size>=nByte ){ |
| 53472 | + int x = size - nByte; |
| 53473 | + testcase( x==4 ); |
| 53474 | + testcase( x==3 ); |
| 53475 | + if( x<4 ){ |
| 53476 | + if( data[hdr+7]>=60 ) goto defragment_page; |
| 53477 | + /* Remove the slot from the free-list. Update the number of |
| 53478 | + ** fragmented bytes within the page. */ |
| 53479 | + memcpy(&data[addr], &data[pc], 2); |
| 53480 | + data[hdr+7] += (u8)x; |
| 53481 | + }else if( size+pc > usableSize ){ |
| 53482 | + return SQLITE_CORRUPT_BKPT; |
| 53483 | + }else{ |
| 53484 | + /* The slot remains on the free-list. Reduce its size to account |
| 53485 | + ** for the portion used by the new allocation. */ |
| 53486 | + put2byte(&data[pc+2], x); |
| 53487 | + } |
| 53488 | + *pIdx = pc + x; |
| 53489 | + return SQLITE_OK; |
| 53490 | + } |
| 53799 | 53491 | } |
| 53800 | 53492 | } |
| 53801 | 53493 | |
| 53802 | 53494 | /* The request could not be fulfilled using a freelist slot. Check |
| 53803 | 53495 | ** to see if defragmentation is necessary. |
| 53804 | 53496 | */ |
| 53805 | 53497 | testcase( gap+2+nByte==top ); |
| 53806 | 53498 | if( gap+2+nByte>top ){ |
| 53807 | | - defragment_page: |
| 53499 | +defragment_page: |
| 53808 | 53500 | testcase( pPage->nCell==0 ); |
| 53809 | 53501 | rc = defragmentPage(pPage); |
| 53810 | 53502 | if( rc ) return rc; |
| 53811 | 53503 | top = get2byteNotZero(&data[hdr+5]); |
| 53812 | 53504 | assert( gap+nByte<=top ); |
| | @@ -53850,11 +53542,11 @@ |
| 53850 | 53542 | unsigned char *data = pPage->aData; /* Page content */ |
| 53851 | 53543 | |
| 53852 | 53544 | assert( pPage->pBt!=0 ); |
| 53853 | 53545 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 53854 | 53546 | assert( iStart>=pPage->hdrOffset+6+pPage->childPtrSize ); |
| 53855 | | - assert( CORRUPT_DB || iEnd <= pPage->pBt->usableSize ); |
| 53547 | + assert( iEnd <= pPage->pBt->usableSize ); |
| 53856 | 53548 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 53857 | 53549 | assert( iSize>=4 ); /* Minimum cell size is 4 */ |
| 53858 | 53550 | assert( iStart<=iLast ); |
| 53859 | 53551 | |
| 53860 | 53552 | /* Overwrite deleted information with zeros when the secure_delete |
| | @@ -55972,33 +55664,56 @@ |
| 55972 | 55664 | ** |
| 55973 | 55665 | ** Every cursor is a candidate to be tripped, including cursors |
| 55974 | 55666 | ** that belong to other database connections that happen to be |
| 55975 | 55667 | ** sharing the cache with pBtree. |
| 55976 | 55668 | ** |
| 55977 | | -** This routine gets called when a rollback occurs. The writeOnly |
| 55978 | | -** flag is set to 1 if the transaction did not make any schema |
| 55979 | | -** changes, in which case the read cursors can continue operating. |
| 55980 | | -** If schema changes did occur in the transaction, then both read |
| 55981 | | -** and write cursors must both be tripped. |
| 55669 | +** This routine gets called when a rollback occurs. If the writeOnly |
| 55670 | +** flag is true, then only write-cursors need be tripped - read-only |
| 55671 | +** cursors save their current positions so that they may continue |
| 55672 | +** following the rollback. Or, if writeOnly is false, all cursors are |
| 55673 | +** tripped. In general, writeOnly is false if the transaction being |
| 55674 | +** rolled back modified the database schema. In this case b-tree root |
| 55675 | +** pages may be moved or deleted from the database altogether, making |
| 55676 | +** it unsafe for read cursors to continue. |
| 55677 | +** |
| 55678 | +** If the writeOnly flag is true and an error is encountered while |
| 55679 | +** saving the current position of a read-only cursor, all cursors, |
| 55680 | +** including all read-cursors are tripped. |
| 55681 | +** |
| 55682 | +** SQLITE_OK is returned if successful, or if an error occurs while |
| 55683 | +** saving a cursor position, an SQLite error code. |
| 55982 | 55684 | */ |
| 55983 | | -SQLITE_PRIVATE void sqlite3BtreeTripAllCursors(Btree *pBtree, int errCode, int writeOnly){ |
| 55685 | +SQLITE_PRIVATE int sqlite3BtreeTripAllCursors(Btree *pBtree, int errCode, int writeOnly){ |
| 55984 | 55686 | BtCursor *p; |
| 55687 | + int rc = SQLITE_OK; |
| 55688 | + |
| 55985 | 55689 | assert( (writeOnly==0 || writeOnly==1) && BTCF_WriteFlag==1 ); |
| 55986 | | - if( pBtree==0 ) return; |
| 55987 | | - sqlite3BtreeEnter(pBtree); |
| 55988 | | - for(p=pBtree->pBt->pCursor; p; p=p->pNext){ |
| 55989 | | - int i; |
| 55990 | | - if( writeOnly && (p->curFlags & BTCF_WriteFlag)==0 ) continue; |
| 55991 | | - sqlite3BtreeClearCursor(p); |
| 55992 | | - p->eState = CURSOR_FAULT; |
| 55993 | | - p->skipNext = errCode; |
| 55994 | | - for(i=0; i<=p->iPage; i++){ |
| 55995 | | - releasePage(p->apPage[i]); |
| 55996 | | - p->apPage[i] = 0; |
| 55997 | | - } |
| 55998 | | - } |
| 55999 | | - sqlite3BtreeLeave(pBtree); |
| 55690 | + if( pBtree ){ |
| 55691 | + sqlite3BtreeEnter(pBtree); |
| 55692 | + for(p=pBtree->pBt->pCursor; p; p=p->pNext){ |
| 55693 | + int i; |
| 55694 | + if( writeOnly && (p->curFlags & BTCF_WriteFlag)==0 ){ |
| 55695 | + if( p->eState==CURSOR_VALID ){ |
| 55696 | + rc = saveCursorPosition(p); |
| 55697 | + if( rc!=SQLITE_OK ){ |
| 55698 | + (void)sqlite3BtreeTripAllCursors(pBtree, rc, 0); |
| 55699 | + break; |
| 55700 | + } |
| 55701 | + } |
| 55702 | + }else{ |
| 55703 | + sqlite3BtreeClearCursor(p); |
| 55704 | + p->eState = CURSOR_FAULT; |
| 55705 | + p->skipNext = errCode; |
| 55706 | + } |
| 55707 | + for(i=0; i<=p->iPage; i++){ |
| 55708 | + releasePage(p->apPage[i]); |
| 55709 | + p->apPage[i] = 0; |
| 55710 | + } |
| 55711 | + } |
| 55712 | + sqlite3BtreeLeave(pBtree); |
| 55713 | + } |
| 55714 | + return rc; |
| 56000 | 55715 | } |
| 56001 | 55716 | |
| 56002 | 55717 | /* |
| 56003 | 55718 | ** Rollback the transaction in progress. |
| 56004 | 55719 | ** |
| | @@ -56023,11 +55738,13 @@ |
| 56023 | 55738 | if( rc ) writeOnly = 0; |
| 56024 | 55739 | }else{ |
| 56025 | 55740 | rc = SQLITE_OK; |
| 56026 | 55741 | } |
| 56027 | 55742 | if( tripCode ){ |
| 56028 | | - sqlite3BtreeTripAllCursors(p, tripCode, writeOnly); |
| 55743 | + int rc2 = sqlite3BtreeTripAllCursors(p, tripCode, writeOnly); |
| 55744 | + assert( rc==SQLITE_OK || (writeOnly==0 && rc2==SQLITE_OK) ); |
| 55745 | + if( rc2!=SQLITE_OK ) rc = rc2; |
| 56029 | 55746 | } |
| 56030 | 55747 | btreeIntegrity(p); |
| 56031 | 55748 | |
| 56032 | 55749 | if( p->inTrans==TRANS_WRITE ){ |
| 56033 | 55750 | int rc2; |
| | @@ -56358,17 +56075,13 @@ |
| 56358 | 56075 | ** |
| 56359 | 56076 | ** This routine cannot fail. It always returns SQLITE_OK. |
| 56360 | 56077 | */ |
| 56361 | 56078 | SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor *pCur, i64 *pSize){ |
| 56362 | 56079 | assert( cursorHoldsMutex(pCur) ); |
| 56363 | | - assert( pCur->eState==CURSOR_INVALID || pCur->eState==CURSOR_VALID ); |
| 56364 | | - if( pCur->eState!=CURSOR_VALID ){ |
| 56365 | | - *pSize = 0; |
| 56366 | | - }else{ |
| 56367 | | - getCellInfo(pCur); |
| 56368 | | - *pSize = pCur->info.nKey; |
| 56369 | | - } |
| 56080 | + assert( pCur->eState==CURSOR_VALID ); |
| 56081 | + getCellInfo(pCur); |
| 56082 | + *pSize = pCur->info.nKey; |
| 56370 | 56083 | return SQLITE_OK; |
| 56371 | 56084 | } |
| 56372 | 56085 | |
| 56373 | 56086 | /* |
| 56374 | 56087 | ** Set *pSize to the number of bytes of data in the entry the |
| | @@ -58444,266 +58157,49 @@ |
| 58444 | 58157 | #endif |
| 58445 | 58158 | } |
| 58446 | 58159 | } |
| 58447 | 58160 | |
| 58448 | 58161 | /* |
| 58449 | | -** Array apCell[] contains pointers to nCell b-tree page cells. The |
| 58450 | | -** szCell[] array contains the size in bytes of each cell. This function |
| 58451 | | -** replaces the current contents of page pPg with the contents of the cell |
| 58452 | | -** array. |
| 58453 | | -** |
| 58454 | | -** Some of the cells in apCell[] may currently be stored in pPg. This |
| 58455 | | -** function works around problems caused by this by making a copy of any |
| 58456 | | -** such cells before overwriting the page data. |
| 58457 | | -** |
| 58458 | | -** The MemPage.nFree field is invalidated by this function. It is the |
| 58459 | | -** responsibility of the caller to set it correctly. |
| 58460 | | -*/ |
| 58461 | | -static void rebuildPage( |
| 58462 | | - MemPage *pPg, /* Edit this page */ |
| 58463 | | - int nCell, /* Final number of cells on page */ |
| 58464 | | - u8 **apCell, /* Array of cells */ |
| 58465 | | - u16 *szCell /* Array of cell sizes */ |
| 58466 | | -){ |
| 58467 | | - const int hdr = pPg->hdrOffset; /* Offset of header on pPg */ |
| 58468 | | - u8 * const aData = pPg->aData; /* Pointer to data for pPg */ |
| 58469 | | - const int usableSize = pPg->pBt->usableSize; |
| 58470 | | - u8 * const pEnd = &aData[usableSize]; |
| 58471 | | - int i; |
| 58472 | | - u8 *pCellptr = pPg->aCellIdx; |
| 58473 | | - u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager); |
| 58474 | | - u8 *pData; |
| 58475 | | - |
| 58476 | | - i = get2byte(&aData[hdr+5]); |
| 58477 | | - memcpy(&pTmp[i], &aData[i], usableSize - i); |
| 58478 | | - |
| 58479 | | - pData = pEnd; |
| 58480 | | - for(i=0; i<nCell; i++){ |
| 58481 | | - u8 *pCell = apCell[i]; |
| 58482 | | - if( pCell>aData && pCell<pEnd ){ |
| 58483 | | - pCell = &pTmp[pCell - aData]; |
| 58484 | | - } |
| 58485 | | - pData -= szCell[i]; |
| 58486 | | - memcpy(pData, pCell, szCell[i]); |
| 58487 | | - put2byte(pCellptr, (pData - aData)); |
| 58488 | | - pCellptr += 2; |
| 58489 | | - assert( szCell[i]==cellSizePtr(pPg, pCell) ); |
| 58490 | | - } |
| 58491 | | - |
| 58492 | | - /* The pPg->nFree field is now set incorrectly. The caller will fix it. */ |
| 58493 | | - pPg->nCell = nCell; |
| 58494 | | - pPg->nOverflow = 0; |
| 58495 | | - |
| 58496 | | - put2byte(&aData[hdr+1], 0); |
| 58497 | | - put2byte(&aData[hdr+3], pPg->nCell); |
| 58498 | | - put2byte(&aData[hdr+5], pData - aData); |
| 58499 | | - aData[hdr+7] = 0x00; |
| 58500 | | -} |
| 58501 | | - |
| 58502 | | -/* |
| 58503 | | -** Array apCell[] contains nCell pointers to b-tree cells. Array szCell |
| 58504 | | -** contains the size in bytes of each such cell. This function attempts to |
| 58505 | | -** add the cells stored in the array to page pPg. If it cannot (because |
| 58506 | | -** the page needs to be defragmented before the cells will fit), non-zero |
| 58507 | | -** is returned. Otherwise, if the cells are added successfully, zero is |
| 58508 | | -** returned. |
| 58509 | | -** |
| 58510 | | -** Argument pCellptr points to the first entry in the cell-pointer array |
| 58511 | | -** (part of page pPg) to populate. After cell apCell[0] is written to the |
| 58512 | | -** page body, a 16-bit offset is written to pCellptr. And so on, for each |
| 58513 | | -** cell in the array. It is the responsibility of the caller to ensure |
| 58514 | | -** that it is safe to overwrite this part of the cell-pointer array. |
| 58515 | | -** |
| 58516 | | -** When this function is called, *ppData points to the start of the |
| 58517 | | -** content area on page pPg. If the size of the content area is extended, |
| 58518 | | -** *ppData is updated to point to the new start of the content area |
| 58519 | | -** before returning. |
| 58520 | | -** |
| 58521 | | -** Finally, argument pBegin points to the byte immediately following the |
| 58522 | | -** end of the space required by this page for the cell-pointer area (for |
| 58523 | | -** all cells - not just those inserted by the current call). If the content |
| 58524 | | -** area must be extended to before this point in order to accomodate all |
| 58525 | | -** cells in apCell[], then the cells do not fit and non-zero is returned. |
| 58526 | | -*/ |
| 58527 | | -static int pageInsertArray( |
| 58528 | | - MemPage *pPg, /* Page to add cells to */ |
| 58529 | | - u8 *pBegin, /* End of cell-pointer array */ |
| 58530 | | - u8 **ppData, /* IN/OUT: Page content -area pointer */ |
| 58531 | | - u8 *pCellptr, /* Pointer to cell-pointer area */ |
| 58532 | | - int nCell, /* Number of cells to add to pPg */ |
| 58533 | | - u8 **apCell, /* Array of cells */ |
| 58534 | | - u16 *szCell /* Array of cell sizes */ |
| 58535 | | -){ |
| 58536 | | - int i; |
| 58537 | | - u8 *aData = pPg->aData; |
| 58538 | | - u8 *pData = *ppData; |
| 58539 | | - const int bFreelist = aData[1] || aData[2]; |
| 58540 | | - assert( CORRUPT_DB || pPg->hdrOffset==0 ); /* Never called on page 1 */ |
| 58541 | | - for(i=0; i<nCell; i++){ |
| 58542 | | - int sz = szCell[i]; |
| 58543 | | - int rc; |
| 58544 | | - u8 *pSlot; |
| 58545 | | - if( bFreelist==0 || (pSlot = pageFindSlot(pPg, sz, &rc, 0))==0 ){ |
| 58546 | | - pData -= sz; |
| 58547 | | - if( pData<pBegin ) return 1; |
| 58548 | | - pSlot = pData; |
| 58549 | | - } |
| 58550 | | - memcpy(pSlot, apCell[i], sz); |
| 58551 | | - put2byte(pCellptr, (pSlot - aData)); |
| 58552 | | - pCellptr += 2; |
| 58553 | | - } |
| 58554 | | - *ppData = pData; |
| 58555 | | - return 0; |
| 58556 | | -} |
| 58557 | | - |
| 58558 | | -/* |
| 58559 | | -** Array apCell[] contains nCell pointers to b-tree cells. Array szCell |
| 58560 | | -** contains the size in bytes of each such cell. This function adds the |
| 58561 | | -** space associated with each cell in the array that is currently stored |
| 58562 | | -** within the body of pPg to the pPg free-list. The cell-pointers and other |
| 58563 | | -** fields of the page are not updated. |
| 58564 | | -** |
| 58565 | | -** This function returns the total number of cells added to the free-list. |
| 58566 | | -*/ |
| 58567 | | -static int pageFreeArray( |
| 58568 | | - MemPage *pPg, /* Page to edit */ |
| 58569 | | - int nCell, /* Cells to delete */ |
| 58570 | | - u8 **apCell, /* Array of cells */ |
| 58571 | | - u16 *szCell /* Array of cell sizes */ |
| 58572 | | -){ |
| 58573 | | - u8 * const aData = pPg->aData; |
| 58574 | | - u8 * const pEnd = &aData[pPg->pBt->usableSize]; |
| 58575 | | - u8 * const pStart = &aData[pPg->hdrOffset + 8 + pPg->childPtrSize]; |
| 58576 | | - int nRet = 0; |
| 58577 | | - int i; |
| 58578 | | - u8 *pFree = 0; |
| 58579 | | - int szFree = 0; |
| 58580 | | - |
| 58581 | | - for(i=0; i<nCell; i++){ |
| 58582 | | - u8 *pCell = apCell[i]; |
| 58583 | | - if( pCell>=pStart && pCell<pEnd ){ |
| 58584 | | - int sz = szCell[i]; |
| 58585 | | - if( pFree!=(pCell + sz) ){ |
| 58586 | | - if( pFree ){ |
| 58587 | | - assert( pFree>aData && (pFree - aData)<65536 ); |
| 58588 | | - freeSpace(pPg, (u16)(pFree - aData), szFree); |
| 58589 | | - } |
| 58590 | | - pFree = pCell; |
| 58591 | | - szFree = sz; |
| 58592 | | - if( pFree+sz>pEnd ) return 0; |
| 58593 | | - }else{ |
| 58594 | | - pFree = pCell; |
| 58595 | | - szFree += sz; |
| 58596 | | - } |
| 58597 | | - nRet++; |
| 58598 | | - } |
| 58599 | | - } |
| 58600 | | - if( pFree ){ |
| 58601 | | - assert( pFree>aData && (pFree - aData)<65536 ); |
| 58602 | | - freeSpace(pPg, (u16)(pFree - aData), szFree); |
| 58603 | | - } |
| 58604 | | - return nRet; |
| 58605 | | -} |
| 58606 | | - |
| 58607 | | -/* |
| 58608 | | -** The pPg->nFree field is invalid when this function returns. It is the |
| 58609 | | -** responsibility of the caller to set it correctly. |
| 58610 | | -*/ |
| 58611 | | -static void editPage( |
| 58612 | | - MemPage *pPg, /* Edit this page */ |
| 58613 | | - int iOld, /* Index of first cell currently on page */ |
| 58614 | | - int iNew, /* Index of new first cell on page */ |
| 58615 | | - int nNew, /* Final number of cells on page */ |
| 58616 | | - u8 **apCell, /* Array of cells */ |
| 58617 | | - u16 *szCell /* Array of cell sizes */ |
| 58618 | | -){ |
| 58619 | | - u8 * const aData = pPg->aData; |
| 58620 | | - const int hdr = pPg->hdrOffset; |
| 58621 | | - u8 *pBegin = &pPg->aCellIdx[nNew * 2]; |
| 58622 | | - int nCell = pPg->nCell; /* Cells stored on pPg */ |
| 58623 | | - u8 *pData; |
| 58624 | | - u8 *pCellptr; |
| 58625 | | - int i; |
| 58626 | | - int iOldEnd = iOld + pPg->nCell + pPg->nOverflow; |
| 58627 | | - int iNewEnd = iNew + nNew; |
| 58628 | | - |
| 58629 | | -#ifdef SQLITE_DEBUG |
| 58630 | | - u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager); |
| 58631 | | - memcpy(pTmp, aData, pPg->pBt->usableSize); |
| 58632 | | -#endif |
| 58633 | | - |
| 58634 | | - /* Remove cells from the start and end of the page */ |
| 58635 | | - if( iOld<iNew ){ |
| 58636 | | - int nShift = pageFreeArray( |
| 58637 | | - pPg, iNew-iOld, &apCell[iOld], &szCell[iOld] |
| 58638 | | - ); |
| 58639 | | - memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2); |
| 58640 | | - nCell -= nShift; |
| 58641 | | - } |
| 58642 | | - if( iNewEnd < iOldEnd ){ |
| 58643 | | - nCell -= pageFreeArray( |
| 58644 | | - pPg, iOldEnd-iNewEnd, &apCell[iNewEnd], &szCell[iNewEnd] |
| 58645 | | - ); |
| 58646 | | - } |
| 58647 | | - |
| 58648 | | - pData = &aData[get2byte(&aData[hdr+5])]; |
| 58649 | | - if( pData<pBegin ) goto editpage_fail; |
| 58650 | | - |
| 58651 | | - /* Add cells to the start of the page */ |
| 58652 | | - if( iNew<iOld ){ |
| 58653 | | - int nAdd = iOld-iNew; |
| 58654 | | - pCellptr = pPg->aCellIdx; |
| 58655 | | - memmove(&pCellptr[nAdd*2], pCellptr, nCell*2); |
| 58656 | | - if( pageInsertArray( |
| 58657 | | - pPg, pBegin, &pData, pCellptr, |
| 58658 | | - nAdd, &apCell[iNew], &szCell[iNew] |
| 58659 | | - ) ) goto editpage_fail; |
| 58660 | | - nCell += nAdd; |
| 58661 | | - } |
| 58662 | | - |
| 58663 | | - /* Add any overflow cells */ |
| 58664 | | - for(i=0; i<pPg->nOverflow; i++){ |
| 58665 | | - int iCell = (iOld + pPg->aiOvfl[i]) - iNew; |
| 58666 | | - if( iCell>=0 && iCell<nNew ){ |
| 58667 | | - pCellptr = &pPg->aCellIdx[iCell * 2]; |
| 58668 | | - memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2); |
| 58669 | | - nCell++; |
| 58670 | | - if( pageInsertArray( |
| 58671 | | - pPg, pBegin, &pData, pCellptr, |
| 58672 | | - 1, &apCell[iCell + iNew], &szCell[iCell + iNew] |
| 58673 | | - ) ) goto editpage_fail; |
| 58674 | | - } |
| 58675 | | - } |
| 58676 | | - |
| 58677 | | - /* Append cells to the end of the page */ |
| 58678 | | - pCellptr = &pPg->aCellIdx[nCell*2]; |
| 58679 | | - if( pageInsertArray( |
| 58680 | | - pPg, pBegin, &pData, pCellptr, |
| 58681 | | - nNew-nCell, &apCell[iNew+nCell], &szCell[iNew+nCell] |
| 58682 | | - ) ) goto editpage_fail; |
| 58683 | | - |
| 58684 | | - pPg->nCell = nNew; |
| 58685 | | - pPg->nOverflow = 0; |
| 58686 | | - |
| 58687 | | - put2byte(&aData[hdr+3], pPg->nCell); |
| 58688 | | - put2byte(&aData[hdr+5], pData - aData); |
| 58689 | | - |
| 58690 | | -#ifdef SQLITE_DEBUG |
| 58691 | | - for(i=0; i<nNew && !CORRUPT_DB; i++){ |
| 58692 | | - u8 *pCell = apCell[i+iNew]; |
| 58693 | | - int iOff = get2byte(&pPg->aCellIdx[i*2]); |
| 58694 | | - if( pCell>=aData && pCell<&aData[pPg->pBt->usableSize] ){ |
| 58695 | | - pCell = &pTmp[pCell - aData]; |
| 58696 | | - } |
| 58697 | | - assert( 0==memcmp(pCell, &aData[iOff], szCell[i+iNew]) ); |
| 58698 | | - } |
| 58699 | | -#endif |
| 58700 | | - |
| 58701 | | - return; |
| 58702 | | - editpage_fail: |
| 58703 | | - /* Unable to edit this page. Rebuild it from scratch instead. */ |
| 58704 | | - rebuildPage(pPg, nNew, &apCell[iNew], &szCell[iNew]); |
| 58162 | +** Add a list of cells to a page. The page should be initially empty. |
| 58163 | +** The cells are guaranteed to fit on the page. |
| 58164 | +*/ |
| 58165 | +static void assemblePage( |
| 58166 | + MemPage *pPage, /* The page to be assembled */ |
| 58167 | + int nCell, /* The number of cells to add to this page */ |
| 58168 | + u8 **apCell, /* Pointers to cell bodies */ |
| 58169 | + u16 *aSize /* Sizes of the cells */ |
| 58170 | +){ |
| 58171 | + int i; /* Loop counter */ |
| 58172 | + u8 *pCellptr; /* Address of next cell pointer */ |
| 58173 | + int cellbody; /* Address of next cell body */ |
| 58174 | + u8 * const data = pPage->aData; /* Pointer to data for pPage */ |
| 58175 | + const int hdr = pPage->hdrOffset; /* Offset of header on pPage */ |
| 58176 | + const int nUsable = pPage->pBt->usableSize; /* Usable size of page */ |
| 58177 | + |
| 58178 | + assert( pPage->nOverflow==0 ); |
| 58179 | + assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 58180 | + assert( nCell>=0 && nCell<=(int)MX_CELL(pPage->pBt) |
| 58181 | + && (int)MX_CELL(pPage->pBt)<=10921); |
| 58182 | + assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 58183 | + |
| 58184 | + /* Check that the page has just been zeroed by zeroPage() */ |
| 58185 | + assert( pPage->nCell==0 ); |
| 58186 | + assert( get2byteNotZero(&data[hdr+5])==nUsable ); |
| 58187 | + |
| 58188 | + pCellptr = &pPage->aCellIdx[nCell*2]; |
| 58189 | + cellbody = nUsable; |
| 58190 | + for(i=nCell-1; i>=0; i--){ |
| 58191 | + u16 sz = aSize[i]; |
| 58192 | + pCellptr -= 2; |
| 58193 | + cellbody -= sz; |
| 58194 | + put2byte(pCellptr, cellbody); |
| 58195 | + memcpy(&data[cellbody], apCell[i], sz); |
| 58196 | + } |
| 58197 | + put2byte(&data[hdr+3], nCell); |
| 58198 | + put2byte(&data[hdr+5], cellbody); |
| 58199 | + pPage->nFree -= (nCell*2 + nUsable - cellbody); |
| 58200 | + pPage->nCell = (u16)nCell; |
| 58705 | 58201 | } |
| 58706 | 58202 | |
| 58707 | 58203 | /* |
| 58708 | 58204 | ** The following parameters determine how many adjacent pages get involved |
| 58709 | 58205 | ** in a balancing operation. NN is the number of neighbors on either side |
| | @@ -58771,12 +58267,11 @@ |
| 58771 | 58267 | u8 *pStop; |
| 58772 | 58268 | |
| 58773 | 58269 | assert( sqlite3PagerIswriteable(pNew->pDbPage) ); |
| 58774 | 58270 | assert( pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) ); |
| 58775 | 58271 | zeroPage(pNew, PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF); |
| 58776 | | - rebuildPage(pNew, 1, &pCell, &szCell); |
| 58777 | | - pNew->nFree = pBt->usableSize - pNew->cellOffset - 2 - szCell; |
| 58272 | + assemblePage(pNew, 1, &pCell, &szCell); |
| 58778 | 58273 | |
| 58779 | 58274 | /* If this is an auto-vacuum database, update the pointer map |
| 58780 | 58275 | ** with entries for the new page, and any pointer from the |
| 58781 | 58276 | ** cell on the page to an overflow page. If either of these |
| 58782 | 58277 | ** operations fails, the return code is set, but the contents |
| | @@ -58991,26 +58486,21 @@ |
| 58991 | 58486 | int subtotal; /* Subtotal of bytes in cells on one page */ |
| 58992 | 58487 | int iSpace1 = 0; /* First unused byte of aSpace1[] */ |
| 58993 | 58488 | int iOvflSpace = 0; /* First unused byte of aOvflSpace[] */ |
| 58994 | 58489 | int szScratch; /* Size of scratch memory requested */ |
| 58995 | 58490 | MemPage *apOld[NB]; /* pPage and up to two siblings */ |
| 58491 | + MemPage *apCopy[NB]; /* Private copies of apOld[] pages */ |
| 58996 | 58492 | MemPage *apNew[NB+2]; /* pPage and up to NB siblings after balancing */ |
| 58997 | 58493 | u8 *pRight; /* Location in parent of right-sibling pointer */ |
| 58998 | 58494 | u8 *apDiv[NB-1]; /* Divider cells in pParent */ |
| 58999 | 58495 | int cntNew[NB+2]; /* Index in aCell[] of cell after i-th page */ |
| 59000 | | - int cntOld[NB+2]; /* Old index in aCell[] after i-th page */ |
| 59001 | | - int szNew[NB+2]; /* Combined size of cells placed on i-th page */ |
| 58496 | + int szNew[NB+2]; /* Combined size of cells place on i-th page */ |
| 59002 | 58497 | u8 **apCell = 0; /* All cells begin balanced */ |
| 59003 | 58498 | u16 *szCell; /* Local size of all cells in apCell[] */ |
| 59004 | 58499 | u8 *aSpace1; /* Space for copies of dividers cells */ |
| 59005 | 58500 | Pgno pgno; /* Temp var to store a page number in */ |
| 59006 | | - u8 abDone[NB+2]; /* True after i'th new page is populated */ |
| 59007 | | - Pgno aPgno[NB+2]; /* Page numbers of new pages before shuffling */ |
| 59008 | | - Pgno aPgOrder[NB+2]; /* Copy of aPgno[] used for sorting pages */ |
| 59009 | | - u16 aPgFlags[NB+2]; /* flags field of new pages before shuffling */ |
| 59010 | 58501 | |
| 59011 | | - memset(abDone, 0, sizeof(abDone)); |
| 59012 | 58502 | pBt = pParent->pBt; |
| 59013 | 58503 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 59014 | 58504 | assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 59015 | 58505 | |
| 59016 | 58506 | #if 0 |
| | @@ -59115,18 +58605,16 @@ |
| 59115 | 58605 | nMaxCells = (nMaxCells + 3)&~3; |
| 59116 | 58606 | |
| 59117 | 58607 | /* |
| 59118 | 58608 | ** Allocate space for memory structures |
| 59119 | 58609 | */ |
| 58610 | + k = pBt->pageSize + ROUND8(sizeof(MemPage)); |
| 59120 | 58611 | szScratch = |
| 59121 | 58612 | nMaxCells*sizeof(u8*) /* apCell */ |
| 59122 | 58613 | + nMaxCells*sizeof(u16) /* szCell */ |
| 59123 | | - + pBt->pageSize; /* aSpace1 */ |
| 59124 | | - |
| 59125 | | - /* EVIDENCE-OF: R-28375-38319 SQLite will never request a scratch buffer |
| 59126 | | - ** that is more than 6 times the database page size. */ |
| 59127 | | - assert( szScratch<=6*pBt->pageSize ); |
| 58614 | + + pBt->pageSize /* aSpace1 */ |
| 58615 | + + k*nOld; /* Page copies (apCopy) */ |
| 59128 | 58616 | apCell = sqlite3ScratchMalloc( szScratch ); |
| 59129 | 58617 | if( apCell==0 ){ |
| 59130 | 58618 | rc = SQLITE_NOMEM; |
| 59131 | 58619 | goto balance_cleanup; |
| 59132 | 58620 | } |
| | @@ -59135,12 +58623,12 @@ |
| 59135 | 58623 | assert( EIGHT_BYTE_ALIGNMENT(aSpace1) ); |
| 59136 | 58624 | |
| 59137 | 58625 | /* |
| 59138 | 58626 | ** Load pointers to all cells on sibling pages and the divider cells |
| 59139 | 58627 | ** into the local apCell[] array. Make copies of the divider cells |
| 59140 | | - ** into space obtained from aSpace1[]. The divider cells have already |
| 59141 | | - ** been removed from pParent. |
| 58628 | + ** into space obtained from aSpace1[] and remove the divider cells |
| 58629 | + ** from pParent. |
| 59142 | 58630 | ** |
| 59143 | 58631 | ** If the siblings are on leaf pages, then the child pointers of the |
| 59144 | 58632 | ** divider cells are stripped from the cells before they are copied |
| 59145 | 58633 | ** into aSpace1[]. In this way, all cells in apCell[] are without |
| 59146 | 58634 | ** child pointers. If siblings are not leaves, then all cell in |
| | @@ -59152,11 +58640,19 @@ |
| 59152 | 58640 | */ |
| 59153 | 58641 | leafCorrection = apOld[0]->leaf*4; |
| 59154 | 58642 | leafData = apOld[0]->intKeyLeaf; |
| 59155 | 58643 | for(i=0; i<nOld; i++){ |
| 59156 | 58644 | int limit; |
| 59157 | | - MemPage *pOld = apOld[i]; |
| 58645 | + |
| 58646 | + /* Before doing anything else, take a copy of the i'th original sibling |
| 58647 | + ** The rest of this function will use data from the copies rather |
| 58648 | + ** that the original pages since the original pages will be in the |
| 58649 | + ** process of being overwritten. */ |
| 58650 | + MemPage *pOld = apCopy[i] = (MemPage*)&aSpace1[pBt->pageSize + k*i]; |
| 58651 | + memcpy(pOld, apOld[i], sizeof(MemPage)); |
| 58652 | + pOld->aData = (void*)&pOld[1]; |
| 58653 | + memcpy(pOld->aData, apOld[i]->aData, pBt->pageSize); |
| 59158 | 58654 | |
| 59159 | 58655 | limit = pOld->nCell+pOld->nOverflow; |
| 59160 | 58656 | if( pOld->nOverflow>0 ){ |
| 59161 | 58657 | for(j=0; j<limit; j++){ |
| 59162 | 58658 | assert( nCell<nMaxCells ); |
| | @@ -59173,11 +58669,10 @@ |
| 59173 | 58669 | apCell[nCell] = findCellv2(aData, maskPage, cellOffset, j); |
| 59174 | 58670 | szCell[nCell] = cellSizePtr(pOld, apCell[nCell]); |
| 59175 | 58671 | nCell++; |
| 59176 | 58672 | } |
| 59177 | 58673 | } |
| 59178 | | - cntOld[i] = nCell; |
| 59179 | 58674 | if( i<nOld-1 && !leafData){ |
| 59180 | 58675 | u16 sz = (u16)szNew[i]; |
| 59181 | 58676 | u8 *pTemp; |
| 59182 | 58677 | assert( nCell<nMaxCells ); |
| 59183 | 58678 | szCell[nCell] = sz; |
| | @@ -59225,11 +58720,11 @@ |
| 59225 | 58720 | usableSpace = pBt->usableSize - 12 + leafCorrection; |
| 59226 | 58721 | for(subtotal=k=i=0; i<nCell; i++){ |
| 59227 | 58722 | assert( i<nMaxCells ); |
| 59228 | 58723 | subtotal += szCell[i] + 2; |
| 59229 | 58724 | if( subtotal > usableSpace ){ |
| 59230 | | - szNew[k] = subtotal - szCell[i] - 2; |
| 58725 | + szNew[k] = subtotal - szCell[i]; |
| 59231 | 58726 | cntNew[k] = i; |
| 59232 | 58727 | if( leafData ){ i--; } |
| 59233 | 58728 | subtotal = 0; |
| 59234 | 58729 | k++; |
| 59235 | 58730 | if( k>NB+1 ){ rc = SQLITE_CORRUPT_BKPT; goto balance_cleanup; } |
| | @@ -59239,14 +58734,13 @@ |
| 59239 | 58734 | cntNew[k] = nCell; |
| 59240 | 58735 | k++; |
| 59241 | 58736 | |
| 59242 | 58737 | /* |
| 59243 | 58738 | ** The packing computed by the previous block is biased toward the siblings |
| 59244 | | - ** on the left side (siblings with smaller keys). The left siblings are |
| 59245 | | - ** always nearly full, while the right-most sibling might be nearly empty. |
| 59246 | | - ** The next block of code attempts to adjust the packing of siblings to |
| 59247 | | - ** get a better balance. |
| 58739 | + ** on the left side. The left siblings are always nearly full, while the |
| 58740 | + ** right-most sibling might be nearly empty. This block of code attempts |
| 58741 | + ** to adjust the packing of siblings to get a better balance. |
| 59248 | 58742 | ** |
| 59249 | 58743 | ** This adjustment is more than an optimization. The packing above might |
| 59250 | 58744 | ** be so out of balance as to be illegal. For example, the right-most |
| 59251 | 58745 | ** sibling might be completely empty. This adjustment is not optional. |
| 59252 | 58746 | */ |
| | @@ -59271,22 +58765,26 @@ |
| 59271 | 58765 | } |
| 59272 | 58766 | szNew[i] = szRight; |
| 59273 | 58767 | szNew[i-1] = szLeft; |
| 59274 | 58768 | } |
| 59275 | 58769 | |
| 59276 | | - /* Sanity check: For a non-corrupt database file one of the follwing |
| 59277 | | - ** must be true: |
| 59278 | | - ** (1) We found one or more cells (cntNew[0])>0), or |
| 59279 | | - ** (2) pPage is a virtual root page. A virtual root page is when |
| 59280 | | - ** the real root page is page 1 and we are the only child of |
| 59281 | | - ** that page. |
| 58770 | + /* Either we found one or more cells (cntnew[0])>0) or pPage is |
| 58771 | + ** a virtual root page. A virtual root page is when the real root |
| 58772 | + ** page is page 1 and we are the only child of that page. |
| 58773 | + ** |
| 58774 | + ** UPDATE: The assert() below is not necessarily true if the database |
| 58775 | + ** file is corrupt. The corruption will be detected and reported later |
| 58776 | + ** in this procedure so there is no need to act upon it now. |
| 59282 | 58777 | */ |
| 59283 | | - assert( cntNew[0]>0 || (pParent->pgno==1 && pParent->nCell==0) || CORRUPT_DB); |
| 59284 | | - TRACE(("BALANCE: old: %d(nc=%d) %d(nc=%d) %d(nc=%d)\n", |
| 59285 | | - apOld[0]->pgno, apOld[0]->nCell, |
| 59286 | | - nOld>=2 ? apOld[1]->pgno : 0, nOld>=2 ? apOld[1]->nCell : 0, |
| 59287 | | - nOld>=3 ? apOld[2]->pgno : 0, nOld>=3 ? apOld[2]->nCell : 0 |
| 58778 | +#if 0 |
| 58779 | + assert( cntNew[0]>0 || (pParent->pgno==1 && pParent->nCell==0) ); |
| 58780 | +#endif |
| 58781 | + |
| 58782 | + TRACE(("BALANCE: old: %d %d %d ", |
| 58783 | + apOld[0]->pgno, |
| 58784 | + nOld>=2 ? apOld[1]->pgno : 0, |
| 58785 | + nOld>=3 ? apOld[2]->pgno : 0 |
| 59288 | 58786 | )); |
| 59289 | 58787 | |
| 59290 | 58788 | /* |
| 59291 | 58789 | ** Allocate k new pages. Reuse old pages where possible. |
| 59292 | 58790 | */ |
| | @@ -59305,14 +58803,12 @@ |
| 59305 | 58803 | if( rc ) goto balance_cleanup; |
| 59306 | 58804 | }else{ |
| 59307 | 58805 | assert( i>0 ); |
| 59308 | 58806 | rc = allocateBtreePage(pBt, &pNew, &pgno, (bBulk ? 1 : pgno), 0); |
| 59309 | 58807 | if( rc ) goto balance_cleanup; |
| 59310 | | - zeroPage(pNew, pageFlags); |
| 59311 | 58808 | apNew[i] = pNew; |
| 59312 | 58809 | nNew++; |
| 59313 | | - cntOld[i] = nCell; |
| 59314 | 58810 | |
| 59315 | 58811 | /* Set the pointer-map entry for the new sibling page. */ |
| 59316 | 58812 | if( ISAUTOVACUUM ){ |
| 59317 | 58813 | ptrmapPut(pBt, pNew->pgno, PTRMAP_BTREE, pParent->pgno, &rc); |
| 59318 | 58814 | if( rc!=SQLITE_OK ){ |
| | @@ -59319,248 +58815,140 @@ |
| 59319 | 58815 | goto balance_cleanup; |
| 59320 | 58816 | } |
| 59321 | 58817 | } |
| 59322 | 58818 | } |
| 59323 | 58819 | } |
| 58820 | + |
| 58821 | + /* Free any old pages that were not reused as new pages. |
| 58822 | + */ |
| 58823 | + while( i<nOld ){ |
| 58824 | + freePage(apOld[i], &rc); |
| 58825 | + if( rc ) goto balance_cleanup; |
| 58826 | + releasePage(apOld[i]); |
| 58827 | + apOld[i] = 0; |
| 58828 | + i++; |
| 58829 | + } |
| 59324 | 58830 | |
| 59325 | 58831 | /* |
| 59326 | | - ** Reassign page numbers so that the new pages are in ascending order. |
| 59327 | | - ** This helps to keep entries in the disk file in order so that a scan |
| 59328 | | - ** of the table is closer to a linear scan through the file. That in turn |
| 59329 | | - ** helps the operating system to deliver pages from the disk more rapidly. |
| 59330 | | - ** |
| 59331 | | - ** An O(n^2) insertion sort algorithm is used, but since n is never more |
| 59332 | | - ** than (NB+2) (a small constant), that should not be a problem. |
| 59333 | | - ** |
| 59334 | | - ** When NB==3, this one optimization makes the database about 25% faster |
| 59335 | | - ** for large insertions and deletions. |
| 59336 | | - */ |
| 59337 | | - for(i=0; i<nNew; i++){ |
| 59338 | | - aPgOrder[i] = aPgno[i] = apNew[i]->pgno; |
| 59339 | | - aPgFlags[i] = apNew[i]->pDbPage->flags; |
| 59340 | | - for(j=0; j<i; j++){ |
| 59341 | | - if( aPgno[j]==aPgno[i] ){ |
| 59342 | | - /* This branch is taken if the set of sibling pages somehow contains |
| 59343 | | - ** duplicate entries. This can happen if the database is corrupt. |
| 59344 | | - ** It would be simpler to detect this as part of the loop below, but |
| 59345 | | - ** we do the detection here in order to avoid populating the pager |
| 59346 | | - ** cache with two separate objects associated with the same |
| 59347 | | - ** page number. */ |
| 59348 | | - assert( CORRUPT_DB ); |
| 59349 | | - rc = SQLITE_CORRUPT_BKPT; |
| 59350 | | - goto balance_cleanup; |
| 59351 | | - } |
| 59352 | | - } |
| 59353 | | - } |
| 59354 | | - for(i=0; i<nNew; i++){ |
| 59355 | | - int iBest = 0; /* aPgno[] index of page number to use */ |
| 59356 | | - for(j=1; j<nNew; j++){ |
| 59357 | | - if( aPgOrder[j]<aPgOrder[iBest] ) iBest = j; |
| 59358 | | - } |
| 59359 | | - pgno = aPgOrder[iBest]; |
| 59360 | | - aPgOrder[iBest] = 0xffffffff; |
| 59361 | | - if( iBest!=i ){ |
| 59362 | | - if( iBest>i ){ |
| 59363 | | - sqlite3PagerRekey(apNew[iBest]->pDbPage, pBt->nPage+iBest+1, 0); |
| 59364 | | - } |
| 59365 | | - sqlite3PagerRekey(apNew[i]->pDbPage, pgno, aPgFlags[iBest]); |
| 59366 | | - apNew[i]->pgno = pgno; |
| 59367 | | - } |
| 59368 | | - } |
| 59369 | | - |
| 59370 | | - TRACE(("BALANCE: new: %d(%d nc=%d) %d(%d nc=%d) %d(%d nc=%d) " |
| 59371 | | - "%d(%d nc=%d) %d(%d nc=%d)\n", |
| 59372 | | - apNew[0]->pgno, szNew[0], cntNew[0], |
| 58832 | + ** Put the new pages in ascending order. This helps to |
| 58833 | + ** keep entries in the disk file in order so that a scan |
| 58834 | + ** of the table is a linear scan through the file. That |
| 58835 | + ** in turn helps the operating system to deliver pages |
| 58836 | + ** from the disk more rapidly. |
| 58837 | + ** |
| 58838 | + ** An O(n^2) insertion sort algorithm is used, but since |
| 58839 | + ** n is never more than NB (a small constant), that should |
| 58840 | + ** not be a problem. |
| 58841 | + ** |
| 58842 | + ** When NB==3, this one optimization makes the database |
| 58843 | + ** about 25% faster for large insertions and deletions. |
| 58844 | + */ |
| 58845 | + for(i=0; i<k-1; i++){ |
| 58846 | + int minV = apNew[i]->pgno; |
| 58847 | + int minI = i; |
| 58848 | + for(j=i+1; j<k; j++){ |
| 58849 | + if( apNew[j]->pgno<(unsigned)minV ){ |
| 58850 | + minI = j; |
| 58851 | + minV = apNew[j]->pgno; |
| 58852 | + } |
| 58853 | + } |
| 58854 | + if( minI>i ){ |
| 58855 | + MemPage *pT; |
| 58856 | + pT = apNew[i]; |
| 58857 | + apNew[i] = apNew[minI]; |
| 58858 | + apNew[minI] = pT; |
| 58859 | + } |
| 58860 | + } |
| 58861 | + TRACE(("new: %d(%d) %d(%d) %d(%d) %d(%d) %d(%d)\n", |
| 58862 | + apNew[0]->pgno, szNew[0], |
| 59373 | 58863 | nNew>=2 ? apNew[1]->pgno : 0, nNew>=2 ? szNew[1] : 0, |
| 59374 | | - nNew>=2 ? cntNew[1] - cntNew[0] - !leafData : 0, |
| 59375 | 58864 | nNew>=3 ? apNew[2]->pgno : 0, nNew>=3 ? szNew[2] : 0, |
| 59376 | | - nNew>=3 ? cntNew[2] - cntNew[1] - !leafData : 0, |
| 59377 | 58865 | nNew>=4 ? apNew[3]->pgno : 0, nNew>=4 ? szNew[3] : 0, |
| 59378 | | - nNew>=4 ? cntNew[3] - cntNew[2] - !leafData : 0, |
| 59379 | | - nNew>=5 ? apNew[4]->pgno : 0, nNew>=5 ? szNew[4] : 0, |
| 59380 | | - nNew>=5 ? cntNew[4] - cntNew[3] - !leafData : 0 |
| 59381 | | - )); |
| 58866 | + nNew>=5 ? apNew[4]->pgno : 0, nNew>=5 ? szNew[4] : 0)); |
| 59382 | 58867 | |
| 59383 | 58868 | assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 59384 | 58869 | put4byte(pRight, apNew[nNew-1]->pgno); |
| 59385 | 58870 | |
| 59386 | | - /* If the sibling pages are not leaves, ensure that the right-child pointer |
| 59387 | | - ** of the right-most new sibling page is set to the value that was |
| 59388 | | - ** originally in the same field of the right-most old sibling page. */ |
| 59389 | | - if( (pageFlags & PTF_LEAF)==0 && nOld!=nNew ){ |
| 59390 | | - MemPage *pOld = (nNew>nOld ? apNew : apOld)[nOld-1]; |
| 59391 | | - memcpy(&apNew[nNew-1]->aData[8], &pOld->aData[8], 4); |
| 59392 | | - } |
| 59393 | | - |
| 59394 | | - /* Make any required updates to pointer map entries associated with |
| 59395 | | - ** cells stored on sibling pages following the balance operation. Pointer |
| 59396 | | - ** map entries associated with divider cells are set by the insertCell() |
| 59397 | | - ** routine. The associated pointer map entries are: |
| 59398 | | - ** |
| 59399 | | - ** a) if the cell contains a reference to an overflow chain, the |
| 59400 | | - ** entry associated with the first page in the overflow chain, and |
| 59401 | | - ** |
| 59402 | | - ** b) if the sibling pages are not leaves, the child page associated |
| 59403 | | - ** with the cell. |
| 59404 | | - ** |
| 59405 | | - ** If the sibling pages are not leaves, then the pointer map entry |
| 59406 | | - ** associated with the right-child of each sibling may also need to be |
| 59407 | | - ** updated. This happens below, after the sibling pages have been |
| 59408 | | - ** populated, not here. |
| 58871 | + /* |
| 58872 | + ** Evenly distribute the data in apCell[] across the new pages. |
| 58873 | + ** Insert divider cells into pParent as necessary. |
| 59409 | 58874 | */ |
| 59410 | | - if( ISAUTOVACUUM ){ |
| 59411 | | - MemPage *pNew = apNew[0]; |
| 59412 | | - u8 *aOld = pNew->aData; |
| 59413 | | - int cntOldNext = pNew->nCell + pNew->nOverflow; |
| 59414 | | - int usableSize = pBt->usableSize; |
| 59415 | | - int iNew = 0; |
| 59416 | | - int iOld = 0; |
| 59417 | | - |
| 59418 | | - for(i=0; i<nCell; i++){ |
| 59419 | | - u8 *pCell = apCell[i]; |
| 59420 | | - if( i==cntOldNext ){ |
| 59421 | | - MemPage *pOld = (++iOld)<nNew ? apNew[iOld] : apOld[iOld]; |
| 59422 | | - cntOldNext += pOld->nCell + pOld->nOverflow + !leafData; |
| 59423 | | - aOld = pOld->aData; |
| 59424 | | - } |
| 59425 | | - if( i==cntNew[iNew] ){ |
| 59426 | | - pNew = apNew[++iNew]; |
| 59427 | | - if( !leafData ) continue; |
| 59428 | | - } |
| 59429 | | - |
| 59430 | | - /* Cell pCell is destined for new sibling page pNew. Originally, it |
| 59431 | | - ** was either part of sibling page iOld (possibly an overflow cell), |
| 59432 | | - ** or else the divider cell to the left of sibling page iOld. So, |
| 59433 | | - ** if sibling page iOld had the same page number as pNew, and if |
| 59434 | | - ** pCell really was a part of sibling page iOld (not a divider or |
| 59435 | | - ** overflow cell), we can skip updating the pointer map entries. */ |
| 59436 | | - if( pNew->pgno!=aPgno[iOld] || pCell<aOld || pCell>=&aOld[usableSize] ){ |
| 59437 | | - if( !leafCorrection ){ |
| 59438 | | - ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc); |
| 59439 | | - } |
| 59440 | | - if( szCell[i]>pNew->minLocal ){ |
| 59441 | | - ptrmapPutOvflPtr(pNew, pCell, &rc); |
| 59442 | | - } |
| 59443 | | - } |
| 59444 | | - } |
| 59445 | | - } |
| 59446 | | - |
| 59447 | | - /* Insert new divider cells into pParent. */ |
| 59448 | | - for(i=0; i<nNew-1; i++){ |
| 59449 | | - u8 *pCell; |
| 59450 | | - u8 *pTemp; |
| 59451 | | - int sz; |
| 58875 | + j = 0; |
| 58876 | + for(i=0; i<nNew; i++){ |
| 58877 | + /* Assemble the new sibling page. */ |
| 59452 | 58878 | MemPage *pNew = apNew[i]; |
| 58879 | + assert( j<nMaxCells ); |
| 58880 | + zeroPage(pNew, pageFlags); |
| 58881 | + assemblePage(pNew, cntNew[i]-j, &apCell[j], &szCell[j]); |
| 58882 | + assert( pNew->nCell>0 || (nNew==1 && cntNew[0]==0) ); |
| 58883 | + assert( pNew->nOverflow==0 ); |
| 58884 | + |
| 59453 | 58885 | j = cntNew[i]; |
| 59454 | 58886 | |
| 59455 | | - assert( j<nMaxCells ); |
| 59456 | | - pCell = apCell[j]; |
| 59457 | | - sz = szCell[j] + leafCorrection; |
| 59458 | | - pTemp = &aOvflSpace[iOvflSpace]; |
| 59459 | | - if( !pNew->leaf ){ |
| 59460 | | - memcpy(&pNew->aData[8], pCell, 4); |
| 59461 | | - }else if( leafData ){ |
| 59462 | | - /* If the tree is a leaf-data tree, and the siblings are leaves, |
| 59463 | | - ** then there is no divider cell in apCell[]. Instead, the divider |
| 59464 | | - ** cell consists of the integer key for the right-most cell of |
| 59465 | | - ** the sibling-page assembled above only. |
| 59466 | | - */ |
| 59467 | | - CellInfo info; |
| 59468 | | - j--; |
| 59469 | | - btreeParseCellPtr(pNew, apCell[j], &info); |
| 59470 | | - pCell = pTemp; |
| 59471 | | - sz = 4 + putVarint(&pCell[4], info.nKey); |
| 59472 | | - pTemp = 0; |
| 59473 | | - }else{ |
| 59474 | | - pCell -= 4; |
| 59475 | | - /* Obscure case for non-leaf-data trees: If the cell at pCell was |
| 59476 | | - ** previously stored on a leaf node, and its reported size was 4 |
| 59477 | | - ** bytes, then it may actually be smaller than this |
| 59478 | | - ** (see btreeParseCellPtr(), 4 bytes is the minimum size of |
| 59479 | | - ** any cell). But it is important to pass the correct size to |
| 59480 | | - ** insertCell(), so reparse the cell now. |
| 59481 | | - ** |
| 59482 | | - ** Note that this can never happen in an SQLite data file, as all |
| 59483 | | - ** cells are at least 4 bytes. It only happens in b-trees used |
| 59484 | | - ** to evaluate "IN (SELECT ...)" and similar clauses. |
| 59485 | | - */ |
| 59486 | | - if( szCell[j]==4 ){ |
| 59487 | | - assert(leafCorrection==4); |
| 59488 | | - sz = cellSizePtr(pParent, pCell); |
| 59489 | | - } |
| 59490 | | - } |
| 59491 | | - iOvflSpace += sz; |
| 59492 | | - assert( sz<=pBt->maxLocal+23 ); |
| 59493 | | - assert( iOvflSpace <= (int)pBt->pageSize ); |
| 59494 | | - insertCell(pParent, nxDiv+i, pCell, sz, pTemp, pNew->pgno, &rc); |
| 59495 | | - if( rc!=SQLITE_OK ) goto balance_cleanup; |
| 59496 | | - assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 59497 | | - } |
| 59498 | | - |
| 59499 | | - /* Now update the actual sibling pages. The order in which they are updated |
| 59500 | | - ** is important, as this code needs to avoid disrupting any page from which |
| 59501 | | - ** cells may still to be read. In practice, this means: |
| 59502 | | - ** |
| 59503 | | - ** (1) If cells are moving left (from apNew[iPg] to apNew[iPg-1]) |
| 59504 | | - ** then it is not safe to update page apNew[iPg] until after |
| 59505 | | - ** the left-hand sibling apNew[iPg-1] has been updated. |
| 59506 | | - ** |
| 59507 | | - ** (2) If cells are moving right (from apNew[iPg] to apNew[iPg+1]) |
| 59508 | | - ** then it is not safe to update page apNew[iPg] until after |
| 59509 | | - ** the right-hand sibling apNew[iPg+1] has been updated. |
| 59510 | | - ** |
| 59511 | | - ** If neither of the above apply, the page is safe to update. |
| 59512 | | - ** |
| 59513 | | - ** The iPg value in the following loop starts at nNew-1 goes down |
| 59514 | | - ** to 0, then back up to nNew-1 again, thus making two passes over |
| 59515 | | - ** the pages. On the initial downward pass, only condition (1) above |
| 59516 | | - ** needs to be tested because (2) will always be true from the previous |
| 59517 | | - ** step. On the upward pass, both conditions are always true, so the |
| 59518 | | - ** upwards pass simply processes pages that were missed on the downward |
| 59519 | | - ** pass. |
| 59520 | | - */ |
| 59521 | | - for(i=1-nNew; i<nNew; i++){ |
| 59522 | | - int iPg = i<0 ? -i : i; |
| 59523 | | - assert( iPg>=0 && iPg<nNew ); |
| 59524 | | - if( abDone[iPg] ) continue; /* Skip pages already processed */ |
| 59525 | | - if( i>=0 /* On the upwards pass, or... */ |
| 59526 | | - || cntOld[iPg-1]>=cntNew[iPg-1] /* Condition (1) is true */ |
| 59527 | | - ){ |
| 59528 | | - int iNew; |
| 59529 | | - int iOld; |
| 59530 | | - int nNewCell; |
| 59531 | | - |
| 59532 | | - /* Verify condition (1): If cells are moving left, update iPg |
| 59533 | | - ** only after iPg-1 has already been updated. */ |
| 59534 | | - assert( iPg==0 || cntOld[iPg-1]>=cntNew[iPg-1] || abDone[iPg-1] ); |
| 59535 | | - |
| 59536 | | - /* Verify condition (2): If cells are moving right, update iPg |
| 59537 | | - ** only after iPg+1 has already been updated. */ |
| 59538 | | - assert( cntNew[iPg]>=cntOld[iPg] || abDone[iPg+1] ); |
| 59539 | | - |
| 59540 | | - if( iPg==0 ){ |
| 59541 | | - iNew = iOld = 0; |
| 59542 | | - nNewCell = cntNew[0]; |
| 59543 | | - }else{ |
| 59544 | | - iOld = iPg<nOld ? (cntOld[iPg-1] + !leafData) : nCell; |
| 59545 | | - iNew = cntNew[iPg-1] + !leafData; |
| 59546 | | - nNewCell = cntNew[iPg] - iNew; |
| 59547 | | - } |
| 59548 | | - |
| 59549 | | - editPage(apNew[iPg], iOld, iNew, nNewCell, apCell, szCell); |
| 59550 | | - abDone[iPg]++; |
| 59551 | | - apNew[iPg]->nFree = usableSpace-szNew[iPg]; |
| 59552 | | - assert( apNew[iPg]->nOverflow==0 ); |
| 59553 | | - assert( apNew[iPg]->nCell==nNewCell ); |
| 59554 | | - } |
| 59555 | | - } |
| 59556 | | - |
| 59557 | | - /* All pages have been processed exactly once */ |
| 59558 | | - assert( memcmp(abDone, "\01\01\01\01\01", nNew)==0 ); |
| 59559 | | - |
| 58887 | + /* If the sibling page assembled above was not the right-most sibling, |
| 58888 | + ** insert a divider cell into the parent page. |
| 58889 | + */ |
| 58890 | + assert( i<nNew-1 || j==nCell ); |
| 58891 | + if( j<nCell ){ |
| 58892 | + u8 *pCell; |
| 58893 | + u8 *pTemp; |
| 58894 | + int sz; |
| 58895 | + |
| 58896 | + assert( j<nMaxCells ); |
| 58897 | + pCell = apCell[j]; |
| 58898 | + sz = szCell[j] + leafCorrection; |
| 58899 | + pTemp = &aOvflSpace[iOvflSpace]; |
| 58900 | + if( !pNew->leaf ){ |
| 58901 | + memcpy(&pNew->aData[8], pCell, 4); |
| 58902 | + }else if( leafData ){ |
| 58903 | + /* If the tree is a leaf-data tree, and the siblings are leaves, |
| 58904 | + ** then there is no divider cell in apCell[]. Instead, the divider |
| 58905 | + ** cell consists of the integer key for the right-most cell of |
| 58906 | + ** the sibling-page assembled above only. |
| 58907 | + */ |
| 58908 | + CellInfo info; |
| 58909 | + j--; |
| 58910 | + btreeParseCellPtr(pNew, apCell[j], &info); |
| 58911 | + pCell = pTemp; |
| 58912 | + sz = 4 + putVarint(&pCell[4], info.nKey); |
| 58913 | + pTemp = 0; |
| 58914 | + }else{ |
| 58915 | + pCell -= 4; |
| 58916 | + /* Obscure case for non-leaf-data trees: If the cell at pCell was |
| 58917 | + ** previously stored on a leaf node, and its reported size was 4 |
| 58918 | + ** bytes, then it may actually be smaller than this |
| 58919 | + ** (see btreeParseCellPtr(), 4 bytes is the minimum size of |
| 58920 | + ** any cell). But it is important to pass the correct size to |
| 58921 | + ** insertCell(), so reparse the cell now. |
| 58922 | + ** |
| 58923 | + ** Note that this can never happen in an SQLite data file, as all |
| 58924 | + ** cells are at least 4 bytes. It only happens in b-trees used |
| 58925 | + ** to evaluate "IN (SELECT ...)" and similar clauses. |
| 58926 | + */ |
| 58927 | + if( szCell[j]==4 ){ |
| 58928 | + assert(leafCorrection==4); |
| 58929 | + sz = cellSizePtr(pParent, pCell); |
| 58930 | + } |
| 58931 | + } |
| 58932 | + iOvflSpace += sz; |
| 58933 | + assert( sz<=pBt->maxLocal+23 ); |
| 58934 | + assert( iOvflSpace <= (int)pBt->pageSize ); |
| 58935 | + insertCell(pParent, nxDiv, pCell, sz, pTemp, pNew->pgno, &rc); |
| 58936 | + if( rc!=SQLITE_OK ) goto balance_cleanup; |
| 58937 | + assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 58938 | + |
| 58939 | + j++; |
| 58940 | + nxDiv++; |
| 58941 | + } |
| 58942 | + } |
| 58943 | + assert( j==nCell ); |
| 59560 | 58944 | assert( nOld>0 ); |
| 59561 | 58945 | assert( nNew>0 ); |
| 58946 | + if( (pageFlags & PTF_LEAF)==0 ){ |
| 58947 | + u8 *zChild = &apCopy[nOld-1]->aData[8]; |
| 58948 | + memcpy(&apNew[nNew-1]->aData[8], zChild, 4); |
| 58949 | + } |
| 59562 | 58950 | |
| 59563 | 58951 | if( isRoot && pParent->nCell==0 && pParent->hdrOffset<=apNew[0]->nFree ){ |
| 59564 | 58952 | /* The root page of the b-tree now contains no cells. The only sibling |
| 59565 | 58953 | ** page is the right-child of the parent. Copy the contents of the |
| 59566 | 58954 | ** child page into the parent, decreasing the overall height of the |
| | @@ -59569,54 +58957,130 @@ |
| 59569 | 58957 | ** |
| 59570 | 58958 | ** If this is an auto-vacuum database, the call to copyNodeContent() |
| 59571 | 58959 | ** sets all pointer-map entries corresponding to database image pages |
| 59572 | 58960 | ** for which the pointer is stored within the content being copied. |
| 59573 | 58961 | ** |
| 59574 | | - ** It is critical that the child page be defragmented before being |
| 59575 | | - ** copied into the parent, because if the parent is page 1 then it will |
| 59576 | | - ** by smaller than the child due to the database header, and so all the |
| 59577 | | - ** free space needs to be up front. |
| 59578 | | - */ |
| 58962 | + ** The second assert below verifies that the child page is defragmented |
| 58963 | + ** (it must be, as it was just reconstructed using assemblePage()). This |
| 58964 | + ** is important if the parent page happens to be page 1 of the database |
| 58965 | + ** image. */ |
| 59579 | 58966 | assert( nNew==1 ); |
| 59580 | | - rc = defragmentPage(apNew[0]); |
| 59581 | | - testcase( rc!=SQLITE_OK ); |
| 59582 | 58967 | assert( apNew[0]->nFree == |
| 59583 | | - (get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2) |
| 59584 | | - || rc!=SQLITE_OK |
| 58968 | + (get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2) |
| 59585 | 58969 | ); |
| 59586 | 58970 | copyNodeContent(apNew[0], pParent, &rc); |
| 59587 | 58971 | freePage(apNew[0], &rc); |
| 59588 | | - }else if( ISAUTOVACUUM && !leafCorrection ){ |
| 59589 | | - /* Fix the pointer map entries associated with the right-child of each |
| 59590 | | - ** sibling page. All other pointer map entries have already been taken |
| 59591 | | - ** care of. */ |
| 59592 | | - for(i=0; i<nNew; i++){ |
| 59593 | | - u32 key = get4byte(&apNew[i]->aData[8]); |
| 59594 | | - ptrmapPut(pBt, key, PTRMAP_BTREE, apNew[i]->pgno, &rc); |
| 59595 | | - } |
| 59596 | | - } |
| 59597 | | - |
| 59598 | | - assert( pParent->isInit ); |
| 59599 | | - TRACE(("BALANCE: finished: old=%d new=%d cells=%d\n", |
| 59600 | | - nOld, nNew, nCell)); |
| 59601 | | - |
| 59602 | | - /* Free any old pages that were not reused as new pages. |
| 59603 | | - */ |
| 59604 | | - for(i=nNew; i<nOld; i++){ |
| 59605 | | - freePage(apOld[i], &rc); |
| 59606 | | - } |
| 58972 | + }else if( ISAUTOVACUUM ){ |
| 58973 | + /* Fix the pointer-map entries for all the cells that were shifted around. |
| 58974 | + ** There are several different types of pointer-map entries that need to |
| 58975 | + ** be dealt with by this routine. Some of these have been set already, but |
| 58976 | + ** many have not. The following is a summary: |
| 58977 | + ** |
| 58978 | + ** 1) The entries associated with new sibling pages that were not |
| 58979 | + ** siblings when this function was called. These have already |
| 58980 | + ** been set. We don't need to worry about old siblings that were |
| 58981 | + ** moved to the free-list - the freePage() code has taken care |
| 58982 | + ** of those. |
| 58983 | + ** |
| 58984 | + ** 2) The pointer-map entries associated with the first overflow |
| 58985 | + ** page in any overflow chains used by new divider cells. These |
| 58986 | + ** have also already been taken care of by the insertCell() code. |
| 58987 | + ** |
| 58988 | + ** 3) If the sibling pages are not leaves, then the child pages of |
| 58989 | + ** cells stored on the sibling pages may need to be updated. |
| 58990 | + ** |
| 58991 | + ** 4) If the sibling pages are not internal intkey nodes, then any |
| 58992 | + ** overflow pages used by these cells may need to be updated |
| 58993 | + ** (internal intkey nodes never contain pointers to overflow pages). |
| 58994 | + ** |
| 58995 | + ** 5) If the sibling pages are not leaves, then the pointer-map |
| 58996 | + ** entries for the right-child pages of each sibling may need |
| 58997 | + ** to be updated. |
| 58998 | + ** |
| 58999 | + ** Cases 1 and 2 are dealt with above by other code. The next |
| 59000 | + ** block deals with cases 3 and 4 and the one after that, case 5. Since |
| 59001 | + ** setting a pointer map entry is a relatively expensive operation, this |
| 59002 | + ** code only sets pointer map entries for child or overflow pages that have |
| 59003 | + ** actually moved between pages. */ |
| 59004 | + MemPage *pNew = apNew[0]; |
| 59005 | + MemPage *pOld = apCopy[0]; |
| 59006 | + int nOverflow = pOld->nOverflow; |
| 59007 | + int iNextOld = pOld->nCell + nOverflow; |
| 59008 | + int iOverflow = (nOverflow ? pOld->aiOvfl[0] : -1); |
| 59009 | + j = 0; /* Current 'old' sibling page */ |
| 59010 | + k = 0; /* Current 'new' sibling page */ |
| 59011 | + for(i=0; i<nCell; i++){ |
| 59012 | + int isDivider = 0; |
| 59013 | + while( i==iNextOld ){ |
| 59014 | + /* Cell i is the cell immediately following the last cell on old |
| 59015 | + ** sibling page j. If the siblings are not leaf pages of an |
| 59016 | + ** intkey b-tree, then cell i was a divider cell. */ |
| 59017 | + assert( j+1 < ArraySize(apCopy) ); |
| 59018 | + assert( j+1 < nOld ); |
| 59019 | + pOld = apCopy[++j]; |
| 59020 | + iNextOld = i + !leafData + pOld->nCell + pOld->nOverflow; |
| 59021 | + if( pOld->nOverflow ){ |
| 59022 | + nOverflow = pOld->nOverflow; |
| 59023 | + iOverflow = i + !leafData + pOld->aiOvfl[0]; |
| 59024 | + } |
| 59025 | + isDivider = !leafData; |
| 59026 | + } |
| 59027 | + |
| 59028 | + assert(nOverflow>0 || iOverflow<i ); |
| 59029 | + assert(nOverflow<2 || pOld->aiOvfl[0]==pOld->aiOvfl[1]-1); |
| 59030 | + assert(nOverflow<3 || pOld->aiOvfl[1]==pOld->aiOvfl[2]-1); |
| 59031 | + if( i==iOverflow ){ |
| 59032 | + isDivider = 1; |
| 59033 | + if( (--nOverflow)>0 ){ |
| 59034 | + iOverflow++; |
| 59035 | + } |
| 59036 | + } |
| 59037 | + |
| 59038 | + if( i==cntNew[k] ){ |
| 59039 | + /* Cell i is the cell immediately following the last cell on new |
| 59040 | + ** sibling page k. If the siblings are not leaf pages of an |
| 59041 | + ** intkey b-tree, then cell i is a divider cell. */ |
| 59042 | + pNew = apNew[++k]; |
| 59043 | + if( !leafData ) continue; |
| 59044 | + } |
| 59045 | + assert( j<nOld ); |
| 59046 | + assert( k<nNew ); |
| 59047 | + |
| 59048 | + /* If the cell was originally divider cell (and is not now) or |
| 59049 | + ** an overflow cell, or if the cell was located on a different sibling |
| 59050 | + ** page before the balancing, then the pointer map entries associated |
| 59051 | + ** with any child or overflow pages need to be updated. */ |
| 59052 | + if( isDivider || pOld->pgno!=pNew->pgno ){ |
| 59053 | + if( !leafCorrection ){ |
| 59054 | + ptrmapPut(pBt, get4byte(apCell[i]), PTRMAP_BTREE, pNew->pgno, &rc); |
| 59055 | + } |
| 59056 | + if( szCell[i]>pNew->minLocal ){ |
| 59057 | + ptrmapPutOvflPtr(pNew, apCell[i], &rc); |
| 59058 | + } |
| 59059 | + } |
| 59060 | + } |
| 59061 | + |
| 59062 | + if( !leafCorrection ){ |
| 59063 | + for(i=0; i<nNew; i++){ |
| 59064 | + u32 key = get4byte(&apNew[i]->aData[8]); |
| 59065 | + ptrmapPut(pBt, key, PTRMAP_BTREE, apNew[i]->pgno, &rc); |
| 59066 | + } |
| 59067 | + } |
| 59607 | 59068 | |
| 59608 | 59069 | #if 0 |
| 59609 | | - if( ISAUTOVACUUM && rc==SQLITE_OK && apNew[0]->isInit ){ |
| 59610 | 59070 | /* The ptrmapCheckPages() contains assert() statements that verify that |
| 59611 | 59071 | ** all pointer map pages are set correctly. This is helpful while |
| 59612 | 59072 | ** debugging. This is usually disabled because a corrupt database may |
| 59613 | 59073 | ** cause an assert() statement to fail. */ |
| 59614 | 59074 | ptrmapCheckPages(apNew, nNew); |
| 59615 | 59075 | ptrmapCheckPages(&pParent, 1); |
| 59076 | +#endif |
| 59616 | 59077 | } |
| 59617 | | -#endif |
| 59078 | + |
| 59079 | + assert( pParent->isInit ); |
| 59080 | + TRACE(("BALANCE: finished: old=%d new=%d cells=%d\n", |
| 59081 | + nOld, nNew, nCell)); |
| 59618 | 59082 | |
| 59619 | 59083 | /* |
| 59620 | 59084 | ** Cleanup before returning. |
| 59621 | 59085 | */ |
| 59622 | 59086 | balance_cleanup: |
| | @@ -61438,15 +60902,10 @@ |
| 61438 | 60902 | */ |
| 61439 | 60903 | SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *p){ |
| 61440 | 60904 | return (p->pBt->btsFlags & BTS_READ_ONLY)!=0; |
| 61441 | 60905 | } |
| 61442 | 60906 | |
| 61443 | | -/* |
| 61444 | | -** Return the size of the header added to each page by this module. |
| 61445 | | -*/ |
| 61446 | | -SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void){ return sizeof(MemPage); } |
| 61447 | | - |
| 61448 | 60907 | /************** End of btree.c ***********************************************/ |
| 61449 | 60908 | /************** Begin file backup.c ******************************************/ |
| 61450 | 60909 | /* |
| 61451 | 60910 | ** 2009 January 28 |
| 61452 | 60911 | ** |
| | @@ -61583,17 +61042,10 @@ |
| 61583 | 61042 | sqlite3* pSrcDb, /* Database connection to read from */ |
| 61584 | 61043 | const char *zSrcDb /* Name of database within pSrcDb */ |
| 61585 | 61044 | ){ |
| 61586 | 61045 | sqlite3_backup *p; /* Value to return */ |
| 61587 | 61046 | |
| 61588 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 61589 | | - if( !sqlite3SafetyCheckOk(pSrcDb)||!sqlite3SafetyCheckOk(pDestDb) ){ |
| 61590 | | - (void)SQLITE_MISUSE_BKPT; |
| 61591 | | - return 0; |
| 61592 | | - } |
| 61593 | | -#endif |
| 61594 | | - |
| 61595 | 61047 | /* Lock the source database handle. The destination database |
| 61596 | 61048 | ** handle is not locked in this routine, but it is locked in |
| 61597 | 61049 | ** sqlite3_backup_step(). The user is required to ensure that no |
| 61598 | 61050 | ** other thread accesses the destination handle for the duration |
| 61599 | 61051 | ** of the backup operation. Any attempt to use the destination |
| | @@ -61786,13 +61238,10 @@ |
| 61786 | 61238 | int rc; |
| 61787 | 61239 | int destMode; /* Destination journal mode */ |
| 61788 | 61240 | int pgszSrc = 0; /* Source page size */ |
| 61789 | 61241 | int pgszDest = 0; /* Destination page size */ |
| 61790 | 61242 | |
| 61791 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 61792 | | - if( p==0 ) return SQLITE_MISUSE_BKPT; |
| 61793 | | -#endif |
| 61794 | 61243 | sqlite3_mutex_enter(p->pSrcDb->mutex); |
| 61795 | 61244 | sqlite3BtreeEnter(p->pSrc); |
| 61796 | 61245 | if( p->pDestDb ){ |
| 61797 | 61246 | sqlite3_mutex_enter(p->pDestDb->mutex); |
| 61798 | 61247 | } |
| | @@ -62078,30 +61527,18 @@ |
| 62078 | 61527 | /* |
| 62079 | 61528 | ** Return the number of pages still to be backed up as of the most recent |
| 62080 | 61529 | ** call to sqlite3_backup_step(). |
| 62081 | 61530 | */ |
| 62082 | 61531 | SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p){ |
| 62083 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 62084 | | - if( p==0 ){ |
| 62085 | | - (void)SQLITE_MISUSE_BKPT; |
| 62086 | | - return 0; |
| 62087 | | - } |
| 62088 | | -#endif |
| 62089 | 61532 | return p->nRemaining; |
| 62090 | 61533 | } |
| 62091 | 61534 | |
| 62092 | 61535 | /* |
| 62093 | 61536 | ** Return the total number of pages in the source database as of the most |
| 62094 | 61537 | ** recent call to sqlite3_backup_step(). |
| 62095 | 61538 | */ |
| 62096 | 61539 | SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p){ |
| 62097 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 62098 | | - if( p==0 ){ |
| 62099 | | - (void)SQLITE_MISUSE_BKPT; |
| 62100 | | - return 0; |
| 62101 | | - } |
| 62102 | | -#endif |
| 62103 | 61540 | return p->nPagecount; |
| 62104 | 61541 | } |
| 62105 | 61542 | |
| 62106 | 61543 | /* |
| 62107 | 61544 | ** This function is called after the contents of page iPage of the |
| | @@ -64388,38 +63825,10 @@ |
| 64388 | 63825 | } |
| 64389 | 63826 | p->nOp += nOp; |
| 64390 | 63827 | } |
| 64391 | 63828 | return addr; |
| 64392 | 63829 | } |
| 64393 | | - |
| 64394 | | -#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) |
| 64395 | | -/* |
| 64396 | | -** Add an entry to the array of counters managed by sqlite3_stmt_scanstatus(). |
| 64397 | | -*/ |
| 64398 | | -SQLITE_PRIVATE void sqlite3VdbeScanStatus( |
| 64399 | | - Vdbe *p, /* VM to add scanstatus() to */ |
| 64400 | | - int addrExplain, /* Address of OP_Explain (or 0) */ |
| 64401 | | - int addrLoop, /* Address of loop counter */ |
| 64402 | | - int addrVisit, /* Address of rows visited counter */ |
| 64403 | | - LogEst nEst, /* Estimated number of output rows */ |
| 64404 | | - const char *zName /* Name of table or index being scanned */ |
| 64405 | | -){ |
| 64406 | | - int nByte = (p->nScan+1) * sizeof(ScanStatus); |
| 64407 | | - ScanStatus *aNew; |
| 64408 | | - aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte); |
| 64409 | | - if( aNew ){ |
| 64410 | | - ScanStatus *pNew = &aNew[p->nScan++]; |
| 64411 | | - pNew->addrExplain = addrExplain; |
| 64412 | | - pNew->addrLoop = addrLoop; |
| 64413 | | - pNew->addrVisit = addrVisit; |
| 64414 | | - pNew->nEst = nEst; |
| 64415 | | - pNew->zName = sqlite3DbStrDup(p->db, zName); |
| 64416 | | - p->aScan = aNew; |
| 64417 | | - } |
| 64418 | | -} |
| 64419 | | -#endif |
| 64420 | | - |
| 64421 | 63830 | |
| 64422 | 63831 | /* |
| 64423 | 63832 | ** Change the value of the P1 operand for a specific instruction. |
| 64424 | 63833 | ** This routine is useful when a large program is loaded from a |
| 64425 | 63834 | ** static array using sqlite3VdbeAddOpList but we want to make a |
| | @@ -65515,13 +64924,10 @@ |
| 65515 | 64924 | p->apArg = allocSpace(p->apArg, nArg*sizeof(Mem*), &zCsr, zEnd, &nByte); |
| 65516 | 64925 | p->azVar = allocSpace(p->azVar, nVar*sizeof(char*), &zCsr, zEnd, &nByte); |
| 65517 | 64926 | p->apCsr = allocSpace(p->apCsr, nCursor*sizeof(VdbeCursor*), |
| 65518 | 64927 | &zCsr, zEnd, &nByte); |
| 65519 | 64928 | p->aOnceFlag = allocSpace(p->aOnceFlag, nOnce, &zCsr, zEnd, &nByte); |
| 65520 | | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 65521 | | - p->anExec = allocSpace(p->anExec, p->nOp*sizeof(i64), &zCsr, zEnd, &nByte); |
| 65522 | | -#endif |
| 65523 | 64929 | if( nByte ){ |
| 65524 | 64930 | p->pFree = sqlite3DbMallocZero(db, nByte); |
| 65525 | 64931 | } |
| 65526 | 64932 | zCsr = p->pFree; |
| 65527 | 64933 | zEnd = &zCsr[nByte]; |
| | @@ -65585,13 +64991,10 @@ |
| 65585 | 64991 | ** is used, for example, when a trigger sub-program is halted to restore |
| 65586 | 64992 | ** control to the main program. |
| 65587 | 64993 | */ |
| 65588 | 64994 | SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){ |
| 65589 | 64995 | Vdbe *v = pFrame->v; |
| 65590 | | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 65591 | | - v->anExec = pFrame->anExec; |
| 65592 | | -#endif |
| 65593 | 64996 | v->aOnceFlag = pFrame->aOnceFlag; |
| 65594 | 64997 | v->nOnceFlag = pFrame->nOnceFlag; |
| 65595 | 64998 | v->aOp = pFrame->aOp; |
| 65596 | 64999 | v->nOp = pFrame->nOp; |
| 65597 | 65000 | v->aMem = pFrame->aMem; |
| | @@ -65598,11 +65001,10 @@ |
| 65598 | 65001 | v->nMem = pFrame->nMem; |
| 65599 | 65002 | v->apCsr = pFrame->apCsr; |
| 65600 | 65003 | v->nCursor = pFrame->nCursor; |
| 65601 | 65004 | v->db->lastRowid = pFrame->lastRowid; |
| 65602 | 65005 | v->nChange = pFrame->nChange; |
| 65603 | | - v->db->nChange = pFrame->nDbChange; |
| 65604 | 65006 | return pFrame->pc; |
| 65605 | 65007 | } |
| 65606 | 65008 | |
| 65607 | 65009 | /* |
| 65608 | 65010 | ** Close all cursors. |
| | @@ -66166,11 +65568,10 @@ |
| 66166 | 65568 | ** so, abort any other statements this handle currently has active. |
| 66167 | 65569 | */ |
| 66168 | 65570 | sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); |
| 66169 | 65571 | sqlite3CloseSavepoints(db); |
| 66170 | 65572 | db->autoCommit = 1; |
| 66171 | | - p->nChange = 0; |
| 66172 | 65573 | } |
| 66173 | 65574 | } |
| 66174 | 65575 | } |
| 66175 | 65576 | |
| 66176 | 65577 | /* Check for immediate foreign key violations. */ |
| | @@ -66207,20 +65608,18 @@ |
| 66207 | 65608 | sqlite3VdbeLeave(p); |
| 66208 | 65609 | return SQLITE_BUSY; |
| 66209 | 65610 | }else if( rc!=SQLITE_OK ){ |
| 66210 | 65611 | p->rc = rc; |
| 66211 | 65612 | sqlite3RollbackAll(db, SQLITE_OK); |
| 66212 | | - p->nChange = 0; |
| 66213 | 65613 | }else{ |
| 66214 | 65614 | db->nDeferredCons = 0; |
| 66215 | 65615 | db->nDeferredImmCons = 0; |
| 66216 | 65616 | db->flags &= ~SQLITE_DeferFKs; |
| 66217 | 65617 | sqlite3CommitInternalChanges(db); |
| 66218 | 65618 | } |
| 66219 | 65619 | }else{ |
| 66220 | 65620 | sqlite3RollbackAll(db, SQLITE_OK); |
| 66221 | | - p->nChange = 0; |
| 66222 | 65621 | } |
| 66223 | 65622 | db->nStatement = 0; |
| 66224 | 65623 | }else if( eStatementOp==0 ){ |
| 66225 | 65624 | if( p->rc==SQLITE_OK || p->errorAction==OE_Fail ){ |
| 66226 | 65625 | eStatementOp = SAVEPOINT_RELEASE; |
| | @@ -66228,11 +65627,10 @@ |
| 66228 | 65627 | eStatementOp = SAVEPOINT_ROLLBACK; |
| 66229 | 65628 | }else{ |
| 66230 | 65629 | sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); |
| 66231 | 65630 | sqlite3CloseSavepoints(db); |
| 66232 | 65631 | db->autoCommit = 1; |
| 66233 | | - p->nChange = 0; |
| 66234 | 65632 | } |
| 66235 | 65633 | } |
| 66236 | 65634 | |
| 66237 | 65635 | /* If eStatementOp is non-zero, then a statement transaction needs to |
| 66238 | 65636 | ** be committed or rolled back. Call sqlite3VdbeCloseStatement() to |
| | @@ -66249,11 +65647,10 @@ |
| 66249 | 65647 | p->zErrMsg = 0; |
| 66250 | 65648 | } |
| 66251 | 65649 | sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); |
| 66252 | 65650 | sqlite3CloseSavepoints(db); |
| 66253 | 65651 | db->autoCommit = 1; |
| 66254 | | - p->nChange = 0; |
| 66255 | 65652 | } |
| 66256 | 65653 | } |
| 66257 | 65654 | |
| 66258 | 65655 | /* If this was an INSERT, UPDATE or DELETE and no statement transaction |
| 66259 | 65656 | ** has been rolled back, update the database connection change-counter. |
| | @@ -66511,16 +65908,10 @@ |
| 66511 | 65908 | for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]); |
| 66512 | 65909 | vdbeFreeOpArray(db, p->aOp, p->nOp); |
| 66513 | 65910 | sqlite3DbFree(db, p->aColName); |
| 66514 | 65911 | sqlite3DbFree(db, p->zSql); |
| 66515 | 65912 | sqlite3DbFree(db, p->pFree); |
| 66516 | | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 66517 | | - for(i=0; i<p->nScan; i++){ |
| 66518 | | - sqlite3DbFree(db, p->aScan[i].zName); |
| 66519 | | - } |
| 66520 | | - sqlite3DbFree(db, p->aScan); |
| 66521 | | -#endif |
| 66522 | 65913 | } |
| 66523 | 65914 | |
| 66524 | 65915 | /* |
| 66525 | 65916 | ** Delete an entire VDBE. |
| 66526 | 65917 | */ |
| | @@ -68884,23 +68275,15 @@ |
| 68884 | 68275 | sqlite3_stmt *pStmt, |
| 68885 | 68276 | int N, |
| 68886 | 68277 | const void *(*xFunc)(Mem*), |
| 68887 | 68278 | int useType |
| 68888 | 68279 | ){ |
| 68889 | | - const void *ret; |
| 68890 | | - Vdbe *p; |
| 68280 | + const void *ret = 0; |
| 68281 | + Vdbe *p = (Vdbe *)pStmt; |
| 68891 | 68282 | int n; |
| 68892 | | - sqlite3 *db; |
| 68893 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 68894 | | - if( pStmt==0 ){ |
| 68895 | | - (void)SQLITE_MISUSE_BKPT; |
| 68896 | | - return 0; |
| 68897 | | - } |
| 68898 | | -#endif |
| 68899 | | - ret = 0; |
| 68900 | | - p = (Vdbe *)pStmt; |
| 68901 | | - db = p->db; |
| 68283 | + sqlite3 *db = p->db; |
| 68284 | + |
| 68902 | 68285 | assert( db!=0 ); |
| 68903 | 68286 | n = sqlite3_column_count(pStmt); |
| 68904 | 68287 | if( N<n && N>=0 ){ |
| 68905 | 68288 | N += useType*n; |
| 68906 | 68289 | sqlite3_mutex_enter(db->mutex); |
| | @@ -69361,16 +68744,10 @@ |
| 69361 | 68744 | ** prepared statement for the database connection. Return NULL if there |
| 69362 | 68745 | ** are no more. |
| 69363 | 68746 | */ |
| 69364 | 68747 | SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt){ |
| 69365 | 68748 | sqlite3_stmt *pNext; |
| 69366 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 69367 | | - if( !sqlite3SafetyCheckOk(pDb) ){ |
| 69368 | | - (void)SQLITE_MISUSE_BKPT; |
| 69369 | | - return 0; |
| 69370 | | - } |
| 69371 | | -#endif |
| 69372 | 68749 | sqlite3_mutex_enter(pDb->mutex); |
| 69373 | 68750 | if( pStmt==0 ){ |
| 69374 | 68751 | pNext = (sqlite3_stmt*)pDb->pVdbe; |
| 69375 | 68752 | }else{ |
| 69376 | 68753 | pNext = (sqlite3_stmt*)((Vdbe*)pStmt)->pNext; |
| | @@ -69382,91 +68759,15 @@ |
| 69382 | 68759 | /* |
| 69383 | 68760 | ** Return the value of a status counter for a prepared statement |
| 69384 | 68761 | */ |
| 69385 | 68762 | SQLITE_API int sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){ |
| 69386 | 68763 | Vdbe *pVdbe = (Vdbe*)pStmt; |
| 69387 | | - u32 v; |
| 69388 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 69389 | | - if( !pStmt ){ |
| 69390 | | - (void)SQLITE_MISUSE_BKPT; |
| 69391 | | - return 0; |
| 69392 | | - } |
| 69393 | | -#endif |
| 69394 | | - v = pVdbe->aCounter[op]; |
| 68764 | + u32 v = pVdbe->aCounter[op]; |
| 69395 | 68765 | if( resetFlag ) pVdbe->aCounter[op] = 0; |
| 69396 | 68766 | return (int)v; |
| 69397 | 68767 | } |
| 69398 | 68768 | |
| 69399 | | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 69400 | | -/* |
| 69401 | | -** Return status data for a single loop within query pStmt. |
| 69402 | | -*/ |
| 69403 | | -SQLITE_API int sqlite3_stmt_scanstatus( |
| 69404 | | - sqlite3_stmt *pStmt, /* Prepared statement being queried */ |
| 69405 | | - int idx, /* Index of loop to report on */ |
| 69406 | | - int iScanStatusOp, /* Which metric to return */ |
| 69407 | | - void *pOut /* OUT: Write the answer here */ |
| 69408 | | -){ |
| 69409 | | - Vdbe *p = (Vdbe*)pStmt; |
| 69410 | | - ScanStatus *pScan; |
| 69411 | | - if( idx<0 || idx>=p->nScan ) return 1; |
| 69412 | | - pScan = &p->aScan[idx]; |
| 69413 | | - switch( iScanStatusOp ){ |
| 69414 | | - case SQLITE_SCANSTAT_NLOOP: { |
| 69415 | | - *(sqlite3_int64*)pOut = p->anExec[pScan->addrLoop]; |
| 69416 | | - break; |
| 69417 | | - } |
| 69418 | | - case SQLITE_SCANSTAT_NVISIT: { |
| 69419 | | - *(sqlite3_int64*)pOut = p->anExec[pScan->addrVisit]; |
| 69420 | | - break; |
| 69421 | | - } |
| 69422 | | - case SQLITE_SCANSTAT_EST: { |
| 69423 | | - double r = 1.0; |
| 69424 | | - LogEst x = pScan->nEst; |
| 69425 | | - while( x<100 ){ |
| 69426 | | - x += 10; |
| 69427 | | - r *= 0.5; |
| 69428 | | - } |
| 69429 | | - *(double*)pOut = r*sqlite3LogEstToInt(x); |
| 69430 | | - break; |
| 69431 | | - } |
| 69432 | | - case SQLITE_SCANSTAT_NAME: { |
| 69433 | | - *(const char**)pOut = pScan->zName; |
| 69434 | | - break; |
| 69435 | | - } |
| 69436 | | - case SQLITE_SCANSTAT_EXPLAIN: { |
| 69437 | | - if( pScan->addrExplain ){ |
| 69438 | | - *(const char**)pOut = p->aOp[ pScan->addrExplain ].p4.z; |
| 69439 | | - }else{ |
| 69440 | | - *(const char**)pOut = 0; |
| 69441 | | - } |
| 69442 | | - break; |
| 69443 | | - } |
| 69444 | | - case SQLITE_SCANSTAT_SELECTID: { |
| 69445 | | - if( pScan->addrExplain ){ |
| 69446 | | - *(int*)pOut = p->aOp[ pScan->addrExplain ].p1; |
| 69447 | | - }else{ |
| 69448 | | - *(int*)pOut = -1; |
| 69449 | | - } |
| 69450 | | - break; |
| 69451 | | - } |
| 69452 | | - default: { |
| 69453 | | - return 1; |
| 69454 | | - } |
| 69455 | | - } |
| 69456 | | - return 0; |
| 69457 | | -} |
| 69458 | | - |
| 69459 | | -/* |
| 69460 | | -** Zero all counters associated with the sqlite3_stmt_scanstatus() data. |
| 69461 | | -*/ |
| 69462 | | -SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt *pStmt){ |
| 69463 | | - Vdbe *p = (Vdbe*)pStmt; |
| 69464 | | - memset(p->anExec, 0, p->nOp * sizeof(i64)); |
| 69465 | | -} |
| 69466 | | -#endif /* SQLITE_ENABLE_STMT_SCANSTATUS */ |
| 69467 | | - |
| 69468 | 68769 | /************** End of vdbeapi.c *********************************************/ |
| 69469 | 68770 | /************** Begin file vdbetrace.c ***************************************/ |
| 69470 | 68771 | /* |
| 69471 | 68772 | ** 2009 November 25 |
| 69472 | 68773 | ** |
| | @@ -70348,13 +69649,10 @@ |
| 70348 | 69649 | #ifdef VDBE_PROFILE |
| 70349 | 69650 | start = sqlite3Hwtime(); |
| 70350 | 69651 | #endif |
| 70351 | 69652 | nVmStep++; |
| 70352 | 69653 | pOp = &aOp[pc]; |
| 70353 | | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 70354 | | - if( p->anExec ) p->anExec[pc]++; |
| 70355 | | -#endif |
| 70356 | 69654 | |
| 70357 | 69655 | /* Only allow tracing if SQLITE_DEBUG is defined. |
| 70358 | 69656 | */ |
| 70359 | 69657 | #ifdef SQLITE_DEBUG |
| 70360 | 69658 | if( db->flags & SQLITE_VdbeTrace ){ |
| | @@ -72570,12 +71868,14 @@ |
| 72570 | 71868 | int isSchemaChange; |
| 72571 | 71869 | iSavepoint = db->nSavepoint - iSavepoint - 1; |
| 72572 | 71870 | if( p1==SAVEPOINT_ROLLBACK ){ |
| 72573 | 71871 | isSchemaChange = (db->flags & SQLITE_InternChanges)!=0; |
| 72574 | 71872 | for(ii=0; ii<db->nDb; ii++){ |
| 72575 | | - sqlite3BtreeTripAllCursors(db->aDb[ii].pBt, SQLITE_ABORT, |
| 71873 | + rc = sqlite3BtreeTripAllCursors(db->aDb[ii].pBt, |
| 71874 | + SQLITE_ABORT_ROLLBACK, |
| 72576 | 71875 | isSchemaChange==0); |
| 71876 | + if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 72577 | 71877 | } |
| 72578 | 71878 | }else{ |
| 72579 | 71879 | isSchemaChange = 0; |
| 72580 | 71880 | } |
| 72581 | 71881 | for(ii=0; ii<db->nDb; ii++){ |
| | @@ -73543,15 +72843,14 @@ |
| 73543 | 72843 | } |
| 73544 | 72844 | pIdxKey = &r; |
| 73545 | 72845 | }else{ |
| 73546 | 72846 | pIdxKey = sqlite3VdbeAllocUnpackedRecord( |
| 73547 | 72847 | pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree |
| 73548 | | - ); |
| 72848 | + ); |
| 73549 | 72849 | if( pIdxKey==0 ) goto no_mem; |
| 73550 | 72850 | assert( pIn3->flags & MEM_Blob ); |
| 73551 | | - /* assert( (pIn3->flags & MEM_Zero)==0 ); // zeroblobs already expanded */ |
| 73552 | | - ExpandBlob(pIn3); |
| 72851 | + assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */ |
| 73553 | 72852 | sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey); |
| 73554 | 72853 | } |
| 73555 | 72854 | pIdxKey->default_rc = 0; |
| 73556 | 72855 | if( pOp->opcode==OP_NoConflict ){ |
| 73557 | 72856 | /* For the OP_NoConflict opcode, take the jump if any of the |
| | @@ -74147,10 +73446,14 @@ |
| 74147 | 73446 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 74148 | 73447 | }else{ |
| 74149 | 73448 | assert( pC->pCursor!=0 ); |
| 74150 | 73449 | rc = sqlite3VdbeCursorRestore(pC); |
| 74151 | 73450 | if( rc ) goto abort_due_to_error; |
| 73451 | + if( pC->nullRow ){ |
| 73452 | + pOut->flags = MEM_Null; |
| 73453 | + break; |
| 73454 | + } |
| 74152 | 73455 | rc = sqlite3BtreeKeySize(pC->pCursor, &v); |
| 74153 | 73456 | assert( rc==SQLITE_OK ); /* Always so because of CursorRestore() above */ |
| 74154 | 73457 | } |
| 74155 | 73458 | pOut->u.i = v; |
| 74156 | 73459 | break; |
| | @@ -74237,13 +73540,13 @@ |
| 74237 | 73540 | } |
| 74238 | 73541 | /* Opcode: Rewind P1 P2 * * * |
| 74239 | 73542 | ** |
| 74240 | 73543 | ** The next use of the Rowid or Column or Next instruction for P1 |
| 74241 | 73544 | ** will refer to the first entry in the database table or index. |
| 74242 | | -** If the table or index is empty, jump immediately to P2. |
| 74243 | | -** If the table or index is not empty, fall through to the following |
| 74244 | | -** instruction. |
| 73545 | +** If the table or index is empty and P2>0, then jump immediately to P2. |
| 73546 | +** If P2 is 0 or if the table or index is not empty, fall through |
| 73547 | +** to the following instruction. |
| 74245 | 73548 | ** |
| 74246 | 73549 | ** This opcode leaves the cursor configured to move in forward order, |
| 74247 | 73550 | ** from the beginning toward the end. In other words, the cursor is |
| 74248 | 73551 | ** configured to use Next, not Prev. |
| 74249 | 73552 | */ |
| | @@ -75155,13 +74458,10 @@ |
| 75155 | 74458 | pFrame->aOp = p->aOp; |
| 75156 | 74459 | pFrame->nOp = p->nOp; |
| 75157 | 74460 | pFrame->token = pProgram->token; |
| 75158 | 74461 | pFrame->aOnceFlag = p->aOnceFlag; |
| 75159 | 74462 | pFrame->nOnceFlag = p->nOnceFlag; |
| 75160 | | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 75161 | | - pFrame->anExec = p->anExec; |
| 75162 | | -#endif |
| 75163 | 74463 | |
| 75164 | 74464 | pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem]; |
| 75165 | 74465 | for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){ |
| 75166 | 74466 | pMem->flags = MEM_Undefined; |
| 75167 | 74467 | pMem->db = db; |
| | @@ -75175,11 +74475,10 @@ |
| 75175 | 74475 | |
| 75176 | 74476 | p->nFrame++; |
| 75177 | 74477 | pFrame->pParent = p->pFrame; |
| 75178 | 74478 | pFrame->lastRowid = lastRowid; |
| 75179 | 74479 | pFrame->nChange = p->nChange; |
| 75180 | | - pFrame->nDbChange = p->db->nChange; |
| 75181 | 74480 | p->nChange = 0; |
| 75182 | 74481 | p->pFrame = pFrame; |
| 75183 | 74482 | p->aMem = aMem = &VdbeFrameMem(pFrame)[-1]; |
| 75184 | 74483 | p->nMem = pFrame->nChildMem; |
| 75185 | 74484 | p->nCursor = (u16)pFrame->nChildCsr; |
| | @@ -75186,13 +74485,10 @@ |
| 75186 | 74485 | p->apCsr = (VdbeCursor **)&aMem[p->nMem+1]; |
| 75187 | 74486 | p->aOp = aOp = pProgram->aOp; |
| 75188 | 74487 | p->nOp = pProgram->nOp; |
| 75189 | 74488 | p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor]; |
| 75190 | 74489 | p->nOnceFlag = pProgram->nOnce; |
| 75191 | | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 75192 | | - p->anExec = 0; |
| 75193 | | -#endif |
| 75194 | 74490 | pc = -1; |
| 75195 | 74491 | memset(p->aOnceFlag, 0, p->nOnceFlag); |
| 75196 | 74492 | |
| 75197 | 74493 | break; |
| 75198 | 74494 | } |
| | @@ -76377,15 +75673,10 @@ |
| 76377 | 75673 | char *zErr = 0; |
| 76378 | 75674 | Table *pTab; |
| 76379 | 75675 | Parse *pParse = 0; |
| 76380 | 75676 | Incrblob *pBlob = 0; |
| 76381 | 75677 | |
| 76382 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 76383 | | - if( !sqlite3SafetyCheckOk(db) || ppBlob==0 || zTable==0 ){ |
| 76384 | | - return SQLITE_MISUSE_BKPT; |
| 76385 | | - } |
| 76386 | | -#endif |
| 76387 | 75678 | flags = !!flags; /* flags = (flags ? 1 : 0); */ |
| 76388 | 75679 | *ppBlob = 0; |
| 76389 | 75680 | |
| 76390 | 75681 | sqlite3_mutex_enter(db->mutex); |
| 76391 | 75682 | |
| | @@ -76600,10 +75891,11 @@ |
| 76600 | 75891 | v = (Vdbe*)p->pStmt; |
| 76601 | 75892 | |
| 76602 | 75893 | if( n<0 || iOffset<0 || (iOffset+n)>p->nByte ){ |
| 76603 | 75894 | /* Request is out of range. Return a transient error. */ |
| 76604 | 75895 | rc = SQLITE_ERROR; |
| 75896 | + sqlite3Error(db, SQLITE_ERROR); |
| 76605 | 75897 | }else if( v==0 ){ |
| 76606 | 75898 | /* If there is no statement handle, then the blob-handle has |
| 76607 | 75899 | ** already been invalidated. Return SQLITE_ABORT in this case. |
| 76608 | 75900 | */ |
| 76609 | 75901 | rc = SQLITE_ABORT; |
| | @@ -76617,14 +75909,14 @@ |
| 76617 | 75909 | sqlite3BtreeLeaveCursor(p->pCsr); |
| 76618 | 75910 | if( rc==SQLITE_ABORT ){ |
| 76619 | 75911 | sqlite3VdbeFinalize(v); |
| 76620 | 75912 | p->pStmt = 0; |
| 76621 | 75913 | }else{ |
| 75914 | + db->errCode = rc; |
| 76622 | 75915 | v->rc = rc; |
| 76623 | 75916 | } |
| 76624 | 75917 | } |
| 76625 | | - sqlite3Error(db, rc); |
| 76626 | 75918 | rc = sqlite3ApiExit(db, rc); |
| 76627 | 75919 | sqlite3_mutex_leave(db->mutex); |
| 76628 | 75920 | return rc; |
| 76629 | 75921 | } |
| 76630 | 75922 | |
| | @@ -76797,11 +76089,11 @@ |
| 76797 | 76089 | ** itself. |
| 76798 | 76090 | ** |
| 76799 | 76091 | ** The sorter is running in multi-threaded mode if (a) the library was built |
| 76800 | 76092 | ** with pre-processor symbol SQLITE_MAX_WORKER_THREADS set to a value greater |
| 76801 | 76093 | ** than zero, and (b) worker threads have been enabled at runtime by calling |
| 76802 | | -** "PRAGMA threads=N" with some value of N greater than 0. |
| 76094 | +** sqlite3_config(SQLITE_CONFIG_WORKER_THREADS, ...). |
| 76803 | 76095 | ** |
| 76804 | 76096 | ** When Rewind() is called, any data remaining in memory is flushed to a |
| 76805 | 76097 | ** final PMA. So at this point the data is stored in some number of sorted |
| 76806 | 76098 | ** PMAs within temporary files on disk. |
| 76807 | 76099 | ** |
| | @@ -77542,13 +76834,15 @@ |
| 77542 | 76834 | pSorter->mnPmaSize = SORTER_MIN_WORKING * pgsz; |
| 77543 | 76835 | mxCache = db->aDb[0].pSchema->cache_size; |
| 77544 | 76836 | if( mxCache<SORTER_MIN_WORKING ) mxCache = SORTER_MIN_WORKING; |
| 77545 | 76837 | pSorter->mxPmaSize = mxCache * pgsz; |
| 77546 | 76838 | |
| 77547 | | - /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of |
| 77548 | | - ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary |
| 77549 | | - ** large heap allocations. |
| 76839 | + /* If the application has not configure scratch memory using |
| 76840 | + ** SQLITE_CONFIG_SCRATCH then we assume it is OK to do large memory |
| 76841 | + ** allocations. If scratch memory has been configured, then assume |
| 76842 | + ** large memory allocations should be avoided to prevent heap |
| 76843 | + ** fragmentation. |
| 77550 | 76844 | */ |
| 77551 | 76845 | if( sqlite3GlobalConfig.pScratch==0 ){ |
| 77552 | 76846 | assert( pSorter->iMemory==0 ); |
| 77553 | 76847 | pSorter->nMemory = pgsz; |
| 77554 | 76848 | pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz); |
| | @@ -79916,19 +79210,19 @@ |
| 79916 | 79210 | ** |
| 79917 | 79211 | ** incrAggFunctionDepth(pExpr,n) is the main routine. incrAggDepth(..) |
| 79918 | 79212 | ** is a helper function - a callback for the tree walker. |
| 79919 | 79213 | */ |
| 79920 | 79214 | static int incrAggDepth(Walker *pWalker, Expr *pExpr){ |
| 79921 | | - if( pExpr->op==TK_AGG_FUNCTION ) pExpr->op2 += pWalker->u.n; |
| 79215 | + if( pExpr->op==TK_AGG_FUNCTION ) pExpr->op2 += pWalker->u.i; |
| 79922 | 79216 | return WRC_Continue; |
| 79923 | 79217 | } |
| 79924 | 79218 | static void incrAggFunctionDepth(Expr *pExpr, int N){ |
| 79925 | 79219 | if( N>0 ){ |
| 79926 | 79220 | Walker w; |
| 79927 | 79221 | memset(&w, 0, sizeof(w)); |
| 79928 | 79222 | w.xExprCallback = incrAggDepth; |
| 79929 | | - w.u.n = N; |
| 79223 | + w.u.i = N; |
| 79930 | 79224 | sqlite3WalkExpr(&w, pExpr); |
| 79931 | 79225 | } |
| 79932 | 79226 | } |
| 79933 | 79227 | |
| 79934 | 79228 | /* |
| | @@ -80472,11 +79766,11 @@ |
| 80472 | 79766 | double r = -1.0; |
| 80473 | 79767 | if( p->op!=TK_FLOAT ) return -1; |
| 80474 | 79768 | sqlite3AtoF(p->u.zToken, &r, sqlite3Strlen30(p->u.zToken), SQLITE_UTF8); |
| 80475 | 79769 | assert( r>=0.0 ); |
| 80476 | 79770 | if( r>1.0 ) return -1; |
| 80477 | | - return (int)(r*134217728.0); |
| 79771 | + return (int)(r*1000.0); |
| 80478 | 79772 | } |
| 80479 | 79773 | |
| 80480 | 79774 | /* |
| 80481 | 79775 | ** This routine is callback for sqlite3WalkExpr(). |
| 80482 | 79776 | ** |
| | @@ -80604,11 +79898,11 @@ |
| 80604 | 79898 | ** EVIDENCE-OF: R-36850-34127 The likely(X) function is short-hand for |
| 80605 | 79899 | ** likelihood(X,0.9375). |
| 80606 | 79900 | ** EVIDENCE-OF: R-53436-40973 The likely(X) function is equivalent to |
| 80607 | 79901 | ** likelihood(X,0.9375). */ |
| 80608 | 79902 | /* TUNING: unlikely() probability is 0.0625. likely() is 0.9375 */ |
| 80609 | | - pExpr->iTable = pDef->zName[0]=='u' ? 8388608 : 125829120; |
| 79903 | + pExpr->iTable = pDef->zName[0]=='u' ? 62 : 938; |
| 80610 | 79904 | } |
| 80611 | 79905 | } |
| 80612 | 79906 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 80613 | 79907 | auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0); |
| 80614 | 79908 | if( auth!=SQLITE_OK ){ |
| | @@ -82561,79 +81855,69 @@ |
| 82561 | 81855 | sqlite3DbFree(db, pList->a); |
| 82562 | 81856 | sqlite3DbFree(db, pList); |
| 82563 | 81857 | } |
| 82564 | 81858 | |
| 82565 | 81859 | /* |
| 82566 | | -** These routines are Walker callbacks used to check expressions to |
| 82567 | | -** see if they are "constant" for some definition of constant. The |
| 82568 | | -** Walker.eCode value determines the type of "constant" we are looking |
| 82569 | | -** for. |
| 81860 | +** These routines are Walker callbacks. Walker.u.pi is a pointer |
| 81861 | +** to an integer. These routines are checking an expression to see |
| 81862 | +** if it is a constant. Set *Walker.u.i to 0 if the expression is |
| 81863 | +** not constant. |
| 82570 | 81864 | ** |
| 82571 | 81865 | ** These callback routines are used to implement the following: |
| 82572 | 81866 | ** |
| 82573 | | -** sqlite3ExprIsConstant() pWalker->eCode==1 |
| 82574 | | -** sqlite3ExprIsConstantNotJoin() pWalker->eCode==2 |
| 82575 | | -** sqlite3ExprRefOneTableOnly() pWalker->eCode==3 |
| 82576 | | -** sqlite3ExprIsConstantOrFunction() pWalker->eCode==4 or 5 |
| 82577 | | -** |
| 82578 | | -** In all cases, the callbacks set Walker.eCode=0 and abort if the expression |
| 82579 | | -** is found to not be a constant. |
| 81867 | +** sqlite3ExprIsConstant() pWalker->u.i==1 |
| 81868 | +** sqlite3ExprIsConstantNotJoin() pWalker->u.i==2 |
| 81869 | +** sqlite3ExprIsConstantOrFunction() pWalker->u.i==3 or 4 |
| 82580 | 81870 | ** |
| 82581 | 81871 | ** The sqlite3ExprIsConstantOrFunction() is used for evaluating expressions |
| 82582 | | -** in a CREATE TABLE statement. The Walker.eCode value is 5 when parsing |
| 82583 | | -** an existing schema and 4 when processing a new statement. A bound |
| 81872 | +** in a CREATE TABLE statement. The Walker.u.i value is 4 when parsing |
| 81873 | +** an existing schema and 3 when processing a new statement. A bound |
| 82584 | 81874 | ** parameter raises an error for new statements, but is silently converted |
| 82585 | 81875 | ** to NULL for existing schemas. This allows sqlite_master tables that |
| 82586 | 81876 | ** contain a bound parameter because they were generated by older versions |
| 82587 | 81877 | ** of SQLite to be parsed by newer versions of SQLite without raising a |
| 82588 | 81878 | ** malformed schema error. |
| 82589 | 81879 | */ |
| 82590 | 81880 | static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){ |
| 82591 | 81881 | |
| 82592 | | - /* If pWalker->eCode is 2 then any term of the expression that comes from |
| 82593 | | - ** the ON or USING clauses of a left join disqualifies the expression |
| 81882 | + /* If pWalker->u.i is 2 then any term of the expression that comes from |
| 81883 | + ** the ON or USING clauses of a join disqualifies the expression |
| 82594 | 81884 | ** from being considered constant. */ |
| 82595 | | - if( pWalker->eCode==2 && ExprHasProperty(pExpr, EP_FromJoin) ){ |
| 82596 | | - pWalker->eCode = 0; |
| 81885 | + if( pWalker->u.i==2 && ExprHasProperty(pExpr, EP_FromJoin) ){ |
| 81886 | + pWalker->u.i = 0; |
| 82597 | 81887 | return WRC_Abort; |
| 82598 | 81888 | } |
| 82599 | 81889 | |
| 82600 | 81890 | switch( pExpr->op ){ |
| 82601 | 81891 | /* Consider functions to be constant if all their arguments are constant |
| 82602 | | - ** and either pWalker->eCode==4 or 5 or the function has the |
| 82603 | | - ** SQLITE_FUNC_CONST flag. */ |
| 81892 | + ** and either pWalker->u.i==3 or 4 or the function as the SQLITE_FUNC_CONST |
| 81893 | + ** flag. */ |
| 82604 | 81894 | case TK_FUNCTION: |
| 82605 | | - if( pWalker->eCode>=4 || ExprHasProperty(pExpr,EP_Constant) ){ |
| 81895 | + if( pWalker->u.i>=3 || ExprHasProperty(pExpr,EP_Constant) ){ |
| 82606 | 81896 | return WRC_Continue; |
| 82607 | | - }else{ |
| 82608 | | - pWalker->eCode = 0; |
| 82609 | | - return WRC_Abort; |
| 82610 | 81897 | } |
| 81898 | + /* Fall through */ |
| 82611 | 81899 | case TK_ID: |
| 82612 | 81900 | case TK_COLUMN: |
| 82613 | 81901 | case TK_AGG_FUNCTION: |
| 82614 | 81902 | case TK_AGG_COLUMN: |
| 82615 | 81903 | testcase( pExpr->op==TK_ID ); |
| 82616 | 81904 | testcase( pExpr->op==TK_COLUMN ); |
| 82617 | 81905 | testcase( pExpr->op==TK_AGG_FUNCTION ); |
| 82618 | 81906 | testcase( pExpr->op==TK_AGG_COLUMN ); |
| 82619 | | - if( pWalker->eCode==3 && pExpr->iTable==pWalker->u.iCur ){ |
| 82620 | | - return WRC_Continue; |
| 82621 | | - }else{ |
| 82622 | | - pWalker->eCode = 0; |
| 82623 | | - return WRC_Abort; |
| 82624 | | - } |
| 81907 | + pWalker->u.i = 0; |
| 81908 | + return WRC_Abort; |
| 82625 | 81909 | case TK_VARIABLE: |
| 82626 | | - if( pWalker->eCode==5 ){ |
| 81910 | + if( pWalker->u.i==4 ){ |
| 82627 | 81911 | /* Silently convert bound parameters that appear inside of CREATE |
| 82628 | 81912 | ** statements into a NULL when parsing the CREATE statement text out |
| 82629 | 81913 | ** of the sqlite_master table */ |
| 82630 | 81914 | pExpr->op = TK_NULL; |
| 82631 | | - }else if( pWalker->eCode==4 ){ |
| 81915 | + }else if( pWalker->u.i==3 ){ |
| 82632 | 81916 | /* A bound parameter in a CREATE statement that originates from |
| 82633 | 81917 | ** sqlite3_prepare() causes an error */ |
| 82634 | | - pWalker->eCode = 0; |
| 81918 | + pWalker->u.i = 0; |
| 82635 | 81919 | return WRC_Abort; |
| 82636 | 81920 | } |
| 82637 | 81921 | /* Fall through */ |
| 82638 | 81922 | default: |
| 82639 | 81923 | testcase( pExpr->op==TK_SELECT ); /* selectNodeIsConstant will disallow */ |
| | @@ -82641,68 +81925,57 @@ |
| 82641 | 81925 | return WRC_Continue; |
| 82642 | 81926 | } |
| 82643 | 81927 | } |
| 82644 | 81928 | static int selectNodeIsConstant(Walker *pWalker, Select *NotUsed){ |
| 82645 | 81929 | UNUSED_PARAMETER(NotUsed); |
| 82646 | | - pWalker->eCode = 0; |
| 81930 | + pWalker->u.i = 0; |
| 82647 | 81931 | return WRC_Abort; |
| 82648 | 81932 | } |
| 82649 | | -static int exprIsConst(Expr *p, int initFlag, int iCur){ |
| 81933 | +static int exprIsConst(Expr *p, int initFlag){ |
| 82650 | 81934 | Walker w; |
| 82651 | 81935 | memset(&w, 0, sizeof(w)); |
| 82652 | | - w.eCode = initFlag; |
| 81936 | + w.u.i = initFlag; |
| 82653 | 81937 | w.xExprCallback = exprNodeIsConstant; |
| 82654 | 81938 | w.xSelectCallback = selectNodeIsConstant; |
| 82655 | | - w.u.iCur = iCur; |
| 82656 | 81939 | sqlite3WalkExpr(&w, p); |
| 82657 | | - return w.eCode; |
| 81940 | + return w.u.i; |
| 82658 | 81941 | } |
| 82659 | 81942 | |
| 82660 | 81943 | /* |
| 82661 | | -** Walk an expression tree. Return non-zero if the expression is constant |
| 81944 | +** Walk an expression tree. Return 1 if the expression is constant |
| 82662 | 81945 | ** and 0 if it involves variables or function calls. |
| 82663 | 81946 | ** |
| 82664 | 81947 | ** For the purposes of this function, a double-quoted string (ex: "abc") |
| 82665 | 81948 | ** is considered a variable but a single-quoted string (ex: 'abc') is |
| 82666 | 81949 | ** a constant. |
| 82667 | 81950 | */ |
| 82668 | 81951 | SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr *p){ |
| 82669 | | - return exprIsConst(p, 1, 0); |
| 81952 | + return exprIsConst(p, 1); |
| 82670 | 81953 | } |
| 82671 | 81954 | |
| 82672 | 81955 | /* |
| 82673 | | -** Walk an expression tree. Return non-zero if the expression is constant |
| 81956 | +** Walk an expression tree. Return 1 if the expression is constant |
| 82674 | 81957 | ** that does no originate from the ON or USING clauses of a join. |
| 82675 | 81958 | ** Return 0 if it involves variables or function calls or terms from |
| 82676 | 81959 | ** an ON or USING clause. |
| 82677 | 81960 | */ |
| 82678 | 81961 | SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr *p){ |
| 82679 | | - return exprIsConst(p, 2, 0); |
| 81962 | + return exprIsConst(p, 2); |
| 82680 | 81963 | } |
| 82681 | 81964 | |
| 82682 | 81965 | /* |
| 82683 | | -** Walk an expression tree. Return non-zero if the expression constant |
| 82684 | | -** for any single row of the table with cursor iCur. In other words, the |
| 82685 | | -** expression must not refer to any non-deterministic function nor any |
| 82686 | | -** table other than iCur. |
| 82687 | | -*/ |
| 82688 | | -SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){ |
| 82689 | | - return exprIsConst(p, 3, iCur); |
| 82690 | | -} |
| 82691 | | - |
| 82692 | | -/* |
| 82693 | | -** Walk an expression tree. Return non-zero if the expression is constant |
| 81966 | +** Walk an expression tree. Return 1 if the expression is constant |
| 82694 | 81967 | ** or a function call with constant arguments. Return and 0 if there |
| 82695 | 81968 | ** are any variables. |
| 82696 | 81969 | ** |
| 82697 | 81970 | ** For the purposes of this function, a double-quoted string (ex: "abc") |
| 82698 | 81971 | ** is considered a variable but a single-quoted string (ex: 'abc') is |
| 82699 | 81972 | ** a constant. |
| 82700 | 81973 | */ |
| 82701 | 81974 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr *p, u8 isInit){ |
| 82702 | 81975 | assert( isInit==0 || isInit==1 ); |
| 82703 | | - return exprIsConst(p, 4+isInit, 0); |
| 81976 | + return exprIsConst(p, 3+isInit); |
| 82704 | 81977 | } |
| 82705 | 81978 | |
| 82706 | 81979 | /* |
| 82707 | 81980 | ** If the expression p codes a constant integer that is small enough |
| 82708 | 81981 | ** to fit in a 32-bit integer, return 1 and put the value of the integer |
| | @@ -83208,11 +82481,10 @@ |
| 83208 | 82481 | sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable); |
| 83209 | 82482 | dest.affSdst = (u8)affinity; |
| 83210 | 82483 | assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable ); |
| 83211 | 82484 | pSelect->iLimit = 0; |
| 83212 | 82485 | testcase( pSelect->selFlags & SF_Distinct ); |
| 83213 | | - pSelect->selFlags &= ~SF_Distinct; |
| 83214 | 82486 | testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */ |
| 83215 | 82487 | if( sqlite3Select(pParse, pSelect, &dest) ){ |
| 83216 | 82488 | sqlite3KeyInfoUnref(pKeyInfo); |
| 83217 | 82489 | return 0; |
| 83218 | 82490 | } |
| | @@ -88149,11 +87421,10 @@ |
| 88149 | 87421 | nSample--; |
| 88150 | 87422 | }else{ |
| 88151 | 87423 | nRow = pIdx->aiRowEst[0]; |
| 88152 | 87424 | nDist100 = ((i64)100 * pIdx->aiRowEst[0]) / pIdx->aiRowEst[iCol+1]; |
| 88153 | 87425 | } |
| 88154 | | - pIdx->nRowEst0 = nRow; |
| 88155 | 87426 | |
| 88156 | 87427 | /* Set nSum to the number of distinct (iCol+1) field prefixes that |
| 88157 | 87428 | ** occur in the stat4 table for this index. Set sumEq to the sum of |
| 88158 | 87429 | ** the nEq values for column iCol for the same set (adding the value |
| 88159 | 87430 | ** only once where there exist duplicate prefixes). */ |
| | @@ -88411,11 +87682,11 @@ |
| 88411 | 87682 | } |
| 88412 | 87683 | |
| 88413 | 87684 | |
| 88414 | 87685 | /* Load the statistics from the sqlite_stat4 table. */ |
| 88415 | 87686 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 88416 | | - if( rc==SQLITE_OK && OptimizationEnabled(db, SQLITE_Stat34) ){ |
| 87687 | + if( rc==SQLITE_OK ){ |
| 88417 | 87688 | int lookasideEnabled = db->lookaside.bEnabled; |
| 88418 | 87689 | db->lookaside.bEnabled = 0; |
| 88419 | 87690 | rc = loadStat4(db, sInfo.zDatabase); |
| 88420 | 87691 | db->lookaside.bEnabled = lookasideEnabled; |
| 88421 | 87692 | } |
| | @@ -89093,13 +88364,10 @@ |
| 89093 | 88364 | SQLITE_API int sqlite3_set_authorizer( |
| 89094 | 88365 | sqlite3 *db, |
| 89095 | 88366 | int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), |
| 89096 | 88367 | void *pArg |
| 89097 | 88368 | ){ |
| 89098 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 89099 | | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 89100 | | -#endif |
| 89101 | 88369 | sqlite3_mutex_enter(db->mutex); |
| 89102 | 88370 | db->xAuth = (sqlite3_xauth)xAuth; |
| 89103 | 88371 | db->pAuthArg = pArg; |
| 89104 | 88372 | sqlite3ExpirePreparedStatements(db); |
| 89105 | 88373 | sqlite3_mutex_leave(db->mutex); |
| | @@ -89590,15 +88858,11 @@ |
| 89590 | 88858 | ** See also sqlite3LocateTable(). |
| 89591 | 88859 | */ |
| 89592 | 88860 | SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){ |
| 89593 | 88861 | Table *p = 0; |
| 89594 | 88862 | int i; |
| 89595 | | - |
| 89596 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 89597 | | - if( !sqlite3SafetyCheckOk(db) || zName==0 ) return 0; |
| 89598 | | -#endif |
| 89599 | | - |
| 88863 | + assert( zName!=0 ); |
| 89600 | 88864 | /* All mutexes are required for schema access. Make sure we hold them. */ |
| 89601 | 88865 | assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) ); |
| 89602 | 88866 | #if SQLITE_USER_AUTHENTICATION |
| 89603 | 88867 | /* Only the admin user is allowed to know that the sqlite_user table |
| 89604 | 88868 | ** exists */ |
| | @@ -104617,16 +103881,13 @@ |
| 104617 | 103881 | Vdbe *pOld, /* VM being reprepared */ |
| 104618 | 103882 | sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */ |
| 104619 | 103883 | const char **pzTail /* OUT: End of parsed string */ |
| 104620 | 103884 | ){ |
| 104621 | 103885 | int rc; |
| 104622 | | - |
| 104623 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 104624 | | - if( ppStmt==0 ) return SQLITE_MISUSE_BKPT; |
| 104625 | | -#endif |
| 103886 | + assert( ppStmt!=0 ); |
| 104626 | 103887 | *ppStmt = 0; |
| 104627 | | - if( !sqlite3SafetyCheckOk(db)||zSql==0 ){ |
| 103888 | + if( !sqlite3SafetyCheckOk(db) ){ |
| 104628 | 103889 | return SQLITE_MISUSE_BKPT; |
| 104629 | 103890 | } |
| 104630 | 103891 | sqlite3_mutex_enter(db->mutex); |
| 104631 | 103892 | sqlite3BtreeEnterAll(db); |
| 104632 | 103893 | rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail); |
| | @@ -104729,15 +103990,13 @@ |
| 104729 | 103990 | */ |
| 104730 | 103991 | char *zSql8; |
| 104731 | 103992 | const char *zTail8 = 0; |
| 104732 | 103993 | int rc = SQLITE_OK; |
| 104733 | 103994 | |
| 104734 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 104735 | | - if( ppStmt==0 ) return SQLITE_MISUSE_BKPT; |
| 104736 | | -#endif |
| 103995 | + assert( ppStmt ); |
| 104737 | 103996 | *ppStmt = 0; |
| 104738 | | - if( !sqlite3SafetyCheckOk(db)||zSql==0 ){ |
| 103997 | + if( !sqlite3SafetyCheckOk(db) ){ |
| 104739 | 103998 | return SQLITE_MISUSE_BKPT; |
| 104740 | 103999 | } |
| 104741 | 104000 | if( nBytes>=0 ){ |
| 104742 | 104001 | int sz; |
| 104743 | 104002 | const char *z = (const char*)zSql; |
| | @@ -110446,13 +109705,10 @@ |
| 110446 | 109705 | char **pzErrMsg /* Write error messages here */ |
| 110447 | 109706 | ){ |
| 110448 | 109707 | int rc; |
| 110449 | 109708 | TabResult res; |
| 110450 | 109709 | |
| 110451 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 110452 | | - if( pazResult==0 ) return SQLITE_MISUSE_BKPT; |
| 110453 | | -#endif |
| 110454 | 109710 | *pazResult = 0; |
| 110455 | 109711 | if( pnColumn ) *pnColumn = 0; |
| 110456 | 109712 | if( pnRow ) *pnRow = 0; |
| 110457 | 109713 | if( pzErrMsg ) *pzErrMsg = 0; |
| 110458 | 109714 | res.zErrMsg = 0; |
| | @@ -112512,11 +111768,11 @@ |
| 112512 | 111768 | ** Two writes per page are required in step (3) because the original |
| 112513 | 111769 | ** database content must be written into the rollback journal prior to |
| 112514 | 111770 | ** overwriting the database with the vacuumed content. |
| 112515 | 111771 | ** |
| 112516 | 111772 | ** Only 1x temporary space and only 1x writes would be required if |
| 112517 | | -** the copy of step (3) were replaced by deleting the original database |
| 111773 | +** the copy of step (3) were replace by deleting the original database |
| 112518 | 111774 | ** and renaming the transient database as the original. But that will |
| 112519 | 111775 | ** not work if other processes are attached to the original database. |
| 112520 | 111776 | ** And a power loss in between deleting the original and renaming the |
| 112521 | 111777 | ** transient would cause the database file to appear to be deleted |
| 112522 | 111778 | ** following reboot. |
| | @@ -112870,13 +112126,10 @@ |
| 112870 | 112126 | sqlite3 *db, /* Database in which module is registered */ |
| 112871 | 112127 | const char *zName, /* Name assigned to this module */ |
| 112872 | 112128 | const sqlite3_module *pModule, /* The definition of the module */ |
| 112873 | 112129 | void *pAux /* Context pointer for xCreate/xConnect */ |
| 112874 | 112130 | ){ |
| 112875 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 112876 | | - if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT; |
| 112877 | | -#endif |
| 112878 | 112131 | return createModule(db, zName, pModule, pAux, 0); |
| 112879 | 112132 | } |
| 112880 | 112133 | |
| 112881 | 112134 | /* |
| 112882 | 112135 | ** External API function used to create a new virtual-table module. |
| | @@ -112886,13 +112139,10 @@ |
| 112886 | 112139 | const char *zName, /* Name assigned to this module */ |
| 112887 | 112140 | const sqlite3_module *pModule, /* The definition of the module */ |
| 112888 | 112141 | void *pAux, /* Context pointer for xCreate/xConnect */ |
| 112889 | 112142 | void (*xDestroy)(void *) /* Module destructor function */ |
| 112890 | 112143 | ){ |
| 112891 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 112892 | | - if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT; |
| 112893 | | -#endif |
| 112894 | 112144 | return createModule(db, zName, pModule, pAux, xDestroy); |
| 112895 | 112145 | } |
| 112896 | 112146 | |
| 112897 | 112147 | /* |
| 112898 | 112148 | ** Lock the virtual table so that it cannot be disconnected. |
| | @@ -113493,13 +112743,10 @@ |
| 113493 | 112743 | |
| 113494 | 112744 | int rc = SQLITE_OK; |
| 113495 | 112745 | Table *pTab; |
| 113496 | 112746 | char *zErr = 0; |
| 113497 | 112747 | |
| 113498 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 113499 | | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 113500 | | -#endif |
| 113501 | 112748 | sqlite3_mutex_enter(db->mutex); |
| 113502 | 112749 | if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){ |
| 113503 | 112750 | sqlite3Error(db, SQLITE_MISUSE); |
| 113504 | 112751 | sqlite3_mutex_leave(db->mutex); |
| 113505 | 112752 | return SQLITE_MISUSE_BKPT; |
| | @@ -113852,13 +113099,10 @@ |
| 113852 | 113099 | */ |
| 113853 | 113100 | SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *db){ |
| 113854 | 113101 | static const unsigned char aMap[] = { |
| 113855 | 113102 | SQLITE_ROLLBACK, SQLITE_ABORT, SQLITE_FAIL, SQLITE_IGNORE, SQLITE_REPLACE |
| 113856 | 113103 | }; |
| 113857 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 113858 | | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 113859 | | -#endif |
| 113860 | 113104 | assert( OE_Rollback==1 && OE_Abort==2 && OE_Fail==3 ); |
| 113861 | 113105 | assert( OE_Ignore==4 && OE_Replace==5 ); |
| 113862 | 113106 | assert( db->vtabOnConflict>=1 && db->vtabOnConflict<=5 ); |
| 113863 | 113107 | return (int)aMap[db->vtabOnConflict-1]; |
| 113864 | 113108 | } |
| | @@ -113870,14 +113114,12 @@ |
| 113870 | 113114 | */ |
| 113871 | 113115 | SQLITE_API int sqlite3_vtab_config(sqlite3 *db, int op, ...){ |
| 113872 | 113116 | va_list ap; |
| 113873 | 113117 | int rc = SQLITE_OK; |
| 113874 | 113118 | |
| 113875 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 113876 | | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 113877 | | -#endif |
| 113878 | 113119 | sqlite3_mutex_enter(db->mutex); |
| 113120 | + |
| 113879 | 113121 | va_start(ap, op); |
| 113880 | 113122 | switch( op ){ |
| 113881 | 113123 | case SQLITE_VTAB_CONSTRAINT_SUPPORT: { |
| 113882 | 113124 | VtabCtx *p = db->pVtabCtx; |
| 113883 | 113125 | if( !p ){ |
| | @@ -114008,13 +113250,10 @@ |
| 114008 | 113250 | } in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */ |
| 114009 | 113251 | Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */ |
| 114010 | 113252 | } u; |
| 114011 | 113253 | struct WhereLoop *pWLoop; /* The selected WhereLoop object */ |
| 114012 | 113254 | Bitmask notReady; /* FROM entries not usable at this level */ |
| 114013 | | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 114014 | | - int addrVisit; /* Address at which row is visited */ |
| 114015 | | -#endif |
| 114016 | 113255 | }; |
| 114017 | 113256 | |
| 114018 | 113257 | /* |
| 114019 | 113258 | ** Each instance of this object represents an algorithm for evaluating one |
| 114020 | 113259 | ** term of a join. Every term of the FROM clause will have at least |
| | @@ -114041,10 +113280,11 @@ |
| 114041 | 113280 | LogEst rRun; /* Cost of running each loop */ |
| 114042 | 113281 | LogEst nOut; /* Estimated number of output rows */ |
| 114043 | 113282 | union { |
| 114044 | 113283 | struct { /* Information for internal btree tables */ |
| 114045 | 113284 | u16 nEq; /* Number of equality constraints */ |
| 113285 | + u16 nSkip; /* Number of initial index columns to skip */ |
| 114046 | 113286 | Index *pIndex; /* Index used, or NULL */ |
| 114047 | 113287 | } btree; |
| 114048 | 113288 | struct { /* Information for virtual tables */ |
| 114049 | 113289 | int idxNum; /* Index number */ |
| 114050 | 113290 | u8 needFree; /* True if sqlite3_free(idxStr) is needed */ |
| | @@ -114053,17 +113293,16 @@ |
| 114053 | 113293 | char *idxStr; /* Index identifier string */ |
| 114054 | 113294 | } vtab; |
| 114055 | 113295 | } u; |
| 114056 | 113296 | u32 wsFlags; /* WHERE_* flags describing the plan */ |
| 114057 | 113297 | u16 nLTerm; /* Number of entries in aLTerm[] */ |
| 114058 | | - u16 nSkip; /* Number of NULL aLTerm[] entries */ |
| 114059 | 113298 | /**** whereLoopXfer() copies fields above ***********************/ |
| 114060 | 113299 | # define WHERE_LOOP_XFER_SZ offsetof(WhereLoop,nLSlot) |
| 114061 | 113300 | u16 nLSlot; /* Number of slots allocated for aLTerm[] */ |
| 114062 | 113301 | WhereTerm **aLTerm; /* WhereTerms used */ |
| 114063 | 113302 | WhereLoop *pNextLoop; /* Next WhereLoop object in the WhereClause */ |
| 114064 | | - WhereTerm *aLTermSpace[3]; /* Initial aLTerm[] space */ |
| 113303 | + WhereTerm *aLTermSpace[4]; /* Initial aLTerm[] space */ |
| 114065 | 113304 | }; |
| 114066 | 113305 | |
| 114067 | 113306 | /* This object holds the prerequisites and the cost of running a |
| 114068 | 113307 | ** subquery on one operand of an OR operator in the WHERE clause. |
| 114069 | 113308 | ** See WhereOrSet for additional information |
| | @@ -114385,11 +113624,10 @@ |
| 114385 | 113624 | #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */ |
| 114386 | 113625 | #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */ |
| 114387 | 113626 | #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */ |
| 114388 | 113627 | #define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */ |
| 114389 | 113628 | #define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/ |
| 114390 | | -#define WHERE_PARTIALIDX 0x00020000 /* The automatic index is partial */ |
| 114391 | 113629 | |
| 114392 | 113630 | /************** End of whereInt.h ********************************************/ |
| 114393 | 113631 | /************** Continuing where we left off in where.c **********************/ |
| 114394 | 113632 | |
| 114395 | 113633 | /* |
| | @@ -114596,11 +113834,11 @@ |
| 114596 | 113834 | } |
| 114597 | 113835 | pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]); |
| 114598 | 113836 | } |
| 114599 | 113837 | pTerm = &pWC->a[idx = pWC->nTerm++]; |
| 114600 | 113838 | if( p && ExprHasProperty(p, EP_Unlikely) ){ |
| 114601 | | - pTerm->truthProb = sqlite3LogEst(p->iTable) - 270; |
| 113839 | + pTerm->truthProb = sqlite3LogEst(p->iTable) - 99; |
| 114602 | 113840 | }else{ |
| 114603 | 113841 | pTerm->truthProb = 1; |
| 114604 | 113842 | } |
| 114605 | 113843 | pTerm->pExpr = sqlite3ExprSkipCollate(p); |
| 114606 | 113844 | pTerm->wtFlags = wtFlags; |
| | @@ -115127,19 +114365,10 @@ |
| 115127 | 114365 | pDerived->flags |= pBase->flags & EP_FromJoin; |
| 115128 | 114366 | pDerived->iRightJoinTable = pBase->iRightJoinTable; |
| 115129 | 114367 | } |
| 115130 | 114368 | } |
| 115131 | 114369 | |
| 115132 | | -/* |
| 115133 | | -** Mark term iChild as being a child of term iParent |
| 115134 | | -*/ |
| 115135 | | -static void markTermAsChild(WhereClause *pWC, int iChild, int iParent){ |
| 115136 | | - pWC->a[iChild].iParent = iParent; |
| 115137 | | - pWC->a[iChild].truthProb = pWC->a[iParent].truthProb; |
| 115138 | | - pWC->a[iParent].nChild++; |
| 115139 | | -} |
| 115140 | | - |
| 115141 | 114370 | #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY) |
| 115142 | 114371 | /* |
| 115143 | 114372 | ** Analyze a term that consists of two or more OR-connected |
| 115144 | 114373 | ** subterms. So in: |
| 115145 | 114374 | ** |
| | @@ -115433,11 +114662,12 @@ |
| 115433 | 114662 | pNew->x.pList = pList; |
| 115434 | 114663 | idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC); |
| 115435 | 114664 | testcase( idxNew==0 ); |
| 115436 | 114665 | exprAnalyze(pSrc, pWC, idxNew); |
| 115437 | 114666 | pTerm = &pWC->a[idxTerm]; |
| 115438 | | - markTermAsChild(pWC, idxNew, idxTerm); |
| 114667 | + pWC->a[idxNew].iParent = idxTerm; |
| 114668 | + pTerm->nChild = 1; |
| 115439 | 114669 | }else{ |
| 115440 | 114670 | sqlite3ExprListDelete(db, pList); |
| 115441 | 114671 | } |
| 115442 | 114672 | pTerm->eOperator = WO_NOOP; /* case 1 trumps case 2 */ |
| 115443 | 114673 | } |
| | @@ -115535,12 +114765,13 @@ |
| 115535 | 114765 | return; |
| 115536 | 114766 | } |
| 115537 | 114767 | idxNew = whereClauseInsert(pWC, pDup, TERM_VIRTUAL|TERM_DYNAMIC); |
| 115538 | 114768 | if( idxNew==0 ) return; |
| 115539 | 114769 | pNew = &pWC->a[idxNew]; |
| 115540 | | - markTermAsChild(pWC, idxNew, idxTerm); |
| 114770 | + pNew->iParent = idxTerm; |
| 115541 | 114771 | pTerm = &pWC->a[idxTerm]; |
| 114772 | + pTerm->nChild = 1; |
| 115542 | 114773 | pTerm->wtFlags |= TERM_COPIED; |
| 115543 | 114774 | if( pExpr->op==TK_EQ |
| 115544 | 114775 | && !ExprHasProperty(pExpr, EP_FromJoin) |
| 115545 | 114776 | && OptimizationEnabled(db, SQLITE_Transitive) |
| 115546 | 114777 | ){ |
| | @@ -115593,12 +114824,13 @@ |
| 115593 | 114824 | transferJoinMarkings(pNewExpr, pExpr); |
| 115594 | 114825 | idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC); |
| 115595 | 114826 | testcase( idxNew==0 ); |
| 115596 | 114827 | exprAnalyze(pSrc, pWC, idxNew); |
| 115597 | 114828 | pTerm = &pWC->a[idxTerm]; |
| 115598 | | - markTermAsChild(pWC, idxNew, idxTerm); |
| 114829 | + pWC->a[idxNew].iParent = idxTerm; |
| 115599 | 114830 | } |
| 114831 | + pTerm->nChild = 2; |
| 115600 | 114832 | } |
| 115601 | 114833 | #endif /* SQLITE_OMIT_BETWEEN_OPTIMIZATION */ |
| 115602 | 114834 | |
| 115603 | 114835 | #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY) |
| 115604 | 114836 | /* Analyze a term that is composed of two or more subterms connected by |
| | @@ -115669,12 +114901,13 @@ |
| 115669 | 114901 | idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC); |
| 115670 | 114902 | testcase( idxNew2==0 ); |
| 115671 | 114903 | exprAnalyze(pSrc, pWC, idxNew2); |
| 115672 | 114904 | pTerm = &pWC->a[idxTerm]; |
| 115673 | 114905 | if( isComplete ){ |
| 115674 | | - markTermAsChild(pWC, idxNew1, idxTerm); |
| 115675 | | - markTermAsChild(pWC, idxNew2, idxTerm); |
| 114906 | + pWC->a[idxNew1].iParent = idxTerm; |
| 114907 | + pWC->a[idxNew2].iParent = idxTerm; |
| 114908 | + pTerm->nChild = 2; |
| 115676 | 114909 | } |
| 115677 | 114910 | } |
| 115678 | 114911 | #endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */ |
| 115679 | 114912 | |
| 115680 | 114913 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| | @@ -115703,12 +114936,13 @@ |
| 115703 | 114936 | pNewTerm = &pWC->a[idxNew]; |
| 115704 | 114937 | pNewTerm->prereqRight = prereqExpr; |
| 115705 | 114938 | pNewTerm->leftCursor = pLeft->iTable; |
| 115706 | 114939 | pNewTerm->u.leftColumn = pLeft->iColumn; |
| 115707 | 114940 | pNewTerm->eOperator = WO_MATCH; |
| 115708 | | - markTermAsChild(pWC, idxNew, idxTerm); |
| 114941 | + pNewTerm->iParent = idxTerm; |
| 115709 | 114942 | pTerm = &pWC->a[idxTerm]; |
| 114943 | + pTerm->nChild = 1; |
| 115710 | 114944 | pTerm->wtFlags |= TERM_COPIED; |
| 115711 | 114945 | pNewTerm->prereqAll = pTerm->prereqAll; |
| 115712 | 114946 | } |
| 115713 | 114947 | } |
| 115714 | 114948 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| | @@ -115725,11 +114959,11 @@ |
| 115725 | 114959 | ** the start of the loop will prevent any results from being returned. |
| 115726 | 114960 | */ |
| 115727 | 114961 | if( pExpr->op==TK_NOTNULL |
| 115728 | 114962 | && pExpr->pLeft->op==TK_COLUMN |
| 115729 | 114963 | && pExpr->pLeft->iColumn>=0 |
| 115730 | | - && OptimizationEnabled(db, SQLITE_Stat34) |
| 114964 | + && OptimizationEnabled(db, SQLITE_Stat3) |
| 115731 | 114965 | ){ |
| 115732 | 114966 | Expr *pNewExpr; |
| 115733 | 114967 | Expr *pLeft = pExpr->pLeft; |
| 115734 | 114968 | int idxNew; |
| 115735 | 114969 | WhereTerm *pNewTerm; |
| | @@ -115744,12 +114978,13 @@ |
| 115744 | 114978 | pNewTerm = &pWC->a[idxNew]; |
| 115745 | 114979 | pNewTerm->prereqRight = 0; |
| 115746 | 114980 | pNewTerm->leftCursor = pLeft->iTable; |
| 115747 | 114981 | pNewTerm->u.leftColumn = pLeft->iColumn; |
| 115748 | 114982 | pNewTerm->eOperator = WO_GT; |
| 115749 | | - markTermAsChild(pWC, idxNew, idxTerm); |
| 114983 | + pNewTerm->iParent = idxTerm; |
| 115750 | 114984 | pTerm = &pWC->a[idxTerm]; |
| 114985 | + pTerm->nChild = 1; |
| 115751 | 114986 | pTerm->wtFlags |= TERM_COPIED; |
| 115752 | 114987 | pNewTerm->prereqAll = pTerm->prereqAll; |
| 115753 | 114988 | } |
| 115754 | 114989 | } |
| 115755 | 114990 | #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */ |
| | @@ -115965,12 +115200,10 @@ |
| 115965 | 115200 | WhereLoop *pLoop; /* The Loop object */ |
| 115966 | 115201 | char *zNotUsed; /* Extra space on the end of pIdx */ |
| 115967 | 115202 | Bitmask idxCols; /* Bitmap of columns used for indexing */ |
| 115968 | 115203 | Bitmask extraCols; /* Bitmap of additional columns */ |
| 115969 | 115204 | u8 sentWarning = 0; /* True if a warnning has been issued */ |
| 115970 | | - Expr *pPartial = 0; /* Partial Index Expression */ |
| 115971 | | - int iContinue = 0; /* Jump here to skip excluded rows */ |
| 115972 | 115205 | |
| 115973 | 115206 | /* Generate code to skip over the creation and initialization of the |
| 115974 | 115207 | ** transient index on 2nd and subsequent iterations of the loop. */ |
| 115975 | 115208 | v = pParse->pVdbe; |
| 115976 | 115209 | assert( v!=0 ); |
| | @@ -115982,16 +115215,10 @@ |
| 115982 | 115215 | pTable = pSrc->pTab; |
| 115983 | 115216 | pWCEnd = &pWC->a[pWC->nTerm]; |
| 115984 | 115217 | pLoop = pLevel->pWLoop; |
| 115985 | 115218 | idxCols = 0; |
| 115986 | 115219 | for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){ |
| 115987 | | - if( pLoop->prereq==0 |
| 115988 | | - && (pTerm->wtFlags & TERM_VIRTUAL)==0 |
| 115989 | | - && sqlite3ExprIsTableConstant(pTerm->pExpr, pSrc->iCursor) ){ |
| 115990 | | - pPartial = sqlite3ExprAnd(pParse->db, pPartial, |
| 115991 | | - sqlite3ExprDup(pParse->db, pTerm->pExpr, 0)); |
| 115992 | | - } |
| 115993 | 115220 | if( termCanDriveIndex(pTerm, pSrc, notReady) ){ |
| 115994 | 115221 | int iCol = pTerm->u.leftColumn; |
| 115995 | 115222 | Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol); |
| 115996 | 115223 | testcase( iCol==BMS ); |
| 115997 | 115224 | testcase( iCol==BMS-1 ); |
| | @@ -116000,13 +115227,11 @@ |
| 116000 | 115227 | "automatic index on %s(%s)", pTable->zName, |
| 116001 | 115228 | pTable->aCol[iCol].zName); |
| 116002 | 115229 | sentWarning = 1; |
| 116003 | 115230 | } |
| 116004 | 115231 | if( (idxCols & cMask)==0 ){ |
| 116005 | | - if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ){ |
| 116006 | | - goto end_auto_index_create; |
| 116007 | | - } |
| 115232 | + if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ) return; |
| 116008 | 115233 | pLoop->aLTerm[nKeyCol++] = pTerm; |
| 116009 | 115234 | idxCols |= cMask; |
| 116010 | 115235 | } |
| 116011 | 115236 | } |
| 116012 | 115237 | } |
| | @@ -116022,23 +115247,24 @@ |
| 116022 | 115247 | ** be a covering index because the index will not be updated if the |
| 116023 | 115248 | ** original table changes and the index and table cannot both be used |
| 116024 | 115249 | ** if they go out of sync. |
| 116025 | 115250 | */ |
| 116026 | 115251 | extraCols = pSrc->colUsed & (~idxCols | MASKBIT(BMS-1)); |
| 116027 | | - mxBitCol = MIN(BMS-1,pTable->nCol); |
| 115252 | + mxBitCol = (pTable->nCol >= BMS-1) ? BMS-1 : pTable->nCol; |
| 116028 | 115253 | testcase( pTable->nCol==BMS-1 ); |
| 116029 | 115254 | testcase( pTable->nCol==BMS-2 ); |
| 116030 | 115255 | for(i=0; i<mxBitCol; i++){ |
| 116031 | 115256 | if( extraCols & MASKBIT(i) ) nKeyCol++; |
| 116032 | 115257 | } |
| 116033 | 115258 | if( pSrc->colUsed & MASKBIT(BMS-1) ){ |
| 116034 | 115259 | nKeyCol += pTable->nCol - BMS + 1; |
| 116035 | 115260 | } |
| 115261 | + pLoop->wsFlags |= WHERE_COLUMN_EQ | WHERE_IDX_ONLY; |
| 116036 | 115262 | |
| 116037 | 115263 | /* Construct the Index object to describe this index */ |
| 116038 | 115264 | pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+1, 0, &zNotUsed); |
| 116039 | | - if( pIdx==0 ) goto end_auto_index_create; |
| 115265 | + if( pIdx==0 ) return; |
| 116040 | 115266 | pLoop->u.btree.pIndex = pIdx; |
| 116041 | 115267 | pIdx->zName = "auto-index"; |
| 116042 | 115268 | pIdx->pTable = pTable; |
| 116043 | 115269 | n = 0; |
| 116044 | 115270 | idxCols = 0; |
| | @@ -116086,33 +115312,22 @@ |
| 116086 | 115312 | sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1); |
| 116087 | 115313 | sqlite3VdbeSetP4KeyInfo(pParse, pIdx); |
| 116088 | 115314 | VdbeComment((v, "for %s", pTable->zName)); |
| 116089 | 115315 | |
| 116090 | 115316 | /* Fill the automatic index with content */ |
| 116091 | | - sqlite3ExprCachePush(pParse); |
| 116092 | 115317 | addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v); |
| 116093 | | - if( pPartial ){ |
| 116094 | | - iContinue = sqlite3VdbeMakeLabel(v); |
| 116095 | | - sqlite3ExprIfFalse(pParse, pPartial, iContinue, SQLITE_JUMPIFNULL); |
| 116096 | | - pLoop->wsFlags |= WHERE_PARTIALIDX; |
| 116097 | | - } |
| 116098 | 115318 | regRecord = sqlite3GetTempReg(pParse); |
| 116099 | 115319 | sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0); |
| 116100 | 115320 | sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord); |
| 116101 | 115321 | sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); |
| 116102 | | - if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue); |
| 116103 | 115322 | sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v); |
| 116104 | 115323 | sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX); |
| 116105 | 115324 | sqlite3VdbeJumpHere(v, addrTop); |
| 116106 | 115325 | sqlite3ReleaseTempReg(pParse, regRecord); |
| 116107 | | - sqlite3ExprCachePop(pParse); |
| 116108 | 115326 | |
| 116109 | 115327 | /* Jump here when skipping the initialization */ |
| 116110 | 115328 | sqlite3VdbeJumpHere(v, addrInit); |
| 116111 | | - |
| 116112 | | -end_auto_index_create: |
| 116113 | | - sqlite3ExprDelete(pParse->db, pPartial); |
| 116114 | 115329 | } |
| 116115 | 115330 | #endif /* SQLITE_OMIT_AUTOMATIC_INDEX */ |
| 116116 | 115331 | |
| 116117 | 115332 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 116118 | 115333 | /* |
| | @@ -116267,23 +115482,23 @@ |
| 116267 | 115482 | } |
| 116268 | 115483 | |
| 116269 | 115484 | return pParse->nErr; |
| 116270 | 115485 | } |
| 116271 | 115486 | #endif /* !defined(SQLITE_OMIT_VIRTUALTABLE) */ |
| 115487 | + |
| 116272 | 115488 | |
| 116273 | 115489 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 116274 | 115490 | /* |
| 116275 | 115491 | ** Estimate the location of a particular key among all keys in an |
| 116276 | 115492 | ** index. Store the results in aStat as follows: |
| 116277 | 115493 | ** |
| 116278 | 115494 | ** aStat[0] Est. number of rows less than pVal |
| 116279 | 115495 | ** aStat[1] Est. number of rows equal to pVal |
| 116280 | 115496 | ** |
| 116281 | | -** Return the index of the sample that is the smallest sample that |
| 116282 | | -** is greater than or equal to pRec. |
| 115497 | +** Return SQLITE_OK on success. |
| 116283 | 115498 | */ |
| 116284 | | -static int whereKeyStats( |
| 115499 | +static void whereKeyStats( |
| 116285 | 115500 | Parse *pParse, /* Database connection */ |
| 116286 | 115501 | Index *pIdx, /* Index to consider domain of */ |
| 116287 | 115502 | UnpackedRecord *pRec, /* Vector of values to consider */ |
| 116288 | 115503 | int roundUp, /* Round up if true. Round down if false */ |
| 116289 | 115504 | tRowcnt *aStat /* OUT: stats written here */ |
| | @@ -116361,11 +115576,10 @@ |
| 116361 | 115576 | }else{ |
| 116362 | 115577 | iGap = iGap/3; |
| 116363 | 115578 | } |
| 116364 | 115579 | aStat[0] = iLower + iGap; |
| 116365 | 115580 | } |
| 116366 | | - return i; |
| 116367 | 115581 | } |
| 116368 | 115582 | #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */ |
| 116369 | 115583 | |
| 116370 | 115584 | /* |
| 116371 | 115585 | ** If it is not NULL, pTerm is a term that provides an upper or lower |
| | @@ -116512,11 +115726,11 @@ |
| 116512 | 115726 | ** pLower pUpper |
| 116513 | 115727 | ** |
| 116514 | 115728 | ** If either of the upper or lower bound is not present, then NULL is passed in |
| 116515 | 115729 | ** place of the corresponding WhereTerm. |
| 116516 | 115730 | ** |
| 116517 | | -** The value in (pBuilder->pNew->u.btree.nEq) is the number of the index |
| 115731 | +** The value in (pBuilder->pNew->u.btree.nEq) is the index of the index |
| 116518 | 115732 | ** column subject to the range constraint. Or, equivalently, the number of |
| 116519 | 115733 | ** equality constraints optimized by the proposed index scan. For example, |
| 116520 | 115734 | ** assuming index p is on t1(a, b), and the SQL query is: |
| 116521 | 115735 | ** |
| 116522 | 115736 | ** ... FROM t1 WHERE a = ? AND b > ? AND b < ? ... |
| | @@ -116528,11 +115742,11 @@ |
| 116528 | 115742 | ** |
| 116529 | 115743 | ** then nEq is set to 0. |
| 116530 | 115744 | ** |
| 116531 | 115745 | ** When this function is called, *pnOut is set to the sqlite3LogEst() of the |
| 116532 | 115746 | ** number of rows that the index scan is expected to visit without |
| 116533 | | -** considering the range constraints. If nEq is 0, then *pnOut is the number of |
| 115747 | +** considering the range constraints. If nEq is 0, this is the number of |
| 116534 | 115748 | ** rows in the index. Assuming no error occurs, *pnOut is adjusted (reduced) |
| 116535 | 115749 | ** to account for the range constraints pLower and pUpper. |
| 116536 | 115750 | ** |
| 116537 | 115751 | ** In the absence of sqlite_stat4 ANALYZE data, or if such data cannot be |
| 116538 | 115752 | ** used, a single range inequality reduces the search space by a factor of 4. |
| | @@ -116552,11 +115766,14 @@ |
| 116552 | 115766 | |
| 116553 | 115767 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 116554 | 115768 | Index *p = pLoop->u.btree.pIndex; |
| 116555 | 115769 | int nEq = pLoop->u.btree.nEq; |
| 116556 | 115770 | |
| 116557 | | - if( p->nSample>0 && nEq<p->nSampleCol ){ |
| 115771 | + if( p->nSample>0 |
| 115772 | + && nEq<p->nSampleCol |
| 115773 | + && OptimizationEnabled(pParse->db, SQLITE_Stat3) |
| 115774 | + ){ |
| 116558 | 115775 | if( nEq==pBuilder->nRecValid ){ |
| 116559 | 115776 | UnpackedRecord *pRec = pBuilder->pRec; |
| 116560 | 115777 | tRowcnt a[2]; |
| 116561 | 115778 | u8 aff; |
| 116562 | 115779 | |
| | @@ -116568,23 +115785,19 @@ |
| 116568 | 115785 | ** |
| 116569 | 115786 | ** Or, if pLower is NULL or $L cannot be extracted from it (because it |
| 116570 | 115787 | ** is not a simple variable or literal value), the lower bound of the |
| 116571 | 115788 | ** range is $P. Due to a quirk in the way whereKeyStats() works, even |
| 116572 | 115789 | ** if $L is available, whereKeyStats() is called for both ($P) and |
| 116573 | | - ** ($P:$L) and the larger of the two returned values is used. |
| 115790 | + ** ($P:$L) and the larger of the two returned values used. |
| 116574 | 115791 | ** |
| 116575 | 115792 | ** Similarly, iUpper is to be set to the estimate of the number of rows |
| 116576 | 115793 | ** less than the upper bound of the range query. Where the upper bound |
| 116577 | 115794 | ** is either ($P) or ($P:$U). Again, even if $U is available, both values |
| 116578 | 115795 | ** of iUpper are requested of whereKeyStats() and the smaller used. |
| 116579 | | - ** |
| 116580 | | - ** The number of rows between the two bounds is then just iUpper-iLower. |
| 116581 | 115796 | */ |
| 116582 | | - tRowcnt iLower; /* Rows less than the lower bound */ |
| 116583 | | - tRowcnt iUpper; /* Rows less than the upper bound */ |
| 116584 | | - int iLwrIdx = -2; /* aSample[] for the lower bound */ |
| 116585 | | - int iUprIdx = -1; /* aSample[] for the upper bound */ |
| 115797 | + tRowcnt iLower; |
| 115798 | + tRowcnt iUpper; |
| 116586 | 115799 | |
| 116587 | 115800 | if( pRec ){ |
| 116588 | 115801 | testcase( pRec->nField!=pBuilder->nRecValid ); |
| 116589 | 115802 | pRec->nField = pBuilder->nRecValid; |
| 116590 | 115803 | } |
| | @@ -116594,11 +115807,11 @@ |
| 116594 | 115807 | aff = p->pTable->aCol[p->aiColumn[nEq]].affinity; |
| 116595 | 115808 | } |
| 116596 | 115809 | /* Determine iLower and iUpper using ($P) only. */ |
| 116597 | 115810 | if( nEq==0 ){ |
| 116598 | 115811 | iLower = 0; |
| 116599 | | - iUpper = p->nRowEst0; |
| 115812 | + iUpper = sqlite3LogEstToInt(p->aiRowLogEst[0]); |
| 116600 | 115813 | }else{ |
| 116601 | 115814 | /* Note: this call could be optimized away - since the same values must |
| 116602 | 115815 | ** have been requested when testing key $P in whereEqualScanEst(). */ |
| 116603 | 115816 | whereKeyStats(pParse, p, pRec, 0, a); |
| 116604 | 115817 | iLower = a[0]; |
| | @@ -116618,11 +115831,11 @@ |
| 116618 | 115831 | int bOk; /* True if value is extracted from pExpr */ |
| 116619 | 115832 | Expr *pExpr = pLower->pExpr->pRight; |
| 116620 | 115833 | rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk); |
| 116621 | 115834 | if( rc==SQLITE_OK && bOk ){ |
| 116622 | 115835 | tRowcnt iNew; |
| 116623 | | - iLwrIdx = whereKeyStats(pParse, p, pRec, 0, a); |
| 115836 | + whereKeyStats(pParse, p, pRec, 0, a); |
| 116624 | 115837 | iNew = a[0] + ((pLower->eOperator & (WO_GT|WO_LE)) ? a[1] : 0); |
| 116625 | 115838 | if( iNew>iLower ) iLower = iNew; |
| 116626 | 115839 | nOut--; |
| 116627 | 115840 | pLower = 0; |
| 116628 | 115841 | } |
| | @@ -116633,11 +115846,11 @@ |
| 116633 | 115846 | int bOk; /* True if value is extracted from pExpr */ |
| 116634 | 115847 | Expr *pExpr = pUpper->pExpr->pRight; |
| 116635 | 115848 | rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk); |
| 116636 | 115849 | if( rc==SQLITE_OK && bOk ){ |
| 116637 | 115850 | tRowcnt iNew; |
| 116638 | | - iUprIdx = whereKeyStats(pParse, p, pRec, 1, a); |
| 115851 | + whereKeyStats(pParse, p, pRec, 1, a); |
| 116639 | 115852 | iNew = a[0] + ((pUpper->eOperator & (WO_GT|WO_LE)) ? a[1] : 0); |
| 116640 | 115853 | if( iNew<iUpper ) iUpper = iNew; |
| 116641 | 115854 | nOut--; |
| 116642 | 115855 | pUpper = 0; |
| 116643 | 115856 | } |
| | @@ -116645,15 +115858,10 @@ |
| 116645 | 115858 | |
| 116646 | 115859 | pBuilder->pRec = pRec; |
| 116647 | 115860 | if( rc==SQLITE_OK ){ |
| 116648 | 115861 | if( iUpper>iLower ){ |
| 116649 | 115862 | nNew = sqlite3LogEst(iUpper - iLower); |
| 116650 | | - /* TUNING: If both iUpper and iLower are derived from the same |
| 116651 | | - ** sample, then assume they are 4x more selective. This brings |
| 116652 | | - ** the estimated selectivity more in line with what it would be |
| 116653 | | - ** if estimated without the use of STAT3/4 tables. */ |
| 116654 | | - if( iLwrIdx==iUprIdx ) nNew -= 20; assert( 20==sqlite3LogEst(4) ); |
| 116655 | 115863 | }else{ |
| 116656 | 115864 | nNew = 10; assert( 10==sqlite3LogEst(2) ); |
| 116657 | 115865 | } |
| 116658 | 115866 | if( nNew<nOut ){ |
| 116659 | 115867 | nOut = nNew; |
| | @@ -116674,19 +115882,16 @@ |
| 116674 | 115882 | #endif |
| 116675 | 115883 | assert( pUpper==0 || (pUpper->wtFlags & TERM_VNULL)==0 ); |
| 116676 | 115884 | nNew = whereRangeAdjust(pLower, nOut); |
| 116677 | 115885 | nNew = whereRangeAdjust(pUpper, nNew); |
| 116678 | 115886 | |
| 116679 | | - /* TUNING: If there is both an upper and lower limit and neither limit |
| 116680 | | - ** has an application-defined likelihood(), assume the range is |
| 115887 | + /* TUNING: If there is both an upper and lower limit, assume the range is |
| 116681 | 115888 | ** reduced by an additional 75%. This means that, by default, an open-ended |
| 116682 | 115889 | ** range query (e.g. col > ?) is assumed to match 1/4 of the rows in the |
| 116683 | 115890 | ** index. While a closed range (e.g. col BETWEEN ? AND ?) is estimated to |
| 116684 | 115891 | ** match 1/64 of the index. */ |
| 116685 | | - if( pLower && pLower->truthProb>0 && pUpper && pUpper->truthProb>0 ){ |
| 116686 | | - nNew -= 20; |
| 116687 | | - } |
| 115892 | + if( pLower && pUpper ) nNew -= 20; |
| 116688 | 115893 | |
| 116689 | 115894 | nOut -= (pLower!=0) + (pUpper!=0); |
| 116690 | 115895 | if( nNew<10 ) nNew = 10; |
| 116691 | 115896 | if( nNew<nOut ) nOut = nNew; |
| 116692 | 115897 | #if defined(WHERETRACE_ENABLED) |
| | @@ -117042,11 +116247,11 @@ |
| 117042 | 116247 | |
| 117043 | 116248 | /* This module is only called on query plans that use an index. */ |
| 117044 | 116249 | pLoop = pLevel->pWLoop; |
| 117045 | 116250 | assert( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 ); |
| 117046 | 116251 | nEq = pLoop->u.btree.nEq; |
| 117047 | | - nSkip = pLoop->nSkip; |
| 116252 | + nSkip = pLoop->u.btree.nSkip; |
| 117048 | 116253 | pIdx = pLoop->u.btree.pIndex; |
| 117049 | 116254 | assert( pIdx!=0 ); |
| 117050 | 116255 | |
| 117051 | 116256 | /* Figure out how many memory cells we will need then allocate them. |
| 117052 | 116257 | */ |
| | @@ -117156,11 +116361,11 @@ |
| 117156 | 116361 | ** "a=? AND b>?" |
| 117157 | 116362 | */ |
| 117158 | 116363 | static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){ |
| 117159 | 116364 | Index *pIndex = pLoop->u.btree.pIndex; |
| 117160 | 116365 | u16 nEq = pLoop->u.btree.nEq; |
| 117161 | | - u16 nSkip = pLoop->nSkip; |
| 116366 | + u16 nSkip = pLoop->u.btree.nSkip; |
| 117162 | 116367 | int i, j; |
| 117163 | 116368 | Column *aCol = pTab->aCol; |
| 117164 | 116369 | i16 *aiColumn = pIndex->aiColumn; |
| 117165 | 116370 | |
| 117166 | 116371 | if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return; |
| | @@ -117187,27 +116392,23 @@ |
| 117187 | 116392 | sqlite3StrAccumAppend(pStr, ")", 1); |
| 117188 | 116393 | } |
| 117189 | 116394 | |
| 117190 | 116395 | /* |
| 117191 | 116396 | ** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN |
| 117192 | | -** command, or if either SQLITE_DEBUG or SQLITE_ENABLE_STMT_SCANSTATUS was |
| 117193 | | -** defined at compile-time. If it is not a no-op, a single OP_Explain opcode |
| 117194 | | -** is added to the output to describe the table scan strategy in pLevel. |
| 117195 | | -** |
| 117196 | | -** If an OP_Explain opcode is added to the VM, its address is returned. |
| 117197 | | -** Otherwise, if no OP_Explain is coded, zero is returned. |
| 116397 | +** command. If the query being compiled is an EXPLAIN QUERY PLAN, a single |
| 116398 | +** record is added to the output to describe the table scan strategy in |
| 116399 | +** pLevel. |
| 117198 | 116400 | */ |
| 117199 | | -static int explainOneScan( |
| 116401 | +static void explainOneScan( |
| 117200 | 116402 | Parse *pParse, /* Parse context */ |
| 117201 | 116403 | SrcList *pTabList, /* Table list this loop refers to */ |
| 117202 | 116404 | WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */ |
| 117203 | 116405 | int iLevel, /* Value for "level" column of output */ |
| 117204 | 116406 | int iFrom, /* Value for "from" column of output */ |
| 117205 | 116407 | u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */ |
| 117206 | 116408 | ){ |
| 117207 | | - int ret = 0; |
| 117208 | | -#if !defined(SQLITE_DEBUG) && !defined(SQLITE_ENABLE_STMT_SCANSTATUS) |
| 116409 | +#ifndef SQLITE_DEBUG |
| 117209 | 116410 | if( pParse->explain==2 ) |
| 117210 | 116411 | #endif |
| 117211 | 116412 | { |
| 117212 | 116413 | struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom]; |
| 117213 | 116414 | Vdbe *v = pParse->pVdbe; /* VM being constructed */ |
| | @@ -117220,11 +116421,11 @@ |
| 117220 | 116421 | StrAccum str; /* EQP output string */ |
| 117221 | 116422 | char zBuf[100]; /* Initial space for EQP output string */ |
| 117222 | 116423 | |
| 117223 | 116424 | pLoop = pLevel->pWLoop; |
| 117224 | 116425 | flags = pLoop->wsFlags; |
| 117225 | | - if( (flags&WHERE_MULTI_OR) || (wctrlFlags&WHERE_ONETABLE_ONLY) ) return 0; |
| 116426 | + if( (flags&WHERE_MULTI_OR) || (wctrlFlags&WHERE_ONETABLE_ONLY) ) return; |
| 117226 | 116427 | |
| 117227 | 116428 | isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0 |
| 117228 | 116429 | || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0)) |
| 117229 | 116430 | || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX)); |
| 117230 | 116431 | |
| | @@ -117249,12 +116450,10 @@ |
| 117249 | 116450 | assert( !(flags&WHERE_AUTO_INDEX) || (flags&WHERE_IDX_ONLY) ); |
| 117250 | 116451 | if( !HasRowid(pItem->pTab) && IsPrimaryKeyIndex(pIdx) ){ |
| 117251 | 116452 | if( isSearch ){ |
| 117252 | 116453 | zFmt = "PRIMARY KEY"; |
| 117253 | 116454 | } |
| 117254 | | - }else if( flags & WHERE_PARTIALIDX ){ |
| 117255 | | - zFmt = "AUTOMATIC PARTIAL COVERING INDEX"; |
| 117256 | 116455 | }else if( flags & WHERE_AUTO_INDEX ){ |
| 117257 | 116456 | zFmt = "AUTOMATIC COVERING INDEX"; |
| 117258 | 116457 | }else if( flags & WHERE_IDX_ONLY ){ |
| 117259 | 116458 | zFmt = "COVERING INDEX %s"; |
| 117260 | 116459 | }else{ |
| | @@ -117292,49 +116491,16 @@ |
| 117292 | 116491 | }else{ |
| 117293 | 116492 | sqlite3StrAccumAppend(&str, " (~1 row)", 9); |
| 117294 | 116493 | } |
| 117295 | 116494 | #endif |
| 117296 | 116495 | zMsg = sqlite3StrAccumFinish(&str); |
| 117297 | | - ret = sqlite3VdbeAddOp4(v, OP_Explain, iId, iLevel, iFrom, zMsg,P4_DYNAMIC); |
| 117298 | | - } |
| 117299 | | - return ret; |
| 117300 | | -} |
| 117301 | | -#else |
| 117302 | | -# define explainOneScan(u,v,w,x,y,z) 0 |
| 117303 | | -#endif /* SQLITE_OMIT_EXPLAIN */ |
| 117304 | | - |
| 117305 | | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 117306 | | -/* |
| 117307 | | -** Configure the VM passed as the first argument with an |
| 117308 | | -** sqlite3_stmt_scanstatus() entry corresponding to the scan used to |
| 117309 | | -** implement level pLvl. Argument pSrclist is a pointer to the FROM |
| 117310 | | -** clause that the scan reads data from. |
| 117311 | | -** |
| 117312 | | -** If argument addrExplain is not 0, it must be the address of an |
| 117313 | | -** OP_Explain instruction that describes the same loop. |
| 117314 | | -*/ |
| 117315 | | -static void addScanStatus( |
| 117316 | | - Vdbe *v, /* Vdbe to add scanstatus entry to */ |
| 117317 | | - SrcList *pSrclist, /* FROM clause pLvl reads data from */ |
| 117318 | | - WhereLevel *pLvl, /* Level to add scanstatus() entry for */ |
| 117319 | | - int addrExplain /* Address of OP_Explain (or 0) */ |
| 117320 | | -){ |
| 117321 | | - const char *zObj = 0; |
| 117322 | | - WhereLoop *pLoop = pLvl->pWLoop; |
| 117323 | | - if( (pLoop->wsFlags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){ |
| 117324 | | - zObj = pLoop->u.btree.pIndex->zName; |
| 117325 | | - }else{ |
| 117326 | | - zObj = pSrclist->a[pLvl->iFrom].zName; |
| 117327 | | - } |
| 117328 | | - sqlite3VdbeScanStatus( |
| 117329 | | - v, addrExplain, pLvl->addrBody, pLvl->addrVisit, pLoop->nOut, zObj |
| 117330 | | - ); |
| 117331 | | -} |
| 117332 | | -#else |
| 117333 | | -# define addScanStatus(a, b, c, d) ((void)d) |
| 117334 | | -#endif |
| 117335 | | - |
| 116496 | + sqlite3VdbeAddOp4(v, OP_Explain, iId, iLevel, iFrom, zMsg, P4_DYNAMIC); |
| 116497 | + } |
| 116498 | +} |
| 116499 | +#else |
| 116500 | +# define explainOneScan(u,v,w,x,y,z) |
| 116501 | +#endif /* SQLITE_OMIT_EXPLAIN */ |
| 117336 | 116502 | |
| 117337 | 116503 | |
| 117338 | 116504 | /* |
| 117339 | 116505 | ** Generate code for the start of the iLevel-th loop in the WHERE clause |
| 117340 | 116506 | ** implementation described by pWInfo. |
| | @@ -117632,11 +116798,11 @@ |
| 117632 | 116798 | u8 bSeekPastNull = 0; /* True to seek past initial nulls */ |
| 117633 | 116799 | u8 bStopAtNull = 0; /* Add condition to terminate at NULLs */ |
| 117634 | 116800 | |
| 117635 | 116801 | pIdx = pLoop->u.btree.pIndex; |
| 117636 | 116802 | iIdxCur = pLevel->iIdxCur; |
| 117637 | | - assert( nEq>=pLoop->nSkip ); |
| 116803 | + assert( nEq>=pLoop->u.btree.nSkip ); |
| 117638 | 116804 | |
| 117639 | 116805 | /* If this loop satisfies a sort order (pOrderBy) request that |
| 117640 | 116806 | ** was passed to this function to implement a "SELECT min(x) ..." |
| 117641 | 116807 | ** query, then the caller will only allow the loop to run for |
| 117642 | 116808 | ** a single iteration. This means that the first row returned |
| | @@ -117649,11 +116815,11 @@ |
| 117649 | 116815 | || (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0 ); |
| 117650 | 116816 | if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0 |
| 117651 | 116817 | && pWInfo->nOBSat>0 |
| 117652 | 116818 | && (pIdx->nKeyCol>nEq) |
| 117653 | 116819 | ){ |
| 117654 | | - assert( pLoop->nSkip==0 ); |
| 116820 | + assert( pLoop->u.btree.nSkip==0 ); |
| 117655 | 116821 | bSeekPastNull = 1; |
| 117656 | 116822 | nExtraReg = 1; |
| 117657 | 116823 | } |
| 117658 | 116824 | |
| 117659 | 116825 | /* Find any inequality constraint terms for the start and end |
| | @@ -117998,15 +117164,13 @@ |
| 117998 | 117164 | pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0, |
| 117999 | 117165 | wctrlFlags, iCovCur); |
| 118000 | 117166 | assert( pSubWInfo || pParse->nErr || db->mallocFailed ); |
| 118001 | 117167 | if( pSubWInfo ){ |
| 118002 | 117168 | WhereLoop *pSubLoop; |
| 118003 | | - int addrExplain = explainOneScan( |
| 117169 | + explainOneScan( |
| 118004 | 117170 | pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0 |
| 118005 | 117171 | ); |
| 118006 | | - addScanStatus(v, pOrTab, &pSubWInfo->a[0], addrExplain); |
| 118007 | | - |
| 118008 | 117172 | /* This is the sub-WHERE clause body. First skip over |
| 118009 | 117173 | ** duplicate rows from prior sub-WHERE clauses, and record the |
| 118010 | 117174 | ** rowid (or PRIMARY KEY) for the current row so that the same |
| 118011 | 117175 | ** row will be skipped in subsequent sub-WHERE clauses. |
| 118012 | 117176 | */ |
| | @@ -118133,14 +117297,10 @@ |
| 118133 | 117297 | VdbeCoverageIf(v, bRev!=0); |
| 118134 | 117298 | pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP; |
| 118135 | 117299 | } |
| 118136 | 117300 | } |
| 118137 | 117301 | |
| 118138 | | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 118139 | | - pLevel->addrVisit = sqlite3VdbeCurrentAddr(v); |
| 118140 | | -#endif |
| 118141 | | - |
| 118142 | 117302 | /* Insert code to test every subexpression that can be completely |
| 118143 | 117303 | ** computed using the current set of tables. |
| 118144 | 117304 | */ |
| 118145 | 117305 | for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){ |
| 118146 | 117306 | Expr *pE; |
| | @@ -118276,11 +117436,11 @@ |
| 118276 | 117436 | } |
| 118277 | 117437 | sqlite3DebugPrintf(" %-19s", z); |
| 118278 | 117438 | sqlite3_free(z); |
| 118279 | 117439 | } |
| 118280 | 117440 | if( p->wsFlags & WHERE_SKIPSCAN ){ |
| 118281 | | - sqlite3DebugPrintf(" f %05x %d-%d", p->wsFlags, p->nLTerm,p->nSkip); |
| 117441 | + sqlite3DebugPrintf(" f %05x %d-%d", p->wsFlags, p->nLTerm,p->u.btree.nSkip); |
| 118282 | 117442 | }else{ |
| 118283 | 117443 | sqlite3DebugPrintf(" f %05x N %d", p->wsFlags, p->nLTerm); |
| 118284 | 117444 | } |
| 118285 | 117445 | sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut); |
| 118286 | 117446 | if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){ |
| | @@ -118387,41 +117547,34 @@ |
| 118387 | 117547 | sqlite3DbFree(db, pWInfo); |
| 118388 | 117548 | } |
| 118389 | 117549 | } |
| 118390 | 117550 | |
| 118391 | 117551 | /* |
| 118392 | | -** Return TRUE if all of the following are true: |
| 117552 | +** Return TRUE if both of the following are true: |
| 118393 | 117553 | ** |
| 118394 | 117554 | ** (1) X has the same or lower cost that Y |
| 118395 | 117555 | ** (2) X is a proper subset of Y |
| 118396 | | -** (3) X skips at least as many columns as Y |
| 118397 | 117556 | ** |
| 118398 | 117557 | ** By "proper subset" we mean that X uses fewer WHERE clause terms |
| 118399 | 117558 | ** than Y and that every WHERE clause term used by X is also used |
| 118400 | 117559 | ** by Y. |
| 118401 | 117560 | ** |
| 118402 | 117561 | ** If X is a proper subset of Y then Y is a better choice and ought |
| 118403 | 117562 | ** to have a lower cost. This routine returns TRUE when that cost |
| 118404 | | -** relationship is inverted and needs to be adjusted. The third rule |
| 118405 | | -** was added because if X uses skip-scan less than Y it still might |
| 118406 | | -** deserve a lower cost even if it is a proper subset of Y. |
| 117563 | +** relationship is inverted and needs to be adjusted. |
| 118407 | 117564 | */ |
| 118408 | 117565 | static int whereLoopCheaperProperSubset( |
| 118409 | 117566 | const WhereLoop *pX, /* First WhereLoop to compare */ |
| 118410 | 117567 | const WhereLoop *pY /* Compare against this WhereLoop */ |
| 118411 | 117568 | ){ |
| 118412 | 117569 | int i, j; |
| 118413 | | - if( pX->nLTerm-pX->nSkip >= pY->nLTerm-pY->nSkip ){ |
| 118414 | | - return 0; /* X is not a subset of Y */ |
| 118415 | | - } |
| 118416 | | - if( pY->nSkip > pX->nSkip ) return 0; |
| 117570 | + if( pX->nLTerm >= pY->nLTerm ) return 0; /* X is not a subset of Y */ |
| 118417 | 117571 | if( pX->rRun >= pY->rRun ){ |
| 118418 | 117572 | if( pX->rRun > pY->rRun ) return 0; /* X costs more than Y */ |
| 118419 | 117573 | if( pX->nOut > pY->nOut ) return 0; /* X costs more than Y */ |
| 118420 | 117574 | } |
| 118421 | 117575 | for(i=pX->nLTerm-1; i>=0; i--){ |
| 118422 | | - if( pX->aLTerm[i]==0 ) continue; |
| 118423 | 117576 | for(j=pY->nLTerm-1; j>=0; j--){ |
| 118424 | 117577 | if( pY->aLTerm[j]==pX->aLTerm[i] ) break; |
| 118425 | 117578 | } |
| 118426 | 117579 | if( j<0 ) return 0; /* X not a subset of Y since term X[i] not used by Y */ |
| 118427 | 117580 | } |
| | @@ -118439,28 +117592,37 @@ |
| 118439 | 117592 | ** is a proper subset. |
| 118440 | 117593 | ** |
| 118441 | 117594 | ** To say "WhereLoop X is a proper subset of Y" means that X uses fewer |
| 118442 | 117595 | ** WHERE clause terms than Y and that every WHERE clause term used by X is |
| 118443 | 117596 | ** also used by Y. |
| 117597 | +** |
| 117598 | +** This adjustment is omitted for SKIPSCAN loops. In a SKIPSCAN loop, the |
| 117599 | +** WhereLoop.nLTerm field is not an accurate measure of the number of WHERE |
| 117600 | +** clause terms covered, since some of the first nLTerm entries in aLTerm[] |
| 117601 | +** will be NULL (because they are skipped). That makes it more difficult |
| 117602 | +** to compare the loops. We could add extra code to do the comparison, and |
| 117603 | +** perhaps we will someday. But SKIPSCAN is sufficiently uncommon, and this |
| 117604 | +** adjustment is sufficient minor, that it is very difficult to construct |
| 117605 | +** a test case where the extra code would improve the query plan. Better |
| 117606 | +** to avoid the added complexity and just omit cost adjustments to SKIPSCAN |
| 117607 | +** loops. |
| 118444 | 117608 | */ |
| 118445 | 117609 | static void whereLoopAdjustCost(const WhereLoop *p, WhereLoop *pTemplate){ |
| 118446 | 117610 | if( (pTemplate->wsFlags & WHERE_INDEXED)==0 ) return; |
| 117611 | + if( (pTemplate->wsFlags & WHERE_SKIPSCAN)!=0 ) return; |
| 118447 | 117612 | for(; p; p=p->pNextLoop){ |
| 118448 | 117613 | if( p->iTab!=pTemplate->iTab ) continue; |
| 118449 | 117614 | if( (p->wsFlags & WHERE_INDEXED)==0 ) continue; |
| 117615 | + if( (p->wsFlags & WHERE_SKIPSCAN)!=0 ) continue; |
| 118450 | 117616 | if( whereLoopCheaperProperSubset(p, pTemplate) ){ |
| 118451 | 117617 | /* Adjust pTemplate cost downward so that it is cheaper than its |
| 118452 | | - ** subset p. */ |
| 118453 | | - WHERETRACE(0x80,("subset cost adjustment %d,%d to %d,%d\n", |
| 118454 | | - pTemplate->rRun, pTemplate->nOut, p->rRun, p->nOut-1)); |
| 117618 | + ** subset p */ |
| 118455 | 117619 | pTemplate->rRun = p->rRun; |
| 118456 | 117620 | pTemplate->nOut = p->nOut - 1; |
| 118457 | 117621 | }else if( whereLoopCheaperProperSubset(pTemplate, p) ){ |
| 118458 | 117622 | /* Adjust pTemplate cost upward so that it is costlier than p since |
| 118459 | 117623 | ** pTemplate is a proper subset of p */ |
| 118460 | | - WHERETRACE(0x80,("subset cost adjustment %d,%d to %d,%d\n", |
| 118461 | | - pTemplate->rRun, pTemplate->nOut, p->rRun, p->nOut+1)); |
| 118462 | 117624 | pTemplate->rRun = p->rRun; |
| 118463 | 117625 | pTemplate->nOut = p->nOut + 1; |
| 118464 | 117626 | } |
| 118465 | 117627 | } |
| 118466 | 117628 | } |
| | @@ -118742,11 +117904,11 @@ |
| 118742 | 117904 | int opMask; /* Valid operators for constraints */ |
| 118743 | 117905 | WhereScan scan; /* Iterator for WHERE terms */ |
| 118744 | 117906 | Bitmask saved_prereq; /* Original value of pNew->prereq */ |
| 118745 | 117907 | u16 saved_nLTerm; /* Original value of pNew->nLTerm */ |
| 118746 | 117908 | u16 saved_nEq; /* Original value of pNew->u.btree.nEq */ |
| 118747 | | - u16 saved_nSkip; /* Original value of pNew->nSkip */ |
| 117909 | + u16 saved_nSkip; /* Original value of pNew->u.btree.nSkip */ |
| 118748 | 117910 | u32 saved_wsFlags; /* Original value of pNew->wsFlags */ |
| 118749 | 117911 | LogEst saved_nOut; /* Original value of pNew->nOut */ |
| 118750 | 117912 | int iCol; /* Index of the column in the table */ |
| 118751 | 117913 | int rc = SQLITE_OK; /* Return code */ |
| 118752 | 117914 | LogEst rSize; /* Number of rows in the table */ |
| | @@ -118771,18 +117933,56 @@ |
| 118771 | 117933 | iCol = pProbe->aiColumn[pNew->u.btree.nEq]; |
| 118772 | 117934 | |
| 118773 | 117935 | pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, iCol, |
| 118774 | 117936 | opMask, pProbe); |
| 118775 | 117937 | saved_nEq = pNew->u.btree.nEq; |
| 118776 | | - saved_nSkip = pNew->nSkip; |
| 117938 | + saved_nSkip = pNew->u.btree.nSkip; |
| 118777 | 117939 | saved_nLTerm = pNew->nLTerm; |
| 118778 | 117940 | saved_wsFlags = pNew->wsFlags; |
| 118779 | 117941 | saved_prereq = pNew->prereq; |
| 118780 | 117942 | saved_nOut = pNew->nOut; |
| 118781 | 117943 | pNew->rSetup = 0; |
| 118782 | 117944 | rSize = pProbe->aiRowLogEst[0]; |
| 118783 | 117945 | rLogSize = estLog(rSize); |
| 117946 | + |
| 117947 | + /* Consider using a skip-scan if there are no WHERE clause constraints |
| 117948 | + ** available for the left-most terms of the index, and if the average |
| 117949 | + ** number of repeats in the left-most terms is at least 18. |
| 117950 | + ** |
| 117951 | + ** The magic number 18 is selected on the basis that scanning 17 rows |
| 117952 | + ** is almost always quicker than an index seek (even though if the index |
| 117953 | + ** contains fewer than 2^17 rows we assume otherwise in other parts of |
| 117954 | + ** the code). And, even if it is not, it should not be too much slower. |
| 117955 | + ** On the other hand, the extra seeks could end up being significantly |
| 117956 | + ** more expensive. */ |
| 117957 | + assert( 42==sqlite3LogEst(18) ); |
| 117958 | + if( saved_nEq==saved_nSkip |
| 117959 | + && saved_nEq+1<pProbe->nKeyCol |
| 117960 | + && pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */ |
| 117961 | + && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK |
| 117962 | + ){ |
| 117963 | + LogEst nIter; |
| 117964 | + pNew->u.btree.nEq++; |
| 117965 | + pNew->u.btree.nSkip++; |
| 117966 | + pNew->aLTerm[pNew->nLTerm++] = 0; |
| 117967 | + pNew->wsFlags |= WHERE_SKIPSCAN; |
| 117968 | + nIter = pProbe->aiRowLogEst[saved_nEq] - pProbe->aiRowLogEst[saved_nEq+1]; |
| 117969 | + if( pTerm ){ |
| 117970 | + /* TUNING: When estimating skip-scan for a term that is also indexable, |
| 117971 | + ** multiply the cost of the skip-scan by 2.0, to make it a little less |
| 117972 | + ** desirable than the regular index lookup. */ |
| 117973 | + nIter += 10; assert( 10==sqlite3LogEst(2) ); |
| 117974 | + } |
| 117975 | + pNew->nOut -= nIter; |
| 117976 | + /* TUNING: Because uncertainties in the estimates for skip-scan queries, |
| 117977 | + ** add a 1.375 fudge factor to make skip-scan slightly less likely. */ |
| 117978 | + nIter += 5; |
| 117979 | + whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nIter + nInMul); |
| 117980 | + pNew->nOut = saved_nOut; |
| 117981 | + pNew->u.btree.nEq = saved_nEq; |
| 117982 | + pNew->u.btree.nSkip = saved_nSkip; |
| 117983 | + } |
| 118784 | 117984 | for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){ |
| 118785 | 117985 | u16 eOp = pTerm->eOperator; /* Shorthand for pTerm->eOperator */ |
| 118786 | 117986 | LogEst rCostIdx; |
| 118787 | 117987 | LogEst nOutUnadjusted; /* nOut before IN() and WHERE adjustments */ |
| 118788 | 117988 | int nIn = 0; |
| | @@ -118873,10 +118073,11 @@ |
| 118873 | 118073 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 118874 | 118074 | tRowcnt nOut = 0; |
| 118875 | 118075 | if( nInMul==0 |
| 118876 | 118076 | && pProbe->nSample |
| 118877 | 118077 | && pNew->u.btree.nEq<=pProbe->nSampleCol |
| 118078 | + && OptimizationEnabled(db, SQLITE_Stat3) |
| 118878 | 118079 | && ((eOp & WO_IN)==0 || !ExprHasProperty(pTerm->pExpr, EP_xIsSelect)) |
| 118879 | 118080 | ){ |
| 118880 | 118081 | Expr *pExpr = pTerm->pExpr; |
| 118881 | 118082 | if( (eOp & (WO_EQ|WO_ISNULL))!=0 ){ |
| 118882 | 118083 | testcase( eOp & WO_EQ ); |
| | @@ -118940,48 +118141,14 @@ |
| 118940 | 118141 | pBuilder->nRecValid = nRecValid; |
| 118941 | 118142 | #endif |
| 118942 | 118143 | } |
| 118943 | 118144 | pNew->prereq = saved_prereq; |
| 118944 | 118145 | pNew->u.btree.nEq = saved_nEq; |
| 118945 | | - pNew->nSkip = saved_nSkip; |
| 118146 | + pNew->u.btree.nSkip = saved_nSkip; |
| 118946 | 118147 | pNew->wsFlags = saved_wsFlags; |
| 118947 | 118148 | pNew->nOut = saved_nOut; |
| 118948 | 118149 | pNew->nLTerm = saved_nLTerm; |
| 118949 | | - |
| 118950 | | - /* Consider using a skip-scan if there are no WHERE clause constraints |
| 118951 | | - ** available for the left-most terms of the index, and if the average |
| 118952 | | - ** number of repeats in the left-most terms is at least 18. |
| 118953 | | - ** |
| 118954 | | - ** The magic number 18 is selected on the basis that scanning 17 rows |
| 118955 | | - ** is almost always quicker than an index seek (even though if the index |
| 118956 | | - ** contains fewer than 2^17 rows we assume otherwise in other parts of |
| 118957 | | - ** the code). And, even if it is not, it should not be too much slower. |
| 118958 | | - ** On the other hand, the extra seeks could end up being significantly |
| 118959 | | - ** more expensive. */ |
| 118960 | | - assert( 42==sqlite3LogEst(18) ); |
| 118961 | | - if( saved_nEq==saved_nSkip |
| 118962 | | - && saved_nEq+1<pProbe->nKeyCol |
| 118963 | | - && pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */ |
| 118964 | | - && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK |
| 118965 | | - ){ |
| 118966 | | - LogEst nIter; |
| 118967 | | - pNew->u.btree.nEq++; |
| 118968 | | - pNew->nSkip++; |
| 118969 | | - pNew->aLTerm[pNew->nLTerm++] = 0; |
| 118970 | | - pNew->wsFlags |= WHERE_SKIPSCAN; |
| 118971 | | - nIter = pProbe->aiRowLogEst[saved_nEq] - pProbe->aiRowLogEst[saved_nEq+1]; |
| 118972 | | - pNew->nOut -= nIter; |
| 118973 | | - /* TUNING: Because uncertainties in the estimates for skip-scan queries, |
| 118974 | | - ** add a 1.375 fudge factor to make skip-scan slightly less likely. */ |
| 118975 | | - nIter += 5; |
| 118976 | | - whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nIter + nInMul); |
| 118977 | | - pNew->nOut = saved_nOut; |
| 118978 | | - pNew->u.btree.nEq = saved_nEq; |
| 118979 | | - pNew->nSkip = saved_nSkip; |
| 118980 | | - pNew->wsFlags = saved_wsFlags; |
| 118981 | | - } |
| 118982 | | - |
| 118983 | 118150 | return rc; |
| 118984 | 118151 | } |
| 118985 | 118152 | |
| 118986 | 118153 | /* |
| 118987 | 118154 | ** Return True if it is possible that pIndex might be useful in |
| | @@ -119156,11 +118323,11 @@ |
| 119156 | 118323 | WhereTerm *pWCEnd = pWC->a + pWC->nTerm; |
| 119157 | 118324 | for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){ |
| 119158 | 118325 | if( pTerm->prereqRight & pNew->maskSelf ) continue; |
| 119159 | 118326 | if( termCanDriveIndex(pTerm, pSrc, 0) ){ |
| 119160 | 118327 | pNew->u.btree.nEq = 1; |
| 119161 | | - pNew->nSkip = 0; |
| 118328 | + pNew->u.btree.nSkip = 0; |
| 119162 | 118329 | pNew->u.btree.pIndex = 0; |
| 119163 | 118330 | pNew->nLTerm = 1; |
| 119164 | 118331 | pNew->aLTerm[0] = pTerm; |
| 119165 | 118332 | /* TUNING: One-time cost for computing the automatic index is |
| 119166 | 118333 | ** estimated to be X*N*log2(N) where N is the number of rows in |
| | @@ -119197,11 +118364,11 @@ |
| 119197 | 118364 | testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */ |
| 119198 | 118365 | continue; /* Partial index inappropriate for this query */ |
| 119199 | 118366 | } |
| 119200 | 118367 | rSize = pProbe->aiRowLogEst[0]; |
| 119201 | 118368 | pNew->u.btree.nEq = 0; |
| 119202 | | - pNew->nSkip = 0; |
| 118369 | + pNew->u.btree.nSkip = 0; |
| 119203 | 118370 | pNew->nLTerm = 0; |
| 119204 | 118371 | pNew->iSortIdx = 0; |
| 119205 | 118372 | pNew->rSetup = 0; |
| 119206 | 118373 | pNew->prereq = mExtra; |
| 119207 | 118374 | pNew->nOut = rSize; |
| | @@ -119747,11 +118914,11 @@ |
| 119747 | 118914 | for(j=0; j<nColumn; j++){ |
| 119748 | 118915 | u8 bOnce; /* True to run the ORDER BY search loop */ |
| 119749 | 118916 | |
| 119750 | 118917 | /* Skip over == and IS NULL terms */ |
| 119751 | 118918 | if( j<pLoop->u.btree.nEq |
| 119752 | | - && pLoop->nSkip==0 |
| 118919 | + && pLoop->u.btree.nSkip==0 |
| 119753 | 118920 | && ((i = pLoop->aLTerm[j]->eOperator) & (WO_EQ|WO_ISNULL))!=0 |
| 119754 | 118921 | ){ |
| 119755 | 118922 | if( i & WO_ISNULL ){ |
| 119756 | 118923 | testcase( isOrderDistinct ); |
| 119757 | 118924 | isOrderDistinct = 0; |
| | @@ -120201,11 +119368,11 @@ |
| 120201 | 119368 | } |
| 120202 | 119369 | } |
| 120203 | 119370 | } |
| 120204 | 119371 | |
| 120205 | 119372 | #ifdef WHERETRACE_ENABLED /* >=2 */ |
| 120206 | | - if( sqlite3WhereTrace & 0x02 ){ |
| 119373 | + if( sqlite3WhereTrace>=2 ){ |
| 120207 | 119374 | sqlite3DebugPrintf("---- after round %d ----\n", iLoop); |
| 120208 | 119375 | for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){ |
| 120209 | 119376 | sqlite3DebugPrintf(" %s cost=%-3d nrow=%-3d order=%c", |
| 120210 | 119377 | wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow, |
| 120211 | 119378 | pTo->isOrdered>=0 ? (pTo->isOrdered+'0') : '?'); |
| | @@ -120320,11 +119487,11 @@ |
| 120320 | 119487 | if( pItem->zIndex ) return 0; |
| 120321 | 119488 | iCur = pItem->iCursor; |
| 120322 | 119489 | pWC = &pWInfo->sWC; |
| 120323 | 119490 | pLoop = pBuilder->pNew; |
| 120324 | 119491 | pLoop->wsFlags = 0; |
| 120325 | | - pLoop->nSkip = 0; |
| 119492 | + pLoop->u.btree.nSkip = 0; |
| 120326 | 119493 | pTerm = findTerm(pWC, iCur, -1, 0, WO_EQ, 0); |
| 120327 | 119494 | if( pTerm ){ |
| 120328 | 119495 | pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_IPK|WHERE_ONEROW; |
| 120329 | 119496 | pLoop->aLTerm[0] = pTerm; |
| 120330 | 119497 | pLoop->nLTerm = 1; |
| | @@ -120332,10 +119499,11 @@ |
| 120332 | 119499 | /* TUNING: Cost of a rowid lookup is 10 */ |
| 120333 | 119500 | pLoop->rRun = 33; /* 33==sqlite3LogEst(10) */ |
| 120334 | 119501 | }else{ |
| 120335 | 119502 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 120336 | 119503 | assert( pLoop->aLTermSpace==pLoop->aLTerm ); |
| 119504 | + assert( ArraySize(pLoop->aLTermSpace)==4 ); |
| 120337 | 119505 | if( !IsUniqueIndex(pIdx) |
| 120338 | 119506 | || pIdx->pPartIdxWhere!=0 |
| 120339 | 119507 | || pIdx->nKeyCol>ArraySize(pLoop->aLTermSpace) |
| 120340 | 119508 | ) continue; |
| 120341 | 119509 | for(j=0; j<pIdx->nKeyCol; j++){ |
| | @@ -120840,30 +120008,22 @@ |
| 120840 | 120008 | ** loop below generates code for a single nested loop of the VM |
| 120841 | 120009 | ** program. |
| 120842 | 120010 | */ |
| 120843 | 120011 | notReady = ~(Bitmask)0; |
| 120844 | 120012 | for(ii=0; ii<nTabList; ii++){ |
| 120845 | | - int addrExplain; |
| 120846 | | - int wsFlags; |
| 120847 | 120013 | pLevel = &pWInfo->a[ii]; |
| 120848 | | - wsFlags = pLevel->pWLoop->wsFlags; |
| 120849 | 120014 | #ifndef SQLITE_OMIT_AUTOMATIC_INDEX |
| 120850 | 120015 | if( (pLevel->pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){ |
| 120851 | 120016 | constructAutomaticIndex(pParse, &pWInfo->sWC, |
| 120852 | 120017 | &pTabList->a[pLevel->iFrom], notReady, pLevel); |
| 120853 | 120018 | if( db->mallocFailed ) goto whereBeginError; |
| 120854 | 120019 | } |
| 120855 | 120020 | #endif |
| 120856 | | - addrExplain = explainOneScan( |
| 120857 | | - pParse, pTabList, pLevel, ii, pLevel->iFrom, wctrlFlags |
| 120858 | | - ); |
| 120021 | + explainOneScan(pParse, pTabList, pLevel, ii, pLevel->iFrom, wctrlFlags); |
| 120859 | 120022 | pLevel->addrBody = sqlite3VdbeCurrentAddr(v); |
| 120860 | 120023 | notReady = codeOneLoopStart(pWInfo, ii, notReady); |
| 120861 | 120024 | pWInfo->iContinue = pLevel->addrCont; |
| 120862 | | - if( (wsFlags&WHERE_MULTI_OR)==0 && (wctrlFlags&WHERE_ONETABLE_ONLY)==0 ){ |
| 120863 | | - addScanStatus(v, pTabList, pLevel, addrExplain); |
| 120864 | | - } |
| 120865 | 120025 | } |
| 120866 | 120026 | |
| 120867 | 120027 | /* Done. */ |
| 120868 | 120028 | VdbeModuleComment((v, "Begin WHERE-core")); |
| 120869 | 120029 | return pWInfo; |
| | @@ -125528,17 +124688,10 @@ |
| 125528 | 124688 | */ |
| 125529 | 124689 | SQLITE_API int sqlite3_complete(const char *zSql){ |
| 125530 | 124690 | u8 state = 0; /* Current state, using numbers defined in header comment */ |
| 125531 | 124691 | u8 token; /* Value of the next token */ |
| 125532 | 124692 | |
| 125533 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 125534 | | - if( zSql==0 ){ |
| 125535 | | - (void)SQLITE_MISUSE_BKPT; |
| 125536 | | - return 0; |
| 125537 | | - } |
| 125538 | | -#endif |
| 125539 | | - |
| 125540 | 124693 | #ifndef SQLITE_OMIT_TRIGGER |
| 125541 | 124694 | /* A complex statement machine used to detect the end of a CREATE TRIGGER |
| 125542 | 124695 | ** statement. This is the normal case. |
| 125543 | 124696 | */ |
| 125544 | 124697 | static const u8 trans[8][8] = { |
| | @@ -126132,107 +125285,75 @@ |
| 126132 | 125285 | |
| 126133 | 125286 | va_start(ap, op); |
| 126134 | 125287 | switch( op ){ |
| 126135 | 125288 | |
| 126136 | 125289 | /* Mutex configuration options are only available in a threadsafe |
| 126137 | | - ** compile. |
| 125290 | + ** compile. |
| 126138 | 125291 | */ |
| 126139 | | -#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-54466-46756 */ |
| 125292 | +#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 |
| 126140 | 125293 | case SQLITE_CONFIG_SINGLETHREAD: { |
| 126141 | 125294 | /* Disable all mutexing */ |
| 126142 | 125295 | sqlite3GlobalConfig.bCoreMutex = 0; |
| 126143 | 125296 | sqlite3GlobalConfig.bFullMutex = 0; |
| 126144 | 125297 | break; |
| 126145 | 125298 | } |
| 126146 | | -#endif |
| 126147 | | -#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-20520-54086 */ |
| 126148 | 125299 | case SQLITE_CONFIG_MULTITHREAD: { |
| 126149 | 125300 | /* Disable mutexing of database connections */ |
| 126150 | 125301 | /* Enable mutexing of core data structures */ |
| 126151 | 125302 | sqlite3GlobalConfig.bCoreMutex = 1; |
| 126152 | 125303 | sqlite3GlobalConfig.bFullMutex = 0; |
| 126153 | 125304 | break; |
| 126154 | 125305 | } |
| 126155 | | -#endif |
| 126156 | | -#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-59593-21810 */ |
| 126157 | 125306 | case SQLITE_CONFIG_SERIALIZED: { |
| 126158 | 125307 | /* Enable all mutexing */ |
| 126159 | 125308 | sqlite3GlobalConfig.bCoreMutex = 1; |
| 126160 | 125309 | sqlite3GlobalConfig.bFullMutex = 1; |
| 126161 | 125310 | break; |
| 126162 | 125311 | } |
| 126163 | | -#endif |
| 126164 | | -#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-63666-48755 */ |
| 126165 | 125312 | case SQLITE_CONFIG_MUTEX: { |
| 126166 | 125313 | /* Specify an alternative mutex implementation */ |
| 126167 | 125314 | sqlite3GlobalConfig.mutex = *va_arg(ap, sqlite3_mutex_methods*); |
| 126168 | 125315 | break; |
| 126169 | 125316 | } |
| 126170 | | -#endif |
| 126171 | | -#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-14450-37597 */ |
| 126172 | 125317 | case SQLITE_CONFIG_GETMUTEX: { |
| 126173 | 125318 | /* Retrieve the current mutex implementation */ |
| 126174 | 125319 | *va_arg(ap, sqlite3_mutex_methods*) = sqlite3GlobalConfig.mutex; |
| 126175 | 125320 | break; |
| 126176 | 125321 | } |
| 126177 | 125322 | #endif |
| 125323 | + |
| 126178 | 125324 | |
| 126179 | 125325 | case SQLITE_CONFIG_MALLOC: { |
| 126180 | | - /* EVIDENCE-OF: R-55594-21030 The SQLITE_CONFIG_MALLOC option takes a |
| 126181 | | - ** single argument which is a pointer to an instance of the |
| 126182 | | - ** sqlite3_mem_methods structure. The argument specifies alternative |
| 126183 | | - ** low-level memory allocation routines to be used in place of the memory |
| 126184 | | - ** allocation routines built into SQLite. */ |
| 125326 | + /* Specify an alternative malloc implementation */ |
| 126185 | 125327 | sqlite3GlobalConfig.m = *va_arg(ap, sqlite3_mem_methods*); |
| 126186 | 125328 | break; |
| 126187 | 125329 | } |
| 126188 | 125330 | case SQLITE_CONFIG_GETMALLOC: { |
| 126189 | | - /* EVIDENCE-OF: R-51213-46414 The SQLITE_CONFIG_GETMALLOC option takes a |
| 126190 | | - ** single argument which is a pointer to an instance of the |
| 126191 | | - ** sqlite3_mem_methods structure. The sqlite3_mem_methods structure is |
| 126192 | | - ** filled with the currently defined memory allocation routines. */ |
| 125331 | + /* Retrieve the current malloc() implementation */ |
| 126193 | 125332 | if( sqlite3GlobalConfig.m.xMalloc==0 ) sqlite3MemSetDefault(); |
| 126194 | 125333 | *va_arg(ap, sqlite3_mem_methods*) = sqlite3GlobalConfig.m; |
| 126195 | 125334 | break; |
| 126196 | 125335 | } |
| 126197 | 125336 | case SQLITE_CONFIG_MEMSTATUS: { |
| 126198 | | - /* EVIDENCE-OF: R-61275-35157 The SQLITE_CONFIG_MEMSTATUS option takes |
| 126199 | | - ** single argument of type int, interpreted as a boolean, which enables |
| 126200 | | - ** or disables the collection of memory allocation statistics. */ |
| 125337 | + /* Enable or disable the malloc status collection */ |
| 126201 | 125338 | sqlite3GlobalConfig.bMemstat = va_arg(ap, int); |
| 126202 | 125339 | break; |
| 126203 | 125340 | } |
| 126204 | 125341 | case SQLITE_CONFIG_SCRATCH: { |
| 126205 | | - /* EVIDENCE-OF: R-08404-60887 There are three arguments to |
| 126206 | | - ** SQLITE_CONFIG_SCRATCH: A pointer an 8-byte aligned memory buffer from |
| 126207 | | - ** which the scratch allocations will be drawn, the size of each scratch |
| 126208 | | - ** allocation (sz), and the maximum number of scratch allocations (N). */ |
| 125342 | + /* Designate a buffer for scratch memory space */ |
| 126209 | 125343 | sqlite3GlobalConfig.pScratch = va_arg(ap, void*); |
| 126210 | 125344 | sqlite3GlobalConfig.szScratch = va_arg(ap, int); |
| 126211 | 125345 | sqlite3GlobalConfig.nScratch = va_arg(ap, int); |
| 126212 | 125346 | break; |
| 126213 | 125347 | } |
| 126214 | 125348 | case SQLITE_CONFIG_PAGECACHE: { |
| 126215 | | - /* EVIDENCE-OF: R-31408-40510 There are three arguments to |
| 126216 | | - ** SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned memory, the size |
| 126217 | | - ** of each page buffer (sz), and the number of pages (N). */ |
| 125349 | + /* Designate a buffer for page cache memory space */ |
| 126218 | 125350 | sqlite3GlobalConfig.pPage = va_arg(ap, void*); |
| 126219 | 125351 | sqlite3GlobalConfig.szPage = va_arg(ap, int); |
| 126220 | 125352 | sqlite3GlobalConfig.nPage = va_arg(ap, int); |
| 126221 | 125353 | break; |
| 126222 | 125354 | } |
| 126223 | | - case SQLITE_CONFIG_PCACHE_HDRSZ: { |
| 126224 | | - /* EVIDENCE-OF: R-39100-27317 The SQLITE_CONFIG_PCACHE_HDRSZ option takes |
| 126225 | | - ** a single parameter which is a pointer to an integer and writes into |
| 126226 | | - ** that integer the number of extra bytes per page required for each page |
| 126227 | | - ** in SQLITE_CONFIG_PAGECACHE. */ |
| 126228 | | - *va_arg(ap, int*) = |
| 126229 | | - sqlite3HeaderSizeBtree() + |
| 126230 | | - sqlite3HeaderSizePcache() + |
| 126231 | | - sqlite3HeaderSizePcache1(); |
| 126232 | | - break; |
| 126233 | | - } |
| 126234 | 125355 | |
| 126235 | 125356 | case SQLITE_CONFIG_PCACHE: { |
| 126236 | 125357 | /* no-op */ |
| 126237 | 125358 | break; |
| 126238 | 125359 | } |
| | @@ -126241,37 +125362,25 @@ |
| 126241 | 125362 | rc = SQLITE_ERROR; |
| 126242 | 125363 | break; |
| 126243 | 125364 | } |
| 126244 | 125365 | |
| 126245 | 125366 | case SQLITE_CONFIG_PCACHE2: { |
| 126246 | | - /* EVIDENCE-OF: R-63325-48378 The SQLITE_CONFIG_PCACHE2 option takes a |
| 126247 | | - ** single argument which is a pointer to an sqlite3_pcache_methods2 |
| 126248 | | - ** object. This object specifies the interface to a custom page cache |
| 126249 | | - ** implementation. */ |
| 125367 | + /* Specify an alternative page cache implementation */ |
| 126250 | 125368 | sqlite3GlobalConfig.pcache2 = *va_arg(ap, sqlite3_pcache_methods2*); |
| 126251 | 125369 | break; |
| 126252 | 125370 | } |
| 126253 | 125371 | case SQLITE_CONFIG_GETPCACHE2: { |
| 126254 | | - /* EVIDENCE-OF: R-22035-46182 The SQLITE_CONFIG_GETPCACHE2 option takes a |
| 126255 | | - ** single argument which is a pointer to an sqlite3_pcache_methods2 |
| 126256 | | - ** object. SQLite copies of the current page cache implementation into |
| 126257 | | - ** that object. */ |
| 126258 | 125372 | if( sqlite3GlobalConfig.pcache2.xInit==0 ){ |
| 126259 | 125373 | sqlite3PCacheSetDefault(); |
| 126260 | 125374 | } |
| 126261 | 125375 | *va_arg(ap, sqlite3_pcache_methods2*) = sqlite3GlobalConfig.pcache2; |
| 126262 | 125376 | break; |
| 126263 | 125377 | } |
| 126264 | 125378 | |
| 126265 | | -/* EVIDENCE-OF: R-06626-12911 The SQLITE_CONFIG_HEAP option is only |
| 126266 | | -** available if SQLite is compiled with either SQLITE_ENABLE_MEMSYS3 or |
| 126267 | | -** SQLITE_ENABLE_MEMSYS5 and returns SQLITE_ERROR if invoked otherwise. */ |
| 126268 | 125379 | #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5) |
| 126269 | 125380 | case SQLITE_CONFIG_HEAP: { |
| 126270 | | - /* EVIDENCE-OF: R-19854-42126 There are three arguments to |
| 126271 | | - ** SQLITE_CONFIG_HEAP: An 8-byte aligned pointer to the memory, the |
| 126272 | | - ** number of bytes in the memory buffer, and the minimum allocation size. */ |
| 125381 | + /* Designate a buffer for heap memory space */ |
| 126273 | 125382 | sqlite3GlobalConfig.pHeap = va_arg(ap, void*); |
| 126274 | 125383 | sqlite3GlobalConfig.nHeap = va_arg(ap, int); |
| 126275 | 125384 | sqlite3GlobalConfig.mnReq = va_arg(ap, int); |
| 126276 | 125385 | |
| 126277 | 125386 | if( sqlite3GlobalConfig.mnReq<1 ){ |
| | @@ -126280,23 +125389,21 @@ |
| 126280 | 125389 | /* cap min request size at 2^12 */ |
| 126281 | 125390 | sqlite3GlobalConfig.mnReq = (1<<12); |
| 126282 | 125391 | } |
| 126283 | 125392 | |
| 126284 | 125393 | if( sqlite3GlobalConfig.pHeap==0 ){ |
| 126285 | | - /* EVIDENCE-OF: R-49920-60189 If the first pointer (the memory pointer) |
| 126286 | | - ** is NULL, then SQLite reverts to using its default memory allocator |
| 126287 | | - ** (the system malloc() implementation), undoing any prior invocation of |
| 126288 | | - ** SQLITE_CONFIG_MALLOC. |
| 126289 | | - ** |
| 126290 | | - ** Setting sqlite3GlobalConfig.m to all zeros will cause malloc to |
| 126291 | | - ** revert to its default implementation when sqlite3_initialize() is run |
| 125394 | + /* If the heap pointer is NULL, then restore the malloc implementation |
| 125395 | + ** back to NULL pointers too. This will cause the malloc to go |
| 125396 | + ** back to its default implementation when sqlite3_initialize() is |
| 125397 | + ** run. |
| 126292 | 125398 | */ |
| 126293 | 125399 | memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m)); |
| 126294 | 125400 | }else{ |
| 126295 | | - /* EVIDENCE-OF: R-61006-08918 If the memory pointer is not NULL then the |
| 126296 | | - ** alternative memory allocator is engaged to handle all of SQLites |
| 126297 | | - ** memory allocation needs. */ |
| 125401 | + /* The heap pointer is not NULL, then install one of the |
| 125402 | + ** mem5.c/mem3.c methods. The enclosing #if guarantees at |
| 125403 | + ** least one of these methods is currently enabled. |
| 125404 | + */ |
| 126298 | 125405 | #ifdef SQLITE_ENABLE_MEMSYS3 |
| 126299 | 125406 | sqlite3GlobalConfig.m = *sqlite3MemGetMemsys3(); |
| 126300 | 125407 | #endif |
| 126301 | 125408 | #ifdef SQLITE_ENABLE_MEMSYS5 |
| 126302 | 125409 | sqlite3GlobalConfig.m = *sqlite3MemGetMemsys5(); |
| | @@ -126331,23 +125438,15 @@ |
| 126331 | 125438 | ** can be changed at start-time using the |
| 126332 | 125439 | ** sqlite3_config(SQLITE_CONFIG_URI,1) or |
| 126333 | 125440 | ** sqlite3_config(SQLITE_CONFIG_URI,0) configuration calls. |
| 126334 | 125441 | */ |
| 126335 | 125442 | case SQLITE_CONFIG_URI: { |
| 126336 | | - /* EVIDENCE-OF: R-25451-61125 The SQLITE_CONFIG_URI option takes a single |
| 126337 | | - ** argument of type int. If non-zero, then URI handling is globally |
| 126338 | | - ** enabled. If the parameter is zero, then URI handling is globally |
| 126339 | | - ** disabled. */ |
| 126340 | 125443 | sqlite3GlobalConfig.bOpenUri = va_arg(ap, int); |
| 126341 | 125444 | break; |
| 126342 | 125445 | } |
| 126343 | 125446 | |
| 126344 | 125447 | case SQLITE_CONFIG_COVERING_INDEX_SCAN: { |
| 126345 | | - /* EVIDENCE-OF: R-36592-02772 The SQLITE_CONFIG_COVERING_INDEX_SCAN |
| 126346 | | - ** option takes a single integer argument which is interpreted as a |
| 126347 | | - ** boolean in order to enable or disable the use of covering indices for |
| 126348 | | - ** full table scans in the query optimizer. */ |
| 126349 | 125448 | sqlite3GlobalConfig.bUseCis = va_arg(ap, int); |
| 126350 | 125449 | break; |
| 126351 | 125450 | } |
| 126352 | 125451 | |
| 126353 | 125452 | #ifdef SQLITE_ENABLE_SQLLOG |
| | @@ -126358,37 +125457,24 @@ |
| 126358 | 125457 | break; |
| 126359 | 125458 | } |
| 126360 | 125459 | #endif |
| 126361 | 125460 | |
| 126362 | 125461 | case SQLITE_CONFIG_MMAP_SIZE: { |
| 126363 | | - /* EVIDENCE-OF: R-58063-38258 SQLITE_CONFIG_MMAP_SIZE takes two 64-bit |
| 126364 | | - ** integer (sqlite3_int64) values that are the default mmap size limit |
| 126365 | | - ** (the default setting for PRAGMA mmap_size) and the maximum allowed |
| 126366 | | - ** mmap size limit. */ |
| 126367 | 125462 | sqlite3_int64 szMmap = va_arg(ap, sqlite3_int64); |
| 126368 | 125463 | sqlite3_int64 mxMmap = va_arg(ap, sqlite3_int64); |
| 126369 | | - /* EVIDENCE-OF: R-53367-43190 If either argument to this option is |
| 126370 | | - ** negative, then that argument is changed to its compile-time default. |
| 126371 | | - ** |
| 126372 | | - ** EVIDENCE-OF: R-34993-45031 The maximum allowed mmap size will be |
| 126373 | | - ** silently truncated if necessary so that it does not exceed the |
| 126374 | | - ** compile-time maximum mmap size set by the SQLITE_MAX_MMAP_SIZE |
| 126375 | | - ** compile-time option. |
| 126376 | | - */ |
| 126377 | | - if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ) mxMmap = SQLITE_MAX_MMAP_SIZE; |
| 125464 | + if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ){ |
| 125465 | + mxMmap = SQLITE_MAX_MMAP_SIZE; |
| 125466 | + } |
| 125467 | + sqlite3GlobalConfig.mxMmap = mxMmap; |
| 126378 | 125468 | if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE; |
| 126379 | 125469 | if( szMmap>mxMmap) szMmap = mxMmap; |
| 126380 | | - sqlite3GlobalConfig.mxMmap = mxMmap; |
| 126381 | 125470 | sqlite3GlobalConfig.szMmap = szMmap; |
| 126382 | 125471 | break; |
| 126383 | 125472 | } |
| 126384 | 125473 | |
| 126385 | | -#if SQLITE_OS_WIN && defined(SQLITE_WIN32_MALLOC) /* IMP: R-04780-55815 */ |
| 125474 | +#if SQLITE_OS_WIN && defined(SQLITE_WIN32_MALLOC) |
| 126386 | 125475 | case SQLITE_CONFIG_WIN32_HEAPSIZE: { |
| 126387 | | - /* EVIDENCE-OF: R-34926-03360 SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit |
| 126388 | | - ** unsigned integer value that specifies the maximum size of the created |
| 126389 | | - ** heap. */ |
| 126390 | 125476 | sqlite3GlobalConfig.nHeap = va_arg(ap, int); |
| 126391 | 125477 | break; |
| 126392 | 125478 | } |
| 126393 | 125479 | #endif |
| 126394 | 125480 | |
| | @@ -126468,29 +125554,19 @@ |
| 126468 | 125554 | |
| 126469 | 125555 | /* |
| 126470 | 125556 | ** Return the mutex associated with a database connection. |
| 126471 | 125557 | */ |
| 126472 | 125558 | SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){ |
| 126473 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 126474 | | - if( !sqlite3SafetyCheckOk(db) ){ |
| 126475 | | - (void)SQLITE_MISUSE_BKPT; |
| 126476 | | - return 0; |
| 126477 | | - } |
| 126478 | | -#endif |
| 126479 | 125559 | return db->mutex; |
| 126480 | 125560 | } |
| 126481 | 125561 | |
| 126482 | 125562 | /* |
| 126483 | 125563 | ** Free up as much memory as we can from the given database |
| 126484 | 125564 | ** connection. |
| 126485 | 125565 | */ |
| 126486 | 125566 | SQLITE_API int sqlite3_db_release_memory(sqlite3 *db){ |
| 126487 | 125567 | int i; |
| 126488 | | - |
| 126489 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 126490 | | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 126491 | | -#endif |
| 126492 | 125568 | sqlite3_mutex_enter(db->mutex); |
| 126493 | 125569 | sqlite3BtreeEnterAll(db); |
| 126494 | 125570 | for(i=0; i<db->nDb; i++){ |
| 126495 | 125571 | Btree *pBt = db->aDb[i].pBt; |
| 126496 | 125572 | if( pBt ){ |
| | @@ -126617,42 +125693,24 @@ |
| 126617 | 125693 | |
| 126618 | 125694 | /* |
| 126619 | 125695 | ** Return the ROWID of the most recent insert |
| 126620 | 125696 | */ |
| 126621 | 125697 | SQLITE_API sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){ |
| 126622 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 126623 | | - if( !sqlite3SafetyCheckOk(db) ){ |
| 126624 | | - (void)SQLITE_MISUSE_BKPT; |
| 126625 | | - return 0; |
| 126626 | | - } |
| 126627 | | -#endif |
| 126628 | 125698 | return db->lastRowid; |
| 126629 | 125699 | } |
| 126630 | 125700 | |
| 126631 | 125701 | /* |
| 126632 | 125702 | ** Return the number of changes in the most recent call to sqlite3_exec(). |
| 126633 | 125703 | */ |
| 126634 | 125704 | SQLITE_API int sqlite3_changes(sqlite3 *db){ |
| 126635 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 126636 | | - if( !sqlite3SafetyCheckOk(db) ){ |
| 126637 | | - (void)SQLITE_MISUSE_BKPT; |
| 126638 | | - return 0; |
| 126639 | | - } |
| 126640 | | -#endif |
| 126641 | 125705 | return db->nChange; |
| 126642 | 125706 | } |
| 126643 | 125707 | |
| 126644 | 125708 | /* |
| 126645 | 125709 | ** Return the number of changes since the database handle was opened. |
| 126646 | 125710 | */ |
| 126647 | 125711 | SQLITE_API int sqlite3_total_changes(sqlite3 *db){ |
| 126648 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 126649 | | - if( !sqlite3SafetyCheckOk(db) ){ |
| 126650 | | - (void)SQLITE_MISUSE_BKPT; |
| 126651 | | - return 0; |
| 126652 | | - } |
| 126653 | | -#endif |
| 126654 | 125712 | return db->nTotalChange; |
| 126655 | 125713 | } |
| 126656 | 125714 | |
| 126657 | 125715 | /* |
| 126658 | 125716 | ** Close all open savepoints. This function only manipulates fields of the |
| | @@ -127197,13 +126255,10 @@ |
| 127197 | 126255 | SQLITE_API int sqlite3_busy_handler( |
| 127198 | 126256 | sqlite3 *db, |
| 127199 | 126257 | int (*xBusy)(void*,int), |
| 127200 | 126258 | void *pArg |
| 127201 | 126259 | ){ |
| 127202 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 127203 | | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE; |
| 127204 | | -#endif |
| 127205 | 126260 | sqlite3_mutex_enter(db->mutex); |
| 127206 | 126261 | db->busyHandler.xFunc = xBusy; |
| 127207 | 126262 | db->busyHandler.pArg = pArg; |
| 127208 | 126263 | db->busyHandler.nBusy = 0; |
| 127209 | 126264 | db->busyTimeout = 0; |
| | @@ -127221,16 +126276,10 @@ |
| 127221 | 126276 | sqlite3 *db, |
| 127222 | 126277 | int nOps, |
| 127223 | 126278 | int (*xProgress)(void*), |
| 127224 | 126279 | void *pArg |
| 127225 | 126280 | ){ |
| 127226 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 127227 | | - if( !sqlite3SafetyCheckOk(db) ){ |
| 127228 | | - (void)SQLITE_MISUSE_BKPT; |
| 127229 | | - return; |
| 127230 | | - } |
| 127231 | | -#endif |
| 127232 | 126281 | sqlite3_mutex_enter(db->mutex); |
| 127233 | 126282 | if( nOps>0 ){ |
| 127234 | 126283 | db->xProgress = xProgress; |
| 127235 | 126284 | db->nProgressOps = (unsigned)nOps; |
| 127236 | 126285 | db->pProgressArg = pArg; |
| | @@ -127247,13 +126296,10 @@ |
| 127247 | 126296 | /* |
| 127248 | 126297 | ** This routine installs a default busy handler that waits for the |
| 127249 | 126298 | ** specified number of milliseconds before returning 0. |
| 127250 | 126299 | */ |
| 127251 | 126300 | SQLITE_API int sqlite3_busy_timeout(sqlite3 *db, int ms){ |
| 127252 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 127253 | | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 127254 | | -#endif |
| 127255 | 126301 | if( ms>0 ){ |
| 127256 | 126302 | sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db); |
| 127257 | 126303 | db->busyTimeout = ms; |
| 127258 | 126304 | }else{ |
| 127259 | 126305 | sqlite3_busy_handler(db, 0, 0); |
| | @@ -127263,16 +126309,10 @@ |
| 127263 | 126309 | |
| 127264 | 126310 | /* |
| 127265 | 126311 | ** Cause any pending operation to stop at its earliest opportunity. |
| 127266 | 126312 | */ |
| 127267 | 126313 | SQLITE_API void sqlite3_interrupt(sqlite3 *db){ |
| 127268 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 127269 | | - if( !sqlite3SafetyCheckOk(db) ){ |
| 127270 | | - (void)SQLITE_MISUSE_BKPT; |
| 127271 | | - return; |
| 127272 | | - } |
| 127273 | | -#endif |
| 127274 | 126314 | db->u1.isInterrupted = 1; |
| 127275 | 126315 | } |
| 127276 | 126316 | |
| 127277 | 126317 | |
| 127278 | 126318 | /* |
| | @@ -127406,16 +126446,10 @@ |
| 127406 | 126446 | void (*xFinal)(sqlite3_context*), |
| 127407 | 126447 | void (*xDestroy)(void *) |
| 127408 | 126448 | ){ |
| 127409 | 126449 | int rc = SQLITE_ERROR; |
| 127410 | 126450 | FuncDestructor *pArg = 0; |
| 127411 | | - |
| 127412 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 127413 | | - if( !sqlite3SafetyCheckOk(db) ){ |
| 127414 | | - return SQLITE_MISUSE_BKPT; |
| 127415 | | - } |
| 127416 | | -#endif |
| 127417 | 126451 | sqlite3_mutex_enter(db->mutex); |
| 127418 | 126452 | if( xDestroy ){ |
| 127419 | 126453 | pArg = (FuncDestructor *)sqlite3DbMallocZero(db, sizeof(FuncDestructor)); |
| 127420 | 126454 | if( !pArg ){ |
| 127421 | 126455 | xDestroy(p); |
| | @@ -127448,14 +126482,10 @@ |
| 127448 | 126482 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
| 127449 | 126483 | void (*xFinal)(sqlite3_context*) |
| 127450 | 126484 | ){ |
| 127451 | 126485 | int rc; |
| 127452 | 126486 | char *zFunc8; |
| 127453 | | - |
| 127454 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 127455 | | - if( !sqlite3SafetyCheckOk(db) || zFunctionName==0 ) return SQLITE_MISUSE_BKPT; |
| 127456 | | -#endif |
| 127457 | 126487 | sqlite3_mutex_enter(db->mutex); |
| 127458 | 126488 | assert( !db->mallocFailed ); |
| 127459 | 126489 | zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE); |
| 127460 | 126490 | rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal,0); |
| 127461 | 126491 | sqlite3DbFree(db, zFunc8); |
| | @@ -127483,16 +126513,10 @@ |
| 127483 | 126513 | const char *zName, |
| 127484 | 126514 | int nArg |
| 127485 | 126515 | ){ |
| 127486 | 126516 | int nName = sqlite3Strlen30(zName); |
| 127487 | 126517 | int rc = SQLITE_OK; |
| 127488 | | - |
| 127489 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 127490 | | - if( !sqlite3SafetyCheckOk(db) || zName==0 || nArg<-2 ){ |
| 127491 | | - return SQLITE_MISUSE_BKPT; |
| 127492 | | - } |
| 127493 | | -#endif |
| 127494 | 126518 | sqlite3_mutex_enter(db->mutex); |
| 127495 | 126519 | if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){ |
| 127496 | 126520 | rc = sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8, |
| 127497 | 126521 | 0, sqlite3InvalidFunction, 0, 0, 0); |
| 127498 | 126522 | } |
| | @@ -127510,17 +126534,10 @@ |
| 127510 | 126534 | ** trace is a pointer to a function that is invoked at the start of each |
| 127511 | 126535 | ** SQL statement. |
| 127512 | 126536 | */ |
| 127513 | 126537 | SQLITE_API void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){ |
| 127514 | 126538 | void *pOld; |
| 127515 | | - |
| 127516 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 127517 | | - if( !sqlite3SafetyCheckOk(db) ){ |
| 127518 | | - (void)SQLITE_MISUSE_BKPT; |
| 127519 | | - return 0; |
| 127520 | | - } |
| 127521 | | -#endif |
| 127522 | 126539 | sqlite3_mutex_enter(db->mutex); |
| 127523 | 126540 | pOld = db->pTraceArg; |
| 127524 | 126541 | db->xTrace = xTrace; |
| 127525 | 126542 | db->pTraceArg = pArg; |
| 127526 | 126543 | sqlite3_mutex_leave(db->mutex); |
| | @@ -127538,17 +126555,10 @@ |
| 127538 | 126555 | sqlite3 *db, |
| 127539 | 126556 | void (*xProfile)(void*,const char*,sqlite_uint64), |
| 127540 | 126557 | void *pArg |
| 127541 | 126558 | ){ |
| 127542 | 126559 | void *pOld; |
| 127543 | | - |
| 127544 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 127545 | | - if( !sqlite3SafetyCheckOk(db) ){ |
| 127546 | | - (void)SQLITE_MISUSE_BKPT; |
| 127547 | | - return 0; |
| 127548 | | - } |
| 127549 | | -#endif |
| 127550 | 126560 | sqlite3_mutex_enter(db->mutex); |
| 127551 | 126561 | pOld = db->pProfileArg; |
| 127552 | 126562 | db->xProfile = xProfile; |
| 127553 | 126563 | db->pProfileArg = pArg; |
| 127554 | 126564 | sqlite3_mutex_leave(db->mutex); |
| | @@ -127565,17 +126575,10 @@ |
| 127565 | 126575 | sqlite3 *db, /* Attach the hook to this database */ |
| 127566 | 126576 | int (*xCallback)(void*), /* Function to invoke on each commit */ |
| 127567 | 126577 | void *pArg /* Argument to the function */ |
| 127568 | 126578 | ){ |
| 127569 | 126579 | void *pOld; |
| 127570 | | - |
| 127571 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 127572 | | - if( !sqlite3SafetyCheckOk(db) ){ |
| 127573 | | - (void)SQLITE_MISUSE_BKPT; |
| 127574 | | - return 0; |
| 127575 | | - } |
| 127576 | | -#endif |
| 127577 | 126580 | sqlite3_mutex_enter(db->mutex); |
| 127578 | 126581 | pOld = db->pCommitArg; |
| 127579 | 126582 | db->xCommitCallback = xCallback; |
| 127580 | 126583 | db->pCommitArg = pArg; |
| 127581 | 126584 | sqlite3_mutex_leave(db->mutex); |
| | @@ -127590,17 +126593,10 @@ |
| 127590 | 126593 | sqlite3 *db, /* Attach the hook to this database */ |
| 127591 | 126594 | void (*xCallback)(void*,int,char const *,char const *,sqlite_int64), |
| 127592 | 126595 | void *pArg /* Argument to the function */ |
| 127593 | 126596 | ){ |
| 127594 | 126597 | void *pRet; |
| 127595 | | - |
| 127596 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 127597 | | - if( !sqlite3SafetyCheckOk(db) ){ |
| 127598 | | - (void)SQLITE_MISUSE_BKPT; |
| 127599 | | - return 0; |
| 127600 | | - } |
| 127601 | | -#endif |
| 127602 | 126598 | sqlite3_mutex_enter(db->mutex); |
| 127603 | 126599 | pRet = db->pUpdateArg; |
| 127604 | 126600 | db->xUpdateCallback = xCallback; |
| 127605 | 126601 | db->pUpdateArg = pArg; |
| 127606 | 126602 | sqlite3_mutex_leave(db->mutex); |
| | @@ -127615,17 +126611,10 @@ |
| 127615 | 126611 | sqlite3 *db, /* Attach the hook to this database */ |
| 127616 | 126612 | void (*xCallback)(void*), /* Callback function */ |
| 127617 | 126613 | void *pArg /* Argument to the function */ |
| 127618 | 126614 | ){ |
| 127619 | 126615 | void *pRet; |
| 127620 | | - |
| 127621 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 127622 | | - if( !sqlite3SafetyCheckOk(db) ){ |
| 127623 | | - (void)SQLITE_MISUSE_BKPT; |
| 127624 | | - return 0; |
| 127625 | | - } |
| 127626 | | -#endif |
| 127627 | 126616 | sqlite3_mutex_enter(db->mutex); |
| 127628 | 126617 | pRet = db->pRollbackArg; |
| 127629 | 126618 | db->xRollbackCallback = xCallback; |
| 127630 | 126619 | db->pRollbackArg = pArg; |
| 127631 | 126620 | sqlite3_mutex_leave(db->mutex); |
| | @@ -127668,13 +126657,10 @@ |
| 127668 | 126657 | SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){ |
| 127669 | 126658 | #ifdef SQLITE_OMIT_WAL |
| 127670 | 126659 | UNUSED_PARAMETER(db); |
| 127671 | 126660 | UNUSED_PARAMETER(nFrame); |
| 127672 | 126661 | #else |
| 127673 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 127674 | | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 127675 | | -#endif |
| 127676 | 126662 | if( nFrame>0 ){ |
| 127677 | 126663 | sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame)); |
| 127678 | 126664 | }else{ |
| 127679 | 126665 | sqlite3_wal_hook(db, 0, 0); |
| 127680 | 126666 | } |
| | @@ -127691,16 +126677,10 @@ |
| 127691 | 126677 | int(*xCallback)(void *, sqlite3*, const char*, int), |
| 127692 | 126678 | void *pArg /* First argument passed to xCallback() */ |
| 127693 | 126679 | ){ |
| 127694 | 126680 | #ifndef SQLITE_OMIT_WAL |
| 127695 | 126681 | void *pRet; |
| 127696 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 127697 | | - if( !sqlite3SafetyCheckOk(db) ){ |
| 127698 | | - (void)SQLITE_MISUSE_BKPT; |
| 127699 | | - return 0; |
| 127700 | | - } |
| 127701 | | -#endif |
| 127702 | 126682 | sqlite3_mutex_enter(db->mutex); |
| 127703 | 126683 | pRet = db->pWalArg; |
| 127704 | 126684 | db->xWalCallback = xCallback; |
| 127705 | 126685 | db->pWalArg = pArg; |
| 127706 | 126686 | sqlite3_mutex_leave(db->mutex); |
| | @@ -127724,14 +126704,10 @@ |
| 127724 | 126704 | return SQLITE_OK; |
| 127725 | 126705 | #else |
| 127726 | 126706 | int rc; /* Return code */ |
| 127727 | 126707 | int iDb = SQLITE_MAX_ATTACHED; /* sqlite3.aDb[] index of db to checkpoint */ |
| 127728 | 126708 | |
| 127729 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 127730 | | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 127731 | | -#endif |
| 127732 | | - |
| 127733 | 126709 | /* Initialize the output variables to -1 in case an error occurs. */ |
| 127734 | 126710 | if( pnLog ) *pnLog = -1; |
| 127735 | 126711 | if( pnCkpt ) *pnCkpt = -1; |
| 127736 | 126712 | |
| 127737 | 126713 | assert( SQLITE_CHECKPOINT_FULL>SQLITE_CHECKPOINT_PASSIVE ); |
| | @@ -128124,16 +127100,10 @@ |
| 128124 | 127100 | ** from forming. |
| 128125 | 127101 | */ |
| 128126 | 127102 | SQLITE_API int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){ |
| 128127 | 127103 | int oldLimit; |
| 128128 | 127104 | |
| 128129 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 128130 | | - if( !sqlite3SafetyCheckOk(db) ){ |
| 128131 | | - (void)SQLITE_MISUSE_BKPT; |
| 128132 | | - return -1; |
| 128133 | | - } |
| 128134 | | -#endif |
| 128135 | 127105 | |
| 128136 | 127106 | /* EVIDENCE-OF: R-30189-54097 For each limit category SQLITE_LIMIT_NAME |
| 128137 | 127107 | ** there is a hard upper bound set at compile-time by a C preprocessor |
| 128138 | 127108 | ** macro called SQLITE_MAX_NAME. (The "_LIMIT_" in the name is changed to |
| 128139 | 127109 | ** "_MAX_".) |
| | @@ -128206,12 +127176,11 @@ |
| 128206 | 127176 | char c; |
| 128207 | 127177 | int nUri = sqlite3Strlen30(zUri); |
| 128208 | 127178 | |
| 128209 | 127179 | assert( *pzErrMsg==0 ); |
| 128210 | 127180 | |
| 128211 | | - if( ((flags & SQLITE_OPEN_URI) /* IMP: R-48725-32206 */ |
| 128212 | | - || sqlite3GlobalConfig.bOpenUri) /* IMP: R-51689-46548 */ |
| 127181 | + if( ((flags & SQLITE_OPEN_URI) || sqlite3GlobalConfig.bOpenUri) |
| 128213 | 127182 | && nUri>=5 && memcmp(zUri, "file:", 5)==0 /* IMP: R-57884-37496 */ |
| 128214 | 127183 | ){ |
| 128215 | 127184 | char *zOpt; |
| 128216 | 127185 | int eState; /* Parser state when parsing URI */ |
| 128217 | 127186 | int iIn; /* Input character index */ |
| | @@ -128416,13 +127385,10 @@ |
| 128416 | 127385 | int rc; /* Return code */ |
| 128417 | 127386 | int isThreadsafe; /* True for threadsafe connections */ |
| 128418 | 127387 | char *zOpen = 0; /* Filename argument to pass to BtreeOpen() */ |
| 128419 | 127388 | char *zErrMsg = 0; /* Error message from sqlite3ParseUri() */ |
| 128420 | 127389 | |
| 128421 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 128422 | | - if( ppDb==0 ) return SQLITE_MISUSE_BKPT; |
| 128423 | | -#endif |
| 128424 | 127390 | *ppDb = 0; |
| 128425 | 127391 | #ifndef SQLITE_OMIT_AUTOINIT |
| 128426 | 127392 | rc = sqlite3_initialize(); |
| 128427 | 127393 | if( rc ) return rc; |
| 128428 | 127394 | #endif |
| | @@ -128708,19 +127674,17 @@ |
| 128708 | 127674 | ){ |
| 128709 | 127675 | char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */ |
| 128710 | 127676 | sqlite3_value *pVal; |
| 128711 | 127677 | int rc; |
| 128712 | 127678 | |
| 128713 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 128714 | | - if( ppDb==0 ) return SQLITE_MISUSE_BKPT; |
| 128715 | | -#endif |
| 127679 | + assert( zFilename ); |
| 127680 | + assert( ppDb ); |
| 128716 | 127681 | *ppDb = 0; |
| 128717 | 127682 | #ifndef SQLITE_OMIT_AUTOINIT |
| 128718 | 127683 | rc = sqlite3_initialize(); |
| 128719 | 127684 | if( rc ) return rc; |
| 128720 | 127685 | #endif |
| 128721 | | - if( zFilename==0 ) zFilename = "\000\000"; |
| 128722 | 127686 | pVal = sqlite3ValueNew(0); |
| 128723 | 127687 | sqlite3ValueSetStr(pVal, -1, zFilename, SQLITE_UTF16NATIVE, SQLITE_STATIC); |
| 128724 | 127688 | zFilename8 = sqlite3ValueText(pVal, SQLITE_UTF8); |
| 128725 | 127689 | if( zFilename8 ){ |
| 128726 | 127690 | rc = openDatabase(zFilename8, ppDb, |
| | @@ -128746,11 +127710,17 @@ |
| 128746 | 127710 | const char *zName, |
| 128747 | 127711 | int enc, |
| 128748 | 127712 | void* pCtx, |
| 128749 | 127713 | int(*xCompare)(void*,int,const void*,int,const void*) |
| 128750 | 127714 | ){ |
| 128751 | | - return sqlite3_create_collation_v2(db, zName, enc, pCtx, xCompare, 0); |
| 127715 | + int rc; |
| 127716 | + sqlite3_mutex_enter(db->mutex); |
| 127717 | + assert( !db->mallocFailed ); |
| 127718 | + rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, 0); |
| 127719 | + rc = sqlite3ApiExit(db, rc); |
| 127720 | + sqlite3_mutex_leave(db->mutex); |
| 127721 | + return rc; |
| 128752 | 127722 | } |
| 128753 | 127723 | |
| 128754 | 127724 | /* |
| 128755 | 127725 | ** Register a new collation sequence with the database handle db. |
| 128756 | 127726 | */ |
| | @@ -128761,14 +127731,10 @@ |
| 128761 | 127731 | void* pCtx, |
| 128762 | 127732 | int(*xCompare)(void*,int,const void*,int,const void*), |
| 128763 | 127733 | void(*xDel)(void*) |
| 128764 | 127734 | ){ |
| 128765 | 127735 | int rc; |
| 128766 | | - |
| 128767 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 128768 | | - if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT; |
| 128769 | | -#endif |
| 128770 | 127736 | sqlite3_mutex_enter(db->mutex); |
| 128771 | 127737 | assert( !db->mallocFailed ); |
| 128772 | 127738 | rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, xDel); |
| 128773 | 127739 | rc = sqlite3ApiExit(db, rc); |
| 128774 | 127740 | sqlite3_mutex_leave(db->mutex); |
| | @@ -128786,14 +127752,10 @@ |
| 128786 | 127752 | void* pCtx, |
| 128787 | 127753 | int(*xCompare)(void*,int,const void*,int,const void*) |
| 128788 | 127754 | ){ |
| 128789 | 127755 | int rc = SQLITE_OK; |
| 128790 | 127756 | char *zName8; |
| 128791 | | - |
| 128792 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 128793 | | - if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT; |
| 128794 | | -#endif |
| 128795 | 127757 | sqlite3_mutex_enter(db->mutex); |
| 128796 | 127758 | assert( !db->mallocFailed ); |
| 128797 | 127759 | zName8 = sqlite3Utf16to8(db, zName, -1, SQLITE_UTF16NATIVE); |
| 128798 | 127760 | if( zName8 ){ |
| 128799 | 127761 | rc = createCollation(db, zName8, (u8)enc, pCtx, xCompare, 0); |
| | @@ -128812,13 +127774,10 @@ |
| 128812 | 127774 | SQLITE_API int sqlite3_collation_needed( |
| 128813 | 127775 | sqlite3 *db, |
| 128814 | 127776 | void *pCollNeededArg, |
| 128815 | 127777 | void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*) |
| 128816 | 127778 | ){ |
| 128817 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 128818 | | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 128819 | | -#endif |
| 128820 | 127779 | sqlite3_mutex_enter(db->mutex); |
| 128821 | 127780 | db->xCollNeeded = xCollNeeded; |
| 128822 | 127781 | db->xCollNeeded16 = 0; |
| 128823 | 127782 | db->pCollNeededArg = pCollNeededArg; |
| 128824 | 127783 | sqlite3_mutex_leave(db->mutex); |
| | @@ -128833,13 +127792,10 @@ |
| 128833 | 127792 | SQLITE_API int sqlite3_collation_needed16( |
| 128834 | 127793 | sqlite3 *db, |
| 128835 | 127794 | void *pCollNeededArg, |
| 128836 | 127795 | void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*) |
| 128837 | 127796 | ){ |
| 128838 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 128839 | | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 128840 | | -#endif |
| 128841 | 127797 | sqlite3_mutex_enter(db->mutex); |
| 128842 | 127798 | db->xCollNeeded = 0; |
| 128843 | 127799 | db->xCollNeeded16 = xCollNeeded16; |
| 128844 | 127800 | db->pCollNeededArg = pCollNeededArg; |
| 128845 | 127801 | sqlite3_mutex_leave(db->mutex); |
| | @@ -128862,16 +127818,10 @@ |
| 128862 | 127818 | ** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on |
| 128863 | 127819 | ** by default. Autocommit is disabled by a BEGIN statement and reenabled |
| 128864 | 127820 | ** by the next COMMIT or ROLLBACK. |
| 128865 | 127821 | */ |
| 128866 | 127822 | SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){ |
| 128867 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 128868 | | - if( !sqlite3SafetyCheckOk(db) ){ |
| 128869 | | - (void)SQLITE_MISUSE_BKPT; |
| 128870 | | - return 0; |
| 128871 | | - } |
| 128872 | | -#endif |
| 128873 | 127823 | return db->autoCommit; |
| 128874 | 127824 | } |
| 128875 | 127825 | |
| 128876 | 127826 | /* |
| 128877 | 127827 | ** The following routines are substitutes for constants SQLITE_CORRUPT, |
| | @@ -129050,13 +128000,10 @@ |
| 129050 | 128000 | |
| 129051 | 128001 | /* |
| 129052 | 128002 | ** Enable or disable the extended result codes. |
| 129053 | 128003 | */ |
| 129054 | 128004 | SQLITE_API int sqlite3_extended_result_codes(sqlite3 *db, int onoff){ |
| 129055 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 129056 | | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 129057 | | -#endif |
| 129058 | 128005 | sqlite3_mutex_enter(db->mutex); |
| 129059 | 128006 | db->errMask = onoff ? 0xffffffff : 0xff; |
| 129060 | 128007 | sqlite3_mutex_leave(db->mutex); |
| 129061 | 128008 | return SQLITE_OK; |
| 129062 | 128009 | } |
| | @@ -129066,13 +128013,10 @@ |
| 129066 | 128013 | */ |
| 129067 | 128014 | SQLITE_API int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){ |
| 129068 | 128015 | int rc = SQLITE_ERROR; |
| 129069 | 128016 | Btree *pBtree; |
| 129070 | 128017 | |
| 129071 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 129072 | | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 129073 | | -#endif |
| 129074 | 128018 | sqlite3_mutex_enter(db->mutex); |
| 129075 | 128019 | pBtree = sqlite3DbNameToBtree(db, zDbName); |
| 129076 | 128020 | if( pBtree ){ |
| 129077 | 128021 | Pager *pPager; |
| 129078 | 128022 | sqlite3_file *fd; |
| | @@ -129411,11 +128355,11 @@ |
| 129411 | 128355 | ** query parameter we seek. This routine returns the value of the zParam |
| 129412 | 128356 | ** parameter if it exists. If the parameter does not exist, this routine |
| 129413 | 128357 | ** returns a NULL pointer. |
| 129414 | 128358 | */ |
| 129415 | 128359 | SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){ |
| 129416 | | - if( zFilename==0 || zParam==0 ) return 0; |
| 128360 | + if( zFilename==0 ) return 0; |
| 129417 | 128361 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 129418 | 128362 | while( zFilename[0] ){ |
| 129419 | 128363 | int x = strcmp(zFilename, zParam); |
| 129420 | 128364 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 129421 | 128365 | if( x==0 ) return zFilename; |
| | @@ -129467,31 +128411,19 @@ |
| 129467 | 128411 | /* |
| 129468 | 128412 | ** Return the filename of the database associated with a database |
| 129469 | 128413 | ** connection. |
| 129470 | 128414 | */ |
| 129471 | 128415 | SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){ |
| 129472 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 129473 | | - if( !sqlite3SafetyCheckOk(db) ){ |
| 129474 | | - (void)SQLITE_MISUSE_BKPT; |
| 129475 | | - return 0; |
| 129476 | | - } |
| 129477 | | -#endif |
| 129478 | 128416 | Btree *pBt = sqlite3DbNameToBtree(db, zDbName); |
| 129479 | 128417 | return pBt ? sqlite3BtreeGetFilename(pBt) : 0; |
| 129480 | 128418 | } |
| 129481 | 128419 | |
| 129482 | 128420 | /* |
| 129483 | 128421 | ** Return 1 if database is read-only or 0 if read/write. Return -1 if |
| 129484 | 128422 | ** no such database exists. |
| 129485 | 128423 | */ |
| 129486 | 128424 | SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){ |
| 129487 | | -#ifdef SQLITE_ENABLE_API_ARMOR |
| 129488 | | - if( !sqlite3SafetyCheckOk(db) ){ |
| 129489 | | - (void)SQLITE_MISUSE_BKPT; |
| 129490 | | - return -1; |
| 129491 | | - } |
| 129492 | | -#endif |
| 129493 | 128425 | Btree *pBt = sqlite3DbNameToBtree(db, zDbName); |
| 129494 | 128426 | return pBt ? sqlite3BtreeIsReadonly(pBt) : -1; |
| 129495 | 128427 | } |
| 129496 | 128428 | |
| 129497 | 128429 | /************** End of main.c ************************************************/ |
| 129498 | 128430 | |