Fossil SCM
Revert the built-in SQLite to version 3.8.7.2 until a btree problem in 3.8.8 is fixed.
Commit
194c3ff362a92432ba47177c86a5c9bf67ed5bf1
Parent
156ef9ec06a069f…
2 files changed
+784
-1910
+182
-312
+784
-1910
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -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-18 21:54:31 4461bf045d8eecf98478035efcdba3f41c709bc5" | |
| 234 | +#define SQLITE_VERSION "3.8.7.2" | |
| 235 | +#define SQLITE_VERSION_NUMBER 3008007 | |
| 236 | +#define SQLITE_SOURCE_ID "2014-11-18 20:57:56 2ab564bf9655b7c7b97ab85cafc8a48329b27f93" | |
| 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 | ** |
| @@ -6975,14 +6941,10 @@ | ||
| 6975 | 6941 | ** and database name of the source database, respectively. |
| 6976 | 6942 | ** ^The source and destination [database connections] (parameters S and D) |
| 6977 | 6943 | ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with |
| 6978 | 6944 | ** an error. |
| 6979 | 6945 | ** |
| 6980 | -** ^A call to sqlite3_backup_init() will fail, returning SQLITE_ERROR, if | |
| 6981 | -** there is already a read or read-write transaction open on the | |
| 6982 | -** destination database. | |
| 6983 | -** | |
| 6984 | 6946 | ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is |
| 6985 | 6947 | ** returned and an error code and error message are stored in the |
| 6986 | 6948 | ** destination [database connection] D. |
| 6987 | 6949 | ** ^The error code and message for the failed call to sqlite3_backup_init() |
| 6988 | 6950 | ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or |
| @@ -7571,102 +7533,10 @@ | ||
| 7571 | 7533 | /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */ |
| 7572 | 7534 | #define SQLITE_FAIL 3 |
| 7573 | 7535 | /* #define SQLITE_ABORT 4 // Also an error code */ |
| 7574 | 7536 | #define SQLITE_REPLACE 5 |
| 7575 | 7537 | |
| 7576 | -/* | |
| 7577 | -** CAPI3REF: Prepared Statement Scan Status Opcodes | |
| 7578 | -** KEYWORDS: {scanstatus options} | |
| 7579 | -** | |
| 7580 | -** The following constants can be used for the T parameter to the | |
| 7581 | -** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a | |
| 7582 | -** different metric for sqlite3_stmt_scanstatus() to return. | |
| 7583 | -** | |
| 7584 | -** <dl> | |
| 7585 | -** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt> | |
| 7586 | -** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the | |
| 7587 | -** total number of times that the X-th loop has run.</dd> | |
| 7588 | -** | |
| 7589 | -** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt> | |
| 7590 | -** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the | |
| 7591 | -** total number of rows examined by all iterations of the X-th loop.</dd> | |
| 7592 | -** | |
| 7593 | -** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt> | |
| 7594 | -** <dd>^The "double" variable pointed to by the T parameter will be set to the | |
| 7595 | -** query planner's estimate for the average number of rows output from each | |
| 7596 | -** iteration of the X-th loop. If the query planner's estimates was accurate, | |
| 7597 | -** then this value will approximate the quotient NVISIT/NLOOP and the | |
| 7598 | -** product of this value for all prior loops with the same SELECTID will | |
| 7599 | -** be the NLOOP value for the current loop. | |
| 7600 | -** | |
| 7601 | -** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt> | |
| 7602 | -** <dd>^The "const char *" variable pointed to by the T parameter will be set to | |
| 7603 | -** a zero-terminated UTF-8 string containing the name of the index or table used | |
| 7604 | -** for the X-th loop. | |
| 7605 | -** | |
| 7606 | -** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt> | |
| 7607 | -** <dd>^The "const char *" variable pointed to by the T parameter will be set to | |
| 7608 | -** a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN] description | |
| 7609 | -** for the X-th loop. | |
| 7610 | -** | |
| 7611 | -** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt> | |
| 7612 | -** <dd>^The "int" variable pointed to by the T parameter will be set to the | |
| 7613 | -** "select-id" for the X-th loop. The select-id identifies which query or | |
| 7614 | -** subquery the loop is part of. The main query has a select-id of zero. | |
| 7615 | -** The select-id is the same value as is output in the first column | |
| 7616 | -** of an [EXPLAIN QUERY PLAN] query. | |
| 7617 | -** </dl> | |
| 7618 | -*/ | |
| 7619 | -#define SQLITE_SCANSTAT_NLOOP 0 | |
| 7620 | -#define SQLITE_SCANSTAT_NVISIT 1 | |
| 7621 | -#define SQLITE_SCANSTAT_EST 2 | |
| 7622 | -#define SQLITE_SCANSTAT_NAME 3 | |
| 7623 | -#define SQLITE_SCANSTAT_EXPLAIN 4 | |
| 7624 | -#define SQLITE_SCANSTAT_SELECTID 5 | |
| 7625 | - | |
| 7626 | -/* | |
| 7627 | -** CAPI3REF: Prepared Statement Scan Status | |
| 7628 | -** | |
| 7629 | -** Return status data for a single loop within query pStmt. | |
| 7630 | -** | |
| 7631 | -** The "iScanStatusOp" parameter determines which status information to return. | |
| 7632 | -** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior of | |
| 7633 | -** this interface is undefined. | |
| 7634 | -** ^The requested measurement is written into a variable pointed to by | |
| 7635 | -** the "pOut" parameter. | |
| 7636 | -** Parameter "idx" identifies the specific loop to retrieve statistics for. | |
| 7637 | -** Loops are numbered starting from zero. ^If idx is out of range - less than | |
| 7638 | -** zero or greater than or equal to the total number of loops used to implement | |
| 7639 | -** the statement - a non-zero value is returned and the variable that pOut | |
| 7640 | -** points to is unchanged. | |
| 7641 | -** | |
| 7642 | -** ^Statistics might not be available for all loops in all statements. ^In cases | |
| 7643 | -** where there exist loops with no available statistics, this function behaves | |
| 7644 | -** as if the loop did not exist - it returns non-zero and leave the variable | |
| 7645 | -** that pOut points to unchanged. | |
| 7646 | -** | |
| 7647 | -** This API is only available if the library is built with pre-processor | |
| 7648 | -** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. | |
| 7649 | -** | |
| 7650 | -** See also: [sqlite3_stmt_scanstatus_reset()] | |
| 7651 | -*/ | |
| 7652 | -SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus( | |
| 7653 | - sqlite3_stmt *pStmt, /* Prepared statement for which info desired */ | |
| 7654 | - int idx, /* Index of loop to report on */ | |
| 7655 | - int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */ | |
| 7656 | - void *pOut /* Result written here */ | |
| 7657 | -); | |
| 7658 | - | |
| 7659 | -/* | |
| 7660 | -** CAPI3REF: Zero Scan-Status Counters | |
| 7661 | -** | |
| 7662 | -** ^Zero all [sqlite3_stmt_scanstatus()] related event counters. | |
| 7663 | -** | |
| 7664 | -** This API is only available if the library is built with pre-processor | |
| 7665 | -** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. | |
| 7666 | -*/ | |
| 7667 | -SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*); | |
| 7668 | 7538 | |
| 7669 | 7539 | |
| 7670 | 7540 | /* |
| 7671 | 7541 | ** Undo the hack that converts floating point types to integer for |
| 7672 | 7542 | ** builds on processors without floating point support. |
| @@ -8108,13 +7978,14 @@ | ||
| 8108 | 7978 | #ifndef SQLITE_POWERSAFE_OVERWRITE |
| 8109 | 7979 | # define SQLITE_POWERSAFE_OVERWRITE 1 |
| 8110 | 7980 | #endif |
| 8111 | 7981 | |
| 8112 | 7982 | /* |
| 8113 | -** EVIDENCE-OF: R-25715-37072 Memory allocation statistics are enabled by | |
| 8114 | -** default unless SQLite is compiled with SQLITE_DEFAULT_MEMSTATUS=0 in | |
| 8115 | -** 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. | |
| 8116 | 7987 | */ |
| 8117 | 7988 | #if !defined(SQLITE_DEFAULT_MEMSTATUS) |
| 8118 | 7989 | # define SQLITE_DEFAULT_MEMSTATUS 1 |
| 8119 | 7990 | #endif |
| 8120 | 7991 | |
| @@ -8740,11 +8611,11 @@ | ||
| 8740 | 8611 | ** Estimated quantities used for query planning are stored as 16-bit |
| 8741 | 8612 | ** logarithms. For quantity X, the value stored is 10*log2(X). This |
| 8742 | 8613 | ** gives a possible range of values of approximately 1.0e986 to 1e-986. |
| 8743 | 8614 | ** But the allowed values are "grainy". Not every value is representable. |
| 8744 | 8615 | ** For example, quantities 16 and 17 are both represented by a LogEst |
| 8745 | -** of 40. However, since LogEst quantities are suppose to be estimates, | |
| 8616 | +** of 40. However, since LogEst quantaties are suppose to be estimates, | |
| 8746 | 8617 | ** not exact values, this imprecision is not a problem. |
| 8747 | 8618 | ** |
| 8748 | 8619 | ** "LogEst" is short for "Logarithmic Estimate". |
| 8749 | 8620 | ** |
| 8750 | 8621 | ** Examples: |
| @@ -9253,11 +9124,10 @@ | ||
| 9253 | 9124 | SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *); |
| 9254 | 9125 | SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *); |
| 9255 | 9126 | SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion); |
| 9256 | 9127 | SQLITE_PRIVATE void sqlite3BtreeCursorHints(BtCursor *, unsigned int mask); |
| 9257 | 9128 | SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *pBt); |
| 9258 | -SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void); | |
| 9259 | 9129 | |
| 9260 | 9130 | #ifndef NDEBUG |
| 9261 | 9131 | SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*); |
| 9262 | 9132 | #endif |
| 9263 | 9133 | |
| @@ -9796,16 +9666,10 @@ | ||
| 9796 | 9666 | # define VdbeCoverageAlwaysTaken(v) |
| 9797 | 9667 | # define VdbeCoverageNeverTaken(v) |
| 9798 | 9668 | # define VDBE_OFFSET_LINENO(x) 0 |
| 9799 | 9669 | #endif |
| 9800 | 9670 | |
| 9801 | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS | |
| 9802 | -SQLITE_PRIVATE void sqlite3VdbeScanStatus(Vdbe*, int, int, int, LogEst, const char*); | |
| 9803 | -#else | |
| 9804 | -# define sqlite3VdbeScanStatus(a,b,c,d,e) | |
| 9805 | -#endif | |
| 9806 | - | |
| 9807 | 9671 | #endif |
| 9808 | 9672 | |
| 9809 | 9673 | /************** End of vdbe.h ************************************************/ |
| 9810 | 9674 | /************** Continuing where we left off in sqliteInt.h ******************/ |
| 9811 | 9675 | /************** Include pager.h in the middle of sqliteInt.h *****************/ |
| @@ -9998,12 +9862,10 @@ | ||
| 9998 | 9862 | SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *); |
| 9999 | 9863 | |
| 10000 | 9864 | /* Functions used to truncate the database file. */ |
| 10001 | 9865 | SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno); |
| 10002 | 9866 | |
| 10003 | -SQLITE_PRIVATE void sqlite3PagerRekey(DbPage*, Pgno, u16); | |
| 10004 | - | |
| 10005 | 9867 | #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_WAL) |
| 10006 | 9868 | SQLITE_PRIVATE void *sqlite3PagerCodec(DbPage *); |
| 10007 | 9869 | #endif |
| 10008 | 9870 | |
| 10009 | 9871 | /* Functions to support testing and debugging. */ |
| @@ -10187,14 +10049,10 @@ | ||
| 10187 | 10049 | SQLITE_PRIVATE void sqlite3PcacheStats(int*,int*,int*,int*); |
| 10188 | 10050 | #endif |
| 10189 | 10051 | |
| 10190 | 10052 | SQLITE_PRIVATE void sqlite3PCacheSetDefault(void); |
| 10191 | 10053 | |
| 10192 | -/* Return the header size */ | |
| 10193 | -SQLITE_PRIVATE int sqlite3HeaderSizePcache(void); | |
| 10194 | -SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void); | |
| 10195 | - | |
| 10196 | 10054 | #endif /* _PCACHE_H_ */ |
| 10197 | 10055 | |
| 10198 | 10056 | /************** End of pcache.h **********************************************/ |
| 10199 | 10057 | /************** Continuing where we left off in sqliteInt.h ******************/ |
| 10200 | 10058 | |
| @@ -10877,11 +10735,11 @@ | ||
| 10877 | 10735 | #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */ |
| 10878 | 10736 | #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */ |
| 10879 | 10737 | #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */ |
| 10880 | 10738 | #define SQLITE_Transitive 0x0200 /* Transitive constraints */ |
| 10881 | 10739 | #define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */ |
| 10882 | -#define SQLITE_Stat34 0x0800 /* Use STAT3 or STAT4 data */ | |
| 10740 | +#define SQLITE_Stat3 0x0800 /* Use the SQLITE_STAT3 table */ | |
| 10883 | 10741 | #define SQLITE_AllOpts 0xffff /* All optimizations */ |
| 10884 | 10742 | |
| 10885 | 10743 | /* |
| 10886 | 10744 | ** Macros for testing whether or not optimizations are enabled or disabled. |
| 10887 | 10745 | */ |
| @@ -11459,18 +11317,16 @@ | ||
| 11459 | 11317 | unsigned idxType:2; /* 1==UNIQUE, 2==PRIMARY KEY, 0==CREATE INDEX */ |
| 11460 | 11318 | unsigned bUnordered:1; /* Use this index for == or IN queries only */ |
| 11461 | 11319 | unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */ |
| 11462 | 11320 | unsigned isResized:1; /* True if resizeIndexObject() has been called */ |
| 11463 | 11321 | unsigned isCovering:1; /* True if this is a covering index */ |
| 11464 | - unsigned noSkipScan:1; /* Do not try to use skip-scan if true */ | |
| 11465 | 11322 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 11466 | 11323 | int nSample; /* Number of elements in aSample[] */ |
| 11467 | 11324 | int nSampleCol; /* Size of IndexSample.anEq[] and so on */ |
| 11468 | 11325 | tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */ |
| 11469 | 11326 | IndexSample *aSample; /* Samples of the left-most key */ |
| 11470 | - tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this index */ | |
| 11471 | - tRowcnt nRowEst0; /* Non-logarithmic number of rows in the index */ | |
| 11327 | + tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this table */ | |
| 11472 | 11328 | #endif |
| 11473 | 11329 | }; |
| 11474 | 11330 | |
| 11475 | 11331 | /* |
| 11476 | 11332 | ** Allowed values for Index.idxType |
| @@ -11664,11 +11520,11 @@ | ||
| 11664 | 11520 | int nHeight; /* Height of the tree headed by this node */ |
| 11665 | 11521 | #endif |
| 11666 | 11522 | int iTable; /* TK_COLUMN: cursor number of table holding column |
| 11667 | 11523 | ** TK_REGISTER: register number |
| 11668 | 11524 | ** TK_TRIGGER: 1 -> new, 0 -> old |
| 11669 | - ** EP_Unlikely: 134217728 times likelihood */ | |
| 11525 | + ** EP_Unlikely: 1000 times likelihood */ | |
| 11670 | 11526 | ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid. |
| 11671 | 11527 | ** TK_VARIABLE: variable number (always >= 1). */ |
| 11672 | 11528 | i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */ |
| 11673 | 11529 | i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */ |
| 11674 | 11530 | u8 op2; /* TK_REGISTER: original value of Expr.op |
| @@ -12556,15 +12412,13 @@ | ||
| 12556 | 12412 | int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */ |
| 12557 | 12413 | int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */ |
| 12558 | 12414 | void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */ |
| 12559 | 12415 | Parse *pParse; /* Parser context. */ |
| 12560 | 12416 | int walkerDepth; /* Number of subqueries */ |
| 12561 | - u8 eCode; /* A small processing code */ | |
| 12562 | 12417 | union { /* Extra data for callback */ |
| 12563 | 12418 | NameContext *pNC; /* Naming context */ |
| 12564 | - int n; /* A counter */ | |
| 12565 | - int iCur; /* A cursor number */ | |
| 12419 | + int i; /* Integer value */ | |
| 12566 | 12420 | SrcList *pSrcList; /* FROM clause */ |
| 12567 | 12421 | struct SrcCount *pSrcCount; /* Counting column references */ |
| 12568 | 12422 | } u; |
| 12569 | 12423 | }; |
| 12570 | 12424 | |
| @@ -12961,11 +12815,10 @@ | ||
| 12961 | 12815 | SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *); |
| 12962 | 12816 | SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*); |
| 12963 | 12817 | SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*); |
| 12964 | 12818 | SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*); |
| 12965 | 12819 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8); |
| 12966 | -SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int); | |
| 12967 | 12820 | SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*); |
| 12968 | 12821 | SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*); |
| 12969 | 12822 | SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char); |
| 12970 | 12823 | SQLITE_PRIVATE int sqlite3IsRowid(const char*); |
| 12971 | 12824 | SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8); |
| @@ -13619,23 +13472,15 @@ | ||
| 13619 | 13472 | ** compatibility for legacy applications, the URI filename capability is |
| 13620 | 13473 | ** disabled by default. |
| 13621 | 13474 | ** |
| 13622 | 13475 | ** EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled |
| 13623 | 13476 | ** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options. |
| 13624 | -** | |
| 13625 | -** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally | |
| 13626 | -** disabled. The default value may be changed by compiling with the | |
| 13627 | -** SQLITE_USE_URI symbol defined. | |
| 13628 | 13477 | */ |
| 13629 | 13478 | #ifndef SQLITE_USE_URI |
| 13630 | 13479 | # define SQLITE_USE_URI 0 |
| 13631 | 13480 | #endif |
| 13632 | 13481 | |
| 13633 | -/* EVIDENCE-OF: R-38720-18127 The default setting is determined by the | |
| 13634 | -** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if | |
| 13635 | -** that compile-time option is omitted. | |
| 13636 | -*/ | |
| 13637 | 13482 | #ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN |
| 13638 | 13483 | # define SQLITE_ALLOW_COVERING_INDEX_SCAN 1 |
| 13639 | 13484 | #endif |
| 13640 | 13485 | |
| 13641 | 13486 | /* |
| @@ -13721,12 +13566,12 @@ | ||
| 13721 | 13566 | ** than 1 GiB. The sqlite3_test_control() interface can be used to |
| 13722 | 13567 | ** move the pending byte. |
| 13723 | 13568 | ** |
| 13724 | 13569 | ** IMPORTANT: Changing the pending byte to any value other than |
| 13725 | 13570 | ** 0x40000000 results in an incompatible database file format! |
| 13726 | -** Changing the pending byte during operation will result in undefined | |
| 13727 | -** and incorrect behavior. | |
| 13571 | +** Changing the pending byte during operating results in undefined | |
| 13572 | +** and dileterious behavior. | |
| 13728 | 13573 | */ |
| 13729 | 13574 | #ifndef SQLITE_OMIT_WSD |
| 13730 | 13575 | SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000; |
| 13731 | 13576 | #endif |
| 13732 | 13577 | |
| @@ -13802,13 +13647,10 @@ | ||
| 13802 | 13647 | "DISABLE_DIRSYNC", |
| 13803 | 13648 | #endif |
| 13804 | 13649 | #ifdef SQLITE_DISABLE_LFS |
| 13805 | 13650 | "DISABLE_LFS", |
| 13806 | 13651 | #endif |
| 13807 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 13808 | - "ENABLE_API_ARMOR", | |
| 13809 | -#endif | |
| 13810 | 13652 | #ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 13811 | 13653 | "ENABLE_ATOMIC_WRITE", |
| 13812 | 13654 | #endif |
| 13813 | 13655 | #ifdef SQLITE_ENABLE_CEROD |
| 13814 | 13656 | "ENABLE_CEROD", |
| @@ -14130,17 +13972,10 @@ | ||
| 14130 | 13972 | ** The name can optionally begin with "SQLITE_" but the "SQLITE_" prefix |
| 14131 | 13973 | ** is not required for a match. |
| 14132 | 13974 | */ |
| 14133 | 13975 | SQLITE_API int sqlite3_compileoption_used(const char *zOptName){ |
| 14134 | 13976 | int i, n; |
| 14135 | - | |
| 14136 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 14137 | - if( zOptName==0 ){ | |
| 14138 | - (void)SQLITE_MISUSE_BKPT; | |
| 14139 | - return 0; | |
| 14140 | - } | |
| 14141 | -#endif | |
| 14142 | 13977 | if( sqlite3StrNICmp(zOptName, "SQLITE_", 7)==0 ) zOptName += 7; |
| 14143 | 13978 | n = sqlite3Strlen30(zOptName); |
| 14144 | 13979 | |
| 14145 | 13980 | /* Since ArraySize(azCompileOpt) is normally in single digits, a |
| 14146 | 13981 | ** linear search is adequate. No need for a binary search. */ |
| @@ -14318,11 +14153,10 @@ | ||
| 14318 | 14153 | typedef struct VdbeFrame VdbeFrame; |
| 14319 | 14154 | struct VdbeFrame { |
| 14320 | 14155 | Vdbe *v; /* VM this frame belongs to */ |
| 14321 | 14156 | VdbeFrame *pParent; /* Parent of this frame, or NULL if parent is main */ |
| 14322 | 14157 | Op *aOp; /* Program instructions for parent frame */ |
| 14323 | - i64 *anExec; /* Event counters from parent frame */ | |
| 14324 | 14158 | Mem *aMem; /* Array of memory cells for parent frame */ |
| 14325 | 14159 | u8 *aOnceFlag; /* Array of OP_Once flags for parent frame */ |
| 14326 | 14160 | VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */ |
| 14327 | 14161 | void *token; /* Copy of SubProgram.token */ |
| 14328 | 14162 | i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */ |
| @@ -14331,12 +14165,11 @@ | ||
| 14331 | 14165 | int nOp; /* Size of aOp array */ |
| 14332 | 14166 | int nMem; /* Number of entries in aMem */ |
| 14333 | 14167 | int nOnceFlag; /* Number of entries in aOnceFlag */ |
| 14334 | 14168 | int nChildMem; /* Number of memory cells for child frame */ |
| 14335 | 14169 | int nChildCsr; /* Number of cursors for child frame */ |
| 14336 | - int nChange; /* Statement changes (Vdbe.nChange) */ | |
| 14337 | - int nDbChange; /* Value of db->nChange */ | |
| 14170 | + int nChange; /* Statement changes (Vdbe.nChanges) */ | |
| 14338 | 14171 | }; |
| 14339 | 14172 | |
| 14340 | 14173 | #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))]) |
| 14341 | 14174 | |
| 14342 | 14175 | /* |
| @@ -14483,20 +14316,10 @@ | ||
| 14483 | 14316 | /* A bitfield type for use inside of structures. Always follow with :N where |
| 14484 | 14317 | ** N is the number of bits. |
| 14485 | 14318 | */ |
| 14486 | 14319 | typedef unsigned bft; /* Bit Field Type */ |
| 14487 | 14320 | |
| 14488 | -typedef struct ScanStatus ScanStatus; | |
| 14489 | -struct ScanStatus { | |
| 14490 | - int addrExplain; /* OP_Explain for loop */ | |
| 14491 | - int addrLoop; /* Address of "loops" counter */ | |
| 14492 | - int addrVisit; /* Address of "rows visited" counter */ | |
| 14493 | - int iSelectID; /* The "Select-ID" for this loop */ | |
| 14494 | - LogEst nEst; /* Estimated output rows per loop */ | |
| 14495 | - char *zName; /* Name of table or index */ | |
| 14496 | -}; | |
| 14497 | - | |
| 14498 | 14321 | /* |
| 14499 | 14322 | ** An instance of the virtual machine. This structure contains the complete |
| 14500 | 14323 | ** state of the virtual machine. |
| 14501 | 14324 | ** |
| 14502 | 14325 | ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare() |
| @@ -14565,15 +14388,10 @@ | ||
| 14565 | 14388 | u32 expmask; /* Binding to these vars invalidates VM */ |
| 14566 | 14389 | SubProgram *pProgram; /* Linked list of all sub-programs used by VM */ |
| 14567 | 14390 | int nOnceFlag; /* Size of array aOnceFlag[] */ |
| 14568 | 14391 | u8 *aOnceFlag; /* Flags for OP_Once */ |
| 14569 | 14392 | AuxData *pAuxData; /* Linked list of auxdata allocations */ |
| 14570 | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS | |
| 14571 | - i64 *anExec; /* Number of times each op has been executed */ | |
| 14572 | - int nScan; /* Entries in aScan[] */ | |
| 14573 | - ScanStatus *aScan; /* Scan definitions for sqlite3_stmt_scanstatus() */ | |
| 14574 | -#endif | |
| 14575 | 14393 | }; |
| 14576 | 14394 | |
| 14577 | 14395 | /* |
| 14578 | 14396 | ** The following are allowed values for Vdbe.magic |
| 14579 | 14397 | */ |
| @@ -14759,13 +14577,10 @@ | ||
| 14759 | 14577 | SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){ |
| 14760 | 14578 | wsdStatInit; |
| 14761 | 14579 | if( op<0 || op>=ArraySize(wsdStat.nowValue) ){ |
| 14762 | 14580 | return SQLITE_MISUSE_BKPT; |
| 14763 | 14581 | } |
| 14764 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 14765 | - if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT; | |
| 14766 | -#endif | |
| 14767 | 14582 | *pCurrent = wsdStat.nowValue[op]; |
| 14768 | 14583 | *pHighwater = wsdStat.mxValue[op]; |
| 14769 | 14584 | if( resetFlag ){ |
| 14770 | 14585 | wsdStat.mxValue[op] = wsdStat.nowValue[op]; |
| 14771 | 14586 | } |
| @@ -14781,15 +14596,10 @@ | ||
| 14781 | 14596 | int *pCurrent, /* Write current value here */ |
| 14782 | 14597 | int *pHighwater, /* Write high-water mark here */ |
| 14783 | 14598 | int resetFlag /* Reset high-water mark if true */ |
| 14784 | 14599 | ){ |
| 14785 | 14600 | int rc = SQLITE_OK; /* Return code */ |
| 14786 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 14787 | - if( !sqlite3SafetyCheckOk(db) || pCurrent==0|| pHighwater==0 ){ | |
| 14788 | - return SQLITE_MISUSE_BKPT; | |
| 14789 | - } | |
| 14790 | -#endif | |
| 14791 | 14601 | sqlite3_mutex_enter(db->mutex); |
| 14792 | 14602 | switch( op ){ |
| 14793 | 14603 | case SQLITE_DBSTATUS_LOOKASIDE_USED: { |
| 14794 | 14604 | *pCurrent = db->lookaside.nOut; |
| 14795 | 14605 | *pHighwater = db->lookaside.mxOut; |
| @@ -14964,11 +14774,11 @@ | ||
| 14964 | 14774 | ** |
| 14965 | 14775 | ** There is only one exported symbol in this file - the function |
| 14966 | 14776 | ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file. |
| 14967 | 14777 | ** All other code has file scope. |
| 14968 | 14778 | ** |
| 14969 | -** SQLite processes all times and dates as julian day numbers. The | |
| 14779 | +** SQLite processes all times and dates as Julian Day numbers. The | |
| 14970 | 14780 | ** dates and times are stored as the number of days since noon |
| 14971 | 14781 | ** in Greenwich on November 24, 4714 B.C. according to the Gregorian |
| 14972 | 14782 | ** calendar system. |
| 14973 | 14783 | ** |
| 14974 | 14784 | ** 1970-01-01 00:00:00 is JD 2440587.5 |
| @@ -14979,11 +14789,11 @@ | ||
| 14979 | 14789 | ** be represented, even though julian day numbers allow a much wider |
| 14980 | 14790 | ** range of dates. |
| 14981 | 14791 | ** |
| 14982 | 14792 | ** The Gregorian calendar system is used for all dates and times, |
| 14983 | 14793 | ** even those that predate the Gregorian calendar. Historians usually |
| 14984 | -** 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 | |
| 14985 | 14795 | ** dates afterwards, depending on locale. Beware of this difference. |
| 14986 | 14796 | ** |
| 14987 | 14797 | ** The conversion algorithms are implemented based on descriptions |
| 14988 | 14798 | ** in the following text: |
| 14989 | 14799 | ** |
| @@ -15251,11 +15061,11 @@ | ||
| 15251 | 15061 | return 1; |
| 15252 | 15062 | } |
| 15253 | 15063 | } |
| 15254 | 15064 | |
| 15255 | 15065 | /* |
| 15256 | -** 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 | |
| 15257 | 15067 | ** the number of errors. |
| 15258 | 15068 | ** |
| 15259 | 15069 | ** The following are acceptable forms for the input string: |
| 15260 | 15070 | ** |
| 15261 | 15071 | ** YYYY-MM-DD HH:MM:SS.FFF +/-HH:MM |
| @@ -15822,11 +15632,11 @@ | ||
| 15822 | 15632 | ** |
| 15823 | 15633 | ** %d day of month |
| 15824 | 15634 | ** %f ** fractional seconds SS.SSS |
| 15825 | 15635 | ** %H hour 00-24 |
| 15826 | 15636 | ** %j day of year 000-366 |
| 15827 | -** %J ** julian day number | |
| 15637 | +** %J ** Julian day number | |
| 15828 | 15638 | ** %m month 01-12 |
| 15829 | 15639 | ** %M minute 00-59 |
| 15830 | 15640 | ** %s seconds since 1970-01-01 |
| 15831 | 15641 | ** %S seconds 00-59 |
| 15832 | 15642 | ** %w day of week 0-6 sunday==0 |
| @@ -16447,14 +16257,10 @@ | ||
| 16447 | 16257 | MUTEX_LOGIC(sqlite3_mutex *mutex;) |
| 16448 | 16258 | #ifndef SQLITE_OMIT_AUTOINIT |
| 16449 | 16259 | int rc = sqlite3_initialize(); |
| 16450 | 16260 | if( rc ) return rc; |
| 16451 | 16261 | #endif |
| 16452 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 16453 | - if( pVfs==0 ) return SQLITE_MISUSE_BKPT; | |
| 16454 | -#endif | |
| 16455 | - | |
| 16456 | 16262 | MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); ) |
| 16457 | 16263 | sqlite3_mutex_enter(mutex); |
| 16458 | 16264 | vfsUnlink(pVfs); |
| 16459 | 16265 | if( makeDflt || vfsList==0 ){ |
| 16460 | 16266 | pVfs->pNext = vfsList; |
| @@ -18808,11 +18614,10 @@ | ||
| 18808 | 18614 | ** Retrieve a pointer to a static mutex or allocate a new dynamic one. |
| 18809 | 18615 | */ |
| 18810 | 18616 | SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int id){ |
| 18811 | 18617 | #ifndef SQLITE_OMIT_AUTOINIT |
| 18812 | 18618 | if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0; |
| 18813 | - if( id>SQLITE_MUTEX_RECURSIVE && sqlite3MutexInit() ) return 0; | |
| 18814 | 18619 | #endif |
| 18815 | 18620 | return sqlite3GlobalConfig.mutex.xMutexAlloc(id); |
| 18816 | 18621 | } |
| 18817 | 18622 | |
| 18818 | 18623 | SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int id){ |
| @@ -19265,16 +19070,12 @@ | ||
| 19265 | 19070 | pthread_mutex_init(&p->mutex, 0); |
| 19266 | 19071 | } |
| 19267 | 19072 | break; |
| 19268 | 19073 | } |
| 19269 | 19074 | default: { |
| 19270 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 19271 | - if( iType-2<0 || iType-2>=ArraySize(staticMutexes) ){ | |
| 19272 | - (void)SQLITE_MISUSE_BKPT; | |
| 19273 | - return 0; | |
| 19274 | - } | |
| 19275 | -#endif | |
| 19075 | + assert( iType-2 >= 0 ); | |
| 19076 | + assert( iType-2 < ArraySize(staticMutexes) ); | |
| 19276 | 19077 | p = &staticMutexes[iType-2]; |
| 19277 | 19078 | #if SQLITE_MUTEX_NREF |
| 19278 | 19079 | p->id = iType; |
| 19279 | 19080 | #endif |
| 19280 | 19081 | break; |
| @@ -20492,16 +20293,15 @@ | ||
| 20492 | 20293 | } |
| 20493 | 20294 | assert( sqlite3_mutex_notheld(mem0.mutex) ); |
| 20494 | 20295 | |
| 20495 | 20296 | |
| 20496 | 20297 | #if SQLITE_THREADSAFE==0 && !defined(NDEBUG) |
| 20497 | - /* EVIDENCE-OF: R-12970-05880 SQLite will not use more than one scratch | |
| 20498 | - ** buffers per thread. | |
| 20499 | - ** | |
| 20500 | - ** This can only be checked in single-threaded mode. | |
| 20501 | - */ | |
| 20502 | - 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 ); | |
| 20503 | 20303 | if( p ) scratchAllocOut++; |
| 20504 | 20304 | #endif |
| 20505 | 20305 | |
| 20506 | 20306 | return p; |
| 20507 | 20307 | } |
| @@ -21156,17 +20956,10 @@ | ||
| 21156 | 20956 | etByte flag_rtz; /* True if trailing zeros should be removed */ |
| 21157 | 20957 | #endif |
| 21158 | 20958 | PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */ |
| 21159 | 20959 | char buf[etBUFSIZE]; /* Conversion buffer */ |
| 21160 | 20960 | |
| 21161 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 21162 | - if( ap==0 ){ | |
| 21163 | - (void)SQLITE_MISUSE_BKPT; | |
| 21164 | - sqlite3StrAccumReset(pAccum); | |
| 21165 | - return; | |
| 21166 | - } | |
| 21167 | -#endif | |
| 21168 | 20961 | bufpt = 0; |
| 21169 | 20962 | if( bFlags ){ |
| 21170 | 20963 | if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){ |
| 21171 | 20964 | pArgList = va_arg(ap, PrintfArguments*); |
| 21172 | 20965 | } |
| @@ -21703,15 +21496,10 @@ | ||
| 21703 | 21496 | return N; |
| 21704 | 21497 | }else{ |
| 21705 | 21498 | char *zOld = (p->zText==p->zBase ? 0 : p->zText); |
| 21706 | 21499 | i64 szNew = p->nChar; |
| 21707 | 21500 | szNew += N + 1; |
| 21708 | - if( szNew+p->nChar<=p->mxAlloc ){ | |
| 21709 | - /* Force exponential buffer size growth as long as it does not overflow, | |
| 21710 | - ** to avoid having to call this routine too often */ | |
| 21711 | - szNew += p->nChar; | |
| 21712 | - } | |
| 21713 | 21501 | if( szNew > p->mxAlloc ){ |
| 21714 | 21502 | sqlite3StrAccumReset(p); |
| 21715 | 21503 | setStrAccumError(p, STRACCUM_TOOBIG); |
| 21716 | 21504 | return 0; |
| 21717 | 21505 | }else{ |
| @@ -21724,11 +21512,10 @@ | ||
| 21724 | 21512 | } |
| 21725 | 21513 | if( zNew ){ |
| 21726 | 21514 | assert( p->zText!=0 || p->nChar==0 ); |
| 21727 | 21515 | if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); |
| 21728 | 21516 | p->zText = zNew; |
| 21729 | - p->nAlloc = sqlite3DbMallocSize(p->db, zNew); | |
| 21730 | 21517 | }else{ |
| 21731 | 21518 | sqlite3StrAccumReset(p); |
| 21732 | 21519 | setStrAccumError(p, STRACCUM_NOMEM); |
| 21733 | 21520 | return 0; |
| 21734 | 21521 | } |
| @@ -21894,17 +21681,10 @@ | ||
| 21894 | 21681 | */ |
| 21895 | 21682 | SQLITE_API char *sqlite3_vmprintf(const char *zFormat, va_list ap){ |
| 21896 | 21683 | char *z; |
| 21897 | 21684 | char zBase[SQLITE_PRINT_BUF_SIZE]; |
| 21898 | 21685 | StrAccum acc; |
| 21899 | - | |
| 21900 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 21901 | - if( zFormat==0 ){ | |
| 21902 | - (void)SQLITE_MISUSE_BKPT; | |
| 21903 | - return 0; | |
| 21904 | - } | |
| 21905 | -#endif | |
| 21906 | 21686 | #ifndef SQLITE_OMIT_AUTOINIT |
| 21907 | 21687 | if( sqlite3_initialize() ) return 0; |
| 21908 | 21688 | #endif |
| 21909 | 21689 | sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH); |
| 21910 | 21690 | acc.useMalloc = 2; |
| @@ -21943,17 +21723,10 @@ | ||
| 21943 | 21723 | ** sqlite3_vsnprintf() is the varargs version. |
| 21944 | 21724 | */ |
| 21945 | 21725 | SQLITE_API char *sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){ |
| 21946 | 21726 | StrAccum acc; |
| 21947 | 21727 | if( n<=0 ) return zBuf; |
| 21948 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 21949 | - if( zBuf==0 || zFormat==0 ) { | |
| 21950 | - (void)SQLITE_MISUSE_BKPT; | |
| 21951 | - if( zBuf && n>0 ) zBuf[0] = 0; | |
| 21952 | - return zBuf; | |
| 21953 | - } | |
| 21954 | -#endif | |
| 21955 | 21728 | sqlite3StrAccumInit(&acc, zBuf, n, 0); |
| 21956 | 21729 | acc.useMalloc = 0; |
| 21957 | 21730 | sqlite3VXPrintf(&acc, 0, zFormat, ap); |
| 21958 | 21731 | return sqlite3StrAccumFinish(&acc); |
| 21959 | 21732 | } |
| @@ -22141,23 +21914,15 @@ | ||
| 22141 | 21914 | #else |
| 22142 | 21915 | # define wsdPrng sqlite3Prng |
| 22143 | 21916 | #endif |
| 22144 | 21917 | |
| 22145 | 21918 | #if SQLITE_THREADSAFE |
| 22146 | - sqlite3_mutex *mutex; | |
| 22147 | -#endif | |
| 22148 | - | |
| 22149 | -#ifndef SQLITE_OMIT_AUTOINIT | |
| 22150 | - if( sqlite3_initialize() ) return; | |
| 22151 | -#endif | |
| 22152 | - | |
| 22153 | -#if SQLITE_THREADSAFE | |
| 22154 | - mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG); | |
| 22155 | -#endif | |
| 22156 | - | |
| 21919 | + sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG); | |
| 22157 | 21920 | sqlite3_mutex_enter(mutex); |
| 22158 | - if( N<=0 || pBuf==0 ){ | |
| 21921 | +#endif | |
| 21922 | + | |
| 21923 | + if( N<=0 ){ | |
| 22159 | 21924 | wsdPrng.isInit = 0; |
| 22160 | 21925 | sqlite3_mutex_leave(mutex); |
| 22161 | 21926 | return; |
| 22162 | 21927 | } |
| 22163 | 21928 | |
| @@ -23275,27 +23040,17 @@ | ||
| 23275 | 23040 | ** case-independent fashion, using the same definition of "case |
| 23276 | 23041 | ** independence" that SQLite uses internally when comparing identifiers. |
| 23277 | 23042 | */ |
| 23278 | 23043 | SQLITE_API int sqlite3_stricmp(const char *zLeft, const char *zRight){ |
| 23279 | 23044 | register unsigned char *a, *b; |
| 23280 | - if( zLeft==0 ){ | |
| 23281 | - return zRight ? -1 : 0; | |
| 23282 | - }else if( zRight==0 ){ | |
| 23283 | - return 1; | |
| 23284 | - } | |
| 23285 | 23045 | a = (unsigned char *)zLeft; |
| 23286 | 23046 | b = (unsigned char *)zRight; |
| 23287 | 23047 | while( *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; } |
| 23288 | 23048 | return UpperToLower[*a] - UpperToLower[*b]; |
| 23289 | 23049 | } |
| 23290 | 23050 | SQLITE_API int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){ |
| 23291 | 23051 | register unsigned char *a, *b; |
| 23292 | - if( zLeft==0 ){ | |
| 23293 | - return zRight ? -1 : 0; | |
| 23294 | - }else if( zRight==0 ){ | |
| 23295 | - return 1; | |
| 23296 | - } | |
| 23297 | 23052 | a = (unsigned char *)zLeft; |
| 23298 | 23053 | b = (unsigned char *)zRight; |
| 23299 | 23054 | while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; } |
| 23300 | 23055 | return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b]; |
| 23301 | 23056 | } |
| @@ -32824,15 +32579,10 @@ | ||
| 32824 | 32579 | #if !SQLITE_OS_WINNT && !defined(SQLITE_OMIT_WAL) |
| 32825 | 32580 | # error "WAL mode requires support from the Windows NT kernel, compile\ |
| 32826 | 32581 | with SQLITE_OMIT_WAL." |
| 32827 | 32582 | #endif |
| 32828 | 32583 | |
| 32829 | -#if !SQLITE_OS_WINNT && SQLITE_MAX_MMAP_SIZE>0 | |
| 32830 | -# error "Memory mapped files require support from the Windows NT kernel,\ | |
| 32831 | - compile with SQLITE_MAX_MMAP_SIZE=0." | |
| 32832 | -#endif | |
| 32833 | - | |
| 32834 | 32584 | /* |
| 32835 | 32585 | ** Are most of the Win32 ANSI APIs available (i.e. with certain exceptions |
| 32836 | 32586 | ** based on the sub-platform)? |
| 32837 | 32587 | */ |
| 32838 | 32588 | #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(SQLITE_WIN32_NO_ANSI) |
| @@ -32958,15 +32708,14 @@ | ||
| 32958 | 32708 | # define winGetDirSep() '\\' |
| 32959 | 32709 | #endif |
| 32960 | 32710 | |
| 32961 | 32711 | /* |
| 32962 | 32712 | ** Do we need to manually define the Win32 file mapping APIs for use with WAL |
| 32963 | -** mode or memory mapped files (e.g. these APIs are available in the Windows | |
| 32964 | -** 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)? | |
| 32965 | 32715 | */ |
| 32966 | -#if SQLITE_WIN32_FILEMAPPING_API && \ | |
| 32967 | - (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) | |
| 32716 | +#if SQLITE_WIN32_FILEMAPPING_API && !defined(SQLITE_OMIT_WAL) | |
| 32968 | 32717 | /* |
| 32969 | 32718 | ** Two of the file mapping APIs are different under WinRT. Figure out which |
| 32970 | 32719 | ** set we need. |
| 32971 | 32720 | */ |
| 32972 | 32721 | #if SQLITE_OS_WINRT |
| @@ -32990,11 +32739,11 @@ | ||
| 32990 | 32739 | |
| 32991 | 32740 | /* |
| 32992 | 32741 | ** This file mapping API is common to both Win32 and WinRT. |
| 32993 | 32742 | */ |
| 32994 | 32743 | WINBASEAPI BOOL WINAPI UnmapViewOfFile(LPCVOID); |
| 32995 | -#endif /* SQLITE_WIN32_FILEMAPPING_API */ | |
| 32744 | +#endif /* SQLITE_WIN32_FILEMAPPING_API && !defined(SQLITE_OMIT_WAL) */ | |
| 32996 | 32745 | |
| 32997 | 32746 | /* |
| 32998 | 32747 | ** Some Microsoft compilers lack this definition. |
| 32999 | 32748 | */ |
| 33000 | 32749 | #ifndef INVALID_FILE_ATTRIBUTES |
| @@ -33283,21 +33032,21 @@ | ||
| 33283 | 33032 | |
| 33284 | 33033 | #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \ |
| 33285 | 33034 | LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent) |
| 33286 | 33035 | |
| 33287 | 33036 | #if (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_ANSI) && \ |
| 33288 | - (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)) | |
| 33037 | + !defined(SQLITE_OMIT_WAL)) | |
| 33289 | 33038 | { "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 }, |
| 33290 | 33039 | #else |
| 33291 | 33040 | { "CreateFileMappingA", (SYSCALL)0, 0 }, |
| 33292 | 33041 | #endif |
| 33293 | 33042 | |
| 33294 | 33043 | #define osCreateFileMappingA ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \ |
| 33295 | 33044 | DWORD,DWORD,DWORD,LPCSTR))aSyscall[6].pCurrent) |
| 33296 | 33045 | |
| 33297 | 33046 | #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \ |
| 33298 | - (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)) | |
| 33047 | + !defined(SQLITE_OMIT_WAL)) | |
| 33299 | 33048 | { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 }, |
| 33300 | 33049 | #else |
| 33301 | 33050 | { "CreateFileMappingW", (SYSCALL)0, 0 }, |
| 33302 | 33051 | #endif |
| 33303 | 33052 | |
| @@ -33633,12 +33382,11 @@ | ||
| 33633 | 33382 | #ifndef osLockFileEx |
| 33634 | 33383 | #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \ |
| 33635 | 33384 | LPOVERLAPPED))aSyscall[48].pCurrent) |
| 33636 | 33385 | #endif |
| 33637 | 33386 | |
| 33638 | -#if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && \ | |
| 33639 | - (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)) | |
| 33387 | +#if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)) | |
| 33640 | 33388 | { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 }, |
| 33641 | 33389 | #else |
| 33642 | 33390 | { "MapViewOfFile", (SYSCALL)0, 0 }, |
| 33643 | 33391 | #endif |
| 33644 | 33392 | |
| @@ -33704,11 +33452,11 @@ | ||
| 33704 | 33452 | #endif |
| 33705 | 33453 | |
| 33706 | 33454 | #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ |
| 33707 | 33455 | LPOVERLAPPED))aSyscall[58].pCurrent) |
| 33708 | 33456 | |
| 33709 | -#if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 | |
| 33457 | +#if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL) | |
| 33710 | 33458 | { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 }, |
| 33711 | 33459 | #else |
| 33712 | 33460 | { "UnmapViewOfFile", (SYSCALL)0, 0 }, |
| 33713 | 33461 | #endif |
| 33714 | 33462 | |
| @@ -33767,11 +33515,11 @@ | ||
| 33767 | 33515 | #endif |
| 33768 | 33516 | |
| 33769 | 33517 | #define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \ |
| 33770 | 33518 | FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[66].pCurrent) |
| 33771 | 33519 | |
| 33772 | -#if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) | |
| 33520 | +#if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL) | |
| 33773 | 33521 | { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 }, |
| 33774 | 33522 | #else |
| 33775 | 33523 | { "MapViewOfFileFromApp", (SYSCALL)0, 0 }, |
| 33776 | 33524 | #endif |
| 33777 | 33525 | |
| @@ -33831,11 +33579,11 @@ | ||
| 33831 | 33579 | |
| 33832 | 33580 | { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 }, |
| 33833 | 33581 | |
| 33834 | 33582 | #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[74].pCurrent) |
| 33835 | 33583 | |
| 33836 | -#if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) | |
| 33584 | +#if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL) | |
| 33837 | 33585 | { "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 }, |
| 33838 | 33586 | #else |
| 33839 | 33587 | { "CreateFileMappingFromApp", (SYSCALL)0, 0 }, |
| 33840 | 33588 | #endif |
| 33841 | 33589 | |
| @@ -39407,17 +39155,10 @@ | ||
| 39407 | 39155 | */ |
| 39408 | 39156 | SQLITE_PRIVATE void sqlite3PcacheShrink(PCache *pCache){ |
| 39409 | 39157 | assert( pCache->pCache!=0 ); |
| 39410 | 39158 | sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache); |
| 39411 | 39159 | } |
| 39412 | - | |
| 39413 | -/* | |
| 39414 | -** Return the size of the header added by this middleware layer | |
| 39415 | -** in the page-cache hierarchy. | |
| 39416 | -*/ | |
| 39417 | -SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return sizeof(PgHdr); } | |
| 39418 | - | |
| 39419 | 39160 | |
| 39420 | 39161 | #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG) |
| 39421 | 39162 | /* |
| 39422 | 39163 | ** For all dirty pages currently in the cache, invoke the specified |
| 39423 | 39164 | ** callback. This is only used if the SQLITE_CHECK_PAGES macro is |
| @@ -40413,15 +40154,10 @@ | ||
| 40413 | 40154 | pcache1Shrink /* xShrink */ |
| 40414 | 40155 | }; |
| 40415 | 40156 | sqlite3_config(SQLITE_CONFIG_PCACHE2, &defaultMethods); |
| 40416 | 40157 | } |
| 40417 | 40158 | |
| 40418 | -/* | |
| 40419 | -** Return the size of the header on each page of this PCACHE implementation. | |
| 40420 | -*/ | |
| 40421 | -SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void){ return sizeof(PgHdr1); } | |
| 40422 | - | |
| 40423 | 40159 | #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 40424 | 40160 | /* |
| 40425 | 40161 | ** This function is called to free superfluous dynamically allocated memory |
| 40426 | 40162 | ** held by the pager system. Memory in use by any SQLite pager allocated |
| 40427 | 40163 | ** by the current thread may be sqlite3_free()ed. |
| @@ -47975,22 +47711,10 @@ | ||
| 47975 | 47711 | |
| 47976 | 47712 | return SQLITE_OK; |
| 47977 | 47713 | } |
| 47978 | 47714 | #endif |
| 47979 | 47715 | |
| 47980 | -/* | |
| 47981 | -** The page handle passed as the first argument refers to a dirty page | |
| 47982 | -** with a page number other than iNew. This function changes the page's | |
| 47983 | -** page number to iNew and sets the value of the PgHdr.flags field to | |
| 47984 | -** the value passed as the third parameter. | |
| 47985 | -*/ | |
| 47986 | -SQLITE_PRIVATE void sqlite3PagerRekey(DbPage *pPg, Pgno iNew, u16 flags){ | |
| 47987 | - assert( pPg->pgno!=iNew ); | |
| 47988 | - pPg->flags = flags; | |
| 47989 | - sqlite3PcacheMove(pPg, iNew); | |
| 47990 | -} | |
| 47991 | - | |
| 47992 | 47716 | /* |
| 47993 | 47717 | ** Return a pointer to the data for the specified page. |
| 47994 | 47718 | */ |
| 47995 | 47719 | SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *pPg){ |
| 47996 | 47720 | assert( pPg->nRef>0 || pPg->pPager->memDb ); |
| @@ -48384,11 +48108,10 @@ | ||
| 48384 | 48108 | SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager){ |
| 48385 | 48109 | assert( pPager->eState>=PAGER_READER ); |
| 48386 | 48110 | return sqlite3WalFramesize(pPager->pWal); |
| 48387 | 48111 | } |
| 48388 | 48112 | #endif |
| 48389 | - | |
| 48390 | 48113 | |
| 48391 | 48114 | #endif /* SQLITE_OMIT_DISKIO */ |
| 48392 | 48115 | |
| 48393 | 48116 | /************** End of pager.c ***********************************************/ |
| 48394 | 48117 | /************** Begin file wal.c *********************************************/ |
| @@ -49895,11 +49618,11 @@ | ||
| 49895 | 49618 | |
| 49896 | 49619 | /* |
| 49897 | 49620 | ** Free an iterator allocated by walIteratorInit(). |
| 49898 | 49621 | */ |
| 49899 | 49622 | static void walIteratorFree(WalIterator *p){ |
| 49900 | - sqlite3_free(p); | |
| 49623 | + sqlite3ScratchFree(p); | |
| 49901 | 49624 | } |
| 49902 | 49625 | |
| 49903 | 49626 | /* |
| 49904 | 49627 | ** Construct a WalInterator object that can be used to loop over all |
| 49905 | 49628 | ** pages in the WAL in ascending order. The caller must hold the checkpoint |
| @@ -49930,21 +49653,21 @@ | ||
| 49930 | 49653 | /* Allocate space for the WalIterator object. */ |
| 49931 | 49654 | nSegment = walFramePage(iLast) + 1; |
| 49932 | 49655 | nByte = sizeof(WalIterator) |
| 49933 | 49656 | + (nSegment-1)*sizeof(struct WalSegment) |
| 49934 | 49657 | + iLast*sizeof(ht_slot); |
| 49935 | - p = (WalIterator *)sqlite3_malloc(nByte); | |
| 49658 | + p = (WalIterator *)sqlite3ScratchMalloc(nByte); | |
| 49936 | 49659 | if( !p ){ |
| 49937 | 49660 | return SQLITE_NOMEM; |
| 49938 | 49661 | } |
| 49939 | 49662 | memset(p, 0, nByte); |
| 49940 | 49663 | p->nSegment = nSegment; |
| 49941 | 49664 | |
| 49942 | 49665 | /* Allocate temporary space used by the merge-sort routine. This block |
| 49943 | 49666 | ** of memory will be freed before this function returns. |
| 49944 | 49667 | */ |
| 49945 | - aTmp = (ht_slot *)sqlite3_malloc( | |
| 49668 | + aTmp = (ht_slot *)sqlite3ScratchMalloc( | |
| 49946 | 49669 | sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast) |
| 49947 | 49670 | ); |
| 49948 | 49671 | if( !aTmp ){ |
| 49949 | 49672 | rc = SQLITE_NOMEM; |
| 49950 | 49673 | } |
| @@ -49977,11 +49700,11 @@ | ||
| 49977 | 49700 | p->aSegment[i].nEntry = nEntry; |
| 49978 | 49701 | p->aSegment[i].aIndex = aIndex; |
| 49979 | 49702 | p->aSegment[i].aPgno = (u32 *)aPgno; |
| 49980 | 49703 | } |
| 49981 | 49704 | } |
| 49982 | - sqlite3_free(aTmp); | |
| 49705 | + sqlite3ScratchFree(aTmp); | |
| 49983 | 49706 | |
| 49984 | 49707 | if( rc!=SQLITE_OK ){ |
| 49985 | 49708 | walIteratorFree(p); |
| 49986 | 49709 | } |
| 49987 | 49710 | *pp = p; |
| @@ -50897,11 +50620,11 @@ | ||
| 50897 | 50620 | ** was in before the client began writing to the database. |
| 50898 | 50621 | */ |
| 50899 | 50622 | memcpy(&pWal->hdr, (void *)walIndexHdr(pWal), sizeof(WalIndexHdr)); |
| 50900 | 50623 | |
| 50901 | 50624 | for(iFrame=pWal->hdr.mxFrame+1; |
| 50902 | - rc==SQLITE_OK && iFrame<=iMax; | |
| 50625 | + ALWAYS(rc==SQLITE_OK) && iFrame<=iMax; | |
| 50903 | 50626 | iFrame++ |
| 50904 | 50627 | ){ |
| 50905 | 50628 | /* This call cannot fail. Unless the page for which the page number |
| 50906 | 50629 | ** is passed as the second argument is (a) in the cache and |
| 50907 | 50630 | ** (b) has an outstanding reference, then xUndo is either a no-op |
| @@ -53620,27 +53343,28 @@ | ||
| 53620 | 53343 | int cellOffset; /* Offset to the cell pointer array */ |
| 53621 | 53344 | int cbrk; /* Offset to the cell content area */ |
| 53622 | 53345 | int nCell; /* Number of cells on the page */ |
| 53623 | 53346 | unsigned char *data; /* The page data */ |
| 53624 | 53347 | unsigned char *temp; /* Temp area for cell content */ |
| 53625 | - unsigned char *src; /* Source of content */ | |
| 53626 | 53348 | int iCellFirst; /* First allowable cell index */ |
| 53627 | 53349 | int iCellLast; /* Last possible cell index */ |
| 53628 | 53350 | |
| 53629 | 53351 | |
| 53630 | 53352 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 53631 | 53353 | assert( pPage->pBt!=0 ); |
| 53632 | 53354 | assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE ); |
| 53633 | 53355 | assert( pPage->nOverflow==0 ); |
| 53634 | 53356 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 53635 | - temp = 0; | |
| 53636 | - src = data = pPage->aData; | |
| 53357 | + temp = sqlite3PagerTempSpace(pPage->pBt->pPager); | |
| 53358 | + data = pPage->aData; | |
| 53637 | 53359 | hdr = pPage->hdrOffset; |
| 53638 | 53360 | cellOffset = pPage->cellOffset; |
| 53639 | 53361 | nCell = pPage->nCell; |
| 53640 | 53362 | assert( nCell==get2byte(&data[hdr+3]) ); |
| 53641 | 53363 | usableSize = pPage->pBt->usableSize; |
| 53364 | + cbrk = get2byte(&data[hdr+5]); | |
| 53365 | + memcpy(&temp[cbrk], &data[cbrk], usableSize - cbrk); | |
| 53642 | 53366 | cbrk = usableSize; |
| 53643 | 53367 | iCellFirst = cellOffset + 2*nCell; |
| 53644 | 53368 | iCellLast = usableSize - 4; |
| 53645 | 53369 | for(i=0; i<nCell; i++){ |
| 53646 | 53370 | u8 *pAddr; /* The i-th cell pointer */ |
| @@ -53655,11 +53379,11 @@ | ||
| 53655 | 53379 | if( pc<iCellFirst || pc>iCellLast ){ |
| 53656 | 53380 | return SQLITE_CORRUPT_BKPT; |
| 53657 | 53381 | } |
| 53658 | 53382 | #endif |
| 53659 | 53383 | assert( pc>=iCellFirst && pc<=iCellLast ); |
| 53660 | - size = cellSizePtr(pPage, &src[pc]); | |
| 53384 | + size = cellSizePtr(pPage, &temp[pc]); | |
| 53661 | 53385 | cbrk -= size; |
| 53662 | 53386 | #if defined(SQLITE_ENABLE_OVERSIZE_CELL_CHECK) |
| 53663 | 53387 | if( cbrk<iCellFirst ){ |
| 53664 | 53388 | return SQLITE_CORRUPT_BKPT; |
| 53665 | 53389 | } |
| @@ -53669,20 +53393,12 @@ | ||
| 53669 | 53393 | } |
| 53670 | 53394 | #endif |
| 53671 | 53395 | assert( cbrk+size<=usableSize && cbrk>=iCellFirst ); |
| 53672 | 53396 | testcase( cbrk+size==usableSize ); |
| 53673 | 53397 | testcase( pc+size==usableSize ); |
| 53398 | + memcpy(&data[cbrk], &temp[pc], size); | |
| 53674 | 53399 | put2byte(pAddr, cbrk); |
| 53675 | - if( temp==0 ){ | |
| 53676 | - int x; | |
| 53677 | - if( cbrk==pc ) continue; | |
| 53678 | - temp = sqlite3PagerTempSpace(pPage->pBt->pPager); | |
| 53679 | - x = get2byte(&data[hdr+5]); | |
| 53680 | - memcpy(&temp[x], &data[x], (cbrk+size) - x); | |
| 53681 | - src = temp; | |
| 53682 | - } | |
| 53683 | - memcpy(&data[cbrk], &src[pc], size); | |
| 53684 | 53400 | } |
| 53685 | 53401 | assert( cbrk>=iCellFirst ); |
| 53686 | 53402 | put2byte(&data[hdr+5], cbrk); |
| 53687 | 53403 | data[hdr+1] = 0; |
| 53688 | 53404 | data[hdr+2] = 0; |
| @@ -53693,66 +53409,10 @@ | ||
| 53693 | 53409 | return SQLITE_CORRUPT_BKPT; |
| 53694 | 53410 | } |
| 53695 | 53411 | return SQLITE_OK; |
| 53696 | 53412 | } |
| 53697 | 53413 | |
| 53698 | -/* | |
| 53699 | -** Search the free-list on page pPg for space to store a cell nByte bytes in | |
| 53700 | -** size. If one can be found, return a pointer to the space and remove it | |
| 53701 | -** from the free-list. | |
| 53702 | -** | |
| 53703 | -** If no suitable space can be found on the free-list, return NULL. | |
| 53704 | -** | |
| 53705 | -** This function may detect corruption within pPg. If corruption is | |
| 53706 | -** detected then *pRc is set to SQLITE_CORRUPT and NULL is returned. | |
| 53707 | -** | |
| 53708 | -** If a slot of at least nByte bytes is found but cannot be used because | |
| 53709 | -** there are already at least 60 fragmented bytes on the page, return NULL. | |
| 53710 | -** In this case, if pbDefrag parameter is not NULL, set *pbDefrag to true. | |
| 53711 | -*/ | |
| 53712 | -static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc, int *pbDefrag){ | |
| 53713 | - const int hdr = pPg->hdrOffset; | |
| 53714 | - u8 * const aData = pPg->aData; | |
| 53715 | - int iAddr; | |
| 53716 | - int pc; | |
| 53717 | - int usableSize = pPg->pBt->usableSize; | |
| 53718 | - | |
| 53719 | - for(iAddr=hdr+1; (pc = get2byte(&aData[iAddr]))>0; iAddr=pc){ | |
| 53720 | - int size; /* Size of the free slot */ | |
| 53721 | - if( pc>usableSize-4 || pc<iAddr+4 ){ | |
| 53722 | - *pRc = SQLITE_CORRUPT_BKPT; | |
| 53723 | - return 0; | |
| 53724 | - } | |
| 53725 | - size = get2byte(&aData[pc+2]); | |
| 53726 | - if( size>=nByte ){ | |
| 53727 | - int x = size - nByte; | |
| 53728 | - testcase( x==4 ); | |
| 53729 | - testcase( x==3 ); | |
| 53730 | - if( x<4 ){ | |
| 53731 | - if( aData[hdr+7]>=60 ){ | |
| 53732 | - if( pbDefrag ) *pbDefrag = 1; | |
| 53733 | - return 0; | |
| 53734 | - } | |
| 53735 | - /* Remove the slot from the free-list. Update the number of | |
| 53736 | - ** fragmented bytes within the page. */ | |
| 53737 | - memcpy(&aData[iAddr], &aData[pc], 2); | |
| 53738 | - aData[hdr+7] += (u8)x; | |
| 53739 | - }else if( size+pc > usableSize ){ | |
| 53740 | - *pRc = SQLITE_CORRUPT_BKPT; | |
| 53741 | - return 0; | |
| 53742 | - }else{ | |
| 53743 | - /* The slot remains on the free-list. Reduce its size to account | |
| 53744 | - ** for the portion used by the new allocation. */ | |
| 53745 | - put2byte(&aData[pc+2], x); | |
| 53746 | - } | |
| 53747 | - return &aData[pc + x]; | |
| 53748 | - } | |
| 53749 | - } | |
| 53750 | - | |
| 53751 | - return 0; | |
| 53752 | -} | |
| 53753 | - | |
| 53754 | 53414 | /* |
| 53755 | 53415 | ** Allocate nByte bytes of space from within the B-Tree page passed |
| 53756 | 53416 | ** as the first argument. Write into *pIdx the index into pPage->aData[] |
| 53757 | 53417 | ** of the first byte of allocated space. Return either SQLITE_OK or |
| 53758 | 53418 | ** an error code (usually SQLITE_CORRUPT). |
| @@ -53766,20 +53426,22 @@ | ||
| 53766 | 53426 | */ |
| 53767 | 53427 | static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ |
| 53768 | 53428 | const int hdr = pPage->hdrOffset; /* Local cache of pPage->hdrOffset */ |
| 53769 | 53429 | u8 * const data = pPage->aData; /* Local cache of pPage->aData */ |
| 53770 | 53430 | int top; /* First byte of cell content area */ |
| 53771 | - int rc = SQLITE_OK; /* Integer return code */ | |
| 53772 | 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 */ | |
| 53773 | 53434 | |
| 53774 | 53435 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 53775 | 53436 | assert( pPage->pBt ); |
| 53776 | 53437 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 53777 | 53438 | assert( nByte>=0 ); /* Minimum cell size is 4 */ |
| 53778 | 53439 | assert( pPage->nFree>=nByte ); |
| 53779 | 53440 | assert( pPage->nOverflow==0 ); |
| 53780 | - assert( nByte < (int)(pPage->pBt->usableSize-8) ); | |
| 53441 | + usableSize = pPage->pBt->usableSize; | |
| 53442 | + assert( nByte < usableSize-8 ); | |
| 53781 | 53443 | |
| 53782 | 53444 | assert( pPage->cellOffset == hdr + 12 - 4*pPage->leaf ); |
| 53783 | 53445 | gap = pPage->cellOffset + 2*pPage->nCell; |
| 53784 | 53446 | assert( gap<=65536 ); |
| 53785 | 53447 | top = get2byte(&data[hdr+5]); |
| @@ -53797,27 +53459,46 @@ | ||
| 53797 | 53459 | */ |
| 53798 | 53460 | testcase( gap+2==top ); |
| 53799 | 53461 | testcase( gap+1==top ); |
| 53800 | 53462 | testcase( gap==top ); |
| 53801 | 53463 | if( gap+2<=top && (data[hdr+1] || data[hdr+2]) ){ |
| 53802 | - int bDefrag = 0; | |
| 53803 | - u8 *pSpace = pageFindSlot(pPage, nByte, &rc, &bDefrag); | |
| 53804 | - if( rc ) return rc; | |
| 53805 | - if( bDefrag ) goto defragment_page; | |
| 53806 | - if( pSpace ){ | |
| 53807 | - assert( pSpace>=data && (pSpace - data)<65536 ); | |
| 53808 | - *pIdx = (int)(pSpace - data); | |
| 53809 | - 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 | + } | |
| 53810 | 53491 | } |
| 53811 | 53492 | } |
| 53812 | 53493 | |
| 53813 | 53494 | /* The request could not be fulfilled using a freelist slot. Check |
| 53814 | 53495 | ** to see if defragmentation is necessary. |
| 53815 | 53496 | */ |
| 53816 | 53497 | testcase( gap+2+nByte==top ); |
| 53817 | 53498 | if( gap+2+nByte>top ){ |
| 53818 | - defragment_page: | |
| 53499 | +defragment_page: | |
| 53819 | 53500 | testcase( pPage->nCell==0 ); |
| 53820 | 53501 | rc = defragmentPage(pPage); |
| 53821 | 53502 | if( rc ) return rc; |
| 53822 | 53503 | top = get2byteNotZero(&data[hdr+5]); |
| 53823 | 53504 | assert( gap+nByte<=top ); |
| @@ -53861,11 +53542,11 @@ | ||
| 53861 | 53542 | unsigned char *data = pPage->aData; /* Page content */ |
| 53862 | 53543 | |
| 53863 | 53544 | assert( pPage->pBt!=0 ); |
| 53864 | 53545 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 53865 | 53546 | assert( iStart>=pPage->hdrOffset+6+pPage->childPtrSize ); |
| 53866 | - assert( CORRUPT_DB || iEnd <= pPage->pBt->usableSize ); | |
| 53547 | + assert( iEnd <= pPage->pBt->usableSize ); | |
| 53867 | 53548 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 53868 | 53549 | assert( iSize>=4 ); /* Minimum cell size is 4 */ |
| 53869 | 53550 | assert( iStart<=iLast ); |
| 53870 | 53551 | |
| 53871 | 53552 | /* Overwrite deleted information with zeros when the secure_delete |
| @@ -58476,266 +58157,49 @@ | ||
| 58476 | 58157 | #endif |
| 58477 | 58158 | } |
| 58478 | 58159 | } |
| 58479 | 58160 | |
| 58480 | 58161 | /* |
| 58481 | -** Array apCell[] contains pointers to nCell b-tree page cells. The | |
| 58482 | -** szCell[] array contains the size in bytes of each cell. This function | |
| 58483 | -** replaces the current contents of page pPg with the contents of the cell | |
| 58484 | -** array. | |
| 58485 | -** | |
| 58486 | -** Some of the cells in apCell[] may currently be stored in pPg. This | |
| 58487 | -** function works around problems caused by this by making a copy of any | |
| 58488 | -** such cells before overwriting the page data. | |
| 58489 | -** | |
| 58490 | -** The MemPage.nFree field is invalidated by this function. It is the | |
| 58491 | -** responsibility of the caller to set it correctly. | |
| 58492 | -*/ | |
| 58493 | -static void rebuildPage( | |
| 58494 | - MemPage *pPg, /* Edit this page */ | |
| 58495 | - int nCell, /* Final number of cells on page */ | |
| 58496 | - u8 **apCell, /* Array of cells */ | |
| 58497 | - u16 *szCell /* Array of cell sizes */ | |
| 58498 | -){ | |
| 58499 | - const int hdr = pPg->hdrOffset; /* Offset of header on pPg */ | |
| 58500 | - u8 * const aData = pPg->aData; /* Pointer to data for pPg */ | |
| 58501 | - const int usableSize = pPg->pBt->usableSize; | |
| 58502 | - u8 * const pEnd = &aData[usableSize]; | |
| 58503 | - int i; | |
| 58504 | - u8 *pCellptr = pPg->aCellIdx; | |
| 58505 | - u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager); | |
| 58506 | - u8 *pData; | |
| 58507 | - | |
| 58508 | - i = get2byte(&aData[hdr+5]); | |
| 58509 | - memcpy(&pTmp[i], &aData[i], usableSize - i); | |
| 58510 | - | |
| 58511 | - pData = pEnd; | |
| 58512 | - for(i=0; i<nCell; i++){ | |
| 58513 | - u8 *pCell = apCell[i]; | |
| 58514 | - if( pCell>aData && pCell<pEnd ){ | |
| 58515 | - pCell = &pTmp[pCell - aData]; | |
| 58516 | - } | |
| 58517 | - pData -= szCell[i]; | |
| 58518 | - memcpy(pData, pCell, szCell[i]); | |
| 58519 | - put2byte(pCellptr, (pData - aData)); | |
| 58520 | - pCellptr += 2; | |
| 58521 | - assert( szCell[i]==cellSizePtr(pPg, pCell) ); | |
| 58522 | - } | |
| 58523 | - | |
| 58524 | - /* The pPg->nFree field is now set incorrectly. The caller will fix it. */ | |
| 58525 | - pPg->nCell = nCell; | |
| 58526 | - pPg->nOverflow = 0; | |
| 58527 | - | |
| 58528 | - put2byte(&aData[hdr+1], 0); | |
| 58529 | - put2byte(&aData[hdr+3], pPg->nCell); | |
| 58530 | - put2byte(&aData[hdr+5], pData - aData); | |
| 58531 | - aData[hdr+7] = 0x00; | |
| 58532 | -} | |
| 58533 | - | |
| 58534 | -/* | |
| 58535 | -** Array apCell[] contains nCell pointers to b-tree cells. Array szCell | |
| 58536 | -** contains the size in bytes of each such cell. This function attempts to | |
| 58537 | -** add the cells stored in the array to page pPg. If it cannot (because | |
| 58538 | -** the page needs to be defragmented before the cells will fit), non-zero | |
| 58539 | -** is returned. Otherwise, if the cells are added successfully, zero is | |
| 58540 | -** returned. | |
| 58541 | -** | |
| 58542 | -** Argument pCellptr points to the first entry in the cell-pointer array | |
| 58543 | -** (part of page pPg) to populate. After cell apCell[0] is written to the | |
| 58544 | -** page body, a 16-bit offset is written to pCellptr. And so on, for each | |
| 58545 | -** cell in the array. It is the responsibility of the caller to ensure | |
| 58546 | -** that it is safe to overwrite this part of the cell-pointer array. | |
| 58547 | -** | |
| 58548 | -** When this function is called, *ppData points to the start of the | |
| 58549 | -** content area on page pPg. If the size of the content area is extended, | |
| 58550 | -** *ppData is updated to point to the new start of the content area | |
| 58551 | -** before returning. | |
| 58552 | -** | |
| 58553 | -** Finally, argument pBegin points to the byte immediately following the | |
| 58554 | -** end of the space required by this page for the cell-pointer area (for | |
| 58555 | -** all cells - not just those inserted by the current call). If the content | |
| 58556 | -** area must be extended to before this point in order to accomodate all | |
| 58557 | -** cells in apCell[], then the cells do not fit and non-zero is returned. | |
| 58558 | -*/ | |
| 58559 | -static int pageInsertArray( | |
| 58560 | - MemPage *pPg, /* Page to add cells to */ | |
| 58561 | - u8 *pBegin, /* End of cell-pointer array */ | |
| 58562 | - u8 **ppData, /* IN/OUT: Page content -area pointer */ | |
| 58563 | - u8 *pCellptr, /* Pointer to cell-pointer area */ | |
| 58564 | - int nCell, /* Number of cells to add to pPg */ | |
| 58565 | - u8 **apCell, /* Array of cells */ | |
| 58566 | - u16 *szCell /* Array of cell sizes */ | |
| 58567 | -){ | |
| 58568 | - int i; | |
| 58569 | - u8 *aData = pPg->aData; | |
| 58570 | - u8 *pData = *ppData; | |
| 58571 | - const int bFreelist = aData[1] || aData[2]; | |
| 58572 | - assert( CORRUPT_DB || pPg->hdrOffset==0 ); /* Never called on page 1 */ | |
| 58573 | - for(i=0; i<nCell; i++){ | |
| 58574 | - int sz = szCell[i]; | |
| 58575 | - int rc; | |
| 58576 | - u8 *pSlot; | |
| 58577 | - if( bFreelist==0 || (pSlot = pageFindSlot(pPg, sz, &rc, 0))==0 ){ | |
| 58578 | - pData -= sz; | |
| 58579 | - if( pData<pBegin ) return 1; | |
| 58580 | - pSlot = pData; | |
| 58581 | - } | |
| 58582 | - memcpy(pSlot, apCell[i], sz); | |
| 58583 | - put2byte(pCellptr, (pSlot - aData)); | |
| 58584 | - pCellptr += 2; | |
| 58585 | - } | |
| 58586 | - *ppData = pData; | |
| 58587 | - return 0; | |
| 58588 | -} | |
| 58589 | - | |
| 58590 | -/* | |
| 58591 | -** Array apCell[] contains nCell pointers to b-tree cells. Array szCell | |
| 58592 | -** contains the size in bytes of each such cell. This function adds the | |
| 58593 | -** space associated with each cell in the array that is currently stored | |
| 58594 | -** within the body of pPg to the pPg free-list. The cell-pointers and other | |
| 58595 | -** fields of the page are not updated. | |
| 58596 | -** | |
| 58597 | -** This function returns the total number of cells added to the free-list. | |
| 58598 | -*/ | |
| 58599 | -static int pageFreeArray( | |
| 58600 | - MemPage *pPg, /* Page to edit */ | |
| 58601 | - int nCell, /* Cells to delete */ | |
| 58602 | - u8 **apCell, /* Array of cells */ | |
| 58603 | - u16 *szCell /* Array of cell sizes */ | |
| 58604 | -){ | |
| 58605 | - u8 * const aData = pPg->aData; | |
| 58606 | - u8 * const pEnd = &aData[pPg->pBt->usableSize]; | |
| 58607 | - u8 * const pStart = &aData[pPg->hdrOffset + 8 + pPg->childPtrSize]; | |
| 58608 | - int nRet = 0; | |
| 58609 | - int i; | |
| 58610 | - u8 *pFree = 0; | |
| 58611 | - int szFree = 0; | |
| 58612 | - | |
| 58613 | - for(i=0; i<nCell; i++){ | |
| 58614 | - u8 *pCell = apCell[i]; | |
| 58615 | - if( pCell>=pStart && pCell<pEnd ){ | |
| 58616 | - int sz = szCell[i]; | |
| 58617 | - if( pFree!=(pCell + sz) ){ | |
| 58618 | - if( pFree ){ | |
| 58619 | - assert( pFree>aData && (pFree - aData)<65536 ); | |
| 58620 | - freeSpace(pPg, (u16)(pFree - aData), szFree); | |
| 58621 | - } | |
| 58622 | - pFree = pCell; | |
| 58623 | - szFree = sz; | |
| 58624 | - if( pFree+sz>pEnd ) return 0; | |
| 58625 | - }else{ | |
| 58626 | - pFree = pCell; | |
| 58627 | - szFree += sz; | |
| 58628 | - } | |
| 58629 | - nRet++; | |
| 58630 | - } | |
| 58631 | - } | |
| 58632 | - if( pFree ){ | |
| 58633 | - assert( pFree>aData && (pFree - aData)<65536 ); | |
| 58634 | - freeSpace(pPg, (u16)(pFree - aData), szFree); | |
| 58635 | - } | |
| 58636 | - return nRet; | |
| 58637 | -} | |
| 58638 | - | |
| 58639 | -/* | |
| 58640 | -** The pPg->nFree field is invalid when this function returns. It is the | |
| 58641 | -** responsibility of the caller to set it correctly. | |
| 58642 | -*/ | |
| 58643 | -static void editPage( | |
| 58644 | - MemPage *pPg, /* Edit this page */ | |
| 58645 | - int iOld, /* Index of first cell currently on page */ | |
| 58646 | - int iNew, /* Index of new first cell on page */ | |
| 58647 | - int nNew, /* Final number of cells on page */ | |
| 58648 | - u8 **apCell, /* Array of cells */ | |
| 58649 | - u16 *szCell /* Array of cell sizes */ | |
| 58650 | -){ | |
| 58651 | - u8 * const aData = pPg->aData; | |
| 58652 | - const int hdr = pPg->hdrOffset; | |
| 58653 | - u8 *pBegin = &pPg->aCellIdx[nNew * 2]; | |
| 58654 | - int nCell = pPg->nCell; /* Cells stored on pPg */ | |
| 58655 | - u8 *pData; | |
| 58656 | - u8 *pCellptr; | |
| 58657 | - int i; | |
| 58658 | - int iOldEnd = iOld + pPg->nCell + pPg->nOverflow; | |
| 58659 | - int iNewEnd = iNew + nNew; | |
| 58660 | - | |
| 58661 | -#ifdef SQLITE_DEBUG | |
| 58662 | - u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager); | |
| 58663 | - memcpy(pTmp, aData, pPg->pBt->usableSize); | |
| 58664 | -#endif | |
| 58665 | - | |
| 58666 | - /* Remove cells from the start and end of the page */ | |
| 58667 | - if( iOld<iNew ){ | |
| 58668 | - int nShift = pageFreeArray( | |
| 58669 | - pPg, iNew-iOld, &apCell[iOld], &szCell[iOld] | |
| 58670 | - ); | |
| 58671 | - memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2); | |
| 58672 | - nCell -= nShift; | |
| 58673 | - } | |
| 58674 | - if( iNewEnd < iOldEnd ){ | |
| 58675 | - nCell -= pageFreeArray( | |
| 58676 | - pPg, iOldEnd-iNewEnd, &apCell[iNewEnd], &szCell[iNewEnd] | |
| 58677 | - ); | |
| 58678 | - } | |
| 58679 | - | |
| 58680 | - pData = &aData[get2byte(&aData[hdr+5])]; | |
| 58681 | - if( pData<pBegin ) goto editpage_fail; | |
| 58682 | - | |
| 58683 | - /* Add cells to the start of the page */ | |
| 58684 | - if( iNew<iOld ){ | |
| 58685 | - int nAdd = iOld-iNew; | |
| 58686 | - pCellptr = pPg->aCellIdx; | |
| 58687 | - memmove(&pCellptr[nAdd*2], pCellptr, nCell*2); | |
| 58688 | - if( pageInsertArray( | |
| 58689 | - pPg, pBegin, &pData, pCellptr, | |
| 58690 | - nAdd, &apCell[iNew], &szCell[iNew] | |
| 58691 | - ) ) goto editpage_fail; | |
| 58692 | - nCell += nAdd; | |
| 58693 | - } | |
| 58694 | - | |
| 58695 | - /* Add any overflow cells */ | |
| 58696 | - for(i=0; i<pPg->nOverflow; i++){ | |
| 58697 | - int iCell = (iOld + pPg->aiOvfl[i]) - iNew; | |
| 58698 | - if( iCell>=0 && iCell<nNew ){ | |
| 58699 | - pCellptr = &pPg->aCellIdx[iCell * 2]; | |
| 58700 | - memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2); | |
| 58701 | - nCell++; | |
| 58702 | - if( pageInsertArray( | |
| 58703 | - pPg, pBegin, &pData, pCellptr, | |
| 58704 | - 1, &apCell[iCell + iNew], &szCell[iCell + iNew] | |
| 58705 | - ) ) goto editpage_fail; | |
| 58706 | - } | |
| 58707 | - } | |
| 58708 | - | |
| 58709 | - /* Append cells to the end of the page */ | |
| 58710 | - pCellptr = &pPg->aCellIdx[nCell*2]; | |
| 58711 | - if( pageInsertArray( | |
| 58712 | - pPg, pBegin, &pData, pCellptr, | |
| 58713 | - nNew-nCell, &apCell[iNew+nCell], &szCell[iNew+nCell] | |
| 58714 | - ) ) goto editpage_fail; | |
| 58715 | - | |
| 58716 | - pPg->nCell = nNew; | |
| 58717 | - pPg->nOverflow = 0; | |
| 58718 | - | |
| 58719 | - put2byte(&aData[hdr+3], pPg->nCell); | |
| 58720 | - put2byte(&aData[hdr+5], pData - aData); | |
| 58721 | - | |
| 58722 | -#ifdef SQLITE_DEBUG | |
| 58723 | - for(i=0; i<nNew && !CORRUPT_DB; i++){ | |
| 58724 | - u8 *pCell = apCell[i+iNew]; | |
| 58725 | - int iOff = get2byte(&pPg->aCellIdx[i*2]); | |
| 58726 | - if( pCell>=aData && pCell<&aData[pPg->pBt->usableSize] ){ | |
| 58727 | - pCell = &pTmp[pCell - aData]; | |
| 58728 | - } | |
| 58729 | - assert( 0==memcmp(pCell, &aData[iOff], szCell[i+iNew]) ); | |
| 58730 | - } | |
| 58731 | -#endif | |
| 58732 | - | |
| 58733 | - return; | |
| 58734 | - editpage_fail: | |
| 58735 | - /* Unable to edit this page. Rebuild it from scratch instead. */ | |
| 58736 | - 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; | |
| 58737 | 58201 | } |
| 58738 | 58202 | |
| 58739 | 58203 | /* |
| 58740 | 58204 | ** The following parameters determine how many adjacent pages get involved |
| 58741 | 58205 | ** in a balancing operation. NN is the number of neighbors on either side |
| @@ -58803,12 +58267,11 @@ | ||
| 58803 | 58267 | u8 *pStop; |
| 58804 | 58268 | |
| 58805 | 58269 | assert( sqlite3PagerIswriteable(pNew->pDbPage) ); |
| 58806 | 58270 | assert( pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) ); |
| 58807 | 58271 | zeroPage(pNew, PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF); |
| 58808 | - rebuildPage(pNew, 1, &pCell, &szCell); | |
| 58809 | - pNew->nFree = pBt->usableSize - pNew->cellOffset - 2 - szCell; | |
| 58272 | + assemblePage(pNew, 1, &pCell, &szCell); | |
| 58810 | 58273 | |
| 58811 | 58274 | /* If this is an auto-vacuum database, update the pointer map |
| 58812 | 58275 | ** with entries for the new page, and any pointer from the |
| 58813 | 58276 | ** cell on the page to an overflow page. If either of these |
| 58814 | 58277 | ** operations fails, the return code is set, but the contents |
| @@ -59023,26 +58486,21 @@ | ||
| 59023 | 58486 | int subtotal; /* Subtotal of bytes in cells on one page */ |
| 59024 | 58487 | int iSpace1 = 0; /* First unused byte of aSpace1[] */ |
| 59025 | 58488 | int iOvflSpace = 0; /* First unused byte of aOvflSpace[] */ |
| 59026 | 58489 | int szScratch; /* Size of scratch memory requested */ |
| 59027 | 58490 | MemPage *apOld[NB]; /* pPage and up to two siblings */ |
| 58491 | + MemPage *apCopy[NB]; /* Private copies of apOld[] pages */ | |
| 59028 | 58492 | MemPage *apNew[NB+2]; /* pPage and up to NB siblings after balancing */ |
| 59029 | 58493 | u8 *pRight; /* Location in parent of right-sibling pointer */ |
| 59030 | 58494 | u8 *apDiv[NB-1]; /* Divider cells in pParent */ |
| 59031 | 58495 | int cntNew[NB+2]; /* Index in aCell[] of cell after i-th page */ |
| 59032 | - int cntOld[NB+2]; /* Old index in aCell[] after i-th page */ | |
| 59033 | - 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 */ | |
| 59034 | 58497 | u8 **apCell = 0; /* All cells begin balanced */ |
| 59035 | 58498 | u16 *szCell; /* Local size of all cells in apCell[] */ |
| 59036 | 58499 | u8 *aSpace1; /* Space for copies of dividers cells */ |
| 59037 | 58500 | Pgno pgno; /* Temp var to store a page number in */ |
| 59038 | - u8 abDone[NB+2]; /* True after i'th new page is populated */ | |
| 59039 | - Pgno aPgno[NB+2]; /* Page numbers of new pages before shuffling */ | |
| 59040 | - Pgno aPgOrder[NB+2]; /* Copy of aPgno[] used for sorting pages */ | |
| 59041 | - u16 aPgFlags[NB+2]; /* flags field of new pages before shuffling */ | |
| 59042 | 58501 | |
| 59043 | - memset(abDone, 0, sizeof(abDone)); | |
| 59044 | 58502 | pBt = pParent->pBt; |
| 59045 | 58503 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 59046 | 58504 | assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 59047 | 58505 | |
| 59048 | 58506 | #if 0 |
| @@ -59147,18 +58605,16 @@ | ||
| 59147 | 58605 | nMaxCells = (nMaxCells + 3)&~3; |
| 59148 | 58606 | |
| 59149 | 58607 | /* |
| 59150 | 58608 | ** Allocate space for memory structures |
| 59151 | 58609 | */ |
| 58610 | + k = pBt->pageSize + ROUND8(sizeof(MemPage)); | |
| 59152 | 58611 | szScratch = |
| 59153 | 58612 | nMaxCells*sizeof(u8*) /* apCell */ |
| 59154 | 58613 | + nMaxCells*sizeof(u16) /* szCell */ |
| 59155 | - + pBt->pageSize; /* aSpace1 */ | |
| 59156 | - | |
| 59157 | - /* EVIDENCE-OF: R-28375-38319 SQLite will never request a scratch buffer | |
| 59158 | - ** that is more than 6 times the database page size. */ | |
| 59159 | - assert( szScratch<=6*pBt->pageSize ); | |
| 58614 | + + pBt->pageSize /* aSpace1 */ | |
| 58615 | + + k*nOld; /* Page copies (apCopy) */ | |
| 59160 | 58616 | apCell = sqlite3ScratchMalloc( szScratch ); |
| 59161 | 58617 | if( apCell==0 ){ |
| 59162 | 58618 | rc = SQLITE_NOMEM; |
| 59163 | 58619 | goto balance_cleanup; |
| 59164 | 58620 | } |
| @@ -59167,12 +58623,12 @@ | ||
| 59167 | 58623 | assert( EIGHT_BYTE_ALIGNMENT(aSpace1) ); |
| 59168 | 58624 | |
| 59169 | 58625 | /* |
| 59170 | 58626 | ** Load pointers to all cells on sibling pages and the divider cells |
| 59171 | 58627 | ** into the local apCell[] array. Make copies of the divider cells |
| 59172 | - ** into space obtained from aSpace1[]. The divider cells have already | |
| 59173 | - ** been removed from pParent. | |
| 58628 | + ** into space obtained from aSpace1[] and remove the divider cells | |
| 58629 | + ** from pParent. | |
| 59174 | 58630 | ** |
| 59175 | 58631 | ** If the siblings are on leaf pages, then the child pointers of the |
| 59176 | 58632 | ** divider cells are stripped from the cells before they are copied |
| 59177 | 58633 | ** into aSpace1[]. In this way, all cells in apCell[] are without |
| 59178 | 58634 | ** child pointers. If siblings are not leaves, then all cell in |
| @@ -59184,11 +58640,19 @@ | ||
| 59184 | 58640 | */ |
| 59185 | 58641 | leafCorrection = apOld[0]->leaf*4; |
| 59186 | 58642 | leafData = apOld[0]->intKeyLeaf; |
| 59187 | 58643 | for(i=0; i<nOld; i++){ |
| 59188 | 58644 | int limit; |
| 59189 | - 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); | |
| 59190 | 58654 | |
| 59191 | 58655 | limit = pOld->nCell+pOld->nOverflow; |
| 59192 | 58656 | if( pOld->nOverflow>0 ){ |
| 59193 | 58657 | for(j=0; j<limit; j++){ |
| 59194 | 58658 | assert( nCell<nMaxCells ); |
| @@ -59205,11 +58669,10 @@ | ||
| 59205 | 58669 | apCell[nCell] = findCellv2(aData, maskPage, cellOffset, j); |
| 59206 | 58670 | szCell[nCell] = cellSizePtr(pOld, apCell[nCell]); |
| 59207 | 58671 | nCell++; |
| 59208 | 58672 | } |
| 59209 | 58673 | } |
| 59210 | - cntOld[i] = nCell; | |
| 59211 | 58674 | if( i<nOld-1 && !leafData){ |
| 59212 | 58675 | u16 sz = (u16)szNew[i]; |
| 59213 | 58676 | u8 *pTemp; |
| 59214 | 58677 | assert( nCell<nMaxCells ); |
| 59215 | 58678 | szCell[nCell] = sz; |
| @@ -59257,11 +58720,11 @@ | ||
| 59257 | 58720 | usableSpace = pBt->usableSize - 12 + leafCorrection; |
| 59258 | 58721 | for(subtotal=k=i=0; i<nCell; i++){ |
| 59259 | 58722 | assert( i<nMaxCells ); |
| 59260 | 58723 | subtotal += szCell[i] + 2; |
| 59261 | 58724 | if( subtotal > usableSpace ){ |
| 59262 | - szNew[k] = subtotal - szCell[i] - 2; | |
| 58725 | + szNew[k] = subtotal - szCell[i]; | |
| 59263 | 58726 | cntNew[k] = i; |
| 59264 | 58727 | if( leafData ){ i--; } |
| 59265 | 58728 | subtotal = 0; |
| 59266 | 58729 | k++; |
| 59267 | 58730 | if( k>NB+1 ){ rc = SQLITE_CORRUPT_BKPT; goto balance_cleanup; } |
| @@ -59271,14 +58734,13 @@ | ||
| 59271 | 58734 | cntNew[k] = nCell; |
| 59272 | 58735 | k++; |
| 59273 | 58736 | |
| 59274 | 58737 | /* |
| 59275 | 58738 | ** The packing computed by the previous block is biased toward the siblings |
| 59276 | - ** on the left side (siblings with smaller keys). The left siblings are | |
| 59277 | - ** always nearly full, while the right-most sibling might be nearly empty. | |
| 59278 | - ** The next block of code attempts to adjust the packing of siblings to | |
| 59279 | - ** 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. | |
| 59280 | 58742 | ** |
| 59281 | 58743 | ** This adjustment is more than an optimization. The packing above might |
| 59282 | 58744 | ** be so out of balance as to be illegal. For example, the right-most |
| 59283 | 58745 | ** sibling might be completely empty. This adjustment is not optional. |
| 59284 | 58746 | */ |
| @@ -59303,22 +58765,26 @@ | ||
| 59303 | 58765 | } |
| 59304 | 58766 | szNew[i] = szRight; |
| 59305 | 58767 | szNew[i-1] = szLeft; |
| 59306 | 58768 | } |
| 59307 | 58769 | |
| 59308 | - /* Sanity check: For a non-corrupt database file one of the follwing | |
| 59309 | - ** must be true: | |
| 59310 | - ** (1) We found one or more cells (cntNew[0])>0), or | |
| 59311 | - ** (2) pPage is a virtual root page. A virtual root page is when | |
| 59312 | - ** the real root page is page 1 and we are the only child of | |
| 59313 | - ** 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. | |
| 59314 | 58777 | */ |
| 59315 | - assert( cntNew[0]>0 || (pParent->pgno==1 && pParent->nCell==0) || CORRUPT_DB); | |
| 59316 | - TRACE(("BALANCE: old: %d(nc=%d) %d(nc=%d) %d(nc=%d)\n", | |
| 59317 | - apOld[0]->pgno, apOld[0]->nCell, | |
| 59318 | - nOld>=2 ? apOld[1]->pgno : 0, nOld>=2 ? apOld[1]->nCell : 0, | |
| 59319 | - 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 | |
| 59320 | 58786 | )); |
| 59321 | 58787 | |
| 59322 | 58788 | /* |
| 59323 | 58789 | ** Allocate k new pages. Reuse old pages where possible. |
| 59324 | 58790 | */ |
| @@ -59337,14 +58803,12 @@ | ||
| 59337 | 58803 | if( rc ) goto balance_cleanup; |
| 59338 | 58804 | }else{ |
| 59339 | 58805 | assert( i>0 ); |
| 59340 | 58806 | rc = allocateBtreePage(pBt, &pNew, &pgno, (bBulk ? 1 : pgno), 0); |
| 59341 | 58807 | if( rc ) goto balance_cleanup; |
| 59342 | - zeroPage(pNew, pageFlags); | |
| 59343 | 58808 | apNew[i] = pNew; |
| 59344 | 58809 | nNew++; |
| 59345 | - cntOld[i] = nCell; | |
| 59346 | 58810 | |
| 59347 | 58811 | /* Set the pointer-map entry for the new sibling page. */ |
| 59348 | 58812 | if( ISAUTOVACUUM ){ |
| 59349 | 58813 | ptrmapPut(pBt, pNew->pgno, PTRMAP_BTREE, pParent->pgno, &rc); |
| 59350 | 58814 | if( rc!=SQLITE_OK ){ |
| @@ -59351,248 +58815,140 @@ | ||
| 59351 | 58815 | goto balance_cleanup; |
| 59352 | 58816 | } |
| 59353 | 58817 | } |
| 59354 | 58818 | } |
| 59355 | 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 | + } | |
| 59356 | 58830 | |
| 59357 | 58831 | /* |
| 59358 | - ** Reassign page numbers so that the new pages are in ascending order. | |
| 59359 | - ** This helps to keep entries in the disk file in order so that a scan | |
| 59360 | - ** of the table is closer to a linear scan through the file. That in turn | |
| 59361 | - ** helps the operating system to deliver pages from the disk more rapidly. | |
| 59362 | - ** | |
| 59363 | - ** An O(n^2) insertion sort algorithm is used, but since n is never more | |
| 59364 | - ** than (NB+2) (a small constant), that should not be a problem. | |
| 59365 | - ** | |
| 59366 | - ** When NB==3, this one optimization makes the database about 25% faster | |
| 59367 | - ** for large insertions and deletions. | |
| 59368 | - */ | |
| 59369 | - for(i=0; i<nNew; i++){ | |
| 59370 | - aPgOrder[i] = aPgno[i] = apNew[i]->pgno; | |
| 59371 | - aPgFlags[i] = apNew[i]->pDbPage->flags; | |
| 59372 | - for(j=0; j<i; j++){ | |
| 59373 | - if( aPgno[j]==aPgno[i] ){ | |
| 59374 | - /* This branch is taken if the set of sibling pages somehow contains | |
| 59375 | - ** duplicate entries. This can happen if the database is corrupt. | |
| 59376 | - ** It would be simpler to detect this as part of the loop below, but | |
| 59377 | - ** we do the detection here in order to avoid populating the pager | |
| 59378 | - ** cache with two separate objects associated with the same | |
| 59379 | - ** page number. */ | |
| 59380 | - assert( CORRUPT_DB ); | |
| 59381 | - rc = SQLITE_CORRUPT_BKPT; | |
| 59382 | - goto balance_cleanup; | |
| 59383 | - } | |
| 59384 | - } | |
| 59385 | - } | |
| 59386 | - for(i=0; i<nNew; i++){ | |
| 59387 | - int iBest = 0; /* aPgno[] index of page number to use */ | |
| 59388 | - for(j=1; j<nNew; j++){ | |
| 59389 | - if( aPgOrder[j]<aPgOrder[iBest] ) iBest = j; | |
| 59390 | - } | |
| 59391 | - pgno = aPgOrder[iBest]; | |
| 59392 | - aPgOrder[iBest] = 0xffffffff; | |
| 59393 | - if( iBest!=i ){ | |
| 59394 | - if( iBest>i ){ | |
| 59395 | - sqlite3PagerRekey(apNew[iBest]->pDbPage, pBt->nPage+iBest+1, 0); | |
| 59396 | - } | |
| 59397 | - sqlite3PagerRekey(apNew[i]->pDbPage, pgno, aPgFlags[iBest]); | |
| 59398 | - apNew[i]->pgno = pgno; | |
| 59399 | - } | |
| 59400 | - } | |
| 59401 | - | |
| 59402 | - TRACE(("BALANCE: new: %d(%d nc=%d) %d(%d nc=%d) %d(%d nc=%d) " | |
| 59403 | - "%d(%d nc=%d) %d(%d nc=%d)\n", | |
| 59404 | - 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], | |
| 59405 | 58863 | nNew>=2 ? apNew[1]->pgno : 0, nNew>=2 ? szNew[1] : 0, |
| 59406 | - nNew>=2 ? cntNew[1] - cntNew[0] - !leafData : 0, | |
| 59407 | 58864 | nNew>=3 ? apNew[2]->pgno : 0, nNew>=3 ? szNew[2] : 0, |
| 59408 | - nNew>=3 ? cntNew[2] - cntNew[1] - !leafData : 0, | |
| 59409 | 58865 | nNew>=4 ? apNew[3]->pgno : 0, nNew>=4 ? szNew[3] : 0, |
| 59410 | - nNew>=4 ? cntNew[3] - cntNew[2] - !leafData : 0, | |
| 59411 | - nNew>=5 ? apNew[4]->pgno : 0, nNew>=5 ? szNew[4] : 0, | |
| 59412 | - nNew>=5 ? cntNew[4] - cntNew[3] - !leafData : 0 | |
| 59413 | - )); | |
| 58866 | + nNew>=5 ? apNew[4]->pgno : 0, nNew>=5 ? szNew[4] : 0)); | |
| 59414 | 58867 | |
| 59415 | 58868 | assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 59416 | 58869 | put4byte(pRight, apNew[nNew-1]->pgno); |
| 59417 | 58870 | |
| 59418 | - /* If the sibling pages are not leaves, ensure that the right-child pointer | |
| 59419 | - ** of the right-most new sibling page is set to the value that was | |
| 59420 | - ** originally in the same field of the right-most old sibling page. */ | |
| 59421 | - if( (pageFlags & PTF_LEAF)==0 && nOld!=nNew ){ | |
| 59422 | - MemPage *pOld = (nNew>nOld ? apNew : apOld)[nOld-1]; | |
| 59423 | - memcpy(&apNew[nNew-1]->aData[8], &pOld->aData[8], 4); | |
| 59424 | - } | |
| 59425 | - | |
| 59426 | - /* Make any required updates to pointer map entries associated with | |
| 59427 | - ** cells stored on sibling pages following the balance operation. Pointer | |
| 59428 | - ** map entries associated with divider cells are set by the insertCell() | |
| 59429 | - ** routine. The associated pointer map entries are: | |
| 59430 | - ** | |
| 59431 | - ** a) if the cell contains a reference to an overflow chain, the | |
| 59432 | - ** entry associated with the first page in the overflow chain, and | |
| 59433 | - ** | |
| 59434 | - ** b) if the sibling pages are not leaves, the child page associated | |
| 59435 | - ** with the cell. | |
| 59436 | - ** | |
| 59437 | - ** If the sibling pages are not leaves, then the pointer map entry | |
| 59438 | - ** associated with the right-child of each sibling may also need to be | |
| 59439 | - ** updated. This happens below, after the sibling pages have been | |
| 59440 | - ** populated, not here. | |
| 58871 | + /* | |
| 58872 | + ** Evenly distribute the data in apCell[] across the new pages. | |
| 58873 | + ** Insert divider cells into pParent as necessary. | |
| 59441 | 58874 | */ |
| 59442 | - if( ISAUTOVACUUM ){ | |
| 59443 | - MemPage *pNew = apNew[0]; | |
| 59444 | - u8 *aOld = pNew->aData; | |
| 59445 | - int cntOldNext = pNew->nCell + pNew->nOverflow; | |
| 59446 | - int usableSize = pBt->usableSize; | |
| 59447 | - int iNew = 0; | |
| 59448 | - int iOld = 0; | |
| 59449 | - | |
| 59450 | - for(i=0; i<nCell; i++){ | |
| 59451 | - u8 *pCell = apCell[i]; | |
| 59452 | - if( i==cntOldNext ){ | |
| 59453 | - MemPage *pOld = (++iOld)<nNew ? apNew[iOld] : apOld[iOld]; | |
| 59454 | - cntOldNext += pOld->nCell + pOld->nOverflow + !leafData; | |
| 59455 | - aOld = pOld->aData; | |
| 59456 | - } | |
| 59457 | - if( i==cntNew[iNew] ){ | |
| 59458 | - pNew = apNew[++iNew]; | |
| 59459 | - if( !leafData ) continue; | |
| 59460 | - } | |
| 59461 | - | |
| 59462 | - /* Cell pCell is destined for new sibling page pNew. Originally, it | |
| 59463 | - ** was either part of sibling page iOld (possibly an overflow cell), | |
| 59464 | - ** or else the divider cell to the left of sibling page iOld. So, | |
| 59465 | - ** if sibling page iOld had the same page number as pNew, and if | |
| 59466 | - ** pCell really was a part of sibling page iOld (not a divider or | |
| 59467 | - ** overflow cell), we can skip updating the pointer map entries. */ | |
| 59468 | - if( pNew->pgno!=aPgno[iOld] || pCell<aOld || pCell>=&aOld[usableSize] ){ | |
| 59469 | - if( !leafCorrection ){ | |
| 59470 | - ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc); | |
| 59471 | - } | |
| 59472 | - if( szCell[i]>pNew->minLocal ){ | |
| 59473 | - ptrmapPutOvflPtr(pNew, pCell, &rc); | |
| 59474 | - } | |
| 59475 | - } | |
| 59476 | - } | |
| 59477 | - } | |
| 59478 | - | |
| 59479 | - /* Insert new divider cells into pParent. */ | |
| 59480 | - for(i=0; i<nNew-1; i++){ | |
| 59481 | - u8 *pCell; | |
| 59482 | - u8 *pTemp; | |
| 59483 | - int sz; | |
| 58875 | + j = 0; | |
| 58876 | + for(i=0; i<nNew; i++){ | |
| 58877 | + /* Assemble the new sibling page. */ | |
| 59484 | 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 | + | |
| 59485 | 58885 | j = cntNew[i]; |
| 59486 | 58886 | |
| 59487 | - assert( j<nMaxCells ); | |
| 59488 | - pCell = apCell[j]; | |
| 59489 | - sz = szCell[j] + leafCorrection; | |
| 59490 | - pTemp = &aOvflSpace[iOvflSpace]; | |
| 59491 | - if( !pNew->leaf ){ | |
| 59492 | - memcpy(&pNew->aData[8], pCell, 4); | |
| 59493 | - }else if( leafData ){ | |
| 59494 | - /* If the tree is a leaf-data tree, and the siblings are leaves, | |
| 59495 | - ** then there is no divider cell in apCell[]. Instead, the divider | |
| 59496 | - ** cell consists of the integer key for the right-most cell of | |
| 59497 | - ** the sibling-page assembled above only. | |
| 59498 | - */ | |
| 59499 | - CellInfo info; | |
| 59500 | - j--; | |
| 59501 | - btreeParseCellPtr(pNew, apCell[j], &info); | |
| 59502 | - pCell = pTemp; | |
| 59503 | - sz = 4 + putVarint(&pCell[4], info.nKey); | |
| 59504 | - pTemp = 0; | |
| 59505 | - }else{ | |
| 59506 | - pCell -= 4; | |
| 59507 | - /* Obscure case for non-leaf-data trees: If the cell at pCell was | |
| 59508 | - ** previously stored on a leaf node, and its reported size was 4 | |
| 59509 | - ** bytes, then it may actually be smaller than this | |
| 59510 | - ** (see btreeParseCellPtr(), 4 bytes is the minimum size of | |
| 59511 | - ** any cell). But it is important to pass the correct size to | |
| 59512 | - ** insertCell(), so reparse the cell now. | |
| 59513 | - ** | |
| 59514 | - ** Note that this can never happen in an SQLite data file, as all | |
| 59515 | - ** cells are at least 4 bytes. It only happens in b-trees used | |
| 59516 | - ** to evaluate "IN (SELECT ...)" and similar clauses. | |
| 59517 | - */ | |
| 59518 | - if( szCell[j]==4 ){ | |
| 59519 | - assert(leafCorrection==4); | |
| 59520 | - sz = cellSizePtr(pParent, pCell); | |
| 59521 | - } | |
| 59522 | - } | |
| 59523 | - iOvflSpace += sz; | |
| 59524 | - assert( sz<=pBt->maxLocal+23 ); | |
| 59525 | - assert( iOvflSpace <= (int)pBt->pageSize ); | |
| 59526 | - insertCell(pParent, nxDiv+i, pCell, sz, pTemp, pNew->pgno, &rc); | |
| 59527 | - if( rc!=SQLITE_OK ) goto balance_cleanup; | |
| 59528 | - assert( sqlite3PagerIswriteable(pParent->pDbPage) ); | |
| 59529 | - } | |
| 59530 | - | |
| 59531 | - /* Now update the actual sibling pages. The order in which they are updated | |
| 59532 | - ** is important, as this code needs to avoid disrupting any page from which | |
| 59533 | - ** cells may still to be read. In practice, this means: | |
| 59534 | - ** | |
| 59535 | - ** (1) If cells are moving left (from apNew[iPg] to apNew[iPg-1]) | |
| 59536 | - ** then it is not safe to update page apNew[iPg] until after | |
| 59537 | - ** the left-hand sibling apNew[iPg-1] has been updated. | |
| 59538 | - ** | |
| 59539 | - ** (2) If cells are moving right (from apNew[iPg] to apNew[iPg+1]) | |
| 59540 | - ** then it is not safe to update page apNew[iPg] until after | |
| 59541 | - ** the right-hand sibling apNew[iPg+1] has been updated. | |
| 59542 | - ** | |
| 59543 | - ** If neither of the above apply, the page is safe to update. | |
| 59544 | - ** | |
| 59545 | - ** The iPg value in the following loop starts at nNew-1 goes down | |
| 59546 | - ** to 0, then back up to nNew-1 again, thus making two passes over | |
| 59547 | - ** the pages. On the initial downward pass, only condition (1) above | |
| 59548 | - ** needs to be tested because (2) will always be true from the previous | |
| 59549 | - ** step. On the upward pass, both conditions are always true, so the | |
| 59550 | - ** upwards pass simply processes pages that were missed on the downward | |
| 59551 | - ** pass. | |
| 59552 | - */ | |
| 59553 | - for(i=1-nNew; i<nNew; i++){ | |
| 59554 | - int iPg = i<0 ? -i : i; | |
| 59555 | - assert( iPg>=0 && iPg<nNew ); | |
| 59556 | - if( abDone[iPg] ) continue; /* Skip pages already processed */ | |
| 59557 | - if( i>=0 /* On the upwards pass, or... */ | |
| 59558 | - || cntOld[iPg-1]>=cntNew[iPg-1] /* Condition (1) is true */ | |
| 59559 | - ){ | |
| 59560 | - int iNew; | |
| 59561 | - int iOld; | |
| 59562 | - int nNewCell; | |
| 59563 | - | |
| 59564 | - /* Verify condition (1): If cells are moving left, update iPg | |
| 59565 | - ** only after iPg-1 has already been updated. */ | |
| 59566 | - assert( iPg==0 || cntOld[iPg-1]>=cntNew[iPg-1] || abDone[iPg-1] ); | |
| 59567 | - | |
| 59568 | - /* Verify condition (2): If cells are moving right, update iPg | |
| 59569 | - ** only after iPg+1 has already been updated. */ | |
| 59570 | - assert( cntNew[iPg]>=cntOld[iPg] || abDone[iPg+1] ); | |
| 59571 | - | |
| 59572 | - if( iPg==0 ){ | |
| 59573 | - iNew = iOld = 0; | |
| 59574 | - nNewCell = cntNew[0]; | |
| 59575 | - }else{ | |
| 59576 | - iOld = iPg<nOld ? (cntOld[iPg-1] + !leafData) : nCell; | |
| 59577 | - iNew = cntNew[iPg-1] + !leafData; | |
| 59578 | - nNewCell = cntNew[iPg] - iNew; | |
| 59579 | - } | |
| 59580 | - | |
| 59581 | - editPage(apNew[iPg], iOld, iNew, nNewCell, apCell, szCell); | |
| 59582 | - abDone[iPg]++; | |
| 59583 | - apNew[iPg]->nFree = usableSpace-szNew[iPg]; | |
| 59584 | - assert( apNew[iPg]->nOverflow==0 ); | |
| 59585 | - assert( apNew[iPg]->nCell==nNewCell ); | |
| 59586 | - } | |
| 59587 | - } | |
| 59588 | - | |
| 59589 | - /* All pages have been processed exactly once */ | |
| 59590 | - assert( memcmp(abDone, "\01\01\01\01\01", nNew)==0 ); | |
| 59591 | - | |
| 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 ); | |
| 59592 | 58944 | assert( nOld>0 ); |
| 59593 | 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 | + } | |
| 59594 | 58950 | |
| 59595 | 58951 | if( isRoot && pParent->nCell==0 && pParent->hdrOffset<=apNew[0]->nFree ){ |
| 59596 | 58952 | /* The root page of the b-tree now contains no cells. The only sibling |
| 59597 | 58953 | ** page is the right-child of the parent. Copy the contents of the |
| 59598 | 58954 | ** child page into the parent, decreasing the overall height of the |
| @@ -59601,54 +58957,130 @@ | ||
| 59601 | 58957 | ** |
| 59602 | 58958 | ** If this is an auto-vacuum database, the call to copyNodeContent() |
| 59603 | 58959 | ** sets all pointer-map entries corresponding to database image pages |
| 59604 | 58960 | ** for which the pointer is stored within the content being copied. |
| 59605 | 58961 | ** |
| 59606 | - ** It is critical that the child page be defragmented before being | |
| 59607 | - ** copied into the parent, because if the parent is page 1 then it will | |
| 59608 | - ** by smaller than the child due to the database header, and so all the | |
| 59609 | - ** free space needs to be up front. | |
| 59610 | - */ | |
| 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. */ | |
| 59611 | 58966 | assert( nNew==1 ); |
| 59612 | - rc = defragmentPage(apNew[0]); | |
| 59613 | - testcase( rc!=SQLITE_OK ); | |
| 59614 | 58967 | assert( apNew[0]->nFree == |
| 59615 | - (get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2) | |
| 59616 | - || rc!=SQLITE_OK | |
| 58968 | + (get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2) | |
| 59617 | 58969 | ); |
| 59618 | 58970 | copyNodeContent(apNew[0], pParent, &rc); |
| 59619 | 58971 | freePage(apNew[0], &rc); |
| 59620 | - }else if( ISAUTOVACUUM && !leafCorrection ){ | |
| 59621 | - /* Fix the pointer map entries associated with the right-child of each | |
| 59622 | - ** sibling page. All other pointer map entries have already been taken | |
| 59623 | - ** care of. */ | |
| 59624 | - for(i=0; i<nNew; i++){ | |
| 59625 | - u32 key = get4byte(&apNew[i]->aData[8]); | |
| 59626 | - ptrmapPut(pBt, key, PTRMAP_BTREE, apNew[i]->pgno, &rc); | |
| 59627 | - } | |
| 59628 | - } | |
| 59629 | - | |
| 59630 | - assert( pParent->isInit ); | |
| 59631 | - TRACE(("BALANCE: finished: old=%d new=%d cells=%d\n", | |
| 59632 | - nOld, nNew, nCell)); | |
| 59633 | - | |
| 59634 | - /* Free any old pages that were not reused as new pages. | |
| 59635 | - */ | |
| 59636 | - for(i=nNew; i<nOld; i++){ | |
| 59637 | - freePage(apOld[i], &rc); | |
| 59638 | - } | |
| 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 | + } | |
| 59639 | 59068 | |
| 59640 | 59069 | #if 0 |
| 59641 | - if( ISAUTOVACUUM && rc==SQLITE_OK && apNew[0]->isInit ){ | |
| 59642 | 59070 | /* The ptrmapCheckPages() contains assert() statements that verify that |
| 59643 | 59071 | ** all pointer map pages are set correctly. This is helpful while |
| 59644 | 59072 | ** debugging. This is usually disabled because a corrupt database may |
| 59645 | 59073 | ** cause an assert() statement to fail. */ |
| 59646 | 59074 | ptrmapCheckPages(apNew, nNew); |
| 59647 | 59075 | ptrmapCheckPages(&pParent, 1); |
| 59076 | +#endif | |
| 59648 | 59077 | } |
| 59649 | -#endif | |
| 59078 | + | |
| 59079 | + assert( pParent->isInit ); | |
| 59080 | + TRACE(("BALANCE: finished: old=%d new=%d cells=%d\n", | |
| 59081 | + nOld, nNew, nCell)); | |
| 59650 | 59082 | |
| 59651 | 59083 | /* |
| 59652 | 59084 | ** Cleanup before returning. |
| 59653 | 59085 | */ |
| 59654 | 59086 | balance_cleanup: |
| @@ -61470,15 +60902,10 @@ | ||
| 61470 | 60902 | */ |
| 61471 | 60903 | SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *p){ |
| 61472 | 60904 | return (p->pBt->btsFlags & BTS_READ_ONLY)!=0; |
| 61473 | 60905 | } |
| 61474 | 60906 | |
| 61475 | -/* | |
| 61476 | -** Return the size of the header added to each page by this module. | |
| 61477 | -*/ | |
| 61478 | -SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void){ return sizeof(MemPage); } | |
| 61479 | - | |
| 61480 | 60907 | /************** End of btree.c ***********************************************/ |
| 61481 | 60908 | /************** Begin file backup.c ******************************************/ |
| 61482 | 60909 | /* |
| 61483 | 60910 | ** 2009 January 28 |
| 61484 | 60911 | ** |
| @@ -61599,24 +61026,10 @@ | ||
| 61599 | 61026 | int rc; |
| 61600 | 61027 | rc = sqlite3BtreeSetPageSize(p->pDest,sqlite3BtreeGetPageSize(p->pSrc),-1,0); |
| 61601 | 61028 | return rc; |
| 61602 | 61029 | } |
| 61603 | 61030 | |
| 61604 | -/* | |
| 61605 | -** Check that there is no open read-transaction on the b-tree passed as the | |
| 61606 | -** second argument. If there is not, return SQLITE_OK. Otherwise, if there | |
| 61607 | -** is an open read-transaction, return SQLITE_ERROR and leave an error | |
| 61608 | -** message in database handle db. | |
| 61609 | -*/ | |
| 61610 | -static int checkReadTransaction(sqlite3 *db, Btree *p){ | |
| 61611 | - if( sqlite3BtreeIsInReadTrans(p) ){ | |
| 61612 | - sqlite3ErrorWithMsg(db, SQLITE_ERROR, "destination database is in use"); | |
| 61613 | - return SQLITE_ERROR; | |
| 61614 | - } | |
| 61615 | - return SQLITE_OK; | |
| 61616 | -} | |
| 61617 | - | |
| 61618 | 61031 | /* |
| 61619 | 61032 | ** Create an sqlite3_backup process to copy the contents of zSrcDb from |
| 61620 | 61033 | ** connection handle pSrcDb to zDestDb in pDestDb. If successful, return |
| 61621 | 61034 | ** a pointer to the new sqlite3_backup object. |
| 61622 | 61035 | ** |
| @@ -61629,17 +61042,10 @@ | ||
| 61629 | 61042 | sqlite3* pSrcDb, /* Database connection to read from */ |
| 61630 | 61043 | const char *zSrcDb /* Name of database within pSrcDb */ |
| 61631 | 61044 | ){ |
| 61632 | 61045 | sqlite3_backup *p; /* Value to return */ |
| 61633 | 61046 | |
| 61634 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 61635 | - if( !sqlite3SafetyCheckOk(pSrcDb)||!sqlite3SafetyCheckOk(pDestDb) ){ | |
| 61636 | - (void)SQLITE_MISUSE_BKPT; | |
| 61637 | - return 0; | |
| 61638 | - } | |
| 61639 | -#endif | |
| 61640 | - | |
| 61641 | 61047 | /* Lock the source database handle. The destination database |
| 61642 | 61048 | ** handle is not locked in this routine, but it is locked in |
| 61643 | 61049 | ** sqlite3_backup_step(). The user is required to ensure that no |
| 61644 | 61050 | ** other thread accesses the destination handle for the duration |
| 61645 | 61051 | ** of the backup operation. Any attempt to use the destination |
| @@ -61672,19 +61078,16 @@ | ||
| 61672 | 61078 | p->pDestDb = pDestDb; |
| 61673 | 61079 | p->pSrcDb = pSrcDb; |
| 61674 | 61080 | p->iNext = 1; |
| 61675 | 61081 | p->isAttached = 0; |
| 61676 | 61082 | |
| 61677 | - if( 0==p->pSrc || 0==p->pDest | |
| 61678 | - || setDestPgsz(p)==SQLITE_NOMEM | |
| 61679 | - || checkReadTransaction(pDestDb, p->pDest)!=SQLITE_OK | |
| 61680 | - ){ | |
| 61083 | + if( 0==p->pSrc || 0==p->pDest || setDestPgsz(p)==SQLITE_NOMEM ){ | |
| 61681 | 61084 | /* One (or both) of the named databases did not exist or an OOM |
| 61682 | - ** error was hit. Or there is a transaction open on the destination | |
| 61683 | - ** database. The error has already been written into the pDestDb | |
| 61684 | - ** handle. All that is left to do here is free the sqlite3_backup | |
| 61685 | - ** structure. */ | |
| 61085 | + ** error was hit. The error has already been written into the | |
| 61086 | + ** pDestDb handle. All that is left to do here is free the | |
| 61087 | + ** sqlite3_backup structure. | |
| 61088 | + */ | |
| 61686 | 61089 | sqlite3_free(p); |
| 61687 | 61090 | p = 0; |
| 61688 | 61091 | } |
| 61689 | 61092 | } |
| 61690 | 61093 | if( p ){ |
| @@ -61835,13 +61238,10 @@ | ||
| 61835 | 61238 | int rc; |
| 61836 | 61239 | int destMode; /* Destination journal mode */ |
| 61837 | 61240 | int pgszSrc = 0; /* Source page size */ |
| 61838 | 61241 | int pgszDest = 0; /* Destination page size */ |
| 61839 | 61242 | |
| 61840 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 61841 | - if( p==0 ) return SQLITE_MISUSE_BKPT; | |
| 61842 | -#endif | |
| 61843 | 61243 | sqlite3_mutex_enter(p->pSrcDb->mutex); |
| 61844 | 61244 | sqlite3BtreeEnter(p->pSrc); |
| 61845 | 61245 | if( p->pDestDb ){ |
| 61846 | 61246 | sqlite3_mutex_enter(p->pDestDb->mutex); |
| 61847 | 61247 | } |
| @@ -62127,30 +61527,18 @@ | ||
| 62127 | 61527 | /* |
| 62128 | 61528 | ** Return the number of pages still to be backed up as of the most recent |
| 62129 | 61529 | ** call to sqlite3_backup_step(). |
| 62130 | 61530 | */ |
| 62131 | 61531 | SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p){ |
| 62132 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 62133 | - if( p==0 ){ | |
| 62134 | - (void)SQLITE_MISUSE_BKPT; | |
| 62135 | - return 0; | |
| 62136 | - } | |
| 62137 | -#endif | |
| 62138 | 61532 | return p->nRemaining; |
| 62139 | 61533 | } |
| 62140 | 61534 | |
| 62141 | 61535 | /* |
| 62142 | 61536 | ** Return the total number of pages in the source database as of the most |
| 62143 | 61537 | ** recent call to sqlite3_backup_step(). |
| 62144 | 61538 | */ |
| 62145 | 61539 | SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p){ |
| 62146 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 62147 | - if( p==0 ){ | |
| 62148 | - (void)SQLITE_MISUSE_BKPT; | |
| 62149 | - return 0; | |
| 62150 | - } | |
| 62151 | -#endif | |
| 62152 | 61540 | return p->nPagecount; |
| 62153 | 61541 | } |
| 62154 | 61542 | |
| 62155 | 61543 | /* |
| 62156 | 61544 | ** This function is called after the contents of page iPage of the |
| @@ -64437,38 +63825,10 @@ | ||
| 64437 | 63825 | } |
| 64438 | 63826 | p->nOp += nOp; |
| 64439 | 63827 | } |
| 64440 | 63828 | return addr; |
| 64441 | 63829 | } |
| 64442 | - | |
| 64443 | -#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) | |
| 64444 | -/* | |
| 64445 | -** Add an entry to the array of counters managed by sqlite3_stmt_scanstatus(). | |
| 64446 | -*/ | |
| 64447 | -SQLITE_PRIVATE void sqlite3VdbeScanStatus( | |
| 64448 | - Vdbe *p, /* VM to add scanstatus() to */ | |
| 64449 | - int addrExplain, /* Address of OP_Explain (or 0) */ | |
| 64450 | - int addrLoop, /* Address of loop counter */ | |
| 64451 | - int addrVisit, /* Address of rows visited counter */ | |
| 64452 | - LogEst nEst, /* Estimated number of output rows */ | |
| 64453 | - const char *zName /* Name of table or index being scanned */ | |
| 64454 | -){ | |
| 64455 | - int nByte = (p->nScan+1) * sizeof(ScanStatus); | |
| 64456 | - ScanStatus *aNew; | |
| 64457 | - aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte); | |
| 64458 | - if( aNew ){ | |
| 64459 | - ScanStatus *pNew = &aNew[p->nScan++]; | |
| 64460 | - pNew->addrExplain = addrExplain; | |
| 64461 | - pNew->addrLoop = addrLoop; | |
| 64462 | - pNew->addrVisit = addrVisit; | |
| 64463 | - pNew->nEst = nEst; | |
| 64464 | - pNew->zName = sqlite3DbStrDup(p->db, zName); | |
| 64465 | - p->aScan = aNew; | |
| 64466 | - } | |
| 64467 | -} | |
| 64468 | -#endif | |
| 64469 | - | |
| 64470 | 63830 | |
| 64471 | 63831 | /* |
| 64472 | 63832 | ** Change the value of the P1 operand for a specific instruction. |
| 64473 | 63833 | ** This routine is useful when a large program is loaded from a |
| 64474 | 63834 | ** static array using sqlite3VdbeAddOpList but we want to make a |
| @@ -65564,13 +64924,10 @@ | ||
| 65564 | 64924 | p->apArg = allocSpace(p->apArg, nArg*sizeof(Mem*), &zCsr, zEnd, &nByte); |
| 65565 | 64925 | p->azVar = allocSpace(p->azVar, nVar*sizeof(char*), &zCsr, zEnd, &nByte); |
| 65566 | 64926 | p->apCsr = allocSpace(p->apCsr, nCursor*sizeof(VdbeCursor*), |
| 65567 | 64927 | &zCsr, zEnd, &nByte); |
| 65568 | 64928 | p->aOnceFlag = allocSpace(p->aOnceFlag, nOnce, &zCsr, zEnd, &nByte); |
| 65569 | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS | |
| 65570 | - p->anExec = allocSpace(p->anExec, p->nOp*sizeof(i64), &zCsr, zEnd, &nByte); | |
| 65571 | -#endif | |
| 65572 | 64929 | if( nByte ){ |
| 65573 | 64930 | p->pFree = sqlite3DbMallocZero(db, nByte); |
| 65574 | 64931 | } |
| 65575 | 64932 | zCsr = p->pFree; |
| 65576 | 64933 | zEnd = &zCsr[nByte]; |
| @@ -65634,13 +64991,10 @@ | ||
| 65634 | 64991 | ** is used, for example, when a trigger sub-program is halted to restore |
| 65635 | 64992 | ** control to the main program. |
| 65636 | 64993 | */ |
| 65637 | 64994 | SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){ |
| 65638 | 64995 | Vdbe *v = pFrame->v; |
| 65639 | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS | |
| 65640 | - v->anExec = pFrame->anExec; | |
| 65641 | -#endif | |
| 65642 | 64996 | v->aOnceFlag = pFrame->aOnceFlag; |
| 65643 | 64997 | v->nOnceFlag = pFrame->nOnceFlag; |
| 65644 | 64998 | v->aOp = pFrame->aOp; |
| 65645 | 64999 | v->nOp = pFrame->nOp; |
| 65646 | 65000 | v->aMem = pFrame->aMem; |
| @@ -65647,11 +65001,10 @@ | ||
| 65647 | 65001 | v->nMem = pFrame->nMem; |
| 65648 | 65002 | v->apCsr = pFrame->apCsr; |
| 65649 | 65003 | v->nCursor = pFrame->nCursor; |
| 65650 | 65004 | v->db->lastRowid = pFrame->lastRowid; |
| 65651 | 65005 | v->nChange = pFrame->nChange; |
| 65652 | - v->db->nChange = pFrame->nDbChange; | |
| 65653 | 65006 | return pFrame->pc; |
| 65654 | 65007 | } |
| 65655 | 65008 | |
| 65656 | 65009 | /* |
| 65657 | 65010 | ** Close all cursors. |
| @@ -66215,11 +65568,10 @@ | ||
| 66215 | 65568 | ** so, abort any other statements this handle currently has active. |
| 66216 | 65569 | */ |
| 66217 | 65570 | sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); |
| 66218 | 65571 | sqlite3CloseSavepoints(db); |
| 66219 | 65572 | db->autoCommit = 1; |
| 66220 | - p->nChange = 0; | |
| 66221 | 65573 | } |
| 66222 | 65574 | } |
| 66223 | 65575 | } |
| 66224 | 65576 | |
| 66225 | 65577 | /* Check for immediate foreign key violations. */ |
| @@ -66256,20 +65608,18 @@ | ||
| 66256 | 65608 | sqlite3VdbeLeave(p); |
| 66257 | 65609 | return SQLITE_BUSY; |
| 66258 | 65610 | }else if( rc!=SQLITE_OK ){ |
| 66259 | 65611 | p->rc = rc; |
| 66260 | 65612 | sqlite3RollbackAll(db, SQLITE_OK); |
| 66261 | - p->nChange = 0; | |
| 66262 | 65613 | }else{ |
| 66263 | 65614 | db->nDeferredCons = 0; |
| 66264 | 65615 | db->nDeferredImmCons = 0; |
| 66265 | 65616 | db->flags &= ~SQLITE_DeferFKs; |
| 66266 | 65617 | sqlite3CommitInternalChanges(db); |
| 66267 | 65618 | } |
| 66268 | 65619 | }else{ |
| 66269 | 65620 | sqlite3RollbackAll(db, SQLITE_OK); |
| 66270 | - p->nChange = 0; | |
| 66271 | 65621 | } |
| 66272 | 65622 | db->nStatement = 0; |
| 66273 | 65623 | }else if( eStatementOp==0 ){ |
| 66274 | 65624 | if( p->rc==SQLITE_OK || p->errorAction==OE_Fail ){ |
| 66275 | 65625 | eStatementOp = SAVEPOINT_RELEASE; |
| @@ -66277,11 +65627,10 @@ | ||
| 66277 | 65627 | eStatementOp = SAVEPOINT_ROLLBACK; |
| 66278 | 65628 | }else{ |
| 66279 | 65629 | sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); |
| 66280 | 65630 | sqlite3CloseSavepoints(db); |
| 66281 | 65631 | db->autoCommit = 1; |
| 66282 | - p->nChange = 0; | |
| 66283 | 65632 | } |
| 66284 | 65633 | } |
| 66285 | 65634 | |
| 66286 | 65635 | /* If eStatementOp is non-zero, then a statement transaction needs to |
| 66287 | 65636 | ** be committed or rolled back. Call sqlite3VdbeCloseStatement() to |
| @@ -66298,11 +65647,10 @@ | ||
| 66298 | 65647 | p->zErrMsg = 0; |
| 66299 | 65648 | } |
| 66300 | 65649 | sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); |
| 66301 | 65650 | sqlite3CloseSavepoints(db); |
| 66302 | 65651 | db->autoCommit = 1; |
| 66303 | - p->nChange = 0; | |
| 66304 | 65652 | } |
| 66305 | 65653 | } |
| 66306 | 65654 | |
| 66307 | 65655 | /* If this was an INSERT, UPDATE or DELETE and no statement transaction |
| 66308 | 65656 | ** has been rolled back, update the database connection change-counter. |
| @@ -66560,16 +65908,10 @@ | ||
| 66560 | 65908 | for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]); |
| 66561 | 65909 | vdbeFreeOpArray(db, p->aOp, p->nOp); |
| 66562 | 65910 | sqlite3DbFree(db, p->aColName); |
| 66563 | 65911 | sqlite3DbFree(db, p->zSql); |
| 66564 | 65912 | sqlite3DbFree(db, p->pFree); |
| 66565 | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS | |
| 66566 | - for(i=0; i<p->nScan; i++){ | |
| 66567 | - sqlite3DbFree(db, p->aScan[i].zName); | |
| 66568 | - } | |
| 66569 | - sqlite3DbFree(db, p->aScan); | |
| 66570 | -#endif | |
| 66571 | 65913 | } |
| 66572 | 65914 | |
| 66573 | 65915 | /* |
| 66574 | 65916 | ** Delete an entire VDBE. |
| 66575 | 65917 | */ |
| @@ -68933,23 +68275,15 @@ | ||
| 68933 | 68275 | sqlite3_stmt *pStmt, |
| 68934 | 68276 | int N, |
| 68935 | 68277 | const void *(*xFunc)(Mem*), |
| 68936 | 68278 | int useType |
| 68937 | 68279 | ){ |
| 68938 | - const void *ret; | |
| 68939 | - Vdbe *p; | |
| 68280 | + const void *ret = 0; | |
| 68281 | + Vdbe *p = (Vdbe *)pStmt; | |
| 68940 | 68282 | int n; |
| 68941 | - sqlite3 *db; | |
| 68942 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 68943 | - if( pStmt==0 ){ | |
| 68944 | - (void)SQLITE_MISUSE_BKPT; | |
| 68945 | - return 0; | |
| 68946 | - } | |
| 68947 | -#endif | |
| 68948 | - ret = 0; | |
| 68949 | - p = (Vdbe *)pStmt; | |
| 68950 | - db = p->db; | |
| 68283 | + sqlite3 *db = p->db; | |
| 68284 | + | |
| 68951 | 68285 | assert( db!=0 ); |
| 68952 | 68286 | n = sqlite3_column_count(pStmt); |
| 68953 | 68287 | if( N<n && N>=0 ){ |
| 68954 | 68288 | N += useType*n; |
| 68955 | 68289 | sqlite3_mutex_enter(db->mutex); |
| @@ -69410,16 +68744,10 @@ | ||
| 69410 | 68744 | ** prepared statement for the database connection. Return NULL if there |
| 69411 | 68745 | ** are no more. |
| 69412 | 68746 | */ |
| 69413 | 68747 | SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt){ |
| 69414 | 68748 | sqlite3_stmt *pNext; |
| 69415 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 69416 | - if( !sqlite3SafetyCheckOk(pDb) ){ | |
| 69417 | - (void)SQLITE_MISUSE_BKPT; | |
| 69418 | - return 0; | |
| 69419 | - } | |
| 69420 | -#endif | |
| 69421 | 68749 | sqlite3_mutex_enter(pDb->mutex); |
| 69422 | 68750 | if( pStmt==0 ){ |
| 69423 | 68751 | pNext = (sqlite3_stmt*)pDb->pVdbe; |
| 69424 | 68752 | }else{ |
| 69425 | 68753 | pNext = (sqlite3_stmt*)((Vdbe*)pStmt)->pNext; |
| @@ -69431,91 +68759,15 @@ | ||
| 69431 | 68759 | /* |
| 69432 | 68760 | ** Return the value of a status counter for a prepared statement |
| 69433 | 68761 | */ |
| 69434 | 68762 | SQLITE_API int sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){ |
| 69435 | 68763 | Vdbe *pVdbe = (Vdbe*)pStmt; |
| 69436 | - u32 v; | |
| 69437 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 69438 | - if( !pStmt ){ | |
| 69439 | - (void)SQLITE_MISUSE_BKPT; | |
| 69440 | - return 0; | |
| 69441 | - } | |
| 69442 | -#endif | |
| 69443 | - v = pVdbe->aCounter[op]; | |
| 68764 | + u32 v = pVdbe->aCounter[op]; | |
| 69444 | 68765 | if( resetFlag ) pVdbe->aCounter[op] = 0; |
| 69445 | 68766 | return (int)v; |
| 69446 | 68767 | } |
| 69447 | 68768 | |
| 69448 | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS | |
| 69449 | -/* | |
| 69450 | -** Return status data for a single loop within query pStmt. | |
| 69451 | -*/ | |
| 69452 | -SQLITE_API int sqlite3_stmt_scanstatus( | |
| 69453 | - sqlite3_stmt *pStmt, /* Prepared statement being queried */ | |
| 69454 | - int idx, /* Index of loop to report on */ | |
| 69455 | - int iScanStatusOp, /* Which metric to return */ | |
| 69456 | - void *pOut /* OUT: Write the answer here */ | |
| 69457 | -){ | |
| 69458 | - Vdbe *p = (Vdbe*)pStmt; | |
| 69459 | - ScanStatus *pScan; | |
| 69460 | - if( idx<0 || idx>=p->nScan ) return 1; | |
| 69461 | - pScan = &p->aScan[idx]; | |
| 69462 | - switch( iScanStatusOp ){ | |
| 69463 | - case SQLITE_SCANSTAT_NLOOP: { | |
| 69464 | - *(sqlite3_int64*)pOut = p->anExec[pScan->addrLoop]; | |
| 69465 | - break; | |
| 69466 | - } | |
| 69467 | - case SQLITE_SCANSTAT_NVISIT: { | |
| 69468 | - *(sqlite3_int64*)pOut = p->anExec[pScan->addrVisit]; | |
| 69469 | - break; | |
| 69470 | - } | |
| 69471 | - case SQLITE_SCANSTAT_EST: { | |
| 69472 | - double r = 1.0; | |
| 69473 | - LogEst x = pScan->nEst; | |
| 69474 | - while( x<100 ){ | |
| 69475 | - x += 10; | |
| 69476 | - r *= 0.5; | |
| 69477 | - } | |
| 69478 | - *(double*)pOut = r*sqlite3LogEstToInt(x); | |
| 69479 | - break; | |
| 69480 | - } | |
| 69481 | - case SQLITE_SCANSTAT_NAME: { | |
| 69482 | - *(const char**)pOut = pScan->zName; | |
| 69483 | - break; | |
| 69484 | - } | |
| 69485 | - case SQLITE_SCANSTAT_EXPLAIN: { | |
| 69486 | - if( pScan->addrExplain ){ | |
| 69487 | - *(const char**)pOut = p->aOp[ pScan->addrExplain ].p4.z; | |
| 69488 | - }else{ | |
| 69489 | - *(const char**)pOut = 0; | |
| 69490 | - } | |
| 69491 | - break; | |
| 69492 | - } | |
| 69493 | - case SQLITE_SCANSTAT_SELECTID: { | |
| 69494 | - if( pScan->addrExplain ){ | |
| 69495 | - *(int*)pOut = p->aOp[ pScan->addrExplain ].p1; | |
| 69496 | - }else{ | |
| 69497 | - *(int*)pOut = -1; | |
| 69498 | - } | |
| 69499 | - break; | |
| 69500 | - } | |
| 69501 | - default: { | |
| 69502 | - return 1; | |
| 69503 | - } | |
| 69504 | - } | |
| 69505 | - return 0; | |
| 69506 | -} | |
| 69507 | - | |
| 69508 | -/* | |
| 69509 | -** Zero all counters associated with the sqlite3_stmt_scanstatus() data. | |
| 69510 | -*/ | |
| 69511 | -SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt *pStmt){ | |
| 69512 | - Vdbe *p = (Vdbe*)pStmt; | |
| 69513 | - memset(p->anExec, 0, p->nOp * sizeof(i64)); | |
| 69514 | -} | |
| 69515 | -#endif /* SQLITE_ENABLE_STMT_SCANSTATUS */ | |
| 69516 | - | |
| 69517 | 68769 | /************** End of vdbeapi.c *********************************************/ |
| 69518 | 68770 | /************** Begin file vdbetrace.c ***************************************/ |
| 69519 | 68771 | /* |
| 69520 | 68772 | ** 2009 November 25 |
| 69521 | 68773 | ** |
| @@ -70397,13 +69649,10 @@ | ||
| 70397 | 69649 | #ifdef VDBE_PROFILE |
| 70398 | 69650 | start = sqlite3Hwtime(); |
| 70399 | 69651 | #endif |
| 70400 | 69652 | nVmStep++; |
| 70401 | 69653 | pOp = &aOp[pc]; |
| 70402 | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS | |
| 70403 | - if( p->anExec ) p->anExec[pc]++; | |
| 70404 | -#endif | |
| 70405 | 69654 | |
| 70406 | 69655 | /* Only allow tracing if SQLITE_DEBUG is defined. |
| 70407 | 69656 | */ |
| 70408 | 69657 | #ifdef SQLITE_DEBUG |
| 70409 | 69658 | if( db->flags & SQLITE_VdbeTrace ){ |
| @@ -73594,15 +72843,14 @@ | ||
| 73594 | 72843 | } |
| 73595 | 72844 | pIdxKey = &r; |
| 73596 | 72845 | }else{ |
| 73597 | 72846 | pIdxKey = sqlite3VdbeAllocUnpackedRecord( |
| 73598 | 72847 | pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree |
| 73599 | - ); | |
| 72848 | + ); | |
| 73600 | 72849 | if( pIdxKey==0 ) goto no_mem; |
| 73601 | 72850 | assert( pIn3->flags & MEM_Blob ); |
| 73602 | - /* assert( (pIn3->flags & MEM_Zero)==0 ); // zeroblobs already expanded */ | |
| 73603 | - ExpandBlob(pIn3); | |
| 72851 | + assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */ | |
| 73604 | 72852 | sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey); |
| 73605 | 72853 | } |
| 73606 | 72854 | pIdxKey->default_rc = 0; |
| 73607 | 72855 | if( pOp->opcode==OP_NoConflict ){ |
| 73608 | 72856 | /* For the OP_NoConflict opcode, take the jump if any of the |
| @@ -74292,13 +73540,13 @@ | ||
| 74292 | 73540 | } |
| 74293 | 73541 | /* Opcode: Rewind P1 P2 * * * |
| 74294 | 73542 | ** |
| 74295 | 73543 | ** The next use of the Rowid or Column or Next instruction for P1 |
| 74296 | 73544 | ** will refer to the first entry in the database table or index. |
| 74297 | -** If the table or index is empty, jump immediately to P2. | |
| 74298 | -** If the table or index is not empty, fall through to the following | |
| 74299 | -** 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. | |
| 74300 | 73548 | ** |
| 74301 | 73549 | ** This opcode leaves the cursor configured to move in forward order, |
| 74302 | 73550 | ** from the beginning toward the end. In other words, the cursor is |
| 74303 | 73551 | ** configured to use Next, not Prev. |
| 74304 | 73552 | */ |
| @@ -75210,13 +74458,10 @@ | ||
| 75210 | 74458 | pFrame->aOp = p->aOp; |
| 75211 | 74459 | pFrame->nOp = p->nOp; |
| 75212 | 74460 | pFrame->token = pProgram->token; |
| 75213 | 74461 | pFrame->aOnceFlag = p->aOnceFlag; |
| 75214 | 74462 | pFrame->nOnceFlag = p->nOnceFlag; |
| 75215 | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS | |
| 75216 | - pFrame->anExec = p->anExec; | |
| 75217 | -#endif | |
| 75218 | 74463 | |
| 75219 | 74464 | pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem]; |
| 75220 | 74465 | for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){ |
| 75221 | 74466 | pMem->flags = MEM_Undefined; |
| 75222 | 74467 | pMem->db = db; |
| @@ -75230,11 +74475,10 @@ | ||
| 75230 | 74475 | |
| 75231 | 74476 | p->nFrame++; |
| 75232 | 74477 | pFrame->pParent = p->pFrame; |
| 75233 | 74478 | pFrame->lastRowid = lastRowid; |
| 75234 | 74479 | pFrame->nChange = p->nChange; |
| 75235 | - pFrame->nDbChange = p->db->nChange; | |
| 75236 | 74480 | p->nChange = 0; |
| 75237 | 74481 | p->pFrame = pFrame; |
| 75238 | 74482 | p->aMem = aMem = &VdbeFrameMem(pFrame)[-1]; |
| 75239 | 74483 | p->nMem = pFrame->nChildMem; |
| 75240 | 74484 | p->nCursor = (u16)pFrame->nChildCsr; |
| @@ -75241,13 +74485,10 @@ | ||
| 75241 | 74485 | p->apCsr = (VdbeCursor **)&aMem[p->nMem+1]; |
| 75242 | 74486 | p->aOp = aOp = pProgram->aOp; |
| 75243 | 74487 | p->nOp = pProgram->nOp; |
| 75244 | 74488 | p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor]; |
| 75245 | 74489 | p->nOnceFlag = pProgram->nOnce; |
| 75246 | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS | |
| 75247 | - p->anExec = 0; | |
| 75248 | -#endif | |
| 75249 | 74490 | pc = -1; |
| 75250 | 74491 | memset(p->aOnceFlag, 0, p->nOnceFlag); |
| 75251 | 74492 | |
| 75252 | 74493 | break; |
| 75253 | 74494 | } |
| @@ -76432,15 +75673,10 @@ | ||
| 76432 | 75673 | char *zErr = 0; |
| 76433 | 75674 | Table *pTab; |
| 76434 | 75675 | Parse *pParse = 0; |
| 76435 | 75676 | Incrblob *pBlob = 0; |
| 76436 | 75677 | |
| 76437 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 76438 | - if( !sqlite3SafetyCheckOk(db) || ppBlob==0 || zTable==0 ){ | |
| 76439 | - return SQLITE_MISUSE_BKPT; | |
| 76440 | - } | |
| 76441 | -#endif | |
| 76442 | 75678 | flags = !!flags; /* flags = (flags ? 1 : 0); */ |
| 76443 | 75679 | *ppBlob = 0; |
| 76444 | 75680 | |
| 76445 | 75681 | sqlite3_mutex_enter(db->mutex); |
| 76446 | 75682 | |
| @@ -76655,10 +75891,11 @@ | ||
| 76655 | 75891 | v = (Vdbe*)p->pStmt; |
| 76656 | 75892 | |
| 76657 | 75893 | if( n<0 || iOffset<0 || (iOffset+n)>p->nByte ){ |
| 76658 | 75894 | /* Request is out of range. Return a transient error. */ |
| 76659 | 75895 | rc = SQLITE_ERROR; |
| 75896 | + sqlite3Error(db, SQLITE_ERROR); | |
| 76660 | 75897 | }else if( v==0 ){ |
| 76661 | 75898 | /* If there is no statement handle, then the blob-handle has |
| 76662 | 75899 | ** already been invalidated. Return SQLITE_ABORT in this case. |
| 76663 | 75900 | */ |
| 76664 | 75901 | rc = SQLITE_ABORT; |
| @@ -76672,14 +75909,14 @@ | ||
| 76672 | 75909 | sqlite3BtreeLeaveCursor(p->pCsr); |
| 76673 | 75910 | if( rc==SQLITE_ABORT ){ |
| 76674 | 75911 | sqlite3VdbeFinalize(v); |
| 76675 | 75912 | p->pStmt = 0; |
| 76676 | 75913 | }else{ |
| 75914 | + db->errCode = rc; | |
| 76677 | 75915 | v->rc = rc; |
| 76678 | 75916 | } |
| 76679 | 75917 | } |
| 76680 | - sqlite3Error(db, rc); | |
| 76681 | 75918 | rc = sqlite3ApiExit(db, rc); |
| 76682 | 75919 | sqlite3_mutex_leave(db->mutex); |
| 76683 | 75920 | return rc; |
| 76684 | 75921 | } |
| 76685 | 75922 | |
| @@ -76852,11 +76089,11 @@ | ||
| 76852 | 76089 | ** itself. |
| 76853 | 76090 | ** |
| 76854 | 76091 | ** The sorter is running in multi-threaded mode if (a) the library was built |
| 76855 | 76092 | ** with pre-processor symbol SQLITE_MAX_WORKER_THREADS set to a value greater |
| 76856 | 76093 | ** than zero, and (b) worker threads have been enabled at runtime by calling |
| 76857 | -** "PRAGMA threads=N" with some value of N greater than 0. | |
| 76094 | +** sqlite3_config(SQLITE_CONFIG_WORKER_THREADS, ...). | |
| 76858 | 76095 | ** |
| 76859 | 76096 | ** When Rewind() is called, any data remaining in memory is flushed to a |
| 76860 | 76097 | ** final PMA. So at this point the data is stored in some number of sorted |
| 76861 | 76098 | ** PMAs within temporary files on disk. |
| 76862 | 76099 | ** |
| @@ -77597,13 +76834,15 @@ | ||
| 77597 | 76834 | pSorter->mnPmaSize = SORTER_MIN_WORKING * pgsz; |
| 77598 | 76835 | mxCache = db->aDb[0].pSchema->cache_size; |
| 77599 | 76836 | if( mxCache<SORTER_MIN_WORKING ) mxCache = SORTER_MIN_WORKING; |
| 77600 | 76837 | pSorter->mxPmaSize = mxCache * pgsz; |
| 77601 | 76838 | |
| 77602 | - /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of | |
| 77603 | - ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary | |
| 77604 | - ** 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. | |
| 77605 | 76844 | */ |
| 77606 | 76845 | if( sqlite3GlobalConfig.pScratch==0 ){ |
| 77607 | 76846 | assert( pSorter->iMemory==0 ); |
| 77608 | 76847 | pSorter->nMemory = pgsz; |
| 77609 | 76848 | pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz); |
| @@ -79971,19 +79210,19 @@ | ||
| 79971 | 79210 | ** |
| 79972 | 79211 | ** incrAggFunctionDepth(pExpr,n) is the main routine. incrAggDepth(..) |
| 79973 | 79212 | ** is a helper function - a callback for the tree walker. |
| 79974 | 79213 | */ |
| 79975 | 79214 | static int incrAggDepth(Walker *pWalker, Expr *pExpr){ |
| 79976 | - if( pExpr->op==TK_AGG_FUNCTION ) pExpr->op2 += pWalker->u.n; | |
| 79215 | + if( pExpr->op==TK_AGG_FUNCTION ) pExpr->op2 += pWalker->u.i; | |
| 79977 | 79216 | return WRC_Continue; |
| 79978 | 79217 | } |
| 79979 | 79218 | static void incrAggFunctionDepth(Expr *pExpr, int N){ |
| 79980 | 79219 | if( N>0 ){ |
| 79981 | 79220 | Walker w; |
| 79982 | 79221 | memset(&w, 0, sizeof(w)); |
| 79983 | 79222 | w.xExprCallback = incrAggDepth; |
| 79984 | - w.u.n = N; | |
| 79223 | + w.u.i = N; | |
| 79985 | 79224 | sqlite3WalkExpr(&w, pExpr); |
| 79986 | 79225 | } |
| 79987 | 79226 | } |
| 79988 | 79227 | |
| 79989 | 79228 | /* |
| @@ -80527,11 +79766,11 @@ | ||
| 80527 | 79766 | double r = -1.0; |
| 80528 | 79767 | if( p->op!=TK_FLOAT ) return -1; |
| 80529 | 79768 | sqlite3AtoF(p->u.zToken, &r, sqlite3Strlen30(p->u.zToken), SQLITE_UTF8); |
| 80530 | 79769 | assert( r>=0.0 ); |
| 80531 | 79770 | if( r>1.0 ) return -1; |
| 80532 | - return (int)(r*134217728.0); | |
| 79771 | + return (int)(r*1000.0); | |
| 80533 | 79772 | } |
| 80534 | 79773 | |
| 80535 | 79774 | /* |
| 80536 | 79775 | ** This routine is callback for sqlite3WalkExpr(). |
| 80537 | 79776 | ** |
| @@ -80659,11 +79898,11 @@ | ||
| 80659 | 79898 | ** EVIDENCE-OF: R-36850-34127 The likely(X) function is short-hand for |
| 80660 | 79899 | ** likelihood(X,0.9375). |
| 80661 | 79900 | ** EVIDENCE-OF: R-53436-40973 The likely(X) function is equivalent to |
| 80662 | 79901 | ** likelihood(X,0.9375). */ |
| 80663 | 79902 | /* TUNING: unlikely() probability is 0.0625. likely() is 0.9375 */ |
| 80664 | - pExpr->iTable = pDef->zName[0]=='u' ? 8388608 : 125829120; | |
| 79903 | + pExpr->iTable = pDef->zName[0]=='u' ? 62 : 938; | |
| 80665 | 79904 | } |
| 80666 | 79905 | } |
| 80667 | 79906 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 80668 | 79907 | auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0); |
| 80669 | 79908 | if( auth!=SQLITE_OK ){ |
| @@ -82616,79 +81855,69 @@ | ||
| 82616 | 81855 | sqlite3DbFree(db, pList->a); |
| 82617 | 81856 | sqlite3DbFree(db, pList); |
| 82618 | 81857 | } |
| 82619 | 81858 | |
| 82620 | 81859 | /* |
| 82621 | -** These routines are Walker callbacks used to check expressions to | |
| 82622 | -** see if they are "constant" for some definition of constant. The | |
| 82623 | -** Walker.eCode value determines the type of "constant" we are looking | |
| 82624 | -** 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. | |
| 82625 | 81864 | ** |
| 82626 | 81865 | ** These callback routines are used to implement the following: |
| 82627 | 81866 | ** |
| 82628 | -** sqlite3ExprIsConstant() pWalker->eCode==1 | |
| 82629 | -** sqlite3ExprIsConstantNotJoin() pWalker->eCode==2 | |
| 82630 | -** sqlite3ExprRefOneTableOnly() pWalker->eCode==3 | |
| 82631 | -** sqlite3ExprIsConstantOrFunction() pWalker->eCode==4 or 5 | |
| 82632 | -** | |
| 82633 | -** In all cases, the callbacks set Walker.eCode=0 and abort if the expression | |
| 82634 | -** 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 | |
| 82635 | 81870 | ** |
| 82636 | 81871 | ** The sqlite3ExprIsConstantOrFunction() is used for evaluating expressions |
| 82637 | -** in a CREATE TABLE statement. The Walker.eCode value is 5 when parsing | |
| 82638 | -** 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 | |
| 82639 | 81874 | ** parameter raises an error for new statements, but is silently converted |
| 82640 | 81875 | ** to NULL for existing schemas. This allows sqlite_master tables that |
| 82641 | 81876 | ** contain a bound parameter because they were generated by older versions |
| 82642 | 81877 | ** of SQLite to be parsed by newer versions of SQLite without raising a |
| 82643 | 81878 | ** malformed schema error. |
| 82644 | 81879 | */ |
| 82645 | 81880 | static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){ |
| 82646 | 81881 | |
| 82647 | - /* If pWalker->eCode is 2 then any term of the expression that comes from | |
| 82648 | - ** 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 | |
| 82649 | 81884 | ** from being considered constant. */ |
| 82650 | - if( pWalker->eCode==2 && ExprHasProperty(pExpr, EP_FromJoin) ){ | |
| 82651 | - pWalker->eCode = 0; | |
| 81885 | + if( pWalker->u.i==2 && ExprHasProperty(pExpr, EP_FromJoin) ){ | |
| 81886 | + pWalker->u.i = 0; | |
| 82652 | 81887 | return WRC_Abort; |
| 82653 | 81888 | } |
| 82654 | 81889 | |
| 82655 | 81890 | switch( pExpr->op ){ |
| 82656 | 81891 | /* Consider functions to be constant if all their arguments are constant |
| 82657 | - ** and either pWalker->eCode==4 or 5 or the function has the | |
| 82658 | - ** SQLITE_FUNC_CONST flag. */ | |
| 81892 | + ** and either pWalker->u.i==3 or 4 or the function as the SQLITE_FUNC_CONST | |
| 81893 | + ** flag. */ | |
| 82659 | 81894 | case TK_FUNCTION: |
| 82660 | - if( pWalker->eCode>=4 || ExprHasProperty(pExpr,EP_Constant) ){ | |
| 81895 | + if( pWalker->u.i>=3 || ExprHasProperty(pExpr,EP_Constant) ){ | |
| 82661 | 81896 | return WRC_Continue; |
| 82662 | - }else{ | |
| 82663 | - pWalker->eCode = 0; | |
| 82664 | - return WRC_Abort; | |
| 82665 | 81897 | } |
| 81898 | + /* Fall through */ | |
| 82666 | 81899 | case TK_ID: |
| 82667 | 81900 | case TK_COLUMN: |
| 82668 | 81901 | case TK_AGG_FUNCTION: |
| 82669 | 81902 | case TK_AGG_COLUMN: |
| 82670 | 81903 | testcase( pExpr->op==TK_ID ); |
| 82671 | 81904 | testcase( pExpr->op==TK_COLUMN ); |
| 82672 | 81905 | testcase( pExpr->op==TK_AGG_FUNCTION ); |
| 82673 | 81906 | testcase( pExpr->op==TK_AGG_COLUMN ); |
| 82674 | - if( pWalker->eCode==3 && pExpr->iTable==pWalker->u.iCur ){ | |
| 82675 | - return WRC_Continue; | |
| 82676 | - }else{ | |
| 82677 | - pWalker->eCode = 0; | |
| 82678 | - return WRC_Abort; | |
| 82679 | - } | |
| 81907 | + pWalker->u.i = 0; | |
| 81908 | + return WRC_Abort; | |
| 82680 | 81909 | case TK_VARIABLE: |
| 82681 | - if( pWalker->eCode==5 ){ | |
| 81910 | + if( pWalker->u.i==4 ){ | |
| 82682 | 81911 | /* Silently convert bound parameters that appear inside of CREATE |
| 82683 | 81912 | ** statements into a NULL when parsing the CREATE statement text out |
| 82684 | 81913 | ** of the sqlite_master table */ |
| 82685 | 81914 | pExpr->op = TK_NULL; |
| 82686 | - }else if( pWalker->eCode==4 ){ | |
| 81915 | + }else if( pWalker->u.i==3 ){ | |
| 82687 | 81916 | /* A bound parameter in a CREATE statement that originates from |
| 82688 | 81917 | ** sqlite3_prepare() causes an error */ |
| 82689 | - pWalker->eCode = 0; | |
| 81918 | + pWalker->u.i = 0; | |
| 82690 | 81919 | return WRC_Abort; |
| 82691 | 81920 | } |
| 82692 | 81921 | /* Fall through */ |
| 82693 | 81922 | default: |
| 82694 | 81923 | testcase( pExpr->op==TK_SELECT ); /* selectNodeIsConstant will disallow */ |
| @@ -82696,68 +81925,57 @@ | ||
| 82696 | 81925 | return WRC_Continue; |
| 82697 | 81926 | } |
| 82698 | 81927 | } |
| 82699 | 81928 | static int selectNodeIsConstant(Walker *pWalker, Select *NotUsed){ |
| 82700 | 81929 | UNUSED_PARAMETER(NotUsed); |
| 82701 | - pWalker->eCode = 0; | |
| 81930 | + pWalker->u.i = 0; | |
| 82702 | 81931 | return WRC_Abort; |
| 82703 | 81932 | } |
| 82704 | -static int exprIsConst(Expr *p, int initFlag, int iCur){ | |
| 81933 | +static int exprIsConst(Expr *p, int initFlag){ | |
| 82705 | 81934 | Walker w; |
| 82706 | 81935 | memset(&w, 0, sizeof(w)); |
| 82707 | - w.eCode = initFlag; | |
| 81936 | + w.u.i = initFlag; | |
| 82708 | 81937 | w.xExprCallback = exprNodeIsConstant; |
| 82709 | 81938 | w.xSelectCallback = selectNodeIsConstant; |
| 82710 | - w.u.iCur = iCur; | |
| 82711 | 81939 | sqlite3WalkExpr(&w, p); |
| 82712 | - return w.eCode; | |
| 81940 | + return w.u.i; | |
| 82713 | 81941 | } |
| 82714 | 81942 | |
| 82715 | 81943 | /* |
| 82716 | -** Walk an expression tree. Return non-zero if the expression is constant | |
| 81944 | +** Walk an expression tree. Return 1 if the expression is constant | |
| 82717 | 81945 | ** and 0 if it involves variables or function calls. |
| 82718 | 81946 | ** |
| 82719 | 81947 | ** For the purposes of this function, a double-quoted string (ex: "abc") |
| 82720 | 81948 | ** is considered a variable but a single-quoted string (ex: 'abc') is |
| 82721 | 81949 | ** a constant. |
| 82722 | 81950 | */ |
| 82723 | 81951 | SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr *p){ |
| 82724 | - return exprIsConst(p, 1, 0); | |
| 81952 | + return exprIsConst(p, 1); | |
| 82725 | 81953 | } |
| 82726 | 81954 | |
| 82727 | 81955 | /* |
| 82728 | -** Walk an expression tree. Return non-zero if the expression is constant | |
| 81956 | +** Walk an expression tree. Return 1 if the expression is constant | |
| 82729 | 81957 | ** that does no originate from the ON or USING clauses of a join. |
| 82730 | 81958 | ** Return 0 if it involves variables or function calls or terms from |
| 82731 | 81959 | ** an ON or USING clause. |
| 82732 | 81960 | */ |
| 82733 | 81961 | SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr *p){ |
| 82734 | - return exprIsConst(p, 2, 0); | |
| 81962 | + return exprIsConst(p, 2); | |
| 82735 | 81963 | } |
| 82736 | 81964 | |
| 82737 | 81965 | /* |
| 82738 | -** Walk an expression tree. Return non-zero if the expression constant | |
| 82739 | -** for any single row of the table with cursor iCur. In other words, the | |
| 82740 | -** expression must not refer to any non-deterministic function nor any | |
| 82741 | -** table other than iCur. | |
| 82742 | -*/ | |
| 82743 | -SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){ | |
| 82744 | - return exprIsConst(p, 3, iCur); | |
| 82745 | -} | |
| 82746 | - | |
| 82747 | -/* | |
| 82748 | -** Walk an expression tree. Return non-zero if the expression is constant | |
| 81966 | +** Walk an expression tree. Return 1 if the expression is constant | |
| 82749 | 81967 | ** or a function call with constant arguments. Return and 0 if there |
| 82750 | 81968 | ** are any variables. |
| 82751 | 81969 | ** |
| 82752 | 81970 | ** For the purposes of this function, a double-quoted string (ex: "abc") |
| 82753 | 81971 | ** is considered a variable but a single-quoted string (ex: 'abc') is |
| 82754 | 81972 | ** a constant. |
| 82755 | 81973 | */ |
| 82756 | 81974 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr *p, u8 isInit){ |
| 82757 | 81975 | assert( isInit==0 || isInit==1 ); |
| 82758 | - return exprIsConst(p, 4+isInit, 0); | |
| 81976 | + return exprIsConst(p, 3+isInit); | |
| 82759 | 81977 | } |
| 82760 | 81978 | |
| 82761 | 81979 | /* |
| 82762 | 81980 | ** If the expression p codes a constant integer that is small enough |
| 82763 | 81981 | ** to fit in a 32-bit integer, return 1 and put the value of the integer |
| @@ -88070,12 +87288,10 @@ | ||
| 88070 | 87288 | while( z[0] ){ |
| 88071 | 87289 | if( sqlite3_strglob("unordered*", z)==0 ){ |
| 88072 | 87290 | pIndex->bUnordered = 1; |
| 88073 | 87291 | }else if( sqlite3_strglob("sz=[0-9]*", z)==0 ){ |
| 88074 | 87292 | pIndex->szIdxRow = sqlite3LogEst(sqlite3Atoi(z+3)); |
| 88075 | - }else if( sqlite3_strglob("noskipscan*", z)==0 ){ | |
| 88076 | - pIndex->noSkipScan = 1; | |
| 88077 | 87293 | } |
| 88078 | 87294 | #ifdef SQLITE_ENABLE_COSTMULT |
| 88079 | 87295 | else if( sqlite3_strglob("costmult=[0-9]*",z)==0 ){ |
| 88080 | 87296 | pIndex->pTable->costMult = sqlite3LogEst(sqlite3Atoi(z+9)); |
| 88081 | 87297 | } |
| @@ -88205,11 +87421,10 @@ | ||
| 88205 | 87421 | nSample--; |
| 88206 | 87422 | }else{ |
| 88207 | 87423 | nRow = pIdx->aiRowEst[0]; |
| 88208 | 87424 | nDist100 = ((i64)100 * pIdx->aiRowEst[0]) / pIdx->aiRowEst[iCol+1]; |
| 88209 | 87425 | } |
| 88210 | - pIdx->nRowEst0 = nRow; | |
| 88211 | 87426 | |
| 88212 | 87427 | /* Set nSum to the number of distinct (iCol+1) field prefixes that |
| 88213 | 87428 | ** occur in the stat4 table for this index. Set sumEq to the sum of |
| 88214 | 87429 | ** the nEq values for column iCol for the same set (adding the value |
| 88215 | 87430 | ** only once where there exist duplicate prefixes). */ |
| @@ -88467,11 +87682,11 @@ | ||
| 88467 | 87682 | } |
| 88468 | 87683 | |
| 88469 | 87684 | |
| 88470 | 87685 | /* Load the statistics from the sqlite_stat4 table. */ |
| 88471 | 87686 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 88472 | - if( rc==SQLITE_OK && OptimizationEnabled(db, SQLITE_Stat34) ){ | |
| 87687 | + if( rc==SQLITE_OK ){ | |
| 88473 | 87688 | int lookasideEnabled = db->lookaside.bEnabled; |
| 88474 | 87689 | db->lookaside.bEnabled = 0; |
| 88475 | 87690 | rc = loadStat4(db, sInfo.zDatabase); |
| 88476 | 87691 | db->lookaside.bEnabled = lookasideEnabled; |
| 88477 | 87692 | } |
| @@ -89149,13 +88364,10 @@ | ||
| 89149 | 88364 | SQLITE_API int sqlite3_set_authorizer( |
| 89150 | 88365 | sqlite3 *db, |
| 89151 | 88366 | int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), |
| 89152 | 88367 | void *pArg |
| 89153 | 88368 | ){ |
| 89154 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 89155 | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; | |
| 89156 | -#endif | |
| 89157 | 88369 | sqlite3_mutex_enter(db->mutex); |
| 89158 | 88370 | db->xAuth = (sqlite3_xauth)xAuth; |
| 89159 | 88371 | db->pAuthArg = pArg; |
| 89160 | 88372 | sqlite3ExpirePreparedStatements(db); |
| 89161 | 88373 | sqlite3_mutex_leave(db->mutex); |
| @@ -89646,15 +88858,11 @@ | ||
| 89646 | 88858 | ** See also sqlite3LocateTable(). |
| 89647 | 88859 | */ |
| 89648 | 88860 | SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){ |
| 89649 | 88861 | Table *p = 0; |
| 89650 | 88862 | int i; |
| 89651 | - | |
| 89652 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 89653 | - if( !sqlite3SafetyCheckOk(db) || zName==0 ) return 0; | |
| 89654 | -#endif | |
| 89655 | - | |
| 88863 | + assert( zName!=0 ); | |
| 89656 | 88864 | /* All mutexes are required for schema access. Make sure we hold them. */ |
| 89657 | 88865 | assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) ); |
| 89658 | 88866 | #if SQLITE_USER_AUTHENTICATION |
| 89659 | 88867 | /* Only the admin user is allowed to know that the sqlite_user table |
| 89660 | 88868 | ** exists */ |
| @@ -104673,16 +103881,13 @@ | ||
| 104673 | 103881 | Vdbe *pOld, /* VM being reprepared */ |
| 104674 | 103882 | sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */ |
| 104675 | 103883 | const char **pzTail /* OUT: End of parsed string */ |
| 104676 | 103884 | ){ |
| 104677 | 103885 | int rc; |
| 104678 | - | |
| 104679 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 104680 | - if( ppStmt==0 ) return SQLITE_MISUSE_BKPT; | |
| 104681 | -#endif | |
| 103886 | + assert( ppStmt!=0 ); | |
| 104682 | 103887 | *ppStmt = 0; |
| 104683 | - if( !sqlite3SafetyCheckOk(db)||zSql==0 ){ | |
| 103888 | + if( !sqlite3SafetyCheckOk(db) ){ | |
| 104684 | 103889 | return SQLITE_MISUSE_BKPT; |
| 104685 | 103890 | } |
| 104686 | 103891 | sqlite3_mutex_enter(db->mutex); |
| 104687 | 103892 | sqlite3BtreeEnterAll(db); |
| 104688 | 103893 | rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail); |
| @@ -104785,15 +103990,13 @@ | ||
| 104785 | 103990 | */ |
| 104786 | 103991 | char *zSql8; |
| 104787 | 103992 | const char *zTail8 = 0; |
| 104788 | 103993 | int rc = SQLITE_OK; |
| 104789 | 103994 | |
| 104790 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 104791 | - if( ppStmt==0 ) return SQLITE_MISUSE_BKPT; | |
| 104792 | -#endif | |
| 103995 | + assert( ppStmt ); | |
| 104793 | 103996 | *ppStmt = 0; |
| 104794 | - if( !sqlite3SafetyCheckOk(db)||zSql==0 ){ | |
| 103997 | + if( !sqlite3SafetyCheckOk(db) ){ | |
| 104795 | 103998 | return SQLITE_MISUSE_BKPT; |
| 104796 | 103999 | } |
| 104797 | 104000 | if( nBytes>=0 ){ |
| 104798 | 104001 | int sz; |
| 104799 | 104002 | const char *z = (const char*)zSql; |
| @@ -110502,13 +109705,10 @@ | ||
| 110502 | 109705 | char **pzErrMsg /* Write error messages here */ |
| 110503 | 109706 | ){ |
| 110504 | 109707 | int rc; |
| 110505 | 109708 | TabResult res; |
| 110506 | 109709 | |
| 110507 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 110508 | - if( pazResult==0 ) return SQLITE_MISUSE_BKPT; | |
| 110509 | -#endif | |
| 110510 | 109710 | *pazResult = 0; |
| 110511 | 109711 | if( pnColumn ) *pnColumn = 0; |
| 110512 | 109712 | if( pnRow ) *pnRow = 0; |
| 110513 | 109713 | if( pzErrMsg ) *pzErrMsg = 0; |
| 110514 | 109714 | res.zErrMsg = 0; |
| @@ -112568,11 +111768,11 @@ | ||
| 112568 | 111768 | ** Two writes per page are required in step (3) because the original |
| 112569 | 111769 | ** database content must be written into the rollback journal prior to |
| 112570 | 111770 | ** overwriting the database with the vacuumed content. |
| 112571 | 111771 | ** |
| 112572 | 111772 | ** Only 1x temporary space and only 1x writes would be required if |
| 112573 | -** 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 | |
| 112574 | 111774 | ** and renaming the transient database as the original. But that will |
| 112575 | 111775 | ** not work if other processes are attached to the original database. |
| 112576 | 111776 | ** And a power loss in between deleting the original and renaming the |
| 112577 | 111777 | ** transient would cause the database file to appear to be deleted |
| 112578 | 111778 | ** following reboot. |
| @@ -112926,13 +112126,10 @@ | ||
| 112926 | 112126 | sqlite3 *db, /* Database in which module is registered */ |
| 112927 | 112127 | const char *zName, /* Name assigned to this module */ |
| 112928 | 112128 | const sqlite3_module *pModule, /* The definition of the module */ |
| 112929 | 112129 | void *pAux /* Context pointer for xCreate/xConnect */ |
| 112930 | 112130 | ){ |
| 112931 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 112932 | - if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT; | |
| 112933 | -#endif | |
| 112934 | 112131 | return createModule(db, zName, pModule, pAux, 0); |
| 112935 | 112132 | } |
| 112936 | 112133 | |
| 112937 | 112134 | /* |
| 112938 | 112135 | ** External API function used to create a new virtual-table module. |
| @@ -112942,13 +112139,10 @@ | ||
| 112942 | 112139 | const char *zName, /* Name assigned to this module */ |
| 112943 | 112140 | const sqlite3_module *pModule, /* The definition of the module */ |
| 112944 | 112141 | void *pAux, /* Context pointer for xCreate/xConnect */ |
| 112945 | 112142 | void (*xDestroy)(void *) /* Module destructor function */ |
| 112946 | 112143 | ){ |
| 112947 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 112948 | - if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT; | |
| 112949 | -#endif | |
| 112950 | 112144 | return createModule(db, zName, pModule, pAux, xDestroy); |
| 112951 | 112145 | } |
| 112952 | 112146 | |
| 112953 | 112147 | /* |
| 112954 | 112148 | ** Lock the virtual table so that it cannot be disconnected. |
| @@ -113549,13 +112743,10 @@ | ||
| 113549 | 112743 | |
| 113550 | 112744 | int rc = SQLITE_OK; |
| 113551 | 112745 | Table *pTab; |
| 113552 | 112746 | char *zErr = 0; |
| 113553 | 112747 | |
| 113554 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 113555 | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; | |
| 113556 | -#endif | |
| 113557 | 112748 | sqlite3_mutex_enter(db->mutex); |
| 113558 | 112749 | if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){ |
| 113559 | 112750 | sqlite3Error(db, SQLITE_MISUSE); |
| 113560 | 112751 | sqlite3_mutex_leave(db->mutex); |
| 113561 | 112752 | return SQLITE_MISUSE_BKPT; |
| @@ -113908,13 +113099,10 @@ | ||
| 113908 | 113099 | */ |
| 113909 | 113100 | SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *db){ |
| 113910 | 113101 | static const unsigned char aMap[] = { |
| 113911 | 113102 | SQLITE_ROLLBACK, SQLITE_ABORT, SQLITE_FAIL, SQLITE_IGNORE, SQLITE_REPLACE |
| 113912 | 113103 | }; |
| 113913 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 113914 | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; | |
| 113915 | -#endif | |
| 113916 | 113104 | assert( OE_Rollback==1 && OE_Abort==2 && OE_Fail==3 ); |
| 113917 | 113105 | assert( OE_Ignore==4 && OE_Replace==5 ); |
| 113918 | 113106 | assert( db->vtabOnConflict>=1 && db->vtabOnConflict<=5 ); |
| 113919 | 113107 | return (int)aMap[db->vtabOnConflict-1]; |
| 113920 | 113108 | } |
| @@ -113926,14 +113114,12 @@ | ||
| 113926 | 113114 | */ |
| 113927 | 113115 | SQLITE_API int sqlite3_vtab_config(sqlite3 *db, int op, ...){ |
| 113928 | 113116 | va_list ap; |
| 113929 | 113117 | int rc = SQLITE_OK; |
| 113930 | 113118 | |
| 113931 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 113932 | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; | |
| 113933 | -#endif | |
| 113934 | 113119 | sqlite3_mutex_enter(db->mutex); |
| 113120 | + | |
| 113935 | 113121 | va_start(ap, op); |
| 113936 | 113122 | switch( op ){ |
| 113937 | 113123 | case SQLITE_VTAB_CONSTRAINT_SUPPORT: { |
| 113938 | 113124 | VtabCtx *p = db->pVtabCtx; |
| 113939 | 113125 | if( !p ){ |
| @@ -114064,13 +113250,10 @@ | ||
| 114064 | 113250 | } in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */ |
| 114065 | 113251 | Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */ |
| 114066 | 113252 | } u; |
| 114067 | 113253 | struct WhereLoop *pWLoop; /* The selected WhereLoop object */ |
| 114068 | 113254 | Bitmask notReady; /* FROM entries not usable at this level */ |
| 114069 | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS | |
| 114070 | - int addrVisit; /* Address at which row is visited */ | |
| 114071 | -#endif | |
| 114072 | 113255 | }; |
| 114073 | 113256 | |
| 114074 | 113257 | /* |
| 114075 | 113258 | ** Each instance of this object represents an algorithm for evaluating one |
| 114076 | 113259 | ** term of a join. Every term of the FROM clause will have at least |
| @@ -114097,10 +113280,11 @@ | ||
| 114097 | 113280 | LogEst rRun; /* Cost of running each loop */ |
| 114098 | 113281 | LogEst nOut; /* Estimated number of output rows */ |
| 114099 | 113282 | union { |
| 114100 | 113283 | struct { /* Information for internal btree tables */ |
| 114101 | 113284 | u16 nEq; /* Number of equality constraints */ |
| 113285 | + u16 nSkip; /* Number of initial index columns to skip */ | |
| 114102 | 113286 | Index *pIndex; /* Index used, or NULL */ |
| 114103 | 113287 | } btree; |
| 114104 | 113288 | struct { /* Information for virtual tables */ |
| 114105 | 113289 | int idxNum; /* Index number */ |
| 114106 | 113290 | u8 needFree; /* True if sqlite3_free(idxStr) is needed */ |
| @@ -114109,17 +113293,16 @@ | ||
| 114109 | 113293 | char *idxStr; /* Index identifier string */ |
| 114110 | 113294 | } vtab; |
| 114111 | 113295 | } u; |
| 114112 | 113296 | u32 wsFlags; /* WHERE_* flags describing the plan */ |
| 114113 | 113297 | u16 nLTerm; /* Number of entries in aLTerm[] */ |
| 114114 | - u16 nSkip; /* Number of NULL aLTerm[] entries */ | |
| 114115 | 113298 | /**** whereLoopXfer() copies fields above ***********************/ |
| 114116 | 113299 | # define WHERE_LOOP_XFER_SZ offsetof(WhereLoop,nLSlot) |
| 114117 | 113300 | u16 nLSlot; /* Number of slots allocated for aLTerm[] */ |
| 114118 | 113301 | WhereTerm **aLTerm; /* WhereTerms used */ |
| 114119 | 113302 | WhereLoop *pNextLoop; /* Next WhereLoop object in the WhereClause */ |
| 114120 | - WhereTerm *aLTermSpace[3]; /* Initial aLTerm[] space */ | |
| 113303 | + WhereTerm *aLTermSpace[4]; /* Initial aLTerm[] space */ | |
| 114121 | 113304 | }; |
| 114122 | 113305 | |
| 114123 | 113306 | /* This object holds the prerequisites and the cost of running a |
| 114124 | 113307 | ** subquery on one operand of an OR operator in the WHERE clause. |
| 114125 | 113308 | ** See WhereOrSet for additional information |
| @@ -114441,11 +113624,10 @@ | ||
| 114441 | 113624 | #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */ |
| 114442 | 113625 | #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */ |
| 114443 | 113626 | #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */ |
| 114444 | 113627 | #define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */ |
| 114445 | 113628 | #define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/ |
| 114446 | -#define WHERE_PARTIALIDX 0x00020000 /* The automatic index is partial */ | |
| 114447 | 113629 | |
| 114448 | 113630 | /************** End of whereInt.h ********************************************/ |
| 114449 | 113631 | /************** Continuing where we left off in where.c **********************/ |
| 114450 | 113632 | |
| 114451 | 113633 | /* |
| @@ -114652,11 +113834,11 @@ | ||
| 114652 | 113834 | } |
| 114653 | 113835 | pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]); |
| 114654 | 113836 | } |
| 114655 | 113837 | pTerm = &pWC->a[idx = pWC->nTerm++]; |
| 114656 | 113838 | if( p && ExprHasProperty(p, EP_Unlikely) ){ |
| 114657 | - pTerm->truthProb = sqlite3LogEst(p->iTable) - 270; | |
| 113839 | + pTerm->truthProb = sqlite3LogEst(p->iTable) - 99; | |
| 114658 | 113840 | }else{ |
| 114659 | 113841 | pTerm->truthProb = 1; |
| 114660 | 113842 | } |
| 114661 | 113843 | pTerm->pExpr = sqlite3ExprSkipCollate(p); |
| 114662 | 113844 | pTerm->wtFlags = wtFlags; |
| @@ -115183,19 +114365,10 @@ | ||
| 115183 | 114365 | pDerived->flags |= pBase->flags & EP_FromJoin; |
| 115184 | 114366 | pDerived->iRightJoinTable = pBase->iRightJoinTable; |
| 115185 | 114367 | } |
| 115186 | 114368 | } |
| 115187 | 114369 | |
| 115188 | -/* | |
| 115189 | -** Mark term iChild as being a child of term iParent | |
| 115190 | -*/ | |
| 115191 | -static void markTermAsChild(WhereClause *pWC, int iChild, int iParent){ | |
| 115192 | - pWC->a[iChild].iParent = iParent; | |
| 115193 | - pWC->a[iChild].truthProb = pWC->a[iParent].truthProb; | |
| 115194 | - pWC->a[iParent].nChild++; | |
| 115195 | -} | |
| 115196 | - | |
| 115197 | 114370 | #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY) |
| 115198 | 114371 | /* |
| 115199 | 114372 | ** Analyze a term that consists of two or more OR-connected |
| 115200 | 114373 | ** subterms. So in: |
| 115201 | 114374 | ** |
| @@ -115489,11 +114662,12 @@ | ||
| 115489 | 114662 | pNew->x.pList = pList; |
| 115490 | 114663 | idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC); |
| 115491 | 114664 | testcase( idxNew==0 ); |
| 115492 | 114665 | exprAnalyze(pSrc, pWC, idxNew); |
| 115493 | 114666 | pTerm = &pWC->a[idxTerm]; |
| 115494 | - markTermAsChild(pWC, idxNew, idxTerm); | |
| 114667 | + pWC->a[idxNew].iParent = idxTerm; | |
| 114668 | + pTerm->nChild = 1; | |
| 115495 | 114669 | }else{ |
| 115496 | 114670 | sqlite3ExprListDelete(db, pList); |
| 115497 | 114671 | } |
| 115498 | 114672 | pTerm->eOperator = WO_NOOP; /* case 1 trumps case 2 */ |
| 115499 | 114673 | } |
| @@ -115591,12 +114765,13 @@ | ||
| 115591 | 114765 | return; |
| 115592 | 114766 | } |
| 115593 | 114767 | idxNew = whereClauseInsert(pWC, pDup, TERM_VIRTUAL|TERM_DYNAMIC); |
| 115594 | 114768 | if( idxNew==0 ) return; |
| 115595 | 114769 | pNew = &pWC->a[idxNew]; |
| 115596 | - markTermAsChild(pWC, idxNew, idxTerm); | |
| 114770 | + pNew->iParent = idxTerm; | |
| 115597 | 114771 | pTerm = &pWC->a[idxTerm]; |
| 114772 | + pTerm->nChild = 1; | |
| 115598 | 114773 | pTerm->wtFlags |= TERM_COPIED; |
| 115599 | 114774 | if( pExpr->op==TK_EQ |
| 115600 | 114775 | && !ExprHasProperty(pExpr, EP_FromJoin) |
| 115601 | 114776 | && OptimizationEnabled(db, SQLITE_Transitive) |
| 115602 | 114777 | ){ |
| @@ -115649,12 +114824,13 @@ | ||
| 115649 | 114824 | transferJoinMarkings(pNewExpr, pExpr); |
| 115650 | 114825 | idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC); |
| 115651 | 114826 | testcase( idxNew==0 ); |
| 115652 | 114827 | exprAnalyze(pSrc, pWC, idxNew); |
| 115653 | 114828 | pTerm = &pWC->a[idxTerm]; |
| 115654 | - markTermAsChild(pWC, idxNew, idxTerm); | |
| 114829 | + pWC->a[idxNew].iParent = idxTerm; | |
| 115655 | 114830 | } |
| 114831 | + pTerm->nChild = 2; | |
| 115656 | 114832 | } |
| 115657 | 114833 | #endif /* SQLITE_OMIT_BETWEEN_OPTIMIZATION */ |
| 115658 | 114834 | |
| 115659 | 114835 | #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY) |
| 115660 | 114836 | /* Analyze a term that is composed of two or more subterms connected by |
| @@ -115725,12 +114901,13 @@ | ||
| 115725 | 114901 | idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC); |
| 115726 | 114902 | testcase( idxNew2==0 ); |
| 115727 | 114903 | exprAnalyze(pSrc, pWC, idxNew2); |
| 115728 | 114904 | pTerm = &pWC->a[idxTerm]; |
| 115729 | 114905 | if( isComplete ){ |
| 115730 | - markTermAsChild(pWC, idxNew1, idxTerm); | |
| 115731 | - markTermAsChild(pWC, idxNew2, idxTerm); | |
| 114906 | + pWC->a[idxNew1].iParent = idxTerm; | |
| 114907 | + pWC->a[idxNew2].iParent = idxTerm; | |
| 114908 | + pTerm->nChild = 2; | |
| 115732 | 114909 | } |
| 115733 | 114910 | } |
| 115734 | 114911 | #endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */ |
| 115735 | 114912 | |
| 115736 | 114913 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| @@ -115759,12 +114936,13 @@ | ||
| 115759 | 114936 | pNewTerm = &pWC->a[idxNew]; |
| 115760 | 114937 | pNewTerm->prereqRight = prereqExpr; |
| 115761 | 114938 | pNewTerm->leftCursor = pLeft->iTable; |
| 115762 | 114939 | pNewTerm->u.leftColumn = pLeft->iColumn; |
| 115763 | 114940 | pNewTerm->eOperator = WO_MATCH; |
| 115764 | - markTermAsChild(pWC, idxNew, idxTerm); | |
| 114941 | + pNewTerm->iParent = idxTerm; | |
| 115765 | 114942 | pTerm = &pWC->a[idxTerm]; |
| 114943 | + pTerm->nChild = 1; | |
| 115766 | 114944 | pTerm->wtFlags |= TERM_COPIED; |
| 115767 | 114945 | pNewTerm->prereqAll = pTerm->prereqAll; |
| 115768 | 114946 | } |
| 115769 | 114947 | } |
| 115770 | 114948 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| @@ -115781,11 +114959,11 @@ | ||
| 115781 | 114959 | ** the start of the loop will prevent any results from being returned. |
| 115782 | 114960 | */ |
| 115783 | 114961 | if( pExpr->op==TK_NOTNULL |
| 115784 | 114962 | && pExpr->pLeft->op==TK_COLUMN |
| 115785 | 114963 | && pExpr->pLeft->iColumn>=0 |
| 115786 | - && OptimizationEnabled(db, SQLITE_Stat34) | |
| 114964 | + && OptimizationEnabled(db, SQLITE_Stat3) | |
| 115787 | 114965 | ){ |
| 115788 | 114966 | Expr *pNewExpr; |
| 115789 | 114967 | Expr *pLeft = pExpr->pLeft; |
| 115790 | 114968 | int idxNew; |
| 115791 | 114969 | WhereTerm *pNewTerm; |
| @@ -115800,12 +114978,13 @@ | ||
| 115800 | 114978 | pNewTerm = &pWC->a[idxNew]; |
| 115801 | 114979 | pNewTerm->prereqRight = 0; |
| 115802 | 114980 | pNewTerm->leftCursor = pLeft->iTable; |
| 115803 | 114981 | pNewTerm->u.leftColumn = pLeft->iColumn; |
| 115804 | 114982 | pNewTerm->eOperator = WO_GT; |
| 115805 | - markTermAsChild(pWC, idxNew, idxTerm); | |
| 114983 | + pNewTerm->iParent = idxTerm; | |
| 115806 | 114984 | pTerm = &pWC->a[idxTerm]; |
| 114985 | + pTerm->nChild = 1; | |
| 115807 | 114986 | pTerm->wtFlags |= TERM_COPIED; |
| 115808 | 114987 | pNewTerm->prereqAll = pTerm->prereqAll; |
| 115809 | 114988 | } |
| 115810 | 114989 | } |
| 115811 | 114990 | #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */ |
| @@ -116021,12 +115200,10 @@ | ||
| 116021 | 115200 | WhereLoop *pLoop; /* The Loop object */ |
| 116022 | 115201 | char *zNotUsed; /* Extra space on the end of pIdx */ |
| 116023 | 115202 | Bitmask idxCols; /* Bitmap of columns used for indexing */ |
| 116024 | 115203 | Bitmask extraCols; /* Bitmap of additional columns */ |
| 116025 | 115204 | u8 sentWarning = 0; /* True if a warnning has been issued */ |
| 116026 | - Expr *pPartial = 0; /* Partial Index Expression */ | |
| 116027 | - int iContinue = 0; /* Jump here to skip excluded rows */ | |
| 116028 | 115205 | |
| 116029 | 115206 | /* Generate code to skip over the creation and initialization of the |
| 116030 | 115207 | ** transient index on 2nd and subsequent iterations of the loop. */ |
| 116031 | 115208 | v = pParse->pVdbe; |
| 116032 | 115209 | assert( v!=0 ); |
| @@ -116038,16 +115215,10 @@ | ||
| 116038 | 115215 | pTable = pSrc->pTab; |
| 116039 | 115216 | pWCEnd = &pWC->a[pWC->nTerm]; |
| 116040 | 115217 | pLoop = pLevel->pWLoop; |
| 116041 | 115218 | idxCols = 0; |
| 116042 | 115219 | for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){ |
| 116043 | - if( pLoop->prereq==0 | |
| 116044 | - && (pTerm->wtFlags & TERM_VIRTUAL)==0 | |
| 116045 | - && sqlite3ExprIsTableConstant(pTerm->pExpr, pSrc->iCursor) ){ | |
| 116046 | - pPartial = sqlite3ExprAnd(pParse->db, pPartial, | |
| 116047 | - sqlite3ExprDup(pParse->db, pTerm->pExpr, 0)); | |
| 116048 | - } | |
| 116049 | 115220 | if( termCanDriveIndex(pTerm, pSrc, notReady) ){ |
| 116050 | 115221 | int iCol = pTerm->u.leftColumn; |
| 116051 | 115222 | Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol); |
| 116052 | 115223 | testcase( iCol==BMS ); |
| 116053 | 115224 | testcase( iCol==BMS-1 ); |
| @@ -116056,13 +115227,11 @@ | ||
| 116056 | 115227 | "automatic index on %s(%s)", pTable->zName, |
| 116057 | 115228 | pTable->aCol[iCol].zName); |
| 116058 | 115229 | sentWarning = 1; |
| 116059 | 115230 | } |
| 116060 | 115231 | if( (idxCols & cMask)==0 ){ |
| 116061 | - if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ){ | |
| 116062 | - goto end_auto_index_create; | |
| 116063 | - } | |
| 115232 | + if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ) return; | |
| 116064 | 115233 | pLoop->aLTerm[nKeyCol++] = pTerm; |
| 116065 | 115234 | idxCols |= cMask; |
| 116066 | 115235 | } |
| 116067 | 115236 | } |
| 116068 | 115237 | } |
| @@ -116078,23 +115247,24 @@ | ||
| 116078 | 115247 | ** be a covering index because the index will not be updated if the |
| 116079 | 115248 | ** original table changes and the index and table cannot both be used |
| 116080 | 115249 | ** if they go out of sync. |
| 116081 | 115250 | */ |
| 116082 | 115251 | extraCols = pSrc->colUsed & (~idxCols | MASKBIT(BMS-1)); |
| 116083 | - mxBitCol = MIN(BMS-1,pTable->nCol); | |
| 115252 | + mxBitCol = (pTable->nCol >= BMS-1) ? BMS-1 : pTable->nCol; | |
| 116084 | 115253 | testcase( pTable->nCol==BMS-1 ); |
| 116085 | 115254 | testcase( pTable->nCol==BMS-2 ); |
| 116086 | 115255 | for(i=0; i<mxBitCol; i++){ |
| 116087 | 115256 | if( extraCols & MASKBIT(i) ) nKeyCol++; |
| 116088 | 115257 | } |
| 116089 | 115258 | if( pSrc->colUsed & MASKBIT(BMS-1) ){ |
| 116090 | 115259 | nKeyCol += pTable->nCol - BMS + 1; |
| 116091 | 115260 | } |
| 115261 | + pLoop->wsFlags |= WHERE_COLUMN_EQ | WHERE_IDX_ONLY; | |
| 116092 | 115262 | |
| 116093 | 115263 | /* Construct the Index object to describe this index */ |
| 116094 | 115264 | pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+1, 0, &zNotUsed); |
| 116095 | - if( pIdx==0 ) goto end_auto_index_create; | |
| 115265 | + if( pIdx==0 ) return; | |
| 116096 | 115266 | pLoop->u.btree.pIndex = pIdx; |
| 116097 | 115267 | pIdx->zName = "auto-index"; |
| 116098 | 115268 | pIdx->pTable = pTable; |
| 116099 | 115269 | n = 0; |
| 116100 | 115270 | idxCols = 0; |
| @@ -116142,33 +115312,22 @@ | ||
| 116142 | 115312 | sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1); |
| 116143 | 115313 | sqlite3VdbeSetP4KeyInfo(pParse, pIdx); |
| 116144 | 115314 | VdbeComment((v, "for %s", pTable->zName)); |
| 116145 | 115315 | |
| 116146 | 115316 | /* Fill the automatic index with content */ |
| 116147 | - sqlite3ExprCachePush(pParse); | |
| 116148 | 115317 | addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v); |
| 116149 | - if( pPartial ){ | |
| 116150 | - iContinue = sqlite3VdbeMakeLabel(v); | |
| 116151 | - sqlite3ExprIfFalse(pParse, pPartial, iContinue, SQLITE_JUMPIFNULL); | |
| 116152 | - pLoop->wsFlags |= WHERE_PARTIALIDX; | |
| 116153 | - } | |
| 116154 | 115318 | regRecord = sqlite3GetTempReg(pParse); |
| 116155 | 115319 | sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0); |
| 116156 | 115320 | sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord); |
| 116157 | 115321 | sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); |
| 116158 | - if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue); | |
| 116159 | 115322 | sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v); |
| 116160 | 115323 | sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX); |
| 116161 | 115324 | sqlite3VdbeJumpHere(v, addrTop); |
| 116162 | 115325 | sqlite3ReleaseTempReg(pParse, regRecord); |
| 116163 | - sqlite3ExprCachePop(pParse); | |
| 116164 | 115326 | |
| 116165 | 115327 | /* Jump here when skipping the initialization */ |
| 116166 | 115328 | sqlite3VdbeJumpHere(v, addrInit); |
| 116167 | - | |
| 116168 | -end_auto_index_create: | |
| 116169 | - sqlite3ExprDelete(pParse->db, pPartial); | |
| 116170 | 115329 | } |
| 116171 | 115330 | #endif /* SQLITE_OMIT_AUTOMATIC_INDEX */ |
| 116172 | 115331 | |
| 116173 | 115332 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 116174 | 115333 | /* |
| @@ -116323,23 +115482,23 @@ | ||
| 116323 | 115482 | } |
| 116324 | 115483 | |
| 116325 | 115484 | return pParse->nErr; |
| 116326 | 115485 | } |
| 116327 | 115486 | #endif /* !defined(SQLITE_OMIT_VIRTUALTABLE) */ |
| 115487 | + | |
| 116328 | 115488 | |
| 116329 | 115489 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 116330 | 115490 | /* |
| 116331 | 115491 | ** Estimate the location of a particular key among all keys in an |
| 116332 | 115492 | ** index. Store the results in aStat as follows: |
| 116333 | 115493 | ** |
| 116334 | 115494 | ** aStat[0] Est. number of rows less than pVal |
| 116335 | 115495 | ** aStat[1] Est. number of rows equal to pVal |
| 116336 | 115496 | ** |
| 116337 | -** Return the index of the sample that is the smallest sample that | |
| 116338 | -** is greater than or equal to pRec. | |
| 115497 | +** Return SQLITE_OK on success. | |
| 116339 | 115498 | */ |
| 116340 | -static int whereKeyStats( | |
| 115499 | +static void whereKeyStats( | |
| 116341 | 115500 | Parse *pParse, /* Database connection */ |
| 116342 | 115501 | Index *pIdx, /* Index to consider domain of */ |
| 116343 | 115502 | UnpackedRecord *pRec, /* Vector of values to consider */ |
| 116344 | 115503 | int roundUp, /* Round up if true. Round down if false */ |
| 116345 | 115504 | tRowcnt *aStat /* OUT: stats written here */ |
| @@ -116417,11 +115576,10 @@ | ||
| 116417 | 115576 | }else{ |
| 116418 | 115577 | iGap = iGap/3; |
| 116419 | 115578 | } |
| 116420 | 115579 | aStat[0] = iLower + iGap; |
| 116421 | 115580 | } |
| 116422 | - return i; | |
| 116423 | 115581 | } |
| 116424 | 115582 | #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */ |
| 116425 | 115583 | |
| 116426 | 115584 | /* |
| 116427 | 115585 | ** If it is not NULL, pTerm is a term that provides an upper or lower |
| @@ -116568,11 +115726,11 @@ | ||
| 116568 | 115726 | ** pLower pUpper |
| 116569 | 115727 | ** |
| 116570 | 115728 | ** If either of the upper or lower bound is not present, then NULL is passed in |
| 116571 | 115729 | ** place of the corresponding WhereTerm. |
| 116572 | 115730 | ** |
| 116573 | -** 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 | |
| 116574 | 115732 | ** column subject to the range constraint. Or, equivalently, the number of |
| 116575 | 115733 | ** equality constraints optimized by the proposed index scan. For example, |
| 116576 | 115734 | ** assuming index p is on t1(a, b), and the SQL query is: |
| 116577 | 115735 | ** |
| 116578 | 115736 | ** ... FROM t1 WHERE a = ? AND b > ? AND b < ? ... |
| @@ -116584,11 +115742,11 @@ | ||
| 116584 | 115742 | ** |
| 116585 | 115743 | ** then nEq is set to 0. |
| 116586 | 115744 | ** |
| 116587 | 115745 | ** When this function is called, *pnOut is set to the sqlite3LogEst() of the |
| 116588 | 115746 | ** number of rows that the index scan is expected to visit without |
| 116589 | -** 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 | |
| 116590 | 115748 | ** rows in the index. Assuming no error occurs, *pnOut is adjusted (reduced) |
| 116591 | 115749 | ** to account for the range constraints pLower and pUpper. |
| 116592 | 115750 | ** |
| 116593 | 115751 | ** In the absence of sqlite_stat4 ANALYZE data, or if such data cannot be |
| 116594 | 115752 | ** used, a single range inequality reduces the search space by a factor of 4. |
| @@ -116608,11 +115766,14 @@ | ||
| 116608 | 115766 | |
| 116609 | 115767 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 116610 | 115768 | Index *p = pLoop->u.btree.pIndex; |
| 116611 | 115769 | int nEq = pLoop->u.btree.nEq; |
| 116612 | 115770 | |
| 116613 | - if( p->nSample>0 && nEq<p->nSampleCol ){ | |
| 115771 | + if( p->nSample>0 | |
| 115772 | + && nEq<p->nSampleCol | |
| 115773 | + && OptimizationEnabled(pParse->db, SQLITE_Stat3) | |
| 115774 | + ){ | |
| 116614 | 115775 | if( nEq==pBuilder->nRecValid ){ |
| 116615 | 115776 | UnpackedRecord *pRec = pBuilder->pRec; |
| 116616 | 115777 | tRowcnt a[2]; |
| 116617 | 115778 | u8 aff; |
| 116618 | 115779 | |
| @@ -116624,23 +115785,19 @@ | ||
| 116624 | 115785 | ** |
| 116625 | 115786 | ** Or, if pLower is NULL or $L cannot be extracted from it (because it |
| 116626 | 115787 | ** is not a simple variable or literal value), the lower bound of the |
| 116627 | 115788 | ** range is $P. Due to a quirk in the way whereKeyStats() works, even |
| 116628 | 115789 | ** if $L is available, whereKeyStats() is called for both ($P) and |
| 116629 | - ** ($P:$L) and the larger of the two returned values is used. | |
| 115790 | + ** ($P:$L) and the larger of the two returned values used. | |
| 116630 | 115791 | ** |
| 116631 | 115792 | ** Similarly, iUpper is to be set to the estimate of the number of rows |
| 116632 | 115793 | ** less than the upper bound of the range query. Where the upper bound |
| 116633 | 115794 | ** is either ($P) or ($P:$U). Again, even if $U is available, both values |
| 116634 | 115795 | ** of iUpper are requested of whereKeyStats() and the smaller used. |
| 116635 | - ** | |
| 116636 | - ** The number of rows between the two bounds is then just iUpper-iLower. | |
| 116637 | 115796 | */ |
| 116638 | - tRowcnt iLower; /* Rows less than the lower bound */ | |
| 116639 | - tRowcnt iUpper; /* Rows less than the upper bound */ | |
| 116640 | - int iLwrIdx = -2; /* aSample[] for the lower bound */ | |
| 116641 | - int iUprIdx = -1; /* aSample[] for the upper bound */ | |
| 115797 | + tRowcnt iLower; | |
| 115798 | + tRowcnt iUpper; | |
| 116642 | 115799 | |
| 116643 | 115800 | if( pRec ){ |
| 116644 | 115801 | testcase( pRec->nField!=pBuilder->nRecValid ); |
| 116645 | 115802 | pRec->nField = pBuilder->nRecValid; |
| 116646 | 115803 | } |
| @@ -116650,11 +115807,11 @@ | ||
| 116650 | 115807 | aff = p->pTable->aCol[p->aiColumn[nEq]].affinity; |
| 116651 | 115808 | } |
| 116652 | 115809 | /* Determine iLower and iUpper using ($P) only. */ |
| 116653 | 115810 | if( nEq==0 ){ |
| 116654 | 115811 | iLower = 0; |
| 116655 | - iUpper = p->nRowEst0; | |
| 115812 | + iUpper = sqlite3LogEstToInt(p->aiRowLogEst[0]); | |
| 116656 | 115813 | }else{ |
| 116657 | 115814 | /* Note: this call could be optimized away - since the same values must |
| 116658 | 115815 | ** have been requested when testing key $P in whereEqualScanEst(). */ |
| 116659 | 115816 | whereKeyStats(pParse, p, pRec, 0, a); |
| 116660 | 115817 | iLower = a[0]; |
| @@ -116674,11 +115831,11 @@ | ||
| 116674 | 115831 | int bOk; /* True if value is extracted from pExpr */ |
| 116675 | 115832 | Expr *pExpr = pLower->pExpr->pRight; |
| 116676 | 115833 | rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk); |
| 116677 | 115834 | if( rc==SQLITE_OK && bOk ){ |
| 116678 | 115835 | tRowcnt iNew; |
| 116679 | - iLwrIdx = whereKeyStats(pParse, p, pRec, 0, a); | |
| 115836 | + whereKeyStats(pParse, p, pRec, 0, a); | |
| 116680 | 115837 | iNew = a[0] + ((pLower->eOperator & (WO_GT|WO_LE)) ? a[1] : 0); |
| 116681 | 115838 | if( iNew>iLower ) iLower = iNew; |
| 116682 | 115839 | nOut--; |
| 116683 | 115840 | pLower = 0; |
| 116684 | 115841 | } |
| @@ -116689,11 +115846,11 @@ | ||
| 116689 | 115846 | int bOk; /* True if value is extracted from pExpr */ |
| 116690 | 115847 | Expr *pExpr = pUpper->pExpr->pRight; |
| 116691 | 115848 | rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk); |
| 116692 | 115849 | if( rc==SQLITE_OK && bOk ){ |
| 116693 | 115850 | tRowcnt iNew; |
| 116694 | - iUprIdx = whereKeyStats(pParse, p, pRec, 1, a); | |
| 115851 | + whereKeyStats(pParse, p, pRec, 1, a); | |
| 116695 | 115852 | iNew = a[0] + ((pUpper->eOperator & (WO_GT|WO_LE)) ? a[1] : 0); |
| 116696 | 115853 | if( iNew<iUpper ) iUpper = iNew; |
| 116697 | 115854 | nOut--; |
| 116698 | 115855 | pUpper = 0; |
| 116699 | 115856 | } |
| @@ -116701,15 +115858,10 @@ | ||
| 116701 | 115858 | |
| 116702 | 115859 | pBuilder->pRec = pRec; |
| 116703 | 115860 | if( rc==SQLITE_OK ){ |
| 116704 | 115861 | if( iUpper>iLower ){ |
| 116705 | 115862 | nNew = sqlite3LogEst(iUpper - iLower); |
| 116706 | - /* TUNING: If both iUpper and iLower are derived from the same | |
| 116707 | - ** sample, then assume they are 4x more selective. This brings | |
| 116708 | - ** the estimated selectivity more in line with what it would be | |
| 116709 | - ** if estimated without the use of STAT3/4 tables. */ | |
| 116710 | - if( iLwrIdx==iUprIdx ) nNew -= 20; assert( 20==sqlite3LogEst(4) ); | |
| 116711 | 115863 | }else{ |
| 116712 | 115864 | nNew = 10; assert( 10==sqlite3LogEst(2) ); |
| 116713 | 115865 | } |
| 116714 | 115866 | if( nNew<nOut ){ |
| 116715 | 115867 | nOut = nNew; |
| @@ -116730,19 +115882,16 @@ | ||
| 116730 | 115882 | #endif |
| 116731 | 115883 | assert( pUpper==0 || (pUpper->wtFlags & TERM_VNULL)==0 ); |
| 116732 | 115884 | nNew = whereRangeAdjust(pLower, nOut); |
| 116733 | 115885 | nNew = whereRangeAdjust(pUpper, nNew); |
| 116734 | 115886 | |
| 116735 | - /* TUNING: If there is both an upper and lower limit and neither limit | |
| 116736 | - ** has an application-defined likelihood(), assume the range is | |
| 115887 | + /* TUNING: If there is both an upper and lower limit, assume the range is | |
| 116737 | 115888 | ** reduced by an additional 75%. This means that, by default, an open-ended |
| 116738 | 115889 | ** range query (e.g. col > ?) is assumed to match 1/4 of the rows in the |
| 116739 | 115890 | ** index. While a closed range (e.g. col BETWEEN ? AND ?) is estimated to |
| 116740 | 115891 | ** match 1/64 of the index. */ |
| 116741 | - if( pLower && pLower->truthProb>0 && pUpper && pUpper->truthProb>0 ){ | |
| 116742 | - nNew -= 20; | |
| 116743 | - } | |
| 115892 | + if( pLower && pUpper ) nNew -= 20; | |
| 116744 | 115893 | |
| 116745 | 115894 | nOut -= (pLower!=0) + (pUpper!=0); |
| 116746 | 115895 | if( nNew<10 ) nNew = 10; |
| 116747 | 115896 | if( nNew<nOut ) nOut = nNew; |
| 116748 | 115897 | #if defined(WHERETRACE_ENABLED) |
| @@ -117098,11 +116247,11 @@ | ||
| 117098 | 116247 | |
| 117099 | 116248 | /* This module is only called on query plans that use an index. */ |
| 117100 | 116249 | pLoop = pLevel->pWLoop; |
| 117101 | 116250 | assert( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 ); |
| 117102 | 116251 | nEq = pLoop->u.btree.nEq; |
| 117103 | - nSkip = pLoop->nSkip; | |
| 116252 | + nSkip = pLoop->u.btree.nSkip; | |
| 117104 | 116253 | pIdx = pLoop->u.btree.pIndex; |
| 117105 | 116254 | assert( pIdx!=0 ); |
| 117106 | 116255 | |
| 117107 | 116256 | /* Figure out how many memory cells we will need then allocate them. |
| 117108 | 116257 | */ |
| @@ -117212,11 +116361,11 @@ | ||
| 117212 | 116361 | ** "a=? AND b>?" |
| 117213 | 116362 | */ |
| 117214 | 116363 | static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){ |
| 117215 | 116364 | Index *pIndex = pLoop->u.btree.pIndex; |
| 117216 | 116365 | u16 nEq = pLoop->u.btree.nEq; |
| 117217 | - u16 nSkip = pLoop->nSkip; | |
| 116366 | + u16 nSkip = pLoop->u.btree.nSkip; | |
| 117218 | 116367 | int i, j; |
| 117219 | 116368 | Column *aCol = pTab->aCol; |
| 117220 | 116369 | i16 *aiColumn = pIndex->aiColumn; |
| 117221 | 116370 | |
| 117222 | 116371 | if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return; |
| @@ -117243,27 +116392,23 @@ | ||
| 117243 | 116392 | sqlite3StrAccumAppend(pStr, ")", 1); |
| 117244 | 116393 | } |
| 117245 | 116394 | |
| 117246 | 116395 | /* |
| 117247 | 116396 | ** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN |
| 117248 | -** command, or if either SQLITE_DEBUG or SQLITE_ENABLE_STMT_SCANSTATUS was | |
| 117249 | -** defined at compile-time. If it is not a no-op, a single OP_Explain opcode | |
| 117250 | -** is added to the output to describe the table scan strategy in pLevel. | |
| 117251 | -** | |
| 117252 | -** If an OP_Explain opcode is added to the VM, its address is returned. | |
| 117253 | -** 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. | |
| 117254 | 116400 | */ |
| 117255 | -static int explainOneScan( | |
| 116401 | +static void explainOneScan( | |
| 117256 | 116402 | Parse *pParse, /* Parse context */ |
| 117257 | 116403 | SrcList *pTabList, /* Table list this loop refers to */ |
| 117258 | 116404 | WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */ |
| 117259 | 116405 | int iLevel, /* Value for "level" column of output */ |
| 117260 | 116406 | int iFrom, /* Value for "from" column of output */ |
| 117261 | 116407 | u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */ |
| 117262 | 116408 | ){ |
| 117263 | - int ret = 0; | |
| 117264 | -#if !defined(SQLITE_DEBUG) && !defined(SQLITE_ENABLE_STMT_SCANSTATUS) | |
| 116409 | +#ifndef SQLITE_DEBUG | |
| 117265 | 116410 | if( pParse->explain==2 ) |
| 117266 | 116411 | #endif |
| 117267 | 116412 | { |
| 117268 | 116413 | struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom]; |
| 117269 | 116414 | Vdbe *v = pParse->pVdbe; /* VM being constructed */ |
| @@ -117276,11 +116421,11 @@ | ||
| 117276 | 116421 | StrAccum str; /* EQP output string */ |
| 117277 | 116422 | char zBuf[100]; /* Initial space for EQP output string */ |
| 117278 | 116423 | |
| 117279 | 116424 | pLoop = pLevel->pWLoop; |
| 117280 | 116425 | flags = pLoop->wsFlags; |
| 117281 | - if( (flags&WHERE_MULTI_OR) || (wctrlFlags&WHERE_ONETABLE_ONLY) ) return 0; | |
| 116426 | + if( (flags&WHERE_MULTI_OR) || (wctrlFlags&WHERE_ONETABLE_ONLY) ) return; | |
| 117282 | 116427 | |
| 117283 | 116428 | isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0 |
| 117284 | 116429 | || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0)) |
| 117285 | 116430 | || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX)); |
| 117286 | 116431 | |
| @@ -117305,12 +116450,10 @@ | ||
| 117305 | 116450 | assert( !(flags&WHERE_AUTO_INDEX) || (flags&WHERE_IDX_ONLY) ); |
| 117306 | 116451 | if( !HasRowid(pItem->pTab) && IsPrimaryKeyIndex(pIdx) ){ |
| 117307 | 116452 | if( isSearch ){ |
| 117308 | 116453 | zFmt = "PRIMARY KEY"; |
| 117309 | 116454 | } |
| 117310 | - }else if( flags & WHERE_PARTIALIDX ){ | |
| 117311 | - zFmt = "AUTOMATIC PARTIAL COVERING INDEX"; | |
| 117312 | 116455 | }else if( flags & WHERE_AUTO_INDEX ){ |
| 117313 | 116456 | zFmt = "AUTOMATIC COVERING INDEX"; |
| 117314 | 116457 | }else if( flags & WHERE_IDX_ONLY ){ |
| 117315 | 116458 | zFmt = "COVERING INDEX %s"; |
| 117316 | 116459 | }else{ |
| @@ -117348,49 +116491,16 @@ | ||
| 117348 | 116491 | }else{ |
| 117349 | 116492 | sqlite3StrAccumAppend(&str, " (~1 row)", 9); |
| 117350 | 116493 | } |
| 117351 | 116494 | #endif |
| 117352 | 116495 | zMsg = sqlite3StrAccumFinish(&str); |
| 117353 | - ret = sqlite3VdbeAddOp4(v, OP_Explain, iId, iLevel, iFrom, zMsg,P4_DYNAMIC); | |
| 117354 | - } | |
| 117355 | - return ret; | |
| 117356 | -} | |
| 117357 | -#else | |
| 117358 | -# define explainOneScan(u,v,w,x,y,z) 0 | |
| 117359 | -#endif /* SQLITE_OMIT_EXPLAIN */ | |
| 117360 | - | |
| 117361 | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS | |
| 117362 | -/* | |
| 117363 | -** Configure the VM passed as the first argument with an | |
| 117364 | -** sqlite3_stmt_scanstatus() entry corresponding to the scan used to | |
| 117365 | -** implement level pLvl. Argument pSrclist is a pointer to the FROM | |
| 117366 | -** clause that the scan reads data from. | |
| 117367 | -** | |
| 117368 | -** If argument addrExplain is not 0, it must be the address of an | |
| 117369 | -** OP_Explain instruction that describes the same loop. | |
| 117370 | -*/ | |
| 117371 | -static void addScanStatus( | |
| 117372 | - Vdbe *v, /* Vdbe to add scanstatus entry to */ | |
| 117373 | - SrcList *pSrclist, /* FROM clause pLvl reads data from */ | |
| 117374 | - WhereLevel *pLvl, /* Level to add scanstatus() entry for */ | |
| 117375 | - int addrExplain /* Address of OP_Explain (or 0) */ | |
| 117376 | -){ | |
| 117377 | - const char *zObj = 0; | |
| 117378 | - WhereLoop *pLoop = pLvl->pWLoop; | |
| 117379 | - if( (pLoop->wsFlags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){ | |
| 117380 | - zObj = pLoop->u.btree.pIndex->zName; | |
| 117381 | - }else{ | |
| 117382 | - zObj = pSrclist->a[pLvl->iFrom].zName; | |
| 117383 | - } | |
| 117384 | - sqlite3VdbeScanStatus( | |
| 117385 | - v, addrExplain, pLvl->addrBody, pLvl->addrVisit, pLoop->nOut, zObj | |
| 117386 | - ); | |
| 117387 | -} | |
| 117388 | -#else | |
| 117389 | -# define addScanStatus(a, b, c, d) ((void)d) | |
| 117390 | -#endif | |
| 117391 | - | |
| 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 */ | |
| 117392 | 116502 | |
| 117393 | 116503 | |
| 117394 | 116504 | /* |
| 117395 | 116505 | ** Generate code for the start of the iLevel-th loop in the WHERE clause |
| 117396 | 116506 | ** implementation described by pWInfo. |
| @@ -117688,11 +116798,11 @@ | ||
| 117688 | 116798 | u8 bSeekPastNull = 0; /* True to seek past initial nulls */ |
| 117689 | 116799 | u8 bStopAtNull = 0; /* Add condition to terminate at NULLs */ |
| 117690 | 116800 | |
| 117691 | 116801 | pIdx = pLoop->u.btree.pIndex; |
| 117692 | 116802 | iIdxCur = pLevel->iIdxCur; |
| 117693 | - assert( nEq>=pLoop->nSkip ); | |
| 116803 | + assert( nEq>=pLoop->u.btree.nSkip ); | |
| 117694 | 116804 | |
| 117695 | 116805 | /* If this loop satisfies a sort order (pOrderBy) request that |
| 117696 | 116806 | ** was passed to this function to implement a "SELECT min(x) ..." |
| 117697 | 116807 | ** query, then the caller will only allow the loop to run for |
| 117698 | 116808 | ** a single iteration. This means that the first row returned |
| @@ -117705,11 +116815,11 @@ | ||
| 117705 | 116815 | || (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0 ); |
| 117706 | 116816 | if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0 |
| 117707 | 116817 | && pWInfo->nOBSat>0 |
| 117708 | 116818 | && (pIdx->nKeyCol>nEq) |
| 117709 | 116819 | ){ |
| 117710 | - assert( pLoop->nSkip==0 ); | |
| 116820 | + assert( pLoop->u.btree.nSkip==0 ); | |
| 117711 | 116821 | bSeekPastNull = 1; |
| 117712 | 116822 | nExtraReg = 1; |
| 117713 | 116823 | } |
| 117714 | 116824 | |
| 117715 | 116825 | /* Find any inequality constraint terms for the start and end |
| @@ -118054,15 +117164,13 @@ | ||
| 118054 | 117164 | pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0, |
| 118055 | 117165 | wctrlFlags, iCovCur); |
| 118056 | 117166 | assert( pSubWInfo || pParse->nErr || db->mallocFailed ); |
| 118057 | 117167 | if( pSubWInfo ){ |
| 118058 | 117168 | WhereLoop *pSubLoop; |
| 118059 | - int addrExplain = explainOneScan( | |
| 117169 | + explainOneScan( | |
| 118060 | 117170 | pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0 |
| 118061 | 117171 | ); |
| 118062 | - addScanStatus(v, pOrTab, &pSubWInfo->a[0], addrExplain); | |
| 118063 | - | |
| 118064 | 117172 | /* This is the sub-WHERE clause body. First skip over |
| 118065 | 117173 | ** duplicate rows from prior sub-WHERE clauses, and record the |
| 118066 | 117174 | ** rowid (or PRIMARY KEY) for the current row so that the same |
| 118067 | 117175 | ** row will be skipped in subsequent sub-WHERE clauses. |
| 118068 | 117176 | */ |
| @@ -118189,14 +117297,10 @@ | ||
| 118189 | 117297 | VdbeCoverageIf(v, bRev!=0); |
| 118190 | 117298 | pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP; |
| 118191 | 117299 | } |
| 118192 | 117300 | } |
| 118193 | 117301 | |
| 118194 | -#ifdef SQLITE_ENABLE_STMT_SCANSTATUS | |
| 118195 | - pLevel->addrVisit = sqlite3VdbeCurrentAddr(v); | |
| 118196 | -#endif | |
| 118197 | - | |
| 118198 | 117302 | /* Insert code to test every subexpression that can be completely |
| 118199 | 117303 | ** computed using the current set of tables. |
| 118200 | 117304 | */ |
| 118201 | 117305 | for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){ |
| 118202 | 117306 | Expr *pE; |
| @@ -118332,11 +117436,11 @@ | ||
| 118332 | 117436 | } |
| 118333 | 117437 | sqlite3DebugPrintf(" %-19s", z); |
| 118334 | 117438 | sqlite3_free(z); |
| 118335 | 117439 | } |
| 118336 | 117440 | if( p->wsFlags & WHERE_SKIPSCAN ){ |
| 118337 | - 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); | |
| 118338 | 117442 | }else{ |
| 118339 | 117443 | sqlite3DebugPrintf(" f %05x N %d", p->wsFlags, p->nLTerm); |
| 118340 | 117444 | } |
| 118341 | 117445 | sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut); |
| 118342 | 117446 | if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){ |
| @@ -118443,41 +117547,34 @@ | ||
| 118443 | 117547 | sqlite3DbFree(db, pWInfo); |
| 118444 | 117548 | } |
| 118445 | 117549 | } |
| 118446 | 117550 | |
| 118447 | 117551 | /* |
| 118448 | -** Return TRUE if all of the following are true: | |
| 117552 | +** Return TRUE if both of the following are true: | |
| 118449 | 117553 | ** |
| 118450 | 117554 | ** (1) X has the same or lower cost that Y |
| 118451 | 117555 | ** (2) X is a proper subset of Y |
| 118452 | -** (3) X skips at least as many columns as Y | |
| 118453 | 117556 | ** |
| 118454 | 117557 | ** By "proper subset" we mean that X uses fewer WHERE clause terms |
| 118455 | 117558 | ** than Y and that every WHERE clause term used by X is also used |
| 118456 | 117559 | ** by Y. |
| 118457 | 117560 | ** |
| 118458 | 117561 | ** If X is a proper subset of Y then Y is a better choice and ought |
| 118459 | 117562 | ** to have a lower cost. This routine returns TRUE when that cost |
| 118460 | -** relationship is inverted and needs to be adjusted. The third rule | |
| 118461 | -** was added because if X uses skip-scan less than Y it still might | |
| 118462 | -** deserve a lower cost even if it is a proper subset of Y. | |
| 117563 | +** relationship is inverted and needs to be adjusted. | |
| 118463 | 117564 | */ |
| 118464 | 117565 | static int whereLoopCheaperProperSubset( |
| 118465 | 117566 | const WhereLoop *pX, /* First WhereLoop to compare */ |
| 118466 | 117567 | const WhereLoop *pY /* Compare against this WhereLoop */ |
| 118467 | 117568 | ){ |
| 118468 | 117569 | int i, j; |
| 118469 | - if( pX->nLTerm-pX->nSkip >= pY->nLTerm-pY->nSkip ){ | |
| 118470 | - return 0; /* X is not a subset of Y */ | |
| 118471 | - } | |
| 118472 | - if( pY->nSkip > pX->nSkip ) return 0; | |
| 117570 | + if( pX->nLTerm >= pY->nLTerm ) return 0; /* X is not a subset of Y */ | |
| 118473 | 117571 | if( pX->rRun >= pY->rRun ){ |
| 118474 | 117572 | if( pX->rRun > pY->rRun ) return 0; /* X costs more than Y */ |
| 118475 | 117573 | if( pX->nOut > pY->nOut ) return 0; /* X costs more than Y */ |
| 118476 | 117574 | } |
| 118477 | 117575 | for(i=pX->nLTerm-1; i>=0; i--){ |
| 118478 | - if( pX->aLTerm[i]==0 ) continue; | |
| 118479 | 117576 | for(j=pY->nLTerm-1; j>=0; j--){ |
| 118480 | 117577 | if( pY->aLTerm[j]==pX->aLTerm[i] ) break; |
| 118481 | 117578 | } |
| 118482 | 117579 | if( j<0 ) return 0; /* X not a subset of Y since term X[i] not used by Y */ |
| 118483 | 117580 | } |
| @@ -118495,28 +117592,37 @@ | ||
| 118495 | 117592 | ** is a proper subset. |
| 118496 | 117593 | ** |
| 118497 | 117594 | ** To say "WhereLoop X is a proper subset of Y" means that X uses fewer |
| 118498 | 117595 | ** WHERE clause terms than Y and that every WHERE clause term used by X is |
| 118499 | 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. | |
| 118500 | 117608 | */ |
| 118501 | 117609 | static void whereLoopAdjustCost(const WhereLoop *p, WhereLoop *pTemplate){ |
| 118502 | 117610 | if( (pTemplate->wsFlags & WHERE_INDEXED)==0 ) return; |
| 117611 | + if( (pTemplate->wsFlags & WHERE_SKIPSCAN)!=0 ) return; | |
| 118503 | 117612 | for(; p; p=p->pNextLoop){ |
| 118504 | 117613 | if( p->iTab!=pTemplate->iTab ) continue; |
| 118505 | 117614 | if( (p->wsFlags & WHERE_INDEXED)==0 ) continue; |
| 117615 | + if( (p->wsFlags & WHERE_SKIPSCAN)!=0 ) continue; | |
| 118506 | 117616 | if( whereLoopCheaperProperSubset(p, pTemplate) ){ |
| 118507 | 117617 | /* Adjust pTemplate cost downward so that it is cheaper than its |
| 118508 | - ** subset p. */ | |
| 118509 | - WHERETRACE(0x80,("subset cost adjustment %d,%d to %d,%d\n", | |
| 118510 | - pTemplate->rRun, pTemplate->nOut, p->rRun, p->nOut-1)); | |
| 117618 | + ** subset p */ | |
| 118511 | 117619 | pTemplate->rRun = p->rRun; |
| 118512 | 117620 | pTemplate->nOut = p->nOut - 1; |
| 118513 | 117621 | }else if( whereLoopCheaperProperSubset(pTemplate, p) ){ |
| 118514 | 117622 | /* Adjust pTemplate cost upward so that it is costlier than p since |
| 118515 | 117623 | ** pTemplate is a proper subset of p */ |
| 118516 | - WHERETRACE(0x80,("subset cost adjustment %d,%d to %d,%d\n", | |
| 118517 | - pTemplate->rRun, pTemplate->nOut, p->rRun, p->nOut+1)); | |
| 118518 | 117624 | pTemplate->rRun = p->rRun; |
| 118519 | 117625 | pTemplate->nOut = p->nOut + 1; |
| 118520 | 117626 | } |
| 118521 | 117627 | } |
| 118522 | 117628 | } |
| @@ -118557,13 +117663,12 @@ | ||
| 118557 | 117663 | ** rSetup. Call this SETUP-INVARIANT */ |
| 118558 | 117664 | assert( p->rSetup>=pTemplate->rSetup ); |
| 118559 | 117665 | |
| 118560 | 117666 | /* Any loop using an appliation-defined index (or PRIMARY KEY or |
| 118561 | 117667 | ** UNIQUE constraint) with one or more == constraints is better |
| 118562 | - ** than an automatic index. Unless it is a skip-scan. */ | |
| 117668 | + ** than an automatic index. */ | |
| 118563 | 117669 | if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 |
| 118564 | - && (pTemplate->nSkip)==0 | |
| 118565 | 117670 | && (pTemplate->wsFlags & WHERE_INDEXED)!=0 |
| 118566 | 117671 | && (pTemplate->wsFlags & WHERE_COLUMN_EQ)!=0 |
| 118567 | 117672 | && (p->prereq & pTemplate->prereq)==pTemplate->prereq |
| 118568 | 117673 | ){ |
| 118569 | 117674 | break; |
| @@ -118799,11 +117904,11 @@ | ||
| 118799 | 117904 | int opMask; /* Valid operators for constraints */ |
| 118800 | 117905 | WhereScan scan; /* Iterator for WHERE terms */ |
| 118801 | 117906 | Bitmask saved_prereq; /* Original value of pNew->prereq */ |
| 118802 | 117907 | u16 saved_nLTerm; /* Original value of pNew->nLTerm */ |
| 118803 | 117908 | u16 saved_nEq; /* Original value of pNew->u.btree.nEq */ |
| 118804 | - u16 saved_nSkip; /* Original value of pNew->nSkip */ | |
| 117909 | + u16 saved_nSkip; /* Original value of pNew->u.btree.nSkip */ | |
| 118805 | 117910 | u32 saved_wsFlags; /* Original value of pNew->wsFlags */ |
| 118806 | 117911 | LogEst saved_nOut; /* Original value of pNew->nOut */ |
| 118807 | 117912 | int iCol; /* Index of the column in the table */ |
| 118808 | 117913 | int rc = SQLITE_OK; /* Return code */ |
| 118809 | 117914 | LogEst rSize; /* Number of rows in the table */ |
| @@ -118828,18 +117933,56 @@ | ||
| 118828 | 117933 | iCol = pProbe->aiColumn[pNew->u.btree.nEq]; |
| 118829 | 117934 | |
| 118830 | 117935 | pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, iCol, |
| 118831 | 117936 | opMask, pProbe); |
| 118832 | 117937 | saved_nEq = pNew->u.btree.nEq; |
| 118833 | - saved_nSkip = pNew->nSkip; | |
| 117938 | + saved_nSkip = pNew->u.btree.nSkip; | |
| 118834 | 117939 | saved_nLTerm = pNew->nLTerm; |
| 118835 | 117940 | saved_wsFlags = pNew->wsFlags; |
| 118836 | 117941 | saved_prereq = pNew->prereq; |
| 118837 | 117942 | saved_nOut = pNew->nOut; |
| 118838 | 117943 | pNew->rSetup = 0; |
| 118839 | 117944 | rSize = pProbe->aiRowLogEst[0]; |
| 118840 | 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 | + } | |
| 118841 | 117984 | for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){ |
| 118842 | 117985 | u16 eOp = pTerm->eOperator; /* Shorthand for pTerm->eOperator */ |
| 118843 | 117986 | LogEst rCostIdx; |
| 118844 | 117987 | LogEst nOutUnadjusted; /* nOut before IN() and WHERE adjustments */ |
| 118845 | 117988 | int nIn = 0; |
| @@ -118930,10 +118073,11 @@ | ||
| 118930 | 118073 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 118931 | 118074 | tRowcnt nOut = 0; |
| 118932 | 118075 | if( nInMul==0 |
| 118933 | 118076 | && pProbe->nSample |
| 118934 | 118077 | && pNew->u.btree.nEq<=pProbe->nSampleCol |
| 118078 | + && OptimizationEnabled(db, SQLITE_Stat3) | |
| 118935 | 118079 | && ((eOp & WO_IN)==0 || !ExprHasProperty(pTerm->pExpr, EP_xIsSelect)) |
| 118936 | 118080 | ){ |
| 118937 | 118081 | Expr *pExpr = pTerm->pExpr; |
| 118938 | 118082 | if( (eOp & (WO_EQ|WO_ISNULL))!=0 ){ |
| 118939 | 118083 | testcase( eOp & WO_EQ ); |
| @@ -118997,49 +118141,14 @@ | ||
| 118997 | 118141 | pBuilder->nRecValid = nRecValid; |
| 118998 | 118142 | #endif |
| 118999 | 118143 | } |
| 119000 | 118144 | pNew->prereq = saved_prereq; |
| 119001 | 118145 | pNew->u.btree.nEq = saved_nEq; |
| 119002 | - pNew->nSkip = saved_nSkip; | |
| 118146 | + pNew->u.btree.nSkip = saved_nSkip; | |
| 119003 | 118147 | pNew->wsFlags = saved_wsFlags; |
| 119004 | 118148 | pNew->nOut = saved_nOut; |
| 119005 | 118149 | pNew->nLTerm = saved_nLTerm; |
| 119006 | - | |
| 119007 | - /* Consider using a skip-scan if there are no WHERE clause constraints | |
| 119008 | - ** available for the left-most terms of the index, and if the average | |
| 119009 | - ** number of repeats in the left-most terms is at least 18. | |
| 119010 | - ** | |
| 119011 | - ** The magic number 18 is selected on the basis that scanning 17 rows | |
| 119012 | - ** is almost always quicker than an index seek (even though if the index | |
| 119013 | - ** contains fewer than 2^17 rows we assume otherwise in other parts of | |
| 119014 | - ** the code). And, even if it is not, it should not be too much slower. | |
| 119015 | - ** On the other hand, the extra seeks could end up being significantly | |
| 119016 | - ** more expensive. */ | |
| 119017 | - assert( 42==sqlite3LogEst(18) ); | |
| 119018 | - if( saved_nEq==saved_nSkip | |
| 119019 | - && saved_nEq+1<pProbe->nKeyCol | |
| 119020 | - && pProbe->noSkipScan==0 | |
| 119021 | - && pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */ | |
| 119022 | - && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK | |
| 119023 | - ){ | |
| 119024 | - LogEst nIter; | |
| 119025 | - pNew->u.btree.nEq++; | |
| 119026 | - pNew->nSkip++; | |
| 119027 | - pNew->aLTerm[pNew->nLTerm++] = 0; | |
| 119028 | - pNew->wsFlags |= WHERE_SKIPSCAN; | |
| 119029 | - nIter = pProbe->aiRowLogEst[saved_nEq] - pProbe->aiRowLogEst[saved_nEq+1]; | |
| 119030 | - pNew->nOut -= nIter; | |
| 119031 | - /* TUNING: Because uncertainties in the estimates for skip-scan queries, | |
| 119032 | - ** add a 1.375 fudge factor to make skip-scan slightly less likely. */ | |
| 119033 | - nIter += 5; | |
| 119034 | - whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nIter + nInMul); | |
| 119035 | - pNew->nOut = saved_nOut; | |
| 119036 | - pNew->u.btree.nEq = saved_nEq; | |
| 119037 | - pNew->nSkip = saved_nSkip; | |
| 119038 | - pNew->wsFlags = saved_wsFlags; | |
| 119039 | - } | |
| 119040 | - | |
| 119041 | 118150 | return rc; |
| 119042 | 118151 | } |
| 119043 | 118152 | |
| 119044 | 118153 | /* |
| 119045 | 118154 | ** Return True if it is possible that pIndex might be useful in |
| @@ -119214,11 +118323,11 @@ | ||
| 119214 | 118323 | WhereTerm *pWCEnd = pWC->a + pWC->nTerm; |
| 119215 | 118324 | for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){ |
| 119216 | 118325 | if( pTerm->prereqRight & pNew->maskSelf ) continue; |
| 119217 | 118326 | if( termCanDriveIndex(pTerm, pSrc, 0) ){ |
| 119218 | 118327 | pNew->u.btree.nEq = 1; |
| 119219 | - pNew->nSkip = 0; | |
| 118328 | + pNew->u.btree.nSkip = 0; | |
| 119220 | 118329 | pNew->u.btree.pIndex = 0; |
| 119221 | 118330 | pNew->nLTerm = 1; |
| 119222 | 118331 | pNew->aLTerm[0] = pTerm; |
| 119223 | 118332 | /* TUNING: One-time cost for computing the automatic index is |
| 119224 | 118333 | ** estimated to be X*N*log2(N) where N is the number of rows in |
| @@ -119255,11 +118364,11 @@ | ||
| 119255 | 118364 | testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */ |
| 119256 | 118365 | continue; /* Partial index inappropriate for this query */ |
| 119257 | 118366 | } |
| 119258 | 118367 | rSize = pProbe->aiRowLogEst[0]; |
| 119259 | 118368 | pNew->u.btree.nEq = 0; |
| 119260 | - pNew->nSkip = 0; | |
| 118369 | + pNew->u.btree.nSkip = 0; | |
| 119261 | 118370 | pNew->nLTerm = 0; |
| 119262 | 118371 | pNew->iSortIdx = 0; |
| 119263 | 118372 | pNew->rSetup = 0; |
| 119264 | 118373 | pNew->prereq = mExtra; |
| 119265 | 118374 | pNew->nOut = rSize; |
| @@ -119805,11 +118914,11 @@ | ||
| 119805 | 118914 | for(j=0; j<nColumn; j++){ |
| 119806 | 118915 | u8 bOnce; /* True to run the ORDER BY search loop */ |
| 119807 | 118916 | |
| 119808 | 118917 | /* Skip over == and IS NULL terms */ |
| 119809 | 118918 | if( j<pLoop->u.btree.nEq |
| 119810 | - && pLoop->nSkip==0 | |
| 118919 | + && pLoop->u.btree.nSkip==0 | |
| 119811 | 118920 | && ((i = pLoop->aLTerm[j]->eOperator) & (WO_EQ|WO_ISNULL))!=0 |
| 119812 | 118921 | ){ |
| 119813 | 118922 | if( i & WO_ISNULL ){ |
| 119814 | 118923 | testcase( isOrderDistinct ); |
| 119815 | 118924 | isOrderDistinct = 0; |
| @@ -120259,11 +119368,11 @@ | ||
| 120259 | 119368 | } |
| 120260 | 119369 | } |
| 120261 | 119370 | } |
| 120262 | 119371 | |
| 120263 | 119372 | #ifdef WHERETRACE_ENABLED /* >=2 */ |
| 120264 | - if( sqlite3WhereTrace & 0x02 ){ | |
| 119373 | + if( sqlite3WhereTrace>=2 ){ | |
| 120265 | 119374 | sqlite3DebugPrintf("---- after round %d ----\n", iLoop); |
| 120266 | 119375 | for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){ |
| 120267 | 119376 | sqlite3DebugPrintf(" %s cost=%-3d nrow=%-3d order=%c", |
| 120268 | 119377 | wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow, |
| 120269 | 119378 | pTo->isOrdered>=0 ? (pTo->isOrdered+'0') : '?'); |
| @@ -120378,11 +119487,11 @@ | ||
| 120378 | 119487 | if( pItem->zIndex ) return 0; |
| 120379 | 119488 | iCur = pItem->iCursor; |
| 120380 | 119489 | pWC = &pWInfo->sWC; |
| 120381 | 119490 | pLoop = pBuilder->pNew; |
| 120382 | 119491 | pLoop->wsFlags = 0; |
| 120383 | - pLoop->nSkip = 0; | |
| 119492 | + pLoop->u.btree.nSkip = 0; | |
| 120384 | 119493 | pTerm = findTerm(pWC, iCur, -1, 0, WO_EQ, 0); |
| 120385 | 119494 | if( pTerm ){ |
| 120386 | 119495 | pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_IPK|WHERE_ONEROW; |
| 120387 | 119496 | pLoop->aLTerm[0] = pTerm; |
| 120388 | 119497 | pLoop->nLTerm = 1; |
| @@ -120390,10 +119499,11 @@ | ||
| 120390 | 119499 | /* TUNING: Cost of a rowid lookup is 10 */ |
| 120391 | 119500 | pLoop->rRun = 33; /* 33==sqlite3LogEst(10) */ |
| 120392 | 119501 | }else{ |
| 120393 | 119502 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 120394 | 119503 | assert( pLoop->aLTermSpace==pLoop->aLTerm ); |
| 119504 | + assert( ArraySize(pLoop->aLTermSpace)==4 ); | |
| 120395 | 119505 | if( !IsUniqueIndex(pIdx) |
| 120396 | 119506 | || pIdx->pPartIdxWhere!=0 |
| 120397 | 119507 | || pIdx->nKeyCol>ArraySize(pLoop->aLTermSpace) |
| 120398 | 119508 | ) continue; |
| 120399 | 119509 | for(j=0; j<pIdx->nKeyCol; j++){ |
| @@ -120898,30 +120008,22 @@ | ||
| 120898 | 120008 | ** loop below generates code for a single nested loop of the VM |
| 120899 | 120009 | ** program. |
| 120900 | 120010 | */ |
| 120901 | 120011 | notReady = ~(Bitmask)0; |
| 120902 | 120012 | for(ii=0; ii<nTabList; ii++){ |
| 120903 | - int addrExplain; | |
| 120904 | - int wsFlags; | |
| 120905 | 120013 | pLevel = &pWInfo->a[ii]; |
| 120906 | - wsFlags = pLevel->pWLoop->wsFlags; | |
| 120907 | 120014 | #ifndef SQLITE_OMIT_AUTOMATIC_INDEX |
| 120908 | 120015 | if( (pLevel->pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){ |
| 120909 | 120016 | constructAutomaticIndex(pParse, &pWInfo->sWC, |
| 120910 | 120017 | &pTabList->a[pLevel->iFrom], notReady, pLevel); |
| 120911 | 120018 | if( db->mallocFailed ) goto whereBeginError; |
| 120912 | 120019 | } |
| 120913 | 120020 | #endif |
| 120914 | - addrExplain = explainOneScan( | |
| 120915 | - pParse, pTabList, pLevel, ii, pLevel->iFrom, wctrlFlags | |
| 120916 | - ); | |
| 120021 | + explainOneScan(pParse, pTabList, pLevel, ii, pLevel->iFrom, wctrlFlags); | |
| 120917 | 120022 | pLevel->addrBody = sqlite3VdbeCurrentAddr(v); |
| 120918 | 120023 | notReady = codeOneLoopStart(pWInfo, ii, notReady); |
| 120919 | 120024 | pWInfo->iContinue = pLevel->addrCont; |
| 120920 | - if( (wsFlags&WHERE_MULTI_OR)==0 && (wctrlFlags&WHERE_ONETABLE_ONLY)==0 ){ | |
| 120921 | - addScanStatus(v, pTabList, pLevel, addrExplain); | |
| 120922 | - } | |
| 120923 | 120025 | } |
| 120924 | 120026 | |
| 120925 | 120027 | /* Done. */ |
| 120926 | 120028 | VdbeModuleComment((v, "Begin WHERE-core")); |
| 120927 | 120029 | return pWInfo; |
| @@ -125586,17 +124688,10 @@ | ||
| 125586 | 124688 | */ |
| 125587 | 124689 | SQLITE_API int sqlite3_complete(const char *zSql){ |
| 125588 | 124690 | u8 state = 0; /* Current state, using numbers defined in header comment */ |
| 125589 | 124691 | u8 token; /* Value of the next token */ |
| 125590 | 124692 | |
| 125591 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 125592 | - if( zSql==0 ){ | |
| 125593 | - (void)SQLITE_MISUSE_BKPT; | |
| 125594 | - return 0; | |
| 125595 | - } | |
| 125596 | -#endif | |
| 125597 | - | |
| 125598 | 124693 | #ifndef SQLITE_OMIT_TRIGGER |
| 125599 | 124694 | /* A complex statement machine used to detect the end of a CREATE TRIGGER |
| 125600 | 124695 | ** statement. This is the normal case. |
| 125601 | 124696 | */ |
| 125602 | 124697 | static const u8 trans[8][8] = { |
| @@ -126190,107 +125285,75 @@ | ||
| 126190 | 125285 | |
| 126191 | 125286 | va_start(ap, op); |
| 126192 | 125287 | switch( op ){ |
| 126193 | 125288 | |
| 126194 | 125289 | /* Mutex configuration options are only available in a threadsafe |
| 126195 | - ** compile. | |
| 125290 | + ** compile. | |
| 126196 | 125291 | */ |
| 126197 | -#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-54466-46756 */ | |
| 125292 | +#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 | |
| 126198 | 125293 | case SQLITE_CONFIG_SINGLETHREAD: { |
| 126199 | 125294 | /* Disable all mutexing */ |
| 126200 | 125295 | sqlite3GlobalConfig.bCoreMutex = 0; |
| 126201 | 125296 | sqlite3GlobalConfig.bFullMutex = 0; |
| 126202 | 125297 | break; |
| 126203 | 125298 | } |
| 126204 | -#endif | |
| 126205 | -#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-20520-54086 */ | |
| 126206 | 125299 | case SQLITE_CONFIG_MULTITHREAD: { |
| 126207 | 125300 | /* Disable mutexing of database connections */ |
| 126208 | 125301 | /* Enable mutexing of core data structures */ |
| 126209 | 125302 | sqlite3GlobalConfig.bCoreMutex = 1; |
| 126210 | 125303 | sqlite3GlobalConfig.bFullMutex = 0; |
| 126211 | 125304 | break; |
| 126212 | 125305 | } |
| 126213 | -#endif | |
| 126214 | -#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-59593-21810 */ | |
| 126215 | 125306 | case SQLITE_CONFIG_SERIALIZED: { |
| 126216 | 125307 | /* Enable all mutexing */ |
| 126217 | 125308 | sqlite3GlobalConfig.bCoreMutex = 1; |
| 126218 | 125309 | sqlite3GlobalConfig.bFullMutex = 1; |
| 126219 | 125310 | break; |
| 126220 | 125311 | } |
| 126221 | -#endif | |
| 126222 | -#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-63666-48755 */ | |
| 126223 | 125312 | case SQLITE_CONFIG_MUTEX: { |
| 126224 | 125313 | /* Specify an alternative mutex implementation */ |
| 126225 | 125314 | sqlite3GlobalConfig.mutex = *va_arg(ap, sqlite3_mutex_methods*); |
| 126226 | 125315 | break; |
| 126227 | 125316 | } |
| 126228 | -#endif | |
| 126229 | -#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-14450-37597 */ | |
| 126230 | 125317 | case SQLITE_CONFIG_GETMUTEX: { |
| 126231 | 125318 | /* Retrieve the current mutex implementation */ |
| 126232 | 125319 | *va_arg(ap, sqlite3_mutex_methods*) = sqlite3GlobalConfig.mutex; |
| 126233 | 125320 | break; |
| 126234 | 125321 | } |
| 126235 | 125322 | #endif |
| 125323 | + | |
| 126236 | 125324 | |
| 126237 | 125325 | case SQLITE_CONFIG_MALLOC: { |
| 126238 | - /* EVIDENCE-OF: R-55594-21030 The SQLITE_CONFIG_MALLOC option takes a | |
| 126239 | - ** single argument which is a pointer to an instance of the | |
| 126240 | - ** sqlite3_mem_methods structure. The argument specifies alternative | |
| 126241 | - ** low-level memory allocation routines to be used in place of the memory | |
| 126242 | - ** allocation routines built into SQLite. */ | |
| 125326 | + /* Specify an alternative malloc implementation */ | |
| 126243 | 125327 | sqlite3GlobalConfig.m = *va_arg(ap, sqlite3_mem_methods*); |
| 126244 | 125328 | break; |
| 126245 | 125329 | } |
| 126246 | 125330 | case SQLITE_CONFIG_GETMALLOC: { |
| 126247 | - /* EVIDENCE-OF: R-51213-46414 The SQLITE_CONFIG_GETMALLOC option takes a | |
| 126248 | - ** single argument which is a pointer to an instance of the | |
| 126249 | - ** sqlite3_mem_methods structure. The sqlite3_mem_methods structure is | |
| 126250 | - ** filled with the currently defined memory allocation routines. */ | |
| 125331 | + /* Retrieve the current malloc() implementation */ | |
| 126251 | 125332 | if( sqlite3GlobalConfig.m.xMalloc==0 ) sqlite3MemSetDefault(); |
| 126252 | 125333 | *va_arg(ap, sqlite3_mem_methods*) = sqlite3GlobalConfig.m; |
| 126253 | 125334 | break; |
| 126254 | 125335 | } |
| 126255 | 125336 | case SQLITE_CONFIG_MEMSTATUS: { |
| 126256 | - /* EVIDENCE-OF: R-61275-35157 The SQLITE_CONFIG_MEMSTATUS option takes | |
| 126257 | - ** single argument of type int, interpreted as a boolean, which enables | |
| 126258 | - ** or disables the collection of memory allocation statistics. */ | |
| 125337 | + /* Enable or disable the malloc status collection */ | |
| 126259 | 125338 | sqlite3GlobalConfig.bMemstat = va_arg(ap, int); |
| 126260 | 125339 | break; |
| 126261 | 125340 | } |
| 126262 | 125341 | case SQLITE_CONFIG_SCRATCH: { |
| 126263 | - /* EVIDENCE-OF: R-08404-60887 There are three arguments to | |
| 126264 | - ** SQLITE_CONFIG_SCRATCH: A pointer an 8-byte aligned memory buffer from | |
| 126265 | - ** which the scratch allocations will be drawn, the size of each scratch | |
| 126266 | - ** allocation (sz), and the maximum number of scratch allocations (N). */ | |
| 125342 | + /* Designate a buffer for scratch memory space */ | |
| 126267 | 125343 | sqlite3GlobalConfig.pScratch = va_arg(ap, void*); |
| 126268 | 125344 | sqlite3GlobalConfig.szScratch = va_arg(ap, int); |
| 126269 | 125345 | sqlite3GlobalConfig.nScratch = va_arg(ap, int); |
| 126270 | 125346 | break; |
| 126271 | 125347 | } |
| 126272 | 125348 | case SQLITE_CONFIG_PAGECACHE: { |
| 126273 | - /* EVIDENCE-OF: R-31408-40510 There are three arguments to | |
| 126274 | - ** SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned memory, the size | |
| 126275 | - ** of each page buffer (sz), and the number of pages (N). */ | |
| 125349 | + /* Designate a buffer for page cache memory space */ | |
| 126276 | 125350 | sqlite3GlobalConfig.pPage = va_arg(ap, void*); |
| 126277 | 125351 | sqlite3GlobalConfig.szPage = va_arg(ap, int); |
| 126278 | 125352 | sqlite3GlobalConfig.nPage = va_arg(ap, int); |
| 126279 | 125353 | break; |
| 126280 | 125354 | } |
| 126281 | - case SQLITE_CONFIG_PCACHE_HDRSZ: { | |
| 126282 | - /* EVIDENCE-OF: R-39100-27317 The SQLITE_CONFIG_PCACHE_HDRSZ option takes | |
| 126283 | - ** a single parameter which is a pointer to an integer and writes into | |
| 126284 | - ** that integer the number of extra bytes per page required for each page | |
| 126285 | - ** in SQLITE_CONFIG_PAGECACHE. */ | |
| 126286 | - *va_arg(ap, int*) = | |
| 126287 | - sqlite3HeaderSizeBtree() + | |
| 126288 | - sqlite3HeaderSizePcache() + | |
| 126289 | - sqlite3HeaderSizePcache1(); | |
| 126290 | - break; | |
| 126291 | - } | |
| 126292 | 125355 | |
| 126293 | 125356 | case SQLITE_CONFIG_PCACHE: { |
| 126294 | 125357 | /* no-op */ |
| 126295 | 125358 | break; |
| 126296 | 125359 | } |
| @@ -126299,37 +125362,25 @@ | ||
| 126299 | 125362 | rc = SQLITE_ERROR; |
| 126300 | 125363 | break; |
| 126301 | 125364 | } |
| 126302 | 125365 | |
| 126303 | 125366 | case SQLITE_CONFIG_PCACHE2: { |
| 126304 | - /* EVIDENCE-OF: R-63325-48378 The SQLITE_CONFIG_PCACHE2 option takes a | |
| 126305 | - ** single argument which is a pointer to an sqlite3_pcache_methods2 | |
| 126306 | - ** object. This object specifies the interface to a custom page cache | |
| 126307 | - ** implementation. */ | |
| 125367 | + /* Specify an alternative page cache implementation */ | |
| 126308 | 125368 | sqlite3GlobalConfig.pcache2 = *va_arg(ap, sqlite3_pcache_methods2*); |
| 126309 | 125369 | break; |
| 126310 | 125370 | } |
| 126311 | 125371 | case SQLITE_CONFIG_GETPCACHE2: { |
| 126312 | - /* EVIDENCE-OF: R-22035-46182 The SQLITE_CONFIG_GETPCACHE2 option takes a | |
| 126313 | - ** single argument which is a pointer to an sqlite3_pcache_methods2 | |
| 126314 | - ** object. SQLite copies of the current page cache implementation into | |
| 126315 | - ** that object. */ | |
| 126316 | 125372 | if( sqlite3GlobalConfig.pcache2.xInit==0 ){ |
| 126317 | 125373 | sqlite3PCacheSetDefault(); |
| 126318 | 125374 | } |
| 126319 | 125375 | *va_arg(ap, sqlite3_pcache_methods2*) = sqlite3GlobalConfig.pcache2; |
| 126320 | 125376 | break; |
| 126321 | 125377 | } |
| 126322 | 125378 | |
| 126323 | -/* EVIDENCE-OF: R-06626-12911 The SQLITE_CONFIG_HEAP option is only | |
| 126324 | -** available if SQLite is compiled with either SQLITE_ENABLE_MEMSYS3 or | |
| 126325 | -** SQLITE_ENABLE_MEMSYS5 and returns SQLITE_ERROR if invoked otherwise. */ | |
| 126326 | 125379 | #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5) |
| 126327 | 125380 | case SQLITE_CONFIG_HEAP: { |
| 126328 | - /* EVIDENCE-OF: R-19854-42126 There are three arguments to | |
| 126329 | - ** SQLITE_CONFIG_HEAP: An 8-byte aligned pointer to the memory, the | |
| 126330 | - ** number of bytes in the memory buffer, and the minimum allocation size. */ | |
| 125381 | + /* Designate a buffer for heap memory space */ | |
| 126331 | 125382 | sqlite3GlobalConfig.pHeap = va_arg(ap, void*); |
| 126332 | 125383 | sqlite3GlobalConfig.nHeap = va_arg(ap, int); |
| 126333 | 125384 | sqlite3GlobalConfig.mnReq = va_arg(ap, int); |
| 126334 | 125385 | |
| 126335 | 125386 | if( sqlite3GlobalConfig.mnReq<1 ){ |
| @@ -126338,23 +125389,21 @@ | ||
| 126338 | 125389 | /* cap min request size at 2^12 */ |
| 126339 | 125390 | sqlite3GlobalConfig.mnReq = (1<<12); |
| 126340 | 125391 | } |
| 126341 | 125392 | |
| 126342 | 125393 | if( sqlite3GlobalConfig.pHeap==0 ){ |
| 126343 | - /* EVIDENCE-OF: R-49920-60189 If the first pointer (the memory pointer) | |
| 126344 | - ** is NULL, then SQLite reverts to using its default memory allocator | |
| 126345 | - ** (the system malloc() implementation), undoing any prior invocation of | |
| 126346 | - ** SQLITE_CONFIG_MALLOC. | |
| 126347 | - ** | |
| 126348 | - ** Setting sqlite3GlobalConfig.m to all zeros will cause malloc to | |
| 126349 | - ** 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. | |
| 126350 | 125398 | */ |
| 126351 | 125399 | memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m)); |
| 126352 | 125400 | }else{ |
| 126353 | - /* EVIDENCE-OF: R-61006-08918 If the memory pointer is not NULL then the | |
| 126354 | - ** alternative memory allocator is engaged to handle all of SQLites | |
| 126355 | - ** 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 | + */ | |
| 126356 | 125405 | #ifdef SQLITE_ENABLE_MEMSYS3 |
| 126357 | 125406 | sqlite3GlobalConfig.m = *sqlite3MemGetMemsys3(); |
| 126358 | 125407 | #endif |
| 126359 | 125408 | #ifdef SQLITE_ENABLE_MEMSYS5 |
| 126360 | 125409 | sqlite3GlobalConfig.m = *sqlite3MemGetMemsys5(); |
| @@ -126389,23 +125438,15 @@ | ||
| 126389 | 125438 | ** can be changed at start-time using the |
| 126390 | 125439 | ** sqlite3_config(SQLITE_CONFIG_URI,1) or |
| 126391 | 125440 | ** sqlite3_config(SQLITE_CONFIG_URI,0) configuration calls. |
| 126392 | 125441 | */ |
| 126393 | 125442 | case SQLITE_CONFIG_URI: { |
| 126394 | - /* EVIDENCE-OF: R-25451-61125 The SQLITE_CONFIG_URI option takes a single | |
| 126395 | - ** argument of type int. If non-zero, then URI handling is globally | |
| 126396 | - ** enabled. If the parameter is zero, then URI handling is globally | |
| 126397 | - ** disabled. */ | |
| 126398 | 125443 | sqlite3GlobalConfig.bOpenUri = va_arg(ap, int); |
| 126399 | 125444 | break; |
| 126400 | 125445 | } |
| 126401 | 125446 | |
| 126402 | 125447 | case SQLITE_CONFIG_COVERING_INDEX_SCAN: { |
| 126403 | - /* EVIDENCE-OF: R-36592-02772 The SQLITE_CONFIG_COVERING_INDEX_SCAN | |
| 126404 | - ** option takes a single integer argument which is interpreted as a | |
| 126405 | - ** boolean in order to enable or disable the use of covering indices for | |
| 126406 | - ** full table scans in the query optimizer. */ | |
| 126407 | 125448 | sqlite3GlobalConfig.bUseCis = va_arg(ap, int); |
| 126408 | 125449 | break; |
| 126409 | 125450 | } |
| 126410 | 125451 | |
| 126411 | 125452 | #ifdef SQLITE_ENABLE_SQLLOG |
| @@ -126416,37 +125457,24 @@ | ||
| 126416 | 125457 | break; |
| 126417 | 125458 | } |
| 126418 | 125459 | #endif |
| 126419 | 125460 | |
| 126420 | 125461 | case SQLITE_CONFIG_MMAP_SIZE: { |
| 126421 | - /* EVIDENCE-OF: R-58063-38258 SQLITE_CONFIG_MMAP_SIZE takes two 64-bit | |
| 126422 | - ** integer (sqlite3_int64) values that are the default mmap size limit | |
| 126423 | - ** (the default setting for PRAGMA mmap_size) and the maximum allowed | |
| 126424 | - ** mmap size limit. */ | |
| 126425 | 125462 | sqlite3_int64 szMmap = va_arg(ap, sqlite3_int64); |
| 126426 | 125463 | sqlite3_int64 mxMmap = va_arg(ap, sqlite3_int64); |
| 126427 | - /* EVIDENCE-OF: R-53367-43190 If either argument to this option is | |
| 126428 | - ** negative, then that argument is changed to its compile-time default. | |
| 126429 | - ** | |
| 126430 | - ** EVIDENCE-OF: R-34993-45031 The maximum allowed mmap size will be | |
| 126431 | - ** silently truncated if necessary so that it does not exceed the | |
| 126432 | - ** compile-time maximum mmap size set by the SQLITE_MAX_MMAP_SIZE | |
| 126433 | - ** compile-time option. | |
| 126434 | - */ | |
| 126435 | - 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; | |
| 126436 | 125468 | if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE; |
| 126437 | 125469 | if( szMmap>mxMmap) szMmap = mxMmap; |
| 126438 | - sqlite3GlobalConfig.mxMmap = mxMmap; | |
| 126439 | 125470 | sqlite3GlobalConfig.szMmap = szMmap; |
| 126440 | 125471 | break; |
| 126441 | 125472 | } |
| 126442 | 125473 | |
| 126443 | -#if SQLITE_OS_WIN && defined(SQLITE_WIN32_MALLOC) /* IMP: R-04780-55815 */ | |
| 125474 | +#if SQLITE_OS_WIN && defined(SQLITE_WIN32_MALLOC) | |
| 126444 | 125475 | case SQLITE_CONFIG_WIN32_HEAPSIZE: { |
| 126445 | - /* EVIDENCE-OF: R-34926-03360 SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit | |
| 126446 | - ** unsigned integer value that specifies the maximum size of the created | |
| 126447 | - ** heap. */ | |
| 126448 | 125476 | sqlite3GlobalConfig.nHeap = va_arg(ap, int); |
| 126449 | 125477 | break; |
| 126450 | 125478 | } |
| 126451 | 125479 | #endif |
| 126452 | 125480 | |
| @@ -126526,29 +125554,19 @@ | ||
| 126526 | 125554 | |
| 126527 | 125555 | /* |
| 126528 | 125556 | ** Return the mutex associated with a database connection. |
| 126529 | 125557 | */ |
| 126530 | 125558 | SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){ |
| 126531 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 126532 | - if( !sqlite3SafetyCheckOk(db) ){ | |
| 126533 | - (void)SQLITE_MISUSE_BKPT; | |
| 126534 | - return 0; | |
| 126535 | - } | |
| 126536 | -#endif | |
| 126537 | 125559 | return db->mutex; |
| 126538 | 125560 | } |
| 126539 | 125561 | |
| 126540 | 125562 | /* |
| 126541 | 125563 | ** Free up as much memory as we can from the given database |
| 126542 | 125564 | ** connection. |
| 126543 | 125565 | */ |
| 126544 | 125566 | SQLITE_API int sqlite3_db_release_memory(sqlite3 *db){ |
| 126545 | 125567 | int i; |
| 126546 | - | |
| 126547 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 126548 | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; | |
| 126549 | -#endif | |
| 126550 | 125568 | sqlite3_mutex_enter(db->mutex); |
| 126551 | 125569 | sqlite3BtreeEnterAll(db); |
| 126552 | 125570 | for(i=0; i<db->nDb; i++){ |
| 126553 | 125571 | Btree *pBt = db->aDb[i].pBt; |
| 126554 | 125572 | if( pBt ){ |
| @@ -126675,42 +125693,24 @@ | ||
| 126675 | 125693 | |
| 126676 | 125694 | /* |
| 126677 | 125695 | ** Return the ROWID of the most recent insert |
| 126678 | 125696 | */ |
| 126679 | 125697 | SQLITE_API sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){ |
| 126680 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 126681 | - if( !sqlite3SafetyCheckOk(db) ){ | |
| 126682 | - (void)SQLITE_MISUSE_BKPT; | |
| 126683 | - return 0; | |
| 126684 | - } | |
| 126685 | -#endif | |
| 126686 | 125698 | return db->lastRowid; |
| 126687 | 125699 | } |
| 126688 | 125700 | |
| 126689 | 125701 | /* |
| 126690 | 125702 | ** Return the number of changes in the most recent call to sqlite3_exec(). |
| 126691 | 125703 | */ |
| 126692 | 125704 | SQLITE_API int sqlite3_changes(sqlite3 *db){ |
| 126693 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 126694 | - if( !sqlite3SafetyCheckOk(db) ){ | |
| 126695 | - (void)SQLITE_MISUSE_BKPT; | |
| 126696 | - return 0; | |
| 126697 | - } | |
| 126698 | -#endif | |
| 126699 | 125705 | return db->nChange; |
| 126700 | 125706 | } |
| 126701 | 125707 | |
| 126702 | 125708 | /* |
| 126703 | 125709 | ** Return the number of changes since the database handle was opened. |
| 126704 | 125710 | */ |
| 126705 | 125711 | SQLITE_API int sqlite3_total_changes(sqlite3 *db){ |
| 126706 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 126707 | - if( !sqlite3SafetyCheckOk(db) ){ | |
| 126708 | - (void)SQLITE_MISUSE_BKPT; | |
| 126709 | - return 0; | |
| 126710 | - } | |
| 126711 | -#endif | |
| 126712 | 125712 | return db->nTotalChange; |
| 126713 | 125713 | } |
| 126714 | 125714 | |
| 126715 | 125715 | /* |
| 126716 | 125716 | ** Close all open savepoints. This function only manipulates fields of the |
| @@ -127255,13 +126255,10 @@ | ||
| 127255 | 126255 | SQLITE_API int sqlite3_busy_handler( |
| 127256 | 126256 | sqlite3 *db, |
| 127257 | 126257 | int (*xBusy)(void*,int), |
| 127258 | 126258 | void *pArg |
| 127259 | 126259 | ){ |
| 127260 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 127261 | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE; | |
| 127262 | -#endif | |
| 127263 | 126260 | sqlite3_mutex_enter(db->mutex); |
| 127264 | 126261 | db->busyHandler.xFunc = xBusy; |
| 127265 | 126262 | db->busyHandler.pArg = pArg; |
| 127266 | 126263 | db->busyHandler.nBusy = 0; |
| 127267 | 126264 | db->busyTimeout = 0; |
| @@ -127279,16 +126276,10 @@ | ||
| 127279 | 126276 | sqlite3 *db, |
| 127280 | 126277 | int nOps, |
| 127281 | 126278 | int (*xProgress)(void*), |
| 127282 | 126279 | void *pArg |
| 127283 | 126280 | ){ |
| 127284 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 127285 | - if( !sqlite3SafetyCheckOk(db) ){ | |
| 127286 | - (void)SQLITE_MISUSE_BKPT; | |
| 127287 | - return; | |
| 127288 | - } | |
| 127289 | -#endif | |
| 127290 | 126281 | sqlite3_mutex_enter(db->mutex); |
| 127291 | 126282 | if( nOps>0 ){ |
| 127292 | 126283 | db->xProgress = xProgress; |
| 127293 | 126284 | db->nProgressOps = (unsigned)nOps; |
| 127294 | 126285 | db->pProgressArg = pArg; |
| @@ -127305,13 +126296,10 @@ | ||
| 127305 | 126296 | /* |
| 127306 | 126297 | ** This routine installs a default busy handler that waits for the |
| 127307 | 126298 | ** specified number of milliseconds before returning 0. |
| 127308 | 126299 | */ |
| 127309 | 126300 | SQLITE_API int sqlite3_busy_timeout(sqlite3 *db, int ms){ |
| 127310 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 127311 | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; | |
| 127312 | -#endif | |
| 127313 | 126301 | if( ms>0 ){ |
| 127314 | 126302 | sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db); |
| 127315 | 126303 | db->busyTimeout = ms; |
| 127316 | 126304 | }else{ |
| 127317 | 126305 | sqlite3_busy_handler(db, 0, 0); |
| @@ -127321,16 +126309,10 @@ | ||
| 127321 | 126309 | |
| 127322 | 126310 | /* |
| 127323 | 126311 | ** Cause any pending operation to stop at its earliest opportunity. |
| 127324 | 126312 | */ |
| 127325 | 126313 | SQLITE_API void sqlite3_interrupt(sqlite3 *db){ |
| 127326 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 127327 | - if( !sqlite3SafetyCheckOk(db) ){ | |
| 127328 | - (void)SQLITE_MISUSE_BKPT; | |
| 127329 | - return; | |
| 127330 | - } | |
| 127331 | -#endif | |
| 127332 | 126314 | db->u1.isInterrupted = 1; |
| 127333 | 126315 | } |
| 127334 | 126316 | |
| 127335 | 126317 | |
| 127336 | 126318 | /* |
| @@ -127464,16 +126446,10 @@ | ||
| 127464 | 126446 | void (*xFinal)(sqlite3_context*), |
| 127465 | 126447 | void (*xDestroy)(void *) |
| 127466 | 126448 | ){ |
| 127467 | 126449 | int rc = SQLITE_ERROR; |
| 127468 | 126450 | FuncDestructor *pArg = 0; |
| 127469 | - | |
| 127470 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 127471 | - if( !sqlite3SafetyCheckOk(db) ){ | |
| 127472 | - return SQLITE_MISUSE_BKPT; | |
| 127473 | - } | |
| 127474 | -#endif | |
| 127475 | 126451 | sqlite3_mutex_enter(db->mutex); |
| 127476 | 126452 | if( xDestroy ){ |
| 127477 | 126453 | pArg = (FuncDestructor *)sqlite3DbMallocZero(db, sizeof(FuncDestructor)); |
| 127478 | 126454 | if( !pArg ){ |
| 127479 | 126455 | xDestroy(p); |
| @@ -127506,14 +126482,10 @@ | ||
| 127506 | 126482 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
| 127507 | 126483 | void (*xFinal)(sqlite3_context*) |
| 127508 | 126484 | ){ |
| 127509 | 126485 | int rc; |
| 127510 | 126486 | char *zFunc8; |
| 127511 | - | |
| 127512 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 127513 | - if( !sqlite3SafetyCheckOk(db) || zFunctionName==0 ) return SQLITE_MISUSE_BKPT; | |
| 127514 | -#endif | |
| 127515 | 126487 | sqlite3_mutex_enter(db->mutex); |
| 127516 | 126488 | assert( !db->mallocFailed ); |
| 127517 | 126489 | zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE); |
| 127518 | 126490 | rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal,0); |
| 127519 | 126491 | sqlite3DbFree(db, zFunc8); |
| @@ -127541,16 +126513,10 @@ | ||
| 127541 | 126513 | const char *zName, |
| 127542 | 126514 | int nArg |
| 127543 | 126515 | ){ |
| 127544 | 126516 | int nName = sqlite3Strlen30(zName); |
| 127545 | 126517 | int rc = SQLITE_OK; |
| 127546 | - | |
| 127547 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 127548 | - if( !sqlite3SafetyCheckOk(db) || zName==0 || nArg<-2 ){ | |
| 127549 | - return SQLITE_MISUSE_BKPT; | |
| 127550 | - } | |
| 127551 | -#endif | |
| 127552 | 126518 | sqlite3_mutex_enter(db->mutex); |
| 127553 | 126519 | if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){ |
| 127554 | 126520 | rc = sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8, |
| 127555 | 126521 | 0, sqlite3InvalidFunction, 0, 0, 0); |
| 127556 | 126522 | } |
| @@ -127568,17 +126534,10 @@ | ||
| 127568 | 126534 | ** trace is a pointer to a function that is invoked at the start of each |
| 127569 | 126535 | ** SQL statement. |
| 127570 | 126536 | */ |
| 127571 | 126537 | SQLITE_API void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){ |
| 127572 | 126538 | void *pOld; |
| 127573 | - | |
| 127574 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 127575 | - if( !sqlite3SafetyCheckOk(db) ){ | |
| 127576 | - (void)SQLITE_MISUSE_BKPT; | |
| 127577 | - return 0; | |
| 127578 | - } | |
| 127579 | -#endif | |
| 127580 | 126539 | sqlite3_mutex_enter(db->mutex); |
| 127581 | 126540 | pOld = db->pTraceArg; |
| 127582 | 126541 | db->xTrace = xTrace; |
| 127583 | 126542 | db->pTraceArg = pArg; |
| 127584 | 126543 | sqlite3_mutex_leave(db->mutex); |
| @@ -127596,17 +126555,10 @@ | ||
| 127596 | 126555 | sqlite3 *db, |
| 127597 | 126556 | void (*xProfile)(void*,const char*,sqlite_uint64), |
| 127598 | 126557 | void *pArg |
| 127599 | 126558 | ){ |
| 127600 | 126559 | void *pOld; |
| 127601 | - | |
| 127602 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 127603 | - if( !sqlite3SafetyCheckOk(db) ){ | |
| 127604 | - (void)SQLITE_MISUSE_BKPT; | |
| 127605 | - return 0; | |
| 127606 | - } | |
| 127607 | -#endif | |
| 127608 | 126560 | sqlite3_mutex_enter(db->mutex); |
| 127609 | 126561 | pOld = db->pProfileArg; |
| 127610 | 126562 | db->xProfile = xProfile; |
| 127611 | 126563 | db->pProfileArg = pArg; |
| 127612 | 126564 | sqlite3_mutex_leave(db->mutex); |
| @@ -127623,17 +126575,10 @@ | ||
| 127623 | 126575 | sqlite3 *db, /* Attach the hook to this database */ |
| 127624 | 126576 | int (*xCallback)(void*), /* Function to invoke on each commit */ |
| 127625 | 126577 | void *pArg /* Argument to the function */ |
| 127626 | 126578 | ){ |
| 127627 | 126579 | void *pOld; |
| 127628 | - | |
| 127629 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 127630 | - if( !sqlite3SafetyCheckOk(db) ){ | |
| 127631 | - (void)SQLITE_MISUSE_BKPT; | |
| 127632 | - return 0; | |
| 127633 | - } | |
| 127634 | -#endif | |
| 127635 | 126580 | sqlite3_mutex_enter(db->mutex); |
| 127636 | 126581 | pOld = db->pCommitArg; |
| 127637 | 126582 | db->xCommitCallback = xCallback; |
| 127638 | 126583 | db->pCommitArg = pArg; |
| 127639 | 126584 | sqlite3_mutex_leave(db->mutex); |
| @@ -127648,17 +126593,10 @@ | ||
| 127648 | 126593 | sqlite3 *db, /* Attach the hook to this database */ |
| 127649 | 126594 | void (*xCallback)(void*,int,char const *,char const *,sqlite_int64), |
| 127650 | 126595 | void *pArg /* Argument to the function */ |
| 127651 | 126596 | ){ |
| 127652 | 126597 | void *pRet; |
| 127653 | - | |
| 127654 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 127655 | - if( !sqlite3SafetyCheckOk(db) ){ | |
| 127656 | - (void)SQLITE_MISUSE_BKPT; | |
| 127657 | - return 0; | |
| 127658 | - } | |
| 127659 | -#endif | |
| 127660 | 126598 | sqlite3_mutex_enter(db->mutex); |
| 127661 | 126599 | pRet = db->pUpdateArg; |
| 127662 | 126600 | db->xUpdateCallback = xCallback; |
| 127663 | 126601 | db->pUpdateArg = pArg; |
| 127664 | 126602 | sqlite3_mutex_leave(db->mutex); |
| @@ -127673,17 +126611,10 @@ | ||
| 127673 | 126611 | sqlite3 *db, /* Attach the hook to this database */ |
| 127674 | 126612 | void (*xCallback)(void*), /* Callback function */ |
| 127675 | 126613 | void *pArg /* Argument to the function */ |
| 127676 | 126614 | ){ |
| 127677 | 126615 | void *pRet; |
| 127678 | - | |
| 127679 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 127680 | - if( !sqlite3SafetyCheckOk(db) ){ | |
| 127681 | - (void)SQLITE_MISUSE_BKPT; | |
| 127682 | - return 0; | |
| 127683 | - } | |
| 127684 | -#endif | |
| 127685 | 126616 | sqlite3_mutex_enter(db->mutex); |
| 127686 | 126617 | pRet = db->pRollbackArg; |
| 127687 | 126618 | db->xRollbackCallback = xCallback; |
| 127688 | 126619 | db->pRollbackArg = pArg; |
| 127689 | 126620 | sqlite3_mutex_leave(db->mutex); |
| @@ -127726,13 +126657,10 @@ | ||
| 127726 | 126657 | SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){ |
| 127727 | 126658 | #ifdef SQLITE_OMIT_WAL |
| 127728 | 126659 | UNUSED_PARAMETER(db); |
| 127729 | 126660 | UNUSED_PARAMETER(nFrame); |
| 127730 | 126661 | #else |
| 127731 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 127732 | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; | |
| 127733 | -#endif | |
| 127734 | 126662 | if( nFrame>0 ){ |
| 127735 | 126663 | sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame)); |
| 127736 | 126664 | }else{ |
| 127737 | 126665 | sqlite3_wal_hook(db, 0, 0); |
| 127738 | 126666 | } |
| @@ -127749,16 +126677,10 @@ | ||
| 127749 | 126677 | int(*xCallback)(void *, sqlite3*, const char*, int), |
| 127750 | 126678 | void *pArg /* First argument passed to xCallback() */ |
| 127751 | 126679 | ){ |
| 127752 | 126680 | #ifndef SQLITE_OMIT_WAL |
| 127753 | 126681 | void *pRet; |
| 127754 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 127755 | - if( !sqlite3SafetyCheckOk(db) ){ | |
| 127756 | - (void)SQLITE_MISUSE_BKPT; | |
| 127757 | - return 0; | |
| 127758 | - } | |
| 127759 | -#endif | |
| 127760 | 126682 | sqlite3_mutex_enter(db->mutex); |
| 127761 | 126683 | pRet = db->pWalArg; |
| 127762 | 126684 | db->xWalCallback = xCallback; |
| 127763 | 126685 | db->pWalArg = pArg; |
| 127764 | 126686 | sqlite3_mutex_leave(db->mutex); |
| @@ -127782,14 +126704,10 @@ | ||
| 127782 | 126704 | return SQLITE_OK; |
| 127783 | 126705 | #else |
| 127784 | 126706 | int rc; /* Return code */ |
| 127785 | 126707 | int iDb = SQLITE_MAX_ATTACHED; /* sqlite3.aDb[] index of db to checkpoint */ |
| 127786 | 126708 | |
| 127787 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 127788 | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; | |
| 127789 | -#endif | |
| 127790 | - | |
| 127791 | 126709 | /* Initialize the output variables to -1 in case an error occurs. */ |
| 127792 | 126710 | if( pnLog ) *pnLog = -1; |
| 127793 | 126711 | if( pnCkpt ) *pnCkpt = -1; |
| 127794 | 126712 | |
| 127795 | 126713 | assert( SQLITE_CHECKPOINT_FULL>SQLITE_CHECKPOINT_PASSIVE ); |
| @@ -128182,16 +127100,10 @@ | ||
| 128182 | 127100 | ** from forming. |
| 128183 | 127101 | */ |
| 128184 | 127102 | SQLITE_API int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){ |
| 128185 | 127103 | int oldLimit; |
| 128186 | 127104 | |
| 128187 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 128188 | - if( !sqlite3SafetyCheckOk(db) ){ | |
| 128189 | - (void)SQLITE_MISUSE_BKPT; | |
| 128190 | - return -1; | |
| 128191 | - } | |
| 128192 | -#endif | |
| 128193 | 127105 | |
| 128194 | 127106 | /* EVIDENCE-OF: R-30189-54097 For each limit category SQLITE_LIMIT_NAME |
| 128195 | 127107 | ** there is a hard upper bound set at compile-time by a C preprocessor |
| 128196 | 127108 | ** macro called SQLITE_MAX_NAME. (The "_LIMIT_" in the name is changed to |
| 128197 | 127109 | ** "_MAX_".) |
| @@ -128264,12 +127176,11 @@ | ||
| 128264 | 127176 | char c; |
| 128265 | 127177 | int nUri = sqlite3Strlen30(zUri); |
| 128266 | 127178 | |
| 128267 | 127179 | assert( *pzErrMsg==0 ); |
| 128268 | 127180 | |
| 128269 | - if( ((flags & SQLITE_OPEN_URI) /* IMP: R-48725-32206 */ | |
| 128270 | - || sqlite3GlobalConfig.bOpenUri) /* IMP: R-51689-46548 */ | |
| 127181 | + if( ((flags & SQLITE_OPEN_URI) || sqlite3GlobalConfig.bOpenUri) | |
| 128271 | 127182 | && nUri>=5 && memcmp(zUri, "file:", 5)==0 /* IMP: R-57884-37496 */ |
| 128272 | 127183 | ){ |
| 128273 | 127184 | char *zOpt; |
| 128274 | 127185 | int eState; /* Parser state when parsing URI */ |
| 128275 | 127186 | int iIn; /* Input character index */ |
| @@ -128474,13 +127385,10 @@ | ||
| 128474 | 127385 | int rc; /* Return code */ |
| 128475 | 127386 | int isThreadsafe; /* True for threadsafe connections */ |
| 128476 | 127387 | char *zOpen = 0; /* Filename argument to pass to BtreeOpen() */ |
| 128477 | 127388 | char *zErrMsg = 0; /* Error message from sqlite3ParseUri() */ |
| 128478 | 127389 | |
| 128479 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 128480 | - if( ppDb==0 ) return SQLITE_MISUSE_BKPT; | |
| 128481 | -#endif | |
| 128482 | 127390 | *ppDb = 0; |
| 128483 | 127391 | #ifndef SQLITE_OMIT_AUTOINIT |
| 128484 | 127392 | rc = sqlite3_initialize(); |
| 128485 | 127393 | if( rc ) return rc; |
| 128486 | 127394 | #endif |
| @@ -128766,19 +127674,17 @@ | ||
| 128766 | 127674 | ){ |
| 128767 | 127675 | char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */ |
| 128768 | 127676 | sqlite3_value *pVal; |
| 128769 | 127677 | int rc; |
| 128770 | 127678 | |
| 128771 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 128772 | - if( ppDb==0 ) return SQLITE_MISUSE_BKPT; | |
| 128773 | -#endif | |
| 127679 | + assert( zFilename ); | |
| 127680 | + assert( ppDb ); | |
| 128774 | 127681 | *ppDb = 0; |
| 128775 | 127682 | #ifndef SQLITE_OMIT_AUTOINIT |
| 128776 | 127683 | rc = sqlite3_initialize(); |
| 128777 | 127684 | if( rc ) return rc; |
| 128778 | 127685 | #endif |
| 128779 | - if( zFilename==0 ) zFilename = "\000\000"; | |
| 128780 | 127686 | pVal = sqlite3ValueNew(0); |
| 128781 | 127687 | sqlite3ValueSetStr(pVal, -1, zFilename, SQLITE_UTF16NATIVE, SQLITE_STATIC); |
| 128782 | 127688 | zFilename8 = sqlite3ValueText(pVal, SQLITE_UTF8); |
| 128783 | 127689 | if( zFilename8 ){ |
| 128784 | 127690 | rc = openDatabase(zFilename8, ppDb, |
| @@ -128804,11 +127710,17 @@ | ||
| 128804 | 127710 | const char *zName, |
| 128805 | 127711 | int enc, |
| 128806 | 127712 | void* pCtx, |
| 128807 | 127713 | int(*xCompare)(void*,int,const void*,int,const void*) |
| 128808 | 127714 | ){ |
| 128809 | - 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; | |
| 128810 | 127722 | } |
| 128811 | 127723 | |
| 128812 | 127724 | /* |
| 128813 | 127725 | ** Register a new collation sequence with the database handle db. |
| 128814 | 127726 | */ |
| @@ -128819,14 +127731,10 @@ | ||
| 128819 | 127731 | void* pCtx, |
| 128820 | 127732 | int(*xCompare)(void*,int,const void*,int,const void*), |
| 128821 | 127733 | void(*xDel)(void*) |
| 128822 | 127734 | ){ |
| 128823 | 127735 | int rc; |
| 128824 | - | |
| 128825 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 128826 | - if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT; | |
| 128827 | -#endif | |
| 128828 | 127736 | sqlite3_mutex_enter(db->mutex); |
| 128829 | 127737 | assert( !db->mallocFailed ); |
| 128830 | 127738 | rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, xDel); |
| 128831 | 127739 | rc = sqlite3ApiExit(db, rc); |
| 128832 | 127740 | sqlite3_mutex_leave(db->mutex); |
| @@ -128844,14 +127752,10 @@ | ||
| 128844 | 127752 | void* pCtx, |
| 128845 | 127753 | int(*xCompare)(void*,int,const void*,int,const void*) |
| 128846 | 127754 | ){ |
| 128847 | 127755 | int rc = SQLITE_OK; |
| 128848 | 127756 | char *zName8; |
| 128849 | - | |
| 128850 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 128851 | - if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT; | |
| 128852 | -#endif | |
| 128853 | 127757 | sqlite3_mutex_enter(db->mutex); |
| 128854 | 127758 | assert( !db->mallocFailed ); |
| 128855 | 127759 | zName8 = sqlite3Utf16to8(db, zName, -1, SQLITE_UTF16NATIVE); |
| 128856 | 127760 | if( zName8 ){ |
| 128857 | 127761 | rc = createCollation(db, zName8, (u8)enc, pCtx, xCompare, 0); |
| @@ -128870,13 +127774,10 @@ | ||
| 128870 | 127774 | SQLITE_API int sqlite3_collation_needed( |
| 128871 | 127775 | sqlite3 *db, |
| 128872 | 127776 | void *pCollNeededArg, |
| 128873 | 127777 | void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*) |
| 128874 | 127778 | ){ |
| 128875 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 128876 | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; | |
| 128877 | -#endif | |
| 128878 | 127779 | sqlite3_mutex_enter(db->mutex); |
| 128879 | 127780 | db->xCollNeeded = xCollNeeded; |
| 128880 | 127781 | db->xCollNeeded16 = 0; |
| 128881 | 127782 | db->pCollNeededArg = pCollNeededArg; |
| 128882 | 127783 | sqlite3_mutex_leave(db->mutex); |
| @@ -128891,13 +127792,10 @@ | ||
| 128891 | 127792 | SQLITE_API int sqlite3_collation_needed16( |
| 128892 | 127793 | sqlite3 *db, |
| 128893 | 127794 | void *pCollNeededArg, |
| 128894 | 127795 | void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*) |
| 128895 | 127796 | ){ |
| 128896 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 128897 | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; | |
| 128898 | -#endif | |
| 128899 | 127797 | sqlite3_mutex_enter(db->mutex); |
| 128900 | 127798 | db->xCollNeeded = 0; |
| 128901 | 127799 | db->xCollNeeded16 = xCollNeeded16; |
| 128902 | 127800 | db->pCollNeededArg = pCollNeededArg; |
| 128903 | 127801 | sqlite3_mutex_leave(db->mutex); |
| @@ -128920,16 +127818,10 @@ | ||
| 128920 | 127818 | ** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on |
| 128921 | 127819 | ** by default. Autocommit is disabled by a BEGIN statement and reenabled |
| 128922 | 127820 | ** by the next COMMIT or ROLLBACK. |
| 128923 | 127821 | */ |
| 128924 | 127822 | SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){ |
| 128925 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 128926 | - if( !sqlite3SafetyCheckOk(db) ){ | |
| 128927 | - (void)SQLITE_MISUSE_BKPT; | |
| 128928 | - return 0; | |
| 128929 | - } | |
| 128930 | -#endif | |
| 128931 | 127823 | return db->autoCommit; |
| 128932 | 127824 | } |
| 128933 | 127825 | |
| 128934 | 127826 | /* |
| 128935 | 127827 | ** The following routines are substitutes for constants SQLITE_CORRUPT, |
| @@ -129108,13 +128000,10 @@ | ||
| 129108 | 128000 | |
| 129109 | 128001 | /* |
| 129110 | 128002 | ** Enable or disable the extended result codes. |
| 129111 | 128003 | */ |
| 129112 | 128004 | SQLITE_API int sqlite3_extended_result_codes(sqlite3 *db, int onoff){ |
| 129113 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 129114 | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; | |
| 129115 | -#endif | |
| 129116 | 128005 | sqlite3_mutex_enter(db->mutex); |
| 129117 | 128006 | db->errMask = onoff ? 0xffffffff : 0xff; |
| 129118 | 128007 | sqlite3_mutex_leave(db->mutex); |
| 129119 | 128008 | return SQLITE_OK; |
| 129120 | 128009 | } |
| @@ -129124,13 +128013,10 @@ | ||
| 129124 | 128013 | */ |
| 129125 | 128014 | SQLITE_API int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){ |
| 129126 | 128015 | int rc = SQLITE_ERROR; |
| 129127 | 128016 | Btree *pBtree; |
| 129128 | 128017 | |
| 129129 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 129130 | - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; | |
| 129131 | -#endif | |
| 129132 | 128018 | sqlite3_mutex_enter(db->mutex); |
| 129133 | 128019 | pBtree = sqlite3DbNameToBtree(db, zDbName); |
| 129134 | 128020 | if( pBtree ){ |
| 129135 | 128021 | Pager *pPager; |
| 129136 | 128022 | sqlite3_file *fd; |
| @@ -129469,11 +128355,11 @@ | ||
| 129469 | 128355 | ** query parameter we seek. This routine returns the value of the zParam |
| 129470 | 128356 | ** parameter if it exists. If the parameter does not exist, this routine |
| 129471 | 128357 | ** returns a NULL pointer. |
| 129472 | 128358 | */ |
| 129473 | 128359 | SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){ |
| 129474 | - if( zFilename==0 || zParam==0 ) return 0; | |
| 128360 | + if( zFilename==0 ) return 0; | |
| 129475 | 128361 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 129476 | 128362 | while( zFilename[0] ){ |
| 129477 | 128363 | int x = strcmp(zFilename, zParam); |
| 129478 | 128364 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 129479 | 128365 | if( x==0 ) return zFilename; |
| @@ -129525,31 +128411,19 @@ | ||
| 129525 | 128411 | /* |
| 129526 | 128412 | ** Return the filename of the database associated with a database |
| 129527 | 128413 | ** connection. |
| 129528 | 128414 | */ |
| 129529 | 128415 | SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){ |
| 129530 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 129531 | - if( !sqlite3SafetyCheckOk(db) ){ | |
| 129532 | - (void)SQLITE_MISUSE_BKPT; | |
| 129533 | - return 0; | |
| 129534 | - } | |
| 129535 | -#endif | |
| 129536 | 128416 | Btree *pBt = sqlite3DbNameToBtree(db, zDbName); |
| 129537 | 128417 | return pBt ? sqlite3BtreeGetFilename(pBt) : 0; |
| 129538 | 128418 | } |
| 129539 | 128419 | |
| 129540 | 128420 | /* |
| 129541 | 128421 | ** Return 1 if database is read-only or 0 if read/write. Return -1 if |
| 129542 | 128422 | ** no such database exists. |
| 129543 | 128423 | */ |
| 129544 | 128424 | SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){ |
| 129545 | -#ifdef SQLITE_ENABLE_API_ARMOR | |
| 129546 | - if( !sqlite3SafetyCheckOk(db) ){ | |
| 129547 | - (void)SQLITE_MISUSE_BKPT; | |
| 129548 | - return -1; | |
| 129549 | - } | |
| 129550 | -#endif | |
| 129551 | 128425 | Btree *pBt = sqlite3DbNameToBtree(db, zDbName); |
| 129552 | 128426 | return pBt ? sqlite3BtreeIsReadonly(pBt) : -1; |
| 129553 | 128427 | } |
| 129554 | 128428 | |
| 129555 | 128429 | /************** End of main.c ************************************************/ |
| 129556 | 128430 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1,8 +1,8 @@ | |
| 1 | /****************************************************************************** |
| 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 |
| 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | ** translation unit. |
| @@ -179,11 +179,11 @@ | |
| 179 | |
| 180 | |
| 181 | /* |
| 182 | ** These no-op macros are used in front of interfaces to mark those |
| 183 | ** interfaces as either deprecated or experimental. New applications |
| 184 | ** should not use deprecated interfaces - they are supported for backwards |
| 185 | ** compatibility only. Application writers should be aware that |
| 186 | ** experimental interfaces are subject to change in point releases. |
| 187 | ** |
| 188 | ** These macros used to resolve to various kinds of compiler magic that |
| 189 | ** would generate warning messages when they were used. But that |
| @@ -229,13 +229,13 @@ | |
| 229 | ** |
| 230 | ** See also: [sqlite3_libversion()], |
| 231 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 232 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 233 | */ |
| 234 | #define SQLITE_VERSION "3.8.8" |
| 235 | #define SQLITE_VERSION_NUMBER 3008008 |
| 236 | #define SQLITE_SOURCE_ID "2014-11-18 21:54:31 4461bf045d8eecf98478035efcdba3f41c709bc5" |
| 237 | |
| 238 | /* |
| 239 | ** CAPI3REF: Run-Time Library Version Numbers |
| 240 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 241 | ** |
| @@ -1626,31 +1626,29 @@ | |
| 1626 | ** it is not possible to set the Serialized [threading mode] and |
| 1627 | ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
| 1628 | ** SQLITE_CONFIG_SERIALIZED configuration option.</dd> |
| 1629 | ** |
| 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 |
| 1634 | ** alternative low-level memory allocation routines to be used in place of |
| 1635 | ** the memory allocation routines built into SQLite.)^ ^SQLite makes |
| 1636 | ** its own private copy of the content of the [sqlite3_mem_methods] structure |
| 1637 | ** before the [sqlite3_config()] call returns.</dd> |
| 1638 | ** |
| 1639 | ** [[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] |
| 1643 | ** structure is filled with the currently defined memory allocation routines.)^ |
| 1644 | ** This option can be used to overload the default memory allocation |
| 1645 | ** routines with a wrapper that simulations memory allocation failure or |
| 1646 | ** tracks memory usage, for example. </dd> |
| 1647 | ** |
| 1648 | ** [[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 |
| 1652 | ** following SQLite interfaces become non-operational: |
| 1653 | ** <ul> |
| 1654 | ** <li> [sqlite3_memory_used()] |
| 1655 | ** <li> [sqlite3_memory_highwater()] |
| 1656 | ** <li> [sqlite3_soft_heap_limit64()] |
| @@ -1660,90 +1658,78 @@ | |
| 1660 | ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory |
| 1661 | ** allocation statistics are disabled by default. |
| 1662 | ** </dd> |
| 1663 | ** |
| 1664 | ** [[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 |
| 1668 | ** aligned memory buffer from which the scratch allocations will be |
| 1669 | ** drawn, the size of each scratch allocation (sz), |
| 1670 | ** and the maximum number of scratch allocations (N).)^ |
| 1671 | ** The first argument must be a pointer to an 8-byte aligned buffer |
| 1672 | ** 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 |
| 1677 | ** 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> |
| 1685 | ** |
| 1686 | ** [[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. |
| 1690 | ** 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 |
| 1694 | ** memory, the size of each page buffer (sz), and the number of pages (N). |
| 1695 | ** 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. |
| 1705 | ** ^SQLite will use the memory provided by the first argument to satisfy its |
| 1706 | ** memory needs for the first N pages that it adds to cache. ^If additional |
| 1707 | ** 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> |
| 1709 | ** |
| 1710 | ** [[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, |
| 1719 | ** the number of bytes in the memory buffer, and the minimum allocation size. |
| 1720 | ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts |
| 1721 | ** to using its default memory allocator (the system malloc() implementation), |
| 1722 | ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the |
| 1723 | ** memory pointer is not NULL then the alternative memory |
| 1724 | ** allocator is engaged to handle all of SQLites memory allocation needs. |
| 1725 | ** The first pointer (the memory pointer) must be aligned to an 8-byte |
| 1726 | ** boundary or subsequent behavior of SQLite will be undefined. |
| 1727 | ** The minimum allocation size is capped at 2**12. Reasonable values |
| 1728 | ** for the minimum allocation size are 2**5 through 2**8.</dd> |
| 1729 | ** |
| 1730 | ** [[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 |
| 1734 | ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the |
| 1735 | ** content of the [sqlite3_mutex_methods] structure before the call to |
| 1736 | ** [sqlite3_config()] returns. ^If SQLite is compiled with |
| 1737 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1738 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1739 | ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will |
| 1740 | ** return [SQLITE_ERROR].</dd> |
| 1741 | ** |
| 1742 | ** [[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 |
| 1745 | ** [sqlite3_mutex_methods] |
| 1746 | ** structure is filled with the currently defined mutex routines.)^ |
| 1747 | ** This option can be used to overload the default mutex allocation |
| 1748 | ** routines with a wrapper used to track mutex usage for performance |
| 1749 | ** profiling or testing, for example. ^If SQLite is compiled with |
| @@ -1751,28 +1737,28 @@ | |
| 1751 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1752 | ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will |
| 1753 | ** return [SQLITE_ERROR].</dd> |
| 1754 | ** |
| 1755 | ** [[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 |
| 1759 | ** 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 |
| 1763 | ** configuration on individual connections.)^ </dd> |
| 1764 | ** |
| 1765 | ** [[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> |
| 1770 | ** |
| 1771 | ** [[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 |
| 1774 | ** page cache implementation into that object.)^ </dd> |
| 1775 | ** |
| 1776 | ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> |
| 1777 | ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite |
| 1778 | ** global [error log]. |
| @@ -1792,27 +1778,26 @@ | |
| 1792 | ** supplied by the application must not invoke any SQLite interface. |
| 1793 | ** In a multi-threaded application, the application-defined logger |
| 1794 | ** function must be threadsafe. </dd> |
| 1795 | ** |
| 1796 | ** [[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 |
| 1801 | ** specified as part of [ATTACH] commands are interpreted as URIs, regardless |
| 1802 | ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database |
| 1803 | ** connection is opened. ^If it is globally disabled, filenames are |
| 1804 | ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the |
| 1805 | ** database connection is opened. ^(By default, URI handling is globally |
| 1806 | ** disabled. The default value may be changed by compiling with the |
| 1807 | ** [SQLITE_USE_URI] symbol defined.)^ |
| 1808 | ** |
| 1809 | ** [[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 |
| 1814 | ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on" |
| 1815 | ** if that compile-time option is omitted. |
| 1816 | ** The ability to disable the use of covering indices for full table scans |
| 1817 | ** is because some incorrectly coded legacy applications might malfunction |
| 1818 | ** when the optimization is enabled. Providing the ability to |
| @@ -1848,32 +1833,23 @@ | |
| 1848 | ** that are the default mmap size limit (the default setting for |
| 1849 | ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit. |
| 1850 | ** ^The default setting can be overridden by each database connection using |
| 1851 | ** either the [PRAGMA mmap_size] command, or by using the |
| 1852 | ** [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 |
| 1855 | ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^ |
| 1856 | ** ^If either argument to this option is negative, then that argument is |
| 1857 | ** changed to its compile-time default. |
| 1858 | ** |
| 1859 | ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]] |
| 1860 | ** <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 |
| 1864 | ** that specifies the maximum size of the created heap. |
| 1865 | ** </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 | */ |
| 1876 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1877 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 1878 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| 1879 | #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ |
| @@ -1894,11 +1870,10 @@ | |
| 1894 | #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */ |
| 1895 | #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */ |
| 1896 | #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */ |
| 1897 | #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */ |
| 1898 | #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */ |
| 1899 | #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */ |
| 1900 | |
| 1901 | /* |
| 1902 | ** CAPI3REF: Database Connection Configuration Options |
| 1903 | ** |
| 1904 | ** These constants are the available integer configuration options that |
| @@ -2022,49 +1997,51 @@ | |
| 2022 | SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); |
| 2023 | |
| 2024 | /* |
| 2025 | ** CAPI3REF: Count The Number Of Rows Modified |
| 2026 | ** |
| 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. |
| 2066 | ** |
| 2067 | ** See also the [sqlite3_total_changes()] interface, the |
| 2068 | ** [count_changes pragma], and the [changes() SQL function]. |
| 2069 | ** |
| 2070 | ** If a separate thread makes changes on the same database connection |
| @@ -2074,21 +2051,24 @@ | |
| 2074 | SQLITE_API int sqlite3_changes(sqlite3*); |
| 2075 | |
| 2076 | /* |
| 2077 | ** CAPI3REF: Total Number Of Rows Modified |
| 2078 | ** |
| 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 | ** |
| 2090 | ** See also the [sqlite3_changes()] interface, the |
| 2091 | ** [count_changes pragma], and the [total_changes() SQL function]. |
| 2092 | ** |
| 2093 | ** If a separate thread makes changes on the same database connection |
| 2094 | ** while [sqlite3_total_changes()] is running then the value |
| @@ -2562,18 +2542,17 @@ | |
| 2562 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2563 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2564 | ** applications to access the same PRNG for other purposes. |
| 2565 | ** |
| 2566 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2567 | ** ^The P parameter can be a NULL pointer. |
| 2568 | ** |
| 2569 | ** ^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 |
| 2575 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2576 | ** method. |
| 2577 | */ |
| 2578 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2579 | |
| @@ -5784,46 +5763,30 @@ | |
| 5784 | ** |
| 5785 | ** <pre> |
| 5786 | ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow; |
| 5787 | ** </pre>)^ |
| 5788 | ** |
| 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 | ** ^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 | ** |
| 5825 | ** |
| 5826 | ** ^(If the row that a BLOB handle points to is modified by an |
| 5827 | ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects |
| 5828 | ** then the BLOB handle is marked as "expired". |
| 5829 | ** This is true if any column of the row is changed, even a column |
| @@ -5837,13 +5800,17 @@ | |
| 5837 | ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of |
| 5838 | ** the opened blob. ^The size of a blob may not be changed by this |
| 5839 | ** interface. Use the [UPDATE] SQL command to change the size of a |
| 5840 | ** blob. |
| 5841 | ** |
| 5842 | ** ^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. |
| 5845 | ** |
| 5846 | ** To avoid a resource leak, every open [BLOB handle] should eventually |
| 5847 | ** be released by a call to [sqlite3_blob_close()]. |
| 5848 | */ |
| 5849 | SQLITE_API int sqlite3_blob_open( |
| @@ -5881,26 +5848,28 @@ | |
| 5881 | SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); |
| 5882 | |
| 5883 | /* |
| 5884 | ** CAPI3REF: Close A BLOB Handle |
| 5885 | ** |
| 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. |
| 5902 | */ |
| 5903 | SQLITE_API int sqlite3_blob_close(sqlite3_blob *); |
| 5904 | |
| 5905 | /* |
| 5906 | ** CAPI3REF: Return The Size Of An Open BLOB |
| @@ -5946,39 +5915,36 @@ | |
| 5946 | SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); |
| 5947 | |
| 5948 | /* |
| 5949 | ** CAPI3REF: Write Data Into A BLOB Incrementally |
| 5950 | ** |
| 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. |
| 5960 | ** |
| 5961 | ** ^If the [BLOB handle] passed as the first argument was not opened for |
| 5962 | ** writing (the flags parameter to [sqlite3_blob_open()] was zero), |
| 5963 | ** this function returns [SQLITE_READONLY]. |
| 5964 | ** |
| 5965 | ** This function may only modify the contents of the BLOB; it is |
| 5966 | ** not possible to increase the size of a BLOB using this API. |
| 5967 | ** ^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. |
| 5972 | ** |
| 5973 | ** ^An attempt to write to an expired [BLOB handle] fails with an |
| 5974 | ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred |
| 5975 | ** before the [BLOB handle] expired are not rolled back by the |
| 5976 | ** expiration of the handle, though of course those changes might |
| 5977 | ** have been overwritten by the statement that expired the BLOB handle |
| 5978 | ** or by other independent statements. |
| 5979 | ** |
| 5980 | ** This routine only works on a [BLOB handle] which has been created |
| 5981 | ** by a prior successful call to [sqlite3_blob_open()] and which has not |
| 5982 | ** been closed by [sqlite3_blob_close()]. Passing any other pointer in |
| 5983 | ** to this routine results in undefined and probably undesirable behavior. |
| 5984 | ** |
| @@ -6975,14 +6941,10 @@ | |
| 6975 | ** and database name of the source database, respectively. |
| 6976 | ** ^The source and destination [database connections] (parameters S and D) |
| 6977 | ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with |
| 6978 | ** an error. |
| 6979 | ** |
| 6980 | ** ^A call to sqlite3_backup_init() will fail, returning SQLITE_ERROR, if |
| 6981 | ** there is already a read or read-write transaction open on the |
| 6982 | ** destination database. |
| 6983 | ** |
| 6984 | ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is |
| 6985 | ** returned and an error code and error message are stored in the |
| 6986 | ** destination [database connection] D. |
| 6987 | ** ^The error code and message for the failed call to sqlite3_backup_init() |
| 6988 | ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or |
| @@ -7571,102 +7533,10 @@ | |
| 7571 | /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */ |
| 7572 | #define SQLITE_FAIL 3 |
| 7573 | /* #define SQLITE_ABORT 4 // Also an error code */ |
| 7574 | #define SQLITE_REPLACE 5 |
| 7575 | |
| 7576 | /* |
| 7577 | ** CAPI3REF: Prepared Statement Scan Status Opcodes |
| 7578 | ** KEYWORDS: {scanstatus options} |
| 7579 | ** |
| 7580 | ** The following constants can be used for the T parameter to the |
| 7581 | ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a |
| 7582 | ** different metric for sqlite3_stmt_scanstatus() to return. |
| 7583 | ** |
| 7584 | ** <dl> |
| 7585 | ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt> |
| 7586 | ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the |
| 7587 | ** total number of times that the X-th loop has run.</dd> |
| 7588 | ** |
| 7589 | ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt> |
| 7590 | ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the |
| 7591 | ** total number of rows examined by all iterations of the X-th loop.</dd> |
| 7592 | ** |
| 7593 | ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt> |
| 7594 | ** <dd>^The "double" variable pointed to by the T parameter will be set to the |
| 7595 | ** query planner's estimate for the average number of rows output from each |
| 7596 | ** iteration of the X-th loop. If the query planner's estimates was accurate, |
| 7597 | ** then this value will approximate the quotient NVISIT/NLOOP and the |
| 7598 | ** product of this value for all prior loops with the same SELECTID will |
| 7599 | ** be the NLOOP value for the current loop. |
| 7600 | ** |
| 7601 | ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt> |
| 7602 | ** <dd>^The "const char *" variable pointed to by the T parameter will be set to |
| 7603 | ** a zero-terminated UTF-8 string containing the name of the index or table used |
| 7604 | ** for the X-th loop. |
| 7605 | ** |
| 7606 | ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt> |
| 7607 | ** <dd>^The "const char *" variable pointed to by the T parameter will be set to |
| 7608 | ** a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN] description |
| 7609 | ** for the X-th loop. |
| 7610 | ** |
| 7611 | ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt> |
| 7612 | ** <dd>^The "int" variable pointed to by the T parameter will be set to the |
| 7613 | ** "select-id" for the X-th loop. The select-id identifies which query or |
| 7614 | ** subquery the loop is part of. The main query has a select-id of zero. |
| 7615 | ** The select-id is the same value as is output in the first column |
| 7616 | ** of an [EXPLAIN QUERY PLAN] query. |
| 7617 | ** </dl> |
| 7618 | */ |
| 7619 | #define SQLITE_SCANSTAT_NLOOP 0 |
| 7620 | #define SQLITE_SCANSTAT_NVISIT 1 |
| 7621 | #define SQLITE_SCANSTAT_EST 2 |
| 7622 | #define SQLITE_SCANSTAT_NAME 3 |
| 7623 | #define SQLITE_SCANSTAT_EXPLAIN 4 |
| 7624 | #define SQLITE_SCANSTAT_SELECTID 5 |
| 7625 | |
| 7626 | /* |
| 7627 | ** CAPI3REF: Prepared Statement Scan Status |
| 7628 | ** |
| 7629 | ** Return status data for a single loop within query pStmt. |
| 7630 | ** |
| 7631 | ** The "iScanStatusOp" parameter determines which status information to return. |
| 7632 | ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior of |
| 7633 | ** this interface is undefined. |
| 7634 | ** ^The requested measurement is written into a variable pointed to by |
| 7635 | ** the "pOut" parameter. |
| 7636 | ** Parameter "idx" identifies the specific loop to retrieve statistics for. |
| 7637 | ** Loops are numbered starting from zero. ^If idx is out of range - less than |
| 7638 | ** zero or greater than or equal to the total number of loops used to implement |
| 7639 | ** the statement - a non-zero value is returned and the variable that pOut |
| 7640 | ** points to is unchanged. |
| 7641 | ** |
| 7642 | ** ^Statistics might not be available for all loops in all statements. ^In cases |
| 7643 | ** where there exist loops with no available statistics, this function behaves |
| 7644 | ** as if the loop did not exist - it returns non-zero and leave the variable |
| 7645 | ** that pOut points to unchanged. |
| 7646 | ** |
| 7647 | ** This API is only available if the library is built with pre-processor |
| 7648 | ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. |
| 7649 | ** |
| 7650 | ** See also: [sqlite3_stmt_scanstatus_reset()] |
| 7651 | */ |
| 7652 | SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus( |
| 7653 | sqlite3_stmt *pStmt, /* Prepared statement for which info desired */ |
| 7654 | int idx, /* Index of loop to report on */ |
| 7655 | int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */ |
| 7656 | void *pOut /* Result written here */ |
| 7657 | ); |
| 7658 | |
| 7659 | /* |
| 7660 | ** CAPI3REF: Zero Scan-Status Counters |
| 7661 | ** |
| 7662 | ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters. |
| 7663 | ** |
| 7664 | ** This API is only available if the library is built with pre-processor |
| 7665 | ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. |
| 7666 | */ |
| 7667 | SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*); |
| 7668 | |
| 7669 | |
| 7670 | /* |
| 7671 | ** Undo the hack that converts floating point types to integer for |
| 7672 | ** builds on processors without floating point support. |
| @@ -8108,13 +7978,14 @@ | |
| 8108 | #ifndef SQLITE_POWERSAFE_OVERWRITE |
| 8109 | # define SQLITE_POWERSAFE_OVERWRITE 1 |
| 8110 | #endif |
| 8111 | |
| 8112 | /* |
| 8113 | ** EVIDENCE-OF: R-25715-37072 Memory allocation statistics are enabled by |
| 8114 | ** default unless SQLite is compiled with SQLITE_DEFAULT_MEMSTATUS=0 in |
| 8115 | ** which case memory allocation statistics are disabled by default. |
| 8116 | */ |
| 8117 | #if !defined(SQLITE_DEFAULT_MEMSTATUS) |
| 8118 | # define SQLITE_DEFAULT_MEMSTATUS 1 |
| 8119 | #endif |
| 8120 | |
| @@ -8740,11 +8611,11 @@ | |
| 8740 | ** Estimated quantities used for query planning are stored as 16-bit |
| 8741 | ** logarithms. For quantity X, the value stored is 10*log2(X). This |
| 8742 | ** gives a possible range of values of approximately 1.0e986 to 1e-986. |
| 8743 | ** But the allowed values are "grainy". Not every value is representable. |
| 8744 | ** For example, quantities 16 and 17 are both represented by a LogEst |
| 8745 | ** of 40. However, since LogEst quantities are suppose to be estimates, |
| 8746 | ** not exact values, this imprecision is not a problem. |
| 8747 | ** |
| 8748 | ** "LogEst" is short for "Logarithmic Estimate". |
| 8749 | ** |
| 8750 | ** Examples: |
| @@ -9253,11 +9124,10 @@ | |
| 9253 | SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *); |
| 9254 | SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *); |
| 9255 | SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion); |
| 9256 | SQLITE_PRIVATE void sqlite3BtreeCursorHints(BtCursor *, unsigned int mask); |
| 9257 | SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *pBt); |
| 9258 | SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void); |
| 9259 | |
| 9260 | #ifndef NDEBUG |
| 9261 | SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*); |
| 9262 | #endif |
| 9263 | |
| @@ -9796,16 +9666,10 @@ | |
| 9796 | # define VdbeCoverageAlwaysTaken(v) |
| 9797 | # define VdbeCoverageNeverTaken(v) |
| 9798 | # define VDBE_OFFSET_LINENO(x) 0 |
| 9799 | #endif |
| 9800 | |
| 9801 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 9802 | SQLITE_PRIVATE void sqlite3VdbeScanStatus(Vdbe*, int, int, int, LogEst, const char*); |
| 9803 | #else |
| 9804 | # define sqlite3VdbeScanStatus(a,b,c,d,e) |
| 9805 | #endif |
| 9806 | |
| 9807 | #endif |
| 9808 | |
| 9809 | /************** End of vdbe.h ************************************************/ |
| 9810 | /************** Continuing where we left off in sqliteInt.h ******************/ |
| 9811 | /************** Include pager.h in the middle of sqliteInt.h *****************/ |
| @@ -9998,12 +9862,10 @@ | |
| 9998 | SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *); |
| 9999 | |
| 10000 | /* Functions used to truncate the database file. */ |
| 10001 | SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno); |
| 10002 | |
| 10003 | SQLITE_PRIVATE void sqlite3PagerRekey(DbPage*, Pgno, u16); |
| 10004 | |
| 10005 | #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_WAL) |
| 10006 | SQLITE_PRIVATE void *sqlite3PagerCodec(DbPage *); |
| 10007 | #endif |
| 10008 | |
| 10009 | /* Functions to support testing and debugging. */ |
| @@ -10187,14 +10049,10 @@ | |
| 10187 | SQLITE_PRIVATE void sqlite3PcacheStats(int*,int*,int*,int*); |
| 10188 | #endif |
| 10189 | |
| 10190 | SQLITE_PRIVATE void sqlite3PCacheSetDefault(void); |
| 10191 | |
| 10192 | /* Return the header size */ |
| 10193 | SQLITE_PRIVATE int sqlite3HeaderSizePcache(void); |
| 10194 | SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void); |
| 10195 | |
| 10196 | #endif /* _PCACHE_H_ */ |
| 10197 | |
| 10198 | /************** End of pcache.h **********************************************/ |
| 10199 | /************** Continuing where we left off in sqliteInt.h ******************/ |
| 10200 | |
| @@ -10877,11 +10735,11 @@ | |
| 10877 | #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */ |
| 10878 | #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */ |
| 10879 | #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */ |
| 10880 | #define SQLITE_Transitive 0x0200 /* Transitive constraints */ |
| 10881 | #define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */ |
| 10882 | #define SQLITE_Stat34 0x0800 /* Use STAT3 or STAT4 data */ |
| 10883 | #define SQLITE_AllOpts 0xffff /* All optimizations */ |
| 10884 | |
| 10885 | /* |
| 10886 | ** Macros for testing whether or not optimizations are enabled or disabled. |
| 10887 | */ |
| @@ -11459,18 +11317,16 @@ | |
| 11459 | unsigned idxType:2; /* 1==UNIQUE, 2==PRIMARY KEY, 0==CREATE INDEX */ |
| 11460 | unsigned bUnordered:1; /* Use this index for == or IN queries only */ |
| 11461 | unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */ |
| 11462 | unsigned isResized:1; /* True if resizeIndexObject() has been called */ |
| 11463 | unsigned isCovering:1; /* True if this is a covering index */ |
| 11464 | unsigned noSkipScan:1; /* Do not try to use skip-scan if true */ |
| 11465 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 11466 | int nSample; /* Number of elements in aSample[] */ |
| 11467 | int nSampleCol; /* Size of IndexSample.anEq[] and so on */ |
| 11468 | tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */ |
| 11469 | IndexSample *aSample; /* Samples of the left-most key */ |
| 11470 | tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this index */ |
| 11471 | tRowcnt nRowEst0; /* Non-logarithmic number of rows in the index */ |
| 11472 | #endif |
| 11473 | }; |
| 11474 | |
| 11475 | /* |
| 11476 | ** Allowed values for Index.idxType |
| @@ -11664,11 +11520,11 @@ | |
| 11664 | int nHeight; /* Height of the tree headed by this node */ |
| 11665 | #endif |
| 11666 | int iTable; /* TK_COLUMN: cursor number of table holding column |
| 11667 | ** TK_REGISTER: register number |
| 11668 | ** TK_TRIGGER: 1 -> new, 0 -> old |
| 11669 | ** EP_Unlikely: 134217728 times likelihood */ |
| 11670 | ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid. |
| 11671 | ** TK_VARIABLE: variable number (always >= 1). */ |
| 11672 | i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */ |
| 11673 | i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */ |
| 11674 | u8 op2; /* TK_REGISTER: original value of Expr.op |
| @@ -12556,15 +12412,13 @@ | |
| 12556 | int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */ |
| 12557 | int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */ |
| 12558 | void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */ |
| 12559 | Parse *pParse; /* Parser context. */ |
| 12560 | int walkerDepth; /* Number of subqueries */ |
| 12561 | u8 eCode; /* A small processing code */ |
| 12562 | union { /* Extra data for callback */ |
| 12563 | NameContext *pNC; /* Naming context */ |
| 12564 | int n; /* A counter */ |
| 12565 | int iCur; /* A cursor number */ |
| 12566 | SrcList *pSrcList; /* FROM clause */ |
| 12567 | struct SrcCount *pSrcCount; /* Counting column references */ |
| 12568 | } u; |
| 12569 | }; |
| 12570 | |
| @@ -12961,11 +12815,10 @@ | |
| 12961 | SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *); |
| 12962 | SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*); |
| 12963 | SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*); |
| 12964 | SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*); |
| 12965 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8); |
| 12966 | SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int); |
| 12967 | SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*); |
| 12968 | SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*); |
| 12969 | SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char); |
| 12970 | SQLITE_PRIVATE int sqlite3IsRowid(const char*); |
| 12971 | SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8); |
| @@ -13619,23 +13472,15 @@ | |
| 13619 | ** compatibility for legacy applications, the URI filename capability is |
| 13620 | ** disabled by default. |
| 13621 | ** |
| 13622 | ** EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled |
| 13623 | ** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options. |
| 13624 | ** |
| 13625 | ** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally |
| 13626 | ** disabled. The default value may be changed by compiling with the |
| 13627 | ** SQLITE_USE_URI symbol defined. |
| 13628 | */ |
| 13629 | #ifndef SQLITE_USE_URI |
| 13630 | # define SQLITE_USE_URI 0 |
| 13631 | #endif |
| 13632 | |
| 13633 | /* EVIDENCE-OF: R-38720-18127 The default setting is determined by the |
| 13634 | ** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if |
| 13635 | ** that compile-time option is omitted. |
| 13636 | */ |
| 13637 | #ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN |
| 13638 | # define SQLITE_ALLOW_COVERING_INDEX_SCAN 1 |
| 13639 | #endif |
| 13640 | |
| 13641 | /* |
| @@ -13721,12 +13566,12 @@ | |
| 13721 | ** than 1 GiB. The sqlite3_test_control() interface can be used to |
| 13722 | ** move the pending byte. |
| 13723 | ** |
| 13724 | ** IMPORTANT: Changing the pending byte to any value other than |
| 13725 | ** 0x40000000 results in an incompatible database file format! |
| 13726 | ** Changing the pending byte during operation will result in undefined |
| 13727 | ** and incorrect behavior. |
| 13728 | */ |
| 13729 | #ifndef SQLITE_OMIT_WSD |
| 13730 | SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000; |
| 13731 | #endif |
| 13732 | |
| @@ -13802,13 +13647,10 @@ | |
| 13802 | "DISABLE_DIRSYNC", |
| 13803 | #endif |
| 13804 | #ifdef SQLITE_DISABLE_LFS |
| 13805 | "DISABLE_LFS", |
| 13806 | #endif |
| 13807 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 13808 | "ENABLE_API_ARMOR", |
| 13809 | #endif |
| 13810 | #ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 13811 | "ENABLE_ATOMIC_WRITE", |
| 13812 | #endif |
| 13813 | #ifdef SQLITE_ENABLE_CEROD |
| 13814 | "ENABLE_CEROD", |
| @@ -14130,17 +13972,10 @@ | |
| 14130 | ** The name can optionally begin with "SQLITE_" but the "SQLITE_" prefix |
| 14131 | ** is not required for a match. |
| 14132 | */ |
| 14133 | SQLITE_API int sqlite3_compileoption_used(const char *zOptName){ |
| 14134 | int i, n; |
| 14135 | |
| 14136 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 14137 | if( zOptName==0 ){ |
| 14138 | (void)SQLITE_MISUSE_BKPT; |
| 14139 | return 0; |
| 14140 | } |
| 14141 | #endif |
| 14142 | if( sqlite3StrNICmp(zOptName, "SQLITE_", 7)==0 ) zOptName += 7; |
| 14143 | n = sqlite3Strlen30(zOptName); |
| 14144 | |
| 14145 | /* Since ArraySize(azCompileOpt) is normally in single digits, a |
| 14146 | ** linear search is adequate. No need for a binary search. */ |
| @@ -14318,11 +14153,10 @@ | |
| 14318 | typedef struct VdbeFrame VdbeFrame; |
| 14319 | struct VdbeFrame { |
| 14320 | Vdbe *v; /* VM this frame belongs to */ |
| 14321 | VdbeFrame *pParent; /* Parent of this frame, or NULL if parent is main */ |
| 14322 | Op *aOp; /* Program instructions for parent frame */ |
| 14323 | i64 *anExec; /* Event counters from parent frame */ |
| 14324 | Mem *aMem; /* Array of memory cells for parent frame */ |
| 14325 | u8 *aOnceFlag; /* Array of OP_Once flags for parent frame */ |
| 14326 | VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */ |
| 14327 | void *token; /* Copy of SubProgram.token */ |
| 14328 | i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */ |
| @@ -14331,12 +14165,11 @@ | |
| 14331 | int nOp; /* Size of aOp array */ |
| 14332 | int nMem; /* Number of entries in aMem */ |
| 14333 | int nOnceFlag; /* Number of entries in aOnceFlag */ |
| 14334 | int nChildMem; /* Number of memory cells for child frame */ |
| 14335 | int nChildCsr; /* Number of cursors for child frame */ |
| 14336 | int nChange; /* Statement changes (Vdbe.nChange) */ |
| 14337 | int nDbChange; /* Value of db->nChange */ |
| 14338 | }; |
| 14339 | |
| 14340 | #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))]) |
| 14341 | |
| 14342 | /* |
| @@ -14483,20 +14316,10 @@ | |
| 14483 | /* A bitfield type for use inside of structures. Always follow with :N where |
| 14484 | ** N is the number of bits. |
| 14485 | */ |
| 14486 | typedef unsigned bft; /* Bit Field Type */ |
| 14487 | |
| 14488 | typedef struct ScanStatus ScanStatus; |
| 14489 | struct ScanStatus { |
| 14490 | int addrExplain; /* OP_Explain for loop */ |
| 14491 | int addrLoop; /* Address of "loops" counter */ |
| 14492 | int addrVisit; /* Address of "rows visited" counter */ |
| 14493 | int iSelectID; /* The "Select-ID" for this loop */ |
| 14494 | LogEst nEst; /* Estimated output rows per loop */ |
| 14495 | char *zName; /* Name of table or index */ |
| 14496 | }; |
| 14497 | |
| 14498 | /* |
| 14499 | ** An instance of the virtual machine. This structure contains the complete |
| 14500 | ** state of the virtual machine. |
| 14501 | ** |
| 14502 | ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare() |
| @@ -14565,15 +14388,10 @@ | |
| 14565 | u32 expmask; /* Binding to these vars invalidates VM */ |
| 14566 | SubProgram *pProgram; /* Linked list of all sub-programs used by VM */ |
| 14567 | int nOnceFlag; /* Size of array aOnceFlag[] */ |
| 14568 | u8 *aOnceFlag; /* Flags for OP_Once */ |
| 14569 | AuxData *pAuxData; /* Linked list of auxdata allocations */ |
| 14570 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 14571 | i64 *anExec; /* Number of times each op has been executed */ |
| 14572 | int nScan; /* Entries in aScan[] */ |
| 14573 | ScanStatus *aScan; /* Scan definitions for sqlite3_stmt_scanstatus() */ |
| 14574 | #endif |
| 14575 | }; |
| 14576 | |
| 14577 | /* |
| 14578 | ** The following are allowed values for Vdbe.magic |
| 14579 | */ |
| @@ -14759,13 +14577,10 @@ | |
| 14759 | SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){ |
| 14760 | wsdStatInit; |
| 14761 | if( op<0 || op>=ArraySize(wsdStat.nowValue) ){ |
| 14762 | return SQLITE_MISUSE_BKPT; |
| 14763 | } |
| 14764 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 14765 | if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT; |
| 14766 | #endif |
| 14767 | *pCurrent = wsdStat.nowValue[op]; |
| 14768 | *pHighwater = wsdStat.mxValue[op]; |
| 14769 | if( resetFlag ){ |
| 14770 | wsdStat.mxValue[op] = wsdStat.nowValue[op]; |
| 14771 | } |
| @@ -14781,15 +14596,10 @@ | |
| 14781 | int *pCurrent, /* Write current value here */ |
| 14782 | int *pHighwater, /* Write high-water mark here */ |
| 14783 | int resetFlag /* Reset high-water mark if true */ |
| 14784 | ){ |
| 14785 | int rc = SQLITE_OK; /* Return code */ |
| 14786 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 14787 | if( !sqlite3SafetyCheckOk(db) || pCurrent==0|| pHighwater==0 ){ |
| 14788 | return SQLITE_MISUSE_BKPT; |
| 14789 | } |
| 14790 | #endif |
| 14791 | sqlite3_mutex_enter(db->mutex); |
| 14792 | switch( op ){ |
| 14793 | case SQLITE_DBSTATUS_LOOKASIDE_USED: { |
| 14794 | *pCurrent = db->lookaside.nOut; |
| 14795 | *pHighwater = db->lookaside.mxOut; |
| @@ -14964,11 +14774,11 @@ | |
| 14964 | ** |
| 14965 | ** There is only one exported symbol in this file - the function |
| 14966 | ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file. |
| 14967 | ** All other code has file scope. |
| 14968 | ** |
| 14969 | ** SQLite processes all times and dates as julian day numbers. The |
| 14970 | ** dates and times are stored as the number of days since noon |
| 14971 | ** in Greenwich on November 24, 4714 B.C. according to the Gregorian |
| 14972 | ** calendar system. |
| 14973 | ** |
| 14974 | ** 1970-01-01 00:00:00 is JD 2440587.5 |
| @@ -14979,11 +14789,11 @@ | |
| 14979 | ** be represented, even though julian day numbers allow a much wider |
| 14980 | ** range of dates. |
| 14981 | ** |
| 14982 | ** The Gregorian calendar system is used for all dates and times, |
| 14983 | ** even those that predate the Gregorian calendar. Historians usually |
| 14984 | ** use the julian calendar for dates prior to 1582-10-15 and for some |
| 14985 | ** dates afterwards, depending on locale. Beware of this difference. |
| 14986 | ** |
| 14987 | ** The conversion algorithms are implemented based on descriptions |
| 14988 | ** in the following text: |
| 14989 | ** |
| @@ -15251,11 +15061,11 @@ | |
| 15251 | return 1; |
| 15252 | } |
| 15253 | } |
| 15254 | |
| 15255 | /* |
| 15256 | ** Attempt to parse the given string into a julian day number. Return |
| 15257 | ** the number of errors. |
| 15258 | ** |
| 15259 | ** The following are acceptable forms for the input string: |
| 15260 | ** |
| 15261 | ** YYYY-MM-DD HH:MM:SS.FFF +/-HH:MM |
| @@ -15822,11 +15632,11 @@ | |
| 15822 | ** |
| 15823 | ** %d day of month |
| 15824 | ** %f ** fractional seconds SS.SSS |
| 15825 | ** %H hour 00-24 |
| 15826 | ** %j day of year 000-366 |
| 15827 | ** %J ** julian day number |
| 15828 | ** %m month 01-12 |
| 15829 | ** %M minute 00-59 |
| 15830 | ** %s seconds since 1970-01-01 |
| 15831 | ** %S seconds 00-59 |
| 15832 | ** %w day of week 0-6 sunday==0 |
| @@ -16447,14 +16257,10 @@ | |
| 16447 | MUTEX_LOGIC(sqlite3_mutex *mutex;) |
| 16448 | #ifndef SQLITE_OMIT_AUTOINIT |
| 16449 | int rc = sqlite3_initialize(); |
| 16450 | if( rc ) return rc; |
| 16451 | #endif |
| 16452 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 16453 | if( pVfs==0 ) return SQLITE_MISUSE_BKPT; |
| 16454 | #endif |
| 16455 | |
| 16456 | MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); ) |
| 16457 | sqlite3_mutex_enter(mutex); |
| 16458 | vfsUnlink(pVfs); |
| 16459 | if( makeDflt || vfsList==0 ){ |
| 16460 | pVfs->pNext = vfsList; |
| @@ -18808,11 +18614,10 @@ | |
| 18808 | ** Retrieve a pointer to a static mutex or allocate a new dynamic one. |
| 18809 | */ |
| 18810 | SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int id){ |
| 18811 | #ifndef SQLITE_OMIT_AUTOINIT |
| 18812 | if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0; |
| 18813 | if( id>SQLITE_MUTEX_RECURSIVE && sqlite3MutexInit() ) return 0; |
| 18814 | #endif |
| 18815 | return sqlite3GlobalConfig.mutex.xMutexAlloc(id); |
| 18816 | } |
| 18817 | |
| 18818 | SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int id){ |
| @@ -19265,16 +19070,12 @@ | |
| 19265 | pthread_mutex_init(&p->mutex, 0); |
| 19266 | } |
| 19267 | break; |
| 19268 | } |
| 19269 | default: { |
| 19270 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 19271 | if( iType-2<0 || iType-2>=ArraySize(staticMutexes) ){ |
| 19272 | (void)SQLITE_MISUSE_BKPT; |
| 19273 | return 0; |
| 19274 | } |
| 19275 | #endif |
| 19276 | p = &staticMutexes[iType-2]; |
| 19277 | #if SQLITE_MUTEX_NREF |
| 19278 | p->id = iType; |
| 19279 | #endif |
| 19280 | break; |
| @@ -20492,16 +20293,15 @@ | |
| 20492 | } |
| 20493 | assert( sqlite3_mutex_notheld(mem0.mutex) ); |
| 20494 | |
| 20495 | |
| 20496 | #if SQLITE_THREADSAFE==0 && !defined(NDEBUG) |
| 20497 | /* EVIDENCE-OF: R-12970-05880 SQLite will not use more than one scratch |
| 20498 | ** buffers per thread. |
| 20499 | ** |
| 20500 | ** This can only be checked in single-threaded mode. |
| 20501 | */ |
| 20502 | assert( scratchAllocOut==0 ); |
| 20503 | if( p ) scratchAllocOut++; |
| 20504 | #endif |
| 20505 | |
| 20506 | return p; |
| 20507 | } |
| @@ -21156,17 +20956,10 @@ | |
| 21156 | etByte flag_rtz; /* True if trailing zeros should be removed */ |
| 21157 | #endif |
| 21158 | PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */ |
| 21159 | char buf[etBUFSIZE]; /* Conversion buffer */ |
| 21160 | |
| 21161 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 21162 | if( ap==0 ){ |
| 21163 | (void)SQLITE_MISUSE_BKPT; |
| 21164 | sqlite3StrAccumReset(pAccum); |
| 21165 | return; |
| 21166 | } |
| 21167 | #endif |
| 21168 | bufpt = 0; |
| 21169 | if( bFlags ){ |
| 21170 | if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){ |
| 21171 | pArgList = va_arg(ap, PrintfArguments*); |
| 21172 | } |
| @@ -21703,15 +21496,10 @@ | |
| 21703 | return N; |
| 21704 | }else{ |
| 21705 | char *zOld = (p->zText==p->zBase ? 0 : p->zText); |
| 21706 | i64 szNew = p->nChar; |
| 21707 | szNew += N + 1; |
| 21708 | if( szNew+p->nChar<=p->mxAlloc ){ |
| 21709 | /* Force exponential buffer size growth as long as it does not overflow, |
| 21710 | ** to avoid having to call this routine too often */ |
| 21711 | szNew += p->nChar; |
| 21712 | } |
| 21713 | if( szNew > p->mxAlloc ){ |
| 21714 | sqlite3StrAccumReset(p); |
| 21715 | setStrAccumError(p, STRACCUM_TOOBIG); |
| 21716 | return 0; |
| 21717 | }else{ |
| @@ -21724,11 +21512,10 @@ | |
| 21724 | } |
| 21725 | if( zNew ){ |
| 21726 | assert( p->zText!=0 || p->nChar==0 ); |
| 21727 | if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); |
| 21728 | p->zText = zNew; |
| 21729 | p->nAlloc = sqlite3DbMallocSize(p->db, zNew); |
| 21730 | }else{ |
| 21731 | sqlite3StrAccumReset(p); |
| 21732 | setStrAccumError(p, STRACCUM_NOMEM); |
| 21733 | return 0; |
| 21734 | } |
| @@ -21894,17 +21681,10 @@ | |
| 21894 | */ |
| 21895 | SQLITE_API char *sqlite3_vmprintf(const char *zFormat, va_list ap){ |
| 21896 | char *z; |
| 21897 | char zBase[SQLITE_PRINT_BUF_SIZE]; |
| 21898 | StrAccum acc; |
| 21899 | |
| 21900 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 21901 | if( zFormat==0 ){ |
| 21902 | (void)SQLITE_MISUSE_BKPT; |
| 21903 | return 0; |
| 21904 | } |
| 21905 | #endif |
| 21906 | #ifndef SQLITE_OMIT_AUTOINIT |
| 21907 | if( sqlite3_initialize() ) return 0; |
| 21908 | #endif |
| 21909 | sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH); |
| 21910 | acc.useMalloc = 2; |
| @@ -21943,17 +21723,10 @@ | |
| 21943 | ** sqlite3_vsnprintf() is the varargs version. |
| 21944 | */ |
| 21945 | SQLITE_API char *sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){ |
| 21946 | StrAccum acc; |
| 21947 | if( n<=0 ) return zBuf; |
| 21948 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 21949 | if( zBuf==0 || zFormat==0 ) { |
| 21950 | (void)SQLITE_MISUSE_BKPT; |
| 21951 | if( zBuf && n>0 ) zBuf[0] = 0; |
| 21952 | return zBuf; |
| 21953 | } |
| 21954 | #endif |
| 21955 | sqlite3StrAccumInit(&acc, zBuf, n, 0); |
| 21956 | acc.useMalloc = 0; |
| 21957 | sqlite3VXPrintf(&acc, 0, zFormat, ap); |
| 21958 | return sqlite3StrAccumFinish(&acc); |
| 21959 | } |
| @@ -22141,23 +21914,15 @@ | |
| 22141 | #else |
| 22142 | # define wsdPrng sqlite3Prng |
| 22143 | #endif |
| 22144 | |
| 22145 | #if SQLITE_THREADSAFE |
| 22146 | sqlite3_mutex *mutex; |
| 22147 | #endif |
| 22148 | |
| 22149 | #ifndef SQLITE_OMIT_AUTOINIT |
| 22150 | if( sqlite3_initialize() ) return; |
| 22151 | #endif |
| 22152 | |
| 22153 | #if SQLITE_THREADSAFE |
| 22154 | mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG); |
| 22155 | #endif |
| 22156 | |
| 22157 | sqlite3_mutex_enter(mutex); |
| 22158 | if( N<=0 || pBuf==0 ){ |
| 22159 | wsdPrng.isInit = 0; |
| 22160 | sqlite3_mutex_leave(mutex); |
| 22161 | return; |
| 22162 | } |
| 22163 | |
| @@ -23275,27 +23040,17 @@ | |
| 23275 | ** case-independent fashion, using the same definition of "case |
| 23276 | ** independence" that SQLite uses internally when comparing identifiers. |
| 23277 | */ |
| 23278 | SQLITE_API int sqlite3_stricmp(const char *zLeft, const char *zRight){ |
| 23279 | register unsigned char *a, *b; |
| 23280 | if( zLeft==0 ){ |
| 23281 | return zRight ? -1 : 0; |
| 23282 | }else if( zRight==0 ){ |
| 23283 | return 1; |
| 23284 | } |
| 23285 | a = (unsigned char *)zLeft; |
| 23286 | b = (unsigned char *)zRight; |
| 23287 | while( *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; } |
| 23288 | return UpperToLower[*a] - UpperToLower[*b]; |
| 23289 | } |
| 23290 | SQLITE_API int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){ |
| 23291 | register unsigned char *a, *b; |
| 23292 | if( zLeft==0 ){ |
| 23293 | return zRight ? -1 : 0; |
| 23294 | }else if( zRight==0 ){ |
| 23295 | return 1; |
| 23296 | } |
| 23297 | a = (unsigned char *)zLeft; |
| 23298 | b = (unsigned char *)zRight; |
| 23299 | while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; } |
| 23300 | return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b]; |
| 23301 | } |
| @@ -32824,15 +32579,10 @@ | |
| 32824 | #if !SQLITE_OS_WINNT && !defined(SQLITE_OMIT_WAL) |
| 32825 | # error "WAL mode requires support from the Windows NT kernel, compile\ |
| 32826 | with SQLITE_OMIT_WAL." |
| 32827 | #endif |
| 32828 | |
| 32829 | #if !SQLITE_OS_WINNT && SQLITE_MAX_MMAP_SIZE>0 |
| 32830 | # error "Memory mapped files require support from the Windows NT kernel,\ |
| 32831 | compile with SQLITE_MAX_MMAP_SIZE=0." |
| 32832 | #endif |
| 32833 | |
| 32834 | /* |
| 32835 | ** Are most of the Win32 ANSI APIs available (i.e. with certain exceptions |
| 32836 | ** based on the sub-platform)? |
| 32837 | */ |
| 32838 | #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(SQLITE_WIN32_NO_ANSI) |
| @@ -32958,15 +32708,14 @@ | |
| 32958 | # define winGetDirSep() '\\' |
| 32959 | #endif |
| 32960 | |
| 32961 | /* |
| 32962 | ** Do we need to manually define the Win32 file mapping APIs for use with WAL |
| 32963 | ** mode or memory mapped files (e.g. these APIs are available in the Windows |
| 32964 | ** CE SDK; however, they are not present in the header file)? |
| 32965 | */ |
| 32966 | #if SQLITE_WIN32_FILEMAPPING_API && \ |
| 32967 | (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) |
| 32968 | /* |
| 32969 | ** Two of the file mapping APIs are different under WinRT. Figure out which |
| 32970 | ** set we need. |
| 32971 | */ |
| 32972 | #if SQLITE_OS_WINRT |
| @@ -32990,11 +32739,11 @@ | |
| 32990 | |
| 32991 | /* |
| 32992 | ** This file mapping API is common to both Win32 and WinRT. |
| 32993 | */ |
| 32994 | WINBASEAPI BOOL WINAPI UnmapViewOfFile(LPCVOID); |
| 32995 | #endif /* SQLITE_WIN32_FILEMAPPING_API */ |
| 32996 | |
| 32997 | /* |
| 32998 | ** Some Microsoft compilers lack this definition. |
| 32999 | */ |
| 33000 | #ifndef INVALID_FILE_ATTRIBUTES |
| @@ -33283,21 +33032,21 @@ | |
| 33283 | |
| 33284 | #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \ |
| 33285 | LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent) |
| 33286 | |
| 33287 | #if (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_ANSI) && \ |
| 33288 | (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)) |
| 33289 | { "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 }, |
| 33290 | #else |
| 33291 | { "CreateFileMappingA", (SYSCALL)0, 0 }, |
| 33292 | #endif |
| 33293 | |
| 33294 | #define osCreateFileMappingA ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \ |
| 33295 | DWORD,DWORD,DWORD,LPCSTR))aSyscall[6].pCurrent) |
| 33296 | |
| 33297 | #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \ |
| 33298 | (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)) |
| 33299 | { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 }, |
| 33300 | #else |
| 33301 | { "CreateFileMappingW", (SYSCALL)0, 0 }, |
| 33302 | #endif |
| 33303 | |
| @@ -33633,12 +33382,11 @@ | |
| 33633 | #ifndef osLockFileEx |
| 33634 | #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \ |
| 33635 | LPOVERLAPPED))aSyscall[48].pCurrent) |
| 33636 | #endif |
| 33637 | |
| 33638 | #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && \ |
| 33639 | (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)) |
| 33640 | { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 }, |
| 33641 | #else |
| 33642 | { "MapViewOfFile", (SYSCALL)0, 0 }, |
| 33643 | #endif |
| 33644 | |
| @@ -33704,11 +33452,11 @@ | |
| 33704 | #endif |
| 33705 | |
| 33706 | #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ |
| 33707 | LPOVERLAPPED))aSyscall[58].pCurrent) |
| 33708 | |
| 33709 | #if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 |
| 33710 | { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 }, |
| 33711 | #else |
| 33712 | { "UnmapViewOfFile", (SYSCALL)0, 0 }, |
| 33713 | #endif |
| 33714 | |
| @@ -33767,11 +33515,11 @@ | |
| 33767 | #endif |
| 33768 | |
| 33769 | #define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \ |
| 33770 | FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[66].pCurrent) |
| 33771 | |
| 33772 | #if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) |
| 33773 | { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 }, |
| 33774 | #else |
| 33775 | { "MapViewOfFileFromApp", (SYSCALL)0, 0 }, |
| 33776 | #endif |
| 33777 | |
| @@ -33831,11 +33579,11 @@ | |
| 33831 | |
| 33832 | { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 }, |
| 33833 | |
| 33834 | #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[74].pCurrent) |
| 33835 | |
| 33836 | #if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) |
| 33837 | { "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 }, |
| 33838 | #else |
| 33839 | { "CreateFileMappingFromApp", (SYSCALL)0, 0 }, |
| 33840 | #endif |
| 33841 | |
| @@ -39407,17 +39155,10 @@ | |
| 39407 | */ |
| 39408 | SQLITE_PRIVATE void sqlite3PcacheShrink(PCache *pCache){ |
| 39409 | assert( pCache->pCache!=0 ); |
| 39410 | sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache); |
| 39411 | } |
| 39412 | |
| 39413 | /* |
| 39414 | ** Return the size of the header added by this middleware layer |
| 39415 | ** in the page-cache hierarchy. |
| 39416 | */ |
| 39417 | SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return sizeof(PgHdr); } |
| 39418 | |
| 39419 | |
| 39420 | #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG) |
| 39421 | /* |
| 39422 | ** For all dirty pages currently in the cache, invoke the specified |
| 39423 | ** callback. This is only used if the SQLITE_CHECK_PAGES macro is |
| @@ -40413,15 +40154,10 @@ | |
| 40413 | pcache1Shrink /* xShrink */ |
| 40414 | }; |
| 40415 | sqlite3_config(SQLITE_CONFIG_PCACHE2, &defaultMethods); |
| 40416 | } |
| 40417 | |
| 40418 | /* |
| 40419 | ** Return the size of the header on each page of this PCACHE implementation. |
| 40420 | */ |
| 40421 | SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void){ return sizeof(PgHdr1); } |
| 40422 | |
| 40423 | #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 40424 | /* |
| 40425 | ** This function is called to free superfluous dynamically allocated memory |
| 40426 | ** held by the pager system. Memory in use by any SQLite pager allocated |
| 40427 | ** by the current thread may be sqlite3_free()ed. |
| @@ -47975,22 +47711,10 @@ | |
| 47975 | |
| 47976 | return SQLITE_OK; |
| 47977 | } |
| 47978 | #endif |
| 47979 | |
| 47980 | /* |
| 47981 | ** The page handle passed as the first argument refers to a dirty page |
| 47982 | ** with a page number other than iNew. This function changes the page's |
| 47983 | ** page number to iNew and sets the value of the PgHdr.flags field to |
| 47984 | ** the value passed as the third parameter. |
| 47985 | */ |
| 47986 | SQLITE_PRIVATE void sqlite3PagerRekey(DbPage *pPg, Pgno iNew, u16 flags){ |
| 47987 | assert( pPg->pgno!=iNew ); |
| 47988 | pPg->flags = flags; |
| 47989 | sqlite3PcacheMove(pPg, iNew); |
| 47990 | } |
| 47991 | |
| 47992 | /* |
| 47993 | ** Return a pointer to the data for the specified page. |
| 47994 | */ |
| 47995 | SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *pPg){ |
| 47996 | assert( pPg->nRef>0 || pPg->pPager->memDb ); |
| @@ -48384,11 +48108,10 @@ | |
| 48384 | SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager){ |
| 48385 | assert( pPager->eState>=PAGER_READER ); |
| 48386 | return sqlite3WalFramesize(pPager->pWal); |
| 48387 | } |
| 48388 | #endif |
| 48389 | |
| 48390 | |
| 48391 | #endif /* SQLITE_OMIT_DISKIO */ |
| 48392 | |
| 48393 | /************** End of pager.c ***********************************************/ |
| 48394 | /************** Begin file wal.c *********************************************/ |
| @@ -49895,11 +49618,11 @@ | |
| 49895 | |
| 49896 | /* |
| 49897 | ** Free an iterator allocated by walIteratorInit(). |
| 49898 | */ |
| 49899 | static void walIteratorFree(WalIterator *p){ |
| 49900 | sqlite3_free(p); |
| 49901 | } |
| 49902 | |
| 49903 | /* |
| 49904 | ** Construct a WalInterator object that can be used to loop over all |
| 49905 | ** pages in the WAL in ascending order. The caller must hold the checkpoint |
| @@ -49930,21 +49653,21 @@ | |
| 49930 | /* Allocate space for the WalIterator object. */ |
| 49931 | nSegment = walFramePage(iLast) + 1; |
| 49932 | nByte = sizeof(WalIterator) |
| 49933 | + (nSegment-1)*sizeof(struct WalSegment) |
| 49934 | + iLast*sizeof(ht_slot); |
| 49935 | p = (WalIterator *)sqlite3_malloc(nByte); |
| 49936 | if( !p ){ |
| 49937 | return SQLITE_NOMEM; |
| 49938 | } |
| 49939 | memset(p, 0, nByte); |
| 49940 | p->nSegment = nSegment; |
| 49941 | |
| 49942 | /* Allocate temporary space used by the merge-sort routine. This block |
| 49943 | ** of memory will be freed before this function returns. |
| 49944 | */ |
| 49945 | aTmp = (ht_slot *)sqlite3_malloc( |
| 49946 | sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast) |
| 49947 | ); |
| 49948 | if( !aTmp ){ |
| 49949 | rc = SQLITE_NOMEM; |
| 49950 | } |
| @@ -49977,11 +49700,11 @@ | |
| 49977 | p->aSegment[i].nEntry = nEntry; |
| 49978 | p->aSegment[i].aIndex = aIndex; |
| 49979 | p->aSegment[i].aPgno = (u32 *)aPgno; |
| 49980 | } |
| 49981 | } |
| 49982 | sqlite3_free(aTmp); |
| 49983 | |
| 49984 | if( rc!=SQLITE_OK ){ |
| 49985 | walIteratorFree(p); |
| 49986 | } |
| 49987 | *pp = p; |
| @@ -50897,11 +50620,11 @@ | |
| 50897 | ** was in before the client began writing to the database. |
| 50898 | */ |
| 50899 | memcpy(&pWal->hdr, (void *)walIndexHdr(pWal), sizeof(WalIndexHdr)); |
| 50900 | |
| 50901 | for(iFrame=pWal->hdr.mxFrame+1; |
| 50902 | rc==SQLITE_OK && iFrame<=iMax; |
| 50903 | iFrame++ |
| 50904 | ){ |
| 50905 | /* This call cannot fail. Unless the page for which the page number |
| 50906 | ** is passed as the second argument is (a) in the cache and |
| 50907 | ** (b) has an outstanding reference, then xUndo is either a no-op |
| @@ -53620,27 +53343,28 @@ | |
| 53620 | int cellOffset; /* Offset to the cell pointer array */ |
| 53621 | int cbrk; /* Offset to the cell content area */ |
| 53622 | int nCell; /* Number of cells on the page */ |
| 53623 | unsigned char *data; /* The page data */ |
| 53624 | unsigned char *temp; /* Temp area for cell content */ |
| 53625 | unsigned char *src; /* Source of content */ |
| 53626 | int iCellFirst; /* First allowable cell index */ |
| 53627 | int iCellLast; /* Last possible cell index */ |
| 53628 | |
| 53629 | |
| 53630 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 53631 | assert( pPage->pBt!=0 ); |
| 53632 | assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE ); |
| 53633 | assert( pPage->nOverflow==0 ); |
| 53634 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 53635 | temp = 0; |
| 53636 | src = data = pPage->aData; |
| 53637 | hdr = pPage->hdrOffset; |
| 53638 | cellOffset = pPage->cellOffset; |
| 53639 | nCell = pPage->nCell; |
| 53640 | assert( nCell==get2byte(&data[hdr+3]) ); |
| 53641 | usableSize = pPage->pBt->usableSize; |
| 53642 | cbrk = usableSize; |
| 53643 | iCellFirst = cellOffset + 2*nCell; |
| 53644 | iCellLast = usableSize - 4; |
| 53645 | for(i=0; i<nCell; i++){ |
| 53646 | u8 *pAddr; /* The i-th cell pointer */ |
| @@ -53655,11 +53379,11 @@ | |
| 53655 | if( pc<iCellFirst || pc>iCellLast ){ |
| 53656 | return SQLITE_CORRUPT_BKPT; |
| 53657 | } |
| 53658 | #endif |
| 53659 | assert( pc>=iCellFirst && pc<=iCellLast ); |
| 53660 | size = cellSizePtr(pPage, &src[pc]); |
| 53661 | cbrk -= size; |
| 53662 | #if defined(SQLITE_ENABLE_OVERSIZE_CELL_CHECK) |
| 53663 | if( cbrk<iCellFirst ){ |
| 53664 | return SQLITE_CORRUPT_BKPT; |
| 53665 | } |
| @@ -53669,20 +53393,12 @@ | |
| 53669 | } |
| 53670 | #endif |
| 53671 | assert( cbrk+size<=usableSize && cbrk>=iCellFirst ); |
| 53672 | testcase( cbrk+size==usableSize ); |
| 53673 | testcase( pc+size==usableSize ); |
| 53674 | put2byte(pAddr, cbrk); |
| 53675 | if( temp==0 ){ |
| 53676 | int x; |
| 53677 | if( cbrk==pc ) continue; |
| 53678 | temp = sqlite3PagerTempSpace(pPage->pBt->pPager); |
| 53679 | x = get2byte(&data[hdr+5]); |
| 53680 | memcpy(&temp[x], &data[x], (cbrk+size) - x); |
| 53681 | src = temp; |
| 53682 | } |
| 53683 | memcpy(&data[cbrk], &src[pc], size); |
| 53684 | } |
| 53685 | assert( cbrk>=iCellFirst ); |
| 53686 | put2byte(&data[hdr+5], cbrk); |
| 53687 | data[hdr+1] = 0; |
| 53688 | data[hdr+2] = 0; |
| @@ -53693,66 +53409,10 @@ | |
| 53693 | return SQLITE_CORRUPT_BKPT; |
| 53694 | } |
| 53695 | return SQLITE_OK; |
| 53696 | } |
| 53697 | |
| 53698 | /* |
| 53699 | ** Search the free-list on page pPg for space to store a cell nByte bytes in |
| 53700 | ** size. If one can be found, return a pointer to the space and remove it |
| 53701 | ** from the free-list. |
| 53702 | ** |
| 53703 | ** If no suitable space can be found on the free-list, return NULL. |
| 53704 | ** |
| 53705 | ** This function may detect corruption within pPg. If corruption is |
| 53706 | ** detected then *pRc is set to SQLITE_CORRUPT and NULL is returned. |
| 53707 | ** |
| 53708 | ** If a slot of at least nByte bytes is found but cannot be used because |
| 53709 | ** there are already at least 60 fragmented bytes on the page, return NULL. |
| 53710 | ** In this case, if pbDefrag parameter is not NULL, set *pbDefrag to true. |
| 53711 | */ |
| 53712 | static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc, int *pbDefrag){ |
| 53713 | const int hdr = pPg->hdrOffset; |
| 53714 | u8 * const aData = pPg->aData; |
| 53715 | int iAddr; |
| 53716 | int pc; |
| 53717 | int usableSize = pPg->pBt->usableSize; |
| 53718 | |
| 53719 | for(iAddr=hdr+1; (pc = get2byte(&aData[iAddr]))>0; iAddr=pc){ |
| 53720 | int size; /* Size of the free slot */ |
| 53721 | if( pc>usableSize-4 || pc<iAddr+4 ){ |
| 53722 | *pRc = SQLITE_CORRUPT_BKPT; |
| 53723 | return 0; |
| 53724 | } |
| 53725 | size = get2byte(&aData[pc+2]); |
| 53726 | if( size>=nByte ){ |
| 53727 | int x = size - nByte; |
| 53728 | testcase( x==4 ); |
| 53729 | testcase( x==3 ); |
| 53730 | if( x<4 ){ |
| 53731 | if( aData[hdr+7]>=60 ){ |
| 53732 | if( pbDefrag ) *pbDefrag = 1; |
| 53733 | return 0; |
| 53734 | } |
| 53735 | /* Remove the slot from the free-list. Update the number of |
| 53736 | ** fragmented bytes within the page. */ |
| 53737 | memcpy(&aData[iAddr], &aData[pc], 2); |
| 53738 | aData[hdr+7] += (u8)x; |
| 53739 | }else if( size+pc > usableSize ){ |
| 53740 | *pRc = SQLITE_CORRUPT_BKPT; |
| 53741 | return 0; |
| 53742 | }else{ |
| 53743 | /* The slot remains on the free-list. Reduce its size to account |
| 53744 | ** for the portion used by the new allocation. */ |
| 53745 | put2byte(&aData[pc+2], x); |
| 53746 | } |
| 53747 | return &aData[pc + x]; |
| 53748 | } |
| 53749 | } |
| 53750 | |
| 53751 | return 0; |
| 53752 | } |
| 53753 | |
| 53754 | /* |
| 53755 | ** Allocate nByte bytes of space from within the B-Tree page passed |
| 53756 | ** as the first argument. Write into *pIdx the index into pPage->aData[] |
| 53757 | ** of the first byte of allocated space. Return either SQLITE_OK or |
| 53758 | ** an error code (usually SQLITE_CORRUPT). |
| @@ -53766,20 +53426,22 @@ | |
| 53766 | */ |
| 53767 | static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ |
| 53768 | const int hdr = pPage->hdrOffset; /* Local cache of pPage->hdrOffset */ |
| 53769 | u8 * const data = pPage->aData; /* Local cache of pPage->aData */ |
| 53770 | int top; /* First byte of cell content area */ |
| 53771 | int rc = SQLITE_OK; /* Integer return code */ |
| 53772 | int gap; /* First byte of gap between cell pointers and cell content */ |
| 53773 | |
| 53774 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 53775 | assert( pPage->pBt ); |
| 53776 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 53777 | assert( nByte>=0 ); /* Minimum cell size is 4 */ |
| 53778 | assert( pPage->nFree>=nByte ); |
| 53779 | assert( pPage->nOverflow==0 ); |
| 53780 | assert( nByte < (int)(pPage->pBt->usableSize-8) ); |
| 53781 | |
| 53782 | assert( pPage->cellOffset == hdr + 12 - 4*pPage->leaf ); |
| 53783 | gap = pPage->cellOffset + 2*pPage->nCell; |
| 53784 | assert( gap<=65536 ); |
| 53785 | top = get2byte(&data[hdr+5]); |
| @@ -53797,27 +53459,46 @@ | |
| 53797 | */ |
| 53798 | testcase( gap+2==top ); |
| 53799 | testcase( gap+1==top ); |
| 53800 | testcase( gap==top ); |
| 53801 | if( gap+2<=top && (data[hdr+1] || data[hdr+2]) ){ |
| 53802 | int bDefrag = 0; |
| 53803 | u8 *pSpace = pageFindSlot(pPage, nByte, &rc, &bDefrag); |
| 53804 | if( rc ) return rc; |
| 53805 | if( bDefrag ) goto defragment_page; |
| 53806 | if( pSpace ){ |
| 53807 | assert( pSpace>=data && (pSpace - data)<65536 ); |
| 53808 | *pIdx = (int)(pSpace - data); |
| 53809 | return SQLITE_OK; |
| 53810 | } |
| 53811 | } |
| 53812 | |
| 53813 | /* The request could not be fulfilled using a freelist slot. Check |
| 53814 | ** to see if defragmentation is necessary. |
| 53815 | */ |
| 53816 | testcase( gap+2+nByte==top ); |
| 53817 | if( gap+2+nByte>top ){ |
| 53818 | defragment_page: |
| 53819 | testcase( pPage->nCell==0 ); |
| 53820 | rc = defragmentPage(pPage); |
| 53821 | if( rc ) return rc; |
| 53822 | top = get2byteNotZero(&data[hdr+5]); |
| 53823 | assert( gap+nByte<=top ); |
| @@ -53861,11 +53542,11 @@ | |
| 53861 | unsigned char *data = pPage->aData; /* Page content */ |
| 53862 | |
| 53863 | assert( pPage->pBt!=0 ); |
| 53864 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 53865 | assert( iStart>=pPage->hdrOffset+6+pPage->childPtrSize ); |
| 53866 | assert( CORRUPT_DB || iEnd <= pPage->pBt->usableSize ); |
| 53867 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 53868 | assert( iSize>=4 ); /* Minimum cell size is 4 */ |
| 53869 | assert( iStart<=iLast ); |
| 53870 | |
| 53871 | /* Overwrite deleted information with zeros when the secure_delete |
| @@ -58476,266 +58157,49 @@ | |
| 58476 | #endif |
| 58477 | } |
| 58478 | } |
| 58479 | |
| 58480 | /* |
| 58481 | ** Array apCell[] contains pointers to nCell b-tree page cells. The |
| 58482 | ** szCell[] array contains the size in bytes of each cell. This function |
| 58483 | ** replaces the current contents of page pPg with the contents of the cell |
| 58484 | ** array. |
| 58485 | ** |
| 58486 | ** Some of the cells in apCell[] may currently be stored in pPg. This |
| 58487 | ** function works around problems caused by this by making a copy of any |
| 58488 | ** such cells before overwriting the page data. |
| 58489 | ** |
| 58490 | ** The MemPage.nFree field is invalidated by this function. It is the |
| 58491 | ** responsibility of the caller to set it correctly. |
| 58492 | */ |
| 58493 | static void rebuildPage( |
| 58494 | MemPage *pPg, /* Edit this page */ |
| 58495 | int nCell, /* Final number of cells on page */ |
| 58496 | u8 **apCell, /* Array of cells */ |
| 58497 | u16 *szCell /* Array of cell sizes */ |
| 58498 | ){ |
| 58499 | const int hdr = pPg->hdrOffset; /* Offset of header on pPg */ |
| 58500 | u8 * const aData = pPg->aData; /* Pointer to data for pPg */ |
| 58501 | const int usableSize = pPg->pBt->usableSize; |
| 58502 | u8 * const pEnd = &aData[usableSize]; |
| 58503 | int i; |
| 58504 | u8 *pCellptr = pPg->aCellIdx; |
| 58505 | u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager); |
| 58506 | u8 *pData; |
| 58507 | |
| 58508 | i = get2byte(&aData[hdr+5]); |
| 58509 | memcpy(&pTmp[i], &aData[i], usableSize - i); |
| 58510 | |
| 58511 | pData = pEnd; |
| 58512 | for(i=0; i<nCell; i++){ |
| 58513 | u8 *pCell = apCell[i]; |
| 58514 | if( pCell>aData && pCell<pEnd ){ |
| 58515 | pCell = &pTmp[pCell - aData]; |
| 58516 | } |
| 58517 | pData -= szCell[i]; |
| 58518 | memcpy(pData, pCell, szCell[i]); |
| 58519 | put2byte(pCellptr, (pData - aData)); |
| 58520 | pCellptr += 2; |
| 58521 | assert( szCell[i]==cellSizePtr(pPg, pCell) ); |
| 58522 | } |
| 58523 | |
| 58524 | /* The pPg->nFree field is now set incorrectly. The caller will fix it. */ |
| 58525 | pPg->nCell = nCell; |
| 58526 | pPg->nOverflow = 0; |
| 58527 | |
| 58528 | put2byte(&aData[hdr+1], 0); |
| 58529 | put2byte(&aData[hdr+3], pPg->nCell); |
| 58530 | put2byte(&aData[hdr+5], pData - aData); |
| 58531 | aData[hdr+7] = 0x00; |
| 58532 | } |
| 58533 | |
| 58534 | /* |
| 58535 | ** Array apCell[] contains nCell pointers to b-tree cells. Array szCell |
| 58536 | ** contains the size in bytes of each such cell. This function attempts to |
| 58537 | ** add the cells stored in the array to page pPg. If it cannot (because |
| 58538 | ** the page needs to be defragmented before the cells will fit), non-zero |
| 58539 | ** is returned. Otherwise, if the cells are added successfully, zero is |
| 58540 | ** returned. |
| 58541 | ** |
| 58542 | ** Argument pCellptr points to the first entry in the cell-pointer array |
| 58543 | ** (part of page pPg) to populate. After cell apCell[0] is written to the |
| 58544 | ** page body, a 16-bit offset is written to pCellptr. And so on, for each |
| 58545 | ** cell in the array. It is the responsibility of the caller to ensure |
| 58546 | ** that it is safe to overwrite this part of the cell-pointer array. |
| 58547 | ** |
| 58548 | ** When this function is called, *ppData points to the start of the |
| 58549 | ** content area on page pPg. If the size of the content area is extended, |
| 58550 | ** *ppData is updated to point to the new start of the content area |
| 58551 | ** before returning. |
| 58552 | ** |
| 58553 | ** Finally, argument pBegin points to the byte immediately following the |
| 58554 | ** end of the space required by this page for the cell-pointer area (for |
| 58555 | ** all cells - not just those inserted by the current call). If the content |
| 58556 | ** area must be extended to before this point in order to accomodate all |
| 58557 | ** cells in apCell[], then the cells do not fit and non-zero is returned. |
| 58558 | */ |
| 58559 | static int pageInsertArray( |
| 58560 | MemPage *pPg, /* Page to add cells to */ |
| 58561 | u8 *pBegin, /* End of cell-pointer array */ |
| 58562 | u8 **ppData, /* IN/OUT: Page content -area pointer */ |
| 58563 | u8 *pCellptr, /* Pointer to cell-pointer area */ |
| 58564 | int nCell, /* Number of cells to add to pPg */ |
| 58565 | u8 **apCell, /* Array of cells */ |
| 58566 | u16 *szCell /* Array of cell sizes */ |
| 58567 | ){ |
| 58568 | int i; |
| 58569 | u8 *aData = pPg->aData; |
| 58570 | u8 *pData = *ppData; |
| 58571 | const int bFreelist = aData[1] || aData[2]; |
| 58572 | assert( CORRUPT_DB || pPg->hdrOffset==0 ); /* Never called on page 1 */ |
| 58573 | for(i=0; i<nCell; i++){ |
| 58574 | int sz = szCell[i]; |
| 58575 | int rc; |
| 58576 | u8 *pSlot; |
| 58577 | if( bFreelist==0 || (pSlot = pageFindSlot(pPg, sz, &rc, 0))==0 ){ |
| 58578 | pData -= sz; |
| 58579 | if( pData<pBegin ) return 1; |
| 58580 | pSlot = pData; |
| 58581 | } |
| 58582 | memcpy(pSlot, apCell[i], sz); |
| 58583 | put2byte(pCellptr, (pSlot - aData)); |
| 58584 | pCellptr += 2; |
| 58585 | } |
| 58586 | *ppData = pData; |
| 58587 | return 0; |
| 58588 | } |
| 58589 | |
| 58590 | /* |
| 58591 | ** Array apCell[] contains nCell pointers to b-tree cells. Array szCell |
| 58592 | ** contains the size in bytes of each such cell. This function adds the |
| 58593 | ** space associated with each cell in the array that is currently stored |
| 58594 | ** within the body of pPg to the pPg free-list. The cell-pointers and other |
| 58595 | ** fields of the page are not updated. |
| 58596 | ** |
| 58597 | ** This function returns the total number of cells added to the free-list. |
| 58598 | */ |
| 58599 | static int pageFreeArray( |
| 58600 | MemPage *pPg, /* Page to edit */ |
| 58601 | int nCell, /* Cells to delete */ |
| 58602 | u8 **apCell, /* Array of cells */ |
| 58603 | u16 *szCell /* Array of cell sizes */ |
| 58604 | ){ |
| 58605 | u8 * const aData = pPg->aData; |
| 58606 | u8 * const pEnd = &aData[pPg->pBt->usableSize]; |
| 58607 | u8 * const pStart = &aData[pPg->hdrOffset + 8 + pPg->childPtrSize]; |
| 58608 | int nRet = 0; |
| 58609 | int i; |
| 58610 | u8 *pFree = 0; |
| 58611 | int szFree = 0; |
| 58612 | |
| 58613 | for(i=0; i<nCell; i++){ |
| 58614 | u8 *pCell = apCell[i]; |
| 58615 | if( pCell>=pStart && pCell<pEnd ){ |
| 58616 | int sz = szCell[i]; |
| 58617 | if( pFree!=(pCell + sz) ){ |
| 58618 | if( pFree ){ |
| 58619 | assert( pFree>aData && (pFree - aData)<65536 ); |
| 58620 | freeSpace(pPg, (u16)(pFree - aData), szFree); |
| 58621 | } |
| 58622 | pFree = pCell; |
| 58623 | szFree = sz; |
| 58624 | if( pFree+sz>pEnd ) return 0; |
| 58625 | }else{ |
| 58626 | pFree = pCell; |
| 58627 | szFree += sz; |
| 58628 | } |
| 58629 | nRet++; |
| 58630 | } |
| 58631 | } |
| 58632 | if( pFree ){ |
| 58633 | assert( pFree>aData && (pFree - aData)<65536 ); |
| 58634 | freeSpace(pPg, (u16)(pFree - aData), szFree); |
| 58635 | } |
| 58636 | return nRet; |
| 58637 | } |
| 58638 | |
| 58639 | /* |
| 58640 | ** The pPg->nFree field is invalid when this function returns. It is the |
| 58641 | ** responsibility of the caller to set it correctly. |
| 58642 | */ |
| 58643 | static void editPage( |
| 58644 | MemPage *pPg, /* Edit this page */ |
| 58645 | int iOld, /* Index of first cell currently on page */ |
| 58646 | int iNew, /* Index of new first cell on page */ |
| 58647 | int nNew, /* Final number of cells on page */ |
| 58648 | u8 **apCell, /* Array of cells */ |
| 58649 | u16 *szCell /* Array of cell sizes */ |
| 58650 | ){ |
| 58651 | u8 * const aData = pPg->aData; |
| 58652 | const int hdr = pPg->hdrOffset; |
| 58653 | u8 *pBegin = &pPg->aCellIdx[nNew * 2]; |
| 58654 | int nCell = pPg->nCell; /* Cells stored on pPg */ |
| 58655 | u8 *pData; |
| 58656 | u8 *pCellptr; |
| 58657 | int i; |
| 58658 | int iOldEnd = iOld + pPg->nCell + pPg->nOverflow; |
| 58659 | int iNewEnd = iNew + nNew; |
| 58660 | |
| 58661 | #ifdef SQLITE_DEBUG |
| 58662 | u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager); |
| 58663 | memcpy(pTmp, aData, pPg->pBt->usableSize); |
| 58664 | #endif |
| 58665 | |
| 58666 | /* Remove cells from the start and end of the page */ |
| 58667 | if( iOld<iNew ){ |
| 58668 | int nShift = pageFreeArray( |
| 58669 | pPg, iNew-iOld, &apCell[iOld], &szCell[iOld] |
| 58670 | ); |
| 58671 | memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2); |
| 58672 | nCell -= nShift; |
| 58673 | } |
| 58674 | if( iNewEnd < iOldEnd ){ |
| 58675 | nCell -= pageFreeArray( |
| 58676 | pPg, iOldEnd-iNewEnd, &apCell[iNewEnd], &szCell[iNewEnd] |
| 58677 | ); |
| 58678 | } |
| 58679 | |
| 58680 | pData = &aData[get2byte(&aData[hdr+5])]; |
| 58681 | if( pData<pBegin ) goto editpage_fail; |
| 58682 | |
| 58683 | /* Add cells to the start of the page */ |
| 58684 | if( iNew<iOld ){ |
| 58685 | int nAdd = iOld-iNew; |
| 58686 | pCellptr = pPg->aCellIdx; |
| 58687 | memmove(&pCellptr[nAdd*2], pCellptr, nCell*2); |
| 58688 | if( pageInsertArray( |
| 58689 | pPg, pBegin, &pData, pCellptr, |
| 58690 | nAdd, &apCell[iNew], &szCell[iNew] |
| 58691 | ) ) goto editpage_fail; |
| 58692 | nCell += nAdd; |
| 58693 | } |
| 58694 | |
| 58695 | /* Add any overflow cells */ |
| 58696 | for(i=0; i<pPg->nOverflow; i++){ |
| 58697 | int iCell = (iOld + pPg->aiOvfl[i]) - iNew; |
| 58698 | if( iCell>=0 && iCell<nNew ){ |
| 58699 | pCellptr = &pPg->aCellIdx[iCell * 2]; |
| 58700 | memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2); |
| 58701 | nCell++; |
| 58702 | if( pageInsertArray( |
| 58703 | pPg, pBegin, &pData, pCellptr, |
| 58704 | 1, &apCell[iCell + iNew], &szCell[iCell + iNew] |
| 58705 | ) ) goto editpage_fail; |
| 58706 | } |
| 58707 | } |
| 58708 | |
| 58709 | /* Append cells to the end of the page */ |
| 58710 | pCellptr = &pPg->aCellIdx[nCell*2]; |
| 58711 | if( pageInsertArray( |
| 58712 | pPg, pBegin, &pData, pCellptr, |
| 58713 | nNew-nCell, &apCell[iNew+nCell], &szCell[iNew+nCell] |
| 58714 | ) ) goto editpage_fail; |
| 58715 | |
| 58716 | pPg->nCell = nNew; |
| 58717 | pPg->nOverflow = 0; |
| 58718 | |
| 58719 | put2byte(&aData[hdr+3], pPg->nCell); |
| 58720 | put2byte(&aData[hdr+5], pData - aData); |
| 58721 | |
| 58722 | #ifdef SQLITE_DEBUG |
| 58723 | for(i=0; i<nNew && !CORRUPT_DB; i++){ |
| 58724 | u8 *pCell = apCell[i+iNew]; |
| 58725 | int iOff = get2byte(&pPg->aCellIdx[i*2]); |
| 58726 | if( pCell>=aData && pCell<&aData[pPg->pBt->usableSize] ){ |
| 58727 | pCell = &pTmp[pCell - aData]; |
| 58728 | } |
| 58729 | assert( 0==memcmp(pCell, &aData[iOff], szCell[i+iNew]) ); |
| 58730 | } |
| 58731 | #endif |
| 58732 | |
| 58733 | return; |
| 58734 | editpage_fail: |
| 58735 | /* Unable to edit this page. Rebuild it from scratch instead. */ |
| 58736 | rebuildPage(pPg, nNew, &apCell[iNew], &szCell[iNew]); |
| 58737 | } |
| 58738 | |
| 58739 | /* |
| 58740 | ** The following parameters determine how many adjacent pages get involved |
| 58741 | ** in a balancing operation. NN is the number of neighbors on either side |
| @@ -58803,12 +58267,11 @@ | |
| 58803 | u8 *pStop; |
| 58804 | |
| 58805 | assert( sqlite3PagerIswriteable(pNew->pDbPage) ); |
| 58806 | assert( pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) ); |
| 58807 | zeroPage(pNew, PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF); |
| 58808 | rebuildPage(pNew, 1, &pCell, &szCell); |
| 58809 | pNew->nFree = pBt->usableSize - pNew->cellOffset - 2 - szCell; |
| 58810 | |
| 58811 | /* If this is an auto-vacuum database, update the pointer map |
| 58812 | ** with entries for the new page, and any pointer from the |
| 58813 | ** cell on the page to an overflow page. If either of these |
| 58814 | ** operations fails, the return code is set, but the contents |
| @@ -59023,26 +58486,21 @@ | |
| 59023 | int subtotal; /* Subtotal of bytes in cells on one page */ |
| 59024 | int iSpace1 = 0; /* First unused byte of aSpace1[] */ |
| 59025 | int iOvflSpace = 0; /* First unused byte of aOvflSpace[] */ |
| 59026 | int szScratch; /* Size of scratch memory requested */ |
| 59027 | MemPage *apOld[NB]; /* pPage and up to two siblings */ |
| 59028 | MemPage *apNew[NB+2]; /* pPage and up to NB siblings after balancing */ |
| 59029 | u8 *pRight; /* Location in parent of right-sibling pointer */ |
| 59030 | u8 *apDiv[NB-1]; /* Divider cells in pParent */ |
| 59031 | int cntNew[NB+2]; /* Index in aCell[] of cell after i-th page */ |
| 59032 | int cntOld[NB+2]; /* Old index in aCell[] after i-th page */ |
| 59033 | int szNew[NB+2]; /* Combined size of cells placed on i-th page */ |
| 59034 | u8 **apCell = 0; /* All cells begin balanced */ |
| 59035 | u16 *szCell; /* Local size of all cells in apCell[] */ |
| 59036 | u8 *aSpace1; /* Space for copies of dividers cells */ |
| 59037 | Pgno pgno; /* Temp var to store a page number in */ |
| 59038 | u8 abDone[NB+2]; /* True after i'th new page is populated */ |
| 59039 | Pgno aPgno[NB+2]; /* Page numbers of new pages before shuffling */ |
| 59040 | Pgno aPgOrder[NB+2]; /* Copy of aPgno[] used for sorting pages */ |
| 59041 | u16 aPgFlags[NB+2]; /* flags field of new pages before shuffling */ |
| 59042 | |
| 59043 | memset(abDone, 0, sizeof(abDone)); |
| 59044 | pBt = pParent->pBt; |
| 59045 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 59046 | assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 59047 | |
| 59048 | #if 0 |
| @@ -59147,18 +58605,16 @@ | |
| 59147 | nMaxCells = (nMaxCells + 3)&~3; |
| 59148 | |
| 59149 | /* |
| 59150 | ** Allocate space for memory structures |
| 59151 | */ |
| 59152 | szScratch = |
| 59153 | nMaxCells*sizeof(u8*) /* apCell */ |
| 59154 | + nMaxCells*sizeof(u16) /* szCell */ |
| 59155 | + pBt->pageSize; /* aSpace1 */ |
| 59156 | |
| 59157 | /* EVIDENCE-OF: R-28375-38319 SQLite will never request a scratch buffer |
| 59158 | ** that is more than 6 times the database page size. */ |
| 59159 | assert( szScratch<=6*pBt->pageSize ); |
| 59160 | apCell = sqlite3ScratchMalloc( szScratch ); |
| 59161 | if( apCell==0 ){ |
| 59162 | rc = SQLITE_NOMEM; |
| 59163 | goto balance_cleanup; |
| 59164 | } |
| @@ -59167,12 +58623,12 @@ | |
| 59167 | assert( EIGHT_BYTE_ALIGNMENT(aSpace1) ); |
| 59168 | |
| 59169 | /* |
| 59170 | ** Load pointers to all cells on sibling pages and the divider cells |
| 59171 | ** into the local apCell[] array. Make copies of the divider cells |
| 59172 | ** into space obtained from aSpace1[]. The divider cells have already |
| 59173 | ** been removed from pParent. |
| 59174 | ** |
| 59175 | ** If the siblings are on leaf pages, then the child pointers of the |
| 59176 | ** divider cells are stripped from the cells before they are copied |
| 59177 | ** into aSpace1[]. In this way, all cells in apCell[] are without |
| 59178 | ** child pointers. If siblings are not leaves, then all cell in |
| @@ -59184,11 +58640,19 @@ | |
| 59184 | */ |
| 59185 | leafCorrection = apOld[0]->leaf*4; |
| 59186 | leafData = apOld[0]->intKeyLeaf; |
| 59187 | for(i=0; i<nOld; i++){ |
| 59188 | int limit; |
| 59189 | MemPage *pOld = apOld[i]; |
| 59190 | |
| 59191 | limit = pOld->nCell+pOld->nOverflow; |
| 59192 | if( pOld->nOverflow>0 ){ |
| 59193 | for(j=0; j<limit; j++){ |
| 59194 | assert( nCell<nMaxCells ); |
| @@ -59205,11 +58669,10 @@ | |
| 59205 | apCell[nCell] = findCellv2(aData, maskPage, cellOffset, j); |
| 59206 | szCell[nCell] = cellSizePtr(pOld, apCell[nCell]); |
| 59207 | nCell++; |
| 59208 | } |
| 59209 | } |
| 59210 | cntOld[i] = nCell; |
| 59211 | if( i<nOld-1 && !leafData){ |
| 59212 | u16 sz = (u16)szNew[i]; |
| 59213 | u8 *pTemp; |
| 59214 | assert( nCell<nMaxCells ); |
| 59215 | szCell[nCell] = sz; |
| @@ -59257,11 +58720,11 @@ | |
| 59257 | usableSpace = pBt->usableSize - 12 + leafCorrection; |
| 59258 | for(subtotal=k=i=0; i<nCell; i++){ |
| 59259 | assert( i<nMaxCells ); |
| 59260 | subtotal += szCell[i] + 2; |
| 59261 | if( subtotal > usableSpace ){ |
| 59262 | szNew[k] = subtotal - szCell[i] - 2; |
| 59263 | cntNew[k] = i; |
| 59264 | if( leafData ){ i--; } |
| 59265 | subtotal = 0; |
| 59266 | k++; |
| 59267 | if( k>NB+1 ){ rc = SQLITE_CORRUPT_BKPT; goto balance_cleanup; } |
| @@ -59271,14 +58734,13 @@ | |
| 59271 | cntNew[k] = nCell; |
| 59272 | k++; |
| 59273 | |
| 59274 | /* |
| 59275 | ** The packing computed by the previous block is biased toward the siblings |
| 59276 | ** on the left side (siblings with smaller keys). The left siblings are |
| 59277 | ** always nearly full, while the right-most sibling might be nearly empty. |
| 59278 | ** The next block of code attempts to adjust the packing of siblings to |
| 59279 | ** get a better balance. |
| 59280 | ** |
| 59281 | ** This adjustment is more than an optimization. The packing above might |
| 59282 | ** be so out of balance as to be illegal. For example, the right-most |
| 59283 | ** sibling might be completely empty. This adjustment is not optional. |
| 59284 | */ |
| @@ -59303,22 +58765,26 @@ | |
| 59303 | } |
| 59304 | szNew[i] = szRight; |
| 59305 | szNew[i-1] = szLeft; |
| 59306 | } |
| 59307 | |
| 59308 | /* Sanity check: For a non-corrupt database file one of the follwing |
| 59309 | ** must be true: |
| 59310 | ** (1) We found one or more cells (cntNew[0])>0), or |
| 59311 | ** (2) pPage is a virtual root page. A virtual root page is when |
| 59312 | ** the real root page is page 1 and we are the only child of |
| 59313 | ** that page. |
| 59314 | */ |
| 59315 | assert( cntNew[0]>0 || (pParent->pgno==1 && pParent->nCell==0) || CORRUPT_DB); |
| 59316 | TRACE(("BALANCE: old: %d(nc=%d) %d(nc=%d) %d(nc=%d)\n", |
| 59317 | apOld[0]->pgno, apOld[0]->nCell, |
| 59318 | nOld>=2 ? apOld[1]->pgno : 0, nOld>=2 ? apOld[1]->nCell : 0, |
| 59319 | nOld>=3 ? apOld[2]->pgno : 0, nOld>=3 ? apOld[2]->nCell : 0 |
| 59320 | )); |
| 59321 | |
| 59322 | /* |
| 59323 | ** Allocate k new pages. Reuse old pages where possible. |
| 59324 | */ |
| @@ -59337,14 +58803,12 @@ | |
| 59337 | if( rc ) goto balance_cleanup; |
| 59338 | }else{ |
| 59339 | assert( i>0 ); |
| 59340 | rc = allocateBtreePage(pBt, &pNew, &pgno, (bBulk ? 1 : pgno), 0); |
| 59341 | if( rc ) goto balance_cleanup; |
| 59342 | zeroPage(pNew, pageFlags); |
| 59343 | apNew[i] = pNew; |
| 59344 | nNew++; |
| 59345 | cntOld[i] = nCell; |
| 59346 | |
| 59347 | /* Set the pointer-map entry for the new sibling page. */ |
| 59348 | if( ISAUTOVACUUM ){ |
| 59349 | ptrmapPut(pBt, pNew->pgno, PTRMAP_BTREE, pParent->pgno, &rc); |
| 59350 | if( rc!=SQLITE_OK ){ |
| @@ -59351,248 +58815,140 @@ | |
| 59351 | goto balance_cleanup; |
| 59352 | } |
| 59353 | } |
| 59354 | } |
| 59355 | } |
| 59356 | |
| 59357 | /* |
| 59358 | ** Reassign page numbers so that the new pages are in ascending order. |
| 59359 | ** This helps to keep entries in the disk file in order so that a scan |
| 59360 | ** of the table is closer to a linear scan through the file. That in turn |
| 59361 | ** helps the operating system to deliver pages from the disk more rapidly. |
| 59362 | ** |
| 59363 | ** An O(n^2) insertion sort algorithm is used, but since n is never more |
| 59364 | ** than (NB+2) (a small constant), that should not be a problem. |
| 59365 | ** |
| 59366 | ** When NB==3, this one optimization makes the database about 25% faster |
| 59367 | ** for large insertions and deletions. |
| 59368 | */ |
| 59369 | for(i=0; i<nNew; i++){ |
| 59370 | aPgOrder[i] = aPgno[i] = apNew[i]->pgno; |
| 59371 | aPgFlags[i] = apNew[i]->pDbPage->flags; |
| 59372 | for(j=0; j<i; j++){ |
| 59373 | if( aPgno[j]==aPgno[i] ){ |
| 59374 | /* This branch is taken if the set of sibling pages somehow contains |
| 59375 | ** duplicate entries. This can happen if the database is corrupt. |
| 59376 | ** It would be simpler to detect this as part of the loop below, but |
| 59377 | ** we do the detection here in order to avoid populating the pager |
| 59378 | ** cache with two separate objects associated with the same |
| 59379 | ** page number. */ |
| 59380 | assert( CORRUPT_DB ); |
| 59381 | rc = SQLITE_CORRUPT_BKPT; |
| 59382 | goto balance_cleanup; |
| 59383 | } |
| 59384 | } |
| 59385 | } |
| 59386 | for(i=0; i<nNew; i++){ |
| 59387 | int iBest = 0; /* aPgno[] index of page number to use */ |
| 59388 | for(j=1; j<nNew; j++){ |
| 59389 | if( aPgOrder[j]<aPgOrder[iBest] ) iBest = j; |
| 59390 | } |
| 59391 | pgno = aPgOrder[iBest]; |
| 59392 | aPgOrder[iBest] = 0xffffffff; |
| 59393 | if( iBest!=i ){ |
| 59394 | if( iBest>i ){ |
| 59395 | sqlite3PagerRekey(apNew[iBest]->pDbPage, pBt->nPage+iBest+1, 0); |
| 59396 | } |
| 59397 | sqlite3PagerRekey(apNew[i]->pDbPage, pgno, aPgFlags[iBest]); |
| 59398 | apNew[i]->pgno = pgno; |
| 59399 | } |
| 59400 | } |
| 59401 | |
| 59402 | TRACE(("BALANCE: new: %d(%d nc=%d) %d(%d nc=%d) %d(%d nc=%d) " |
| 59403 | "%d(%d nc=%d) %d(%d nc=%d)\n", |
| 59404 | apNew[0]->pgno, szNew[0], cntNew[0], |
| 59405 | nNew>=2 ? apNew[1]->pgno : 0, nNew>=2 ? szNew[1] : 0, |
| 59406 | nNew>=2 ? cntNew[1] - cntNew[0] - !leafData : 0, |
| 59407 | nNew>=3 ? apNew[2]->pgno : 0, nNew>=3 ? szNew[2] : 0, |
| 59408 | nNew>=3 ? cntNew[2] - cntNew[1] - !leafData : 0, |
| 59409 | nNew>=4 ? apNew[3]->pgno : 0, nNew>=4 ? szNew[3] : 0, |
| 59410 | nNew>=4 ? cntNew[3] - cntNew[2] - !leafData : 0, |
| 59411 | nNew>=5 ? apNew[4]->pgno : 0, nNew>=5 ? szNew[4] : 0, |
| 59412 | nNew>=5 ? cntNew[4] - cntNew[3] - !leafData : 0 |
| 59413 | )); |
| 59414 | |
| 59415 | assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 59416 | put4byte(pRight, apNew[nNew-1]->pgno); |
| 59417 | |
| 59418 | /* If the sibling pages are not leaves, ensure that the right-child pointer |
| 59419 | ** of the right-most new sibling page is set to the value that was |
| 59420 | ** originally in the same field of the right-most old sibling page. */ |
| 59421 | if( (pageFlags & PTF_LEAF)==0 && nOld!=nNew ){ |
| 59422 | MemPage *pOld = (nNew>nOld ? apNew : apOld)[nOld-1]; |
| 59423 | memcpy(&apNew[nNew-1]->aData[8], &pOld->aData[8], 4); |
| 59424 | } |
| 59425 | |
| 59426 | /* Make any required updates to pointer map entries associated with |
| 59427 | ** cells stored on sibling pages following the balance operation. Pointer |
| 59428 | ** map entries associated with divider cells are set by the insertCell() |
| 59429 | ** routine. The associated pointer map entries are: |
| 59430 | ** |
| 59431 | ** a) if the cell contains a reference to an overflow chain, the |
| 59432 | ** entry associated with the first page in the overflow chain, and |
| 59433 | ** |
| 59434 | ** b) if the sibling pages are not leaves, the child page associated |
| 59435 | ** with the cell. |
| 59436 | ** |
| 59437 | ** If the sibling pages are not leaves, then the pointer map entry |
| 59438 | ** associated with the right-child of each sibling may also need to be |
| 59439 | ** updated. This happens below, after the sibling pages have been |
| 59440 | ** populated, not here. |
| 59441 | */ |
| 59442 | if( ISAUTOVACUUM ){ |
| 59443 | MemPage *pNew = apNew[0]; |
| 59444 | u8 *aOld = pNew->aData; |
| 59445 | int cntOldNext = pNew->nCell + pNew->nOverflow; |
| 59446 | int usableSize = pBt->usableSize; |
| 59447 | int iNew = 0; |
| 59448 | int iOld = 0; |
| 59449 | |
| 59450 | for(i=0; i<nCell; i++){ |
| 59451 | u8 *pCell = apCell[i]; |
| 59452 | if( i==cntOldNext ){ |
| 59453 | MemPage *pOld = (++iOld)<nNew ? apNew[iOld] : apOld[iOld]; |
| 59454 | cntOldNext += pOld->nCell + pOld->nOverflow + !leafData; |
| 59455 | aOld = pOld->aData; |
| 59456 | } |
| 59457 | if( i==cntNew[iNew] ){ |
| 59458 | pNew = apNew[++iNew]; |
| 59459 | if( !leafData ) continue; |
| 59460 | } |
| 59461 | |
| 59462 | /* Cell pCell is destined for new sibling page pNew. Originally, it |
| 59463 | ** was either part of sibling page iOld (possibly an overflow cell), |
| 59464 | ** or else the divider cell to the left of sibling page iOld. So, |
| 59465 | ** if sibling page iOld had the same page number as pNew, and if |
| 59466 | ** pCell really was a part of sibling page iOld (not a divider or |
| 59467 | ** overflow cell), we can skip updating the pointer map entries. */ |
| 59468 | if( pNew->pgno!=aPgno[iOld] || pCell<aOld || pCell>=&aOld[usableSize] ){ |
| 59469 | if( !leafCorrection ){ |
| 59470 | ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc); |
| 59471 | } |
| 59472 | if( szCell[i]>pNew->minLocal ){ |
| 59473 | ptrmapPutOvflPtr(pNew, pCell, &rc); |
| 59474 | } |
| 59475 | } |
| 59476 | } |
| 59477 | } |
| 59478 | |
| 59479 | /* Insert new divider cells into pParent. */ |
| 59480 | for(i=0; i<nNew-1; i++){ |
| 59481 | u8 *pCell; |
| 59482 | u8 *pTemp; |
| 59483 | int sz; |
| 59484 | MemPage *pNew = apNew[i]; |
| 59485 | j = cntNew[i]; |
| 59486 | |
| 59487 | assert( j<nMaxCells ); |
| 59488 | pCell = apCell[j]; |
| 59489 | sz = szCell[j] + leafCorrection; |
| 59490 | pTemp = &aOvflSpace[iOvflSpace]; |
| 59491 | if( !pNew->leaf ){ |
| 59492 | memcpy(&pNew->aData[8], pCell, 4); |
| 59493 | }else if( leafData ){ |
| 59494 | /* If the tree is a leaf-data tree, and the siblings are leaves, |
| 59495 | ** then there is no divider cell in apCell[]. Instead, the divider |
| 59496 | ** cell consists of the integer key for the right-most cell of |
| 59497 | ** the sibling-page assembled above only. |
| 59498 | */ |
| 59499 | CellInfo info; |
| 59500 | j--; |
| 59501 | btreeParseCellPtr(pNew, apCell[j], &info); |
| 59502 | pCell = pTemp; |
| 59503 | sz = 4 + putVarint(&pCell[4], info.nKey); |
| 59504 | pTemp = 0; |
| 59505 | }else{ |
| 59506 | pCell -= 4; |
| 59507 | /* Obscure case for non-leaf-data trees: If the cell at pCell was |
| 59508 | ** previously stored on a leaf node, and its reported size was 4 |
| 59509 | ** bytes, then it may actually be smaller than this |
| 59510 | ** (see btreeParseCellPtr(), 4 bytes is the minimum size of |
| 59511 | ** any cell). But it is important to pass the correct size to |
| 59512 | ** insertCell(), so reparse the cell now. |
| 59513 | ** |
| 59514 | ** Note that this can never happen in an SQLite data file, as all |
| 59515 | ** cells are at least 4 bytes. It only happens in b-trees used |
| 59516 | ** to evaluate "IN (SELECT ...)" and similar clauses. |
| 59517 | */ |
| 59518 | if( szCell[j]==4 ){ |
| 59519 | assert(leafCorrection==4); |
| 59520 | sz = cellSizePtr(pParent, pCell); |
| 59521 | } |
| 59522 | } |
| 59523 | iOvflSpace += sz; |
| 59524 | assert( sz<=pBt->maxLocal+23 ); |
| 59525 | assert( iOvflSpace <= (int)pBt->pageSize ); |
| 59526 | insertCell(pParent, nxDiv+i, pCell, sz, pTemp, pNew->pgno, &rc); |
| 59527 | if( rc!=SQLITE_OK ) goto balance_cleanup; |
| 59528 | assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 59529 | } |
| 59530 | |
| 59531 | /* Now update the actual sibling pages. The order in which they are updated |
| 59532 | ** is important, as this code needs to avoid disrupting any page from which |
| 59533 | ** cells may still to be read. In practice, this means: |
| 59534 | ** |
| 59535 | ** (1) If cells are moving left (from apNew[iPg] to apNew[iPg-1]) |
| 59536 | ** then it is not safe to update page apNew[iPg] until after |
| 59537 | ** the left-hand sibling apNew[iPg-1] has been updated. |
| 59538 | ** |
| 59539 | ** (2) If cells are moving right (from apNew[iPg] to apNew[iPg+1]) |
| 59540 | ** then it is not safe to update page apNew[iPg] until after |
| 59541 | ** the right-hand sibling apNew[iPg+1] has been updated. |
| 59542 | ** |
| 59543 | ** If neither of the above apply, the page is safe to update. |
| 59544 | ** |
| 59545 | ** The iPg value in the following loop starts at nNew-1 goes down |
| 59546 | ** to 0, then back up to nNew-1 again, thus making two passes over |
| 59547 | ** the pages. On the initial downward pass, only condition (1) above |
| 59548 | ** needs to be tested because (2) will always be true from the previous |
| 59549 | ** step. On the upward pass, both conditions are always true, so the |
| 59550 | ** upwards pass simply processes pages that were missed on the downward |
| 59551 | ** pass. |
| 59552 | */ |
| 59553 | for(i=1-nNew; i<nNew; i++){ |
| 59554 | int iPg = i<0 ? -i : i; |
| 59555 | assert( iPg>=0 && iPg<nNew ); |
| 59556 | if( abDone[iPg] ) continue; /* Skip pages already processed */ |
| 59557 | if( i>=0 /* On the upwards pass, or... */ |
| 59558 | || cntOld[iPg-1]>=cntNew[iPg-1] /* Condition (1) is true */ |
| 59559 | ){ |
| 59560 | int iNew; |
| 59561 | int iOld; |
| 59562 | int nNewCell; |
| 59563 | |
| 59564 | /* Verify condition (1): If cells are moving left, update iPg |
| 59565 | ** only after iPg-1 has already been updated. */ |
| 59566 | assert( iPg==0 || cntOld[iPg-1]>=cntNew[iPg-1] || abDone[iPg-1] ); |
| 59567 | |
| 59568 | /* Verify condition (2): If cells are moving right, update iPg |
| 59569 | ** only after iPg+1 has already been updated. */ |
| 59570 | assert( cntNew[iPg]>=cntOld[iPg] || abDone[iPg+1] ); |
| 59571 | |
| 59572 | if( iPg==0 ){ |
| 59573 | iNew = iOld = 0; |
| 59574 | nNewCell = cntNew[0]; |
| 59575 | }else{ |
| 59576 | iOld = iPg<nOld ? (cntOld[iPg-1] + !leafData) : nCell; |
| 59577 | iNew = cntNew[iPg-1] + !leafData; |
| 59578 | nNewCell = cntNew[iPg] - iNew; |
| 59579 | } |
| 59580 | |
| 59581 | editPage(apNew[iPg], iOld, iNew, nNewCell, apCell, szCell); |
| 59582 | abDone[iPg]++; |
| 59583 | apNew[iPg]->nFree = usableSpace-szNew[iPg]; |
| 59584 | assert( apNew[iPg]->nOverflow==0 ); |
| 59585 | assert( apNew[iPg]->nCell==nNewCell ); |
| 59586 | } |
| 59587 | } |
| 59588 | |
| 59589 | /* All pages have been processed exactly once */ |
| 59590 | assert( memcmp(abDone, "\01\01\01\01\01", nNew)==0 ); |
| 59591 | |
| 59592 | assert( nOld>0 ); |
| 59593 | assert( nNew>0 ); |
| 59594 | |
| 59595 | if( isRoot && pParent->nCell==0 && pParent->hdrOffset<=apNew[0]->nFree ){ |
| 59596 | /* The root page of the b-tree now contains no cells. The only sibling |
| 59597 | ** page is the right-child of the parent. Copy the contents of the |
| 59598 | ** child page into the parent, decreasing the overall height of the |
| @@ -59601,54 +58957,130 @@ | |
| 59601 | ** |
| 59602 | ** If this is an auto-vacuum database, the call to copyNodeContent() |
| 59603 | ** sets all pointer-map entries corresponding to database image pages |
| 59604 | ** for which the pointer is stored within the content being copied. |
| 59605 | ** |
| 59606 | ** It is critical that the child page be defragmented before being |
| 59607 | ** copied into the parent, because if the parent is page 1 then it will |
| 59608 | ** by smaller than the child due to the database header, and so all the |
| 59609 | ** free space needs to be up front. |
| 59610 | */ |
| 59611 | assert( nNew==1 ); |
| 59612 | rc = defragmentPage(apNew[0]); |
| 59613 | testcase( rc!=SQLITE_OK ); |
| 59614 | assert( apNew[0]->nFree == |
| 59615 | (get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2) |
| 59616 | || rc!=SQLITE_OK |
| 59617 | ); |
| 59618 | copyNodeContent(apNew[0], pParent, &rc); |
| 59619 | freePage(apNew[0], &rc); |
| 59620 | }else if( ISAUTOVACUUM && !leafCorrection ){ |
| 59621 | /* Fix the pointer map entries associated with the right-child of each |
| 59622 | ** sibling page. All other pointer map entries have already been taken |
| 59623 | ** care of. */ |
| 59624 | for(i=0; i<nNew; i++){ |
| 59625 | u32 key = get4byte(&apNew[i]->aData[8]); |
| 59626 | ptrmapPut(pBt, key, PTRMAP_BTREE, apNew[i]->pgno, &rc); |
| 59627 | } |
| 59628 | } |
| 59629 | |
| 59630 | assert( pParent->isInit ); |
| 59631 | TRACE(("BALANCE: finished: old=%d new=%d cells=%d\n", |
| 59632 | nOld, nNew, nCell)); |
| 59633 | |
| 59634 | /* Free any old pages that were not reused as new pages. |
| 59635 | */ |
| 59636 | for(i=nNew; i<nOld; i++){ |
| 59637 | freePage(apOld[i], &rc); |
| 59638 | } |
| 59639 | |
| 59640 | #if 0 |
| 59641 | if( ISAUTOVACUUM && rc==SQLITE_OK && apNew[0]->isInit ){ |
| 59642 | /* The ptrmapCheckPages() contains assert() statements that verify that |
| 59643 | ** all pointer map pages are set correctly. This is helpful while |
| 59644 | ** debugging. This is usually disabled because a corrupt database may |
| 59645 | ** cause an assert() statement to fail. */ |
| 59646 | ptrmapCheckPages(apNew, nNew); |
| 59647 | ptrmapCheckPages(&pParent, 1); |
| 59648 | } |
| 59649 | #endif |
| 59650 | |
| 59651 | /* |
| 59652 | ** Cleanup before returning. |
| 59653 | */ |
| 59654 | balance_cleanup: |
| @@ -61470,15 +60902,10 @@ | |
| 61470 | */ |
| 61471 | SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *p){ |
| 61472 | return (p->pBt->btsFlags & BTS_READ_ONLY)!=0; |
| 61473 | } |
| 61474 | |
| 61475 | /* |
| 61476 | ** Return the size of the header added to each page by this module. |
| 61477 | */ |
| 61478 | SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void){ return sizeof(MemPage); } |
| 61479 | |
| 61480 | /************** End of btree.c ***********************************************/ |
| 61481 | /************** Begin file backup.c ******************************************/ |
| 61482 | /* |
| 61483 | ** 2009 January 28 |
| 61484 | ** |
| @@ -61599,24 +61026,10 @@ | |
| 61599 | int rc; |
| 61600 | rc = sqlite3BtreeSetPageSize(p->pDest,sqlite3BtreeGetPageSize(p->pSrc),-1,0); |
| 61601 | return rc; |
| 61602 | } |
| 61603 | |
| 61604 | /* |
| 61605 | ** Check that there is no open read-transaction on the b-tree passed as the |
| 61606 | ** second argument. If there is not, return SQLITE_OK. Otherwise, if there |
| 61607 | ** is an open read-transaction, return SQLITE_ERROR and leave an error |
| 61608 | ** message in database handle db. |
| 61609 | */ |
| 61610 | static int checkReadTransaction(sqlite3 *db, Btree *p){ |
| 61611 | if( sqlite3BtreeIsInReadTrans(p) ){ |
| 61612 | sqlite3ErrorWithMsg(db, SQLITE_ERROR, "destination database is in use"); |
| 61613 | return SQLITE_ERROR; |
| 61614 | } |
| 61615 | return SQLITE_OK; |
| 61616 | } |
| 61617 | |
| 61618 | /* |
| 61619 | ** Create an sqlite3_backup process to copy the contents of zSrcDb from |
| 61620 | ** connection handle pSrcDb to zDestDb in pDestDb. If successful, return |
| 61621 | ** a pointer to the new sqlite3_backup object. |
| 61622 | ** |
| @@ -61629,17 +61042,10 @@ | |
| 61629 | sqlite3* pSrcDb, /* Database connection to read from */ |
| 61630 | const char *zSrcDb /* Name of database within pSrcDb */ |
| 61631 | ){ |
| 61632 | sqlite3_backup *p; /* Value to return */ |
| 61633 | |
| 61634 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 61635 | if( !sqlite3SafetyCheckOk(pSrcDb)||!sqlite3SafetyCheckOk(pDestDb) ){ |
| 61636 | (void)SQLITE_MISUSE_BKPT; |
| 61637 | return 0; |
| 61638 | } |
| 61639 | #endif |
| 61640 | |
| 61641 | /* Lock the source database handle. The destination database |
| 61642 | ** handle is not locked in this routine, but it is locked in |
| 61643 | ** sqlite3_backup_step(). The user is required to ensure that no |
| 61644 | ** other thread accesses the destination handle for the duration |
| 61645 | ** of the backup operation. Any attempt to use the destination |
| @@ -61672,19 +61078,16 @@ | |
| 61672 | p->pDestDb = pDestDb; |
| 61673 | p->pSrcDb = pSrcDb; |
| 61674 | p->iNext = 1; |
| 61675 | p->isAttached = 0; |
| 61676 | |
| 61677 | if( 0==p->pSrc || 0==p->pDest |
| 61678 | || setDestPgsz(p)==SQLITE_NOMEM |
| 61679 | || checkReadTransaction(pDestDb, p->pDest)!=SQLITE_OK |
| 61680 | ){ |
| 61681 | /* One (or both) of the named databases did not exist or an OOM |
| 61682 | ** error was hit. Or there is a transaction open on the destination |
| 61683 | ** database. The error has already been written into the pDestDb |
| 61684 | ** handle. All that is left to do here is free the sqlite3_backup |
| 61685 | ** structure. */ |
| 61686 | sqlite3_free(p); |
| 61687 | p = 0; |
| 61688 | } |
| 61689 | } |
| 61690 | if( p ){ |
| @@ -61835,13 +61238,10 @@ | |
| 61835 | int rc; |
| 61836 | int destMode; /* Destination journal mode */ |
| 61837 | int pgszSrc = 0; /* Source page size */ |
| 61838 | int pgszDest = 0; /* Destination page size */ |
| 61839 | |
| 61840 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 61841 | if( p==0 ) return SQLITE_MISUSE_BKPT; |
| 61842 | #endif |
| 61843 | sqlite3_mutex_enter(p->pSrcDb->mutex); |
| 61844 | sqlite3BtreeEnter(p->pSrc); |
| 61845 | if( p->pDestDb ){ |
| 61846 | sqlite3_mutex_enter(p->pDestDb->mutex); |
| 61847 | } |
| @@ -62127,30 +61527,18 @@ | |
| 62127 | /* |
| 62128 | ** Return the number of pages still to be backed up as of the most recent |
| 62129 | ** call to sqlite3_backup_step(). |
| 62130 | */ |
| 62131 | SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p){ |
| 62132 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 62133 | if( p==0 ){ |
| 62134 | (void)SQLITE_MISUSE_BKPT; |
| 62135 | return 0; |
| 62136 | } |
| 62137 | #endif |
| 62138 | return p->nRemaining; |
| 62139 | } |
| 62140 | |
| 62141 | /* |
| 62142 | ** Return the total number of pages in the source database as of the most |
| 62143 | ** recent call to sqlite3_backup_step(). |
| 62144 | */ |
| 62145 | SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p){ |
| 62146 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 62147 | if( p==0 ){ |
| 62148 | (void)SQLITE_MISUSE_BKPT; |
| 62149 | return 0; |
| 62150 | } |
| 62151 | #endif |
| 62152 | return p->nPagecount; |
| 62153 | } |
| 62154 | |
| 62155 | /* |
| 62156 | ** This function is called after the contents of page iPage of the |
| @@ -64437,38 +63825,10 @@ | |
| 64437 | } |
| 64438 | p->nOp += nOp; |
| 64439 | } |
| 64440 | return addr; |
| 64441 | } |
| 64442 | |
| 64443 | #if defined(SQLITE_ENABLE_STMT_SCANSTATUS) |
| 64444 | /* |
| 64445 | ** Add an entry to the array of counters managed by sqlite3_stmt_scanstatus(). |
| 64446 | */ |
| 64447 | SQLITE_PRIVATE void sqlite3VdbeScanStatus( |
| 64448 | Vdbe *p, /* VM to add scanstatus() to */ |
| 64449 | int addrExplain, /* Address of OP_Explain (or 0) */ |
| 64450 | int addrLoop, /* Address of loop counter */ |
| 64451 | int addrVisit, /* Address of rows visited counter */ |
| 64452 | LogEst nEst, /* Estimated number of output rows */ |
| 64453 | const char *zName /* Name of table or index being scanned */ |
| 64454 | ){ |
| 64455 | int nByte = (p->nScan+1) * sizeof(ScanStatus); |
| 64456 | ScanStatus *aNew; |
| 64457 | aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte); |
| 64458 | if( aNew ){ |
| 64459 | ScanStatus *pNew = &aNew[p->nScan++]; |
| 64460 | pNew->addrExplain = addrExplain; |
| 64461 | pNew->addrLoop = addrLoop; |
| 64462 | pNew->addrVisit = addrVisit; |
| 64463 | pNew->nEst = nEst; |
| 64464 | pNew->zName = sqlite3DbStrDup(p->db, zName); |
| 64465 | p->aScan = aNew; |
| 64466 | } |
| 64467 | } |
| 64468 | #endif |
| 64469 | |
| 64470 | |
| 64471 | /* |
| 64472 | ** Change the value of the P1 operand for a specific instruction. |
| 64473 | ** This routine is useful when a large program is loaded from a |
| 64474 | ** static array using sqlite3VdbeAddOpList but we want to make a |
| @@ -65564,13 +64924,10 @@ | |
| 65564 | p->apArg = allocSpace(p->apArg, nArg*sizeof(Mem*), &zCsr, zEnd, &nByte); |
| 65565 | p->azVar = allocSpace(p->azVar, nVar*sizeof(char*), &zCsr, zEnd, &nByte); |
| 65566 | p->apCsr = allocSpace(p->apCsr, nCursor*sizeof(VdbeCursor*), |
| 65567 | &zCsr, zEnd, &nByte); |
| 65568 | p->aOnceFlag = allocSpace(p->aOnceFlag, nOnce, &zCsr, zEnd, &nByte); |
| 65569 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 65570 | p->anExec = allocSpace(p->anExec, p->nOp*sizeof(i64), &zCsr, zEnd, &nByte); |
| 65571 | #endif |
| 65572 | if( nByte ){ |
| 65573 | p->pFree = sqlite3DbMallocZero(db, nByte); |
| 65574 | } |
| 65575 | zCsr = p->pFree; |
| 65576 | zEnd = &zCsr[nByte]; |
| @@ -65634,13 +64991,10 @@ | |
| 65634 | ** is used, for example, when a trigger sub-program is halted to restore |
| 65635 | ** control to the main program. |
| 65636 | */ |
| 65637 | SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){ |
| 65638 | Vdbe *v = pFrame->v; |
| 65639 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 65640 | v->anExec = pFrame->anExec; |
| 65641 | #endif |
| 65642 | v->aOnceFlag = pFrame->aOnceFlag; |
| 65643 | v->nOnceFlag = pFrame->nOnceFlag; |
| 65644 | v->aOp = pFrame->aOp; |
| 65645 | v->nOp = pFrame->nOp; |
| 65646 | v->aMem = pFrame->aMem; |
| @@ -65647,11 +65001,10 @@ | |
| 65647 | v->nMem = pFrame->nMem; |
| 65648 | v->apCsr = pFrame->apCsr; |
| 65649 | v->nCursor = pFrame->nCursor; |
| 65650 | v->db->lastRowid = pFrame->lastRowid; |
| 65651 | v->nChange = pFrame->nChange; |
| 65652 | v->db->nChange = pFrame->nDbChange; |
| 65653 | return pFrame->pc; |
| 65654 | } |
| 65655 | |
| 65656 | /* |
| 65657 | ** Close all cursors. |
| @@ -66215,11 +65568,10 @@ | |
| 66215 | ** so, abort any other statements this handle currently has active. |
| 66216 | */ |
| 66217 | sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); |
| 66218 | sqlite3CloseSavepoints(db); |
| 66219 | db->autoCommit = 1; |
| 66220 | p->nChange = 0; |
| 66221 | } |
| 66222 | } |
| 66223 | } |
| 66224 | |
| 66225 | /* Check for immediate foreign key violations. */ |
| @@ -66256,20 +65608,18 @@ | |
| 66256 | sqlite3VdbeLeave(p); |
| 66257 | return SQLITE_BUSY; |
| 66258 | }else if( rc!=SQLITE_OK ){ |
| 66259 | p->rc = rc; |
| 66260 | sqlite3RollbackAll(db, SQLITE_OK); |
| 66261 | p->nChange = 0; |
| 66262 | }else{ |
| 66263 | db->nDeferredCons = 0; |
| 66264 | db->nDeferredImmCons = 0; |
| 66265 | db->flags &= ~SQLITE_DeferFKs; |
| 66266 | sqlite3CommitInternalChanges(db); |
| 66267 | } |
| 66268 | }else{ |
| 66269 | sqlite3RollbackAll(db, SQLITE_OK); |
| 66270 | p->nChange = 0; |
| 66271 | } |
| 66272 | db->nStatement = 0; |
| 66273 | }else if( eStatementOp==0 ){ |
| 66274 | if( p->rc==SQLITE_OK || p->errorAction==OE_Fail ){ |
| 66275 | eStatementOp = SAVEPOINT_RELEASE; |
| @@ -66277,11 +65627,10 @@ | |
| 66277 | eStatementOp = SAVEPOINT_ROLLBACK; |
| 66278 | }else{ |
| 66279 | sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); |
| 66280 | sqlite3CloseSavepoints(db); |
| 66281 | db->autoCommit = 1; |
| 66282 | p->nChange = 0; |
| 66283 | } |
| 66284 | } |
| 66285 | |
| 66286 | /* If eStatementOp is non-zero, then a statement transaction needs to |
| 66287 | ** be committed or rolled back. Call sqlite3VdbeCloseStatement() to |
| @@ -66298,11 +65647,10 @@ | |
| 66298 | p->zErrMsg = 0; |
| 66299 | } |
| 66300 | sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); |
| 66301 | sqlite3CloseSavepoints(db); |
| 66302 | db->autoCommit = 1; |
| 66303 | p->nChange = 0; |
| 66304 | } |
| 66305 | } |
| 66306 | |
| 66307 | /* If this was an INSERT, UPDATE or DELETE and no statement transaction |
| 66308 | ** has been rolled back, update the database connection change-counter. |
| @@ -66560,16 +65908,10 @@ | |
| 66560 | for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]); |
| 66561 | vdbeFreeOpArray(db, p->aOp, p->nOp); |
| 66562 | sqlite3DbFree(db, p->aColName); |
| 66563 | sqlite3DbFree(db, p->zSql); |
| 66564 | sqlite3DbFree(db, p->pFree); |
| 66565 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 66566 | for(i=0; i<p->nScan; i++){ |
| 66567 | sqlite3DbFree(db, p->aScan[i].zName); |
| 66568 | } |
| 66569 | sqlite3DbFree(db, p->aScan); |
| 66570 | #endif |
| 66571 | } |
| 66572 | |
| 66573 | /* |
| 66574 | ** Delete an entire VDBE. |
| 66575 | */ |
| @@ -68933,23 +68275,15 @@ | |
| 68933 | sqlite3_stmt *pStmt, |
| 68934 | int N, |
| 68935 | const void *(*xFunc)(Mem*), |
| 68936 | int useType |
| 68937 | ){ |
| 68938 | const void *ret; |
| 68939 | Vdbe *p; |
| 68940 | int n; |
| 68941 | sqlite3 *db; |
| 68942 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 68943 | if( pStmt==0 ){ |
| 68944 | (void)SQLITE_MISUSE_BKPT; |
| 68945 | return 0; |
| 68946 | } |
| 68947 | #endif |
| 68948 | ret = 0; |
| 68949 | p = (Vdbe *)pStmt; |
| 68950 | db = p->db; |
| 68951 | assert( db!=0 ); |
| 68952 | n = sqlite3_column_count(pStmt); |
| 68953 | if( N<n && N>=0 ){ |
| 68954 | N += useType*n; |
| 68955 | sqlite3_mutex_enter(db->mutex); |
| @@ -69410,16 +68744,10 @@ | |
| 69410 | ** prepared statement for the database connection. Return NULL if there |
| 69411 | ** are no more. |
| 69412 | */ |
| 69413 | SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt){ |
| 69414 | sqlite3_stmt *pNext; |
| 69415 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 69416 | if( !sqlite3SafetyCheckOk(pDb) ){ |
| 69417 | (void)SQLITE_MISUSE_BKPT; |
| 69418 | return 0; |
| 69419 | } |
| 69420 | #endif |
| 69421 | sqlite3_mutex_enter(pDb->mutex); |
| 69422 | if( pStmt==0 ){ |
| 69423 | pNext = (sqlite3_stmt*)pDb->pVdbe; |
| 69424 | }else{ |
| 69425 | pNext = (sqlite3_stmt*)((Vdbe*)pStmt)->pNext; |
| @@ -69431,91 +68759,15 @@ | |
| 69431 | /* |
| 69432 | ** Return the value of a status counter for a prepared statement |
| 69433 | */ |
| 69434 | SQLITE_API int sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){ |
| 69435 | Vdbe *pVdbe = (Vdbe*)pStmt; |
| 69436 | u32 v; |
| 69437 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 69438 | if( !pStmt ){ |
| 69439 | (void)SQLITE_MISUSE_BKPT; |
| 69440 | return 0; |
| 69441 | } |
| 69442 | #endif |
| 69443 | v = pVdbe->aCounter[op]; |
| 69444 | if( resetFlag ) pVdbe->aCounter[op] = 0; |
| 69445 | return (int)v; |
| 69446 | } |
| 69447 | |
| 69448 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 69449 | /* |
| 69450 | ** Return status data for a single loop within query pStmt. |
| 69451 | */ |
| 69452 | SQLITE_API int sqlite3_stmt_scanstatus( |
| 69453 | sqlite3_stmt *pStmt, /* Prepared statement being queried */ |
| 69454 | int idx, /* Index of loop to report on */ |
| 69455 | int iScanStatusOp, /* Which metric to return */ |
| 69456 | void *pOut /* OUT: Write the answer here */ |
| 69457 | ){ |
| 69458 | Vdbe *p = (Vdbe*)pStmt; |
| 69459 | ScanStatus *pScan; |
| 69460 | if( idx<0 || idx>=p->nScan ) return 1; |
| 69461 | pScan = &p->aScan[idx]; |
| 69462 | switch( iScanStatusOp ){ |
| 69463 | case SQLITE_SCANSTAT_NLOOP: { |
| 69464 | *(sqlite3_int64*)pOut = p->anExec[pScan->addrLoop]; |
| 69465 | break; |
| 69466 | } |
| 69467 | case SQLITE_SCANSTAT_NVISIT: { |
| 69468 | *(sqlite3_int64*)pOut = p->anExec[pScan->addrVisit]; |
| 69469 | break; |
| 69470 | } |
| 69471 | case SQLITE_SCANSTAT_EST: { |
| 69472 | double r = 1.0; |
| 69473 | LogEst x = pScan->nEst; |
| 69474 | while( x<100 ){ |
| 69475 | x += 10; |
| 69476 | r *= 0.5; |
| 69477 | } |
| 69478 | *(double*)pOut = r*sqlite3LogEstToInt(x); |
| 69479 | break; |
| 69480 | } |
| 69481 | case SQLITE_SCANSTAT_NAME: { |
| 69482 | *(const char**)pOut = pScan->zName; |
| 69483 | break; |
| 69484 | } |
| 69485 | case SQLITE_SCANSTAT_EXPLAIN: { |
| 69486 | if( pScan->addrExplain ){ |
| 69487 | *(const char**)pOut = p->aOp[ pScan->addrExplain ].p4.z; |
| 69488 | }else{ |
| 69489 | *(const char**)pOut = 0; |
| 69490 | } |
| 69491 | break; |
| 69492 | } |
| 69493 | case SQLITE_SCANSTAT_SELECTID: { |
| 69494 | if( pScan->addrExplain ){ |
| 69495 | *(int*)pOut = p->aOp[ pScan->addrExplain ].p1; |
| 69496 | }else{ |
| 69497 | *(int*)pOut = -1; |
| 69498 | } |
| 69499 | break; |
| 69500 | } |
| 69501 | default: { |
| 69502 | return 1; |
| 69503 | } |
| 69504 | } |
| 69505 | return 0; |
| 69506 | } |
| 69507 | |
| 69508 | /* |
| 69509 | ** Zero all counters associated with the sqlite3_stmt_scanstatus() data. |
| 69510 | */ |
| 69511 | SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt *pStmt){ |
| 69512 | Vdbe *p = (Vdbe*)pStmt; |
| 69513 | memset(p->anExec, 0, p->nOp * sizeof(i64)); |
| 69514 | } |
| 69515 | #endif /* SQLITE_ENABLE_STMT_SCANSTATUS */ |
| 69516 | |
| 69517 | /************** End of vdbeapi.c *********************************************/ |
| 69518 | /************** Begin file vdbetrace.c ***************************************/ |
| 69519 | /* |
| 69520 | ** 2009 November 25 |
| 69521 | ** |
| @@ -70397,13 +69649,10 @@ | |
| 70397 | #ifdef VDBE_PROFILE |
| 70398 | start = sqlite3Hwtime(); |
| 70399 | #endif |
| 70400 | nVmStep++; |
| 70401 | pOp = &aOp[pc]; |
| 70402 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 70403 | if( p->anExec ) p->anExec[pc]++; |
| 70404 | #endif |
| 70405 | |
| 70406 | /* Only allow tracing if SQLITE_DEBUG is defined. |
| 70407 | */ |
| 70408 | #ifdef SQLITE_DEBUG |
| 70409 | if( db->flags & SQLITE_VdbeTrace ){ |
| @@ -73594,15 +72843,14 @@ | |
| 73594 | } |
| 73595 | pIdxKey = &r; |
| 73596 | }else{ |
| 73597 | pIdxKey = sqlite3VdbeAllocUnpackedRecord( |
| 73598 | pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree |
| 73599 | ); |
| 73600 | if( pIdxKey==0 ) goto no_mem; |
| 73601 | assert( pIn3->flags & MEM_Blob ); |
| 73602 | /* assert( (pIn3->flags & MEM_Zero)==0 ); // zeroblobs already expanded */ |
| 73603 | ExpandBlob(pIn3); |
| 73604 | sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey); |
| 73605 | } |
| 73606 | pIdxKey->default_rc = 0; |
| 73607 | if( pOp->opcode==OP_NoConflict ){ |
| 73608 | /* For the OP_NoConflict opcode, take the jump if any of the |
| @@ -74292,13 +73540,13 @@ | |
| 74292 | } |
| 74293 | /* Opcode: Rewind P1 P2 * * * |
| 74294 | ** |
| 74295 | ** The next use of the Rowid or Column or Next instruction for P1 |
| 74296 | ** will refer to the first entry in the database table or index. |
| 74297 | ** If the table or index is empty, jump immediately to P2. |
| 74298 | ** If the table or index is not empty, fall through to the following |
| 74299 | ** instruction. |
| 74300 | ** |
| 74301 | ** This opcode leaves the cursor configured to move in forward order, |
| 74302 | ** from the beginning toward the end. In other words, the cursor is |
| 74303 | ** configured to use Next, not Prev. |
| 74304 | */ |
| @@ -75210,13 +74458,10 @@ | |
| 75210 | pFrame->aOp = p->aOp; |
| 75211 | pFrame->nOp = p->nOp; |
| 75212 | pFrame->token = pProgram->token; |
| 75213 | pFrame->aOnceFlag = p->aOnceFlag; |
| 75214 | pFrame->nOnceFlag = p->nOnceFlag; |
| 75215 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 75216 | pFrame->anExec = p->anExec; |
| 75217 | #endif |
| 75218 | |
| 75219 | pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem]; |
| 75220 | for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){ |
| 75221 | pMem->flags = MEM_Undefined; |
| 75222 | pMem->db = db; |
| @@ -75230,11 +74475,10 @@ | |
| 75230 | |
| 75231 | p->nFrame++; |
| 75232 | pFrame->pParent = p->pFrame; |
| 75233 | pFrame->lastRowid = lastRowid; |
| 75234 | pFrame->nChange = p->nChange; |
| 75235 | pFrame->nDbChange = p->db->nChange; |
| 75236 | p->nChange = 0; |
| 75237 | p->pFrame = pFrame; |
| 75238 | p->aMem = aMem = &VdbeFrameMem(pFrame)[-1]; |
| 75239 | p->nMem = pFrame->nChildMem; |
| 75240 | p->nCursor = (u16)pFrame->nChildCsr; |
| @@ -75241,13 +74485,10 @@ | |
| 75241 | p->apCsr = (VdbeCursor **)&aMem[p->nMem+1]; |
| 75242 | p->aOp = aOp = pProgram->aOp; |
| 75243 | p->nOp = pProgram->nOp; |
| 75244 | p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor]; |
| 75245 | p->nOnceFlag = pProgram->nOnce; |
| 75246 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 75247 | p->anExec = 0; |
| 75248 | #endif |
| 75249 | pc = -1; |
| 75250 | memset(p->aOnceFlag, 0, p->nOnceFlag); |
| 75251 | |
| 75252 | break; |
| 75253 | } |
| @@ -76432,15 +75673,10 @@ | |
| 76432 | char *zErr = 0; |
| 76433 | Table *pTab; |
| 76434 | Parse *pParse = 0; |
| 76435 | Incrblob *pBlob = 0; |
| 76436 | |
| 76437 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 76438 | if( !sqlite3SafetyCheckOk(db) || ppBlob==0 || zTable==0 ){ |
| 76439 | return SQLITE_MISUSE_BKPT; |
| 76440 | } |
| 76441 | #endif |
| 76442 | flags = !!flags; /* flags = (flags ? 1 : 0); */ |
| 76443 | *ppBlob = 0; |
| 76444 | |
| 76445 | sqlite3_mutex_enter(db->mutex); |
| 76446 | |
| @@ -76655,10 +75891,11 @@ | |
| 76655 | v = (Vdbe*)p->pStmt; |
| 76656 | |
| 76657 | if( n<0 || iOffset<0 || (iOffset+n)>p->nByte ){ |
| 76658 | /* Request is out of range. Return a transient error. */ |
| 76659 | rc = SQLITE_ERROR; |
| 76660 | }else if( v==0 ){ |
| 76661 | /* If there is no statement handle, then the blob-handle has |
| 76662 | ** already been invalidated. Return SQLITE_ABORT in this case. |
| 76663 | */ |
| 76664 | rc = SQLITE_ABORT; |
| @@ -76672,14 +75909,14 @@ | |
| 76672 | sqlite3BtreeLeaveCursor(p->pCsr); |
| 76673 | if( rc==SQLITE_ABORT ){ |
| 76674 | sqlite3VdbeFinalize(v); |
| 76675 | p->pStmt = 0; |
| 76676 | }else{ |
| 76677 | v->rc = rc; |
| 76678 | } |
| 76679 | } |
| 76680 | sqlite3Error(db, rc); |
| 76681 | rc = sqlite3ApiExit(db, rc); |
| 76682 | sqlite3_mutex_leave(db->mutex); |
| 76683 | return rc; |
| 76684 | } |
| 76685 | |
| @@ -76852,11 +76089,11 @@ | |
| 76852 | ** itself. |
| 76853 | ** |
| 76854 | ** The sorter is running in multi-threaded mode if (a) the library was built |
| 76855 | ** with pre-processor symbol SQLITE_MAX_WORKER_THREADS set to a value greater |
| 76856 | ** than zero, and (b) worker threads have been enabled at runtime by calling |
| 76857 | ** "PRAGMA threads=N" with some value of N greater than 0. |
| 76858 | ** |
| 76859 | ** When Rewind() is called, any data remaining in memory is flushed to a |
| 76860 | ** final PMA. So at this point the data is stored in some number of sorted |
| 76861 | ** PMAs within temporary files on disk. |
| 76862 | ** |
| @@ -77597,13 +76834,15 @@ | |
| 77597 | pSorter->mnPmaSize = SORTER_MIN_WORKING * pgsz; |
| 77598 | mxCache = db->aDb[0].pSchema->cache_size; |
| 77599 | if( mxCache<SORTER_MIN_WORKING ) mxCache = SORTER_MIN_WORKING; |
| 77600 | pSorter->mxPmaSize = mxCache * pgsz; |
| 77601 | |
| 77602 | /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of |
| 77603 | ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary |
| 77604 | ** large heap allocations. |
| 77605 | */ |
| 77606 | if( sqlite3GlobalConfig.pScratch==0 ){ |
| 77607 | assert( pSorter->iMemory==0 ); |
| 77608 | pSorter->nMemory = pgsz; |
| 77609 | pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz); |
| @@ -79971,19 +79210,19 @@ | |
| 79971 | ** |
| 79972 | ** incrAggFunctionDepth(pExpr,n) is the main routine. incrAggDepth(..) |
| 79973 | ** is a helper function - a callback for the tree walker. |
| 79974 | */ |
| 79975 | static int incrAggDepth(Walker *pWalker, Expr *pExpr){ |
| 79976 | if( pExpr->op==TK_AGG_FUNCTION ) pExpr->op2 += pWalker->u.n; |
| 79977 | return WRC_Continue; |
| 79978 | } |
| 79979 | static void incrAggFunctionDepth(Expr *pExpr, int N){ |
| 79980 | if( N>0 ){ |
| 79981 | Walker w; |
| 79982 | memset(&w, 0, sizeof(w)); |
| 79983 | w.xExprCallback = incrAggDepth; |
| 79984 | w.u.n = N; |
| 79985 | sqlite3WalkExpr(&w, pExpr); |
| 79986 | } |
| 79987 | } |
| 79988 | |
| 79989 | /* |
| @@ -80527,11 +79766,11 @@ | |
| 80527 | double r = -1.0; |
| 80528 | if( p->op!=TK_FLOAT ) return -1; |
| 80529 | sqlite3AtoF(p->u.zToken, &r, sqlite3Strlen30(p->u.zToken), SQLITE_UTF8); |
| 80530 | assert( r>=0.0 ); |
| 80531 | if( r>1.0 ) return -1; |
| 80532 | return (int)(r*134217728.0); |
| 80533 | } |
| 80534 | |
| 80535 | /* |
| 80536 | ** This routine is callback for sqlite3WalkExpr(). |
| 80537 | ** |
| @@ -80659,11 +79898,11 @@ | |
| 80659 | ** EVIDENCE-OF: R-36850-34127 The likely(X) function is short-hand for |
| 80660 | ** likelihood(X,0.9375). |
| 80661 | ** EVIDENCE-OF: R-53436-40973 The likely(X) function is equivalent to |
| 80662 | ** likelihood(X,0.9375). */ |
| 80663 | /* TUNING: unlikely() probability is 0.0625. likely() is 0.9375 */ |
| 80664 | pExpr->iTable = pDef->zName[0]=='u' ? 8388608 : 125829120; |
| 80665 | } |
| 80666 | } |
| 80667 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 80668 | auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0); |
| 80669 | if( auth!=SQLITE_OK ){ |
| @@ -82616,79 +81855,69 @@ | |
| 82616 | sqlite3DbFree(db, pList->a); |
| 82617 | sqlite3DbFree(db, pList); |
| 82618 | } |
| 82619 | |
| 82620 | /* |
| 82621 | ** These routines are Walker callbacks used to check expressions to |
| 82622 | ** see if they are "constant" for some definition of constant. The |
| 82623 | ** Walker.eCode value determines the type of "constant" we are looking |
| 82624 | ** for. |
| 82625 | ** |
| 82626 | ** These callback routines are used to implement the following: |
| 82627 | ** |
| 82628 | ** sqlite3ExprIsConstant() pWalker->eCode==1 |
| 82629 | ** sqlite3ExprIsConstantNotJoin() pWalker->eCode==2 |
| 82630 | ** sqlite3ExprRefOneTableOnly() pWalker->eCode==3 |
| 82631 | ** sqlite3ExprIsConstantOrFunction() pWalker->eCode==4 or 5 |
| 82632 | ** |
| 82633 | ** In all cases, the callbacks set Walker.eCode=0 and abort if the expression |
| 82634 | ** is found to not be a constant. |
| 82635 | ** |
| 82636 | ** The sqlite3ExprIsConstantOrFunction() is used for evaluating expressions |
| 82637 | ** in a CREATE TABLE statement. The Walker.eCode value is 5 when parsing |
| 82638 | ** an existing schema and 4 when processing a new statement. A bound |
| 82639 | ** parameter raises an error for new statements, but is silently converted |
| 82640 | ** to NULL for existing schemas. This allows sqlite_master tables that |
| 82641 | ** contain a bound parameter because they were generated by older versions |
| 82642 | ** of SQLite to be parsed by newer versions of SQLite without raising a |
| 82643 | ** malformed schema error. |
| 82644 | */ |
| 82645 | static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){ |
| 82646 | |
| 82647 | /* If pWalker->eCode is 2 then any term of the expression that comes from |
| 82648 | ** the ON or USING clauses of a left join disqualifies the expression |
| 82649 | ** from being considered constant. */ |
| 82650 | if( pWalker->eCode==2 && ExprHasProperty(pExpr, EP_FromJoin) ){ |
| 82651 | pWalker->eCode = 0; |
| 82652 | return WRC_Abort; |
| 82653 | } |
| 82654 | |
| 82655 | switch( pExpr->op ){ |
| 82656 | /* Consider functions to be constant if all their arguments are constant |
| 82657 | ** and either pWalker->eCode==4 or 5 or the function has the |
| 82658 | ** SQLITE_FUNC_CONST flag. */ |
| 82659 | case TK_FUNCTION: |
| 82660 | if( pWalker->eCode>=4 || ExprHasProperty(pExpr,EP_Constant) ){ |
| 82661 | return WRC_Continue; |
| 82662 | }else{ |
| 82663 | pWalker->eCode = 0; |
| 82664 | return WRC_Abort; |
| 82665 | } |
| 82666 | case TK_ID: |
| 82667 | case TK_COLUMN: |
| 82668 | case TK_AGG_FUNCTION: |
| 82669 | case TK_AGG_COLUMN: |
| 82670 | testcase( pExpr->op==TK_ID ); |
| 82671 | testcase( pExpr->op==TK_COLUMN ); |
| 82672 | testcase( pExpr->op==TK_AGG_FUNCTION ); |
| 82673 | testcase( pExpr->op==TK_AGG_COLUMN ); |
| 82674 | if( pWalker->eCode==3 && pExpr->iTable==pWalker->u.iCur ){ |
| 82675 | return WRC_Continue; |
| 82676 | }else{ |
| 82677 | pWalker->eCode = 0; |
| 82678 | return WRC_Abort; |
| 82679 | } |
| 82680 | case TK_VARIABLE: |
| 82681 | if( pWalker->eCode==5 ){ |
| 82682 | /* Silently convert bound parameters that appear inside of CREATE |
| 82683 | ** statements into a NULL when parsing the CREATE statement text out |
| 82684 | ** of the sqlite_master table */ |
| 82685 | pExpr->op = TK_NULL; |
| 82686 | }else if( pWalker->eCode==4 ){ |
| 82687 | /* A bound parameter in a CREATE statement that originates from |
| 82688 | ** sqlite3_prepare() causes an error */ |
| 82689 | pWalker->eCode = 0; |
| 82690 | return WRC_Abort; |
| 82691 | } |
| 82692 | /* Fall through */ |
| 82693 | default: |
| 82694 | testcase( pExpr->op==TK_SELECT ); /* selectNodeIsConstant will disallow */ |
| @@ -82696,68 +81925,57 @@ | |
| 82696 | return WRC_Continue; |
| 82697 | } |
| 82698 | } |
| 82699 | static int selectNodeIsConstant(Walker *pWalker, Select *NotUsed){ |
| 82700 | UNUSED_PARAMETER(NotUsed); |
| 82701 | pWalker->eCode = 0; |
| 82702 | return WRC_Abort; |
| 82703 | } |
| 82704 | static int exprIsConst(Expr *p, int initFlag, int iCur){ |
| 82705 | Walker w; |
| 82706 | memset(&w, 0, sizeof(w)); |
| 82707 | w.eCode = initFlag; |
| 82708 | w.xExprCallback = exprNodeIsConstant; |
| 82709 | w.xSelectCallback = selectNodeIsConstant; |
| 82710 | w.u.iCur = iCur; |
| 82711 | sqlite3WalkExpr(&w, p); |
| 82712 | return w.eCode; |
| 82713 | } |
| 82714 | |
| 82715 | /* |
| 82716 | ** Walk an expression tree. Return non-zero if the expression is constant |
| 82717 | ** and 0 if it involves variables or function calls. |
| 82718 | ** |
| 82719 | ** For the purposes of this function, a double-quoted string (ex: "abc") |
| 82720 | ** is considered a variable but a single-quoted string (ex: 'abc') is |
| 82721 | ** a constant. |
| 82722 | */ |
| 82723 | SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr *p){ |
| 82724 | return exprIsConst(p, 1, 0); |
| 82725 | } |
| 82726 | |
| 82727 | /* |
| 82728 | ** Walk an expression tree. Return non-zero if the expression is constant |
| 82729 | ** that does no originate from the ON or USING clauses of a join. |
| 82730 | ** Return 0 if it involves variables or function calls or terms from |
| 82731 | ** an ON or USING clause. |
| 82732 | */ |
| 82733 | SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr *p){ |
| 82734 | return exprIsConst(p, 2, 0); |
| 82735 | } |
| 82736 | |
| 82737 | /* |
| 82738 | ** Walk an expression tree. Return non-zero if the expression constant |
| 82739 | ** for any single row of the table with cursor iCur. In other words, the |
| 82740 | ** expression must not refer to any non-deterministic function nor any |
| 82741 | ** table other than iCur. |
| 82742 | */ |
| 82743 | SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){ |
| 82744 | return exprIsConst(p, 3, iCur); |
| 82745 | } |
| 82746 | |
| 82747 | /* |
| 82748 | ** Walk an expression tree. Return non-zero if the expression is constant |
| 82749 | ** or a function call with constant arguments. Return and 0 if there |
| 82750 | ** are any variables. |
| 82751 | ** |
| 82752 | ** For the purposes of this function, a double-quoted string (ex: "abc") |
| 82753 | ** is considered a variable but a single-quoted string (ex: 'abc') is |
| 82754 | ** a constant. |
| 82755 | */ |
| 82756 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr *p, u8 isInit){ |
| 82757 | assert( isInit==0 || isInit==1 ); |
| 82758 | return exprIsConst(p, 4+isInit, 0); |
| 82759 | } |
| 82760 | |
| 82761 | /* |
| 82762 | ** If the expression p codes a constant integer that is small enough |
| 82763 | ** to fit in a 32-bit integer, return 1 and put the value of the integer |
| @@ -88070,12 +87288,10 @@ | |
| 88070 | while( z[0] ){ |
| 88071 | if( sqlite3_strglob("unordered*", z)==0 ){ |
| 88072 | pIndex->bUnordered = 1; |
| 88073 | }else if( sqlite3_strglob("sz=[0-9]*", z)==0 ){ |
| 88074 | pIndex->szIdxRow = sqlite3LogEst(sqlite3Atoi(z+3)); |
| 88075 | }else if( sqlite3_strglob("noskipscan*", z)==0 ){ |
| 88076 | pIndex->noSkipScan = 1; |
| 88077 | } |
| 88078 | #ifdef SQLITE_ENABLE_COSTMULT |
| 88079 | else if( sqlite3_strglob("costmult=[0-9]*",z)==0 ){ |
| 88080 | pIndex->pTable->costMult = sqlite3LogEst(sqlite3Atoi(z+9)); |
| 88081 | } |
| @@ -88205,11 +87421,10 @@ | |
| 88205 | nSample--; |
| 88206 | }else{ |
| 88207 | nRow = pIdx->aiRowEst[0]; |
| 88208 | nDist100 = ((i64)100 * pIdx->aiRowEst[0]) / pIdx->aiRowEst[iCol+1]; |
| 88209 | } |
| 88210 | pIdx->nRowEst0 = nRow; |
| 88211 | |
| 88212 | /* Set nSum to the number of distinct (iCol+1) field prefixes that |
| 88213 | ** occur in the stat4 table for this index. Set sumEq to the sum of |
| 88214 | ** the nEq values for column iCol for the same set (adding the value |
| 88215 | ** only once where there exist duplicate prefixes). */ |
| @@ -88467,11 +87682,11 @@ | |
| 88467 | } |
| 88468 | |
| 88469 | |
| 88470 | /* Load the statistics from the sqlite_stat4 table. */ |
| 88471 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 88472 | if( rc==SQLITE_OK && OptimizationEnabled(db, SQLITE_Stat34) ){ |
| 88473 | int lookasideEnabled = db->lookaside.bEnabled; |
| 88474 | db->lookaside.bEnabled = 0; |
| 88475 | rc = loadStat4(db, sInfo.zDatabase); |
| 88476 | db->lookaside.bEnabled = lookasideEnabled; |
| 88477 | } |
| @@ -89149,13 +88364,10 @@ | |
| 89149 | SQLITE_API int sqlite3_set_authorizer( |
| 89150 | sqlite3 *db, |
| 89151 | int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), |
| 89152 | void *pArg |
| 89153 | ){ |
| 89154 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 89155 | if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 89156 | #endif |
| 89157 | sqlite3_mutex_enter(db->mutex); |
| 89158 | db->xAuth = (sqlite3_xauth)xAuth; |
| 89159 | db->pAuthArg = pArg; |
| 89160 | sqlite3ExpirePreparedStatements(db); |
| 89161 | sqlite3_mutex_leave(db->mutex); |
| @@ -89646,15 +88858,11 @@ | |
| 89646 | ** See also sqlite3LocateTable(). |
| 89647 | */ |
| 89648 | SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){ |
| 89649 | Table *p = 0; |
| 89650 | int i; |
| 89651 | |
| 89652 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 89653 | if( !sqlite3SafetyCheckOk(db) || zName==0 ) return 0; |
| 89654 | #endif |
| 89655 | |
| 89656 | /* All mutexes are required for schema access. Make sure we hold them. */ |
| 89657 | assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) ); |
| 89658 | #if SQLITE_USER_AUTHENTICATION |
| 89659 | /* Only the admin user is allowed to know that the sqlite_user table |
| 89660 | ** exists */ |
| @@ -104673,16 +103881,13 @@ | |
| 104673 | Vdbe *pOld, /* VM being reprepared */ |
| 104674 | sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */ |
| 104675 | const char **pzTail /* OUT: End of parsed string */ |
| 104676 | ){ |
| 104677 | int rc; |
| 104678 | |
| 104679 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 104680 | if( ppStmt==0 ) return SQLITE_MISUSE_BKPT; |
| 104681 | #endif |
| 104682 | *ppStmt = 0; |
| 104683 | if( !sqlite3SafetyCheckOk(db)||zSql==0 ){ |
| 104684 | return SQLITE_MISUSE_BKPT; |
| 104685 | } |
| 104686 | sqlite3_mutex_enter(db->mutex); |
| 104687 | sqlite3BtreeEnterAll(db); |
| 104688 | rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail); |
| @@ -104785,15 +103990,13 @@ | |
| 104785 | */ |
| 104786 | char *zSql8; |
| 104787 | const char *zTail8 = 0; |
| 104788 | int rc = SQLITE_OK; |
| 104789 | |
| 104790 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 104791 | if( ppStmt==0 ) return SQLITE_MISUSE_BKPT; |
| 104792 | #endif |
| 104793 | *ppStmt = 0; |
| 104794 | if( !sqlite3SafetyCheckOk(db)||zSql==0 ){ |
| 104795 | return SQLITE_MISUSE_BKPT; |
| 104796 | } |
| 104797 | if( nBytes>=0 ){ |
| 104798 | int sz; |
| 104799 | const char *z = (const char*)zSql; |
| @@ -110502,13 +109705,10 @@ | |
| 110502 | char **pzErrMsg /* Write error messages here */ |
| 110503 | ){ |
| 110504 | int rc; |
| 110505 | TabResult res; |
| 110506 | |
| 110507 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 110508 | if( pazResult==0 ) return SQLITE_MISUSE_BKPT; |
| 110509 | #endif |
| 110510 | *pazResult = 0; |
| 110511 | if( pnColumn ) *pnColumn = 0; |
| 110512 | if( pnRow ) *pnRow = 0; |
| 110513 | if( pzErrMsg ) *pzErrMsg = 0; |
| 110514 | res.zErrMsg = 0; |
| @@ -112568,11 +111768,11 @@ | |
| 112568 | ** Two writes per page are required in step (3) because the original |
| 112569 | ** database content must be written into the rollback journal prior to |
| 112570 | ** overwriting the database with the vacuumed content. |
| 112571 | ** |
| 112572 | ** Only 1x temporary space and only 1x writes would be required if |
| 112573 | ** the copy of step (3) were replaced by deleting the original database |
| 112574 | ** and renaming the transient database as the original. But that will |
| 112575 | ** not work if other processes are attached to the original database. |
| 112576 | ** And a power loss in between deleting the original and renaming the |
| 112577 | ** transient would cause the database file to appear to be deleted |
| 112578 | ** following reboot. |
| @@ -112926,13 +112126,10 @@ | |
| 112926 | sqlite3 *db, /* Database in which module is registered */ |
| 112927 | const char *zName, /* Name assigned to this module */ |
| 112928 | const sqlite3_module *pModule, /* The definition of the module */ |
| 112929 | void *pAux /* Context pointer for xCreate/xConnect */ |
| 112930 | ){ |
| 112931 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 112932 | if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT; |
| 112933 | #endif |
| 112934 | return createModule(db, zName, pModule, pAux, 0); |
| 112935 | } |
| 112936 | |
| 112937 | /* |
| 112938 | ** External API function used to create a new virtual-table module. |
| @@ -112942,13 +112139,10 @@ | |
| 112942 | const char *zName, /* Name assigned to this module */ |
| 112943 | const sqlite3_module *pModule, /* The definition of the module */ |
| 112944 | void *pAux, /* Context pointer for xCreate/xConnect */ |
| 112945 | void (*xDestroy)(void *) /* Module destructor function */ |
| 112946 | ){ |
| 112947 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 112948 | if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT; |
| 112949 | #endif |
| 112950 | return createModule(db, zName, pModule, pAux, xDestroy); |
| 112951 | } |
| 112952 | |
| 112953 | /* |
| 112954 | ** Lock the virtual table so that it cannot be disconnected. |
| @@ -113549,13 +112743,10 @@ | |
| 113549 | |
| 113550 | int rc = SQLITE_OK; |
| 113551 | Table *pTab; |
| 113552 | char *zErr = 0; |
| 113553 | |
| 113554 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 113555 | if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 113556 | #endif |
| 113557 | sqlite3_mutex_enter(db->mutex); |
| 113558 | if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){ |
| 113559 | sqlite3Error(db, SQLITE_MISUSE); |
| 113560 | sqlite3_mutex_leave(db->mutex); |
| 113561 | return SQLITE_MISUSE_BKPT; |
| @@ -113908,13 +113099,10 @@ | |
| 113908 | */ |
| 113909 | SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *db){ |
| 113910 | static const unsigned char aMap[] = { |
| 113911 | SQLITE_ROLLBACK, SQLITE_ABORT, SQLITE_FAIL, SQLITE_IGNORE, SQLITE_REPLACE |
| 113912 | }; |
| 113913 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 113914 | if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 113915 | #endif |
| 113916 | assert( OE_Rollback==1 && OE_Abort==2 && OE_Fail==3 ); |
| 113917 | assert( OE_Ignore==4 && OE_Replace==5 ); |
| 113918 | assert( db->vtabOnConflict>=1 && db->vtabOnConflict<=5 ); |
| 113919 | return (int)aMap[db->vtabOnConflict-1]; |
| 113920 | } |
| @@ -113926,14 +113114,12 @@ | |
| 113926 | */ |
| 113927 | SQLITE_API int sqlite3_vtab_config(sqlite3 *db, int op, ...){ |
| 113928 | va_list ap; |
| 113929 | int rc = SQLITE_OK; |
| 113930 | |
| 113931 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 113932 | if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 113933 | #endif |
| 113934 | sqlite3_mutex_enter(db->mutex); |
| 113935 | va_start(ap, op); |
| 113936 | switch( op ){ |
| 113937 | case SQLITE_VTAB_CONSTRAINT_SUPPORT: { |
| 113938 | VtabCtx *p = db->pVtabCtx; |
| 113939 | if( !p ){ |
| @@ -114064,13 +113250,10 @@ | |
| 114064 | } in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */ |
| 114065 | Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */ |
| 114066 | } u; |
| 114067 | struct WhereLoop *pWLoop; /* The selected WhereLoop object */ |
| 114068 | Bitmask notReady; /* FROM entries not usable at this level */ |
| 114069 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 114070 | int addrVisit; /* Address at which row is visited */ |
| 114071 | #endif |
| 114072 | }; |
| 114073 | |
| 114074 | /* |
| 114075 | ** Each instance of this object represents an algorithm for evaluating one |
| 114076 | ** term of a join. Every term of the FROM clause will have at least |
| @@ -114097,10 +113280,11 @@ | |
| 114097 | LogEst rRun; /* Cost of running each loop */ |
| 114098 | LogEst nOut; /* Estimated number of output rows */ |
| 114099 | union { |
| 114100 | struct { /* Information for internal btree tables */ |
| 114101 | u16 nEq; /* Number of equality constraints */ |
| 114102 | Index *pIndex; /* Index used, or NULL */ |
| 114103 | } btree; |
| 114104 | struct { /* Information for virtual tables */ |
| 114105 | int idxNum; /* Index number */ |
| 114106 | u8 needFree; /* True if sqlite3_free(idxStr) is needed */ |
| @@ -114109,17 +113293,16 @@ | |
| 114109 | char *idxStr; /* Index identifier string */ |
| 114110 | } vtab; |
| 114111 | } u; |
| 114112 | u32 wsFlags; /* WHERE_* flags describing the plan */ |
| 114113 | u16 nLTerm; /* Number of entries in aLTerm[] */ |
| 114114 | u16 nSkip; /* Number of NULL aLTerm[] entries */ |
| 114115 | /**** whereLoopXfer() copies fields above ***********************/ |
| 114116 | # define WHERE_LOOP_XFER_SZ offsetof(WhereLoop,nLSlot) |
| 114117 | u16 nLSlot; /* Number of slots allocated for aLTerm[] */ |
| 114118 | WhereTerm **aLTerm; /* WhereTerms used */ |
| 114119 | WhereLoop *pNextLoop; /* Next WhereLoop object in the WhereClause */ |
| 114120 | WhereTerm *aLTermSpace[3]; /* Initial aLTerm[] space */ |
| 114121 | }; |
| 114122 | |
| 114123 | /* This object holds the prerequisites and the cost of running a |
| 114124 | ** subquery on one operand of an OR operator in the WHERE clause. |
| 114125 | ** See WhereOrSet for additional information |
| @@ -114441,11 +113624,10 @@ | |
| 114441 | #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */ |
| 114442 | #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */ |
| 114443 | #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */ |
| 114444 | #define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */ |
| 114445 | #define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/ |
| 114446 | #define WHERE_PARTIALIDX 0x00020000 /* The automatic index is partial */ |
| 114447 | |
| 114448 | /************** End of whereInt.h ********************************************/ |
| 114449 | /************** Continuing where we left off in where.c **********************/ |
| 114450 | |
| 114451 | /* |
| @@ -114652,11 +113834,11 @@ | |
| 114652 | } |
| 114653 | pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]); |
| 114654 | } |
| 114655 | pTerm = &pWC->a[idx = pWC->nTerm++]; |
| 114656 | if( p && ExprHasProperty(p, EP_Unlikely) ){ |
| 114657 | pTerm->truthProb = sqlite3LogEst(p->iTable) - 270; |
| 114658 | }else{ |
| 114659 | pTerm->truthProb = 1; |
| 114660 | } |
| 114661 | pTerm->pExpr = sqlite3ExprSkipCollate(p); |
| 114662 | pTerm->wtFlags = wtFlags; |
| @@ -115183,19 +114365,10 @@ | |
| 115183 | pDerived->flags |= pBase->flags & EP_FromJoin; |
| 115184 | pDerived->iRightJoinTable = pBase->iRightJoinTable; |
| 115185 | } |
| 115186 | } |
| 115187 | |
| 115188 | /* |
| 115189 | ** Mark term iChild as being a child of term iParent |
| 115190 | */ |
| 115191 | static void markTermAsChild(WhereClause *pWC, int iChild, int iParent){ |
| 115192 | pWC->a[iChild].iParent = iParent; |
| 115193 | pWC->a[iChild].truthProb = pWC->a[iParent].truthProb; |
| 115194 | pWC->a[iParent].nChild++; |
| 115195 | } |
| 115196 | |
| 115197 | #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY) |
| 115198 | /* |
| 115199 | ** Analyze a term that consists of two or more OR-connected |
| 115200 | ** subterms. So in: |
| 115201 | ** |
| @@ -115489,11 +114662,12 @@ | |
| 115489 | pNew->x.pList = pList; |
| 115490 | idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC); |
| 115491 | testcase( idxNew==0 ); |
| 115492 | exprAnalyze(pSrc, pWC, idxNew); |
| 115493 | pTerm = &pWC->a[idxTerm]; |
| 115494 | markTermAsChild(pWC, idxNew, idxTerm); |
| 115495 | }else{ |
| 115496 | sqlite3ExprListDelete(db, pList); |
| 115497 | } |
| 115498 | pTerm->eOperator = WO_NOOP; /* case 1 trumps case 2 */ |
| 115499 | } |
| @@ -115591,12 +114765,13 @@ | |
| 115591 | return; |
| 115592 | } |
| 115593 | idxNew = whereClauseInsert(pWC, pDup, TERM_VIRTUAL|TERM_DYNAMIC); |
| 115594 | if( idxNew==0 ) return; |
| 115595 | pNew = &pWC->a[idxNew]; |
| 115596 | markTermAsChild(pWC, idxNew, idxTerm); |
| 115597 | pTerm = &pWC->a[idxTerm]; |
| 115598 | pTerm->wtFlags |= TERM_COPIED; |
| 115599 | if( pExpr->op==TK_EQ |
| 115600 | && !ExprHasProperty(pExpr, EP_FromJoin) |
| 115601 | && OptimizationEnabled(db, SQLITE_Transitive) |
| 115602 | ){ |
| @@ -115649,12 +114824,13 @@ | |
| 115649 | transferJoinMarkings(pNewExpr, pExpr); |
| 115650 | idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC); |
| 115651 | testcase( idxNew==0 ); |
| 115652 | exprAnalyze(pSrc, pWC, idxNew); |
| 115653 | pTerm = &pWC->a[idxTerm]; |
| 115654 | markTermAsChild(pWC, idxNew, idxTerm); |
| 115655 | } |
| 115656 | } |
| 115657 | #endif /* SQLITE_OMIT_BETWEEN_OPTIMIZATION */ |
| 115658 | |
| 115659 | #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY) |
| 115660 | /* Analyze a term that is composed of two or more subterms connected by |
| @@ -115725,12 +114901,13 @@ | |
| 115725 | idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC); |
| 115726 | testcase( idxNew2==0 ); |
| 115727 | exprAnalyze(pSrc, pWC, idxNew2); |
| 115728 | pTerm = &pWC->a[idxTerm]; |
| 115729 | if( isComplete ){ |
| 115730 | markTermAsChild(pWC, idxNew1, idxTerm); |
| 115731 | markTermAsChild(pWC, idxNew2, idxTerm); |
| 115732 | } |
| 115733 | } |
| 115734 | #endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */ |
| 115735 | |
| 115736 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| @@ -115759,12 +114936,13 @@ | |
| 115759 | pNewTerm = &pWC->a[idxNew]; |
| 115760 | pNewTerm->prereqRight = prereqExpr; |
| 115761 | pNewTerm->leftCursor = pLeft->iTable; |
| 115762 | pNewTerm->u.leftColumn = pLeft->iColumn; |
| 115763 | pNewTerm->eOperator = WO_MATCH; |
| 115764 | markTermAsChild(pWC, idxNew, idxTerm); |
| 115765 | pTerm = &pWC->a[idxTerm]; |
| 115766 | pTerm->wtFlags |= TERM_COPIED; |
| 115767 | pNewTerm->prereqAll = pTerm->prereqAll; |
| 115768 | } |
| 115769 | } |
| 115770 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| @@ -115781,11 +114959,11 @@ | |
| 115781 | ** the start of the loop will prevent any results from being returned. |
| 115782 | */ |
| 115783 | if( pExpr->op==TK_NOTNULL |
| 115784 | && pExpr->pLeft->op==TK_COLUMN |
| 115785 | && pExpr->pLeft->iColumn>=0 |
| 115786 | && OptimizationEnabled(db, SQLITE_Stat34) |
| 115787 | ){ |
| 115788 | Expr *pNewExpr; |
| 115789 | Expr *pLeft = pExpr->pLeft; |
| 115790 | int idxNew; |
| 115791 | WhereTerm *pNewTerm; |
| @@ -115800,12 +114978,13 @@ | |
| 115800 | pNewTerm = &pWC->a[idxNew]; |
| 115801 | pNewTerm->prereqRight = 0; |
| 115802 | pNewTerm->leftCursor = pLeft->iTable; |
| 115803 | pNewTerm->u.leftColumn = pLeft->iColumn; |
| 115804 | pNewTerm->eOperator = WO_GT; |
| 115805 | markTermAsChild(pWC, idxNew, idxTerm); |
| 115806 | pTerm = &pWC->a[idxTerm]; |
| 115807 | pTerm->wtFlags |= TERM_COPIED; |
| 115808 | pNewTerm->prereqAll = pTerm->prereqAll; |
| 115809 | } |
| 115810 | } |
| 115811 | #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */ |
| @@ -116021,12 +115200,10 @@ | |
| 116021 | WhereLoop *pLoop; /* The Loop object */ |
| 116022 | char *zNotUsed; /* Extra space on the end of pIdx */ |
| 116023 | Bitmask idxCols; /* Bitmap of columns used for indexing */ |
| 116024 | Bitmask extraCols; /* Bitmap of additional columns */ |
| 116025 | u8 sentWarning = 0; /* True if a warnning has been issued */ |
| 116026 | Expr *pPartial = 0; /* Partial Index Expression */ |
| 116027 | int iContinue = 0; /* Jump here to skip excluded rows */ |
| 116028 | |
| 116029 | /* Generate code to skip over the creation and initialization of the |
| 116030 | ** transient index on 2nd and subsequent iterations of the loop. */ |
| 116031 | v = pParse->pVdbe; |
| 116032 | assert( v!=0 ); |
| @@ -116038,16 +115215,10 @@ | |
| 116038 | pTable = pSrc->pTab; |
| 116039 | pWCEnd = &pWC->a[pWC->nTerm]; |
| 116040 | pLoop = pLevel->pWLoop; |
| 116041 | idxCols = 0; |
| 116042 | for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){ |
| 116043 | if( pLoop->prereq==0 |
| 116044 | && (pTerm->wtFlags & TERM_VIRTUAL)==0 |
| 116045 | && sqlite3ExprIsTableConstant(pTerm->pExpr, pSrc->iCursor) ){ |
| 116046 | pPartial = sqlite3ExprAnd(pParse->db, pPartial, |
| 116047 | sqlite3ExprDup(pParse->db, pTerm->pExpr, 0)); |
| 116048 | } |
| 116049 | if( termCanDriveIndex(pTerm, pSrc, notReady) ){ |
| 116050 | int iCol = pTerm->u.leftColumn; |
| 116051 | Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol); |
| 116052 | testcase( iCol==BMS ); |
| 116053 | testcase( iCol==BMS-1 ); |
| @@ -116056,13 +115227,11 @@ | |
| 116056 | "automatic index on %s(%s)", pTable->zName, |
| 116057 | pTable->aCol[iCol].zName); |
| 116058 | sentWarning = 1; |
| 116059 | } |
| 116060 | if( (idxCols & cMask)==0 ){ |
| 116061 | if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ){ |
| 116062 | goto end_auto_index_create; |
| 116063 | } |
| 116064 | pLoop->aLTerm[nKeyCol++] = pTerm; |
| 116065 | idxCols |= cMask; |
| 116066 | } |
| 116067 | } |
| 116068 | } |
| @@ -116078,23 +115247,24 @@ | |
| 116078 | ** be a covering index because the index will not be updated if the |
| 116079 | ** original table changes and the index and table cannot both be used |
| 116080 | ** if they go out of sync. |
| 116081 | */ |
| 116082 | extraCols = pSrc->colUsed & (~idxCols | MASKBIT(BMS-1)); |
| 116083 | mxBitCol = MIN(BMS-1,pTable->nCol); |
| 116084 | testcase( pTable->nCol==BMS-1 ); |
| 116085 | testcase( pTable->nCol==BMS-2 ); |
| 116086 | for(i=0; i<mxBitCol; i++){ |
| 116087 | if( extraCols & MASKBIT(i) ) nKeyCol++; |
| 116088 | } |
| 116089 | if( pSrc->colUsed & MASKBIT(BMS-1) ){ |
| 116090 | nKeyCol += pTable->nCol - BMS + 1; |
| 116091 | } |
| 116092 | |
| 116093 | /* Construct the Index object to describe this index */ |
| 116094 | pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+1, 0, &zNotUsed); |
| 116095 | if( pIdx==0 ) goto end_auto_index_create; |
| 116096 | pLoop->u.btree.pIndex = pIdx; |
| 116097 | pIdx->zName = "auto-index"; |
| 116098 | pIdx->pTable = pTable; |
| 116099 | n = 0; |
| 116100 | idxCols = 0; |
| @@ -116142,33 +115312,22 @@ | |
| 116142 | sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1); |
| 116143 | sqlite3VdbeSetP4KeyInfo(pParse, pIdx); |
| 116144 | VdbeComment((v, "for %s", pTable->zName)); |
| 116145 | |
| 116146 | /* Fill the automatic index with content */ |
| 116147 | sqlite3ExprCachePush(pParse); |
| 116148 | addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v); |
| 116149 | if( pPartial ){ |
| 116150 | iContinue = sqlite3VdbeMakeLabel(v); |
| 116151 | sqlite3ExprIfFalse(pParse, pPartial, iContinue, SQLITE_JUMPIFNULL); |
| 116152 | pLoop->wsFlags |= WHERE_PARTIALIDX; |
| 116153 | } |
| 116154 | regRecord = sqlite3GetTempReg(pParse); |
| 116155 | sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0); |
| 116156 | sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord); |
| 116157 | sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); |
| 116158 | if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue); |
| 116159 | sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v); |
| 116160 | sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX); |
| 116161 | sqlite3VdbeJumpHere(v, addrTop); |
| 116162 | sqlite3ReleaseTempReg(pParse, regRecord); |
| 116163 | sqlite3ExprCachePop(pParse); |
| 116164 | |
| 116165 | /* Jump here when skipping the initialization */ |
| 116166 | sqlite3VdbeJumpHere(v, addrInit); |
| 116167 | |
| 116168 | end_auto_index_create: |
| 116169 | sqlite3ExprDelete(pParse->db, pPartial); |
| 116170 | } |
| 116171 | #endif /* SQLITE_OMIT_AUTOMATIC_INDEX */ |
| 116172 | |
| 116173 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 116174 | /* |
| @@ -116323,23 +115482,23 @@ | |
| 116323 | } |
| 116324 | |
| 116325 | return pParse->nErr; |
| 116326 | } |
| 116327 | #endif /* !defined(SQLITE_OMIT_VIRTUALTABLE) */ |
| 116328 | |
| 116329 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 116330 | /* |
| 116331 | ** Estimate the location of a particular key among all keys in an |
| 116332 | ** index. Store the results in aStat as follows: |
| 116333 | ** |
| 116334 | ** aStat[0] Est. number of rows less than pVal |
| 116335 | ** aStat[1] Est. number of rows equal to pVal |
| 116336 | ** |
| 116337 | ** Return the index of the sample that is the smallest sample that |
| 116338 | ** is greater than or equal to pRec. |
| 116339 | */ |
| 116340 | static int whereKeyStats( |
| 116341 | Parse *pParse, /* Database connection */ |
| 116342 | Index *pIdx, /* Index to consider domain of */ |
| 116343 | UnpackedRecord *pRec, /* Vector of values to consider */ |
| 116344 | int roundUp, /* Round up if true. Round down if false */ |
| 116345 | tRowcnt *aStat /* OUT: stats written here */ |
| @@ -116417,11 +115576,10 @@ | |
| 116417 | }else{ |
| 116418 | iGap = iGap/3; |
| 116419 | } |
| 116420 | aStat[0] = iLower + iGap; |
| 116421 | } |
| 116422 | return i; |
| 116423 | } |
| 116424 | #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */ |
| 116425 | |
| 116426 | /* |
| 116427 | ** If it is not NULL, pTerm is a term that provides an upper or lower |
| @@ -116568,11 +115726,11 @@ | |
| 116568 | ** pLower pUpper |
| 116569 | ** |
| 116570 | ** If either of the upper or lower bound is not present, then NULL is passed in |
| 116571 | ** place of the corresponding WhereTerm. |
| 116572 | ** |
| 116573 | ** The value in (pBuilder->pNew->u.btree.nEq) is the number of the index |
| 116574 | ** column subject to the range constraint. Or, equivalently, the number of |
| 116575 | ** equality constraints optimized by the proposed index scan. For example, |
| 116576 | ** assuming index p is on t1(a, b), and the SQL query is: |
| 116577 | ** |
| 116578 | ** ... FROM t1 WHERE a = ? AND b > ? AND b < ? ... |
| @@ -116584,11 +115742,11 @@ | |
| 116584 | ** |
| 116585 | ** then nEq is set to 0. |
| 116586 | ** |
| 116587 | ** When this function is called, *pnOut is set to the sqlite3LogEst() of the |
| 116588 | ** number of rows that the index scan is expected to visit without |
| 116589 | ** considering the range constraints. If nEq is 0, then *pnOut is the number of |
| 116590 | ** rows in the index. Assuming no error occurs, *pnOut is adjusted (reduced) |
| 116591 | ** to account for the range constraints pLower and pUpper. |
| 116592 | ** |
| 116593 | ** In the absence of sqlite_stat4 ANALYZE data, or if such data cannot be |
| 116594 | ** used, a single range inequality reduces the search space by a factor of 4. |
| @@ -116608,11 +115766,14 @@ | |
| 116608 | |
| 116609 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 116610 | Index *p = pLoop->u.btree.pIndex; |
| 116611 | int nEq = pLoop->u.btree.nEq; |
| 116612 | |
| 116613 | if( p->nSample>0 && nEq<p->nSampleCol ){ |
| 116614 | if( nEq==pBuilder->nRecValid ){ |
| 116615 | UnpackedRecord *pRec = pBuilder->pRec; |
| 116616 | tRowcnt a[2]; |
| 116617 | u8 aff; |
| 116618 | |
| @@ -116624,23 +115785,19 @@ | |
| 116624 | ** |
| 116625 | ** Or, if pLower is NULL or $L cannot be extracted from it (because it |
| 116626 | ** is not a simple variable or literal value), the lower bound of the |
| 116627 | ** range is $P. Due to a quirk in the way whereKeyStats() works, even |
| 116628 | ** if $L is available, whereKeyStats() is called for both ($P) and |
| 116629 | ** ($P:$L) and the larger of the two returned values is used. |
| 116630 | ** |
| 116631 | ** Similarly, iUpper is to be set to the estimate of the number of rows |
| 116632 | ** less than the upper bound of the range query. Where the upper bound |
| 116633 | ** is either ($P) or ($P:$U). Again, even if $U is available, both values |
| 116634 | ** of iUpper are requested of whereKeyStats() and the smaller used. |
| 116635 | ** |
| 116636 | ** The number of rows between the two bounds is then just iUpper-iLower. |
| 116637 | */ |
| 116638 | tRowcnt iLower; /* Rows less than the lower bound */ |
| 116639 | tRowcnt iUpper; /* Rows less than the upper bound */ |
| 116640 | int iLwrIdx = -2; /* aSample[] for the lower bound */ |
| 116641 | int iUprIdx = -1; /* aSample[] for the upper bound */ |
| 116642 | |
| 116643 | if( pRec ){ |
| 116644 | testcase( pRec->nField!=pBuilder->nRecValid ); |
| 116645 | pRec->nField = pBuilder->nRecValid; |
| 116646 | } |
| @@ -116650,11 +115807,11 @@ | |
| 116650 | aff = p->pTable->aCol[p->aiColumn[nEq]].affinity; |
| 116651 | } |
| 116652 | /* Determine iLower and iUpper using ($P) only. */ |
| 116653 | if( nEq==0 ){ |
| 116654 | iLower = 0; |
| 116655 | iUpper = p->nRowEst0; |
| 116656 | }else{ |
| 116657 | /* Note: this call could be optimized away - since the same values must |
| 116658 | ** have been requested when testing key $P in whereEqualScanEst(). */ |
| 116659 | whereKeyStats(pParse, p, pRec, 0, a); |
| 116660 | iLower = a[0]; |
| @@ -116674,11 +115831,11 @@ | |
| 116674 | int bOk; /* True if value is extracted from pExpr */ |
| 116675 | Expr *pExpr = pLower->pExpr->pRight; |
| 116676 | rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk); |
| 116677 | if( rc==SQLITE_OK && bOk ){ |
| 116678 | tRowcnt iNew; |
| 116679 | iLwrIdx = whereKeyStats(pParse, p, pRec, 0, a); |
| 116680 | iNew = a[0] + ((pLower->eOperator & (WO_GT|WO_LE)) ? a[1] : 0); |
| 116681 | if( iNew>iLower ) iLower = iNew; |
| 116682 | nOut--; |
| 116683 | pLower = 0; |
| 116684 | } |
| @@ -116689,11 +115846,11 @@ | |
| 116689 | int bOk; /* True if value is extracted from pExpr */ |
| 116690 | Expr *pExpr = pUpper->pExpr->pRight; |
| 116691 | rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk); |
| 116692 | if( rc==SQLITE_OK && bOk ){ |
| 116693 | tRowcnt iNew; |
| 116694 | iUprIdx = whereKeyStats(pParse, p, pRec, 1, a); |
| 116695 | iNew = a[0] + ((pUpper->eOperator & (WO_GT|WO_LE)) ? a[1] : 0); |
| 116696 | if( iNew<iUpper ) iUpper = iNew; |
| 116697 | nOut--; |
| 116698 | pUpper = 0; |
| 116699 | } |
| @@ -116701,15 +115858,10 @@ | |
| 116701 | |
| 116702 | pBuilder->pRec = pRec; |
| 116703 | if( rc==SQLITE_OK ){ |
| 116704 | if( iUpper>iLower ){ |
| 116705 | nNew = sqlite3LogEst(iUpper - iLower); |
| 116706 | /* TUNING: If both iUpper and iLower are derived from the same |
| 116707 | ** sample, then assume they are 4x more selective. This brings |
| 116708 | ** the estimated selectivity more in line with what it would be |
| 116709 | ** if estimated without the use of STAT3/4 tables. */ |
| 116710 | if( iLwrIdx==iUprIdx ) nNew -= 20; assert( 20==sqlite3LogEst(4) ); |
| 116711 | }else{ |
| 116712 | nNew = 10; assert( 10==sqlite3LogEst(2) ); |
| 116713 | } |
| 116714 | if( nNew<nOut ){ |
| 116715 | nOut = nNew; |
| @@ -116730,19 +115882,16 @@ | |
| 116730 | #endif |
| 116731 | assert( pUpper==0 || (pUpper->wtFlags & TERM_VNULL)==0 ); |
| 116732 | nNew = whereRangeAdjust(pLower, nOut); |
| 116733 | nNew = whereRangeAdjust(pUpper, nNew); |
| 116734 | |
| 116735 | /* TUNING: If there is both an upper and lower limit and neither limit |
| 116736 | ** has an application-defined likelihood(), assume the range is |
| 116737 | ** reduced by an additional 75%. This means that, by default, an open-ended |
| 116738 | ** range query (e.g. col > ?) is assumed to match 1/4 of the rows in the |
| 116739 | ** index. While a closed range (e.g. col BETWEEN ? AND ?) is estimated to |
| 116740 | ** match 1/64 of the index. */ |
| 116741 | if( pLower && pLower->truthProb>0 && pUpper && pUpper->truthProb>0 ){ |
| 116742 | nNew -= 20; |
| 116743 | } |
| 116744 | |
| 116745 | nOut -= (pLower!=0) + (pUpper!=0); |
| 116746 | if( nNew<10 ) nNew = 10; |
| 116747 | if( nNew<nOut ) nOut = nNew; |
| 116748 | #if defined(WHERETRACE_ENABLED) |
| @@ -117098,11 +116247,11 @@ | |
| 117098 | |
| 117099 | /* This module is only called on query plans that use an index. */ |
| 117100 | pLoop = pLevel->pWLoop; |
| 117101 | assert( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 ); |
| 117102 | nEq = pLoop->u.btree.nEq; |
| 117103 | nSkip = pLoop->nSkip; |
| 117104 | pIdx = pLoop->u.btree.pIndex; |
| 117105 | assert( pIdx!=0 ); |
| 117106 | |
| 117107 | /* Figure out how many memory cells we will need then allocate them. |
| 117108 | */ |
| @@ -117212,11 +116361,11 @@ | |
| 117212 | ** "a=? AND b>?" |
| 117213 | */ |
| 117214 | static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){ |
| 117215 | Index *pIndex = pLoop->u.btree.pIndex; |
| 117216 | u16 nEq = pLoop->u.btree.nEq; |
| 117217 | u16 nSkip = pLoop->nSkip; |
| 117218 | int i, j; |
| 117219 | Column *aCol = pTab->aCol; |
| 117220 | i16 *aiColumn = pIndex->aiColumn; |
| 117221 | |
| 117222 | if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return; |
| @@ -117243,27 +116392,23 @@ | |
| 117243 | sqlite3StrAccumAppend(pStr, ")", 1); |
| 117244 | } |
| 117245 | |
| 117246 | /* |
| 117247 | ** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN |
| 117248 | ** command, or if either SQLITE_DEBUG or SQLITE_ENABLE_STMT_SCANSTATUS was |
| 117249 | ** defined at compile-time. If it is not a no-op, a single OP_Explain opcode |
| 117250 | ** is added to the output to describe the table scan strategy in pLevel. |
| 117251 | ** |
| 117252 | ** If an OP_Explain opcode is added to the VM, its address is returned. |
| 117253 | ** Otherwise, if no OP_Explain is coded, zero is returned. |
| 117254 | */ |
| 117255 | static int explainOneScan( |
| 117256 | Parse *pParse, /* Parse context */ |
| 117257 | SrcList *pTabList, /* Table list this loop refers to */ |
| 117258 | WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */ |
| 117259 | int iLevel, /* Value for "level" column of output */ |
| 117260 | int iFrom, /* Value for "from" column of output */ |
| 117261 | u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */ |
| 117262 | ){ |
| 117263 | int ret = 0; |
| 117264 | #if !defined(SQLITE_DEBUG) && !defined(SQLITE_ENABLE_STMT_SCANSTATUS) |
| 117265 | if( pParse->explain==2 ) |
| 117266 | #endif |
| 117267 | { |
| 117268 | struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom]; |
| 117269 | Vdbe *v = pParse->pVdbe; /* VM being constructed */ |
| @@ -117276,11 +116421,11 @@ | |
| 117276 | StrAccum str; /* EQP output string */ |
| 117277 | char zBuf[100]; /* Initial space for EQP output string */ |
| 117278 | |
| 117279 | pLoop = pLevel->pWLoop; |
| 117280 | flags = pLoop->wsFlags; |
| 117281 | if( (flags&WHERE_MULTI_OR) || (wctrlFlags&WHERE_ONETABLE_ONLY) ) return 0; |
| 117282 | |
| 117283 | isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0 |
| 117284 | || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0)) |
| 117285 | || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX)); |
| 117286 | |
| @@ -117305,12 +116450,10 @@ | |
| 117305 | assert( !(flags&WHERE_AUTO_INDEX) || (flags&WHERE_IDX_ONLY) ); |
| 117306 | if( !HasRowid(pItem->pTab) && IsPrimaryKeyIndex(pIdx) ){ |
| 117307 | if( isSearch ){ |
| 117308 | zFmt = "PRIMARY KEY"; |
| 117309 | } |
| 117310 | }else if( flags & WHERE_PARTIALIDX ){ |
| 117311 | zFmt = "AUTOMATIC PARTIAL COVERING INDEX"; |
| 117312 | }else if( flags & WHERE_AUTO_INDEX ){ |
| 117313 | zFmt = "AUTOMATIC COVERING INDEX"; |
| 117314 | }else if( flags & WHERE_IDX_ONLY ){ |
| 117315 | zFmt = "COVERING INDEX %s"; |
| 117316 | }else{ |
| @@ -117348,49 +116491,16 @@ | |
| 117348 | }else{ |
| 117349 | sqlite3StrAccumAppend(&str, " (~1 row)", 9); |
| 117350 | } |
| 117351 | #endif |
| 117352 | zMsg = sqlite3StrAccumFinish(&str); |
| 117353 | ret = sqlite3VdbeAddOp4(v, OP_Explain, iId, iLevel, iFrom, zMsg,P4_DYNAMIC); |
| 117354 | } |
| 117355 | return ret; |
| 117356 | } |
| 117357 | #else |
| 117358 | # define explainOneScan(u,v,w,x,y,z) 0 |
| 117359 | #endif /* SQLITE_OMIT_EXPLAIN */ |
| 117360 | |
| 117361 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 117362 | /* |
| 117363 | ** Configure the VM passed as the first argument with an |
| 117364 | ** sqlite3_stmt_scanstatus() entry corresponding to the scan used to |
| 117365 | ** implement level pLvl. Argument pSrclist is a pointer to the FROM |
| 117366 | ** clause that the scan reads data from. |
| 117367 | ** |
| 117368 | ** If argument addrExplain is not 0, it must be the address of an |
| 117369 | ** OP_Explain instruction that describes the same loop. |
| 117370 | */ |
| 117371 | static void addScanStatus( |
| 117372 | Vdbe *v, /* Vdbe to add scanstatus entry to */ |
| 117373 | SrcList *pSrclist, /* FROM clause pLvl reads data from */ |
| 117374 | WhereLevel *pLvl, /* Level to add scanstatus() entry for */ |
| 117375 | int addrExplain /* Address of OP_Explain (or 0) */ |
| 117376 | ){ |
| 117377 | const char *zObj = 0; |
| 117378 | WhereLoop *pLoop = pLvl->pWLoop; |
| 117379 | if( (pLoop->wsFlags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){ |
| 117380 | zObj = pLoop->u.btree.pIndex->zName; |
| 117381 | }else{ |
| 117382 | zObj = pSrclist->a[pLvl->iFrom].zName; |
| 117383 | } |
| 117384 | sqlite3VdbeScanStatus( |
| 117385 | v, addrExplain, pLvl->addrBody, pLvl->addrVisit, pLoop->nOut, zObj |
| 117386 | ); |
| 117387 | } |
| 117388 | #else |
| 117389 | # define addScanStatus(a, b, c, d) ((void)d) |
| 117390 | #endif |
| 117391 | |
| 117392 | |
| 117393 | |
| 117394 | /* |
| 117395 | ** Generate code for the start of the iLevel-th loop in the WHERE clause |
| 117396 | ** implementation described by pWInfo. |
| @@ -117688,11 +116798,11 @@ | |
| 117688 | u8 bSeekPastNull = 0; /* True to seek past initial nulls */ |
| 117689 | u8 bStopAtNull = 0; /* Add condition to terminate at NULLs */ |
| 117690 | |
| 117691 | pIdx = pLoop->u.btree.pIndex; |
| 117692 | iIdxCur = pLevel->iIdxCur; |
| 117693 | assert( nEq>=pLoop->nSkip ); |
| 117694 | |
| 117695 | /* If this loop satisfies a sort order (pOrderBy) request that |
| 117696 | ** was passed to this function to implement a "SELECT min(x) ..." |
| 117697 | ** query, then the caller will only allow the loop to run for |
| 117698 | ** a single iteration. This means that the first row returned |
| @@ -117705,11 +116815,11 @@ | |
| 117705 | || (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0 ); |
| 117706 | if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0 |
| 117707 | && pWInfo->nOBSat>0 |
| 117708 | && (pIdx->nKeyCol>nEq) |
| 117709 | ){ |
| 117710 | assert( pLoop->nSkip==0 ); |
| 117711 | bSeekPastNull = 1; |
| 117712 | nExtraReg = 1; |
| 117713 | } |
| 117714 | |
| 117715 | /* Find any inequality constraint terms for the start and end |
| @@ -118054,15 +117164,13 @@ | |
| 118054 | pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0, |
| 118055 | wctrlFlags, iCovCur); |
| 118056 | assert( pSubWInfo || pParse->nErr || db->mallocFailed ); |
| 118057 | if( pSubWInfo ){ |
| 118058 | WhereLoop *pSubLoop; |
| 118059 | int addrExplain = explainOneScan( |
| 118060 | pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0 |
| 118061 | ); |
| 118062 | addScanStatus(v, pOrTab, &pSubWInfo->a[0], addrExplain); |
| 118063 | |
| 118064 | /* This is the sub-WHERE clause body. First skip over |
| 118065 | ** duplicate rows from prior sub-WHERE clauses, and record the |
| 118066 | ** rowid (or PRIMARY KEY) for the current row so that the same |
| 118067 | ** row will be skipped in subsequent sub-WHERE clauses. |
| 118068 | */ |
| @@ -118189,14 +117297,10 @@ | |
| 118189 | VdbeCoverageIf(v, bRev!=0); |
| 118190 | pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP; |
| 118191 | } |
| 118192 | } |
| 118193 | |
| 118194 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 118195 | pLevel->addrVisit = sqlite3VdbeCurrentAddr(v); |
| 118196 | #endif |
| 118197 | |
| 118198 | /* Insert code to test every subexpression that can be completely |
| 118199 | ** computed using the current set of tables. |
| 118200 | */ |
| 118201 | for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){ |
| 118202 | Expr *pE; |
| @@ -118332,11 +117436,11 @@ | |
| 118332 | } |
| 118333 | sqlite3DebugPrintf(" %-19s", z); |
| 118334 | sqlite3_free(z); |
| 118335 | } |
| 118336 | if( p->wsFlags & WHERE_SKIPSCAN ){ |
| 118337 | sqlite3DebugPrintf(" f %05x %d-%d", p->wsFlags, p->nLTerm,p->nSkip); |
| 118338 | }else{ |
| 118339 | sqlite3DebugPrintf(" f %05x N %d", p->wsFlags, p->nLTerm); |
| 118340 | } |
| 118341 | sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut); |
| 118342 | if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){ |
| @@ -118443,41 +117547,34 @@ | |
| 118443 | sqlite3DbFree(db, pWInfo); |
| 118444 | } |
| 118445 | } |
| 118446 | |
| 118447 | /* |
| 118448 | ** Return TRUE if all of the following are true: |
| 118449 | ** |
| 118450 | ** (1) X has the same or lower cost that Y |
| 118451 | ** (2) X is a proper subset of Y |
| 118452 | ** (3) X skips at least as many columns as Y |
| 118453 | ** |
| 118454 | ** By "proper subset" we mean that X uses fewer WHERE clause terms |
| 118455 | ** than Y and that every WHERE clause term used by X is also used |
| 118456 | ** by Y. |
| 118457 | ** |
| 118458 | ** If X is a proper subset of Y then Y is a better choice and ought |
| 118459 | ** to have a lower cost. This routine returns TRUE when that cost |
| 118460 | ** relationship is inverted and needs to be adjusted. The third rule |
| 118461 | ** was added because if X uses skip-scan less than Y it still might |
| 118462 | ** deserve a lower cost even if it is a proper subset of Y. |
| 118463 | */ |
| 118464 | static int whereLoopCheaperProperSubset( |
| 118465 | const WhereLoop *pX, /* First WhereLoop to compare */ |
| 118466 | const WhereLoop *pY /* Compare against this WhereLoop */ |
| 118467 | ){ |
| 118468 | int i, j; |
| 118469 | if( pX->nLTerm-pX->nSkip >= pY->nLTerm-pY->nSkip ){ |
| 118470 | return 0; /* X is not a subset of Y */ |
| 118471 | } |
| 118472 | if( pY->nSkip > pX->nSkip ) return 0; |
| 118473 | if( pX->rRun >= pY->rRun ){ |
| 118474 | if( pX->rRun > pY->rRun ) return 0; /* X costs more than Y */ |
| 118475 | if( pX->nOut > pY->nOut ) return 0; /* X costs more than Y */ |
| 118476 | } |
| 118477 | for(i=pX->nLTerm-1; i>=0; i--){ |
| 118478 | if( pX->aLTerm[i]==0 ) continue; |
| 118479 | for(j=pY->nLTerm-1; j>=0; j--){ |
| 118480 | if( pY->aLTerm[j]==pX->aLTerm[i] ) break; |
| 118481 | } |
| 118482 | if( j<0 ) return 0; /* X not a subset of Y since term X[i] not used by Y */ |
| 118483 | } |
| @@ -118495,28 +117592,37 @@ | |
| 118495 | ** is a proper subset. |
| 118496 | ** |
| 118497 | ** To say "WhereLoop X is a proper subset of Y" means that X uses fewer |
| 118498 | ** WHERE clause terms than Y and that every WHERE clause term used by X is |
| 118499 | ** also used by Y. |
| 118500 | */ |
| 118501 | static void whereLoopAdjustCost(const WhereLoop *p, WhereLoop *pTemplate){ |
| 118502 | if( (pTemplate->wsFlags & WHERE_INDEXED)==0 ) return; |
| 118503 | for(; p; p=p->pNextLoop){ |
| 118504 | if( p->iTab!=pTemplate->iTab ) continue; |
| 118505 | if( (p->wsFlags & WHERE_INDEXED)==0 ) continue; |
| 118506 | if( whereLoopCheaperProperSubset(p, pTemplate) ){ |
| 118507 | /* Adjust pTemplate cost downward so that it is cheaper than its |
| 118508 | ** subset p. */ |
| 118509 | WHERETRACE(0x80,("subset cost adjustment %d,%d to %d,%d\n", |
| 118510 | pTemplate->rRun, pTemplate->nOut, p->rRun, p->nOut-1)); |
| 118511 | pTemplate->rRun = p->rRun; |
| 118512 | pTemplate->nOut = p->nOut - 1; |
| 118513 | }else if( whereLoopCheaperProperSubset(pTemplate, p) ){ |
| 118514 | /* Adjust pTemplate cost upward so that it is costlier than p since |
| 118515 | ** pTemplate is a proper subset of p */ |
| 118516 | WHERETRACE(0x80,("subset cost adjustment %d,%d to %d,%d\n", |
| 118517 | pTemplate->rRun, pTemplate->nOut, p->rRun, p->nOut+1)); |
| 118518 | pTemplate->rRun = p->rRun; |
| 118519 | pTemplate->nOut = p->nOut + 1; |
| 118520 | } |
| 118521 | } |
| 118522 | } |
| @@ -118557,13 +117663,12 @@ | |
| 118557 | ** rSetup. Call this SETUP-INVARIANT */ |
| 118558 | assert( p->rSetup>=pTemplate->rSetup ); |
| 118559 | |
| 118560 | /* Any loop using an appliation-defined index (or PRIMARY KEY or |
| 118561 | ** UNIQUE constraint) with one or more == constraints is better |
| 118562 | ** than an automatic index. Unless it is a skip-scan. */ |
| 118563 | if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 |
| 118564 | && (pTemplate->nSkip)==0 |
| 118565 | && (pTemplate->wsFlags & WHERE_INDEXED)!=0 |
| 118566 | && (pTemplate->wsFlags & WHERE_COLUMN_EQ)!=0 |
| 118567 | && (p->prereq & pTemplate->prereq)==pTemplate->prereq |
| 118568 | ){ |
| 118569 | break; |
| @@ -118799,11 +117904,11 @@ | |
| 118799 | int opMask; /* Valid operators for constraints */ |
| 118800 | WhereScan scan; /* Iterator for WHERE terms */ |
| 118801 | Bitmask saved_prereq; /* Original value of pNew->prereq */ |
| 118802 | u16 saved_nLTerm; /* Original value of pNew->nLTerm */ |
| 118803 | u16 saved_nEq; /* Original value of pNew->u.btree.nEq */ |
| 118804 | u16 saved_nSkip; /* Original value of pNew->nSkip */ |
| 118805 | u32 saved_wsFlags; /* Original value of pNew->wsFlags */ |
| 118806 | LogEst saved_nOut; /* Original value of pNew->nOut */ |
| 118807 | int iCol; /* Index of the column in the table */ |
| 118808 | int rc = SQLITE_OK; /* Return code */ |
| 118809 | LogEst rSize; /* Number of rows in the table */ |
| @@ -118828,18 +117933,56 @@ | |
| 118828 | iCol = pProbe->aiColumn[pNew->u.btree.nEq]; |
| 118829 | |
| 118830 | pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, iCol, |
| 118831 | opMask, pProbe); |
| 118832 | saved_nEq = pNew->u.btree.nEq; |
| 118833 | saved_nSkip = pNew->nSkip; |
| 118834 | saved_nLTerm = pNew->nLTerm; |
| 118835 | saved_wsFlags = pNew->wsFlags; |
| 118836 | saved_prereq = pNew->prereq; |
| 118837 | saved_nOut = pNew->nOut; |
| 118838 | pNew->rSetup = 0; |
| 118839 | rSize = pProbe->aiRowLogEst[0]; |
| 118840 | rLogSize = estLog(rSize); |
| 118841 | for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){ |
| 118842 | u16 eOp = pTerm->eOperator; /* Shorthand for pTerm->eOperator */ |
| 118843 | LogEst rCostIdx; |
| 118844 | LogEst nOutUnadjusted; /* nOut before IN() and WHERE adjustments */ |
| 118845 | int nIn = 0; |
| @@ -118930,10 +118073,11 @@ | |
| 118930 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 118931 | tRowcnt nOut = 0; |
| 118932 | if( nInMul==0 |
| 118933 | && pProbe->nSample |
| 118934 | && pNew->u.btree.nEq<=pProbe->nSampleCol |
| 118935 | && ((eOp & WO_IN)==0 || !ExprHasProperty(pTerm->pExpr, EP_xIsSelect)) |
| 118936 | ){ |
| 118937 | Expr *pExpr = pTerm->pExpr; |
| 118938 | if( (eOp & (WO_EQ|WO_ISNULL))!=0 ){ |
| 118939 | testcase( eOp & WO_EQ ); |
| @@ -118997,49 +118141,14 @@ | |
| 118997 | pBuilder->nRecValid = nRecValid; |
| 118998 | #endif |
| 118999 | } |
| 119000 | pNew->prereq = saved_prereq; |
| 119001 | pNew->u.btree.nEq = saved_nEq; |
| 119002 | pNew->nSkip = saved_nSkip; |
| 119003 | pNew->wsFlags = saved_wsFlags; |
| 119004 | pNew->nOut = saved_nOut; |
| 119005 | pNew->nLTerm = saved_nLTerm; |
| 119006 | |
| 119007 | /* Consider using a skip-scan if there are no WHERE clause constraints |
| 119008 | ** available for the left-most terms of the index, and if the average |
| 119009 | ** number of repeats in the left-most terms is at least 18. |
| 119010 | ** |
| 119011 | ** The magic number 18 is selected on the basis that scanning 17 rows |
| 119012 | ** is almost always quicker than an index seek (even though if the index |
| 119013 | ** contains fewer than 2^17 rows we assume otherwise in other parts of |
| 119014 | ** the code). And, even if it is not, it should not be too much slower. |
| 119015 | ** On the other hand, the extra seeks could end up being significantly |
| 119016 | ** more expensive. */ |
| 119017 | assert( 42==sqlite3LogEst(18) ); |
| 119018 | if( saved_nEq==saved_nSkip |
| 119019 | && saved_nEq+1<pProbe->nKeyCol |
| 119020 | && pProbe->noSkipScan==0 |
| 119021 | && pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */ |
| 119022 | && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK |
| 119023 | ){ |
| 119024 | LogEst nIter; |
| 119025 | pNew->u.btree.nEq++; |
| 119026 | pNew->nSkip++; |
| 119027 | pNew->aLTerm[pNew->nLTerm++] = 0; |
| 119028 | pNew->wsFlags |= WHERE_SKIPSCAN; |
| 119029 | nIter = pProbe->aiRowLogEst[saved_nEq] - pProbe->aiRowLogEst[saved_nEq+1]; |
| 119030 | pNew->nOut -= nIter; |
| 119031 | /* TUNING: Because uncertainties in the estimates for skip-scan queries, |
| 119032 | ** add a 1.375 fudge factor to make skip-scan slightly less likely. */ |
| 119033 | nIter += 5; |
| 119034 | whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nIter + nInMul); |
| 119035 | pNew->nOut = saved_nOut; |
| 119036 | pNew->u.btree.nEq = saved_nEq; |
| 119037 | pNew->nSkip = saved_nSkip; |
| 119038 | pNew->wsFlags = saved_wsFlags; |
| 119039 | } |
| 119040 | |
| 119041 | return rc; |
| 119042 | } |
| 119043 | |
| 119044 | /* |
| 119045 | ** Return True if it is possible that pIndex might be useful in |
| @@ -119214,11 +118323,11 @@ | |
| 119214 | WhereTerm *pWCEnd = pWC->a + pWC->nTerm; |
| 119215 | for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){ |
| 119216 | if( pTerm->prereqRight & pNew->maskSelf ) continue; |
| 119217 | if( termCanDriveIndex(pTerm, pSrc, 0) ){ |
| 119218 | pNew->u.btree.nEq = 1; |
| 119219 | pNew->nSkip = 0; |
| 119220 | pNew->u.btree.pIndex = 0; |
| 119221 | pNew->nLTerm = 1; |
| 119222 | pNew->aLTerm[0] = pTerm; |
| 119223 | /* TUNING: One-time cost for computing the automatic index is |
| 119224 | ** estimated to be X*N*log2(N) where N is the number of rows in |
| @@ -119255,11 +118364,11 @@ | |
| 119255 | testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */ |
| 119256 | continue; /* Partial index inappropriate for this query */ |
| 119257 | } |
| 119258 | rSize = pProbe->aiRowLogEst[0]; |
| 119259 | pNew->u.btree.nEq = 0; |
| 119260 | pNew->nSkip = 0; |
| 119261 | pNew->nLTerm = 0; |
| 119262 | pNew->iSortIdx = 0; |
| 119263 | pNew->rSetup = 0; |
| 119264 | pNew->prereq = mExtra; |
| 119265 | pNew->nOut = rSize; |
| @@ -119805,11 +118914,11 @@ | |
| 119805 | for(j=0; j<nColumn; j++){ |
| 119806 | u8 bOnce; /* True to run the ORDER BY search loop */ |
| 119807 | |
| 119808 | /* Skip over == and IS NULL terms */ |
| 119809 | if( j<pLoop->u.btree.nEq |
| 119810 | && pLoop->nSkip==0 |
| 119811 | && ((i = pLoop->aLTerm[j]->eOperator) & (WO_EQ|WO_ISNULL))!=0 |
| 119812 | ){ |
| 119813 | if( i & WO_ISNULL ){ |
| 119814 | testcase( isOrderDistinct ); |
| 119815 | isOrderDistinct = 0; |
| @@ -120259,11 +119368,11 @@ | |
| 120259 | } |
| 120260 | } |
| 120261 | } |
| 120262 | |
| 120263 | #ifdef WHERETRACE_ENABLED /* >=2 */ |
| 120264 | if( sqlite3WhereTrace & 0x02 ){ |
| 120265 | sqlite3DebugPrintf("---- after round %d ----\n", iLoop); |
| 120266 | for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){ |
| 120267 | sqlite3DebugPrintf(" %s cost=%-3d nrow=%-3d order=%c", |
| 120268 | wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow, |
| 120269 | pTo->isOrdered>=0 ? (pTo->isOrdered+'0') : '?'); |
| @@ -120378,11 +119487,11 @@ | |
| 120378 | if( pItem->zIndex ) return 0; |
| 120379 | iCur = pItem->iCursor; |
| 120380 | pWC = &pWInfo->sWC; |
| 120381 | pLoop = pBuilder->pNew; |
| 120382 | pLoop->wsFlags = 0; |
| 120383 | pLoop->nSkip = 0; |
| 120384 | pTerm = findTerm(pWC, iCur, -1, 0, WO_EQ, 0); |
| 120385 | if( pTerm ){ |
| 120386 | pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_IPK|WHERE_ONEROW; |
| 120387 | pLoop->aLTerm[0] = pTerm; |
| 120388 | pLoop->nLTerm = 1; |
| @@ -120390,10 +119499,11 @@ | |
| 120390 | /* TUNING: Cost of a rowid lookup is 10 */ |
| 120391 | pLoop->rRun = 33; /* 33==sqlite3LogEst(10) */ |
| 120392 | }else{ |
| 120393 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 120394 | assert( pLoop->aLTermSpace==pLoop->aLTerm ); |
| 120395 | if( !IsUniqueIndex(pIdx) |
| 120396 | || pIdx->pPartIdxWhere!=0 |
| 120397 | || pIdx->nKeyCol>ArraySize(pLoop->aLTermSpace) |
| 120398 | ) continue; |
| 120399 | for(j=0; j<pIdx->nKeyCol; j++){ |
| @@ -120898,30 +120008,22 @@ | |
| 120898 | ** loop below generates code for a single nested loop of the VM |
| 120899 | ** program. |
| 120900 | */ |
| 120901 | notReady = ~(Bitmask)0; |
| 120902 | for(ii=0; ii<nTabList; ii++){ |
| 120903 | int addrExplain; |
| 120904 | int wsFlags; |
| 120905 | pLevel = &pWInfo->a[ii]; |
| 120906 | wsFlags = pLevel->pWLoop->wsFlags; |
| 120907 | #ifndef SQLITE_OMIT_AUTOMATIC_INDEX |
| 120908 | if( (pLevel->pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){ |
| 120909 | constructAutomaticIndex(pParse, &pWInfo->sWC, |
| 120910 | &pTabList->a[pLevel->iFrom], notReady, pLevel); |
| 120911 | if( db->mallocFailed ) goto whereBeginError; |
| 120912 | } |
| 120913 | #endif |
| 120914 | addrExplain = explainOneScan( |
| 120915 | pParse, pTabList, pLevel, ii, pLevel->iFrom, wctrlFlags |
| 120916 | ); |
| 120917 | pLevel->addrBody = sqlite3VdbeCurrentAddr(v); |
| 120918 | notReady = codeOneLoopStart(pWInfo, ii, notReady); |
| 120919 | pWInfo->iContinue = pLevel->addrCont; |
| 120920 | if( (wsFlags&WHERE_MULTI_OR)==0 && (wctrlFlags&WHERE_ONETABLE_ONLY)==0 ){ |
| 120921 | addScanStatus(v, pTabList, pLevel, addrExplain); |
| 120922 | } |
| 120923 | } |
| 120924 | |
| 120925 | /* Done. */ |
| 120926 | VdbeModuleComment((v, "Begin WHERE-core")); |
| 120927 | return pWInfo; |
| @@ -125586,17 +124688,10 @@ | |
| 125586 | */ |
| 125587 | SQLITE_API int sqlite3_complete(const char *zSql){ |
| 125588 | u8 state = 0; /* Current state, using numbers defined in header comment */ |
| 125589 | u8 token; /* Value of the next token */ |
| 125590 | |
| 125591 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 125592 | if( zSql==0 ){ |
| 125593 | (void)SQLITE_MISUSE_BKPT; |
| 125594 | return 0; |
| 125595 | } |
| 125596 | #endif |
| 125597 | |
| 125598 | #ifndef SQLITE_OMIT_TRIGGER |
| 125599 | /* A complex statement machine used to detect the end of a CREATE TRIGGER |
| 125600 | ** statement. This is the normal case. |
| 125601 | */ |
| 125602 | static const u8 trans[8][8] = { |
| @@ -126190,107 +125285,75 @@ | |
| 126190 | |
| 126191 | va_start(ap, op); |
| 126192 | switch( op ){ |
| 126193 | |
| 126194 | /* Mutex configuration options are only available in a threadsafe |
| 126195 | ** compile. |
| 126196 | */ |
| 126197 | #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-54466-46756 */ |
| 126198 | case SQLITE_CONFIG_SINGLETHREAD: { |
| 126199 | /* Disable all mutexing */ |
| 126200 | sqlite3GlobalConfig.bCoreMutex = 0; |
| 126201 | sqlite3GlobalConfig.bFullMutex = 0; |
| 126202 | break; |
| 126203 | } |
| 126204 | #endif |
| 126205 | #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-20520-54086 */ |
| 126206 | case SQLITE_CONFIG_MULTITHREAD: { |
| 126207 | /* Disable mutexing of database connections */ |
| 126208 | /* Enable mutexing of core data structures */ |
| 126209 | sqlite3GlobalConfig.bCoreMutex = 1; |
| 126210 | sqlite3GlobalConfig.bFullMutex = 0; |
| 126211 | break; |
| 126212 | } |
| 126213 | #endif |
| 126214 | #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-59593-21810 */ |
| 126215 | case SQLITE_CONFIG_SERIALIZED: { |
| 126216 | /* Enable all mutexing */ |
| 126217 | sqlite3GlobalConfig.bCoreMutex = 1; |
| 126218 | sqlite3GlobalConfig.bFullMutex = 1; |
| 126219 | break; |
| 126220 | } |
| 126221 | #endif |
| 126222 | #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-63666-48755 */ |
| 126223 | case SQLITE_CONFIG_MUTEX: { |
| 126224 | /* Specify an alternative mutex implementation */ |
| 126225 | sqlite3GlobalConfig.mutex = *va_arg(ap, sqlite3_mutex_methods*); |
| 126226 | break; |
| 126227 | } |
| 126228 | #endif |
| 126229 | #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-14450-37597 */ |
| 126230 | case SQLITE_CONFIG_GETMUTEX: { |
| 126231 | /* Retrieve the current mutex implementation */ |
| 126232 | *va_arg(ap, sqlite3_mutex_methods*) = sqlite3GlobalConfig.mutex; |
| 126233 | break; |
| 126234 | } |
| 126235 | #endif |
| 126236 | |
| 126237 | case SQLITE_CONFIG_MALLOC: { |
| 126238 | /* EVIDENCE-OF: R-55594-21030 The SQLITE_CONFIG_MALLOC option takes a |
| 126239 | ** single argument which is a pointer to an instance of the |
| 126240 | ** sqlite3_mem_methods structure. The argument specifies alternative |
| 126241 | ** low-level memory allocation routines to be used in place of the memory |
| 126242 | ** allocation routines built into SQLite. */ |
| 126243 | sqlite3GlobalConfig.m = *va_arg(ap, sqlite3_mem_methods*); |
| 126244 | break; |
| 126245 | } |
| 126246 | case SQLITE_CONFIG_GETMALLOC: { |
| 126247 | /* EVIDENCE-OF: R-51213-46414 The SQLITE_CONFIG_GETMALLOC option takes a |
| 126248 | ** single argument which is a pointer to an instance of the |
| 126249 | ** sqlite3_mem_methods structure. The sqlite3_mem_methods structure is |
| 126250 | ** filled with the currently defined memory allocation routines. */ |
| 126251 | if( sqlite3GlobalConfig.m.xMalloc==0 ) sqlite3MemSetDefault(); |
| 126252 | *va_arg(ap, sqlite3_mem_methods*) = sqlite3GlobalConfig.m; |
| 126253 | break; |
| 126254 | } |
| 126255 | case SQLITE_CONFIG_MEMSTATUS: { |
| 126256 | /* EVIDENCE-OF: R-61275-35157 The SQLITE_CONFIG_MEMSTATUS option takes |
| 126257 | ** single argument of type int, interpreted as a boolean, which enables |
| 126258 | ** or disables the collection of memory allocation statistics. */ |
| 126259 | sqlite3GlobalConfig.bMemstat = va_arg(ap, int); |
| 126260 | break; |
| 126261 | } |
| 126262 | case SQLITE_CONFIG_SCRATCH: { |
| 126263 | /* EVIDENCE-OF: R-08404-60887 There are three arguments to |
| 126264 | ** SQLITE_CONFIG_SCRATCH: A pointer an 8-byte aligned memory buffer from |
| 126265 | ** which the scratch allocations will be drawn, the size of each scratch |
| 126266 | ** allocation (sz), and the maximum number of scratch allocations (N). */ |
| 126267 | sqlite3GlobalConfig.pScratch = va_arg(ap, void*); |
| 126268 | sqlite3GlobalConfig.szScratch = va_arg(ap, int); |
| 126269 | sqlite3GlobalConfig.nScratch = va_arg(ap, int); |
| 126270 | break; |
| 126271 | } |
| 126272 | case SQLITE_CONFIG_PAGECACHE: { |
| 126273 | /* EVIDENCE-OF: R-31408-40510 There are three arguments to |
| 126274 | ** SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned memory, the size |
| 126275 | ** of each page buffer (sz), and the number of pages (N). */ |
| 126276 | sqlite3GlobalConfig.pPage = va_arg(ap, void*); |
| 126277 | sqlite3GlobalConfig.szPage = va_arg(ap, int); |
| 126278 | sqlite3GlobalConfig.nPage = va_arg(ap, int); |
| 126279 | break; |
| 126280 | } |
| 126281 | case SQLITE_CONFIG_PCACHE_HDRSZ: { |
| 126282 | /* EVIDENCE-OF: R-39100-27317 The SQLITE_CONFIG_PCACHE_HDRSZ option takes |
| 126283 | ** a single parameter which is a pointer to an integer and writes into |
| 126284 | ** that integer the number of extra bytes per page required for each page |
| 126285 | ** in SQLITE_CONFIG_PAGECACHE. */ |
| 126286 | *va_arg(ap, int*) = |
| 126287 | sqlite3HeaderSizeBtree() + |
| 126288 | sqlite3HeaderSizePcache() + |
| 126289 | sqlite3HeaderSizePcache1(); |
| 126290 | break; |
| 126291 | } |
| 126292 | |
| 126293 | case SQLITE_CONFIG_PCACHE: { |
| 126294 | /* no-op */ |
| 126295 | break; |
| 126296 | } |
| @@ -126299,37 +125362,25 @@ | |
| 126299 | rc = SQLITE_ERROR; |
| 126300 | break; |
| 126301 | } |
| 126302 | |
| 126303 | case SQLITE_CONFIG_PCACHE2: { |
| 126304 | /* EVIDENCE-OF: R-63325-48378 The SQLITE_CONFIG_PCACHE2 option takes a |
| 126305 | ** single argument which is a pointer to an sqlite3_pcache_methods2 |
| 126306 | ** object. This object specifies the interface to a custom page cache |
| 126307 | ** implementation. */ |
| 126308 | sqlite3GlobalConfig.pcache2 = *va_arg(ap, sqlite3_pcache_methods2*); |
| 126309 | break; |
| 126310 | } |
| 126311 | case SQLITE_CONFIG_GETPCACHE2: { |
| 126312 | /* EVIDENCE-OF: R-22035-46182 The SQLITE_CONFIG_GETPCACHE2 option takes a |
| 126313 | ** single argument which is a pointer to an sqlite3_pcache_methods2 |
| 126314 | ** object. SQLite copies of the current page cache implementation into |
| 126315 | ** that object. */ |
| 126316 | if( sqlite3GlobalConfig.pcache2.xInit==0 ){ |
| 126317 | sqlite3PCacheSetDefault(); |
| 126318 | } |
| 126319 | *va_arg(ap, sqlite3_pcache_methods2*) = sqlite3GlobalConfig.pcache2; |
| 126320 | break; |
| 126321 | } |
| 126322 | |
| 126323 | /* EVIDENCE-OF: R-06626-12911 The SQLITE_CONFIG_HEAP option is only |
| 126324 | ** available if SQLite is compiled with either SQLITE_ENABLE_MEMSYS3 or |
| 126325 | ** SQLITE_ENABLE_MEMSYS5 and returns SQLITE_ERROR if invoked otherwise. */ |
| 126326 | #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5) |
| 126327 | case SQLITE_CONFIG_HEAP: { |
| 126328 | /* EVIDENCE-OF: R-19854-42126 There are three arguments to |
| 126329 | ** SQLITE_CONFIG_HEAP: An 8-byte aligned pointer to the memory, the |
| 126330 | ** number of bytes in the memory buffer, and the minimum allocation size. */ |
| 126331 | sqlite3GlobalConfig.pHeap = va_arg(ap, void*); |
| 126332 | sqlite3GlobalConfig.nHeap = va_arg(ap, int); |
| 126333 | sqlite3GlobalConfig.mnReq = va_arg(ap, int); |
| 126334 | |
| 126335 | if( sqlite3GlobalConfig.mnReq<1 ){ |
| @@ -126338,23 +125389,21 @@ | |
| 126338 | /* cap min request size at 2^12 */ |
| 126339 | sqlite3GlobalConfig.mnReq = (1<<12); |
| 126340 | } |
| 126341 | |
| 126342 | if( sqlite3GlobalConfig.pHeap==0 ){ |
| 126343 | /* EVIDENCE-OF: R-49920-60189 If the first pointer (the memory pointer) |
| 126344 | ** is NULL, then SQLite reverts to using its default memory allocator |
| 126345 | ** (the system malloc() implementation), undoing any prior invocation of |
| 126346 | ** SQLITE_CONFIG_MALLOC. |
| 126347 | ** |
| 126348 | ** Setting sqlite3GlobalConfig.m to all zeros will cause malloc to |
| 126349 | ** revert to its default implementation when sqlite3_initialize() is run |
| 126350 | */ |
| 126351 | memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m)); |
| 126352 | }else{ |
| 126353 | /* EVIDENCE-OF: R-61006-08918 If the memory pointer is not NULL then the |
| 126354 | ** alternative memory allocator is engaged to handle all of SQLites |
| 126355 | ** memory allocation needs. */ |
| 126356 | #ifdef SQLITE_ENABLE_MEMSYS3 |
| 126357 | sqlite3GlobalConfig.m = *sqlite3MemGetMemsys3(); |
| 126358 | #endif |
| 126359 | #ifdef SQLITE_ENABLE_MEMSYS5 |
| 126360 | sqlite3GlobalConfig.m = *sqlite3MemGetMemsys5(); |
| @@ -126389,23 +125438,15 @@ | |
| 126389 | ** can be changed at start-time using the |
| 126390 | ** sqlite3_config(SQLITE_CONFIG_URI,1) or |
| 126391 | ** sqlite3_config(SQLITE_CONFIG_URI,0) configuration calls. |
| 126392 | */ |
| 126393 | case SQLITE_CONFIG_URI: { |
| 126394 | /* EVIDENCE-OF: R-25451-61125 The SQLITE_CONFIG_URI option takes a single |
| 126395 | ** argument of type int. If non-zero, then URI handling is globally |
| 126396 | ** enabled. If the parameter is zero, then URI handling is globally |
| 126397 | ** disabled. */ |
| 126398 | sqlite3GlobalConfig.bOpenUri = va_arg(ap, int); |
| 126399 | break; |
| 126400 | } |
| 126401 | |
| 126402 | case SQLITE_CONFIG_COVERING_INDEX_SCAN: { |
| 126403 | /* EVIDENCE-OF: R-36592-02772 The SQLITE_CONFIG_COVERING_INDEX_SCAN |
| 126404 | ** option takes a single integer argument which is interpreted as a |
| 126405 | ** boolean in order to enable or disable the use of covering indices for |
| 126406 | ** full table scans in the query optimizer. */ |
| 126407 | sqlite3GlobalConfig.bUseCis = va_arg(ap, int); |
| 126408 | break; |
| 126409 | } |
| 126410 | |
| 126411 | #ifdef SQLITE_ENABLE_SQLLOG |
| @@ -126416,37 +125457,24 @@ | |
| 126416 | break; |
| 126417 | } |
| 126418 | #endif |
| 126419 | |
| 126420 | case SQLITE_CONFIG_MMAP_SIZE: { |
| 126421 | /* EVIDENCE-OF: R-58063-38258 SQLITE_CONFIG_MMAP_SIZE takes two 64-bit |
| 126422 | ** integer (sqlite3_int64) values that are the default mmap size limit |
| 126423 | ** (the default setting for PRAGMA mmap_size) and the maximum allowed |
| 126424 | ** mmap size limit. */ |
| 126425 | sqlite3_int64 szMmap = va_arg(ap, sqlite3_int64); |
| 126426 | sqlite3_int64 mxMmap = va_arg(ap, sqlite3_int64); |
| 126427 | /* EVIDENCE-OF: R-53367-43190 If either argument to this option is |
| 126428 | ** negative, then that argument is changed to its compile-time default. |
| 126429 | ** |
| 126430 | ** EVIDENCE-OF: R-34993-45031 The maximum allowed mmap size will be |
| 126431 | ** silently truncated if necessary so that it does not exceed the |
| 126432 | ** compile-time maximum mmap size set by the SQLITE_MAX_MMAP_SIZE |
| 126433 | ** compile-time option. |
| 126434 | */ |
| 126435 | if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ) mxMmap = SQLITE_MAX_MMAP_SIZE; |
| 126436 | if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE; |
| 126437 | if( szMmap>mxMmap) szMmap = mxMmap; |
| 126438 | sqlite3GlobalConfig.mxMmap = mxMmap; |
| 126439 | sqlite3GlobalConfig.szMmap = szMmap; |
| 126440 | break; |
| 126441 | } |
| 126442 | |
| 126443 | #if SQLITE_OS_WIN && defined(SQLITE_WIN32_MALLOC) /* IMP: R-04780-55815 */ |
| 126444 | case SQLITE_CONFIG_WIN32_HEAPSIZE: { |
| 126445 | /* EVIDENCE-OF: R-34926-03360 SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit |
| 126446 | ** unsigned integer value that specifies the maximum size of the created |
| 126447 | ** heap. */ |
| 126448 | sqlite3GlobalConfig.nHeap = va_arg(ap, int); |
| 126449 | break; |
| 126450 | } |
| 126451 | #endif |
| 126452 | |
| @@ -126526,29 +125554,19 @@ | |
| 126526 | |
| 126527 | /* |
| 126528 | ** Return the mutex associated with a database connection. |
| 126529 | */ |
| 126530 | SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){ |
| 126531 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 126532 | if( !sqlite3SafetyCheckOk(db) ){ |
| 126533 | (void)SQLITE_MISUSE_BKPT; |
| 126534 | return 0; |
| 126535 | } |
| 126536 | #endif |
| 126537 | return db->mutex; |
| 126538 | } |
| 126539 | |
| 126540 | /* |
| 126541 | ** Free up as much memory as we can from the given database |
| 126542 | ** connection. |
| 126543 | */ |
| 126544 | SQLITE_API int sqlite3_db_release_memory(sqlite3 *db){ |
| 126545 | int i; |
| 126546 | |
| 126547 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 126548 | if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 126549 | #endif |
| 126550 | sqlite3_mutex_enter(db->mutex); |
| 126551 | sqlite3BtreeEnterAll(db); |
| 126552 | for(i=0; i<db->nDb; i++){ |
| 126553 | Btree *pBt = db->aDb[i].pBt; |
| 126554 | if( pBt ){ |
| @@ -126675,42 +125693,24 @@ | |
| 126675 | |
| 126676 | /* |
| 126677 | ** Return the ROWID of the most recent insert |
| 126678 | */ |
| 126679 | SQLITE_API sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){ |
| 126680 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 126681 | if( !sqlite3SafetyCheckOk(db) ){ |
| 126682 | (void)SQLITE_MISUSE_BKPT; |
| 126683 | return 0; |
| 126684 | } |
| 126685 | #endif |
| 126686 | return db->lastRowid; |
| 126687 | } |
| 126688 | |
| 126689 | /* |
| 126690 | ** Return the number of changes in the most recent call to sqlite3_exec(). |
| 126691 | */ |
| 126692 | SQLITE_API int sqlite3_changes(sqlite3 *db){ |
| 126693 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 126694 | if( !sqlite3SafetyCheckOk(db) ){ |
| 126695 | (void)SQLITE_MISUSE_BKPT; |
| 126696 | return 0; |
| 126697 | } |
| 126698 | #endif |
| 126699 | return db->nChange; |
| 126700 | } |
| 126701 | |
| 126702 | /* |
| 126703 | ** Return the number of changes since the database handle was opened. |
| 126704 | */ |
| 126705 | SQLITE_API int sqlite3_total_changes(sqlite3 *db){ |
| 126706 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 126707 | if( !sqlite3SafetyCheckOk(db) ){ |
| 126708 | (void)SQLITE_MISUSE_BKPT; |
| 126709 | return 0; |
| 126710 | } |
| 126711 | #endif |
| 126712 | return db->nTotalChange; |
| 126713 | } |
| 126714 | |
| 126715 | /* |
| 126716 | ** Close all open savepoints. This function only manipulates fields of the |
| @@ -127255,13 +126255,10 @@ | |
| 127255 | SQLITE_API int sqlite3_busy_handler( |
| 127256 | sqlite3 *db, |
| 127257 | int (*xBusy)(void*,int), |
| 127258 | void *pArg |
| 127259 | ){ |
| 127260 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 127261 | if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE; |
| 127262 | #endif |
| 127263 | sqlite3_mutex_enter(db->mutex); |
| 127264 | db->busyHandler.xFunc = xBusy; |
| 127265 | db->busyHandler.pArg = pArg; |
| 127266 | db->busyHandler.nBusy = 0; |
| 127267 | db->busyTimeout = 0; |
| @@ -127279,16 +126276,10 @@ | |
| 127279 | sqlite3 *db, |
| 127280 | int nOps, |
| 127281 | int (*xProgress)(void*), |
| 127282 | void *pArg |
| 127283 | ){ |
| 127284 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 127285 | if( !sqlite3SafetyCheckOk(db) ){ |
| 127286 | (void)SQLITE_MISUSE_BKPT; |
| 127287 | return; |
| 127288 | } |
| 127289 | #endif |
| 127290 | sqlite3_mutex_enter(db->mutex); |
| 127291 | if( nOps>0 ){ |
| 127292 | db->xProgress = xProgress; |
| 127293 | db->nProgressOps = (unsigned)nOps; |
| 127294 | db->pProgressArg = pArg; |
| @@ -127305,13 +126296,10 @@ | |
| 127305 | /* |
| 127306 | ** This routine installs a default busy handler that waits for the |
| 127307 | ** specified number of milliseconds before returning 0. |
| 127308 | */ |
| 127309 | SQLITE_API int sqlite3_busy_timeout(sqlite3 *db, int ms){ |
| 127310 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 127311 | if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 127312 | #endif |
| 127313 | if( ms>0 ){ |
| 127314 | sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db); |
| 127315 | db->busyTimeout = ms; |
| 127316 | }else{ |
| 127317 | sqlite3_busy_handler(db, 0, 0); |
| @@ -127321,16 +126309,10 @@ | |
| 127321 | |
| 127322 | /* |
| 127323 | ** Cause any pending operation to stop at its earliest opportunity. |
| 127324 | */ |
| 127325 | SQLITE_API void sqlite3_interrupt(sqlite3 *db){ |
| 127326 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 127327 | if( !sqlite3SafetyCheckOk(db) ){ |
| 127328 | (void)SQLITE_MISUSE_BKPT; |
| 127329 | return; |
| 127330 | } |
| 127331 | #endif |
| 127332 | db->u1.isInterrupted = 1; |
| 127333 | } |
| 127334 | |
| 127335 | |
| 127336 | /* |
| @@ -127464,16 +126446,10 @@ | |
| 127464 | void (*xFinal)(sqlite3_context*), |
| 127465 | void (*xDestroy)(void *) |
| 127466 | ){ |
| 127467 | int rc = SQLITE_ERROR; |
| 127468 | FuncDestructor *pArg = 0; |
| 127469 | |
| 127470 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 127471 | if( !sqlite3SafetyCheckOk(db) ){ |
| 127472 | return SQLITE_MISUSE_BKPT; |
| 127473 | } |
| 127474 | #endif |
| 127475 | sqlite3_mutex_enter(db->mutex); |
| 127476 | if( xDestroy ){ |
| 127477 | pArg = (FuncDestructor *)sqlite3DbMallocZero(db, sizeof(FuncDestructor)); |
| 127478 | if( !pArg ){ |
| 127479 | xDestroy(p); |
| @@ -127506,14 +126482,10 @@ | |
| 127506 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
| 127507 | void (*xFinal)(sqlite3_context*) |
| 127508 | ){ |
| 127509 | int rc; |
| 127510 | char *zFunc8; |
| 127511 | |
| 127512 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 127513 | if( !sqlite3SafetyCheckOk(db) || zFunctionName==0 ) return SQLITE_MISUSE_BKPT; |
| 127514 | #endif |
| 127515 | sqlite3_mutex_enter(db->mutex); |
| 127516 | assert( !db->mallocFailed ); |
| 127517 | zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE); |
| 127518 | rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal,0); |
| 127519 | sqlite3DbFree(db, zFunc8); |
| @@ -127541,16 +126513,10 @@ | |
| 127541 | const char *zName, |
| 127542 | int nArg |
| 127543 | ){ |
| 127544 | int nName = sqlite3Strlen30(zName); |
| 127545 | int rc = SQLITE_OK; |
| 127546 | |
| 127547 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 127548 | if( !sqlite3SafetyCheckOk(db) || zName==0 || nArg<-2 ){ |
| 127549 | return SQLITE_MISUSE_BKPT; |
| 127550 | } |
| 127551 | #endif |
| 127552 | sqlite3_mutex_enter(db->mutex); |
| 127553 | if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){ |
| 127554 | rc = sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8, |
| 127555 | 0, sqlite3InvalidFunction, 0, 0, 0); |
| 127556 | } |
| @@ -127568,17 +126534,10 @@ | |
| 127568 | ** trace is a pointer to a function that is invoked at the start of each |
| 127569 | ** SQL statement. |
| 127570 | */ |
| 127571 | SQLITE_API void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){ |
| 127572 | void *pOld; |
| 127573 | |
| 127574 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 127575 | if( !sqlite3SafetyCheckOk(db) ){ |
| 127576 | (void)SQLITE_MISUSE_BKPT; |
| 127577 | return 0; |
| 127578 | } |
| 127579 | #endif |
| 127580 | sqlite3_mutex_enter(db->mutex); |
| 127581 | pOld = db->pTraceArg; |
| 127582 | db->xTrace = xTrace; |
| 127583 | db->pTraceArg = pArg; |
| 127584 | sqlite3_mutex_leave(db->mutex); |
| @@ -127596,17 +126555,10 @@ | |
| 127596 | sqlite3 *db, |
| 127597 | void (*xProfile)(void*,const char*,sqlite_uint64), |
| 127598 | void *pArg |
| 127599 | ){ |
| 127600 | void *pOld; |
| 127601 | |
| 127602 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 127603 | if( !sqlite3SafetyCheckOk(db) ){ |
| 127604 | (void)SQLITE_MISUSE_BKPT; |
| 127605 | return 0; |
| 127606 | } |
| 127607 | #endif |
| 127608 | sqlite3_mutex_enter(db->mutex); |
| 127609 | pOld = db->pProfileArg; |
| 127610 | db->xProfile = xProfile; |
| 127611 | db->pProfileArg = pArg; |
| 127612 | sqlite3_mutex_leave(db->mutex); |
| @@ -127623,17 +126575,10 @@ | |
| 127623 | sqlite3 *db, /* Attach the hook to this database */ |
| 127624 | int (*xCallback)(void*), /* Function to invoke on each commit */ |
| 127625 | void *pArg /* Argument to the function */ |
| 127626 | ){ |
| 127627 | void *pOld; |
| 127628 | |
| 127629 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 127630 | if( !sqlite3SafetyCheckOk(db) ){ |
| 127631 | (void)SQLITE_MISUSE_BKPT; |
| 127632 | return 0; |
| 127633 | } |
| 127634 | #endif |
| 127635 | sqlite3_mutex_enter(db->mutex); |
| 127636 | pOld = db->pCommitArg; |
| 127637 | db->xCommitCallback = xCallback; |
| 127638 | db->pCommitArg = pArg; |
| 127639 | sqlite3_mutex_leave(db->mutex); |
| @@ -127648,17 +126593,10 @@ | |
| 127648 | sqlite3 *db, /* Attach the hook to this database */ |
| 127649 | void (*xCallback)(void*,int,char const *,char const *,sqlite_int64), |
| 127650 | void *pArg /* Argument to the function */ |
| 127651 | ){ |
| 127652 | void *pRet; |
| 127653 | |
| 127654 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 127655 | if( !sqlite3SafetyCheckOk(db) ){ |
| 127656 | (void)SQLITE_MISUSE_BKPT; |
| 127657 | return 0; |
| 127658 | } |
| 127659 | #endif |
| 127660 | sqlite3_mutex_enter(db->mutex); |
| 127661 | pRet = db->pUpdateArg; |
| 127662 | db->xUpdateCallback = xCallback; |
| 127663 | db->pUpdateArg = pArg; |
| 127664 | sqlite3_mutex_leave(db->mutex); |
| @@ -127673,17 +126611,10 @@ | |
| 127673 | sqlite3 *db, /* Attach the hook to this database */ |
| 127674 | void (*xCallback)(void*), /* Callback function */ |
| 127675 | void *pArg /* Argument to the function */ |
| 127676 | ){ |
| 127677 | void *pRet; |
| 127678 | |
| 127679 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 127680 | if( !sqlite3SafetyCheckOk(db) ){ |
| 127681 | (void)SQLITE_MISUSE_BKPT; |
| 127682 | return 0; |
| 127683 | } |
| 127684 | #endif |
| 127685 | sqlite3_mutex_enter(db->mutex); |
| 127686 | pRet = db->pRollbackArg; |
| 127687 | db->xRollbackCallback = xCallback; |
| 127688 | db->pRollbackArg = pArg; |
| 127689 | sqlite3_mutex_leave(db->mutex); |
| @@ -127726,13 +126657,10 @@ | |
| 127726 | SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){ |
| 127727 | #ifdef SQLITE_OMIT_WAL |
| 127728 | UNUSED_PARAMETER(db); |
| 127729 | UNUSED_PARAMETER(nFrame); |
| 127730 | #else |
| 127731 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 127732 | if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 127733 | #endif |
| 127734 | if( nFrame>0 ){ |
| 127735 | sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame)); |
| 127736 | }else{ |
| 127737 | sqlite3_wal_hook(db, 0, 0); |
| 127738 | } |
| @@ -127749,16 +126677,10 @@ | |
| 127749 | int(*xCallback)(void *, sqlite3*, const char*, int), |
| 127750 | void *pArg /* First argument passed to xCallback() */ |
| 127751 | ){ |
| 127752 | #ifndef SQLITE_OMIT_WAL |
| 127753 | void *pRet; |
| 127754 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 127755 | if( !sqlite3SafetyCheckOk(db) ){ |
| 127756 | (void)SQLITE_MISUSE_BKPT; |
| 127757 | return 0; |
| 127758 | } |
| 127759 | #endif |
| 127760 | sqlite3_mutex_enter(db->mutex); |
| 127761 | pRet = db->pWalArg; |
| 127762 | db->xWalCallback = xCallback; |
| 127763 | db->pWalArg = pArg; |
| 127764 | sqlite3_mutex_leave(db->mutex); |
| @@ -127782,14 +126704,10 @@ | |
| 127782 | return SQLITE_OK; |
| 127783 | #else |
| 127784 | int rc; /* Return code */ |
| 127785 | int iDb = SQLITE_MAX_ATTACHED; /* sqlite3.aDb[] index of db to checkpoint */ |
| 127786 | |
| 127787 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 127788 | if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 127789 | #endif |
| 127790 | |
| 127791 | /* Initialize the output variables to -1 in case an error occurs. */ |
| 127792 | if( pnLog ) *pnLog = -1; |
| 127793 | if( pnCkpt ) *pnCkpt = -1; |
| 127794 | |
| 127795 | assert( SQLITE_CHECKPOINT_FULL>SQLITE_CHECKPOINT_PASSIVE ); |
| @@ -128182,16 +127100,10 @@ | |
| 128182 | ** from forming. |
| 128183 | */ |
| 128184 | SQLITE_API int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){ |
| 128185 | int oldLimit; |
| 128186 | |
| 128187 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 128188 | if( !sqlite3SafetyCheckOk(db) ){ |
| 128189 | (void)SQLITE_MISUSE_BKPT; |
| 128190 | return -1; |
| 128191 | } |
| 128192 | #endif |
| 128193 | |
| 128194 | /* EVIDENCE-OF: R-30189-54097 For each limit category SQLITE_LIMIT_NAME |
| 128195 | ** there is a hard upper bound set at compile-time by a C preprocessor |
| 128196 | ** macro called SQLITE_MAX_NAME. (The "_LIMIT_" in the name is changed to |
| 128197 | ** "_MAX_".) |
| @@ -128264,12 +127176,11 @@ | |
| 128264 | char c; |
| 128265 | int nUri = sqlite3Strlen30(zUri); |
| 128266 | |
| 128267 | assert( *pzErrMsg==0 ); |
| 128268 | |
| 128269 | if( ((flags & SQLITE_OPEN_URI) /* IMP: R-48725-32206 */ |
| 128270 | || sqlite3GlobalConfig.bOpenUri) /* IMP: R-51689-46548 */ |
| 128271 | && nUri>=5 && memcmp(zUri, "file:", 5)==0 /* IMP: R-57884-37496 */ |
| 128272 | ){ |
| 128273 | char *zOpt; |
| 128274 | int eState; /* Parser state when parsing URI */ |
| 128275 | int iIn; /* Input character index */ |
| @@ -128474,13 +127385,10 @@ | |
| 128474 | int rc; /* Return code */ |
| 128475 | int isThreadsafe; /* True for threadsafe connections */ |
| 128476 | char *zOpen = 0; /* Filename argument to pass to BtreeOpen() */ |
| 128477 | char *zErrMsg = 0; /* Error message from sqlite3ParseUri() */ |
| 128478 | |
| 128479 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 128480 | if( ppDb==0 ) return SQLITE_MISUSE_BKPT; |
| 128481 | #endif |
| 128482 | *ppDb = 0; |
| 128483 | #ifndef SQLITE_OMIT_AUTOINIT |
| 128484 | rc = sqlite3_initialize(); |
| 128485 | if( rc ) return rc; |
| 128486 | #endif |
| @@ -128766,19 +127674,17 @@ | |
| 128766 | ){ |
| 128767 | char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */ |
| 128768 | sqlite3_value *pVal; |
| 128769 | int rc; |
| 128770 | |
| 128771 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 128772 | if( ppDb==0 ) return SQLITE_MISUSE_BKPT; |
| 128773 | #endif |
| 128774 | *ppDb = 0; |
| 128775 | #ifndef SQLITE_OMIT_AUTOINIT |
| 128776 | rc = sqlite3_initialize(); |
| 128777 | if( rc ) return rc; |
| 128778 | #endif |
| 128779 | if( zFilename==0 ) zFilename = "\000\000"; |
| 128780 | pVal = sqlite3ValueNew(0); |
| 128781 | sqlite3ValueSetStr(pVal, -1, zFilename, SQLITE_UTF16NATIVE, SQLITE_STATIC); |
| 128782 | zFilename8 = sqlite3ValueText(pVal, SQLITE_UTF8); |
| 128783 | if( zFilename8 ){ |
| 128784 | rc = openDatabase(zFilename8, ppDb, |
| @@ -128804,11 +127710,17 @@ | |
| 128804 | const char *zName, |
| 128805 | int enc, |
| 128806 | void* pCtx, |
| 128807 | int(*xCompare)(void*,int,const void*,int,const void*) |
| 128808 | ){ |
| 128809 | return sqlite3_create_collation_v2(db, zName, enc, pCtx, xCompare, 0); |
| 128810 | } |
| 128811 | |
| 128812 | /* |
| 128813 | ** Register a new collation sequence with the database handle db. |
| 128814 | */ |
| @@ -128819,14 +127731,10 @@ | |
| 128819 | void* pCtx, |
| 128820 | int(*xCompare)(void*,int,const void*,int,const void*), |
| 128821 | void(*xDel)(void*) |
| 128822 | ){ |
| 128823 | int rc; |
| 128824 | |
| 128825 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 128826 | if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT; |
| 128827 | #endif |
| 128828 | sqlite3_mutex_enter(db->mutex); |
| 128829 | assert( !db->mallocFailed ); |
| 128830 | rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, xDel); |
| 128831 | rc = sqlite3ApiExit(db, rc); |
| 128832 | sqlite3_mutex_leave(db->mutex); |
| @@ -128844,14 +127752,10 @@ | |
| 128844 | void* pCtx, |
| 128845 | int(*xCompare)(void*,int,const void*,int,const void*) |
| 128846 | ){ |
| 128847 | int rc = SQLITE_OK; |
| 128848 | char *zName8; |
| 128849 | |
| 128850 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 128851 | if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT; |
| 128852 | #endif |
| 128853 | sqlite3_mutex_enter(db->mutex); |
| 128854 | assert( !db->mallocFailed ); |
| 128855 | zName8 = sqlite3Utf16to8(db, zName, -1, SQLITE_UTF16NATIVE); |
| 128856 | if( zName8 ){ |
| 128857 | rc = createCollation(db, zName8, (u8)enc, pCtx, xCompare, 0); |
| @@ -128870,13 +127774,10 @@ | |
| 128870 | SQLITE_API int sqlite3_collation_needed( |
| 128871 | sqlite3 *db, |
| 128872 | void *pCollNeededArg, |
| 128873 | void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*) |
| 128874 | ){ |
| 128875 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 128876 | if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 128877 | #endif |
| 128878 | sqlite3_mutex_enter(db->mutex); |
| 128879 | db->xCollNeeded = xCollNeeded; |
| 128880 | db->xCollNeeded16 = 0; |
| 128881 | db->pCollNeededArg = pCollNeededArg; |
| 128882 | sqlite3_mutex_leave(db->mutex); |
| @@ -128891,13 +127792,10 @@ | |
| 128891 | SQLITE_API int sqlite3_collation_needed16( |
| 128892 | sqlite3 *db, |
| 128893 | void *pCollNeededArg, |
| 128894 | void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*) |
| 128895 | ){ |
| 128896 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 128897 | if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 128898 | #endif |
| 128899 | sqlite3_mutex_enter(db->mutex); |
| 128900 | db->xCollNeeded = 0; |
| 128901 | db->xCollNeeded16 = xCollNeeded16; |
| 128902 | db->pCollNeededArg = pCollNeededArg; |
| 128903 | sqlite3_mutex_leave(db->mutex); |
| @@ -128920,16 +127818,10 @@ | |
| 128920 | ** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on |
| 128921 | ** by default. Autocommit is disabled by a BEGIN statement and reenabled |
| 128922 | ** by the next COMMIT or ROLLBACK. |
| 128923 | */ |
| 128924 | SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){ |
| 128925 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 128926 | if( !sqlite3SafetyCheckOk(db) ){ |
| 128927 | (void)SQLITE_MISUSE_BKPT; |
| 128928 | return 0; |
| 128929 | } |
| 128930 | #endif |
| 128931 | return db->autoCommit; |
| 128932 | } |
| 128933 | |
| 128934 | /* |
| 128935 | ** The following routines are substitutes for constants SQLITE_CORRUPT, |
| @@ -129108,13 +128000,10 @@ | |
| 129108 | |
| 129109 | /* |
| 129110 | ** Enable or disable the extended result codes. |
| 129111 | */ |
| 129112 | SQLITE_API int sqlite3_extended_result_codes(sqlite3 *db, int onoff){ |
| 129113 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 129114 | if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 129115 | #endif |
| 129116 | sqlite3_mutex_enter(db->mutex); |
| 129117 | db->errMask = onoff ? 0xffffffff : 0xff; |
| 129118 | sqlite3_mutex_leave(db->mutex); |
| 129119 | return SQLITE_OK; |
| 129120 | } |
| @@ -129124,13 +128013,10 @@ | |
| 129124 | */ |
| 129125 | SQLITE_API int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){ |
| 129126 | int rc = SQLITE_ERROR; |
| 129127 | Btree *pBtree; |
| 129128 | |
| 129129 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 129130 | if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 129131 | #endif |
| 129132 | sqlite3_mutex_enter(db->mutex); |
| 129133 | pBtree = sqlite3DbNameToBtree(db, zDbName); |
| 129134 | if( pBtree ){ |
| 129135 | Pager *pPager; |
| 129136 | sqlite3_file *fd; |
| @@ -129469,11 +128355,11 @@ | |
| 129469 | ** query parameter we seek. This routine returns the value of the zParam |
| 129470 | ** parameter if it exists. If the parameter does not exist, this routine |
| 129471 | ** returns a NULL pointer. |
| 129472 | */ |
| 129473 | SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){ |
| 129474 | if( zFilename==0 || zParam==0 ) return 0; |
| 129475 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 129476 | while( zFilename[0] ){ |
| 129477 | int x = strcmp(zFilename, zParam); |
| 129478 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 129479 | if( x==0 ) return zFilename; |
| @@ -129525,31 +128411,19 @@ | |
| 129525 | /* |
| 129526 | ** Return the filename of the database associated with a database |
| 129527 | ** connection. |
| 129528 | */ |
| 129529 | SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){ |
| 129530 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 129531 | if( !sqlite3SafetyCheckOk(db) ){ |
| 129532 | (void)SQLITE_MISUSE_BKPT; |
| 129533 | return 0; |
| 129534 | } |
| 129535 | #endif |
| 129536 | Btree *pBt = sqlite3DbNameToBtree(db, zDbName); |
| 129537 | return pBt ? sqlite3BtreeGetFilename(pBt) : 0; |
| 129538 | } |
| 129539 | |
| 129540 | /* |
| 129541 | ** Return 1 if database is read-only or 0 if read/write. Return -1 if |
| 129542 | ** no such database exists. |
| 129543 | */ |
| 129544 | SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){ |
| 129545 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 129546 | if( !sqlite3SafetyCheckOk(db) ){ |
| 129547 | (void)SQLITE_MISUSE_BKPT; |
| 129548 | return -1; |
| 129549 | } |
| 129550 | #endif |
| 129551 | Btree *pBt = sqlite3DbNameToBtree(db, zDbName); |
| 129552 | return pBt ? sqlite3BtreeIsReadonly(pBt) : -1; |
| 129553 | } |
| 129554 | |
| 129555 | /************** End of main.c ************************************************/ |
| 129556 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1,8 +1,8 @@ | |
| 1 | /****************************************************************************** |
| 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | ** version 3.8.7.2. By combining all the individual C code files into this |
| 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | ** translation unit. |
| @@ -179,11 +179,11 @@ | |
| 179 | |
| 180 | |
| 181 | /* |
| 182 | ** These no-op macros are used in front of interfaces to mark those |
| 183 | ** interfaces as either deprecated or experimental. New applications |
| 184 | ** should not use deprecated interfaces - they are support for backwards |
| 185 | ** compatibility only. Application writers should be aware that |
| 186 | ** experimental interfaces are subject to change in point releases. |
| 187 | ** |
| 188 | ** These macros used to resolve to various kinds of compiler magic that |
| 189 | ** would generate warning messages when they were used. But that |
| @@ -229,13 +229,13 @@ | |
| 229 | ** |
| 230 | ** See also: [sqlite3_libversion()], |
| 231 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 232 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 233 | */ |
| 234 | #define SQLITE_VERSION "3.8.7.2" |
| 235 | #define SQLITE_VERSION_NUMBER 3008007 |
| 236 | #define SQLITE_SOURCE_ID "2014-11-18 20:57:56 2ab564bf9655b7c7b97ab85cafc8a48329b27f93" |
| 237 | |
| 238 | /* |
| 239 | ** CAPI3REF: Run-Time Library Version Numbers |
| 240 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 241 | ** |
| @@ -1626,31 +1626,29 @@ | |
| 1626 | ** it is not possible to set the Serialized [threading mode] and |
| 1627 | ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
| 1628 | ** SQLITE_CONFIG_SERIALIZED configuration option.</dd> |
| 1629 | ** |
| 1630 | ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt> |
| 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 |
| 1633 | ** alternative low-level memory allocation routines to be used in place of |
| 1634 | ** the memory allocation routines built into SQLite.)^ ^SQLite makes |
| 1635 | ** its own private copy of the content of the [sqlite3_mem_methods] structure |
| 1636 | ** before the [sqlite3_config()] call returns.</dd> |
| 1637 | ** |
| 1638 | ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt> |
| 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] |
| 1641 | ** structure is filled with the currently defined memory allocation routines.)^ |
| 1642 | ** This option can be used to overload the default memory allocation |
| 1643 | ** routines with a wrapper that simulations memory allocation failure or |
| 1644 | ** tracks memory usage, for example. </dd> |
| 1645 | ** |
| 1646 | ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> |
| 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 |
| 1650 | ** following SQLite interfaces become non-operational: |
| 1651 | ** <ul> |
| 1652 | ** <li> [sqlite3_memory_used()] |
| 1653 | ** <li> [sqlite3_memory_highwater()] |
| 1654 | ** <li> [sqlite3_soft_heap_limit64()] |
| @@ -1660,90 +1658,78 @@ | |
| 1658 | ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory |
| 1659 | ** allocation statistics are disabled by default. |
| 1660 | ** </dd> |
| 1661 | ** |
| 1662 | ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt> |
| 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 |
| 1665 | ** aligned memory buffer from which the scratch allocations will be |
| 1666 | ** drawn, the size of each scratch allocation (sz), |
| 1667 | ** and the maximum number of scratch allocations (N). The sz |
| 1668 | ** argument must be a multiple of 16. |
| 1669 | ** The first argument must be a pointer to an 8-byte aligned buffer |
| 1670 | ** of at least sz*N bytes of memory. |
| 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 |
| 1675 | ** scratch memory beyond what is provided by this configuration option, then |
| 1676 | ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd> |
| 1677 | ** |
| 1678 | ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt> |
| 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. |
| 1681 | ** This configuration should not be used if an application-define page |
| 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 |
| 1684 | ** memory, the size of each page buffer (sz), and the number of pages (N). |
| 1685 | ** The sz argument should be the size of the largest database page |
| 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. |
| 1691 | ** ^SQLite will use the memory provided by the first argument to satisfy its |
| 1692 | ** memory needs for the first N pages that it adds to cache. ^If additional |
| 1693 | ** page cache memory is needed beyond what is provided by this option, then |
| 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> |
| 1698 | ** |
| 1699 | ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> |
| 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, |
| 1704 | ** the number of bytes in the memory buffer, and the minimum allocation size. |
| 1705 | ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts |
| 1706 | ** to using its default memory allocator (the system malloc() implementation), |
| 1707 | ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the |
| 1708 | ** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or |
| 1709 | ** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory |
| 1710 | ** allocator is engaged to handle all of SQLites memory allocation needs. |
| 1711 | ** The first pointer (the memory pointer) must be aligned to an 8-byte |
| 1712 | ** boundary or subsequent behavior of SQLite will be undefined. |
| 1713 | ** The minimum allocation size is capped at 2**12. Reasonable values |
| 1714 | ** for the minimum allocation size are 2**5 through 2**8.</dd> |
| 1715 | ** |
| 1716 | ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt> |
| 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 |
| 1720 | ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the |
| 1721 | ** content of the [sqlite3_mutex_methods] structure before the call to |
| 1722 | ** [sqlite3_config()] returns. ^If SQLite is compiled with |
| 1723 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1724 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1725 | ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will |
| 1726 | ** return [SQLITE_ERROR].</dd> |
| 1727 | ** |
| 1728 | ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt> |
| 1729 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1730 | ** instance of the [sqlite3_mutex_methods] structure. The |
| 1731 | ** [sqlite3_mutex_methods] |
| 1732 | ** structure is filled with the currently defined mutex routines.)^ |
| 1733 | ** This option can be used to overload the default mutex allocation |
| 1734 | ** routines with a wrapper used to track mutex usage for performance |
| 1735 | ** profiling or testing, for example. ^If SQLite is compiled with |
| @@ -1751,28 +1737,28 @@ | |
| 1737 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1738 | ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will |
| 1739 | ** return [SQLITE_ERROR].</dd> |
| 1740 | ** |
| 1741 | ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt> |
| 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 |
| 1745 | ** size of each lookaside buffer slot and the second is the number of |
| 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 |
| 1749 | ** configuration on individual connections.)^ </dd> |
| 1750 | ** |
| 1751 | ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt> |
| 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> |
| 1756 | ** |
| 1757 | ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt> |
| 1758 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1759 | ** [sqlite3_pcache_methods2] object. SQLite copies of the current |
| 1760 | ** page cache implementation into that object.)^ </dd> |
| 1761 | ** |
| 1762 | ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> |
| 1763 | ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite |
| 1764 | ** global [error log]. |
| @@ -1792,27 +1778,26 @@ | |
| 1778 | ** supplied by the application must not invoke any SQLite interface. |
| 1779 | ** In a multi-threaded application, the application-defined logger |
| 1780 | ** function must be threadsafe. </dd> |
| 1781 | ** |
| 1782 | ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI |
| 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 |
| 1787 | ** specified as part of [ATTACH] commands are interpreted as URIs, regardless |
| 1788 | ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database |
| 1789 | ** connection is opened. ^If it is globally disabled, filenames are |
| 1790 | ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the |
| 1791 | ** database connection is opened. ^(By default, URI handling is globally |
| 1792 | ** disabled. The default value may be changed by compiling with the |
| 1793 | ** [SQLITE_USE_URI] symbol defined.)^ |
| 1794 | ** |
| 1795 | ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN |
| 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 |
| 1799 | ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on" |
| 1800 | ** if that compile-time option is omitted. |
| 1801 | ** The ability to disable the use of covering indices for full table scans |
| 1802 | ** is because some incorrectly coded legacy applications might malfunction |
| 1803 | ** when the optimization is enabled. Providing the ability to |
| @@ -1848,32 +1833,23 @@ | |
| 1833 | ** that are the default mmap size limit (the default setting for |
| 1834 | ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit. |
| 1835 | ** ^The default setting can be overridden by each database connection using |
| 1836 | ** either the [PRAGMA mmap_size] command, or by using the |
| 1837 | ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size |
| 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 |
| 1840 | ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^ |
| 1841 | ** ^If either argument to this option is negative, then that argument is |
| 1842 | ** changed to its compile-time default. |
| 1843 | ** |
| 1844 | ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]] |
| 1845 | ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE |
| 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 |
| 1849 | ** that specifies the maximum size of the created heap. |
| 1850 | ** </dl> |
| 1851 | */ |
| 1852 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1853 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 1854 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| 1855 | #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ |
| @@ -1894,11 +1870,10 @@ | |
| 1870 | #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */ |
| 1871 | #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */ |
| 1872 | #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */ |
| 1873 | #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */ |
| 1874 | #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */ |
| 1875 | |
| 1876 | /* |
| 1877 | ** CAPI3REF: Database Connection Configuration Options |
| 1878 | ** |
| 1879 | ** These constants are the available integer configuration options that |
| @@ -2022,49 +1997,51 @@ | |
| 1997 | SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); |
| 1998 | |
| 1999 | /* |
| 2000 | ** CAPI3REF: Count The Number Of Rows Modified |
| 2001 | ** |
| 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.)^ |
| 2043 | ** |
| 2044 | ** See also the [sqlite3_total_changes()] interface, the |
| 2045 | ** [count_changes pragma], and the [changes() SQL function]. |
| 2046 | ** |
| 2047 | ** If a separate thread makes changes on the same database connection |
| @@ -2074,21 +2051,24 @@ | |
| 2051 | SQLITE_API int sqlite3_changes(sqlite3*); |
| 2052 | |
| 2053 | /* |
| 2054 | ** CAPI3REF: Total Number Of Rows Modified |
| 2055 | ** |
| 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 | ** |
| 2070 | ** See also the [sqlite3_changes()] interface, the |
| 2071 | ** [count_changes pragma], and the [total_changes() SQL function]. |
| 2072 | ** |
| 2073 | ** If a separate thread makes changes on the same database connection |
| 2074 | ** while [sqlite3_total_changes()] is running then the value |
| @@ -2562,18 +2542,17 @@ | |
| 2542 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2543 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2544 | ** applications to access the same PRNG for other purposes. |
| 2545 | ** |
| 2546 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2547 | ** ^If N is less than one, then P can be a NULL pointer. |
| 2548 | ** |
| 2549 | ** ^If this routine has not been previously called or if the previous |
| 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 |
| 2554 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2555 | ** method. |
| 2556 | */ |
| 2557 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2558 | |
| @@ -5784,46 +5763,30 @@ | |
| 5763 | ** |
| 5764 | ** <pre> |
| 5765 | ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow; |
| 5766 | ** </pre>)^ |
| 5767 | ** |
| 5768 | ** ^If the flags parameter is non-zero, then the BLOB is opened for read |
| 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. |
| 5788 | ** |
| 5789 | ** ^(If the row that a BLOB handle points to is modified by an |
| 5790 | ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects |
| 5791 | ** then the BLOB handle is marked as "expired". |
| 5792 | ** This is true if any column of the row is changed, even a column |
| @@ -5837,13 +5800,17 @@ | |
| 5800 | ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of |
| 5801 | ** the opened blob. ^The size of a blob may not be changed by this |
| 5802 | ** interface. Use the [UPDATE] SQL command to change the size of a |
| 5803 | ** blob. |
| 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 | ** |
| 5808 | ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces |
| 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. |
| 5812 | ** |
| 5813 | ** To avoid a resource leak, every open [BLOB handle] should eventually |
| 5814 | ** be released by a call to [sqlite3_blob_close()]. |
| 5815 | */ |
| 5816 | SQLITE_API int sqlite3_blob_open( |
| @@ -5881,26 +5848,28 @@ | |
| 5848 | SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); |
| 5849 | |
| 5850 | /* |
| 5851 | ** CAPI3REF: Close A BLOB Handle |
| 5852 | ** |
| 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. |
| 5871 | */ |
| 5872 | SQLITE_API int sqlite3_blob_close(sqlite3_blob *); |
| 5873 | |
| 5874 | /* |
| 5875 | ** CAPI3REF: Return The Size Of An Open BLOB |
| @@ -5946,39 +5915,36 @@ | |
| 5915 | SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); |
| 5916 | |
| 5917 | /* |
| 5918 | ** CAPI3REF: Write Data Into A BLOB Incrementally |
| 5919 | ** |
| 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. |
| 5923 | ** |
| 5924 | ** ^If the [BLOB handle] passed as the first argument was not opened for |
| 5925 | ** writing (the flags parameter to [sqlite3_blob_open()] was zero), |
| 5926 | ** this function returns [SQLITE_READONLY]. |
| 5927 | ** |
| 5928 | ** ^This function may only modify the contents of the BLOB; it is |
| 5929 | ** not possible to increase the size of a BLOB using this API. |
| 5930 | ** ^If offset iOffset is less than N bytes from the end of the BLOB, |
| 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. |
| 5935 | ** |
| 5936 | ** ^An attempt to write to an expired [BLOB handle] fails with an |
| 5937 | ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred |
| 5938 | ** before the [BLOB handle] expired are not rolled back by the |
| 5939 | ** expiration of the handle, though of course those changes might |
| 5940 | ** have been overwritten by the statement that expired the BLOB handle |
| 5941 | ** or by other independent statements. |
| 5942 | ** |
| 5943 | ** ^(On success, sqlite3_blob_write() returns SQLITE_OK. |
| 5944 | ** Otherwise, an [error code] or an [extended error code] is returned.)^ |
| 5945 | ** |
| 5946 | ** This routine only works on a [BLOB handle] which has been created |
| 5947 | ** by a prior successful call to [sqlite3_blob_open()] and which has not |
| 5948 | ** been closed by [sqlite3_blob_close()]. Passing any other pointer in |
| 5949 | ** to this routine results in undefined and probably undesirable behavior. |
| 5950 | ** |
| @@ -6975,14 +6941,10 @@ | |
| 6941 | ** and database name of the source database, respectively. |
| 6942 | ** ^The source and destination [database connections] (parameters S and D) |
| 6943 | ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with |
| 6944 | ** an error. |
| 6945 | ** |
| 6946 | ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is |
| 6947 | ** returned and an error code and error message are stored in the |
| 6948 | ** destination [database connection] D. |
| 6949 | ** ^The error code and message for the failed call to sqlite3_backup_init() |
| 6950 | ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or |
| @@ -7571,102 +7533,10 @@ | |
| 7533 | /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */ |
| 7534 | #define SQLITE_FAIL 3 |
| 7535 | /* #define SQLITE_ABORT 4 // Also an error code */ |
| 7536 | #define SQLITE_REPLACE 5 |
| 7537 | |
| 7538 | |
| 7539 | |
| 7540 | /* |
| 7541 | ** Undo the hack that converts floating point types to integer for |
| 7542 | ** builds on processors without floating point support. |
| @@ -8108,13 +7978,14 @@ | |
| 7978 | #ifndef SQLITE_POWERSAFE_OVERWRITE |
| 7979 | # define SQLITE_POWERSAFE_OVERWRITE 1 |
| 7980 | #endif |
| 7981 | |
| 7982 | /* |
| 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. |
| 7987 | */ |
| 7988 | #if !defined(SQLITE_DEFAULT_MEMSTATUS) |
| 7989 | # define SQLITE_DEFAULT_MEMSTATUS 1 |
| 7990 | #endif |
| 7991 | |
| @@ -8740,11 +8611,11 @@ | |
| 8611 | ** Estimated quantities used for query planning are stored as 16-bit |
| 8612 | ** logarithms. For quantity X, the value stored is 10*log2(X). This |
| 8613 | ** gives a possible range of values of approximately 1.0e986 to 1e-986. |
| 8614 | ** But the allowed values are "grainy". Not every value is representable. |
| 8615 | ** For example, quantities 16 and 17 are both represented by a LogEst |
| 8616 | ** of 40. However, since LogEst quantaties are suppose to be estimates, |
| 8617 | ** not exact values, this imprecision is not a problem. |
| 8618 | ** |
| 8619 | ** "LogEst" is short for "Logarithmic Estimate". |
| 8620 | ** |
| 8621 | ** Examples: |
| @@ -9253,11 +9124,10 @@ | |
| 9124 | SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *); |
| 9125 | SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *); |
| 9126 | SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion); |
| 9127 | SQLITE_PRIVATE void sqlite3BtreeCursorHints(BtCursor *, unsigned int mask); |
| 9128 | SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *pBt); |
| 9129 | |
| 9130 | #ifndef NDEBUG |
| 9131 | SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*); |
| 9132 | #endif |
| 9133 | |
| @@ -9796,16 +9666,10 @@ | |
| 9666 | # define VdbeCoverageAlwaysTaken(v) |
| 9667 | # define VdbeCoverageNeverTaken(v) |
| 9668 | # define VDBE_OFFSET_LINENO(x) 0 |
| 9669 | #endif |
| 9670 | |
| 9671 | #endif |
| 9672 | |
| 9673 | /************** End of vdbe.h ************************************************/ |
| 9674 | /************** Continuing where we left off in sqliteInt.h ******************/ |
| 9675 | /************** Include pager.h in the middle of sqliteInt.h *****************/ |
| @@ -9998,12 +9862,10 @@ | |
| 9862 | SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *); |
| 9863 | |
| 9864 | /* Functions used to truncate the database file. */ |
| 9865 | SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno); |
| 9866 | |
| 9867 | #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_WAL) |
| 9868 | SQLITE_PRIVATE void *sqlite3PagerCodec(DbPage *); |
| 9869 | #endif |
| 9870 | |
| 9871 | /* Functions to support testing and debugging. */ |
| @@ -10187,14 +10049,10 @@ | |
| 10049 | SQLITE_PRIVATE void sqlite3PcacheStats(int*,int*,int*,int*); |
| 10050 | #endif |
| 10051 | |
| 10052 | SQLITE_PRIVATE void sqlite3PCacheSetDefault(void); |
| 10053 | |
| 10054 | #endif /* _PCACHE_H_ */ |
| 10055 | |
| 10056 | /************** End of pcache.h **********************************************/ |
| 10057 | /************** Continuing where we left off in sqliteInt.h ******************/ |
| 10058 | |
| @@ -10877,11 +10735,11 @@ | |
| 10735 | #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */ |
| 10736 | #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */ |
| 10737 | #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */ |
| 10738 | #define SQLITE_Transitive 0x0200 /* Transitive constraints */ |
| 10739 | #define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */ |
| 10740 | #define SQLITE_Stat3 0x0800 /* Use the SQLITE_STAT3 table */ |
| 10741 | #define SQLITE_AllOpts 0xffff /* All optimizations */ |
| 10742 | |
| 10743 | /* |
| 10744 | ** Macros for testing whether or not optimizations are enabled or disabled. |
| 10745 | */ |
| @@ -11459,18 +11317,16 @@ | |
| 11317 | unsigned idxType:2; /* 1==UNIQUE, 2==PRIMARY KEY, 0==CREATE INDEX */ |
| 11318 | unsigned bUnordered:1; /* Use this index for == or IN queries only */ |
| 11319 | unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */ |
| 11320 | unsigned isResized:1; /* True if resizeIndexObject() has been called */ |
| 11321 | unsigned isCovering:1; /* True if this is a covering index */ |
| 11322 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 11323 | int nSample; /* Number of elements in aSample[] */ |
| 11324 | int nSampleCol; /* Size of IndexSample.anEq[] and so on */ |
| 11325 | tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */ |
| 11326 | IndexSample *aSample; /* Samples of the left-most key */ |
| 11327 | tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this table */ |
| 11328 | #endif |
| 11329 | }; |
| 11330 | |
| 11331 | /* |
| 11332 | ** Allowed values for Index.idxType |
| @@ -11664,11 +11520,11 @@ | |
| 11520 | int nHeight; /* Height of the tree headed by this node */ |
| 11521 | #endif |
| 11522 | int iTable; /* TK_COLUMN: cursor number of table holding column |
| 11523 | ** TK_REGISTER: register number |
| 11524 | ** TK_TRIGGER: 1 -> new, 0 -> old |
| 11525 | ** EP_Unlikely: 1000 times likelihood */ |
| 11526 | ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid. |
| 11527 | ** TK_VARIABLE: variable number (always >= 1). */ |
| 11528 | i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */ |
| 11529 | i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */ |
| 11530 | u8 op2; /* TK_REGISTER: original value of Expr.op |
| @@ -12556,15 +12412,13 @@ | |
| 12412 | int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */ |
| 12413 | int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */ |
| 12414 | void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */ |
| 12415 | Parse *pParse; /* Parser context. */ |
| 12416 | int walkerDepth; /* Number of subqueries */ |
| 12417 | union { /* Extra data for callback */ |
| 12418 | NameContext *pNC; /* Naming context */ |
| 12419 | int i; /* Integer value */ |
| 12420 | SrcList *pSrcList; /* FROM clause */ |
| 12421 | struct SrcCount *pSrcCount; /* Counting column references */ |
| 12422 | } u; |
| 12423 | }; |
| 12424 | |
| @@ -12961,11 +12815,10 @@ | |
| 12815 | SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *); |
| 12816 | SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*); |
| 12817 | SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*); |
| 12818 | SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*); |
| 12819 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8); |
| 12820 | SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*); |
| 12821 | SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*); |
| 12822 | SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char); |
| 12823 | SQLITE_PRIVATE int sqlite3IsRowid(const char*); |
| 12824 | SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8); |
| @@ -13619,23 +13472,15 @@ | |
| 13472 | ** compatibility for legacy applications, the URI filename capability is |
| 13473 | ** disabled by default. |
| 13474 | ** |
| 13475 | ** EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled |
| 13476 | ** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options. |
| 13477 | */ |
| 13478 | #ifndef SQLITE_USE_URI |
| 13479 | # define SQLITE_USE_URI 0 |
| 13480 | #endif |
| 13481 | |
| 13482 | #ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN |
| 13483 | # define SQLITE_ALLOW_COVERING_INDEX_SCAN 1 |
| 13484 | #endif |
| 13485 | |
| 13486 | /* |
| @@ -13721,12 +13566,12 @@ | |
| 13566 | ** than 1 GiB. The sqlite3_test_control() interface can be used to |
| 13567 | ** move the pending byte. |
| 13568 | ** |
| 13569 | ** IMPORTANT: Changing the pending byte to any value other than |
| 13570 | ** 0x40000000 results in an incompatible database file format! |
| 13571 | ** Changing the pending byte during operating results in undefined |
| 13572 | ** and dileterious behavior. |
| 13573 | */ |
| 13574 | #ifndef SQLITE_OMIT_WSD |
| 13575 | SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000; |
| 13576 | #endif |
| 13577 | |
| @@ -13802,13 +13647,10 @@ | |
| 13647 | "DISABLE_DIRSYNC", |
| 13648 | #endif |
| 13649 | #ifdef SQLITE_DISABLE_LFS |
| 13650 | "DISABLE_LFS", |
| 13651 | #endif |
| 13652 | #ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 13653 | "ENABLE_ATOMIC_WRITE", |
| 13654 | #endif |
| 13655 | #ifdef SQLITE_ENABLE_CEROD |
| 13656 | "ENABLE_CEROD", |
| @@ -14130,17 +13972,10 @@ | |
| 13972 | ** The name can optionally begin with "SQLITE_" but the "SQLITE_" prefix |
| 13973 | ** is not required for a match. |
| 13974 | */ |
| 13975 | SQLITE_API int sqlite3_compileoption_used(const char *zOptName){ |
| 13976 | int i, n; |
| 13977 | if( sqlite3StrNICmp(zOptName, "SQLITE_", 7)==0 ) zOptName += 7; |
| 13978 | n = sqlite3Strlen30(zOptName); |
| 13979 | |
| 13980 | /* Since ArraySize(azCompileOpt) is normally in single digits, a |
| 13981 | ** linear search is adequate. No need for a binary search. */ |
| @@ -14318,11 +14153,10 @@ | |
| 14153 | typedef struct VdbeFrame VdbeFrame; |
| 14154 | struct VdbeFrame { |
| 14155 | Vdbe *v; /* VM this frame belongs to */ |
| 14156 | VdbeFrame *pParent; /* Parent of this frame, or NULL if parent is main */ |
| 14157 | Op *aOp; /* Program instructions for parent frame */ |
| 14158 | Mem *aMem; /* Array of memory cells for parent frame */ |
| 14159 | u8 *aOnceFlag; /* Array of OP_Once flags for parent frame */ |
| 14160 | VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */ |
| 14161 | void *token; /* Copy of SubProgram.token */ |
| 14162 | i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */ |
| @@ -14331,12 +14165,11 @@ | |
| 14165 | int nOp; /* Size of aOp array */ |
| 14166 | int nMem; /* Number of entries in aMem */ |
| 14167 | int nOnceFlag; /* Number of entries in aOnceFlag */ |
| 14168 | int nChildMem; /* Number of memory cells for child frame */ |
| 14169 | int nChildCsr; /* Number of cursors for child frame */ |
| 14170 | int nChange; /* Statement changes (Vdbe.nChanges) */ |
| 14171 | }; |
| 14172 | |
| 14173 | #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))]) |
| 14174 | |
| 14175 | /* |
| @@ -14483,20 +14316,10 @@ | |
| 14316 | /* A bitfield type for use inside of structures. Always follow with :N where |
| 14317 | ** N is the number of bits. |
| 14318 | */ |
| 14319 | typedef unsigned bft; /* Bit Field Type */ |
| 14320 | |
| 14321 | /* |
| 14322 | ** An instance of the virtual machine. This structure contains the complete |
| 14323 | ** state of the virtual machine. |
| 14324 | ** |
| 14325 | ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare() |
| @@ -14565,15 +14388,10 @@ | |
| 14388 | u32 expmask; /* Binding to these vars invalidates VM */ |
| 14389 | SubProgram *pProgram; /* Linked list of all sub-programs used by VM */ |
| 14390 | int nOnceFlag; /* Size of array aOnceFlag[] */ |
| 14391 | u8 *aOnceFlag; /* Flags for OP_Once */ |
| 14392 | AuxData *pAuxData; /* Linked list of auxdata allocations */ |
| 14393 | }; |
| 14394 | |
| 14395 | /* |
| 14396 | ** The following are allowed values for Vdbe.magic |
| 14397 | */ |
| @@ -14759,13 +14577,10 @@ | |
| 14577 | SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){ |
| 14578 | wsdStatInit; |
| 14579 | if( op<0 || op>=ArraySize(wsdStat.nowValue) ){ |
| 14580 | return SQLITE_MISUSE_BKPT; |
| 14581 | } |
| 14582 | *pCurrent = wsdStat.nowValue[op]; |
| 14583 | *pHighwater = wsdStat.mxValue[op]; |
| 14584 | if( resetFlag ){ |
| 14585 | wsdStat.mxValue[op] = wsdStat.nowValue[op]; |
| 14586 | } |
| @@ -14781,15 +14596,10 @@ | |
| 14596 | int *pCurrent, /* Write current value here */ |
| 14597 | int *pHighwater, /* Write high-water mark here */ |
| 14598 | int resetFlag /* Reset high-water mark if true */ |
| 14599 | ){ |
| 14600 | int rc = SQLITE_OK; /* Return code */ |
| 14601 | sqlite3_mutex_enter(db->mutex); |
| 14602 | switch( op ){ |
| 14603 | case SQLITE_DBSTATUS_LOOKASIDE_USED: { |
| 14604 | *pCurrent = db->lookaside.nOut; |
| 14605 | *pHighwater = db->lookaside.mxOut; |
| @@ -14964,11 +14774,11 @@ | |
| 14774 | ** |
| 14775 | ** There is only one exported symbol in this file - the function |
| 14776 | ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file. |
| 14777 | ** All other code has file scope. |
| 14778 | ** |
| 14779 | ** SQLite processes all times and dates as Julian Day numbers. The |
| 14780 | ** dates and times are stored as the number of days since noon |
| 14781 | ** in Greenwich on November 24, 4714 B.C. according to the Gregorian |
| 14782 | ** calendar system. |
| 14783 | ** |
| 14784 | ** 1970-01-01 00:00:00 is JD 2440587.5 |
| @@ -14979,11 +14789,11 @@ | |
| 14789 | ** be represented, even though julian day numbers allow a much wider |
| 14790 | ** range of dates. |
| 14791 | ** |
| 14792 | ** The Gregorian calendar system is used for all dates and times, |
| 14793 | ** even those that predate the Gregorian calendar. Historians usually |
| 14794 | ** use the Julian calendar for dates prior to 1582-10-15 and for some |
| 14795 | ** dates afterwards, depending on locale. Beware of this difference. |
| 14796 | ** |
| 14797 | ** The conversion algorithms are implemented based on descriptions |
| 14798 | ** in the following text: |
| 14799 | ** |
| @@ -15251,11 +15061,11 @@ | |
| 15061 | return 1; |
| 15062 | } |
| 15063 | } |
| 15064 | |
| 15065 | /* |
| 15066 | ** Attempt to parse the given string into a Julian Day Number. Return |
| 15067 | ** the number of errors. |
| 15068 | ** |
| 15069 | ** The following are acceptable forms for the input string: |
| 15070 | ** |
| 15071 | ** YYYY-MM-DD HH:MM:SS.FFF +/-HH:MM |
| @@ -15822,11 +15632,11 @@ | |
| 15632 | ** |
| 15633 | ** %d day of month |
| 15634 | ** %f ** fractional seconds SS.SSS |
| 15635 | ** %H hour 00-24 |
| 15636 | ** %j day of year 000-366 |
| 15637 | ** %J ** Julian day number |
| 15638 | ** %m month 01-12 |
| 15639 | ** %M minute 00-59 |
| 15640 | ** %s seconds since 1970-01-01 |
| 15641 | ** %S seconds 00-59 |
| 15642 | ** %w day of week 0-6 sunday==0 |
| @@ -16447,14 +16257,10 @@ | |
| 16257 | MUTEX_LOGIC(sqlite3_mutex *mutex;) |
| 16258 | #ifndef SQLITE_OMIT_AUTOINIT |
| 16259 | int rc = sqlite3_initialize(); |
| 16260 | if( rc ) return rc; |
| 16261 | #endif |
| 16262 | MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); ) |
| 16263 | sqlite3_mutex_enter(mutex); |
| 16264 | vfsUnlink(pVfs); |
| 16265 | if( makeDflt || vfsList==0 ){ |
| 16266 | pVfs->pNext = vfsList; |
| @@ -18808,11 +18614,10 @@ | |
| 18614 | ** Retrieve a pointer to a static mutex or allocate a new dynamic one. |
| 18615 | */ |
| 18616 | SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int id){ |
| 18617 | #ifndef SQLITE_OMIT_AUTOINIT |
| 18618 | if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0; |
| 18619 | #endif |
| 18620 | return sqlite3GlobalConfig.mutex.xMutexAlloc(id); |
| 18621 | } |
| 18622 | |
| 18623 | SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int id){ |
| @@ -19265,16 +19070,12 @@ | |
| 19070 | pthread_mutex_init(&p->mutex, 0); |
| 19071 | } |
| 19072 | break; |
| 19073 | } |
| 19074 | default: { |
| 19075 | assert( iType-2 >= 0 ); |
| 19076 | assert( iType-2 < ArraySize(staticMutexes) ); |
| 19077 | p = &staticMutexes[iType-2]; |
| 19078 | #if SQLITE_MUTEX_NREF |
| 19079 | p->id = iType; |
| 19080 | #endif |
| 19081 | break; |
| @@ -20492,16 +20293,15 @@ | |
| 20293 | } |
| 20294 | assert( sqlite3_mutex_notheld(mem0.mutex) ); |
| 20295 | |
| 20296 | |
| 20297 | #if SQLITE_THREADSAFE==0 && !defined(NDEBUG) |
| 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 ); |
| 20303 | if( p ) scratchAllocOut++; |
| 20304 | #endif |
| 20305 | |
| 20306 | return p; |
| 20307 | } |
| @@ -21156,17 +20956,10 @@ | |
| 20956 | etByte flag_rtz; /* True if trailing zeros should be removed */ |
| 20957 | #endif |
| 20958 | PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */ |
| 20959 | char buf[etBUFSIZE]; /* Conversion buffer */ |
| 20960 | |
| 20961 | bufpt = 0; |
| 20962 | if( bFlags ){ |
| 20963 | if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){ |
| 20964 | pArgList = va_arg(ap, PrintfArguments*); |
| 20965 | } |
| @@ -21703,15 +21496,10 @@ | |
| 21496 | return N; |
| 21497 | }else{ |
| 21498 | char *zOld = (p->zText==p->zBase ? 0 : p->zText); |
| 21499 | i64 szNew = p->nChar; |
| 21500 | szNew += N + 1; |
| 21501 | if( szNew > p->mxAlloc ){ |
| 21502 | sqlite3StrAccumReset(p); |
| 21503 | setStrAccumError(p, STRACCUM_TOOBIG); |
| 21504 | return 0; |
| 21505 | }else{ |
| @@ -21724,11 +21512,10 @@ | |
| 21512 | } |
| 21513 | if( zNew ){ |
| 21514 | assert( p->zText!=0 || p->nChar==0 ); |
| 21515 | if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); |
| 21516 | p->zText = zNew; |
| 21517 | }else{ |
| 21518 | sqlite3StrAccumReset(p); |
| 21519 | setStrAccumError(p, STRACCUM_NOMEM); |
| 21520 | return 0; |
| 21521 | } |
| @@ -21894,17 +21681,10 @@ | |
| 21681 | */ |
| 21682 | SQLITE_API char *sqlite3_vmprintf(const char *zFormat, va_list ap){ |
| 21683 | char *z; |
| 21684 | char zBase[SQLITE_PRINT_BUF_SIZE]; |
| 21685 | StrAccum acc; |
| 21686 | #ifndef SQLITE_OMIT_AUTOINIT |
| 21687 | if( sqlite3_initialize() ) return 0; |
| 21688 | #endif |
| 21689 | sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH); |
| 21690 | acc.useMalloc = 2; |
| @@ -21943,17 +21723,10 @@ | |
| 21723 | ** sqlite3_vsnprintf() is the varargs version. |
| 21724 | */ |
| 21725 | SQLITE_API char *sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){ |
| 21726 | StrAccum acc; |
| 21727 | if( n<=0 ) return zBuf; |
| 21728 | sqlite3StrAccumInit(&acc, zBuf, n, 0); |
| 21729 | acc.useMalloc = 0; |
| 21730 | sqlite3VXPrintf(&acc, 0, zFormat, ap); |
| 21731 | return sqlite3StrAccumFinish(&acc); |
| 21732 | } |
| @@ -22141,23 +21914,15 @@ | |
| 21914 | #else |
| 21915 | # define wsdPrng sqlite3Prng |
| 21916 | #endif |
| 21917 | |
| 21918 | #if SQLITE_THREADSAFE |
| 21919 | sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG); |
| 21920 | sqlite3_mutex_enter(mutex); |
| 21921 | #endif |
| 21922 | |
| 21923 | if( N<=0 ){ |
| 21924 | wsdPrng.isInit = 0; |
| 21925 | sqlite3_mutex_leave(mutex); |
| 21926 | return; |
| 21927 | } |
| 21928 | |
| @@ -23275,27 +23040,17 @@ | |
| 23040 | ** case-independent fashion, using the same definition of "case |
| 23041 | ** independence" that SQLite uses internally when comparing identifiers. |
| 23042 | */ |
| 23043 | SQLITE_API int sqlite3_stricmp(const char *zLeft, const char *zRight){ |
| 23044 | register unsigned char *a, *b; |
| 23045 | a = (unsigned char *)zLeft; |
| 23046 | b = (unsigned char *)zRight; |
| 23047 | while( *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; } |
| 23048 | return UpperToLower[*a] - UpperToLower[*b]; |
| 23049 | } |
| 23050 | SQLITE_API int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){ |
| 23051 | register unsigned char *a, *b; |
| 23052 | a = (unsigned char *)zLeft; |
| 23053 | b = (unsigned char *)zRight; |
| 23054 | while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; } |
| 23055 | return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b]; |
| 23056 | } |
| @@ -32824,15 +32579,10 @@ | |
| 32579 | #if !SQLITE_OS_WINNT && !defined(SQLITE_OMIT_WAL) |
| 32580 | # error "WAL mode requires support from the Windows NT kernel, compile\ |
| 32581 | with SQLITE_OMIT_WAL." |
| 32582 | #endif |
| 32583 | |
| 32584 | /* |
| 32585 | ** Are most of the Win32 ANSI APIs available (i.e. with certain exceptions |
| 32586 | ** based on the sub-platform)? |
| 32587 | */ |
| 32588 | #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(SQLITE_WIN32_NO_ANSI) |
| @@ -32958,15 +32708,14 @@ | |
| 32708 | # define winGetDirSep() '\\' |
| 32709 | #endif |
| 32710 | |
| 32711 | /* |
| 32712 | ** Do we need to manually define the Win32 file mapping APIs for use with WAL |
| 32713 | ** mode (e.g. these APIs are available in the Windows CE SDK; however, they |
| 32714 | ** are not present in the header file)? |
| 32715 | */ |
| 32716 | #if SQLITE_WIN32_FILEMAPPING_API && !defined(SQLITE_OMIT_WAL) |
| 32717 | /* |
| 32718 | ** Two of the file mapping APIs are different under WinRT. Figure out which |
| 32719 | ** set we need. |
| 32720 | */ |
| 32721 | #if SQLITE_OS_WINRT |
| @@ -32990,11 +32739,11 @@ | |
| 32739 | |
| 32740 | /* |
| 32741 | ** This file mapping API is common to both Win32 and WinRT. |
| 32742 | */ |
| 32743 | WINBASEAPI BOOL WINAPI UnmapViewOfFile(LPCVOID); |
| 32744 | #endif /* SQLITE_WIN32_FILEMAPPING_API && !defined(SQLITE_OMIT_WAL) */ |
| 32745 | |
| 32746 | /* |
| 32747 | ** Some Microsoft compilers lack this definition. |
| 32748 | */ |
| 32749 | #ifndef INVALID_FILE_ATTRIBUTES |
| @@ -33283,21 +33032,21 @@ | |
| 33032 | |
| 33033 | #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \ |
| 33034 | LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent) |
| 33035 | |
| 33036 | #if (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_ANSI) && \ |
| 33037 | !defined(SQLITE_OMIT_WAL)) |
| 33038 | { "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 }, |
| 33039 | #else |
| 33040 | { "CreateFileMappingA", (SYSCALL)0, 0 }, |
| 33041 | #endif |
| 33042 | |
| 33043 | #define osCreateFileMappingA ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \ |
| 33044 | DWORD,DWORD,DWORD,LPCSTR))aSyscall[6].pCurrent) |
| 33045 | |
| 33046 | #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \ |
| 33047 | !defined(SQLITE_OMIT_WAL)) |
| 33048 | { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 }, |
| 33049 | #else |
| 33050 | { "CreateFileMappingW", (SYSCALL)0, 0 }, |
| 33051 | #endif |
| 33052 | |
| @@ -33633,12 +33382,11 @@ | |
| 33382 | #ifndef osLockFileEx |
| 33383 | #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \ |
| 33384 | LPOVERLAPPED))aSyscall[48].pCurrent) |
| 33385 | #endif |
| 33386 | |
| 33387 | #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)) |
| 33388 | { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 }, |
| 33389 | #else |
| 33390 | { "MapViewOfFile", (SYSCALL)0, 0 }, |
| 33391 | #endif |
| 33392 | |
| @@ -33704,11 +33452,11 @@ | |
| 33452 | #endif |
| 33453 | |
| 33454 | #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ |
| 33455 | LPOVERLAPPED))aSyscall[58].pCurrent) |
| 33456 | |
| 33457 | #if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL) |
| 33458 | { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 }, |
| 33459 | #else |
| 33460 | { "UnmapViewOfFile", (SYSCALL)0, 0 }, |
| 33461 | #endif |
| 33462 | |
| @@ -33767,11 +33515,11 @@ | |
| 33515 | #endif |
| 33516 | |
| 33517 | #define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \ |
| 33518 | FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[66].pCurrent) |
| 33519 | |
| 33520 | #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL) |
| 33521 | { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 }, |
| 33522 | #else |
| 33523 | { "MapViewOfFileFromApp", (SYSCALL)0, 0 }, |
| 33524 | #endif |
| 33525 | |
| @@ -33831,11 +33579,11 @@ | |
| 33579 | |
| 33580 | { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 }, |
| 33581 | |
| 33582 | #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[74].pCurrent) |
| 33583 | |
| 33584 | #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL) |
| 33585 | { "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 }, |
| 33586 | #else |
| 33587 | { "CreateFileMappingFromApp", (SYSCALL)0, 0 }, |
| 33588 | #endif |
| 33589 | |
| @@ -39407,17 +39155,10 @@ | |
| 39155 | */ |
| 39156 | SQLITE_PRIVATE void sqlite3PcacheShrink(PCache *pCache){ |
| 39157 | assert( pCache->pCache!=0 ); |
| 39158 | sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache); |
| 39159 | } |
| 39160 | |
| 39161 | #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG) |
| 39162 | /* |
| 39163 | ** For all dirty pages currently in the cache, invoke the specified |
| 39164 | ** callback. This is only used if the SQLITE_CHECK_PAGES macro is |
| @@ -40413,15 +40154,10 @@ | |
| 40154 | pcache1Shrink /* xShrink */ |
| 40155 | }; |
| 40156 | sqlite3_config(SQLITE_CONFIG_PCACHE2, &defaultMethods); |
| 40157 | } |
| 40158 | |
| 40159 | #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 40160 | /* |
| 40161 | ** This function is called to free superfluous dynamically allocated memory |
| 40162 | ** held by the pager system. Memory in use by any SQLite pager allocated |
| 40163 | ** by the current thread may be sqlite3_free()ed. |
| @@ -47975,22 +47711,10 @@ | |
| 47711 | |
| 47712 | return SQLITE_OK; |
| 47713 | } |
| 47714 | #endif |
| 47715 | |
| 47716 | /* |
| 47717 | ** Return a pointer to the data for the specified page. |
| 47718 | */ |
| 47719 | SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *pPg){ |
| 47720 | assert( pPg->nRef>0 || pPg->pPager->memDb ); |
| @@ -48384,11 +48108,10 @@ | |
| 48108 | SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager){ |
| 48109 | assert( pPager->eState>=PAGER_READER ); |
| 48110 | return sqlite3WalFramesize(pPager->pWal); |
| 48111 | } |
| 48112 | #endif |
| 48113 | |
| 48114 | #endif /* SQLITE_OMIT_DISKIO */ |
| 48115 | |
| 48116 | /************** End of pager.c ***********************************************/ |
| 48117 | /************** Begin file wal.c *********************************************/ |
| @@ -49895,11 +49618,11 @@ | |
| 49618 | |
| 49619 | /* |
| 49620 | ** Free an iterator allocated by walIteratorInit(). |
| 49621 | */ |
| 49622 | static void walIteratorFree(WalIterator *p){ |
| 49623 | sqlite3ScratchFree(p); |
| 49624 | } |
| 49625 | |
| 49626 | /* |
| 49627 | ** Construct a WalInterator object that can be used to loop over all |
| 49628 | ** pages in the WAL in ascending order. The caller must hold the checkpoint |
| @@ -49930,21 +49653,21 @@ | |
| 49653 | /* Allocate space for the WalIterator object. */ |
| 49654 | nSegment = walFramePage(iLast) + 1; |
| 49655 | nByte = sizeof(WalIterator) |
| 49656 | + (nSegment-1)*sizeof(struct WalSegment) |
| 49657 | + iLast*sizeof(ht_slot); |
| 49658 | p = (WalIterator *)sqlite3ScratchMalloc(nByte); |
| 49659 | if( !p ){ |
| 49660 | return SQLITE_NOMEM; |
| 49661 | } |
| 49662 | memset(p, 0, nByte); |
| 49663 | p->nSegment = nSegment; |
| 49664 | |
| 49665 | /* Allocate temporary space used by the merge-sort routine. This block |
| 49666 | ** of memory will be freed before this function returns. |
| 49667 | */ |
| 49668 | aTmp = (ht_slot *)sqlite3ScratchMalloc( |
| 49669 | sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast) |
| 49670 | ); |
| 49671 | if( !aTmp ){ |
| 49672 | rc = SQLITE_NOMEM; |
| 49673 | } |
| @@ -49977,11 +49700,11 @@ | |
| 49700 | p->aSegment[i].nEntry = nEntry; |
| 49701 | p->aSegment[i].aIndex = aIndex; |
| 49702 | p->aSegment[i].aPgno = (u32 *)aPgno; |
| 49703 | } |
| 49704 | } |
| 49705 | sqlite3ScratchFree(aTmp); |
| 49706 | |
| 49707 | if( rc!=SQLITE_OK ){ |
| 49708 | walIteratorFree(p); |
| 49709 | } |
| 49710 | *pp = p; |
| @@ -50897,11 +50620,11 @@ | |
| 50620 | ** was in before the client began writing to the database. |
| 50621 | */ |
| 50622 | memcpy(&pWal->hdr, (void *)walIndexHdr(pWal), sizeof(WalIndexHdr)); |
| 50623 | |
| 50624 | for(iFrame=pWal->hdr.mxFrame+1; |
| 50625 | ALWAYS(rc==SQLITE_OK) && iFrame<=iMax; |
| 50626 | iFrame++ |
| 50627 | ){ |
| 50628 | /* This call cannot fail. Unless the page for which the page number |
| 50629 | ** is passed as the second argument is (a) in the cache and |
| 50630 | ** (b) has an outstanding reference, then xUndo is either a no-op |
| @@ -53620,27 +53343,28 @@ | |
| 53343 | int cellOffset; /* Offset to the cell pointer array */ |
| 53344 | int cbrk; /* Offset to the cell content area */ |
| 53345 | int nCell; /* Number of cells on the page */ |
| 53346 | unsigned char *data; /* The page data */ |
| 53347 | unsigned char *temp; /* Temp area for cell content */ |
| 53348 | int iCellFirst; /* First allowable cell index */ |
| 53349 | int iCellLast; /* Last possible cell index */ |
| 53350 | |
| 53351 | |
| 53352 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 53353 | assert( pPage->pBt!=0 ); |
| 53354 | assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE ); |
| 53355 | assert( pPage->nOverflow==0 ); |
| 53356 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 53357 | temp = sqlite3PagerTempSpace(pPage->pBt->pPager); |
| 53358 | data = pPage->aData; |
| 53359 | hdr = pPage->hdrOffset; |
| 53360 | cellOffset = pPage->cellOffset; |
| 53361 | nCell = pPage->nCell; |
| 53362 | assert( nCell==get2byte(&data[hdr+3]) ); |
| 53363 | usableSize = pPage->pBt->usableSize; |
| 53364 | cbrk = get2byte(&data[hdr+5]); |
| 53365 | memcpy(&temp[cbrk], &data[cbrk], usableSize - cbrk); |
| 53366 | cbrk = usableSize; |
| 53367 | iCellFirst = cellOffset + 2*nCell; |
| 53368 | iCellLast = usableSize - 4; |
| 53369 | for(i=0; i<nCell; i++){ |
| 53370 | u8 *pAddr; /* The i-th cell pointer */ |
| @@ -53655,11 +53379,11 @@ | |
| 53379 | if( pc<iCellFirst || pc>iCellLast ){ |
| 53380 | return SQLITE_CORRUPT_BKPT; |
| 53381 | } |
| 53382 | #endif |
| 53383 | assert( pc>=iCellFirst && pc<=iCellLast ); |
| 53384 | size = cellSizePtr(pPage, &temp[pc]); |
| 53385 | cbrk -= size; |
| 53386 | #if defined(SQLITE_ENABLE_OVERSIZE_CELL_CHECK) |
| 53387 | if( cbrk<iCellFirst ){ |
| 53388 | return SQLITE_CORRUPT_BKPT; |
| 53389 | } |
| @@ -53669,20 +53393,12 @@ | |
| 53393 | } |
| 53394 | #endif |
| 53395 | assert( cbrk+size<=usableSize && cbrk>=iCellFirst ); |
| 53396 | testcase( cbrk+size==usableSize ); |
| 53397 | testcase( pc+size==usableSize ); |
| 53398 | memcpy(&data[cbrk], &temp[pc], size); |
| 53399 | put2byte(pAddr, cbrk); |
| 53400 | } |
| 53401 | assert( cbrk>=iCellFirst ); |
| 53402 | put2byte(&data[hdr+5], cbrk); |
| 53403 | data[hdr+1] = 0; |
| 53404 | data[hdr+2] = 0; |
| @@ -53693,66 +53409,10 @@ | |
| 53409 | return SQLITE_CORRUPT_BKPT; |
| 53410 | } |
| 53411 | return SQLITE_OK; |
| 53412 | } |
| 53413 | |
| 53414 | /* |
| 53415 | ** Allocate nByte bytes of space from within the B-Tree page passed |
| 53416 | ** as the first argument. Write into *pIdx the index into pPage->aData[] |
| 53417 | ** of the first byte of allocated space. Return either SQLITE_OK or |
| 53418 | ** an error code (usually SQLITE_CORRUPT). |
| @@ -53766,20 +53426,22 @@ | |
| 53426 | */ |
| 53427 | static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ |
| 53428 | const int hdr = pPage->hdrOffset; /* Local cache of pPage->hdrOffset */ |
| 53429 | u8 * const data = pPage->aData; /* Local cache of pPage->aData */ |
| 53430 | int top; /* First byte of cell content area */ |
| 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 */ |
| 53434 | |
| 53435 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 53436 | assert( pPage->pBt ); |
| 53437 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 53438 | assert( nByte>=0 ); /* Minimum cell size is 4 */ |
| 53439 | assert( pPage->nFree>=nByte ); |
| 53440 | assert( pPage->nOverflow==0 ); |
| 53441 | usableSize = pPage->pBt->usableSize; |
| 53442 | assert( nByte < usableSize-8 ); |
| 53443 | |
| 53444 | assert( pPage->cellOffset == hdr + 12 - 4*pPage->leaf ); |
| 53445 | gap = pPage->cellOffset + 2*pPage->nCell; |
| 53446 | assert( gap<=65536 ); |
| 53447 | top = get2byte(&data[hdr+5]); |
| @@ -53797,27 +53459,46 @@ | |
| 53459 | */ |
| 53460 | testcase( gap+2==top ); |
| 53461 | testcase( gap+1==top ); |
| 53462 | testcase( gap==top ); |
| 53463 | if( gap+2<=top && (data[hdr+1] || data[hdr+2]) ){ |
| 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 | } |
| 53491 | } |
| 53492 | } |
| 53493 | |
| 53494 | /* The request could not be fulfilled using a freelist slot. Check |
| 53495 | ** to see if defragmentation is necessary. |
| 53496 | */ |
| 53497 | testcase( gap+2+nByte==top ); |
| 53498 | if( gap+2+nByte>top ){ |
| 53499 | defragment_page: |
| 53500 | testcase( pPage->nCell==0 ); |
| 53501 | rc = defragmentPage(pPage); |
| 53502 | if( rc ) return rc; |
| 53503 | top = get2byteNotZero(&data[hdr+5]); |
| 53504 | assert( gap+nByte<=top ); |
| @@ -53861,11 +53542,11 @@ | |
| 53542 | unsigned char *data = pPage->aData; /* Page content */ |
| 53543 | |
| 53544 | assert( pPage->pBt!=0 ); |
| 53545 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 53546 | assert( iStart>=pPage->hdrOffset+6+pPage->childPtrSize ); |
| 53547 | assert( iEnd <= pPage->pBt->usableSize ); |
| 53548 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 53549 | assert( iSize>=4 ); /* Minimum cell size is 4 */ |
| 53550 | assert( iStart<=iLast ); |
| 53551 | |
| 53552 | /* Overwrite deleted information with zeros when the secure_delete |
| @@ -58476,266 +58157,49 @@ | |
| 58157 | #endif |
| 58158 | } |
| 58159 | } |
| 58160 | |
| 58161 | /* |
| 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; |
| 58201 | } |
| 58202 | |
| 58203 | /* |
| 58204 | ** The following parameters determine how many adjacent pages get involved |
| 58205 | ** in a balancing operation. NN is the number of neighbors on either side |
| @@ -58803,12 +58267,11 @@ | |
| 58267 | u8 *pStop; |
| 58268 | |
| 58269 | assert( sqlite3PagerIswriteable(pNew->pDbPage) ); |
| 58270 | assert( pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) ); |
| 58271 | zeroPage(pNew, PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF); |
| 58272 | assemblePage(pNew, 1, &pCell, &szCell); |
| 58273 | |
| 58274 | /* If this is an auto-vacuum database, update the pointer map |
| 58275 | ** with entries for the new page, and any pointer from the |
| 58276 | ** cell on the page to an overflow page. If either of these |
| 58277 | ** operations fails, the return code is set, but the contents |
| @@ -59023,26 +58486,21 @@ | |
| 58486 | int subtotal; /* Subtotal of bytes in cells on one page */ |
| 58487 | int iSpace1 = 0; /* First unused byte of aSpace1[] */ |
| 58488 | int iOvflSpace = 0; /* First unused byte of aOvflSpace[] */ |
| 58489 | int szScratch; /* Size of scratch memory requested */ |
| 58490 | MemPage *apOld[NB]; /* pPage and up to two siblings */ |
| 58491 | MemPage *apCopy[NB]; /* Private copies of apOld[] pages */ |
| 58492 | MemPage *apNew[NB+2]; /* pPage and up to NB siblings after balancing */ |
| 58493 | u8 *pRight; /* Location in parent of right-sibling pointer */ |
| 58494 | u8 *apDiv[NB-1]; /* Divider cells in pParent */ |
| 58495 | int cntNew[NB+2]; /* Index in aCell[] of cell after i-th page */ |
| 58496 | int szNew[NB+2]; /* Combined size of cells place on i-th page */ |
| 58497 | u8 **apCell = 0; /* All cells begin balanced */ |
| 58498 | u16 *szCell; /* Local size of all cells in apCell[] */ |
| 58499 | u8 *aSpace1; /* Space for copies of dividers cells */ |
| 58500 | Pgno pgno; /* Temp var to store a page number in */ |
| 58501 | |
| 58502 | pBt = pParent->pBt; |
| 58503 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 58504 | assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 58505 | |
| 58506 | #if 0 |
| @@ -59147,18 +58605,16 @@ | |
| 58605 | nMaxCells = (nMaxCells + 3)&~3; |
| 58606 | |
| 58607 | /* |
| 58608 | ** Allocate space for memory structures |
| 58609 | */ |
| 58610 | k = pBt->pageSize + ROUND8(sizeof(MemPage)); |
| 58611 | szScratch = |
| 58612 | nMaxCells*sizeof(u8*) /* apCell */ |
| 58613 | + nMaxCells*sizeof(u16) /* szCell */ |
| 58614 | + pBt->pageSize /* aSpace1 */ |
| 58615 | + k*nOld; /* Page copies (apCopy) */ |
| 58616 | apCell = sqlite3ScratchMalloc( szScratch ); |
| 58617 | if( apCell==0 ){ |
| 58618 | rc = SQLITE_NOMEM; |
| 58619 | goto balance_cleanup; |
| 58620 | } |
| @@ -59167,12 +58623,12 @@ | |
| 58623 | assert( EIGHT_BYTE_ALIGNMENT(aSpace1) ); |
| 58624 | |
| 58625 | /* |
| 58626 | ** Load pointers to all cells on sibling pages and the divider cells |
| 58627 | ** into the local apCell[] array. Make copies of the divider cells |
| 58628 | ** into space obtained from aSpace1[] and remove the divider cells |
| 58629 | ** from pParent. |
| 58630 | ** |
| 58631 | ** If the siblings are on leaf pages, then the child pointers of the |
| 58632 | ** divider cells are stripped from the cells before they are copied |
| 58633 | ** into aSpace1[]. In this way, all cells in apCell[] are without |
| 58634 | ** child pointers. If siblings are not leaves, then all cell in |
| @@ -59184,11 +58640,19 @@ | |
| 58640 | */ |
| 58641 | leafCorrection = apOld[0]->leaf*4; |
| 58642 | leafData = apOld[0]->intKeyLeaf; |
| 58643 | for(i=0; i<nOld; i++){ |
| 58644 | int limit; |
| 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); |
| 58654 | |
| 58655 | limit = pOld->nCell+pOld->nOverflow; |
| 58656 | if( pOld->nOverflow>0 ){ |
| 58657 | for(j=0; j<limit; j++){ |
| 58658 | assert( nCell<nMaxCells ); |
| @@ -59205,11 +58669,10 @@ | |
| 58669 | apCell[nCell] = findCellv2(aData, maskPage, cellOffset, j); |
| 58670 | szCell[nCell] = cellSizePtr(pOld, apCell[nCell]); |
| 58671 | nCell++; |
| 58672 | } |
| 58673 | } |
| 58674 | if( i<nOld-1 && !leafData){ |
| 58675 | u16 sz = (u16)szNew[i]; |
| 58676 | u8 *pTemp; |
| 58677 | assert( nCell<nMaxCells ); |
| 58678 | szCell[nCell] = sz; |
| @@ -59257,11 +58720,11 @@ | |
| 58720 | usableSpace = pBt->usableSize - 12 + leafCorrection; |
| 58721 | for(subtotal=k=i=0; i<nCell; i++){ |
| 58722 | assert( i<nMaxCells ); |
| 58723 | subtotal += szCell[i] + 2; |
| 58724 | if( subtotal > usableSpace ){ |
| 58725 | szNew[k] = subtotal - szCell[i]; |
| 58726 | cntNew[k] = i; |
| 58727 | if( leafData ){ i--; } |
| 58728 | subtotal = 0; |
| 58729 | k++; |
| 58730 | if( k>NB+1 ){ rc = SQLITE_CORRUPT_BKPT; goto balance_cleanup; } |
| @@ -59271,14 +58734,13 @@ | |
| 58734 | cntNew[k] = nCell; |
| 58735 | k++; |
| 58736 | |
| 58737 | /* |
| 58738 | ** The packing computed by the previous block is biased toward the siblings |
| 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. |
| 58742 | ** |
| 58743 | ** This adjustment is more than an optimization. The packing above might |
| 58744 | ** be so out of balance as to be illegal. For example, the right-most |
| 58745 | ** sibling might be completely empty. This adjustment is not optional. |
| 58746 | */ |
| @@ -59303,22 +58765,26 @@ | |
| 58765 | } |
| 58766 | szNew[i] = szRight; |
| 58767 | szNew[i-1] = szLeft; |
| 58768 | } |
| 58769 | |
| 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. |
| 58777 | */ |
| 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 |
| 58786 | )); |
| 58787 | |
| 58788 | /* |
| 58789 | ** Allocate k new pages. Reuse old pages where possible. |
| 58790 | */ |
| @@ -59337,14 +58803,12 @@ | |
| 58803 | if( rc ) goto balance_cleanup; |
| 58804 | }else{ |
| 58805 | assert( i>0 ); |
| 58806 | rc = allocateBtreePage(pBt, &pNew, &pgno, (bBulk ? 1 : pgno), 0); |
| 58807 | if( rc ) goto balance_cleanup; |
| 58808 | apNew[i] = pNew; |
| 58809 | nNew++; |
| 58810 | |
| 58811 | /* Set the pointer-map entry for the new sibling page. */ |
| 58812 | if( ISAUTOVACUUM ){ |
| 58813 | ptrmapPut(pBt, pNew->pgno, PTRMAP_BTREE, pParent->pgno, &rc); |
| 58814 | if( rc!=SQLITE_OK ){ |
| @@ -59351,248 +58815,140 @@ | |
| 58815 | goto balance_cleanup; |
| 58816 | } |
| 58817 | } |
| 58818 | } |
| 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 | } |
| 58830 | |
| 58831 | /* |
| 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], |
| 58863 | nNew>=2 ? apNew[1]->pgno : 0, nNew>=2 ? szNew[1] : 0, |
| 58864 | nNew>=3 ? apNew[2]->pgno : 0, nNew>=3 ? szNew[2] : 0, |
| 58865 | nNew>=4 ? apNew[3]->pgno : 0, nNew>=4 ? szNew[3] : 0, |
| 58866 | nNew>=5 ? apNew[4]->pgno : 0, nNew>=5 ? szNew[4] : 0)); |
| 58867 | |
| 58868 | assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 58869 | put4byte(pRight, apNew[nNew-1]->pgno); |
| 58870 | |
| 58871 | /* |
| 58872 | ** Evenly distribute the data in apCell[] across the new pages. |
| 58873 | ** Insert divider cells into pParent as necessary. |
| 58874 | */ |
| 58875 | j = 0; |
| 58876 | for(i=0; i<nNew; i++){ |
| 58877 | /* Assemble the new sibling page. */ |
| 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 | |
| 58885 | j = cntNew[i]; |
| 58886 | |
| 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 ); |
| 58944 | assert( nOld>0 ); |
| 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 | } |
| 58950 | |
| 58951 | if( isRoot && pParent->nCell==0 && pParent->hdrOffset<=apNew[0]->nFree ){ |
| 58952 | /* The root page of the b-tree now contains no cells. The only sibling |
| 58953 | ** page is the right-child of the parent. Copy the contents of the |
| 58954 | ** child page into the parent, decreasing the overall height of the |
| @@ -59601,54 +58957,130 @@ | |
| 58957 | ** |
| 58958 | ** If this is an auto-vacuum database, the call to copyNodeContent() |
| 58959 | ** sets all pointer-map entries corresponding to database image pages |
| 58960 | ** for which the pointer is stored within the content being copied. |
| 58961 | ** |
| 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. */ |
| 58966 | assert( nNew==1 ); |
| 58967 | assert( apNew[0]->nFree == |
| 58968 | (get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2) |
| 58969 | ); |
| 58970 | copyNodeContent(apNew[0], pParent, &rc); |
| 58971 | freePage(apNew[0], &rc); |
| 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 | } |
| 59068 | |
| 59069 | #if 0 |
| 59070 | /* The ptrmapCheckPages() contains assert() statements that verify that |
| 59071 | ** all pointer map pages are set correctly. This is helpful while |
| 59072 | ** debugging. This is usually disabled because a corrupt database may |
| 59073 | ** cause an assert() statement to fail. */ |
| 59074 | ptrmapCheckPages(apNew, nNew); |
| 59075 | ptrmapCheckPages(&pParent, 1); |
| 59076 | #endif |
| 59077 | } |
| 59078 | |
| 59079 | assert( pParent->isInit ); |
| 59080 | TRACE(("BALANCE: finished: old=%d new=%d cells=%d\n", |
| 59081 | nOld, nNew, nCell)); |
| 59082 | |
| 59083 | /* |
| 59084 | ** Cleanup before returning. |
| 59085 | */ |
| 59086 | balance_cleanup: |
| @@ -61470,15 +60902,10 @@ | |
| 60902 | */ |
| 60903 | SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *p){ |
| 60904 | return (p->pBt->btsFlags & BTS_READ_ONLY)!=0; |
| 60905 | } |
| 60906 | |
| 60907 | /************** End of btree.c ***********************************************/ |
| 60908 | /************** Begin file backup.c ******************************************/ |
| 60909 | /* |
| 60910 | ** 2009 January 28 |
| 60911 | ** |
| @@ -61599,24 +61026,10 @@ | |
| 61026 | int rc; |
| 61027 | rc = sqlite3BtreeSetPageSize(p->pDest,sqlite3BtreeGetPageSize(p->pSrc),-1,0); |
| 61028 | return rc; |
| 61029 | } |
| 61030 | |
| 61031 | /* |
| 61032 | ** Create an sqlite3_backup process to copy the contents of zSrcDb from |
| 61033 | ** connection handle pSrcDb to zDestDb in pDestDb. If successful, return |
| 61034 | ** a pointer to the new sqlite3_backup object. |
| 61035 | ** |
| @@ -61629,17 +61042,10 @@ | |
| 61042 | sqlite3* pSrcDb, /* Database connection to read from */ |
| 61043 | const char *zSrcDb /* Name of database within pSrcDb */ |
| 61044 | ){ |
| 61045 | sqlite3_backup *p; /* Value to return */ |
| 61046 | |
| 61047 | /* Lock the source database handle. The destination database |
| 61048 | ** handle is not locked in this routine, but it is locked in |
| 61049 | ** sqlite3_backup_step(). The user is required to ensure that no |
| 61050 | ** other thread accesses the destination handle for the duration |
| 61051 | ** of the backup operation. Any attempt to use the destination |
| @@ -61672,19 +61078,16 @@ | |
| 61078 | p->pDestDb = pDestDb; |
| 61079 | p->pSrcDb = pSrcDb; |
| 61080 | p->iNext = 1; |
| 61081 | p->isAttached = 0; |
| 61082 | |
| 61083 | if( 0==p->pSrc || 0==p->pDest || setDestPgsz(p)==SQLITE_NOMEM ){ |
| 61084 | /* One (or both) of the named databases did not exist or an OOM |
| 61085 | ** error was hit. The error has already been written into the |
| 61086 | ** pDestDb handle. All that is left to do here is free the |
| 61087 | ** sqlite3_backup structure. |
| 61088 | */ |
| 61089 | sqlite3_free(p); |
| 61090 | p = 0; |
| 61091 | } |
| 61092 | } |
| 61093 | if( p ){ |
| @@ -61835,13 +61238,10 @@ | |
| 61238 | int rc; |
| 61239 | int destMode; /* Destination journal mode */ |
| 61240 | int pgszSrc = 0; /* Source page size */ |
| 61241 | int pgszDest = 0; /* Destination page size */ |
| 61242 | |
| 61243 | sqlite3_mutex_enter(p->pSrcDb->mutex); |
| 61244 | sqlite3BtreeEnter(p->pSrc); |
| 61245 | if( p->pDestDb ){ |
| 61246 | sqlite3_mutex_enter(p->pDestDb->mutex); |
| 61247 | } |
| @@ -62127,30 +61527,18 @@ | |
| 61527 | /* |
| 61528 | ** Return the number of pages still to be backed up as of the most recent |
| 61529 | ** call to sqlite3_backup_step(). |
| 61530 | */ |
| 61531 | SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p){ |
| 61532 | return p->nRemaining; |
| 61533 | } |
| 61534 | |
| 61535 | /* |
| 61536 | ** Return the total number of pages in the source database as of the most |
| 61537 | ** recent call to sqlite3_backup_step(). |
| 61538 | */ |
| 61539 | SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p){ |
| 61540 | return p->nPagecount; |
| 61541 | } |
| 61542 | |
| 61543 | /* |
| 61544 | ** This function is called after the contents of page iPage of the |
| @@ -64437,38 +63825,10 @@ | |
| 63825 | } |
| 63826 | p->nOp += nOp; |
| 63827 | } |
| 63828 | return addr; |
| 63829 | } |
| 63830 | |
| 63831 | /* |
| 63832 | ** Change the value of the P1 operand for a specific instruction. |
| 63833 | ** This routine is useful when a large program is loaded from a |
| 63834 | ** static array using sqlite3VdbeAddOpList but we want to make a |
| @@ -65564,13 +64924,10 @@ | |
| 64924 | p->apArg = allocSpace(p->apArg, nArg*sizeof(Mem*), &zCsr, zEnd, &nByte); |
| 64925 | p->azVar = allocSpace(p->azVar, nVar*sizeof(char*), &zCsr, zEnd, &nByte); |
| 64926 | p->apCsr = allocSpace(p->apCsr, nCursor*sizeof(VdbeCursor*), |
| 64927 | &zCsr, zEnd, &nByte); |
| 64928 | p->aOnceFlag = allocSpace(p->aOnceFlag, nOnce, &zCsr, zEnd, &nByte); |
| 64929 | if( nByte ){ |
| 64930 | p->pFree = sqlite3DbMallocZero(db, nByte); |
| 64931 | } |
| 64932 | zCsr = p->pFree; |
| 64933 | zEnd = &zCsr[nByte]; |
| @@ -65634,13 +64991,10 @@ | |
| 64991 | ** is used, for example, when a trigger sub-program is halted to restore |
| 64992 | ** control to the main program. |
| 64993 | */ |
| 64994 | SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){ |
| 64995 | Vdbe *v = pFrame->v; |
| 64996 | v->aOnceFlag = pFrame->aOnceFlag; |
| 64997 | v->nOnceFlag = pFrame->nOnceFlag; |
| 64998 | v->aOp = pFrame->aOp; |
| 64999 | v->nOp = pFrame->nOp; |
| 65000 | v->aMem = pFrame->aMem; |
| @@ -65647,11 +65001,10 @@ | |
| 65001 | v->nMem = pFrame->nMem; |
| 65002 | v->apCsr = pFrame->apCsr; |
| 65003 | v->nCursor = pFrame->nCursor; |
| 65004 | v->db->lastRowid = pFrame->lastRowid; |
| 65005 | v->nChange = pFrame->nChange; |
| 65006 | return pFrame->pc; |
| 65007 | } |
| 65008 | |
| 65009 | /* |
| 65010 | ** Close all cursors. |
| @@ -66215,11 +65568,10 @@ | |
| 65568 | ** so, abort any other statements this handle currently has active. |
| 65569 | */ |
| 65570 | sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); |
| 65571 | sqlite3CloseSavepoints(db); |
| 65572 | db->autoCommit = 1; |
| 65573 | } |
| 65574 | } |
| 65575 | } |
| 65576 | |
| 65577 | /* Check for immediate foreign key violations. */ |
| @@ -66256,20 +65608,18 @@ | |
| 65608 | sqlite3VdbeLeave(p); |
| 65609 | return SQLITE_BUSY; |
| 65610 | }else if( rc!=SQLITE_OK ){ |
| 65611 | p->rc = rc; |
| 65612 | sqlite3RollbackAll(db, SQLITE_OK); |
| 65613 | }else{ |
| 65614 | db->nDeferredCons = 0; |
| 65615 | db->nDeferredImmCons = 0; |
| 65616 | db->flags &= ~SQLITE_DeferFKs; |
| 65617 | sqlite3CommitInternalChanges(db); |
| 65618 | } |
| 65619 | }else{ |
| 65620 | sqlite3RollbackAll(db, SQLITE_OK); |
| 65621 | } |
| 65622 | db->nStatement = 0; |
| 65623 | }else if( eStatementOp==0 ){ |
| 65624 | if( p->rc==SQLITE_OK || p->errorAction==OE_Fail ){ |
| 65625 | eStatementOp = SAVEPOINT_RELEASE; |
| @@ -66277,11 +65627,10 @@ | |
| 65627 | eStatementOp = SAVEPOINT_ROLLBACK; |
| 65628 | }else{ |
| 65629 | sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); |
| 65630 | sqlite3CloseSavepoints(db); |
| 65631 | db->autoCommit = 1; |
| 65632 | } |
| 65633 | } |
| 65634 | |
| 65635 | /* If eStatementOp is non-zero, then a statement transaction needs to |
| 65636 | ** be committed or rolled back. Call sqlite3VdbeCloseStatement() to |
| @@ -66298,11 +65647,10 @@ | |
| 65647 | p->zErrMsg = 0; |
| 65648 | } |
| 65649 | sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); |
| 65650 | sqlite3CloseSavepoints(db); |
| 65651 | db->autoCommit = 1; |
| 65652 | } |
| 65653 | } |
| 65654 | |
| 65655 | /* If this was an INSERT, UPDATE or DELETE and no statement transaction |
| 65656 | ** has been rolled back, update the database connection change-counter. |
| @@ -66560,16 +65908,10 @@ | |
| 65908 | for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]); |
| 65909 | vdbeFreeOpArray(db, p->aOp, p->nOp); |
| 65910 | sqlite3DbFree(db, p->aColName); |
| 65911 | sqlite3DbFree(db, p->zSql); |
| 65912 | sqlite3DbFree(db, p->pFree); |
| 65913 | } |
| 65914 | |
| 65915 | /* |
| 65916 | ** Delete an entire VDBE. |
| 65917 | */ |
| @@ -68933,23 +68275,15 @@ | |
| 68275 | sqlite3_stmt *pStmt, |
| 68276 | int N, |
| 68277 | const void *(*xFunc)(Mem*), |
| 68278 | int useType |
| 68279 | ){ |
| 68280 | const void *ret = 0; |
| 68281 | Vdbe *p = (Vdbe *)pStmt; |
| 68282 | int n; |
| 68283 | sqlite3 *db = p->db; |
| 68284 | |
| 68285 | assert( db!=0 ); |
| 68286 | n = sqlite3_column_count(pStmt); |
| 68287 | if( N<n && N>=0 ){ |
| 68288 | N += useType*n; |
| 68289 | sqlite3_mutex_enter(db->mutex); |
| @@ -69410,16 +68744,10 @@ | |
| 68744 | ** prepared statement for the database connection. Return NULL if there |
| 68745 | ** are no more. |
| 68746 | */ |
| 68747 | SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt){ |
| 68748 | sqlite3_stmt *pNext; |
| 68749 | sqlite3_mutex_enter(pDb->mutex); |
| 68750 | if( pStmt==0 ){ |
| 68751 | pNext = (sqlite3_stmt*)pDb->pVdbe; |
| 68752 | }else{ |
| 68753 | pNext = (sqlite3_stmt*)((Vdbe*)pStmt)->pNext; |
| @@ -69431,91 +68759,15 @@ | |
| 68759 | /* |
| 68760 | ** Return the value of a status counter for a prepared statement |
| 68761 | */ |
| 68762 | SQLITE_API int sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){ |
| 68763 | Vdbe *pVdbe = (Vdbe*)pStmt; |
| 68764 | u32 v = pVdbe->aCounter[op]; |
| 68765 | if( resetFlag ) pVdbe->aCounter[op] = 0; |
| 68766 | return (int)v; |
| 68767 | } |
| 68768 | |
| 68769 | /************** End of vdbeapi.c *********************************************/ |
| 68770 | /************** Begin file vdbetrace.c ***************************************/ |
| 68771 | /* |
| 68772 | ** 2009 November 25 |
| 68773 | ** |
| @@ -70397,13 +69649,10 @@ | |
| 69649 | #ifdef VDBE_PROFILE |
| 69650 | start = sqlite3Hwtime(); |
| 69651 | #endif |
| 69652 | nVmStep++; |
| 69653 | pOp = &aOp[pc]; |
| 69654 | |
| 69655 | /* Only allow tracing if SQLITE_DEBUG is defined. |
| 69656 | */ |
| 69657 | #ifdef SQLITE_DEBUG |
| 69658 | if( db->flags & SQLITE_VdbeTrace ){ |
| @@ -73594,15 +72843,14 @@ | |
| 72843 | } |
| 72844 | pIdxKey = &r; |
| 72845 | }else{ |
| 72846 | pIdxKey = sqlite3VdbeAllocUnpackedRecord( |
| 72847 | pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree |
| 72848 | ); |
| 72849 | if( pIdxKey==0 ) goto no_mem; |
| 72850 | assert( pIn3->flags & MEM_Blob ); |
| 72851 | assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */ |
| 72852 | sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey); |
| 72853 | } |
| 72854 | pIdxKey->default_rc = 0; |
| 72855 | if( pOp->opcode==OP_NoConflict ){ |
| 72856 | /* For the OP_NoConflict opcode, take the jump if any of the |
| @@ -74292,13 +73540,13 @@ | |
| 73540 | } |
| 73541 | /* Opcode: Rewind P1 P2 * * * |
| 73542 | ** |
| 73543 | ** The next use of the Rowid or Column or Next instruction for P1 |
| 73544 | ** will refer to the first entry in the database table or index. |
| 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. |
| 73548 | ** |
| 73549 | ** This opcode leaves the cursor configured to move in forward order, |
| 73550 | ** from the beginning toward the end. In other words, the cursor is |
| 73551 | ** configured to use Next, not Prev. |
| 73552 | */ |
| @@ -75210,13 +74458,10 @@ | |
| 74458 | pFrame->aOp = p->aOp; |
| 74459 | pFrame->nOp = p->nOp; |
| 74460 | pFrame->token = pProgram->token; |
| 74461 | pFrame->aOnceFlag = p->aOnceFlag; |
| 74462 | pFrame->nOnceFlag = p->nOnceFlag; |
| 74463 | |
| 74464 | pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem]; |
| 74465 | for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){ |
| 74466 | pMem->flags = MEM_Undefined; |
| 74467 | pMem->db = db; |
| @@ -75230,11 +74475,10 @@ | |
| 74475 | |
| 74476 | p->nFrame++; |
| 74477 | pFrame->pParent = p->pFrame; |
| 74478 | pFrame->lastRowid = lastRowid; |
| 74479 | pFrame->nChange = p->nChange; |
| 74480 | p->nChange = 0; |
| 74481 | p->pFrame = pFrame; |
| 74482 | p->aMem = aMem = &VdbeFrameMem(pFrame)[-1]; |
| 74483 | p->nMem = pFrame->nChildMem; |
| 74484 | p->nCursor = (u16)pFrame->nChildCsr; |
| @@ -75241,13 +74485,10 @@ | |
| 74485 | p->apCsr = (VdbeCursor **)&aMem[p->nMem+1]; |
| 74486 | p->aOp = aOp = pProgram->aOp; |
| 74487 | p->nOp = pProgram->nOp; |
| 74488 | p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor]; |
| 74489 | p->nOnceFlag = pProgram->nOnce; |
| 74490 | pc = -1; |
| 74491 | memset(p->aOnceFlag, 0, p->nOnceFlag); |
| 74492 | |
| 74493 | break; |
| 74494 | } |
| @@ -76432,15 +75673,10 @@ | |
| 75673 | char *zErr = 0; |
| 75674 | Table *pTab; |
| 75675 | Parse *pParse = 0; |
| 75676 | Incrblob *pBlob = 0; |
| 75677 | |
| 75678 | flags = !!flags; /* flags = (flags ? 1 : 0); */ |
| 75679 | *ppBlob = 0; |
| 75680 | |
| 75681 | sqlite3_mutex_enter(db->mutex); |
| 75682 | |
| @@ -76655,10 +75891,11 @@ | |
| 75891 | v = (Vdbe*)p->pStmt; |
| 75892 | |
| 75893 | if( n<0 || iOffset<0 || (iOffset+n)>p->nByte ){ |
| 75894 | /* Request is out of range. Return a transient error. */ |
| 75895 | rc = SQLITE_ERROR; |
| 75896 | sqlite3Error(db, SQLITE_ERROR); |
| 75897 | }else if( v==0 ){ |
| 75898 | /* If there is no statement handle, then the blob-handle has |
| 75899 | ** already been invalidated. Return SQLITE_ABORT in this case. |
| 75900 | */ |
| 75901 | rc = SQLITE_ABORT; |
| @@ -76672,14 +75909,14 @@ | |
| 75909 | sqlite3BtreeLeaveCursor(p->pCsr); |
| 75910 | if( rc==SQLITE_ABORT ){ |
| 75911 | sqlite3VdbeFinalize(v); |
| 75912 | p->pStmt = 0; |
| 75913 | }else{ |
| 75914 | db->errCode = rc; |
| 75915 | v->rc = rc; |
| 75916 | } |
| 75917 | } |
| 75918 | rc = sqlite3ApiExit(db, rc); |
| 75919 | sqlite3_mutex_leave(db->mutex); |
| 75920 | return rc; |
| 75921 | } |
| 75922 | |
| @@ -76852,11 +76089,11 @@ | |
| 76089 | ** itself. |
| 76090 | ** |
| 76091 | ** The sorter is running in multi-threaded mode if (a) the library was built |
| 76092 | ** with pre-processor symbol SQLITE_MAX_WORKER_THREADS set to a value greater |
| 76093 | ** than zero, and (b) worker threads have been enabled at runtime by calling |
| 76094 | ** sqlite3_config(SQLITE_CONFIG_WORKER_THREADS, ...). |
| 76095 | ** |
| 76096 | ** When Rewind() is called, any data remaining in memory is flushed to a |
| 76097 | ** final PMA. So at this point the data is stored in some number of sorted |
| 76098 | ** PMAs within temporary files on disk. |
| 76099 | ** |
| @@ -77597,13 +76834,15 @@ | |
| 76834 | pSorter->mnPmaSize = SORTER_MIN_WORKING * pgsz; |
| 76835 | mxCache = db->aDb[0].pSchema->cache_size; |
| 76836 | if( mxCache<SORTER_MIN_WORKING ) mxCache = SORTER_MIN_WORKING; |
| 76837 | pSorter->mxPmaSize = mxCache * pgsz; |
| 76838 | |
| 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. |
| 76844 | */ |
| 76845 | if( sqlite3GlobalConfig.pScratch==0 ){ |
| 76846 | assert( pSorter->iMemory==0 ); |
| 76847 | pSorter->nMemory = pgsz; |
| 76848 | pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz); |
| @@ -79971,19 +79210,19 @@ | |
| 79210 | ** |
| 79211 | ** incrAggFunctionDepth(pExpr,n) is the main routine. incrAggDepth(..) |
| 79212 | ** is a helper function - a callback for the tree walker. |
| 79213 | */ |
| 79214 | static int incrAggDepth(Walker *pWalker, Expr *pExpr){ |
| 79215 | if( pExpr->op==TK_AGG_FUNCTION ) pExpr->op2 += pWalker->u.i; |
| 79216 | return WRC_Continue; |
| 79217 | } |
| 79218 | static void incrAggFunctionDepth(Expr *pExpr, int N){ |
| 79219 | if( N>0 ){ |
| 79220 | Walker w; |
| 79221 | memset(&w, 0, sizeof(w)); |
| 79222 | w.xExprCallback = incrAggDepth; |
| 79223 | w.u.i = N; |
| 79224 | sqlite3WalkExpr(&w, pExpr); |
| 79225 | } |
| 79226 | } |
| 79227 | |
| 79228 | /* |
| @@ -80527,11 +79766,11 @@ | |
| 79766 | double r = -1.0; |
| 79767 | if( p->op!=TK_FLOAT ) return -1; |
| 79768 | sqlite3AtoF(p->u.zToken, &r, sqlite3Strlen30(p->u.zToken), SQLITE_UTF8); |
| 79769 | assert( r>=0.0 ); |
| 79770 | if( r>1.0 ) return -1; |
| 79771 | return (int)(r*1000.0); |
| 79772 | } |
| 79773 | |
| 79774 | /* |
| 79775 | ** This routine is callback for sqlite3WalkExpr(). |
| 79776 | ** |
| @@ -80659,11 +79898,11 @@ | |
| 79898 | ** EVIDENCE-OF: R-36850-34127 The likely(X) function is short-hand for |
| 79899 | ** likelihood(X,0.9375). |
| 79900 | ** EVIDENCE-OF: R-53436-40973 The likely(X) function is equivalent to |
| 79901 | ** likelihood(X,0.9375). */ |
| 79902 | /* TUNING: unlikely() probability is 0.0625. likely() is 0.9375 */ |
| 79903 | pExpr->iTable = pDef->zName[0]=='u' ? 62 : 938; |
| 79904 | } |
| 79905 | } |
| 79906 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 79907 | auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0); |
| 79908 | if( auth!=SQLITE_OK ){ |
| @@ -82616,79 +81855,69 @@ | |
| 81855 | sqlite3DbFree(db, pList->a); |
| 81856 | sqlite3DbFree(db, pList); |
| 81857 | } |
| 81858 | |
| 81859 | /* |
| 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. |
| 81864 | ** |
| 81865 | ** These callback routines are used to implement the following: |
| 81866 | ** |
| 81867 | ** sqlite3ExprIsConstant() pWalker->u.i==1 |
| 81868 | ** sqlite3ExprIsConstantNotJoin() pWalker->u.i==2 |
| 81869 | ** sqlite3ExprIsConstantOrFunction() pWalker->u.i==3 or 4 |
| 81870 | ** |
| 81871 | ** The sqlite3ExprIsConstantOrFunction() is used for evaluating expressions |
| 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 |
| 81874 | ** parameter raises an error for new statements, but is silently converted |
| 81875 | ** to NULL for existing schemas. This allows sqlite_master tables that |
| 81876 | ** contain a bound parameter because they were generated by older versions |
| 81877 | ** of SQLite to be parsed by newer versions of SQLite without raising a |
| 81878 | ** malformed schema error. |
| 81879 | */ |
| 81880 | static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){ |
| 81881 | |
| 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 |
| 81884 | ** from being considered constant. */ |
| 81885 | if( pWalker->u.i==2 && ExprHasProperty(pExpr, EP_FromJoin) ){ |
| 81886 | pWalker->u.i = 0; |
| 81887 | return WRC_Abort; |
| 81888 | } |
| 81889 | |
| 81890 | switch( pExpr->op ){ |
| 81891 | /* Consider functions to be constant if all their arguments are constant |
| 81892 | ** and either pWalker->u.i==3 or 4 or the function as the SQLITE_FUNC_CONST |
| 81893 | ** flag. */ |
| 81894 | case TK_FUNCTION: |
| 81895 | if( pWalker->u.i>=3 || ExprHasProperty(pExpr,EP_Constant) ){ |
| 81896 | return WRC_Continue; |
| 81897 | } |
| 81898 | /* Fall through */ |
| 81899 | case TK_ID: |
| 81900 | case TK_COLUMN: |
| 81901 | case TK_AGG_FUNCTION: |
| 81902 | case TK_AGG_COLUMN: |
| 81903 | testcase( pExpr->op==TK_ID ); |
| 81904 | testcase( pExpr->op==TK_COLUMN ); |
| 81905 | testcase( pExpr->op==TK_AGG_FUNCTION ); |
| 81906 | testcase( pExpr->op==TK_AGG_COLUMN ); |
| 81907 | pWalker->u.i = 0; |
| 81908 | return WRC_Abort; |
| 81909 | case TK_VARIABLE: |
| 81910 | if( pWalker->u.i==4 ){ |
| 81911 | /* Silently convert bound parameters that appear inside of CREATE |
| 81912 | ** statements into a NULL when parsing the CREATE statement text out |
| 81913 | ** of the sqlite_master table */ |
| 81914 | pExpr->op = TK_NULL; |
| 81915 | }else if( pWalker->u.i==3 ){ |
| 81916 | /* A bound parameter in a CREATE statement that originates from |
| 81917 | ** sqlite3_prepare() causes an error */ |
| 81918 | pWalker->u.i = 0; |
| 81919 | return WRC_Abort; |
| 81920 | } |
| 81921 | /* Fall through */ |
| 81922 | default: |
| 81923 | testcase( pExpr->op==TK_SELECT ); /* selectNodeIsConstant will disallow */ |
| @@ -82696,68 +81925,57 @@ | |
| 81925 | return WRC_Continue; |
| 81926 | } |
| 81927 | } |
| 81928 | static int selectNodeIsConstant(Walker *pWalker, Select *NotUsed){ |
| 81929 | UNUSED_PARAMETER(NotUsed); |
| 81930 | pWalker->u.i = 0; |
| 81931 | return WRC_Abort; |
| 81932 | } |
| 81933 | static int exprIsConst(Expr *p, int initFlag){ |
| 81934 | Walker w; |
| 81935 | memset(&w, 0, sizeof(w)); |
| 81936 | w.u.i = initFlag; |
| 81937 | w.xExprCallback = exprNodeIsConstant; |
| 81938 | w.xSelectCallback = selectNodeIsConstant; |
| 81939 | sqlite3WalkExpr(&w, p); |
| 81940 | return w.u.i; |
| 81941 | } |
| 81942 | |
| 81943 | /* |
| 81944 | ** Walk an expression tree. Return 1 if the expression is constant |
| 81945 | ** and 0 if it involves variables or function calls. |
| 81946 | ** |
| 81947 | ** For the purposes of this function, a double-quoted string (ex: "abc") |
| 81948 | ** is considered a variable but a single-quoted string (ex: 'abc') is |
| 81949 | ** a constant. |
| 81950 | */ |
| 81951 | SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr *p){ |
| 81952 | return exprIsConst(p, 1); |
| 81953 | } |
| 81954 | |
| 81955 | /* |
| 81956 | ** Walk an expression tree. Return 1 if the expression is constant |
| 81957 | ** that does no originate from the ON or USING clauses of a join. |
| 81958 | ** Return 0 if it involves variables or function calls or terms from |
| 81959 | ** an ON or USING clause. |
| 81960 | */ |
| 81961 | SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr *p){ |
| 81962 | return exprIsConst(p, 2); |
| 81963 | } |
| 81964 | |
| 81965 | /* |
| 81966 | ** Walk an expression tree. Return 1 if the expression is constant |
| 81967 | ** or a function call with constant arguments. Return and 0 if there |
| 81968 | ** are any variables. |
| 81969 | ** |
| 81970 | ** For the purposes of this function, a double-quoted string (ex: "abc") |
| 81971 | ** is considered a variable but a single-quoted string (ex: 'abc') is |
| 81972 | ** a constant. |
| 81973 | */ |
| 81974 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr *p, u8 isInit){ |
| 81975 | assert( isInit==0 || isInit==1 ); |
| 81976 | return exprIsConst(p, 3+isInit); |
| 81977 | } |
| 81978 | |
| 81979 | /* |
| 81980 | ** If the expression p codes a constant integer that is small enough |
| 81981 | ** to fit in a 32-bit integer, return 1 and put the value of the integer |
| @@ -88070,12 +87288,10 @@ | |
| 87288 | while( z[0] ){ |
| 87289 | if( sqlite3_strglob("unordered*", z)==0 ){ |
| 87290 | pIndex->bUnordered = 1; |
| 87291 | }else if( sqlite3_strglob("sz=[0-9]*", z)==0 ){ |
| 87292 | pIndex->szIdxRow = sqlite3LogEst(sqlite3Atoi(z+3)); |
| 87293 | } |
| 87294 | #ifdef SQLITE_ENABLE_COSTMULT |
| 87295 | else if( sqlite3_strglob("costmult=[0-9]*",z)==0 ){ |
| 87296 | pIndex->pTable->costMult = sqlite3LogEst(sqlite3Atoi(z+9)); |
| 87297 | } |
| @@ -88205,11 +87421,10 @@ | |
| 87421 | nSample--; |
| 87422 | }else{ |
| 87423 | nRow = pIdx->aiRowEst[0]; |
| 87424 | nDist100 = ((i64)100 * pIdx->aiRowEst[0]) / pIdx->aiRowEst[iCol+1]; |
| 87425 | } |
| 87426 | |
| 87427 | /* Set nSum to the number of distinct (iCol+1) field prefixes that |
| 87428 | ** occur in the stat4 table for this index. Set sumEq to the sum of |
| 87429 | ** the nEq values for column iCol for the same set (adding the value |
| 87430 | ** only once where there exist duplicate prefixes). */ |
| @@ -88467,11 +87682,11 @@ | |
| 87682 | } |
| 87683 | |
| 87684 | |
| 87685 | /* Load the statistics from the sqlite_stat4 table. */ |
| 87686 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 87687 | if( rc==SQLITE_OK ){ |
| 87688 | int lookasideEnabled = db->lookaside.bEnabled; |
| 87689 | db->lookaside.bEnabled = 0; |
| 87690 | rc = loadStat4(db, sInfo.zDatabase); |
| 87691 | db->lookaside.bEnabled = lookasideEnabled; |
| 87692 | } |
| @@ -89149,13 +88364,10 @@ | |
| 88364 | SQLITE_API int sqlite3_set_authorizer( |
| 88365 | sqlite3 *db, |
| 88366 | int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), |
| 88367 | void *pArg |
| 88368 | ){ |
| 88369 | sqlite3_mutex_enter(db->mutex); |
| 88370 | db->xAuth = (sqlite3_xauth)xAuth; |
| 88371 | db->pAuthArg = pArg; |
| 88372 | sqlite3ExpirePreparedStatements(db); |
| 88373 | sqlite3_mutex_leave(db->mutex); |
| @@ -89646,15 +88858,11 @@ | |
| 88858 | ** See also sqlite3LocateTable(). |
| 88859 | */ |
| 88860 | SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){ |
| 88861 | Table *p = 0; |
| 88862 | int i; |
| 88863 | assert( zName!=0 ); |
| 88864 | /* All mutexes are required for schema access. Make sure we hold them. */ |
| 88865 | assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) ); |
| 88866 | #if SQLITE_USER_AUTHENTICATION |
| 88867 | /* Only the admin user is allowed to know that the sqlite_user table |
| 88868 | ** exists */ |
| @@ -104673,16 +103881,13 @@ | |
| 103881 | Vdbe *pOld, /* VM being reprepared */ |
| 103882 | sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */ |
| 103883 | const char **pzTail /* OUT: End of parsed string */ |
| 103884 | ){ |
| 103885 | int rc; |
| 103886 | assert( ppStmt!=0 ); |
| 103887 | *ppStmt = 0; |
| 103888 | if( !sqlite3SafetyCheckOk(db) ){ |
| 103889 | return SQLITE_MISUSE_BKPT; |
| 103890 | } |
| 103891 | sqlite3_mutex_enter(db->mutex); |
| 103892 | sqlite3BtreeEnterAll(db); |
| 103893 | rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail); |
| @@ -104785,15 +103990,13 @@ | |
| 103990 | */ |
| 103991 | char *zSql8; |
| 103992 | const char *zTail8 = 0; |
| 103993 | int rc = SQLITE_OK; |
| 103994 | |
| 103995 | assert( ppStmt ); |
| 103996 | *ppStmt = 0; |
| 103997 | if( !sqlite3SafetyCheckOk(db) ){ |
| 103998 | return SQLITE_MISUSE_BKPT; |
| 103999 | } |
| 104000 | if( nBytes>=0 ){ |
| 104001 | int sz; |
| 104002 | const char *z = (const char*)zSql; |
| @@ -110502,13 +109705,10 @@ | |
| 109705 | char **pzErrMsg /* Write error messages here */ |
| 109706 | ){ |
| 109707 | int rc; |
| 109708 | TabResult res; |
| 109709 | |
| 109710 | *pazResult = 0; |
| 109711 | if( pnColumn ) *pnColumn = 0; |
| 109712 | if( pnRow ) *pnRow = 0; |
| 109713 | if( pzErrMsg ) *pzErrMsg = 0; |
| 109714 | res.zErrMsg = 0; |
| @@ -112568,11 +111768,11 @@ | |
| 111768 | ** Two writes per page are required in step (3) because the original |
| 111769 | ** database content must be written into the rollback journal prior to |
| 111770 | ** overwriting the database with the vacuumed content. |
| 111771 | ** |
| 111772 | ** Only 1x temporary space and only 1x writes would be required if |
| 111773 | ** the copy of step (3) were replace by deleting the original database |
| 111774 | ** and renaming the transient database as the original. But that will |
| 111775 | ** not work if other processes are attached to the original database. |
| 111776 | ** And a power loss in between deleting the original and renaming the |
| 111777 | ** transient would cause the database file to appear to be deleted |
| 111778 | ** following reboot. |
| @@ -112926,13 +112126,10 @@ | |
| 112126 | sqlite3 *db, /* Database in which module is registered */ |
| 112127 | const char *zName, /* Name assigned to this module */ |
| 112128 | const sqlite3_module *pModule, /* The definition of the module */ |
| 112129 | void *pAux /* Context pointer for xCreate/xConnect */ |
| 112130 | ){ |
| 112131 | return createModule(db, zName, pModule, pAux, 0); |
| 112132 | } |
| 112133 | |
| 112134 | /* |
| 112135 | ** External API function used to create a new virtual-table module. |
| @@ -112942,13 +112139,10 @@ | |
| 112139 | const char *zName, /* Name assigned to this module */ |
| 112140 | const sqlite3_module *pModule, /* The definition of the module */ |
| 112141 | void *pAux, /* Context pointer for xCreate/xConnect */ |
| 112142 | void (*xDestroy)(void *) /* Module destructor function */ |
| 112143 | ){ |
| 112144 | return createModule(db, zName, pModule, pAux, xDestroy); |
| 112145 | } |
| 112146 | |
| 112147 | /* |
| 112148 | ** Lock the virtual table so that it cannot be disconnected. |
| @@ -113549,13 +112743,10 @@ | |
| 112743 | |
| 112744 | int rc = SQLITE_OK; |
| 112745 | Table *pTab; |
| 112746 | char *zErr = 0; |
| 112747 | |
| 112748 | sqlite3_mutex_enter(db->mutex); |
| 112749 | if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){ |
| 112750 | sqlite3Error(db, SQLITE_MISUSE); |
| 112751 | sqlite3_mutex_leave(db->mutex); |
| 112752 | return SQLITE_MISUSE_BKPT; |
| @@ -113908,13 +113099,10 @@ | |
| 113099 | */ |
| 113100 | SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *db){ |
| 113101 | static const unsigned char aMap[] = { |
| 113102 | SQLITE_ROLLBACK, SQLITE_ABORT, SQLITE_FAIL, SQLITE_IGNORE, SQLITE_REPLACE |
| 113103 | }; |
| 113104 | assert( OE_Rollback==1 && OE_Abort==2 && OE_Fail==3 ); |
| 113105 | assert( OE_Ignore==4 && OE_Replace==5 ); |
| 113106 | assert( db->vtabOnConflict>=1 && db->vtabOnConflict<=5 ); |
| 113107 | return (int)aMap[db->vtabOnConflict-1]; |
| 113108 | } |
| @@ -113926,14 +113114,12 @@ | |
| 113114 | */ |
| 113115 | SQLITE_API int sqlite3_vtab_config(sqlite3 *db, int op, ...){ |
| 113116 | va_list ap; |
| 113117 | int rc = SQLITE_OK; |
| 113118 | |
| 113119 | sqlite3_mutex_enter(db->mutex); |
| 113120 | |
| 113121 | va_start(ap, op); |
| 113122 | switch( op ){ |
| 113123 | case SQLITE_VTAB_CONSTRAINT_SUPPORT: { |
| 113124 | VtabCtx *p = db->pVtabCtx; |
| 113125 | if( !p ){ |
| @@ -114064,13 +113250,10 @@ | |
| 113250 | } in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */ |
| 113251 | Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */ |
| 113252 | } u; |
| 113253 | struct WhereLoop *pWLoop; /* The selected WhereLoop object */ |
| 113254 | Bitmask notReady; /* FROM entries not usable at this level */ |
| 113255 | }; |
| 113256 | |
| 113257 | /* |
| 113258 | ** Each instance of this object represents an algorithm for evaluating one |
| 113259 | ** term of a join. Every term of the FROM clause will have at least |
| @@ -114097,10 +113280,11 @@ | |
| 113280 | LogEst rRun; /* Cost of running each loop */ |
| 113281 | LogEst nOut; /* Estimated number of output rows */ |
| 113282 | union { |
| 113283 | struct { /* Information for internal btree tables */ |
| 113284 | u16 nEq; /* Number of equality constraints */ |
| 113285 | u16 nSkip; /* Number of initial index columns to skip */ |
| 113286 | Index *pIndex; /* Index used, or NULL */ |
| 113287 | } btree; |
| 113288 | struct { /* Information for virtual tables */ |
| 113289 | int idxNum; /* Index number */ |
| 113290 | u8 needFree; /* True if sqlite3_free(idxStr) is needed */ |
| @@ -114109,17 +113293,16 @@ | |
| 113293 | char *idxStr; /* Index identifier string */ |
| 113294 | } vtab; |
| 113295 | } u; |
| 113296 | u32 wsFlags; /* WHERE_* flags describing the plan */ |
| 113297 | u16 nLTerm; /* Number of entries in aLTerm[] */ |
| 113298 | /**** whereLoopXfer() copies fields above ***********************/ |
| 113299 | # define WHERE_LOOP_XFER_SZ offsetof(WhereLoop,nLSlot) |
| 113300 | u16 nLSlot; /* Number of slots allocated for aLTerm[] */ |
| 113301 | WhereTerm **aLTerm; /* WhereTerms used */ |
| 113302 | WhereLoop *pNextLoop; /* Next WhereLoop object in the WhereClause */ |
| 113303 | WhereTerm *aLTermSpace[4]; /* Initial aLTerm[] space */ |
| 113304 | }; |
| 113305 | |
| 113306 | /* This object holds the prerequisites and the cost of running a |
| 113307 | ** subquery on one operand of an OR operator in the WHERE clause. |
| 113308 | ** See WhereOrSet for additional information |
| @@ -114441,11 +113624,10 @@ | |
| 113624 | #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */ |
| 113625 | #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */ |
| 113626 | #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */ |
| 113627 | #define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */ |
| 113628 | #define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/ |
| 113629 | |
| 113630 | /************** End of whereInt.h ********************************************/ |
| 113631 | /************** Continuing where we left off in where.c **********************/ |
| 113632 | |
| 113633 | /* |
| @@ -114652,11 +113834,11 @@ | |
| 113834 | } |
| 113835 | pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]); |
| 113836 | } |
| 113837 | pTerm = &pWC->a[idx = pWC->nTerm++]; |
| 113838 | if( p && ExprHasProperty(p, EP_Unlikely) ){ |
| 113839 | pTerm->truthProb = sqlite3LogEst(p->iTable) - 99; |
| 113840 | }else{ |
| 113841 | pTerm->truthProb = 1; |
| 113842 | } |
| 113843 | pTerm->pExpr = sqlite3ExprSkipCollate(p); |
| 113844 | pTerm->wtFlags = wtFlags; |
| @@ -115183,19 +114365,10 @@ | |
| 114365 | pDerived->flags |= pBase->flags & EP_FromJoin; |
| 114366 | pDerived->iRightJoinTable = pBase->iRightJoinTable; |
| 114367 | } |
| 114368 | } |
| 114369 | |
| 114370 | #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY) |
| 114371 | /* |
| 114372 | ** Analyze a term that consists of two or more OR-connected |
| 114373 | ** subterms. So in: |
| 114374 | ** |
| @@ -115489,11 +114662,12 @@ | |
| 114662 | pNew->x.pList = pList; |
| 114663 | idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC); |
| 114664 | testcase( idxNew==0 ); |
| 114665 | exprAnalyze(pSrc, pWC, idxNew); |
| 114666 | pTerm = &pWC->a[idxTerm]; |
| 114667 | pWC->a[idxNew].iParent = idxTerm; |
| 114668 | pTerm->nChild = 1; |
| 114669 | }else{ |
| 114670 | sqlite3ExprListDelete(db, pList); |
| 114671 | } |
| 114672 | pTerm->eOperator = WO_NOOP; /* case 1 trumps case 2 */ |
| 114673 | } |
| @@ -115591,12 +114765,13 @@ | |
| 114765 | return; |
| 114766 | } |
| 114767 | idxNew = whereClauseInsert(pWC, pDup, TERM_VIRTUAL|TERM_DYNAMIC); |
| 114768 | if( idxNew==0 ) return; |
| 114769 | pNew = &pWC->a[idxNew]; |
| 114770 | pNew->iParent = idxTerm; |
| 114771 | pTerm = &pWC->a[idxTerm]; |
| 114772 | pTerm->nChild = 1; |
| 114773 | pTerm->wtFlags |= TERM_COPIED; |
| 114774 | if( pExpr->op==TK_EQ |
| 114775 | && !ExprHasProperty(pExpr, EP_FromJoin) |
| 114776 | && OptimizationEnabled(db, SQLITE_Transitive) |
| 114777 | ){ |
| @@ -115649,12 +114824,13 @@ | |
| 114824 | transferJoinMarkings(pNewExpr, pExpr); |
| 114825 | idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC); |
| 114826 | testcase( idxNew==0 ); |
| 114827 | exprAnalyze(pSrc, pWC, idxNew); |
| 114828 | pTerm = &pWC->a[idxTerm]; |
| 114829 | pWC->a[idxNew].iParent = idxTerm; |
| 114830 | } |
| 114831 | pTerm->nChild = 2; |
| 114832 | } |
| 114833 | #endif /* SQLITE_OMIT_BETWEEN_OPTIMIZATION */ |
| 114834 | |
| 114835 | #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY) |
| 114836 | /* Analyze a term that is composed of two or more subterms connected by |
| @@ -115725,12 +114901,13 @@ | |
| 114901 | idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC); |
| 114902 | testcase( idxNew2==0 ); |
| 114903 | exprAnalyze(pSrc, pWC, idxNew2); |
| 114904 | pTerm = &pWC->a[idxTerm]; |
| 114905 | if( isComplete ){ |
| 114906 | pWC->a[idxNew1].iParent = idxTerm; |
| 114907 | pWC->a[idxNew2].iParent = idxTerm; |
| 114908 | pTerm->nChild = 2; |
| 114909 | } |
| 114910 | } |
| 114911 | #endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */ |
| 114912 | |
| 114913 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| @@ -115759,12 +114936,13 @@ | |
| 114936 | pNewTerm = &pWC->a[idxNew]; |
| 114937 | pNewTerm->prereqRight = prereqExpr; |
| 114938 | pNewTerm->leftCursor = pLeft->iTable; |
| 114939 | pNewTerm->u.leftColumn = pLeft->iColumn; |
| 114940 | pNewTerm->eOperator = WO_MATCH; |
| 114941 | pNewTerm->iParent = idxTerm; |
| 114942 | pTerm = &pWC->a[idxTerm]; |
| 114943 | pTerm->nChild = 1; |
| 114944 | pTerm->wtFlags |= TERM_COPIED; |
| 114945 | pNewTerm->prereqAll = pTerm->prereqAll; |
| 114946 | } |
| 114947 | } |
| 114948 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| @@ -115781,11 +114959,11 @@ | |
| 114959 | ** the start of the loop will prevent any results from being returned. |
| 114960 | */ |
| 114961 | if( pExpr->op==TK_NOTNULL |
| 114962 | && pExpr->pLeft->op==TK_COLUMN |
| 114963 | && pExpr->pLeft->iColumn>=0 |
| 114964 | && OptimizationEnabled(db, SQLITE_Stat3) |
| 114965 | ){ |
| 114966 | Expr *pNewExpr; |
| 114967 | Expr *pLeft = pExpr->pLeft; |
| 114968 | int idxNew; |
| 114969 | WhereTerm *pNewTerm; |
| @@ -115800,12 +114978,13 @@ | |
| 114978 | pNewTerm = &pWC->a[idxNew]; |
| 114979 | pNewTerm->prereqRight = 0; |
| 114980 | pNewTerm->leftCursor = pLeft->iTable; |
| 114981 | pNewTerm->u.leftColumn = pLeft->iColumn; |
| 114982 | pNewTerm->eOperator = WO_GT; |
| 114983 | pNewTerm->iParent = idxTerm; |
| 114984 | pTerm = &pWC->a[idxTerm]; |
| 114985 | pTerm->nChild = 1; |
| 114986 | pTerm->wtFlags |= TERM_COPIED; |
| 114987 | pNewTerm->prereqAll = pTerm->prereqAll; |
| 114988 | } |
| 114989 | } |
| 114990 | #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */ |
| @@ -116021,12 +115200,10 @@ | |
| 115200 | WhereLoop *pLoop; /* The Loop object */ |
| 115201 | char *zNotUsed; /* Extra space on the end of pIdx */ |
| 115202 | Bitmask idxCols; /* Bitmap of columns used for indexing */ |
| 115203 | Bitmask extraCols; /* Bitmap of additional columns */ |
| 115204 | u8 sentWarning = 0; /* True if a warnning has been issued */ |
| 115205 | |
| 115206 | /* Generate code to skip over the creation and initialization of the |
| 115207 | ** transient index on 2nd and subsequent iterations of the loop. */ |
| 115208 | v = pParse->pVdbe; |
| 115209 | assert( v!=0 ); |
| @@ -116038,16 +115215,10 @@ | |
| 115215 | pTable = pSrc->pTab; |
| 115216 | pWCEnd = &pWC->a[pWC->nTerm]; |
| 115217 | pLoop = pLevel->pWLoop; |
| 115218 | idxCols = 0; |
| 115219 | for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){ |
| 115220 | if( termCanDriveIndex(pTerm, pSrc, notReady) ){ |
| 115221 | int iCol = pTerm->u.leftColumn; |
| 115222 | Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol); |
| 115223 | testcase( iCol==BMS ); |
| 115224 | testcase( iCol==BMS-1 ); |
| @@ -116056,13 +115227,11 @@ | |
| 115227 | "automatic index on %s(%s)", pTable->zName, |
| 115228 | pTable->aCol[iCol].zName); |
| 115229 | sentWarning = 1; |
| 115230 | } |
| 115231 | if( (idxCols & cMask)==0 ){ |
| 115232 | if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ) return; |
| 115233 | pLoop->aLTerm[nKeyCol++] = pTerm; |
| 115234 | idxCols |= cMask; |
| 115235 | } |
| 115236 | } |
| 115237 | } |
| @@ -116078,23 +115247,24 @@ | |
| 115247 | ** be a covering index because the index will not be updated if the |
| 115248 | ** original table changes and the index and table cannot both be used |
| 115249 | ** if they go out of sync. |
| 115250 | */ |
| 115251 | extraCols = pSrc->colUsed & (~idxCols | MASKBIT(BMS-1)); |
| 115252 | mxBitCol = (pTable->nCol >= BMS-1) ? BMS-1 : pTable->nCol; |
| 115253 | testcase( pTable->nCol==BMS-1 ); |
| 115254 | testcase( pTable->nCol==BMS-2 ); |
| 115255 | for(i=0; i<mxBitCol; i++){ |
| 115256 | if( extraCols & MASKBIT(i) ) nKeyCol++; |
| 115257 | } |
| 115258 | if( pSrc->colUsed & MASKBIT(BMS-1) ){ |
| 115259 | nKeyCol += pTable->nCol - BMS + 1; |
| 115260 | } |
| 115261 | pLoop->wsFlags |= WHERE_COLUMN_EQ | WHERE_IDX_ONLY; |
| 115262 | |
| 115263 | /* Construct the Index object to describe this index */ |
| 115264 | pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+1, 0, &zNotUsed); |
| 115265 | if( pIdx==0 ) return; |
| 115266 | pLoop->u.btree.pIndex = pIdx; |
| 115267 | pIdx->zName = "auto-index"; |
| 115268 | pIdx->pTable = pTable; |
| 115269 | n = 0; |
| 115270 | idxCols = 0; |
| @@ -116142,33 +115312,22 @@ | |
| 115312 | sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1); |
| 115313 | sqlite3VdbeSetP4KeyInfo(pParse, pIdx); |
| 115314 | VdbeComment((v, "for %s", pTable->zName)); |
| 115315 | |
| 115316 | /* Fill the automatic index with content */ |
| 115317 | addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v); |
| 115318 | regRecord = sqlite3GetTempReg(pParse); |
| 115319 | sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0); |
| 115320 | sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord); |
| 115321 | sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); |
| 115322 | sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v); |
| 115323 | sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX); |
| 115324 | sqlite3VdbeJumpHere(v, addrTop); |
| 115325 | sqlite3ReleaseTempReg(pParse, regRecord); |
| 115326 | |
| 115327 | /* Jump here when skipping the initialization */ |
| 115328 | sqlite3VdbeJumpHere(v, addrInit); |
| 115329 | } |
| 115330 | #endif /* SQLITE_OMIT_AUTOMATIC_INDEX */ |
| 115331 | |
| 115332 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 115333 | /* |
| @@ -116323,23 +115482,23 @@ | |
| 115482 | } |
| 115483 | |
| 115484 | return pParse->nErr; |
| 115485 | } |
| 115486 | #endif /* !defined(SQLITE_OMIT_VIRTUALTABLE) */ |
| 115487 | |
| 115488 | |
| 115489 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 115490 | /* |
| 115491 | ** Estimate the location of a particular key among all keys in an |
| 115492 | ** index. Store the results in aStat as follows: |
| 115493 | ** |
| 115494 | ** aStat[0] Est. number of rows less than pVal |
| 115495 | ** aStat[1] Est. number of rows equal to pVal |
| 115496 | ** |
| 115497 | ** Return SQLITE_OK on success. |
| 115498 | */ |
| 115499 | static void whereKeyStats( |
| 115500 | Parse *pParse, /* Database connection */ |
| 115501 | Index *pIdx, /* Index to consider domain of */ |
| 115502 | UnpackedRecord *pRec, /* Vector of values to consider */ |
| 115503 | int roundUp, /* Round up if true. Round down if false */ |
| 115504 | tRowcnt *aStat /* OUT: stats written here */ |
| @@ -116417,11 +115576,10 @@ | |
| 115576 | }else{ |
| 115577 | iGap = iGap/3; |
| 115578 | } |
| 115579 | aStat[0] = iLower + iGap; |
| 115580 | } |
| 115581 | } |
| 115582 | #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */ |
| 115583 | |
| 115584 | /* |
| 115585 | ** If it is not NULL, pTerm is a term that provides an upper or lower |
| @@ -116568,11 +115726,11 @@ | |
| 115726 | ** pLower pUpper |
| 115727 | ** |
| 115728 | ** If either of the upper or lower bound is not present, then NULL is passed in |
| 115729 | ** place of the corresponding WhereTerm. |
| 115730 | ** |
| 115731 | ** The value in (pBuilder->pNew->u.btree.nEq) is the index of the index |
| 115732 | ** column subject to the range constraint. Or, equivalently, the number of |
| 115733 | ** equality constraints optimized by the proposed index scan. For example, |
| 115734 | ** assuming index p is on t1(a, b), and the SQL query is: |
| 115735 | ** |
| 115736 | ** ... FROM t1 WHERE a = ? AND b > ? AND b < ? ... |
| @@ -116584,11 +115742,11 @@ | |
| 115742 | ** |
| 115743 | ** then nEq is set to 0. |
| 115744 | ** |
| 115745 | ** When this function is called, *pnOut is set to the sqlite3LogEst() of the |
| 115746 | ** number of rows that the index scan is expected to visit without |
| 115747 | ** considering the range constraints. If nEq is 0, this is the number of |
| 115748 | ** rows in the index. Assuming no error occurs, *pnOut is adjusted (reduced) |
| 115749 | ** to account for the range constraints pLower and pUpper. |
| 115750 | ** |
| 115751 | ** In the absence of sqlite_stat4 ANALYZE data, or if such data cannot be |
| 115752 | ** used, a single range inequality reduces the search space by a factor of 4. |
| @@ -116608,11 +115766,14 @@ | |
| 115766 | |
| 115767 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 115768 | Index *p = pLoop->u.btree.pIndex; |
| 115769 | int nEq = pLoop->u.btree.nEq; |
| 115770 | |
| 115771 | if( p->nSample>0 |
| 115772 | && nEq<p->nSampleCol |
| 115773 | && OptimizationEnabled(pParse->db, SQLITE_Stat3) |
| 115774 | ){ |
| 115775 | if( nEq==pBuilder->nRecValid ){ |
| 115776 | UnpackedRecord *pRec = pBuilder->pRec; |
| 115777 | tRowcnt a[2]; |
| 115778 | u8 aff; |
| 115779 | |
| @@ -116624,23 +115785,19 @@ | |
| 115785 | ** |
| 115786 | ** Or, if pLower is NULL or $L cannot be extracted from it (because it |
| 115787 | ** is not a simple variable or literal value), the lower bound of the |
| 115788 | ** range is $P. Due to a quirk in the way whereKeyStats() works, even |
| 115789 | ** if $L is available, whereKeyStats() is called for both ($P) and |
| 115790 | ** ($P:$L) and the larger of the two returned values used. |
| 115791 | ** |
| 115792 | ** Similarly, iUpper is to be set to the estimate of the number of rows |
| 115793 | ** less than the upper bound of the range query. Where the upper bound |
| 115794 | ** is either ($P) or ($P:$U). Again, even if $U is available, both values |
| 115795 | ** of iUpper are requested of whereKeyStats() and the smaller used. |
| 115796 | */ |
| 115797 | tRowcnt iLower; |
| 115798 | tRowcnt iUpper; |
| 115799 | |
| 115800 | if( pRec ){ |
| 115801 | testcase( pRec->nField!=pBuilder->nRecValid ); |
| 115802 | pRec->nField = pBuilder->nRecValid; |
| 115803 | } |
| @@ -116650,11 +115807,11 @@ | |
| 115807 | aff = p->pTable->aCol[p->aiColumn[nEq]].affinity; |
| 115808 | } |
| 115809 | /* Determine iLower and iUpper using ($P) only. */ |
| 115810 | if( nEq==0 ){ |
| 115811 | iLower = 0; |
| 115812 | iUpper = sqlite3LogEstToInt(p->aiRowLogEst[0]); |
| 115813 | }else{ |
| 115814 | /* Note: this call could be optimized away - since the same values must |
| 115815 | ** have been requested when testing key $P in whereEqualScanEst(). */ |
| 115816 | whereKeyStats(pParse, p, pRec, 0, a); |
| 115817 | iLower = a[0]; |
| @@ -116674,11 +115831,11 @@ | |
| 115831 | int bOk; /* True if value is extracted from pExpr */ |
| 115832 | Expr *pExpr = pLower->pExpr->pRight; |
| 115833 | rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk); |
| 115834 | if( rc==SQLITE_OK && bOk ){ |
| 115835 | tRowcnt iNew; |
| 115836 | whereKeyStats(pParse, p, pRec, 0, a); |
| 115837 | iNew = a[0] + ((pLower->eOperator & (WO_GT|WO_LE)) ? a[1] : 0); |
| 115838 | if( iNew>iLower ) iLower = iNew; |
| 115839 | nOut--; |
| 115840 | pLower = 0; |
| 115841 | } |
| @@ -116689,11 +115846,11 @@ | |
| 115846 | int bOk; /* True if value is extracted from pExpr */ |
| 115847 | Expr *pExpr = pUpper->pExpr->pRight; |
| 115848 | rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk); |
| 115849 | if( rc==SQLITE_OK && bOk ){ |
| 115850 | tRowcnt iNew; |
| 115851 | whereKeyStats(pParse, p, pRec, 1, a); |
| 115852 | iNew = a[0] + ((pUpper->eOperator & (WO_GT|WO_LE)) ? a[1] : 0); |
| 115853 | if( iNew<iUpper ) iUpper = iNew; |
| 115854 | nOut--; |
| 115855 | pUpper = 0; |
| 115856 | } |
| @@ -116701,15 +115858,10 @@ | |
| 115858 | |
| 115859 | pBuilder->pRec = pRec; |
| 115860 | if( rc==SQLITE_OK ){ |
| 115861 | if( iUpper>iLower ){ |
| 115862 | nNew = sqlite3LogEst(iUpper - iLower); |
| 115863 | }else{ |
| 115864 | nNew = 10; assert( 10==sqlite3LogEst(2) ); |
| 115865 | } |
| 115866 | if( nNew<nOut ){ |
| 115867 | nOut = nNew; |
| @@ -116730,19 +115882,16 @@ | |
| 115882 | #endif |
| 115883 | assert( pUpper==0 || (pUpper->wtFlags & TERM_VNULL)==0 ); |
| 115884 | nNew = whereRangeAdjust(pLower, nOut); |
| 115885 | nNew = whereRangeAdjust(pUpper, nNew); |
| 115886 | |
| 115887 | /* TUNING: If there is both an upper and lower limit, assume the range is |
| 115888 | ** reduced by an additional 75%. This means that, by default, an open-ended |
| 115889 | ** range query (e.g. col > ?) is assumed to match 1/4 of the rows in the |
| 115890 | ** index. While a closed range (e.g. col BETWEEN ? AND ?) is estimated to |
| 115891 | ** match 1/64 of the index. */ |
| 115892 | if( pLower && pUpper ) nNew -= 20; |
| 115893 | |
| 115894 | nOut -= (pLower!=0) + (pUpper!=0); |
| 115895 | if( nNew<10 ) nNew = 10; |
| 115896 | if( nNew<nOut ) nOut = nNew; |
| 115897 | #if defined(WHERETRACE_ENABLED) |
| @@ -117098,11 +116247,11 @@ | |
| 116247 | |
| 116248 | /* This module is only called on query plans that use an index. */ |
| 116249 | pLoop = pLevel->pWLoop; |
| 116250 | assert( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 ); |
| 116251 | nEq = pLoop->u.btree.nEq; |
| 116252 | nSkip = pLoop->u.btree.nSkip; |
| 116253 | pIdx = pLoop->u.btree.pIndex; |
| 116254 | assert( pIdx!=0 ); |
| 116255 | |
| 116256 | /* Figure out how many memory cells we will need then allocate them. |
| 116257 | */ |
| @@ -117212,11 +116361,11 @@ | |
| 116361 | ** "a=? AND b>?" |
| 116362 | */ |
| 116363 | static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){ |
| 116364 | Index *pIndex = pLoop->u.btree.pIndex; |
| 116365 | u16 nEq = pLoop->u.btree.nEq; |
| 116366 | u16 nSkip = pLoop->u.btree.nSkip; |
| 116367 | int i, j; |
| 116368 | Column *aCol = pTab->aCol; |
| 116369 | i16 *aiColumn = pIndex->aiColumn; |
| 116370 | |
| 116371 | if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return; |
| @@ -117243,27 +116392,23 @@ | |
| 116392 | sqlite3StrAccumAppend(pStr, ")", 1); |
| 116393 | } |
| 116394 | |
| 116395 | /* |
| 116396 | ** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN |
| 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. |
| 116400 | */ |
| 116401 | static void explainOneScan( |
| 116402 | Parse *pParse, /* Parse context */ |
| 116403 | SrcList *pTabList, /* Table list this loop refers to */ |
| 116404 | WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */ |
| 116405 | int iLevel, /* Value for "level" column of output */ |
| 116406 | int iFrom, /* Value for "from" column of output */ |
| 116407 | u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */ |
| 116408 | ){ |
| 116409 | #ifndef SQLITE_DEBUG |
| 116410 | if( pParse->explain==2 ) |
| 116411 | #endif |
| 116412 | { |
| 116413 | struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom]; |
| 116414 | Vdbe *v = pParse->pVdbe; /* VM being constructed */ |
| @@ -117276,11 +116421,11 @@ | |
| 116421 | StrAccum str; /* EQP output string */ |
| 116422 | char zBuf[100]; /* Initial space for EQP output string */ |
| 116423 | |
| 116424 | pLoop = pLevel->pWLoop; |
| 116425 | flags = pLoop->wsFlags; |
| 116426 | if( (flags&WHERE_MULTI_OR) || (wctrlFlags&WHERE_ONETABLE_ONLY) ) return; |
| 116427 | |
| 116428 | isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0 |
| 116429 | || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0)) |
| 116430 | || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX)); |
| 116431 | |
| @@ -117305,12 +116450,10 @@ | |
| 116450 | assert( !(flags&WHERE_AUTO_INDEX) || (flags&WHERE_IDX_ONLY) ); |
| 116451 | if( !HasRowid(pItem->pTab) && IsPrimaryKeyIndex(pIdx) ){ |
| 116452 | if( isSearch ){ |
| 116453 | zFmt = "PRIMARY KEY"; |
| 116454 | } |
| 116455 | }else if( flags & WHERE_AUTO_INDEX ){ |
| 116456 | zFmt = "AUTOMATIC COVERING INDEX"; |
| 116457 | }else if( flags & WHERE_IDX_ONLY ){ |
| 116458 | zFmt = "COVERING INDEX %s"; |
| 116459 | }else{ |
| @@ -117348,49 +116491,16 @@ | |
| 116491 | }else{ |
| 116492 | sqlite3StrAccumAppend(&str, " (~1 row)", 9); |
| 116493 | } |
| 116494 | #endif |
| 116495 | zMsg = sqlite3StrAccumFinish(&str); |
| 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 */ |
| 116502 | |
| 116503 | |
| 116504 | /* |
| 116505 | ** Generate code for the start of the iLevel-th loop in the WHERE clause |
| 116506 | ** implementation described by pWInfo. |
| @@ -117688,11 +116798,11 @@ | |
| 116798 | u8 bSeekPastNull = 0; /* True to seek past initial nulls */ |
| 116799 | u8 bStopAtNull = 0; /* Add condition to terminate at NULLs */ |
| 116800 | |
| 116801 | pIdx = pLoop->u.btree.pIndex; |
| 116802 | iIdxCur = pLevel->iIdxCur; |
| 116803 | assert( nEq>=pLoop->u.btree.nSkip ); |
| 116804 | |
| 116805 | /* If this loop satisfies a sort order (pOrderBy) request that |
| 116806 | ** was passed to this function to implement a "SELECT min(x) ..." |
| 116807 | ** query, then the caller will only allow the loop to run for |
| 116808 | ** a single iteration. This means that the first row returned |
| @@ -117705,11 +116815,11 @@ | |
| 116815 | || (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0 ); |
| 116816 | if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0 |
| 116817 | && pWInfo->nOBSat>0 |
| 116818 | && (pIdx->nKeyCol>nEq) |
| 116819 | ){ |
| 116820 | assert( pLoop->u.btree.nSkip==0 ); |
| 116821 | bSeekPastNull = 1; |
| 116822 | nExtraReg = 1; |
| 116823 | } |
| 116824 | |
| 116825 | /* Find any inequality constraint terms for the start and end |
| @@ -118054,15 +117164,13 @@ | |
| 117164 | pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0, |
| 117165 | wctrlFlags, iCovCur); |
| 117166 | assert( pSubWInfo || pParse->nErr || db->mallocFailed ); |
| 117167 | if( pSubWInfo ){ |
| 117168 | WhereLoop *pSubLoop; |
| 117169 | explainOneScan( |
| 117170 | pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0 |
| 117171 | ); |
| 117172 | /* This is the sub-WHERE clause body. First skip over |
| 117173 | ** duplicate rows from prior sub-WHERE clauses, and record the |
| 117174 | ** rowid (or PRIMARY KEY) for the current row so that the same |
| 117175 | ** row will be skipped in subsequent sub-WHERE clauses. |
| 117176 | */ |
| @@ -118189,14 +117297,10 @@ | |
| 117297 | VdbeCoverageIf(v, bRev!=0); |
| 117298 | pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP; |
| 117299 | } |
| 117300 | } |
| 117301 | |
| 117302 | /* Insert code to test every subexpression that can be completely |
| 117303 | ** computed using the current set of tables. |
| 117304 | */ |
| 117305 | for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){ |
| 117306 | Expr *pE; |
| @@ -118332,11 +117436,11 @@ | |
| 117436 | } |
| 117437 | sqlite3DebugPrintf(" %-19s", z); |
| 117438 | sqlite3_free(z); |
| 117439 | } |
| 117440 | if( p->wsFlags & WHERE_SKIPSCAN ){ |
| 117441 | sqlite3DebugPrintf(" f %05x %d-%d", p->wsFlags, p->nLTerm,p->u.btree.nSkip); |
| 117442 | }else{ |
| 117443 | sqlite3DebugPrintf(" f %05x N %d", p->wsFlags, p->nLTerm); |
| 117444 | } |
| 117445 | sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut); |
| 117446 | if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){ |
| @@ -118443,41 +117547,34 @@ | |
| 117547 | sqlite3DbFree(db, pWInfo); |
| 117548 | } |
| 117549 | } |
| 117550 | |
| 117551 | /* |
| 117552 | ** Return TRUE if both of the following are true: |
| 117553 | ** |
| 117554 | ** (1) X has the same or lower cost that Y |
| 117555 | ** (2) X is a proper subset of Y |
| 117556 | ** |
| 117557 | ** By "proper subset" we mean that X uses fewer WHERE clause terms |
| 117558 | ** than Y and that every WHERE clause term used by X is also used |
| 117559 | ** by Y. |
| 117560 | ** |
| 117561 | ** If X is a proper subset of Y then Y is a better choice and ought |
| 117562 | ** to have a lower cost. This routine returns TRUE when that cost |
| 117563 | ** relationship is inverted and needs to be adjusted. |
| 117564 | */ |
| 117565 | static int whereLoopCheaperProperSubset( |
| 117566 | const WhereLoop *pX, /* First WhereLoop to compare */ |
| 117567 | const WhereLoop *pY /* Compare against this WhereLoop */ |
| 117568 | ){ |
| 117569 | int i, j; |
| 117570 | if( pX->nLTerm >= pY->nLTerm ) return 0; /* X is not a subset of Y */ |
| 117571 | if( pX->rRun >= pY->rRun ){ |
| 117572 | if( pX->rRun > pY->rRun ) return 0; /* X costs more than Y */ |
| 117573 | if( pX->nOut > pY->nOut ) return 0; /* X costs more than Y */ |
| 117574 | } |
| 117575 | for(i=pX->nLTerm-1; i>=0; i--){ |
| 117576 | for(j=pY->nLTerm-1; j>=0; j--){ |
| 117577 | if( pY->aLTerm[j]==pX->aLTerm[i] ) break; |
| 117578 | } |
| 117579 | if( j<0 ) return 0; /* X not a subset of Y since term X[i] not used by Y */ |
| 117580 | } |
| @@ -118495,28 +117592,37 @@ | |
| 117592 | ** is a proper subset. |
| 117593 | ** |
| 117594 | ** To say "WhereLoop X is a proper subset of Y" means that X uses fewer |
| 117595 | ** WHERE clause terms than Y and that every WHERE clause term used by X is |
| 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. |
| 117608 | */ |
| 117609 | static void whereLoopAdjustCost(const WhereLoop *p, WhereLoop *pTemplate){ |
| 117610 | if( (pTemplate->wsFlags & WHERE_INDEXED)==0 ) return; |
| 117611 | if( (pTemplate->wsFlags & WHERE_SKIPSCAN)!=0 ) return; |
| 117612 | for(; p; p=p->pNextLoop){ |
| 117613 | if( p->iTab!=pTemplate->iTab ) continue; |
| 117614 | if( (p->wsFlags & WHERE_INDEXED)==0 ) continue; |
| 117615 | if( (p->wsFlags & WHERE_SKIPSCAN)!=0 ) continue; |
| 117616 | if( whereLoopCheaperProperSubset(p, pTemplate) ){ |
| 117617 | /* Adjust pTemplate cost downward so that it is cheaper than its |
| 117618 | ** subset p */ |
| 117619 | pTemplate->rRun = p->rRun; |
| 117620 | pTemplate->nOut = p->nOut - 1; |
| 117621 | }else if( whereLoopCheaperProperSubset(pTemplate, p) ){ |
| 117622 | /* Adjust pTemplate cost upward so that it is costlier than p since |
| 117623 | ** pTemplate is a proper subset of p */ |
| 117624 | pTemplate->rRun = p->rRun; |
| 117625 | pTemplate->nOut = p->nOut + 1; |
| 117626 | } |
| 117627 | } |
| 117628 | } |
| @@ -118557,13 +117663,12 @@ | |
| 117663 | ** rSetup. Call this SETUP-INVARIANT */ |
| 117664 | assert( p->rSetup>=pTemplate->rSetup ); |
| 117665 | |
| 117666 | /* Any loop using an appliation-defined index (or PRIMARY KEY or |
| 117667 | ** UNIQUE constraint) with one or more == constraints is better |
| 117668 | ** than an automatic index. */ |
| 117669 | if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 |
| 117670 | && (pTemplate->wsFlags & WHERE_INDEXED)!=0 |
| 117671 | && (pTemplate->wsFlags & WHERE_COLUMN_EQ)!=0 |
| 117672 | && (p->prereq & pTemplate->prereq)==pTemplate->prereq |
| 117673 | ){ |
| 117674 | break; |
| @@ -118799,11 +117904,11 @@ | |
| 117904 | int opMask; /* Valid operators for constraints */ |
| 117905 | WhereScan scan; /* Iterator for WHERE terms */ |
| 117906 | Bitmask saved_prereq; /* Original value of pNew->prereq */ |
| 117907 | u16 saved_nLTerm; /* Original value of pNew->nLTerm */ |
| 117908 | u16 saved_nEq; /* Original value of pNew->u.btree.nEq */ |
| 117909 | u16 saved_nSkip; /* Original value of pNew->u.btree.nSkip */ |
| 117910 | u32 saved_wsFlags; /* Original value of pNew->wsFlags */ |
| 117911 | LogEst saved_nOut; /* Original value of pNew->nOut */ |
| 117912 | int iCol; /* Index of the column in the table */ |
| 117913 | int rc = SQLITE_OK; /* Return code */ |
| 117914 | LogEst rSize; /* Number of rows in the table */ |
| @@ -118828,18 +117933,56 @@ | |
| 117933 | iCol = pProbe->aiColumn[pNew->u.btree.nEq]; |
| 117934 | |
| 117935 | pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, iCol, |
| 117936 | opMask, pProbe); |
| 117937 | saved_nEq = pNew->u.btree.nEq; |
| 117938 | saved_nSkip = pNew->u.btree.nSkip; |
| 117939 | saved_nLTerm = pNew->nLTerm; |
| 117940 | saved_wsFlags = pNew->wsFlags; |
| 117941 | saved_prereq = pNew->prereq; |
| 117942 | saved_nOut = pNew->nOut; |
| 117943 | pNew->rSetup = 0; |
| 117944 | rSize = pProbe->aiRowLogEst[0]; |
| 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 | } |
| 117984 | for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){ |
| 117985 | u16 eOp = pTerm->eOperator; /* Shorthand for pTerm->eOperator */ |
| 117986 | LogEst rCostIdx; |
| 117987 | LogEst nOutUnadjusted; /* nOut before IN() and WHERE adjustments */ |
| 117988 | int nIn = 0; |
| @@ -118930,10 +118073,11 @@ | |
| 118073 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 118074 | tRowcnt nOut = 0; |
| 118075 | if( nInMul==0 |
| 118076 | && pProbe->nSample |
| 118077 | && pNew->u.btree.nEq<=pProbe->nSampleCol |
| 118078 | && OptimizationEnabled(db, SQLITE_Stat3) |
| 118079 | && ((eOp & WO_IN)==0 || !ExprHasProperty(pTerm->pExpr, EP_xIsSelect)) |
| 118080 | ){ |
| 118081 | Expr *pExpr = pTerm->pExpr; |
| 118082 | if( (eOp & (WO_EQ|WO_ISNULL))!=0 ){ |
| 118083 | testcase( eOp & WO_EQ ); |
| @@ -118997,49 +118141,14 @@ | |
| 118141 | pBuilder->nRecValid = nRecValid; |
| 118142 | #endif |
| 118143 | } |
| 118144 | pNew->prereq = saved_prereq; |
| 118145 | pNew->u.btree.nEq = saved_nEq; |
| 118146 | pNew->u.btree.nSkip = saved_nSkip; |
| 118147 | pNew->wsFlags = saved_wsFlags; |
| 118148 | pNew->nOut = saved_nOut; |
| 118149 | pNew->nLTerm = saved_nLTerm; |
| 118150 | return rc; |
| 118151 | } |
| 118152 | |
| 118153 | /* |
| 118154 | ** Return True if it is possible that pIndex might be useful in |
| @@ -119214,11 +118323,11 @@ | |
| 118323 | WhereTerm *pWCEnd = pWC->a + pWC->nTerm; |
| 118324 | for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){ |
| 118325 | if( pTerm->prereqRight & pNew->maskSelf ) continue; |
| 118326 | if( termCanDriveIndex(pTerm, pSrc, 0) ){ |
| 118327 | pNew->u.btree.nEq = 1; |
| 118328 | pNew->u.btree.nSkip = 0; |
| 118329 | pNew->u.btree.pIndex = 0; |
| 118330 | pNew->nLTerm = 1; |
| 118331 | pNew->aLTerm[0] = pTerm; |
| 118332 | /* TUNING: One-time cost for computing the automatic index is |
| 118333 | ** estimated to be X*N*log2(N) where N is the number of rows in |
| @@ -119255,11 +118364,11 @@ | |
| 118364 | testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */ |
| 118365 | continue; /* Partial index inappropriate for this query */ |
| 118366 | } |
| 118367 | rSize = pProbe->aiRowLogEst[0]; |
| 118368 | pNew->u.btree.nEq = 0; |
| 118369 | pNew->u.btree.nSkip = 0; |
| 118370 | pNew->nLTerm = 0; |
| 118371 | pNew->iSortIdx = 0; |
| 118372 | pNew->rSetup = 0; |
| 118373 | pNew->prereq = mExtra; |
| 118374 | pNew->nOut = rSize; |
| @@ -119805,11 +118914,11 @@ | |
| 118914 | for(j=0; j<nColumn; j++){ |
| 118915 | u8 bOnce; /* True to run the ORDER BY search loop */ |
| 118916 | |
| 118917 | /* Skip over == and IS NULL terms */ |
| 118918 | if( j<pLoop->u.btree.nEq |
| 118919 | && pLoop->u.btree.nSkip==0 |
| 118920 | && ((i = pLoop->aLTerm[j]->eOperator) & (WO_EQ|WO_ISNULL))!=0 |
| 118921 | ){ |
| 118922 | if( i & WO_ISNULL ){ |
| 118923 | testcase( isOrderDistinct ); |
| 118924 | isOrderDistinct = 0; |
| @@ -120259,11 +119368,11 @@ | |
| 119368 | } |
| 119369 | } |
| 119370 | } |
| 119371 | |
| 119372 | #ifdef WHERETRACE_ENABLED /* >=2 */ |
| 119373 | if( sqlite3WhereTrace>=2 ){ |
| 119374 | sqlite3DebugPrintf("---- after round %d ----\n", iLoop); |
| 119375 | for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){ |
| 119376 | sqlite3DebugPrintf(" %s cost=%-3d nrow=%-3d order=%c", |
| 119377 | wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow, |
| 119378 | pTo->isOrdered>=0 ? (pTo->isOrdered+'0') : '?'); |
| @@ -120378,11 +119487,11 @@ | |
| 119487 | if( pItem->zIndex ) return 0; |
| 119488 | iCur = pItem->iCursor; |
| 119489 | pWC = &pWInfo->sWC; |
| 119490 | pLoop = pBuilder->pNew; |
| 119491 | pLoop->wsFlags = 0; |
| 119492 | pLoop->u.btree.nSkip = 0; |
| 119493 | pTerm = findTerm(pWC, iCur, -1, 0, WO_EQ, 0); |
| 119494 | if( pTerm ){ |
| 119495 | pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_IPK|WHERE_ONEROW; |
| 119496 | pLoop->aLTerm[0] = pTerm; |
| 119497 | pLoop->nLTerm = 1; |
| @@ -120390,10 +119499,11 @@ | |
| 119499 | /* TUNING: Cost of a rowid lookup is 10 */ |
| 119500 | pLoop->rRun = 33; /* 33==sqlite3LogEst(10) */ |
| 119501 | }else{ |
| 119502 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 119503 | assert( pLoop->aLTermSpace==pLoop->aLTerm ); |
| 119504 | assert( ArraySize(pLoop->aLTermSpace)==4 ); |
| 119505 | if( !IsUniqueIndex(pIdx) |
| 119506 | || pIdx->pPartIdxWhere!=0 |
| 119507 | || pIdx->nKeyCol>ArraySize(pLoop->aLTermSpace) |
| 119508 | ) continue; |
| 119509 | for(j=0; j<pIdx->nKeyCol; j++){ |
| @@ -120898,30 +120008,22 @@ | |
| 120008 | ** loop below generates code for a single nested loop of the VM |
| 120009 | ** program. |
| 120010 | */ |
| 120011 | notReady = ~(Bitmask)0; |
| 120012 | for(ii=0; ii<nTabList; ii++){ |
| 120013 | pLevel = &pWInfo->a[ii]; |
| 120014 | #ifndef SQLITE_OMIT_AUTOMATIC_INDEX |
| 120015 | if( (pLevel->pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){ |
| 120016 | constructAutomaticIndex(pParse, &pWInfo->sWC, |
| 120017 | &pTabList->a[pLevel->iFrom], notReady, pLevel); |
| 120018 | if( db->mallocFailed ) goto whereBeginError; |
| 120019 | } |
| 120020 | #endif |
| 120021 | explainOneScan(pParse, pTabList, pLevel, ii, pLevel->iFrom, wctrlFlags); |
| 120022 | pLevel->addrBody = sqlite3VdbeCurrentAddr(v); |
| 120023 | notReady = codeOneLoopStart(pWInfo, ii, notReady); |
| 120024 | pWInfo->iContinue = pLevel->addrCont; |
| 120025 | } |
| 120026 | |
| 120027 | /* Done. */ |
| 120028 | VdbeModuleComment((v, "Begin WHERE-core")); |
| 120029 | return pWInfo; |
| @@ -125586,17 +124688,10 @@ | |
| 124688 | */ |
| 124689 | SQLITE_API int sqlite3_complete(const char *zSql){ |
| 124690 | u8 state = 0; /* Current state, using numbers defined in header comment */ |
| 124691 | u8 token; /* Value of the next token */ |
| 124692 | |
| 124693 | #ifndef SQLITE_OMIT_TRIGGER |
| 124694 | /* A complex statement machine used to detect the end of a CREATE TRIGGER |
| 124695 | ** statement. This is the normal case. |
| 124696 | */ |
| 124697 | static const u8 trans[8][8] = { |
| @@ -126190,107 +125285,75 @@ | |
| 125285 | |
| 125286 | va_start(ap, op); |
| 125287 | switch( op ){ |
| 125288 | |
| 125289 | /* Mutex configuration options are only available in a threadsafe |
| 125290 | ** compile. |
| 125291 | */ |
| 125292 | #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 |
| 125293 | case SQLITE_CONFIG_SINGLETHREAD: { |
| 125294 | /* Disable all mutexing */ |
| 125295 | sqlite3GlobalConfig.bCoreMutex = 0; |
| 125296 | sqlite3GlobalConfig.bFullMutex = 0; |
| 125297 | break; |
| 125298 | } |
| 125299 | case SQLITE_CONFIG_MULTITHREAD: { |
| 125300 | /* Disable mutexing of database connections */ |
| 125301 | /* Enable mutexing of core data structures */ |
| 125302 | sqlite3GlobalConfig.bCoreMutex = 1; |
| 125303 | sqlite3GlobalConfig.bFullMutex = 0; |
| 125304 | break; |
| 125305 | } |
| 125306 | case SQLITE_CONFIG_SERIALIZED: { |
| 125307 | /* Enable all mutexing */ |
| 125308 | sqlite3GlobalConfig.bCoreMutex = 1; |
| 125309 | sqlite3GlobalConfig.bFullMutex = 1; |
| 125310 | break; |
| 125311 | } |
| 125312 | case SQLITE_CONFIG_MUTEX: { |
| 125313 | /* Specify an alternative mutex implementation */ |
| 125314 | sqlite3GlobalConfig.mutex = *va_arg(ap, sqlite3_mutex_methods*); |
| 125315 | break; |
| 125316 | } |
| 125317 | case SQLITE_CONFIG_GETMUTEX: { |
| 125318 | /* Retrieve the current mutex implementation */ |
| 125319 | *va_arg(ap, sqlite3_mutex_methods*) = sqlite3GlobalConfig.mutex; |
| 125320 | break; |
| 125321 | } |
| 125322 | #endif |
| 125323 | |
| 125324 | |
| 125325 | case SQLITE_CONFIG_MALLOC: { |
| 125326 | /* Specify an alternative malloc implementation */ |
| 125327 | sqlite3GlobalConfig.m = *va_arg(ap, sqlite3_mem_methods*); |
| 125328 | break; |
| 125329 | } |
| 125330 | case SQLITE_CONFIG_GETMALLOC: { |
| 125331 | /* Retrieve the current malloc() implementation */ |
| 125332 | if( sqlite3GlobalConfig.m.xMalloc==0 ) sqlite3MemSetDefault(); |
| 125333 | *va_arg(ap, sqlite3_mem_methods*) = sqlite3GlobalConfig.m; |
| 125334 | break; |
| 125335 | } |
| 125336 | case SQLITE_CONFIG_MEMSTATUS: { |
| 125337 | /* Enable or disable the malloc status collection */ |
| 125338 | sqlite3GlobalConfig.bMemstat = va_arg(ap, int); |
| 125339 | break; |
| 125340 | } |
| 125341 | case SQLITE_CONFIG_SCRATCH: { |
| 125342 | /* Designate a buffer for scratch memory space */ |
| 125343 | sqlite3GlobalConfig.pScratch = va_arg(ap, void*); |
| 125344 | sqlite3GlobalConfig.szScratch = va_arg(ap, int); |
| 125345 | sqlite3GlobalConfig.nScratch = va_arg(ap, int); |
| 125346 | break; |
| 125347 | } |
| 125348 | case SQLITE_CONFIG_PAGECACHE: { |
| 125349 | /* Designate a buffer for page cache memory space */ |
| 125350 | sqlite3GlobalConfig.pPage = va_arg(ap, void*); |
| 125351 | sqlite3GlobalConfig.szPage = va_arg(ap, int); |
| 125352 | sqlite3GlobalConfig.nPage = va_arg(ap, int); |
| 125353 | break; |
| 125354 | } |
| 125355 | |
| 125356 | case SQLITE_CONFIG_PCACHE: { |
| 125357 | /* no-op */ |
| 125358 | break; |
| 125359 | } |
| @@ -126299,37 +125362,25 @@ | |
| 125362 | rc = SQLITE_ERROR; |
| 125363 | break; |
| 125364 | } |
| 125365 | |
| 125366 | case SQLITE_CONFIG_PCACHE2: { |
| 125367 | /* Specify an alternative page cache implementation */ |
| 125368 | sqlite3GlobalConfig.pcache2 = *va_arg(ap, sqlite3_pcache_methods2*); |
| 125369 | break; |
| 125370 | } |
| 125371 | case SQLITE_CONFIG_GETPCACHE2: { |
| 125372 | if( sqlite3GlobalConfig.pcache2.xInit==0 ){ |
| 125373 | sqlite3PCacheSetDefault(); |
| 125374 | } |
| 125375 | *va_arg(ap, sqlite3_pcache_methods2*) = sqlite3GlobalConfig.pcache2; |
| 125376 | break; |
| 125377 | } |
| 125378 | |
| 125379 | #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5) |
| 125380 | case SQLITE_CONFIG_HEAP: { |
| 125381 | /* Designate a buffer for heap memory space */ |
| 125382 | sqlite3GlobalConfig.pHeap = va_arg(ap, void*); |
| 125383 | sqlite3GlobalConfig.nHeap = va_arg(ap, int); |
| 125384 | sqlite3GlobalConfig.mnReq = va_arg(ap, int); |
| 125385 | |
| 125386 | if( sqlite3GlobalConfig.mnReq<1 ){ |
| @@ -126338,23 +125389,21 @@ | |
| 125389 | /* cap min request size at 2^12 */ |
| 125390 | sqlite3GlobalConfig.mnReq = (1<<12); |
| 125391 | } |
| 125392 | |
| 125393 | if( sqlite3GlobalConfig.pHeap==0 ){ |
| 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. |
| 125398 | */ |
| 125399 | memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m)); |
| 125400 | }else{ |
| 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 | */ |
| 125405 | #ifdef SQLITE_ENABLE_MEMSYS3 |
| 125406 | sqlite3GlobalConfig.m = *sqlite3MemGetMemsys3(); |
| 125407 | #endif |
| 125408 | #ifdef SQLITE_ENABLE_MEMSYS5 |
| 125409 | sqlite3GlobalConfig.m = *sqlite3MemGetMemsys5(); |
| @@ -126389,23 +125438,15 @@ | |
| 125438 | ** can be changed at start-time using the |
| 125439 | ** sqlite3_config(SQLITE_CONFIG_URI,1) or |
| 125440 | ** sqlite3_config(SQLITE_CONFIG_URI,0) configuration calls. |
| 125441 | */ |
| 125442 | case SQLITE_CONFIG_URI: { |
| 125443 | sqlite3GlobalConfig.bOpenUri = va_arg(ap, int); |
| 125444 | break; |
| 125445 | } |
| 125446 | |
| 125447 | case SQLITE_CONFIG_COVERING_INDEX_SCAN: { |
| 125448 | sqlite3GlobalConfig.bUseCis = va_arg(ap, int); |
| 125449 | break; |
| 125450 | } |
| 125451 | |
| 125452 | #ifdef SQLITE_ENABLE_SQLLOG |
| @@ -126416,37 +125457,24 @@ | |
| 125457 | break; |
| 125458 | } |
| 125459 | #endif |
| 125460 | |
| 125461 | case SQLITE_CONFIG_MMAP_SIZE: { |
| 125462 | sqlite3_int64 szMmap = va_arg(ap, sqlite3_int64); |
| 125463 | sqlite3_int64 mxMmap = va_arg(ap, sqlite3_int64); |
| 125464 | if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ){ |
| 125465 | mxMmap = SQLITE_MAX_MMAP_SIZE; |
| 125466 | } |
| 125467 | sqlite3GlobalConfig.mxMmap = mxMmap; |
| 125468 | if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE; |
| 125469 | if( szMmap>mxMmap) szMmap = mxMmap; |
| 125470 | sqlite3GlobalConfig.szMmap = szMmap; |
| 125471 | break; |
| 125472 | } |
| 125473 | |
| 125474 | #if SQLITE_OS_WIN && defined(SQLITE_WIN32_MALLOC) |
| 125475 | case SQLITE_CONFIG_WIN32_HEAPSIZE: { |
| 125476 | sqlite3GlobalConfig.nHeap = va_arg(ap, int); |
| 125477 | break; |
| 125478 | } |
| 125479 | #endif |
| 125480 | |
| @@ -126526,29 +125554,19 @@ | |
| 125554 | |
| 125555 | /* |
| 125556 | ** Return the mutex associated with a database connection. |
| 125557 | */ |
| 125558 | SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){ |
| 125559 | return db->mutex; |
| 125560 | } |
| 125561 | |
| 125562 | /* |
| 125563 | ** Free up as much memory as we can from the given database |
| 125564 | ** connection. |
| 125565 | */ |
| 125566 | SQLITE_API int sqlite3_db_release_memory(sqlite3 *db){ |
| 125567 | int i; |
| 125568 | sqlite3_mutex_enter(db->mutex); |
| 125569 | sqlite3BtreeEnterAll(db); |
| 125570 | for(i=0; i<db->nDb; i++){ |
| 125571 | Btree *pBt = db->aDb[i].pBt; |
| 125572 | if( pBt ){ |
| @@ -126675,42 +125693,24 @@ | |
| 125693 | |
| 125694 | /* |
| 125695 | ** Return the ROWID of the most recent insert |
| 125696 | */ |
| 125697 | SQLITE_API sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){ |
| 125698 | return db->lastRowid; |
| 125699 | } |
| 125700 | |
| 125701 | /* |
| 125702 | ** Return the number of changes in the most recent call to sqlite3_exec(). |
| 125703 | */ |
| 125704 | SQLITE_API int sqlite3_changes(sqlite3 *db){ |
| 125705 | return db->nChange; |
| 125706 | } |
| 125707 | |
| 125708 | /* |
| 125709 | ** Return the number of changes since the database handle was opened. |
| 125710 | */ |
| 125711 | SQLITE_API int sqlite3_total_changes(sqlite3 *db){ |
| 125712 | return db->nTotalChange; |
| 125713 | } |
| 125714 | |
| 125715 | /* |
| 125716 | ** Close all open savepoints. This function only manipulates fields of the |
| @@ -127255,13 +126255,10 @@ | |
| 126255 | SQLITE_API int sqlite3_busy_handler( |
| 126256 | sqlite3 *db, |
| 126257 | int (*xBusy)(void*,int), |
| 126258 | void *pArg |
| 126259 | ){ |
| 126260 | sqlite3_mutex_enter(db->mutex); |
| 126261 | db->busyHandler.xFunc = xBusy; |
| 126262 | db->busyHandler.pArg = pArg; |
| 126263 | db->busyHandler.nBusy = 0; |
| 126264 | db->busyTimeout = 0; |
| @@ -127279,16 +126276,10 @@ | |
| 126276 | sqlite3 *db, |
| 126277 | int nOps, |
| 126278 | int (*xProgress)(void*), |
| 126279 | void *pArg |
| 126280 | ){ |
| 126281 | sqlite3_mutex_enter(db->mutex); |
| 126282 | if( nOps>0 ){ |
| 126283 | db->xProgress = xProgress; |
| 126284 | db->nProgressOps = (unsigned)nOps; |
| 126285 | db->pProgressArg = pArg; |
| @@ -127305,13 +126296,10 @@ | |
| 126296 | /* |
| 126297 | ** This routine installs a default busy handler that waits for the |
| 126298 | ** specified number of milliseconds before returning 0. |
| 126299 | */ |
| 126300 | SQLITE_API int sqlite3_busy_timeout(sqlite3 *db, int ms){ |
| 126301 | if( ms>0 ){ |
| 126302 | sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db); |
| 126303 | db->busyTimeout = ms; |
| 126304 | }else{ |
| 126305 | sqlite3_busy_handler(db, 0, 0); |
| @@ -127321,16 +126309,10 @@ | |
| 126309 | |
| 126310 | /* |
| 126311 | ** Cause any pending operation to stop at its earliest opportunity. |
| 126312 | */ |
| 126313 | SQLITE_API void sqlite3_interrupt(sqlite3 *db){ |
| 126314 | db->u1.isInterrupted = 1; |
| 126315 | } |
| 126316 | |
| 126317 | |
| 126318 | /* |
| @@ -127464,16 +126446,10 @@ | |
| 126446 | void (*xFinal)(sqlite3_context*), |
| 126447 | void (*xDestroy)(void *) |
| 126448 | ){ |
| 126449 | int rc = SQLITE_ERROR; |
| 126450 | FuncDestructor *pArg = 0; |
| 126451 | sqlite3_mutex_enter(db->mutex); |
| 126452 | if( xDestroy ){ |
| 126453 | pArg = (FuncDestructor *)sqlite3DbMallocZero(db, sizeof(FuncDestructor)); |
| 126454 | if( !pArg ){ |
| 126455 | xDestroy(p); |
| @@ -127506,14 +126482,10 @@ | |
| 126482 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
| 126483 | void (*xFinal)(sqlite3_context*) |
| 126484 | ){ |
| 126485 | int rc; |
| 126486 | char *zFunc8; |
| 126487 | sqlite3_mutex_enter(db->mutex); |
| 126488 | assert( !db->mallocFailed ); |
| 126489 | zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE); |
| 126490 | rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal,0); |
| 126491 | sqlite3DbFree(db, zFunc8); |
| @@ -127541,16 +126513,10 @@ | |
| 126513 | const char *zName, |
| 126514 | int nArg |
| 126515 | ){ |
| 126516 | int nName = sqlite3Strlen30(zName); |
| 126517 | int rc = SQLITE_OK; |
| 126518 | sqlite3_mutex_enter(db->mutex); |
| 126519 | if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){ |
| 126520 | rc = sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8, |
| 126521 | 0, sqlite3InvalidFunction, 0, 0, 0); |
| 126522 | } |
| @@ -127568,17 +126534,10 @@ | |
| 126534 | ** trace is a pointer to a function that is invoked at the start of each |
| 126535 | ** SQL statement. |
| 126536 | */ |
| 126537 | SQLITE_API void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){ |
| 126538 | void *pOld; |
| 126539 | sqlite3_mutex_enter(db->mutex); |
| 126540 | pOld = db->pTraceArg; |
| 126541 | db->xTrace = xTrace; |
| 126542 | db->pTraceArg = pArg; |
| 126543 | sqlite3_mutex_leave(db->mutex); |
| @@ -127596,17 +126555,10 @@ | |
| 126555 | sqlite3 *db, |
| 126556 | void (*xProfile)(void*,const char*,sqlite_uint64), |
| 126557 | void *pArg |
| 126558 | ){ |
| 126559 | void *pOld; |
| 126560 | sqlite3_mutex_enter(db->mutex); |
| 126561 | pOld = db->pProfileArg; |
| 126562 | db->xProfile = xProfile; |
| 126563 | db->pProfileArg = pArg; |
| 126564 | sqlite3_mutex_leave(db->mutex); |
| @@ -127623,17 +126575,10 @@ | |
| 126575 | sqlite3 *db, /* Attach the hook to this database */ |
| 126576 | int (*xCallback)(void*), /* Function to invoke on each commit */ |
| 126577 | void *pArg /* Argument to the function */ |
| 126578 | ){ |
| 126579 | void *pOld; |
| 126580 | sqlite3_mutex_enter(db->mutex); |
| 126581 | pOld = db->pCommitArg; |
| 126582 | db->xCommitCallback = xCallback; |
| 126583 | db->pCommitArg = pArg; |
| 126584 | sqlite3_mutex_leave(db->mutex); |
| @@ -127648,17 +126593,10 @@ | |
| 126593 | sqlite3 *db, /* Attach the hook to this database */ |
| 126594 | void (*xCallback)(void*,int,char const *,char const *,sqlite_int64), |
| 126595 | void *pArg /* Argument to the function */ |
| 126596 | ){ |
| 126597 | void *pRet; |
| 126598 | sqlite3_mutex_enter(db->mutex); |
| 126599 | pRet = db->pUpdateArg; |
| 126600 | db->xUpdateCallback = xCallback; |
| 126601 | db->pUpdateArg = pArg; |
| 126602 | sqlite3_mutex_leave(db->mutex); |
| @@ -127673,17 +126611,10 @@ | |
| 126611 | sqlite3 *db, /* Attach the hook to this database */ |
| 126612 | void (*xCallback)(void*), /* Callback function */ |
| 126613 | void *pArg /* Argument to the function */ |
| 126614 | ){ |
| 126615 | void *pRet; |
| 126616 | sqlite3_mutex_enter(db->mutex); |
| 126617 | pRet = db->pRollbackArg; |
| 126618 | db->xRollbackCallback = xCallback; |
| 126619 | db->pRollbackArg = pArg; |
| 126620 | sqlite3_mutex_leave(db->mutex); |
| @@ -127726,13 +126657,10 @@ | |
| 126657 | SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){ |
| 126658 | #ifdef SQLITE_OMIT_WAL |
| 126659 | UNUSED_PARAMETER(db); |
| 126660 | UNUSED_PARAMETER(nFrame); |
| 126661 | #else |
| 126662 | if( nFrame>0 ){ |
| 126663 | sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame)); |
| 126664 | }else{ |
| 126665 | sqlite3_wal_hook(db, 0, 0); |
| 126666 | } |
| @@ -127749,16 +126677,10 @@ | |
| 126677 | int(*xCallback)(void *, sqlite3*, const char*, int), |
| 126678 | void *pArg /* First argument passed to xCallback() */ |
| 126679 | ){ |
| 126680 | #ifndef SQLITE_OMIT_WAL |
| 126681 | void *pRet; |
| 126682 | sqlite3_mutex_enter(db->mutex); |
| 126683 | pRet = db->pWalArg; |
| 126684 | db->xWalCallback = xCallback; |
| 126685 | db->pWalArg = pArg; |
| 126686 | sqlite3_mutex_leave(db->mutex); |
| @@ -127782,14 +126704,10 @@ | |
| 126704 | return SQLITE_OK; |
| 126705 | #else |
| 126706 | int rc; /* Return code */ |
| 126707 | int iDb = SQLITE_MAX_ATTACHED; /* sqlite3.aDb[] index of db to checkpoint */ |
| 126708 | |
| 126709 | /* Initialize the output variables to -1 in case an error occurs. */ |
| 126710 | if( pnLog ) *pnLog = -1; |
| 126711 | if( pnCkpt ) *pnCkpt = -1; |
| 126712 | |
| 126713 | assert( SQLITE_CHECKPOINT_FULL>SQLITE_CHECKPOINT_PASSIVE ); |
| @@ -128182,16 +127100,10 @@ | |
| 127100 | ** from forming. |
| 127101 | */ |
| 127102 | SQLITE_API int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){ |
| 127103 | int oldLimit; |
| 127104 | |
| 127105 | |
| 127106 | /* EVIDENCE-OF: R-30189-54097 For each limit category SQLITE_LIMIT_NAME |
| 127107 | ** there is a hard upper bound set at compile-time by a C preprocessor |
| 127108 | ** macro called SQLITE_MAX_NAME. (The "_LIMIT_" in the name is changed to |
| 127109 | ** "_MAX_".) |
| @@ -128264,12 +127176,11 @@ | |
| 127176 | char c; |
| 127177 | int nUri = sqlite3Strlen30(zUri); |
| 127178 | |
| 127179 | assert( *pzErrMsg==0 ); |
| 127180 | |
| 127181 | if( ((flags & SQLITE_OPEN_URI) || sqlite3GlobalConfig.bOpenUri) |
| 127182 | && nUri>=5 && memcmp(zUri, "file:", 5)==0 /* IMP: R-57884-37496 */ |
| 127183 | ){ |
| 127184 | char *zOpt; |
| 127185 | int eState; /* Parser state when parsing URI */ |
| 127186 | int iIn; /* Input character index */ |
| @@ -128474,13 +127385,10 @@ | |
| 127385 | int rc; /* Return code */ |
| 127386 | int isThreadsafe; /* True for threadsafe connections */ |
| 127387 | char *zOpen = 0; /* Filename argument to pass to BtreeOpen() */ |
| 127388 | char *zErrMsg = 0; /* Error message from sqlite3ParseUri() */ |
| 127389 | |
| 127390 | *ppDb = 0; |
| 127391 | #ifndef SQLITE_OMIT_AUTOINIT |
| 127392 | rc = sqlite3_initialize(); |
| 127393 | if( rc ) return rc; |
| 127394 | #endif |
| @@ -128766,19 +127674,17 @@ | |
| 127674 | ){ |
| 127675 | char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */ |
| 127676 | sqlite3_value *pVal; |
| 127677 | int rc; |
| 127678 | |
| 127679 | assert( zFilename ); |
| 127680 | assert( ppDb ); |
| 127681 | *ppDb = 0; |
| 127682 | #ifndef SQLITE_OMIT_AUTOINIT |
| 127683 | rc = sqlite3_initialize(); |
| 127684 | if( rc ) return rc; |
| 127685 | #endif |
| 127686 | pVal = sqlite3ValueNew(0); |
| 127687 | sqlite3ValueSetStr(pVal, -1, zFilename, SQLITE_UTF16NATIVE, SQLITE_STATIC); |
| 127688 | zFilename8 = sqlite3ValueText(pVal, SQLITE_UTF8); |
| 127689 | if( zFilename8 ){ |
| 127690 | rc = openDatabase(zFilename8, ppDb, |
| @@ -128804,11 +127710,17 @@ | |
| 127710 | const char *zName, |
| 127711 | int enc, |
| 127712 | void* pCtx, |
| 127713 | int(*xCompare)(void*,int,const void*,int,const void*) |
| 127714 | ){ |
| 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; |
| 127722 | } |
| 127723 | |
| 127724 | /* |
| 127725 | ** Register a new collation sequence with the database handle db. |
| 127726 | */ |
| @@ -128819,14 +127731,10 @@ | |
| 127731 | void* pCtx, |
| 127732 | int(*xCompare)(void*,int,const void*,int,const void*), |
| 127733 | void(*xDel)(void*) |
| 127734 | ){ |
| 127735 | int rc; |
| 127736 | sqlite3_mutex_enter(db->mutex); |
| 127737 | assert( !db->mallocFailed ); |
| 127738 | rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, xDel); |
| 127739 | rc = sqlite3ApiExit(db, rc); |
| 127740 | sqlite3_mutex_leave(db->mutex); |
| @@ -128844,14 +127752,10 @@ | |
| 127752 | void* pCtx, |
| 127753 | int(*xCompare)(void*,int,const void*,int,const void*) |
| 127754 | ){ |
| 127755 | int rc = SQLITE_OK; |
| 127756 | char *zName8; |
| 127757 | sqlite3_mutex_enter(db->mutex); |
| 127758 | assert( !db->mallocFailed ); |
| 127759 | zName8 = sqlite3Utf16to8(db, zName, -1, SQLITE_UTF16NATIVE); |
| 127760 | if( zName8 ){ |
| 127761 | rc = createCollation(db, zName8, (u8)enc, pCtx, xCompare, 0); |
| @@ -128870,13 +127774,10 @@ | |
| 127774 | SQLITE_API int sqlite3_collation_needed( |
| 127775 | sqlite3 *db, |
| 127776 | void *pCollNeededArg, |
| 127777 | void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*) |
| 127778 | ){ |
| 127779 | sqlite3_mutex_enter(db->mutex); |
| 127780 | db->xCollNeeded = xCollNeeded; |
| 127781 | db->xCollNeeded16 = 0; |
| 127782 | db->pCollNeededArg = pCollNeededArg; |
| 127783 | sqlite3_mutex_leave(db->mutex); |
| @@ -128891,13 +127792,10 @@ | |
| 127792 | SQLITE_API int sqlite3_collation_needed16( |
| 127793 | sqlite3 *db, |
| 127794 | void *pCollNeededArg, |
| 127795 | void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*) |
| 127796 | ){ |
| 127797 | sqlite3_mutex_enter(db->mutex); |
| 127798 | db->xCollNeeded = 0; |
| 127799 | db->xCollNeeded16 = xCollNeeded16; |
| 127800 | db->pCollNeededArg = pCollNeededArg; |
| 127801 | sqlite3_mutex_leave(db->mutex); |
| @@ -128920,16 +127818,10 @@ | |
| 127818 | ** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on |
| 127819 | ** by default. Autocommit is disabled by a BEGIN statement and reenabled |
| 127820 | ** by the next COMMIT or ROLLBACK. |
| 127821 | */ |
| 127822 | SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){ |
| 127823 | return db->autoCommit; |
| 127824 | } |
| 127825 | |
| 127826 | /* |
| 127827 | ** The following routines are substitutes for constants SQLITE_CORRUPT, |
| @@ -129108,13 +128000,10 @@ | |
| 128000 | |
| 128001 | /* |
| 128002 | ** Enable or disable the extended result codes. |
| 128003 | */ |
| 128004 | SQLITE_API int sqlite3_extended_result_codes(sqlite3 *db, int onoff){ |
| 128005 | sqlite3_mutex_enter(db->mutex); |
| 128006 | db->errMask = onoff ? 0xffffffff : 0xff; |
| 128007 | sqlite3_mutex_leave(db->mutex); |
| 128008 | return SQLITE_OK; |
| 128009 | } |
| @@ -129124,13 +128013,10 @@ | |
| 128013 | */ |
| 128014 | SQLITE_API int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){ |
| 128015 | int rc = SQLITE_ERROR; |
| 128016 | Btree *pBtree; |
| 128017 | |
| 128018 | sqlite3_mutex_enter(db->mutex); |
| 128019 | pBtree = sqlite3DbNameToBtree(db, zDbName); |
| 128020 | if( pBtree ){ |
| 128021 | Pager *pPager; |
| 128022 | sqlite3_file *fd; |
| @@ -129469,11 +128355,11 @@ | |
| 128355 | ** query parameter we seek. This routine returns the value of the zParam |
| 128356 | ** parameter if it exists. If the parameter does not exist, this routine |
| 128357 | ** returns a NULL pointer. |
| 128358 | */ |
| 128359 | SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){ |
| 128360 | if( zFilename==0 ) return 0; |
| 128361 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 128362 | while( zFilename[0] ){ |
| 128363 | int x = strcmp(zFilename, zParam); |
| 128364 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 128365 | if( x==0 ) return zFilename; |
| @@ -129525,31 +128411,19 @@ | |
| 128411 | /* |
| 128412 | ** Return the filename of the database associated with a database |
| 128413 | ** connection. |
| 128414 | */ |
| 128415 | SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){ |
| 128416 | Btree *pBt = sqlite3DbNameToBtree(db, zDbName); |
| 128417 | return pBt ? sqlite3BtreeGetFilename(pBt) : 0; |
| 128418 | } |
| 128419 | |
| 128420 | /* |
| 128421 | ** Return 1 if database is read-only or 0 if read/write. Return -1 if |
| 128422 | ** no such database exists. |
| 128423 | */ |
| 128424 | SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){ |
| 128425 | Btree *pBt = sqlite3DbNameToBtree(db, zDbName); |
| 128426 | return pBt ? sqlite3BtreeIsReadonly(pBt) : -1; |
| 128427 | } |
| 128428 | |
| 128429 | /************** End of main.c ************************************************/ |
| 128430 |
+182
-312
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -55,11 +55,11 @@ | ||
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | /* |
| 58 | 58 | ** These no-op macros are used in front of interfaces to mark those |
| 59 | 59 | ** interfaces as either deprecated or experimental. New applications |
| 60 | -** should not use deprecated interfaces - they are supported for backwards | |
| 60 | +** should not use deprecated interfaces - they are support for backwards | |
| 61 | 61 | ** compatibility only. Application writers should be aware that |
| 62 | 62 | ** experimental interfaces are subject to change in point releases. |
| 63 | 63 | ** |
| 64 | 64 | ** These macros used to resolve to various kinds of compiler magic that |
| 65 | 65 | ** would generate warning messages when they were used. But that |
| @@ -105,13 +105,13 @@ | ||
| 105 | 105 | ** |
| 106 | 106 | ** See also: [sqlite3_libversion()], |
| 107 | 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | 109 | */ |
| 110 | -#define SQLITE_VERSION "3.8.8" | |
| 111 | -#define SQLITE_VERSION_NUMBER 3008008 | |
| 112 | -#define SQLITE_SOURCE_ID "2014-11-18 21:54:31 4461bf045d8eecf98478035efcdba3f41c709bc5" | |
| 110 | +#define SQLITE_VERSION "3.8.7.2" | |
| 111 | +#define SQLITE_VERSION_NUMBER 3008007 | |
| 112 | +#define SQLITE_SOURCE_ID "2014-11-18 20:57:56 2ab564bf9655b7c7b97ab85cafc8a48329b27f93" | |
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| @@ -1502,31 +1502,29 @@ | ||
| 1502 | 1502 | ** it is not possible to set the Serialized [threading mode] and |
| 1503 | 1503 | ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
| 1504 | 1504 | ** SQLITE_CONFIG_SERIALIZED configuration option.</dd> |
| 1505 | 1505 | ** |
| 1506 | 1506 | ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt> |
| 1507 | -** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is | |
| 1508 | -** a pointer to an instance of the [sqlite3_mem_methods] structure. | |
| 1509 | -** The argument specifies | |
| 1507 | +** <dd> ^(This option takes a single argument which is a pointer to an | |
| 1508 | +** instance of the [sqlite3_mem_methods] structure. The argument specifies | |
| 1510 | 1509 | ** alternative low-level memory allocation routines to be used in place of |
| 1511 | 1510 | ** the memory allocation routines built into SQLite.)^ ^SQLite makes |
| 1512 | 1511 | ** its own private copy of the content of the [sqlite3_mem_methods] structure |
| 1513 | 1512 | ** before the [sqlite3_config()] call returns.</dd> |
| 1514 | 1513 | ** |
| 1515 | 1514 | ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt> |
| 1516 | -** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which | |
| 1517 | -** is a pointer to an instance of the [sqlite3_mem_methods] structure. | |
| 1518 | -** The [sqlite3_mem_methods] | |
| 1515 | +** <dd> ^(This option takes a single argument which is a pointer to an | |
| 1516 | +** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods] | |
| 1519 | 1517 | ** structure is filled with the currently defined memory allocation routines.)^ |
| 1520 | 1518 | ** This option can be used to overload the default memory allocation |
| 1521 | 1519 | ** routines with a wrapper that simulations memory allocation failure or |
| 1522 | 1520 | ** tracks memory usage, for example. </dd> |
| 1523 | 1521 | ** |
| 1524 | 1522 | ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> |
| 1525 | -** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int, | |
| 1526 | -** interpreted as a boolean, which enables or disables the collection of | |
| 1527 | -** memory allocation statistics. ^(When memory allocation statistics are disabled, the | |
| 1523 | +** <dd> ^This option takes single argument of type int, interpreted as a | |
| 1524 | +** boolean, which enables or disables the collection of memory allocation | |
| 1525 | +** statistics. ^(When memory allocation statistics are disabled, the | |
| 1528 | 1526 | ** following SQLite interfaces become non-operational: |
| 1529 | 1527 | ** <ul> |
| 1530 | 1528 | ** <li> [sqlite3_memory_used()] |
| 1531 | 1529 | ** <li> [sqlite3_memory_highwater()] |
| 1532 | 1530 | ** <li> [sqlite3_soft_heap_limit64()] |
| @@ -1536,90 +1534,78 @@ | ||
| 1536 | 1534 | ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory |
| 1537 | 1535 | ** allocation statistics are disabled by default. |
| 1538 | 1536 | ** </dd> |
| 1539 | 1537 | ** |
| 1540 | 1538 | ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt> |
| 1541 | -** <dd> ^The SQLITE_CONFIG_SCRATCH option specifies a static memory buffer | |
| 1542 | -** that SQLite can use for scratch memory. ^(There are three arguments | |
| 1543 | -** to SQLITE_CONFIG_SCRATCH: A pointer an 8-byte | |
| 1539 | +** <dd> ^This option specifies a static memory buffer that SQLite can use for | |
| 1540 | +** scratch memory. There are three arguments: A pointer an 8-byte | |
| 1544 | 1541 | ** aligned memory buffer from which the scratch allocations will be |
| 1545 | 1542 | ** drawn, the size of each scratch allocation (sz), |
| 1546 | -** and the maximum number of scratch allocations (N).)^ | |
| 1543 | +** and the maximum number of scratch allocations (N). The sz | |
| 1544 | +** argument must be a multiple of 16. | |
| 1547 | 1545 | ** The first argument must be a pointer to an 8-byte aligned buffer |
| 1548 | 1546 | ** of at least sz*N bytes of memory. |
| 1549 | -** ^SQLite will not use more than one scratch buffers per thread. | |
| 1550 | -** ^SQLite will never request a scratch buffer that is more than 6 | |
| 1551 | -** times the database page size. | |
| 1552 | -** ^If SQLite needs needs additional | |
| 1547 | +** ^SQLite will use no more than two scratch buffers per thread. So | |
| 1548 | +** N should be set to twice the expected maximum number of threads. | |
| 1549 | +** ^SQLite will never require a scratch buffer that is more than 6 | |
| 1550 | +** times the database page size. ^If SQLite needs needs additional | |
| 1553 | 1551 | ** scratch memory beyond what is provided by this configuration option, then |
| 1554 | -** [sqlite3_malloc()] will be used to obtain the memory needed.<p> | |
| 1555 | -** ^When the application provides any amount of scratch memory using | |
| 1556 | -** SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary large | |
| 1557 | -** [sqlite3_malloc|heap allocations]. | |
| 1558 | -** This can help [Robson proof|prevent memory allocation failures] due to heap | |
| 1559 | -** fragmentation in low-memory embedded systems. | |
| 1560 | -** </dd> | |
| 1552 | +** [sqlite3_malloc()] will be used to obtain the memory needed.</dd> | |
| 1561 | 1553 | ** |
| 1562 | 1554 | ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt> |
| 1563 | -** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a static memory buffer | |
| 1564 | -** that SQLite can use for the database page cache with the default page | |
| 1565 | -** cache implementation. | |
| 1555 | +** <dd> ^This option specifies a static memory buffer that SQLite can use for | |
| 1556 | +** the database page cache with the default page cache implementation. | |
| 1566 | 1557 | ** This configuration should not be used if an application-define page |
| 1567 | -** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2] | |
| 1568 | -** configuration option. | |
| 1569 | -** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned | |
| 1558 | +** cache implementation is loaded using the SQLITE_CONFIG_PCACHE2 option. | |
| 1559 | +** There are three arguments to this option: A pointer to 8-byte aligned | |
| 1570 | 1560 | ** memory, the size of each page buffer (sz), and the number of pages (N). |
| 1571 | 1561 | ** The sz argument should be the size of the largest database page |
| 1572 | -** (a power of two between 512 and 32768) plus some extra bytes for each | |
| 1573 | -** page header. ^The number of extra bytes needed by the page header | |
| 1574 | -** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option | |
| 1575 | -** to [sqlite3_config()]. | |
| 1576 | -** ^It is harmless, apart from the wasted memory, | |
| 1577 | -** for the sz parameter to be larger than necessary. The first | |
| 1578 | -** argument should pointer to an 8-byte aligned block of memory that | |
| 1579 | -** is at least sz*N bytes of memory, otherwise subsequent behavior is | |
| 1580 | -** undefined. | |
| 1562 | +** (a power of two between 512 and 32768) plus a little extra for each | |
| 1563 | +** page header. ^The page header size is 20 to 40 bytes depending on | |
| 1564 | +** the host architecture. ^It is harmless, apart from the wasted memory, | |
| 1565 | +** to make sz a little too large. The first | |
| 1566 | +** argument should point to an allocation of at least sz*N bytes of memory. | |
| 1581 | 1567 | ** ^SQLite will use the memory provided by the first argument to satisfy its |
| 1582 | 1568 | ** memory needs for the first N pages that it adds to cache. ^If additional |
| 1583 | 1569 | ** page cache memory is needed beyond what is provided by this option, then |
| 1584 | -** SQLite goes to [sqlite3_malloc()] for the additional storage space.</dd> | |
| 1570 | +** SQLite goes to [sqlite3_malloc()] for the additional storage space. | |
| 1571 | +** The pointer in the first argument must | |
| 1572 | +** be aligned to an 8-byte boundary or subsequent behavior of SQLite | |
| 1573 | +** will be undefined.</dd> | |
| 1585 | 1574 | ** |
| 1586 | 1575 | ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> |
| 1587 | -** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer | |
| 1588 | -** that SQLite will use for all of its dynamic memory allocation needs | |
| 1589 | -** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. | |
| 1590 | -** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled | |
| 1591 | -** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns | |
| 1592 | -** [SQLITE_ERROR] if invoked otherwise. | |
| 1593 | -** ^There are three arguments to SQLITE_CONFIG_HEAP: | |
| 1594 | -** An 8-byte aligned pointer to the memory, | |
| 1576 | +** <dd> ^This option specifies a static memory buffer that SQLite will use | |
| 1577 | +** for all of its dynamic memory allocation needs beyond those provided | |
| 1578 | +** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. | |
| 1579 | +** There are three arguments: An 8-byte aligned pointer to the memory, | |
| 1595 | 1580 | ** the number of bytes in the memory buffer, and the minimum allocation size. |
| 1596 | 1581 | ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts |
| 1597 | 1582 | ** to using its default memory allocator (the system malloc() implementation), |
| 1598 | 1583 | ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the |
| 1599 | -** memory pointer is not NULL then the alternative memory | |
| 1584 | +** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or | |
| 1585 | +** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory | |
| 1600 | 1586 | ** allocator is engaged to handle all of SQLites memory allocation needs. |
| 1601 | 1587 | ** The first pointer (the memory pointer) must be aligned to an 8-byte |
| 1602 | 1588 | ** boundary or subsequent behavior of SQLite will be undefined. |
| 1603 | 1589 | ** The minimum allocation size is capped at 2**12. Reasonable values |
| 1604 | 1590 | ** for the minimum allocation size are 2**5 through 2**8.</dd> |
| 1605 | 1591 | ** |
| 1606 | 1592 | ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt> |
| 1607 | -** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a | |
| 1608 | -** pointer to an instance of the [sqlite3_mutex_methods] structure. | |
| 1609 | -** The argument specifies alternative low-level mutex routines to be used in place | |
| 1593 | +** <dd> ^(This option takes a single argument which is a pointer to an | |
| 1594 | +** instance of the [sqlite3_mutex_methods] structure. The argument specifies | |
| 1595 | +** alternative low-level mutex routines to be used in place | |
| 1610 | 1596 | ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the |
| 1611 | 1597 | ** content of the [sqlite3_mutex_methods] structure before the call to |
| 1612 | 1598 | ** [sqlite3_config()] returns. ^If SQLite is compiled with |
| 1613 | 1599 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1614 | 1600 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1615 | 1601 | ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will |
| 1616 | 1602 | ** return [SQLITE_ERROR].</dd> |
| 1617 | 1603 | ** |
| 1618 | 1604 | ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt> |
| 1619 | -** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which | |
| 1620 | -** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The | |
| 1605 | +** <dd> ^(This option takes a single argument which is a pointer to an | |
| 1606 | +** instance of the [sqlite3_mutex_methods] structure. The | |
| 1621 | 1607 | ** [sqlite3_mutex_methods] |
| 1622 | 1608 | ** structure is filled with the currently defined mutex routines.)^ |
| 1623 | 1609 | ** This option can be used to overload the default mutex allocation |
| 1624 | 1610 | ** routines with a wrapper used to track mutex usage for performance |
| 1625 | 1611 | ** profiling or testing, for example. ^If SQLite is compiled with |
| @@ -1627,28 +1613,28 @@ | ||
| 1627 | 1613 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1628 | 1614 | ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will |
| 1629 | 1615 | ** return [SQLITE_ERROR].</dd> |
| 1630 | 1616 | ** |
| 1631 | 1617 | ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt> |
| 1632 | -** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine | |
| 1633 | -** the default size of lookaside memory on each [database connection]. | |
| 1634 | -** The first argument is the | |
| 1618 | +** <dd> ^(This option takes two arguments that determine the default | |
| 1619 | +** memory allocation for the lookaside memory allocator on each | |
| 1620 | +** [database connection]. The first argument is the | |
| 1635 | 1621 | ** size of each lookaside buffer slot and the second is the number of |
| 1636 | -** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE | |
| 1637 | -** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] | |
| 1638 | -** option to [sqlite3_db_config()] can be used to change the lookaside | |
| 1622 | +** slots allocated to each database connection.)^ ^(This option sets the | |
| 1623 | +** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] | |
| 1624 | +** verb to [sqlite3_db_config()] can be used to change the lookaside | |
| 1639 | 1625 | ** configuration on individual connections.)^ </dd> |
| 1640 | 1626 | ** |
| 1641 | 1627 | ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt> |
| 1642 | -** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is | |
| 1643 | -** a pointer to an [sqlite3_pcache_methods2] object. This object specifies | |
| 1644 | -** the interface to a custom page cache implementation.)^ | |
| 1645 | -** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd> | |
| 1628 | +** <dd> ^(This option takes a single argument which is a pointer to | |
| 1629 | +** an [sqlite3_pcache_methods2] object. This object specifies the interface | |
| 1630 | +** to a custom page cache implementation.)^ ^SQLite makes a copy of the | |
| 1631 | +** object and uses it for page cache memory allocations.</dd> | |
| 1646 | 1632 | ** |
| 1647 | 1633 | ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt> |
| 1648 | -** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which | |
| 1649 | -** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of the current | |
| 1634 | +** <dd> ^(This option takes a single argument which is a pointer to an | |
| 1635 | +** [sqlite3_pcache_methods2] object. SQLite copies of the current | |
| 1650 | 1636 | ** page cache implementation into that object.)^ </dd> |
| 1651 | 1637 | ** |
| 1652 | 1638 | ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> |
| 1653 | 1639 | ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite |
| 1654 | 1640 | ** global [error log]. |
| @@ -1668,27 +1654,26 @@ | ||
| 1668 | 1654 | ** supplied by the application must not invoke any SQLite interface. |
| 1669 | 1655 | ** In a multi-threaded application, the application-defined logger |
| 1670 | 1656 | ** function must be threadsafe. </dd> |
| 1671 | 1657 | ** |
| 1672 | 1658 | ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI |
| 1673 | -** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int. | |
| 1674 | -** If non-zero, then URI handling is globally enabled. If the parameter is zero, | |
| 1675 | -** then URI handling is globally disabled.)^ ^If URI handling is globally enabled, | |
| 1676 | -** all filenames passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or | |
| 1659 | +** <dd>^(This option takes a single argument of type int. If non-zero, then | |
| 1660 | +** URI handling is globally enabled. If the parameter is zero, then URI handling | |
| 1661 | +** is globally disabled.)^ ^If URI handling is globally enabled, all filenames | |
| 1662 | +** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or | |
| 1677 | 1663 | ** specified as part of [ATTACH] commands are interpreted as URIs, regardless |
| 1678 | 1664 | ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database |
| 1679 | 1665 | ** connection is opened. ^If it is globally disabled, filenames are |
| 1680 | 1666 | ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the |
| 1681 | 1667 | ** database connection is opened. ^(By default, URI handling is globally |
| 1682 | 1668 | ** disabled. The default value may be changed by compiling with the |
| 1683 | 1669 | ** [SQLITE_USE_URI] symbol defined.)^ |
| 1684 | 1670 | ** |
| 1685 | 1671 | ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN |
| 1686 | -** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer | |
| 1687 | -** argument which is interpreted as a boolean in order to enable or disable | |
| 1688 | -** the use of covering indices for full table scans in the query optimizer. | |
| 1689 | -** ^The default setting is determined | |
| 1672 | +** <dd>^This option takes a single integer argument which is interpreted as | |
| 1673 | +** a boolean in order to enable or disable the use of covering indices for | |
| 1674 | +** full table scans in the query optimizer. ^The default setting is determined | |
| 1690 | 1675 | ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on" |
| 1691 | 1676 | ** if that compile-time option is omitted. |
| 1692 | 1677 | ** The ability to disable the use of covering indices for full table scans |
| 1693 | 1678 | ** is because some incorrectly coded legacy applications might malfunction |
| 1694 | 1679 | ** when the optimization is enabled. Providing the ability to |
| @@ -1724,32 +1709,23 @@ | ||
| 1724 | 1709 | ** that are the default mmap size limit (the default setting for |
| 1725 | 1710 | ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit. |
| 1726 | 1711 | ** ^The default setting can be overridden by each database connection using |
| 1727 | 1712 | ** either the [PRAGMA mmap_size] command, or by using the |
| 1728 | 1713 | ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size |
| 1729 | -** will be silently truncated if necessary so that it does not exceed the | |
| 1730 | -** compile-time maximum mmap size set by the | |
| 1714 | +** cannot be changed at run-time. Nor may the maximum allowed mmap size | |
| 1715 | +** exceed the compile-time maximum mmap size set by the | |
| 1731 | 1716 | ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^ |
| 1732 | 1717 | ** ^If either argument to this option is negative, then that argument is |
| 1733 | 1718 | ** changed to its compile-time default. |
| 1734 | 1719 | ** |
| 1735 | 1720 | ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]] |
| 1736 | 1721 | ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE |
| 1737 | -** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is | |
| 1738 | -** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro defined. | |
| 1739 | -** ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value | |
| 1722 | +** <dd>^This option is only available if SQLite is compiled for Windows | |
| 1723 | +** with the [SQLITE_WIN32_MALLOC] pre-processor macro defined. | |
| 1724 | +** SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value | |
| 1740 | 1725 | ** that specifies the maximum size of the created heap. |
| 1741 | 1726 | ** </dl> |
| 1742 | -** | |
| 1743 | -** [[SQLITE_CONFIG_PCACHE_HDRSZ]] | |
| 1744 | -** <dt>SQLITE_CONFIG_PCACHE_HDRSZ | |
| 1745 | -** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which | |
| 1746 | -** is a pointer to an integer and writes into that integer the number of extra | |
| 1747 | -** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE]. The amount of | |
| 1748 | -** extra space required can change depending on the compiler, | |
| 1749 | -** target platform, and SQLite version. | |
| 1750 | -** </dl> | |
| 1751 | 1727 | */ |
| 1752 | 1728 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1753 | 1729 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 1754 | 1730 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| 1755 | 1731 | #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ |
| @@ -1770,11 +1746,10 @@ | ||
| 1770 | 1746 | #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */ |
| 1771 | 1747 | #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */ |
| 1772 | 1748 | #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */ |
| 1773 | 1749 | #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */ |
| 1774 | 1750 | #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */ |
| 1775 | -#define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */ | |
| 1776 | 1751 | |
| 1777 | 1752 | /* |
| 1778 | 1753 | ** CAPI3REF: Database Connection Configuration Options |
| 1779 | 1754 | ** |
| 1780 | 1755 | ** These constants are the available integer configuration options that |
| @@ -1898,49 +1873,51 @@ | ||
| 1898 | 1873 | SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); |
| 1899 | 1874 | |
| 1900 | 1875 | /* |
| 1901 | 1876 | ** CAPI3REF: Count The Number Of Rows Modified |
| 1902 | 1877 | ** |
| 1903 | -** ^This function returns the number of rows modified, inserted or | |
| 1904 | -** deleted by the most recently completed INSERT, UPDATE or DELETE | |
| 1905 | -** statement on the database connection specified by the only parameter. | |
| 1906 | -** ^Executing any other type of SQL statement does not modify the value | |
| 1907 | -** returned by this function. | |
| 1908 | -** | |
| 1909 | -** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are | |
| 1910 | -** considered - auxiliary changes caused by [CREATE TRIGGER | triggers], | |
| 1911 | -** [foreign key actions] or [REPLACE] constraint resolution are not counted. | |
| 1912 | -** | |
| 1913 | -** Changes to a view that are intercepted by | |
| 1914 | -** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value | |
| 1915 | -** returned by sqlite3_changes() immediately after an INSERT, UPDATE or | |
| 1916 | -** DELETE statement run on a view is always zero. Only changes made to real | |
| 1917 | -** tables are counted. | |
| 1918 | -** | |
| 1919 | -** Things are more complicated if the sqlite3_changes() function is | |
| 1920 | -** executed while a trigger program is running. This may happen if the | |
| 1921 | -** program uses the [changes() SQL function], or if some other callback | |
| 1922 | -** function invokes sqlite3_changes() directly. Essentially: | |
| 1923 | -** | |
| 1924 | -** <ul> | |
| 1925 | -** <li> ^(Before entering a trigger program the value returned by | |
| 1926 | -** sqlite3_changes() function is saved. After the trigger program | |
| 1927 | -** has finished, the original value is restored.)^ | |
| 1928 | -** | |
| 1929 | -** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE | |
| 1930 | -** statement sets the value returned by sqlite3_changes() | |
| 1931 | -** upon completion as normal. Of course, this value will not include | |
| 1932 | -** any changes performed by sub-triggers, as the sqlite3_changes() | |
| 1933 | -** value will be saved and restored after each sub-trigger has run.)^ | |
| 1934 | -** </ul> | |
| 1935 | -** | |
| 1936 | -** ^This means that if the changes() SQL function (or similar) is used | |
| 1937 | -** by the first INSERT, UPDATE or DELETE statement within a trigger, it | |
| 1938 | -** returns the value as set when the calling statement began executing. | |
| 1939 | -** ^If it is used by the second or subsequent such statement within a trigger | |
| 1940 | -** program, the value returned reflects the number of rows modified by the | |
| 1941 | -** previous INSERT, UPDATE or DELETE statement within the same trigger. | |
| 1878 | +** ^This function returns the number of database rows that were changed | |
| 1879 | +** or inserted or deleted by the most recently completed SQL statement | |
| 1880 | +** on the [database connection] specified by the first parameter. | |
| 1881 | +** ^(Only changes that are directly specified by the [INSERT], [UPDATE], | |
| 1882 | +** or [DELETE] statement are counted. Auxiliary changes caused by | |
| 1883 | +** triggers or [foreign key actions] are not counted.)^ Use the | |
| 1884 | +** [sqlite3_total_changes()] function to find the total number of changes | |
| 1885 | +** including changes caused by triggers and foreign key actions. | |
| 1886 | +** | |
| 1887 | +** ^Changes to a view that are simulated by an [INSTEAD OF trigger] | |
| 1888 | +** are not counted. Only real table changes are counted. | |
| 1889 | +** | |
| 1890 | +** ^(A "row change" is a change to a single row of a single table | |
| 1891 | +** caused by an INSERT, DELETE, or UPDATE statement. Rows that | |
| 1892 | +** are changed as side effects of [REPLACE] constraint resolution, | |
| 1893 | +** rollback, ABORT processing, [DROP TABLE], or by any other | |
| 1894 | +** mechanisms do not count as direct row changes.)^ | |
| 1895 | +** | |
| 1896 | +** A "trigger context" is a scope of execution that begins and | |
| 1897 | +** ends with the script of a [CREATE TRIGGER | trigger]. | |
| 1898 | +** Most SQL statements are | |
| 1899 | +** evaluated outside of any trigger. This is the "top level" | |
| 1900 | +** trigger context. If a trigger fires from the top level, a | |
| 1901 | +** new trigger context is entered for the duration of that one | |
| 1902 | +** trigger. Subtriggers create subcontexts for their duration. | |
| 1903 | +** | |
| 1904 | +** ^Calling [sqlite3_exec()] or [sqlite3_step()] recursively does | |
| 1905 | +** not create a new trigger context. | |
| 1906 | +** | |
| 1907 | +** ^This function returns the number of direct row changes in the | |
| 1908 | +** most recent INSERT, UPDATE, or DELETE statement within the same | |
| 1909 | +** trigger context. | |
| 1910 | +** | |
| 1911 | +** ^Thus, when called from the top level, this function returns the | |
| 1912 | +** number of changes in the most recent INSERT, UPDATE, or DELETE | |
| 1913 | +** that also occurred at the top level. ^(Within the body of a trigger, | |
| 1914 | +** the sqlite3_changes() interface can be called to find the number of | |
| 1915 | +** changes in the most recently completed INSERT, UPDATE, or DELETE | |
| 1916 | +** statement within the body of the same trigger. | |
| 1917 | +** However, the number returned does not include changes | |
| 1918 | +** caused by subtriggers since those have their own context.)^ | |
| 1942 | 1919 | ** |
| 1943 | 1920 | ** See also the [sqlite3_total_changes()] interface, the |
| 1944 | 1921 | ** [count_changes pragma], and the [changes() SQL function]. |
| 1945 | 1922 | ** |
| 1946 | 1923 | ** If a separate thread makes changes on the same database connection |
| @@ -1950,21 +1927,24 @@ | ||
| 1950 | 1927 | SQLITE_API int sqlite3_changes(sqlite3*); |
| 1951 | 1928 | |
| 1952 | 1929 | /* |
| 1953 | 1930 | ** CAPI3REF: Total Number Of Rows Modified |
| 1954 | 1931 | ** |
| 1955 | -** ^This function returns the total number of rows inserted, modified or | |
| 1956 | -** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed | |
| 1957 | -** since the database connection was opened, including those executed as | |
| 1958 | -** part of trigger programs. ^Executing any other type of SQL statement | |
| 1959 | -** does not affect the value returned by sqlite3_total_changes(). | |
| 1960 | -** | |
| 1961 | -** ^Changes made as part of [foreign key actions] are included in the | |
| 1962 | -** count, but those made as part of REPLACE constraint resolution are | |
| 1963 | -** not. ^Changes to a view that are intercepted by INSTEAD OF triggers | |
| 1964 | -** are not counted. | |
| 1965 | -** | |
| 1932 | +** ^This function returns the number of row changes caused by [INSERT], | |
| 1933 | +** [UPDATE] or [DELETE] statements since the [database connection] was opened. | |
| 1934 | +** ^(The count returned by sqlite3_total_changes() includes all changes | |
| 1935 | +** from all [CREATE TRIGGER | trigger] contexts and changes made by | |
| 1936 | +** [foreign key actions]. However, | |
| 1937 | +** the count does not include changes used to implement [REPLACE] constraints, | |
| 1938 | +** do rollbacks or ABORT processing, or [DROP TABLE] processing. The | |
| 1939 | +** count does not include rows of views that fire an [INSTEAD OF trigger], | |
| 1940 | +** though if the INSTEAD OF trigger makes changes of its own, those changes | |
| 1941 | +** are counted.)^ | |
| 1942 | +** ^The sqlite3_total_changes() function counts the changes as soon as | |
| 1943 | +** the statement that makes them is completed (when the statement handle | |
| 1944 | +** is passed to [sqlite3_reset()] or [sqlite3_finalize()]). | |
| 1945 | +** | |
| 1966 | 1946 | ** See also the [sqlite3_changes()] interface, the |
| 1967 | 1947 | ** [count_changes pragma], and the [total_changes() SQL function]. |
| 1968 | 1948 | ** |
| 1969 | 1949 | ** If a separate thread makes changes on the same database connection |
| 1970 | 1950 | ** while [sqlite3_total_changes()] is running then the value |
| @@ -2438,18 +2418,17 @@ | ||
| 2438 | 2418 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2439 | 2419 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2440 | 2420 | ** applications to access the same PRNG for other purposes. |
| 2441 | 2421 | ** |
| 2442 | 2422 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2443 | -** ^The P parameter can be a NULL pointer. | |
| 2423 | +** ^If N is less than one, then P can be a NULL pointer. | |
| 2444 | 2424 | ** |
| 2445 | 2425 | ** ^If this routine has not been previously called or if the previous |
| 2446 | -** call had N less than one or a NULL pointer for P, then the PRNG is | |
| 2447 | -** seeded using randomness obtained from the xRandomness method of | |
| 2448 | -** the default [sqlite3_vfs] object. | |
| 2449 | -** ^If the previous call to this routine had an N of 1 or more and a | |
| 2450 | -** non-NULL P then the pseudo-randomness is generated | |
| 2426 | +** call had N less than one, then the PRNG is seeded using randomness | |
| 2427 | +** obtained from the xRandomness method of the default [sqlite3_vfs] object. | |
| 2428 | +** ^If the previous call to this routine had an N of 1 or more then | |
| 2429 | +** the pseudo-randomness is generated | |
| 2451 | 2430 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2452 | 2431 | ** method. |
| 2453 | 2432 | */ |
| 2454 | 2433 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2455 | 2434 | |
| @@ -5660,46 +5639,30 @@ | ||
| 5660 | 5639 | ** |
| 5661 | 5640 | ** <pre> |
| 5662 | 5641 | ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow; |
| 5663 | 5642 | ** </pre>)^ |
| 5664 | 5643 | ** |
| 5665 | -** ^(Parameter zDb is not the filename that contains the database, but | |
| 5666 | -** rather the symbolic name of the database. For attached databases, this is | |
| 5667 | -** the name that appears after the AS keyword in the [ATTACH] statement. | |
| 5668 | -** For the main database file, the database name is "main". For TEMP | |
| 5669 | -** tables, the database name is "temp".)^ | |
| 5670 | -** | |
| 5671 | 5644 | ** ^If the flags parameter is non-zero, then the BLOB is opened for read |
| 5672 | -** and write access. ^If the flags parameter is zero, the BLOB is opened for | |
| 5673 | -** read-only access. | |
| 5674 | -** | |
| 5675 | -** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored | |
| 5676 | -** in *ppBlob. Otherwise an [error code] is returned and, unless the error | |
| 5677 | -** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided | |
| 5678 | -** the API is not misused, it is always safe to call [sqlite3_blob_close()] | |
| 5679 | -** on *ppBlob after this function it returns. | |
| 5680 | -** | |
| 5681 | -** This function fails with SQLITE_ERROR if any of the following are true: | |
| 5682 | -** <ul> | |
| 5683 | -** <li> ^(Database zDb does not exist)^, | |
| 5684 | -** <li> ^(Table zTable does not exist within database zDb)^, | |
| 5685 | -** <li> ^(Table zTable is a WITHOUT ROWID table)^, | |
| 5686 | -** <li> ^(Column zColumn does not exist)^, | |
| 5687 | -** <li> ^(Row iRow is not present in the table)^, | |
| 5688 | -** <li> ^(The specified column of row iRow contains a value that is not | |
| 5689 | -** a TEXT or BLOB value)^, | |
| 5690 | -** <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE | |
| 5691 | -** constraint and the blob is being opened for read/write access)^, | |
| 5692 | -** <li> ^([foreign key constraints | Foreign key constraints] are enabled, | |
| 5693 | -** column zColumn is part of a [child key] definition and the blob is | |
| 5694 | -** being opened for read/write access)^. | |
| 5695 | -** </ul> | |
| 5696 | -** | |
| 5697 | -** ^Unless it returns SQLITE_MISUSE, this function sets the | |
| 5698 | -** [database connection] error code and message accessible via | |
| 5699 | -** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. | |
| 5700 | -** | |
| 5645 | +** and write access. ^If it is zero, the BLOB is opened for read access. | |
| 5646 | +** ^It is not possible to open a column that is part of an index or primary | |
| 5647 | +** key for writing. ^If [foreign key constraints] are enabled, it is | |
| 5648 | +** not possible to open a column that is part of a [child key] for writing. | |
| 5649 | +** | |
| 5650 | +** ^Note that the database name is not the filename that contains | |
| 5651 | +** the database but rather the symbolic name of the database that | |
| 5652 | +** appears after the AS keyword when the database is connected using [ATTACH]. | |
| 5653 | +** ^For the main database file, the database name is "main". | |
| 5654 | +** ^For TEMP tables, the database name is "temp". | |
| 5655 | +** | |
| 5656 | +** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is written | |
| 5657 | +** to *ppBlob. Otherwise an [error code] is returned and *ppBlob is set | |
| 5658 | +** to be a null pointer.)^ | |
| 5659 | +** ^This function sets the [database connection] error code and message | |
| 5660 | +** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()] and related | |
| 5661 | +** functions. ^Note that the *ppBlob variable is always initialized in a | |
| 5662 | +** way that makes it safe to invoke [sqlite3_blob_close()] on *ppBlob | |
| 5663 | +** regardless of the success or failure of this routine. | |
| 5701 | 5664 | ** |
| 5702 | 5665 | ** ^(If the row that a BLOB handle points to is modified by an |
| 5703 | 5666 | ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects |
| 5704 | 5667 | ** then the BLOB handle is marked as "expired". |
| 5705 | 5668 | ** This is true if any column of the row is changed, even a column |
| @@ -5713,13 +5676,17 @@ | ||
| 5713 | 5676 | ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of |
| 5714 | 5677 | ** the opened blob. ^The size of a blob may not be changed by this |
| 5715 | 5678 | ** interface. Use the [UPDATE] SQL command to change the size of a |
| 5716 | 5679 | ** blob. |
| 5717 | 5680 | ** |
| 5681 | +** ^The [sqlite3_blob_open()] interface will fail for a [WITHOUT ROWID] | |
| 5682 | +** table. Incremental BLOB I/O is not possible on [WITHOUT ROWID] tables. | |
| 5683 | +** | |
| 5718 | 5684 | ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces |
| 5719 | -** and the built-in [zeroblob] SQL function may be used to create a | |
| 5720 | -** zero-filled blob to read or write using the incremental-blob interface. | |
| 5685 | +** and the built-in [zeroblob] SQL function can be used, if desired, | |
| 5686 | +** to create an empty, zero-filled blob in which to read or write using | |
| 5687 | +** this interface. | |
| 5721 | 5688 | ** |
| 5722 | 5689 | ** To avoid a resource leak, every open [BLOB handle] should eventually |
| 5723 | 5690 | ** be released by a call to [sqlite3_blob_close()]. |
| 5724 | 5691 | */ |
| 5725 | 5692 | SQLITE_API int sqlite3_blob_open( |
| @@ -5757,26 +5724,28 @@ | ||
| 5757 | 5724 | SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); |
| 5758 | 5725 | |
| 5759 | 5726 | /* |
| 5760 | 5727 | ** CAPI3REF: Close A BLOB Handle |
| 5761 | 5728 | ** |
| 5762 | -** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed | |
| 5763 | -** unconditionally. Even if this routine returns an error code, the | |
| 5764 | -** handle is still closed.)^ | |
| 5765 | -** | |
| 5766 | -** ^If the blob handle being closed was opened for read-write access, and if | |
| 5767 | -** the database is in auto-commit mode and there are no other open read-write | |
| 5768 | -** blob handles or active write statements, the current transaction is | |
| 5769 | -** committed. ^If an error occurs while committing the transaction, an error | |
| 5770 | -** code is returned and the transaction rolled back. | |
| 5771 | -** | |
| 5772 | -** Calling this function with an argument that is not a NULL pointer or an | |
| 5773 | -** open blob handle results in undefined behaviour. ^Calling this routine | |
| 5774 | -** with a null pointer (such as would be returned by a failed call to | |
| 5775 | -** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function | |
| 5776 | -** is passed a valid open blob handle, the values returned by the | |
| 5777 | -** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning. | |
| 5729 | +** ^Closes an open [BLOB handle]. | |
| 5730 | +** | |
| 5731 | +** ^Closing a BLOB shall cause the current transaction to commit | |
| 5732 | +** if there are no other BLOBs, no pending prepared statements, and the | |
| 5733 | +** database connection is in [autocommit mode]. | |
| 5734 | +** ^If any writes were made to the BLOB, they might be held in cache | |
| 5735 | +** until the close operation if they will fit. | |
| 5736 | +** | |
| 5737 | +** ^(Closing the BLOB often forces the changes | |
| 5738 | +** out to disk and so if any I/O errors occur, they will likely occur | |
| 5739 | +** at the time when the BLOB is closed. Any errors that occur during | |
| 5740 | +** closing are reported as a non-zero return value.)^ | |
| 5741 | +** | |
| 5742 | +** ^(The BLOB is closed unconditionally. Even if this routine returns | |
| 5743 | +** an error code, the BLOB is still closed.)^ | |
| 5744 | +** | |
| 5745 | +** ^Calling this routine with a null pointer (such as would be returned | |
| 5746 | +** by a failed call to [sqlite3_blob_open()]) is a harmless no-op. | |
| 5778 | 5747 | */ |
| 5779 | 5748 | SQLITE_API int sqlite3_blob_close(sqlite3_blob *); |
| 5780 | 5749 | |
| 5781 | 5750 | /* |
| 5782 | 5751 | ** CAPI3REF: Return The Size Of An Open BLOB |
| @@ -5822,39 +5791,36 @@ | ||
| 5822 | 5791 | SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); |
| 5823 | 5792 | |
| 5824 | 5793 | /* |
| 5825 | 5794 | ** CAPI3REF: Write Data Into A BLOB Incrementally |
| 5826 | 5795 | ** |
| 5827 | -** ^(This function is used to write data into an open [BLOB handle] from a | |
| 5828 | -** caller-supplied buffer. N bytes of data are copied from the buffer Z | |
| 5829 | -** into the open BLOB, starting at offset iOffset.)^ | |
| 5830 | -** | |
| 5831 | -** ^(On success, sqlite3_blob_write() returns SQLITE_OK. | |
| 5832 | -** Otherwise, an [error code] or an [extended error code] is returned.)^ | |
| 5833 | -** ^Unless SQLITE_MISUSE is returned, this function sets the | |
| 5834 | -** [database connection] error code and message accessible via | |
| 5835 | -** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. | |
| 5796 | +** ^This function is used to write data into an open [BLOB handle] from a | |
| 5797 | +** caller-supplied buffer. ^N bytes of data are copied from the buffer Z | |
| 5798 | +** into the open BLOB, starting at offset iOffset. | |
| 5836 | 5799 | ** |
| 5837 | 5800 | ** ^If the [BLOB handle] passed as the first argument was not opened for |
| 5838 | 5801 | ** writing (the flags parameter to [sqlite3_blob_open()] was zero), |
| 5839 | 5802 | ** this function returns [SQLITE_READONLY]. |
| 5840 | 5803 | ** |
| 5841 | -** This function may only modify the contents of the BLOB; it is | |
| 5804 | +** ^This function may only modify the contents of the BLOB; it is | |
| 5842 | 5805 | ** not possible to increase the size of a BLOB using this API. |
| 5843 | 5806 | ** ^If offset iOffset is less than N bytes from the end of the BLOB, |
| 5844 | -** [SQLITE_ERROR] is returned and no data is written. The size of the | |
| 5845 | -** BLOB (and hence the maximum value of N+iOffset) can be determined | |
| 5846 | -** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less | |
| 5847 | -** than zero [SQLITE_ERROR] is returned and no data is written. | |
| 5807 | +** [SQLITE_ERROR] is returned and no data is written. ^If N is | |
| 5808 | +** less than zero [SQLITE_ERROR] is returned and no data is written. | |
| 5809 | +** The size of the BLOB (and hence the maximum value of N+iOffset) | |
| 5810 | +** can be determined using the [sqlite3_blob_bytes()] interface. | |
| 5848 | 5811 | ** |
| 5849 | 5812 | ** ^An attempt to write to an expired [BLOB handle] fails with an |
| 5850 | 5813 | ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred |
| 5851 | 5814 | ** before the [BLOB handle] expired are not rolled back by the |
| 5852 | 5815 | ** expiration of the handle, though of course those changes might |
| 5853 | 5816 | ** have been overwritten by the statement that expired the BLOB handle |
| 5854 | 5817 | ** or by other independent statements. |
| 5855 | 5818 | ** |
| 5819 | +** ^(On success, sqlite3_blob_write() returns SQLITE_OK. | |
| 5820 | +** Otherwise, an [error code] or an [extended error code] is returned.)^ | |
| 5821 | +** | |
| 5856 | 5822 | ** This routine only works on a [BLOB handle] which has been created |
| 5857 | 5823 | ** by a prior successful call to [sqlite3_blob_open()] and which has not |
| 5858 | 5824 | ** been closed by [sqlite3_blob_close()]. Passing any other pointer in |
| 5859 | 5825 | ** to this routine results in undefined and probably undesirable behavior. |
| 5860 | 5826 | ** |
| @@ -6851,14 +6817,10 @@ | ||
| 6851 | 6817 | ** and database name of the source database, respectively. |
| 6852 | 6818 | ** ^The source and destination [database connections] (parameters S and D) |
| 6853 | 6819 | ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with |
| 6854 | 6820 | ** an error. |
| 6855 | 6821 | ** |
| 6856 | -** ^A call to sqlite3_backup_init() will fail, returning SQLITE_ERROR, if | |
| 6857 | -** there is already a read or read-write transaction open on the | |
| 6858 | -** destination database. | |
| 6859 | -** | |
| 6860 | 6822 | ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is |
| 6861 | 6823 | ** returned and an error code and error message are stored in the |
| 6862 | 6824 | ** destination [database connection] D. |
| 6863 | 6825 | ** ^The error code and message for the failed call to sqlite3_backup_init() |
| 6864 | 6826 | ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or |
| @@ -7447,102 +7409,10 @@ | ||
| 7447 | 7409 | /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */ |
| 7448 | 7410 | #define SQLITE_FAIL 3 |
| 7449 | 7411 | /* #define SQLITE_ABORT 4 // Also an error code */ |
| 7450 | 7412 | #define SQLITE_REPLACE 5 |
| 7451 | 7413 | |
| 7452 | -/* | |
| 7453 | -** CAPI3REF: Prepared Statement Scan Status Opcodes | |
| 7454 | -** KEYWORDS: {scanstatus options} | |
| 7455 | -** | |
| 7456 | -** The following constants can be used for the T parameter to the | |
| 7457 | -** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a | |
| 7458 | -** different metric for sqlite3_stmt_scanstatus() to return. | |
| 7459 | -** | |
| 7460 | -** <dl> | |
| 7461 | -** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt> | |
| 7462 | -** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the | |
| 7463 | -** total number of times that the X-th loop has run.</dd> | |
| 7464 | -** | |
| 7465 | -** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt> | |
| 7466 | -** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the | |
| 7467 | -** total number of rows examined by all iterations of the X-th loop.</dd> | |
| 7468 | -** | |
| 7469 | -** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt> | |
| 7470 | -** <dd>^The "double" variable pointed to by the T parameter will be set to the | |
| 7471 | -** query planner's estimate for the average number of rows output from each | |
| 7472 | -** iteration of the X-th loop. If the query planner's estimates was accurate, | |
| 7473 | -** then this value will approximate the quotient NVISIT/NLOOP and the | |
| 7474 | -** product of this value for all prior loops with the same SELECTID will | |
| 7475 | -** be the NLOOP value for the current loop. | |
| 7476 | -** | |
| 7477 | -** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt> | |
| 7478 | -** <dd>^The "const char *" variable pointed to by the T parameter will be set to | |
| 7479 | -** a zero-terminated UTF-8 string containing the name of the index or table used | |
| 7480 | -** for the X-th loop. | |
| 7481 | -** | |
| 7482 | -** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt> | |
| 7483 | -** <dd>^The "const char *" variable pointed to by the T parameter will be set to | |
| 7484 | -** a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN] description | |
| 7485 | -** for the X-th loop. | |
| 7486 | -** | |
| 7487 | -** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt> | |
| 7488 | -** <dd>^The "int" variable pointed to by the T parameter will be set to the | |
| 7489 | -** "select-id" for the X-th loop. The select-id identifies which query or | |
| 7490 | -** subquery the loop is part of. The main query has a select-id of zero. | |
| 7491 | -** The select-id is the same value as is output in the first column | |
| 7492 | -** of an [EXPLAIN QUERY PLAN] query. | |
| 7493 | -** </dl> | |
| 7494 | -*/ | |
| 7495 | -#define SQLITE_SCANSTAT_NLOOP 0 | |
| 7496 | -#define SQLITE_SCANSTAT_NVISIT 1 | |
| 7497 | -#define SQLITE_SCANSTAT_EST 2 | |
| 7498 | -#define SQLITE_SCANSTAT_NAME 3 | |
| 7499 | -#define SQLITE_SCANSTAT_EXPLAIN 4 | |
| 7500 | -#define SQLITE_SCANSTAT_SELECTID 5 | |
| 7501 | - | |
| 7502 | -/* | |
| 7503 | -** CAPI3REF: Prepared Statement Scan Status | |
| 7504 | -** | |
| 7505 | -** Return status data for a single loop within query pStmt. | |
| 7506 | -** | |
| 7507 | -** The "iScanStatusOp" parameter determines which status information to return. | |
| 7508 | -** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior of | |
| 7509 | -** this interface is undefined. | |
| 7510 | -** ^The requested measurement is written into a variable pointed to by | |
| 7511 | -** the "pOut" parameter. | |
| 7512 | -** Parameter "idx" identifies the specific loop to retrieve statistics for. | |
| 7513 | -** Loops are numbered starting from zero. ^If idx is out of range - less than | |
| 7514 | -** zero or greater than or equal to the total number of loops used to implement | |
| 7515 | -** the statement - a non-zero value is returned and the variable that pOut | |
| 7516 | -** points to is unchanged. | |
| 7517 | -** | |
| 7518 | -** ^Statistics might not be available for all loops in all statements. ^In cases | |
| 7519 | -** where there exist loops with no available statistics, this function behaves | |
| 7520 | -** as if the loop did not exist - it returns non-zero and leave the variable | |
| 7521 | -** that pOut points to unchanged. | |
| 7522 | -** | |
| 7523 | -** This API is only available if the library is built with pre-processor | |
| 7524 | -** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. | |
| 7525 | -** | |
| 7526 | -** See also: [sqlite3_stmt_scanstatus_reset()] | |
| 7527 | -*/ | |
| 7528 | -SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus( | |
| 7529 | - sqlite3_stmt *pStmt, /* Prepared statement for which info desired */ | |
| 7530 | - int idx, /* Index of loop to report on */ | |
| 7531 | - int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */ | |
| 7532 | - void *pOut /* Result written here */ | |
| 7533 | -); | |
| 7534 | - | |
| 7535 | -/* | |
| 7536 | -** CAPI3REF: Zero Scan-Status Counters | |
| 7537 | -** | |
| 7538 | -** ^Zero all [sqlite3_stmt_scanstatus()] related event counters. | |
| 7539 | -** | |
| 7540 | -** This API is only available if the library is built with pre-processor | |
| 7541 | -** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. | |
| 7542 | -*/ | |
| 7543 | -SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*); | |
| 7544 | 7414 | |
| 7545 | 7415 | |
| 7546 | 7416 | /* |
| 7547 | 7417 | ** Undo the hack that converts floating point types to integer for |
| 7548 | 7418 | ** builds on processors without floating point support. |
| 7549 | 7419 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -55,11 +55,11 @@ | |
| 55 | |
| 56 | |
| 57 | /* |
| 58 | ** These no-op macros are used in front of interfaces to mark those |
| 59 | ** interfaces as either deprecated or experimental. New applications |
| 60 | ** should not use deprecated interfaces - they are supported for backwards |
| 61 | ** compatibility only. Application writers should be aware that |
| 62 | ** experimental interfaces are subject to change in point releases. |
| 63 | ** |
| 64 | ** These macros used to resolve to various kinds of compiler magic that |
| 65 | ** would generate warning messages when they were used. But that |
| @@ -105,13 +105,13 @@ | |
| 105 | ** |
| 106 | ** See also: [sqlite3_libversion()], |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.8.8" |
| 111 | #define SQLITE_VERSION_NUMBER 3008008 |
| 112 | #define SQLITE_SOURCE_ID "2014-11-18 21:54:31 4461bf045d8eecf98478035efcdba3f41c709bc5" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -1502,31 +1502,29 @@ | |
| 1502 | ** it is not possible to set the Serialized [threading mode] and |
| 1503 | ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
| 1504 | ** SQLITE_CONFIG_SERIALIZED configuration option.</dd> |
| 1505 | ** |
| 1506 | ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt> |
| 1507 | ** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is |
| 1508 | ** a pointer to an instance of the [sqlite3_mem_methods] structure. |
| 1509 | ** The argument specifies |
| 1510 | ** alternative low-level memory allocation routines to be used in place of |
| 1511 | ** the memory allocation routines built into SQLite.)^ ^SQLite makes |
| 1512 | ** its own private copy of the content of the [sqlite3_mem_methods] structure |
| 1513 | ** before the [sqlite3_config()] call returns.</dd> |
| 1514 | ** |
| 1515 | ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt> |
| 1516 | ** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which |
| 1517 | ** is a pointer to an instance of the [sqlite3_mem_methods] structure. |
| 1518 | ** The [sqlite3_mem_methods] |
| 1519 | ** structure is filled with the currently defined memory allocation routines.)^ |
| 1520 | ** This option can be used to overload the default memory allocation |
| 1521 | ** routines with a wrapper that simulations memory allocation failure or |
| 1522 | ** tracks memory usage, for example. </dd> |
| 1523 | ** |
| 1524 | ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> |
| 1525 | ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int, |
| 1526 | ** interpreted as a boolean, which enables or disables the collection of |
| 1527 | ** memory allocation statistics. ^(When memory allocation statistics are disabled, the |
| 1528 | ** following SQLite interfaces become non-operational: |
| 1529 | ** <ul> |
| 1530 | ** <li> [sqlite3_memory_used()] |
| 1531 | ** <li> [sqlite3_memory_highwater()] |
| 1532 | ** <li> [sqlite3_soft_heap_limit64()] |
| @@ -1536,90 +1534,78 @@ | |
| 1536 | ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory |
| 1537 | ** allocation statistics are disabled by default. |
| 1538 | ** </dd> |
| 1539 | ** |
| 1540 | ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt> |
| 1541 | ** <dd> ^The SQLITE_CONFIG_SCRATCH option specifies a static memory buffer |
| 1542 | ** that SQLite can use for scratch memory. ^(There are three arguments |
| 1543 | ** to SQLITE_CONFIG_SCRATCH: A pointer an 8-byte |
| 1544 | ** aligned memory buffer from which the scratch allocations will be |
| 1545 | ** drawn, the size of each scratch allocation (sz), |
| 1546 | ** and the maximum number of scratch allocations (N).)^ |
| 1547 | ** The first argument must be a pointer to an 8-byte aligned buffer |
| 1548 | ** of at least sz*N bytes of memory. |
| 1549 | ** ^SQLite will not use more than one scratch buffers per thread. |
| 1550 | ** ^SQLite will never request a scratch buffer that is more than 6 |
| 1551 | ** times the database page size. |
| 1552 | ** ^If SQLite needs needs additional |
| 1553 | ** scratch memory beyond what is provided by this configuration option, then |
| 1554 | ** [sqlite3_malloc()] will be used to obtain the memory needed.<p> |
| 1555 | ** ^When the application provides any amount of scratch memory using |
| 1556 | ** SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary large |
| 1557 | ** [sqlite3_malloc|heap allocations]. |
| 1558 | ** This can help [Robson proof|prevent memory allocation failures] due to heap |
| 1559 | ** fragmentation in low-memory embedded systems. |
| 1560 | ** </dd> |
| 1561 | ** |
| 1562 | ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt> |
| 1563 | ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a static memory buffer |
| 1564 | ** that SQLite can use for the database page cache with the default page |
| 1565 | ** cache implementation. |
| 1566 | ** This configuration should not be used if an application-define page |
| 1567 | ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2] |
| 1568 | ** configuration option. |
| 1569 | ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned |
| 1570 | ** memory, the size of each page buffer (sz), and the number of pages (N). |
| 1571 | ** The sz argument should be the size of the largest database page |
| 1572 | ** (a power of two between 512 and 32768) plus some extra bytes for each |
| 1573 | ** page header. ^The number of extra bytes needed by the page header |
| 1574 | ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option |
| 1575 | ** to [sqlite3_config()]. |
| 1576 | ** ^It is harmless, apart from the wasted memory, |
| 1577 | ** for the sz parameter to be larger than necessary. The first |
| 1578 | ** argument should pointer to an 8-byte aligned block of memory that |
| 1579 | ** is at least sz*N bytes of memory, otherwise subsequent behavior is |
| 1580 | ** undefined. |
| 1581 | ** ^SQLite will use the memory provided by the first argument to satisfy its |
| 1582 | ** memory needs for the first N pages that it adds to cache. ^If additional |
| 1583 | ** page cache memory is needed beyond what is provided by this option, then |
| 1584 | ** SQLite goes to [sqlite3_malloc()] for the additional storage space.</dd> |
| 1585 | ** |
| 1586 | ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> |
| 1587 | ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer |
| 1588 | ** that SQLite will use for all of its dynamic memory allocation needs |
| 1589 | ** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. |
| 1590 | ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled |
| 1591 | ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns |
| 1592 | ** [SQLITE_ERROR] if invoked otherwise. |
| 1593 | ** ^There are three arguments to SQLITE_CONFIG_HEAP: |
| 1594 | ** An 8-byte aligned pointer to the memory, |
| 1595 | ** the number of bytes in the memory buffer, and the minimum allocation size. |
| 1596 | ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts |
| 1597 | ** to using its default memory allocator (the system malloc() implementation), |
| 1598 | ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the |
| 1599 | ** memory pointer is not NULL then the alternative memory |
| 1600 | ** allocator is engaged to handle all of SQLites memory allocation needs. |
| 1601 | ** The first pointer (the memory pointer) must be aligned to an 8-byte |
| 1602 | ** boundary or subsequent behavior of SQLite will be undefined. |
| 1603 | ** The minimum allocation size is capped at 2**12. Reasonable values |
| 1604 | ** for the minimum allocation size are 2**5 through 2**8.</dd> |
| 1605 | ** |
| 1606 | ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt> |
| 1607 | ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a |
| 1608 | ** pointer to an instance of the [sqlite3_mutex_methods] structure. |
| 1609 | ** The argument specifies alternative low-level mutex routines to be used in place |
| 1610 | ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the |
| 1611 | ** content of the [sqlite3_mutex_methods] structure before the call to |
| 1612 | ** [sqlite3_config()] returns. ^If SQLite is compiled with |
| 1613 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1614 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1615 | ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will |
| 1616 | ** return [SQLITE_ERROR].</dd> |
| 1617 | ** |
| 1618 | ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt> |
| 1619 | ** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which |
| 1620 | ** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The |
| 1621 | ** [sqlite3_mutex_methods] |
| 1622 | ** structure is filled with the currently defined mutex routines.)^ |
| 1623 | ** This option can be used to overload the default mutex allocation |
| 1624 | ** routines with a wrapper used to track mutex usage for performance |
| 1625 | ** profiling or testing, for example. ^If SQLite is compiled with |
| @@ -1627,28 +1613,28 @@ | |
| 1627 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1628 | ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will |
| 1629 | ** return [SQLITE_ERROR].</dd> |
| 1630 | ** |
| 1631 | ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt> |
| 1632 | ** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine |
| 1633 | ** the default size of lookaside memory on each [database connection]. |
| 1634 | ** The first argument is the |
| 1635 | ** size of each lookaside buffer slot and the second is the number of |
| 1636 | ** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE |
| 1637 | ** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] |
| 1638 | ** option to [sqlite3_db_config()] can be used to change the lookaside |
| 1639 | ** configuration on individual connections.)^ </dd> |
| 1640 | ** |
| 1641 | ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt> |
| 1642 | ** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is |
| 1643 | ** a pointer to an [sqlite3_pcache_methods2] object. This object specifies |
| 1644 | ** the interface to a custom page cache implementation.)^ |
| 1645 | ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd> |
| 1646 | ** |
| 1647 | ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt> |
| 1648 | ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which |
| 1649 | ** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of the current |
| 1650 | ** page cache implementation into that object.)^ </dd> |
| 1651 | ** |
| 1652 | ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> |
| 1653 | ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite |
| 1654 | ** global [error log]. |
| @@ -1668,27 +1654,26 @@ | |
| 1668 | ** supplied by the application must not invoke any SQLite interface. |
| 1669 | ** In a multi-threaded application, the application-defined logger |
| 1670 | ** function must be threadsafe. </dd> |
| 1671 | ** |
| 1672 | ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI |
| 1673 | ** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int. |
| 1674 | ** If non-zero, then URI handling is globally enabled. If the parameter is zero, |
| 1675 | ** then URI handling is globally disabled.)^ ^If URI handling is globally enabled, |
| 1676 | ** all filenames passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or |
| 1677 | ** specified as part of [ATTACH] commands are interpreted as URIs, regardless |
| 1678 | ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database |
| 1679 | ** connection is opened. ^If it is globally disabled, filenames are |
| 1680 | ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the |
| 1681 | ** database connection is opened. ^(By default, URI handling is globally |
| 1682 | ** disabled. The default value may be changed by compiling with the |
| 1683 | ** [SQLITE_USE_URI] symbol defined.)^ |
| 1684 | ** |
| 1685 | ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN |
| 1686 | ** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer |
| 1687 | ** argument which is interpreted as a boolean in order to enable or disable |
| 1688 | ** the use of covering indices for full table scans in the query optimizer. |
| 1689 | ** ^The default setting is determined |
| 1690 | ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on" |
| 1691 | ** if that compile-time option is omitted. |
| 1692 | ** The ability to disable the use of covering indices for full table scans |
| 1693 | ** is because some incorrectly coded legacy applications might malfunction |
| 1694 | ** when the optimization is enabled. Providing the ability to |
| @@ -1724,32 +1709,23 @@ | |
| 1724 | ** that are the default mmap size limit (the default setting for |
| 1725 | ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit. |
| 1726 | ** ^The default setting can be overridden by each database connection using |
| 1727 | ** either the [PRAGMA mmap_size] command, or by using the |
| 1728 | ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size |
| 1729 | ** will be silently truncated if necessary so that it does not exceed the |
| 1730 | ** compile-time maximum mmap size set by the |
| 1731 | ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^ |
| 1732 | ** ^If either argument to this option is negative, then that argument is |
| 1733 | ** changed to its compile-time default. |
| 1734 | ** |
| 1735 | ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]] |
| 1736 | ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE |
| 1737 | ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is |
| 1738 | ** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro defined. |
| 1739 | ** ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value |
| 1740 | ** that specifies the maximum size of the created heap. |
| 1741 | ** </dl> |
| 1742 | ** |
| 1743 | ** [[SQLITE_CONFIG_PCACHE_HDRSZ]] |
| 1744 | ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ |
| 1745 | ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which |
| 1746 | ** is a pointer to an integer and writes into that integer the number of extra |
| 1747 | ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE]. The amount of |
| 1748 | ** extra space required can change depending on the compiler, |
| 1749 | ** target platform, and SQLite version. |
| 1750 | ** </dl> |
| 1751 | */ |
| 1752 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1753 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 1754 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| 1755 | #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ |
| @@ -1770,11 +1746,10 @@ | |
| 1770 | #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */ |
| 1771 | #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */ |
| 1772 | #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */ |
| 1773 | #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */ |
| 1774 | #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */ |
| 1775 | #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */ |
| 1776 | |
| 1777 | /* |
| 1778 | ** CAPI3REF: Database Connection Configuration Options |
| 1779 | ** |
| 1780 | ** These constants are the available integer configuration options that |
| @@ -1898,49 +1873,51 @@ | |
| 1898 | SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); |
| 1899 | |
| 1900 | /* |
| 1901 | ** CAPI3REF: Count The Number Of Rows Modified |
| 1902 | ** |
| 1903 | ** ^This function returns the number of rows modified, inserted or |
| 1904 | ** deleted by the most recently completed INSERT, UPDATE or DELETE |
| 1905 | ** statement on the database connection specified by the only parameter. |
| 1906 | ** ^Executing any other type of SQL statement does not modify the value |
| 1907 | ** returned by this function. |
| 1908 | ** |
| 1909 | ** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are |
| 1910 | ** considered - auxiliary changes caused by [CREATE TRIGGER | triggers], |
| 1911 | ** [foreign key actions] or [REPLACE] constraint resolution are not counted. |
| 1912 | ** |
| 1913 | ** Changes to a view that are intercepted by |
| 1914 | ** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value |
| 1915 | ** returned by sqlite3_changes() immediately after an INSERT, UPDATE or |
| 1916 | ** DELETE statement run on a view is always zero. Only changes made to real |
| 1917 | ** tables are counted. |
| 1918 | ** |
| 1919 | ** Things are more complicated if the sqlite3_changes() function is |
| 1920 | ** executed while a trigger program is running. This may happen if the |
| 1921 | ** program uses the [changes() SQL function], or if some other callback |
| 1922 | ** function invokes sqlite3_changes() directly. Essentially: |
| 1923 | ** |
| 1924 | ** <ul> |
| 1925 | ** <li> ^(Before entering a trigger program the value returned by |
| 1926 | ** sqlite3_changes() function is saved. After the trigger program |
| 1927 | ** has finished, the original value is restored.)^ |
| 1928 | ** |
| 1929 | ** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE |
| 1930 | ** statement sets the value returned by sqlite3_changes() |
| 1931 | ** upon completion as normal. Of course, this value will not include |
| 1932 | ** any changes performed by sub-triggers, as the sqlite3_changes() |
| 1933 | ** value will be saved and restored after each sub-trigger has run.)^ |
| 1934 | ** </ul> |
| 1935 | ** |
| 1936 | ** ^This means that if the changes() SQL function (or similar) is used |
| 1937 | ** by the first INSERT, UPDATE or DELETE statement within a trigger, it |
| 1938 | ** returns the value as set when the calling statement began executing. |
| 1939 | ** ^If it is used by the second or subsequent such statement within a trigger |
| 1940 | ** program, the value returned reflects the number of rows modified by the |
| 1941 | ** previous INSERT, UPDATE or DELETE statement within the same trigger. |
| 1942 | ** |
| 1943 | ** See also the [sqlite3_total_changes()] interface, the |
| 1944 | ** [count_changes pragma], and the [changes() SQL function]. |
| 1945 | ** |
| 1946 | ** If a separate thread makes changes on the same database connection |
| @@ -1950,21 +1927,24 @@ | |
| 1950 | SQLITE_API int sqlite3_changes(sqlite3*); |
| 1951 | |
| 1952 | /* |
| 1953 | ** CAPI3REF: Total Number Of Rows Modified |
| 1954 | ** |
| 1955 | ** ^This function returns the total number of rows inserted, modified or |
| 1956 | ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed |
| 1957 | ** since the database connection was opened, including those executed as |
| 1958 | ** part of trigger programs. ^Executing any other type of SQL statement |
| 1959 | ** does not affect the value returned by sqlite3_total_changes(). |
| 1960 | ** |
| 1961 | ** ^Changes made as part of [foreign key actions] are included in the |
| 1962 | ** count, but those made as part of REPLACE constraint resolution are |
| 1963 | ** not. ^Changes to a view that are intercepted by INSTEAD OF triggers |
| 1964 | ** are not counted. |
| 1965 | ** |
| 1966 | ** See also the [sqlite3_changes()] interface, the |
| 1967 | ** [count_changes pragma], and the [total_changes() SQL function]. |
| 1968 | ** |
| 1969 | ** If a separate thread makes changes on the same database connection |
| 1970 | ** while [sqlite3_total_changes()] is running then the value |
| @@ -2438,18 +2418,17 @@ | |
| 2438 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2439 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2440 | ** applications to access the same PRNG for other purposes. |
| 2441 | ** |
| 2442 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2443 | ** ^The P parameter can be a NULL pointer. |
| 2444 | ** |
| 2445 | ** ^If this routine has not been previously called or if the previous |
| 2446 | ** call had N less than one or a NULL pointer for P, then the PRNG is |
| 2447 | ** seeded using randomness obtained from the xRandomness method of |
| 2448 | ** the default [sqlite3_vfs] object. |
| 2449 | ** ^If the previous call to this routine had an N of 1 or more and a |
| 2450 | ** non-NULL P then the pseudo-randomness is generated |
| 2451 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2452 | ** method. |
| 2453 | */ |
| 2454 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2455 | |
| @@ -5660,46 +5639,30 @@ | |
| 5660 | ** |
| 5661 | ** <pre> |
| 5662 | ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow; |
| 5663 | ** </pre>)^ |
| 5664 | ** |
| 5665 | ** ^(Parameter zDb is not the filename that contains the database, but |
| 5666 | ** rather the symbolic name of the database. For attached databases, this is |
| 5667 | ** the name that appears after the AS keyword in the [ATTACH] statement. |
| 5668 | ** For the main database file, the database name is "main". For TEMP |
| 5669 | ** tables, the database name is "temp".)^ |
| 5670 | ** |
| 5671 | ** ^If the flags parameter is non-zero, then the BLOB is opened for read |
| 5672 | ** and write access. ^If the flags parameter is zero, the BLOB is opened for |
| 5673 | ** read-only access. |
| 5674 | ** |
| 5675 | ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored |
| 5676 | ** in *ppBlob. Otherwise an [error code] is returned and, unless the error |
| 5677 | ** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided |
| 5678 | ** the API is not misused, it is always safe to call [sqlite3_blob_close()] |
| 5679 | ** on *ppBlob after this function it returns. |
| 5680 | ** |
| 5681 | ** This function fails with SQLITE_ERROR if any of the following are true: |
| 5682 | ** <ul> |
| 5683 | ** <li> ^(Database zDb does not exist)^, |
| 5684 | ** <li> ^(Table zTable does not exist within database zDb)^, |
| 5685 | ** <li> ^(Table zTable is a WITHOUT ROWID table)^, |
| 5686 | ** <li> ^(Column zColumn does not exist)^, |
| 5687 | ** <li> ^(Row iRow is not present in the table)^, |
| 5688 | ** <li> ^(The specified column of row iRow contains a value that is not |
| 5689 | ** a TEXT or BLOB value)^, |
| 5690 | ** <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE |
| 5691 | ** constraint and the blob is being opened for read/write access)^, |
| 5692 | ** <li> ^([foreign key constraints | Foreign key constraints] are enabled, |
| 5693 | ** column zColumn is part of a [child key] definition and the blob is |
| 5694 | ** being opened for read/write access)^. |
| 5695 | ** </ul> |
| 5696 | ** |
| 5697 | ** ^Unless it returns SQLITE_MISUSE, this function sets the |
| 5698 | ** [database connection] error code and message accessible via |
| 5699 | ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. |
| 5700 | ** |
| 5701 | ** |
| 5702 | ** ^(If the row that a BLOB handle points to is modified by an |
| 5703 | ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects |
| 5704 | ** then the BLOB handle is marked as "expired". |
| 5705 | ** This is true if any column of the row is changed, even a column |
| @@ -5713,13 +5676,17 @@ | |
| 5713 | ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of |
| 5714 | ** the opened blob. ^The size of a blob may not be changed by this |
| 5715 | ** interface. Use the [UPDATE] SQL command to change the size of a |
| 5716 | ** blob. |
| 5717 | ** |
| 5718 | ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces |
| 5719 | ** and the built-in [zeroblob] SQL function may be used to create a |
| 5720 | ** zero-filled blob to read or write using the incremental-blob interface. |
| 5721 | ** |
| 5722 | ** To avoid a resource leak, every open [BLOB handle] should eventually |
| 5723 | ** be released by a call to [sqlite3_blob_close()]. |
| 5724 | */ |
| 5725 | SQLITE_API int sqlite3_blob_open( |
| @@ -5757,26 +5724,28 @@ | |
| 5757 | SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); |
| 5758 | |
| 5759 | /* |
| 5760 | ** CAPI3REF: Close A BLOB Handle |
| 5761 | ** |
| 5762 | ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed |
| 5763 | ** unconditionally. Even if this routine returns an error code, the |
| 5764 | ** handle is still closed.)^ |
| 5765 | ** |
| 5766 | ** ^If the blob handle being closed was opened for read-write access, and if |
| 5767 | ** the database is in auto-commit mode and there are no other open read-write |
| 5768 | ** blob handles or active write statements, the current transaction is |
| 5769 | ** committed. ^If an error occurs while committing the transaction, an error |
| 5770 | ** code is returned and the transaction rolled back. |
| 5771 | ** |
| 5772 | ** Calling this function with an argument that is not a NULL pointer or an |
| 5773 | ** open blob handle results in undefined behaviour. ^Calling this routine |
| 5774 | ** with a null pointer (such as would be returned by a failed call to |
| 5775 | ** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function |
| 5776 | ** is passed a valid open blob handle, the values returned by the |
| 5777 | ** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning. |
| 5778 | */ |
| 5779 | SQLITE_API int sqlite3_blob_close(sqlite3_blob *); |
| 5780 | |
| 5781 | /* |
| 5782 | ** CAPI3REF: Return The Size Of An Open BLOB |
| @@ -5822,39 +5791,36 @@ | |
| 5822 | SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); |
| 5823 | |
| 5824 | /* |
| 5825 | ** CAPI3REF: Write Data Into A BLOB Incrementally |
| 5826 | ** |
| 5827 | ** ^(This function is used to write data into an open [BLOB handle] from a |
| 5828 | ** caller-supplied buffer. N bytes of data are copied from the buffer Z |
| 5829 | ** into the open BLOB, starting at offset iOffset.)^ |
| 5830 | ** |
| 5831 | ** ^(On success, sqlite3_blob_write() returns SQLITE_OK. |
| 5832 | ** Otherwise, an [error code] or an [extended error code] is returned.)^ |
| 5833 | ** ^Unless SQLITE_MISUSE is returned, this function sets the |
| 5834 | ** [database connection] error code and message accessible via |
| 5835 | ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. |
| 5836 | ** |
| 5837 | ** ^If the [BLOB handle] passed as the first argument was not opened for |
| 5838 | ** writing (the flags parameter to [sqlite3_blob_open()] was zero), |
| 5839 | ** this function returns [SQLITE_READONLY]. |
| 5840 | ** |
| 5841 | ** This function may only modify the contents of the BLOB; it is |
| 5842 | ** not possible to increase the size of a BLOB using this API. |
| 5843 | ** ^If offset iOffset is less than N bytes from the end of the BLOB, |
| 5844 | ** [SQLITE_ERROR] is returned and no data is written. The size of the |
| 5845 | ** BLOB (and hence the maximum value of N+iOffset) can be determined |
| 5846 | ** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less |
| 5847 | ** than zero [SQLITE_ERROR] is returned and no data is written. |
| 5848 | ** |
| 5849 | ** ^An attempt to write to an expired [BLOB handle] fails with an |
| 5850 | ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred |
| 5851 | ** before the [BLOB handle] expired are not rolled back by the |
| 5852 | ** expiration of the handle, though of course those changes might |
| 5853 | ** have been overwritten by the statement that expired the BLOB handle |
| 5854 | ** or by other independent statements. |
| 5855 | ** |
| 5856 | ** This routine only works on a [BLOB handle] which has been created |
| 5857 | ** by a prior successful call to [sqlite3_blob_open()] and which has not |
| 5858 | ** been closed by [sqlite3_blob_close()]. Passing any other pointer in |
| 5859 | ** to this routine results in undefined and probably undesirable behavior. |
| 5860 | ** |
| @@ -6851,14 +6817,10 @@ | |
| 6851 | ** and database name of the source database, respectively. |
| 6852 | ** ^The source and destination [database connections] (parameters S and D) |
| 6853 | ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with |
| 6854 | ** an error. |
| 6855 | ** |
| 6856 | ** ^A call to sqlite3_backup_init() will fail, returning SQLITE_ERROR, if |
| 6857 | ** there is already a read or read-write transaction open on the |
| 6858 | ** destination database. |
| 6859 | ** |
| 6860 | ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is |
| 6861 | ** returned and an error code and error message are stored in the |
| 6862 | ** destination [database connection] D. |
| 6863 | ** ^The error code and message for the failed call to sqlite3_backup_init() |
| 6864 | ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or |
| @@ -7447,102 +7409,10 @@ | |
| 7447 | /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */ |
| 7448 | #define SQLITE_FAIL 3 |
| 7449 | /* #define SQLITE_ABORT 4 // Also an error code */ |
| 7450 | #define SQLITE_REPLACE 5 |
| 7451 | |
| 7452 | /* |
| 7453 | ** CAPI3REF: Prepared Statement Scan Status Opcodes |
| 7454 | ** KEYWORDS: {scanstatus options} |
| 7455 | ** |
| 7456 | ** The following constants can be used for the T parameter to the |
| 7457 | ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a |
| 7458 | ** different metric for sqlite3_stmt_scanstatus() to return. |
| 7459 | ** |
| 7460 | ** <dl> |
| 7461 | ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt> |
| 7462 | ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the |
| 7463 | ** total number of times that the X-th loop has run.</dd> |
| 7464 | ** |
| 7465 | ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt> |
| 7466 | ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the |
| 7467 | ** total number of rows examined by all iterations of the X-th loop.</dd> |
| 7468 | ** |
| 7469 | ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt> |
| 7470 | ** <dd>^The "double" variable pointed to by the T parameter will be set to the |
| 7471 | ** query planner's estimate for the average number of rows output from each |
| 7472 | ** iteration of the X-th loop. If the query planner's estimates was accurate, |
| 7473 | ** then this value will approximate the quotient NVISIT/NLOOP and the |
| 7474 | ** product of this value for all prior loops with the same SELECTID will |
| 7475 | ** be the NLOOP value for the current loop. |
| 7476 | ** |
| 7477 | ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt> |
| 7478 | ** <dd>^The "const char *" variable pointed to by the T parameter will be set to |
| 7479 | ** a zero-terminated UTF-8 string containing the name of the index or table used |
| 7480 | ** for the X-th loop. |
| 7481 | ** |
| 7482 | ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt> |
| 7483 | ** <dd>^The "const char *" variable pointed to by the T parameter will be set to |
| 7484 | ** a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN] description |
| 7485 | ** for the X-th loop. |
| 7486 | ** |
| 7487 | ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt> |
| 7488 | ** <dd>^The "int" variable pointed to by the T parameter will be set to the |
| 7489 | ** "select-id" for the X-th loop. The select-id identifies which query or |
| 7490 | ** subquery the loop is part of. The main query has a select-id of zero. |
| 7491 | ** The select-id is the same value as is output in the first column |
| 7492 | ** of an [EXPLAIN QUERY PLAN] query. |
| 7493 | ** </dl> |
| 7494 | */ |
| 7495 | #define SQLITE_SCANSTAT_NLOOP 0 |
| 7496 | #define SQLITE_SCANSTAT_NVISIT 1 |
| 7497 | #define SQLITE_SCANSTAT_EST 2 |
| 7498 | #define SQLITE_SCANSTAT_NAME 3 |
| 7499 | #define SQLITE_SCANSTAT_EXPLAIN 4 |
| 7500 | #define SQLITE_SCANSTAT_SELECTID 5 |
| 7501 | |
| 7502 | /* |
| 7503 | ** CAPI3REF: Prepared Statement Scan Status |
| 7504 | ** |
| 7505 | ** Return status data for a single loop within query pStmt. |
| 7506 | ** |
| 7507 | ** The "iScanStatusOp" parameter determines which status information to return. |
| 7508 | ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior of |
| 7509 | ** this interface is undefined. |
| 7510 | ** ^The requested measurement is written into a variable pointed to by |
| 7511 | ** the "pOut" parameter. |
| 7512 | ** Parameter "idx" identifies the specific loop to retrieve statistics for. |
| 7513 | ** Loops are numbered starting from zero. ^If idx is out of range - less than |
| 7514 | ** zero or greater than or equal to the total number of loops used to implement |
| 7515 | ** the statement - a non-zero value is returned and the variable that pOut |
| 7516 | ** points to is unchanged. |
| 7517 | ** |
| 7518 | ** ^Statistics might not be available for all loops in all statements. ^In cases |
| 7519 | ** where there exist loops with no available statistics, this function behaves |
| 7520 | ** as if the loop did not exist - it returns non-zero and leave the variable |
| 7521 | ** that pOut points to unchanged. |
| 7522 | ** |
| 7523 | ** This API is only available if the library is built with pre-processor |
| 7524 | ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. |
| 7525 | ** |
| 7526 | ** See also: [sqlite3_stmt_scanstatus_reset()] |
| 7527 | */ |
| 7528 | SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus( |
| 7529 | sqlite3_stmt *pStmt, /* Prepared statement for which info desired */ |
| 7530 | int idx, /* Index of loop to report on */ |
| 7531 | int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */ |
| 7532 | void *pOut /* Result written here */ |
| 7533 | ); |
| 7534 | |
| 7535 | /* |
| 7536 | ** CAPI3REF: Zero Scan-Status Counters |
| 7537 | ** |
| 7538 | ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters. |
| 7539 | ** |
| 7540 | ** This API is only available if the library is built with pre-processor |
| 7541 | ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. |
| 7542 | */ |
| 7543 | SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*); |
| 7544 | |
| 7545 | |
| 7546 | /* |
| 7547 | ** Undo the hack that converts floating point types to integer for |
| 7548 | ** builds on processors without floating point support. |
| 7549 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -55,11 +55,11 @@ | |
| 55 | |
| 56 | |
| 57 | /* |
| 58 | ** These no-op macros are used in front of interfaces to mark those |
| 59 | ** interfaces as either deprecated or experimental. New applications |
| 60 | ** should not use deprecated interfaces - they are support for backwards |
| 61 | ** compatibility only. Application writers should be aware that |
| 62 | ** experimental interfaces are subject to change in point releases. |
| 63 | ** |
| 64 | ** These macros used to resolve to various kinds of compiler magic that |
| 65 | ** would generate warning messages when they were used. But that |
| @@ -105,13 +105,13 @@ | |
| 105 | ** |
| 106 | ** See also: [sqlite3_libversion()], |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.8.7.2" |
| 111 | #define SQLITE_VERSION_NUMBER 3008007 |
| 112 | #define SQLITE_SOURCE_ID "2014-11-18 20:57:56 2ab564bf9655b7c7b97ab85cafc8a48329b27f93" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -1502,31 +1502,29 @@ | |
| 1502 | ** it is not possible to set the Serialized [threading mode] and |
| 1503 | ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
| 1504 | ** SQLITE_CONFIG_SERIALIZED configuration option.</dd> |
| 1505 | ** |
| 1506 | ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt> |
| 1507 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1508 | ** instance of the [sqlite3_mem_methods] structure. The argument specifies |
| 1509 | ** alternative low-level memory allocation routines to be used in place of |
| 1510 | ** the memory allocation routines built into SQLite.)^ ^SQLite makes |
| 1511 | ** its own private copy of the content of the [sqlite3_mem_methods] structure |
| 1512 | ** before the [sqlite3_config()] call returns.</dd> |
| 1513 | ** |
| 1514 | ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt> |
| 1515 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1516 | ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods] |
| 1517 | ** structure is filled with the currently defined memory allocation routines.)^ |
| 1518 | ** This option can be used to overload the default memory allocation |
| 1519 | ** routines with a wrapper that simulations memory allocation failure or |
| 1520 | ** tracks memory usage, for example. </dd> |
| 1521 | ** |
| 1522 | ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> |
| 1523 | ** <dd> ^This option takes single argument of type int, interpreted as a |
| 1524 | ** boolean, which enables or disables the collection of memory allocation |
| 1525 | ** statistics. ^(When memory allocation statistics are disabled, the |
| 1526 | ** following SQLite interfaces become non-operational: |
| 1527 | ** <ul> |
| 1528 | ** <li> [sqlite3_memory_used()] |
| 1529 | ** <li> [sqlite3_memory_highwater()] |
| 1530 | ** <li> [sqlite3_soft_heap_limit64()] |
| @@ -1536,90 +1534,78 @@ | |
| 1534 | ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory |
| 1535 | ** allocation statistics are disabled by default. |
| 1536 | ** </dd> |
| 1537 | ** |
| 1538 | ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt> |
| 1539 | ** <dd> ^This option specifies a static memory buffer that SQLite can use for |
| 1540 | ** scratch memory. There are three arguments: A pointer an 8-byte |
| 1541 | ** aligned memory buffer from which the scratch allocations will be |
| 1542 | ** drawn, the size of each scratch allocation (sz), |
| 1543 | ** and the maximum number of scratch allocations (N). The sz |
| 1544 | ** argument must be a multiple of 16. |
| 1545 | ** The first argument must be a pointer to an 8-byte aligned buffer |
| 1546 | ** of at least sz*N bytes of memory. |
| 1547 | ** ^SQLite will use no more than two scratch buffers per thread. So |
| 1548 | ** N should be set to twice the expected maximum number of threads. |
| 1549 | ** ^SQLite will never require a scratch buffer that is more than 6 |
| 1550 | ** times the database page size. ^If SQLite needs needs additional |
| 1551 | ** scratch memory beyond what is provided by this configuration option, then |
| 1552 | ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd> |
| 1553 | ** |
| 1554 | ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt> |
| 1555 | ** <dd> ^This option specifies a static memory buffer that SQLite can use for |
| 1556 | ** the database page cache with the default page cache implementation. |
| 1557 | ** This configuration should not be used if an application-define page |
| 1558 | ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE2 option. |
| 1559 | ** There are three arguments to this option: A pointer to 8-byte aligned |
| 1560 | ** memory, the size of each page buffer (sz), and the number of pages (N). |
| 1561 | ** The sz argument should be the size of the largest database page |
| 1562 | ** (a power of two between 512 and 32768) plus a little extra for each |
| 1563 | ** page header. ^The page header size is 20 to 40 bytes depending on |
| 1564 | ** the host architecture. ^It is harmless, apart from the wasted memory, |
| 1565 | ** to make sz a little too large. The first |
| 1566 | ** argument should point to an allocation of at least sz*N bytes of memory. |
| 1567 | ** ^SQLite will use the memory provided by the first argument to satisfy its |
| 1568 | ** memory needs for the first N pages that it adds to cache. ^If additional |
| 1569 | ** page cache memory is needed beyond what is provided by this option, then |
| 1570 | ** SQLite goes to [sqlite3_malloc()] for the additional storage space. |
| 1571 | ** The pointer in the first argument must |
| 1572 | ** be aligned to an 8-byte boundary or subsequent behavior of SQLite |
| 1573 | ** will be undefined.</dd> |
| 1574 | ** |
| 1575 | ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> |
| 1576 | ** <dd> ^This option specifies a static memory buffer that SQLite will use |
| 1577 | ** for all of its dynamic memory allocation needs beyond those provided |
| 1578 | ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. |
| 1579 | ** There are three arguments: An 8-byte aligned pointer to the memory, |
| 1580 | ** the number of bytes in the memory buffer, and the minimum allocation size. |
| 1581 | ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts |
| 1582 | ** to using its default memory allocator (the system malloc() implementation), |
| 1583 | ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the |
| 1584 | ** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or |
| 1585 | ** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory |
| 1586 | ** allocator is engaged to handle all of SQLites memory allocation needs. |
| 1587 | ** The first pointer (the memory pointer) must be aligned to an 8-byte |
| 1588 | ** boundary or subsequent behavior of SQLite will be undefined. |
| 1589 | ** The minimum allocation size is capped at 2**12. Reasonable values |
| 1590 | ** for the minimum allocation size are 2**5 through 2**8.</dd> |
| 1591 | ** |
| 1592 | ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt> |
| 1593 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1594 | ** instance of the [sqlite3_mutex_methods] structure. The argument specifies |
| 1595 | ** alternative low-level mutex routines to be used in place |
| 1596 | ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the |
| 1597 | ** content of the [sqlite3_mutex_methods] structure before the call to |
| 1598 | ** [sqlite3_config()] returns. ^If SQLite is compiled with |
| 1599 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1600 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1601 | ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will |
| 1602 | ** return [SQLITE_ERROR].</dd> |
| 1603 | ** |
| 1604 | ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt> |
| 1605 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1606 | ** instance of the [sqlite3_mutex_methods] structure. The |
| 1607 | ** [sqlite3_mutex_methods] |
| 1608 | ** structure is filled with the currently defined mutex routines.)^ |
| 1609 | ** This option can be used to overload the default mutex allocation |
| 1610 | ** routines with a wrapper used to track mutex usage for performance |
| 1611 | ** profiling or testing, for example. ^If SQLite is compiled with |
| @@ -1627,28 +1613,28 @@ | |
| 1613 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1614 | ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will |
| 1615 | ** return [SQLITE_ERROR].</dd> |
| 1616 | ** |
| 1617 | ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt> |
| 1618 | ** <dd> ^(This option takes two arguments that determine the default |
| 1619 | ** memory allocation for the lookaside memory allocator on each |
| 1620 | ** [database connection]. The first argument is the |
| 1621 | ** size of each lookaside buffer slot and the second is the number of |
| 1622 | ** slots allocated to each database connection.)^ ^(This option sets the |
| 1623 | ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] |
| 1624 | ** verb to [sqlite3_db_config()] can be used to change the lookaside |
| 1625 | ** configuration on individual connections.)^ </dd> |
| 1626 | ** |
| 1627 | ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt> |
| 1628 | ** <dd> ^(This option takes a single argument which is a pointer to |
| 1629 | ** an [sqlite3_pcache_methods2] object. This object specifies the interface |
| 1630 | ** to a custom page cache implementation.)^ ^SQLite makes a copy of the |
| 1631 | ** object and uses it for page cache memory allocations.</dd> |
| 1632 | ** |
| 1633 | ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt> |
| 1634 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1635 | ** [sqlite3_pcache_methods2] object. SQLite copies of the current |
| 1636 | ** page cache implementation into that object.)^ </dd> |
| 1637 | ** |
| 1638 | ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> |
| 1639 | ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite |
| 1640 | ** global [error log]. |
| @@ -1668,27 +1654,26 @@ | |
| 1654 | ** supplied by the application must not invoke any SQLite interface. |
| 1655 | ** In a multi-threaded application, the application-defined logger |
| 1656 | ** function must be threadsafe. </dd> |
| 1657 | ** |
| 1658 | ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI |
| 1659 | ** <dd>^(This option takes a single argument of type int. If non-zero, then |
| 1660 | ** URI handling is globally enabled. If the parameter is zero, then URI handling |
| 1661 | ** is globally disabled.)^ ^If URI handling is globally enabled, all filenames |
| 1662 | ** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or |
| 1663 | ** specified as part of [ATTACH] commands are interpreted as URIs, regardless |
| 1664 | ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database |
| 1665 | ** connection is opened. ^If it is globally disabled, filenames are |
| 1666 | ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the |
| 1667 | ** database connection is opened. ^(By default, URI handling is globally |
| 1668 | ** disabled. The default value may be changed by compiling with the |
| 1669 | ** [SQLITE_USE_URI] symbol defined.)^ |
| 1670 | ** |
| 1671 | ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN |
| 1672 | ** <dd>^This option takes a single integer argument which is interpreted as |
| 1673 | ** a boolean in order to enable or disable the use of covering indices for |
| 1674 | ** full table scans in the query optimizer. ^The default setting is determined |
| 1675 | ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on" |
| 1676 | ** if that compile-time option is omitted. |
| 1677 | ** The ability to disable the use of covering indices for full table scans |
| 1678 | ** is because some incorrectly coded legacy applications might malfunction |
| 1679 | ** when the optimization is enabled. Providing the ability to |
| @@ -1724,32 +1709,23 @@ | |
| 1709 | ** that are the default mmap size limit (the default setting for |
| 1710 | ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit. |
| 1711 | ** ^The default setting can be overridden by each database connection using |
| 1712 | ** either the [PRAGMA mmap_size] command, or by using the |
| 1713 | ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size |
| 1714 | ** cannot be changed at run-time. Nor may the maximum allowed mmap size |
| 1715 | ** exceed the compile-time maximum mmap size set by the |
| 1716 | ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^ |
| 1717 | ** ^If either argument to this option is negative, then that argument is |
| 1718 | ** changed to its compile-time default. |
| 1719 | ** |
| 1720 | ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]] |
| 1721 | ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE |
| 1722 | ** <dd>^This option is only available if SQLite is compiled for Windows |
| 1723 | ** with the [SQLITE_WIN32_MALLOC] pre-processor macro defined. |
| 1724 | ** SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value |
| 1725 | ** that specifies the maximum size of the created heap. |
| 1726 | ** </dl> |
| 1727 | */ |
| 1728 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1729 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 1730 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| 1731 | #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ |
| @@ -1770,11 +1746,10 @@ | |
| 1746 | #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */ |
| 1747 | #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */ |
| 1748 | #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */ |
| 1749 | #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */ |
| 1750 | #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */ |
| 1751 | |
| 1752 | /* |
| 1753 | ** CAPI3REF: Database Connection Configuration Options |
| 1754 | ** |
| 1755 | ** These constants are the available integer configuration options that |
| @@ -1898,49 +1873,51 @@ | |
| 1873 | SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); |
| 1874 | |
| 1875 | /* |
| 1876 | ** CAPI3REF: Count The Number Of Rows Modified |
| 1877 | ** |
| 1878 | ** ^This function returns the number of database rows that were changed |
| 1879 | ** or inserted or deleted by the most recently completed SQL statement |
| 1880 | ** on the [database connection] specified by the first parameter. |
| 1881 | ** ^(Only changes that are directly specified by the [INSERT], [UPDATE], |
| 1882 | ** or [DELETE] statement are counted. Auxiliary changes caused by |
| 1883 | ** triggers or [foreign key actions] are not counted.)^ Use the |
| 1884 | ** [sqlite3_total_changes()] function to find the total number of changes |
| 1885 | ** including changes caused by triggers and foreign key actions. |
| 1886 | ** |
| 1887 | ** ^Changes to a view that are simulated by an [INSTEAD OF trigger] |
| 1888 | ** are not counted. Only real table changes are counted. |
| 1889 | ** |
| 1890 | ** ^(A "row change" is a change to a single row of a single table |
| 1891 | ** caused by an INSERT, DELETE, or UPDATE statement. Rows that |
| 1892 | ** are changed as side effects of [REPLACE] constraint resolution, |
| 1893 | ** rollback, ABORT processing, [DROP TABLE], or by any other |
| 1894 | ** mechanisms do not count as direct row changes.)^ |
| 1895 | ** |
| 1896 | ** A "trigger context" is a scope of execution that begins and |
| 1897 | ** ends with the script of a [CREATE TRIGGER | trigger]. |
| 1898 | ** Most SQL statements are |
| 1899 | ** evaluated outside of any trigger. This is the "top level" |
| 1900 | ** trigger context. If a trigger fires from the top level, a |
| 1901 | ** new trigger context is entered for the duration of that one |
| 1902 | ** trigger. Subtriggers create subcontexts for their duration. |
| 1903 | ** |
| 1904 | ** ^Calling [sqlite3_exec()] or [sqlite3_step()] recursively does |
| 1905 | ** not create a new trigger context. |
| 1906 | ** |
| 1907 | ** ^This function returns the number of direct row changes in the |
| 1908 | ** most recent INSERT, UPDATE, or DELETE statement within the same |
| 1909 | ** trigger context. |
| 1910 | ** |
| 1911 | ** ^Thus, when called from the top level, this function returns the |
| 1912 | ** number of changes in the most recent INSERT, UPDATE, or DELETE |
| 1913 | ** that also occurred at the top level. ^(Within the body of a trigger, |
| 1914 | ** the sqlite3_changes() interface can be called to find the number of |
| 1915 | ** changes in the most recently completed INSERT, UPDATE, or DELETE |
| 1916 | ** statement within the body of the same trigger. |
| 1917 | ** However, the number returned does not include changes |
| 1918 | ** caused by subtriggers since those have their own context.)^ |
| 1919 | ** |
| 1920 | ** See also the [sqlite3_total_changes()] interface, the |
| 1921 | ** [count_changes pragma], and the [changes() SQL function]. |
| 1922 | ** |
| 1923 | ** If a separate thread makes changes on the same database connection |
| @@ -1950,21 +1927,24 @@ | |
| 1927 | SQLITE_API int sqlite3_changes(sqlite3*); |
| 1928 | |
| 1929 | /* |
| 1930 | ** CAPI3REF: Total Number Of Rows Modified |
| 1931 | ** |
| 1932 | ** ^This function returns the number of row changes caused by [INSERT], |
| 1933 | ** [UPDATE] or [DELETE] statements since the [database connection] was opened. |
| 1934 | ** ^(The count returned by sqlite3_total_changes() includes all changes |
| 1935 | ** from all [CREATE TRIGGER | trigger] contexts and changes made by |
| 1936 | ** [foreign key actions]. However, |
| 1937 | ** the count does not include changes used to implement [REPLACE] constraints, |
| 1938 | ** do rollbacks or ABORT processing, or [DROP TABLE] processing. The |
| 1939 | ** count does not include rows of views that fire an [INSTEAD OF trigger], |
| 1940 | ** though if the INSTEAD OF trigger makes changes of its own, those changes |
| 1941 | ** are counted.)^ |
| 1942 | ** ^The sqlite3_total_changes() function counts the changes as soon as |
| 1943 | ** the statement that makes them is completed (when the statement handle |
| 1944 | ** is passed to [sqlite3_reset()] or [sqlite3_finalize()]). |
| 1945 | ** |
| 1946 | ** See also the [sqlite3_changes()] interface, the |
| 1947 | ** [count_changes pragma], and the [total_changes() SQL function]. |
| 1948 | ** |
| 1949 | ** If a separate thread makes changes on the same database connection |
| 1950 | ** while [sqlite3_total_changes()] is running then the value |
| @@ -2438,18 +2418,17 @@ | |
| 2418 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2419 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2420 | ** applications to access the same PRNG for other purposes. |
| 2421 | ** |
| 2422 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2423 | ** ^If N is less than one, then P can be a NULL pointer. |
| 2424 | ** |
| 2425 | ** ^If this routine has not been previously called or if the previous |
| 2426 | ** call had N less than one, then the PRNG is seeded using randomness |
| 2427 | ** obtained from the xRandomness method of the default [sqlite3_vfs] object. |
| 2428 | ** ^If the previous call to this routine had an N of 1 or more then |
| 2429 | ** the pseudo-randomness is generated |
| 2430 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2431 | ** method. |
| 2432 | */ |
| 2433 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2434 | |
| @@ -5660,46 +5639,30 @@ | |
| 5639 | ** |
| 5640 | ** <pre> |
| 5641 | ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow; |
| 5642 | ** </pre>)^ |
| 5643 | ** |
| 5644 | ** ^If the flags parameter is non-zero, then the BLOB is opened for read |
| 5645 | ** and write access. ^If it is zero, the BLOB is opened for read access. |
| 5646 | ** ^It is not possible to open a column that is part of an index or primary |
| 5647 | ** key for writing. ^If [foreign key constraints] are enabled, it is |
| 5648 | ** not possible to open a column that is part of a [child key] for writing. |
| 5649 | ** |
| 5650 | ** ^Note that the database name is not the filename that contains |
| 5651 | ** the database but rather the symbolic name of the database that |
| 5652 | ** appears after the AS keyword when the database is connected using [ATTACH]. |
| 5653 | ** ^For the main database file, the database name is "main". |
| 5654 | ** ^For TEMP tables, the database name is "temp". |
| 5655 | ** |
| 5656 | ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is written |
| 5657 | ** to *ppBlob. Otherwise an [error code] is returned and *ppBlob is set |
| 5658 | ** to be a null pointer.)^ |
| 5659 | ** ^This function sets the [database connection] error code and message |
| 5660 | ** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()] and related |
| 5661 | ** functions. ^Note that the *ppBlob variable is always initialized in a |
| 5662 | ** way that makes it safe to invoke [sqlite3_blob_close()] on *ppBlob |
| 5663 | ** regardless of the success or failure of this routine. |
| 5664 | ** |
| 5665 | ** ^(If the row that a BLOB handle points to is modified by an |
| 5666 | ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects |
| 5667 | ** then the BLOB handle is marked as "expired". |
| 5668 | ** This is true if any column of the row is changed, even a column |
| @@ -5713,13 +5676,17 @@ | |
| 5676 | ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of |
| 5677 | ** the opened blob. ^The size of a blob may not be changed by this |
| 5678 | ** interface. Use the [UPDATE] SQL command to change the size of a |
| 5679 | ** blob. |
| 5680 | ** |
| 5681 | ** ^The [sqlite3_blob_open()] interface will fail for a [WITHOUT ROWID] |
| 5682 | ** table. Incremental BLOB I/O is not possible on [WITHOUT ROWID] tables. |
| 5683 | ** |
| 5684 | ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces |
| 5685 | ** and the built-in [zeroblob] SQL function can be used, if desired, |
| 5686 | ** to create an empty, zero-filled blob in which to read or write using |
| 5687 | ** this interface. |
| 5688 | ** |
| 5689 | ** To avoid a resource leak, every open [BLOB handle] should eventually |
| 5690 | ** be released by a call to [sqlite3_blob_close()]. |
| 5691 | */ |
| 5692 | SQLITE_API int sqlite3_blob_open( |
| @@ -5757,26 +5724,28 @@ | |
| 5724 | SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); |
| 5725 | |
| 5726 | /* |
| 5727 | ** CAPI3REF: Close A BLOB Handle |
| 5728 | ** |
| 5729 | ** ^Closes an open [BLOB handle]. |
| 5730 | ** |
| 5731 | ** ^Closing a BLOB shall cause the current transaction to commit |
| 5732 | ** if there are no other BLOBs, no pending prepared statements, and the |
| 5733 | ** database connection is in [autocommit mode]. |
| 5734 | ** ^If any writes were made to the BLOB, they might be held in cache |
| 5735 | ** until the close operation if they will fit. |
| 5736 | ** |
| 5737 | ** ^(Closing the BLOB often forces the changes |
| 5738 | ** out to disk and so if any I/O errors occur, they will likely occur |
| 5739 | ** at the time when the BLOB is closed. Any errors that occur during |
| 5740 | ** closing are reported as a non-zero return value.)^ |
| 5741 | ** |
| 5742 | ** ^(The BLOB is closed unconditionally. Even if this routine returns |
| 5743 | ** an error code, the BLOB is still closed.)^ |
| 5744 | ** |
| 5745 | ** ^Calling this routine with a null pointer (such as would be returned |
| 5746 | ** by a failed call to [sqlite3_blob_open()]) is a harmless no-op. |
| 5747 | */ |
| 5748 | SQLITE_API int sqlite3_blob_close(sqlite3_blob *); |
| 5749 | |
| 5750 | /* |
| 5751 | ** CAPI3REF: Return The Size Of An Open BLOB |
| @@ -5822,39 +5791,36 @@ | |
| 5791 | SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); |
| 5792 | |
| 5793 | /* |
| 5794 | ** CAPI3REF: Write Data Into A BLOB Incrementally |
| 5795 | ** |
| 5796 | ** ^This function is used to write data into an open [BLOB handle] from a |
| 5797 | ** caller-supplied buffer. ^N bytes of data are copied from the buffer Z |
| 5798 | ** into the open BLOB, starting at offset iOffset. |
| 5799 | ** |
| 5800 | ** ^If the [BLOB handle] passed as the first argument was not opened for |
| 5801 | ** writing (the flags parameter to [sqlite3_blob_open()] was zero), |
| 5802 | ** this function returns [SQLITE_READONLY]. |
| 5803 | ** |
| 5804 | ** ^This function may only modify the contents of the BLOB; it is |
| 5805 | ** not possible to increase the size of a BLOB using this API. |
| 5806 | ** ^If offset iOffset is less than N bytes from the end of the BLOB, |
| 5807 | ** [SQLITE_ERROR] is returned and no data is written. ^If N is |
| 5808 | ** less than zero [SQLITE_ERROR] is returned and no data is written. |
| 5809 | ** The size of the BLOB (and hence the maximum value of N+iOffset) |
| 5810 | ** can be determined using the [sqlite3_blob_bytes()] interface. |
| 5811 | ** |
| 5812 | ** ^An attempt to write to an expired [BLOB handle] fails with an |
| 5813 | ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred |
| 5814 | ** before the [BLOB handle] expired are not rolled back by the |
| 5815 | ** expiration of the handle, though of course those changes might |
| 5816 | ** have been overwritten by the statement that expired the BLOB handle |
| 5817 | ** or by other independent statements. |
| 5818 | ** |
| 5819 | ** ^(On success, sqlite3_blob_write() returns SQLITE_OK. |
| 5820 | ** Otherwise, an [error code] or an [extended error code] is returned.)^ |
| 5821 | ** |
| 5822 | ** This routine only works on a [BLOB handle] which has been created |
| 5823 | ** by a prior successful call to [sqlite3_blob_open()] and which has not |
| 5824 | ** been closed by [sqlite3_blob_close()]. Passing any other pointer in |
| 5825 | ** to this routine results in undefined and probably undesirable behavior. |
| 5826 | ** |
| @@ -6851,14 +6817,10 @@ | |
| 6817 | ** and database name of the source database, respectively. |
| 6818 | ** ^The source and destination [database connections] (parameters S and D) |
| 6819 | ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with |
| 6820 | ** an error. |
| 6821 | ** |
| 6822 | ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is |
| 6823 | ** returned and an error code and error message are stored in the |
| 6824 | ** destination [database connection] D. |
| 6825 | ** ^The error code and message for the failed call to sqlite3_backup_init() |
| 6826 | ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or |
| @@ -7447,102 +7409,10 @@ | |
| 7409 | /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */ |
| 7410 | #define SQLITE_FAIL 3 |
| 7411 | /* #define SQLITE_ABORT 4 // Also an error code */ |
| 7412 | #define SQLITE_REPLACE 5 |
| 7413 | |
| 7414 | |
| 7415 | |
| 7416 | /* |
| 7417 | ** Undo the hack that converts floating point types to integer for |
| 7418 | ** builds on processors without floating point support. |
| 7419 |