Fossil SCM
Update the built-in SQLite to the latest 3.7.7 alpha version. This adds no new capabilities - it is merely a beta-test of the SQLite version 3.7.7.
Commit
dcfa88bd466bad8192eb53372914cfe51a16d1bc
Parent
91d648426ad8117…
2 files changed
+1360
-312
+339
-77
+1360
-312
| --- 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.7.6.1. By combining all the individual C code files into this | |
| 3 | +** version 3.7.7. 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. |
| @@ -648,13 +648,13 @@ | ||
| 648 | 648 | ** |
| 649 | 649 | ** See also: [sqlite3_libversion()], |
| 650 | 650 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 651 | 651 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 652 | 652 | */ |
| 653 | -#define SQLITE_VERSION "3.7.6.1" | |
| 654 | -#define SQLITE_VERSION_NUMBER 3007006 | |
| 655 | -#define SQLITE_SOURCE_ID "2011-04-27 19:54:44 f55156c5194e85c47728b8a97fde3e5f0a5c9b56" | |
| 653 | +#define SQLITE_VERSION "3.7.7" | |
| 654 | +#define SQLITE_VERSION_NUMBER 3007007 | |
| 655 | +#define SQLITE_SOURCE_ID "2011-05-18 03:02:10 186d7ff1d9804d508e472e4939608bf2be67bdc2" | |
| 656 | 656 | |
| 657 | 657 | /* |
| 658 | 658 | ** CAPI3REF: Run-Time Library Version Numbers |
| 659 | 659 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 660 | 660 | ** |
| @@ -916,11 +916,12 @@ | ||
| 916 | 916 | ** Many SQLite functions return an integer result code from the set shown |
| 917 | 917 | ** here in order to indicates success or failure. |
| 918 | 918 | ** |
| 919 | 919 | ** New error codes may be added in future versions of SQLite. |
| 920 | 920 | ** |
| 921 | -** See also: [SQLITE_IOERR_READ | extended result codes] | |
| 921 | +** See also: [SQLITE_IOERR_READ | extended result codes], | |
| 922 | +** [sqlite3_vtab_on_conflict()] [SQLITE_ROLLBACK | result codes]. | |
| 922 | 923 | */ |
| 923 | 924 | #define SQLITE_OK 0 /* Successful result */ |
| 924 | 925 | /* beginning-of-error-codes */ |
| 925 | 926 | #define SQLITE_ERROR 1 /* SQL error or missing database */ |
| 926 | 927 | #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ |
| @@ -998,25 +999,26 @@ | ||
| 998 | 999 | #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) |
| 999 | 1000 | #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) |
| 1000 | 1001 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 1001 | 1002 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 1002 | 1003 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 1004 | +#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) | |
| 1003 | 1005 | |
| 1004 | 1006 | /* |
| 1005 | 1007 | ** CAPI3REF: Flags For File Open Operations |
| 1006 | 1008 | ** |
| 1007 | 1009 | ** These bit values are intended for use in the |
| 1008 | 1010 | ** 3rd parameter to the [sqlite3_open_v2()] interface and |
| 1009 | -** in the 4th parameter to the xOpen method of the | |
| 1010 | -** [sqlite3_vfs] object. | |
| 1011 | +** in the 4th parameter to the [sqlite3_vfs.xOpen] method. | |
| 1011 | 1012 | */ |
| 1012 | 1013 | #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ |
| 1013 | 1014 | #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ |
| 1014 | 1015 | #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ |
| 1015 | 1016 | #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ |
| 1016 | 1017 | #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ |
| 1017 | 1018 | #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ |
| 1019 | +#define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */ | |
| 1018 | 1020 | #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ |
| 1019 | 1021 | #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ |
| 1020 | 1022 | #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ |
| 1021 | 1023 | #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ |
| 1022 | 1024 | #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ |
| @@ -1123,21 +1125,22 @@ | ||
| 1123 | 1125 | }; |
| 1124 | 1126 | |
| 1125 | 1127 | /* |
| 1126 | 1128 | ** CAPI3REF: OS Interface File Virtual Methods Object |
| 1127 | 1129 | ** |
| 1128 | -** Every file opened by the [sqlite3_vfs] xOpen method populates an | |
| 1130 | +** Every file opened by the [sqlite3_vfs.xOpen] method populates an | |
| 1129 | 1131 | ** [sqlite3_file] object (or, more commonly, a subclass of the |
| 1130 | 1132 | ** [sqlite3_file] object) with a pointer to an instance of this object. |
| 1131 | 1133 | ** This object defines the methods used to perform various operations |
| 1132 | 1134 | ** against the open file represented by the [sqlite3_file] object. |
| 1133 | 1135 | ** |
| 1134 | -** If the xOpen method sets the sqlite3_file.pMethods element | |
| 1136 | +** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element | |
| 1135 | 1137 | ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method |
| 1136 | -** may be invoked even if the xOpen reported that it failed. The | |
| 1137 | -** only way to prevent a call to xClose following a failed xOpen | |
| 1138 | -** is for the xOpen to set the sqlite3_file.pMethods element to NULL. | |
| 1138 | +** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The | |
| 1139 | +** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen] | |
| 1140 | +** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element | |
| 1141 | +** to NULL. | |
| 1139 | 1142 | ** |
| 1140 | 1143 | ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or |
| 1141 | 1144 | ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync(). |
| 1142 | 1145 | ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY] |
| 1143 | 1146 | ** flag may be ORed in to indicate that only the data of the file |
| @@ -1302,10 +1305,11 @@ | ||
| 1302 | 1305 | */ |
| 1303 | 1306 | typedef struct sqlite3_mutex sqlite3_mutex; |
| 1304 | 1307 | |
| 1305 | 1308 | /* |
| 1306 | 1309 | ** CAPI3REF: OS Interface Object |
| 1310 | +** KEYWORDS: VFS VFSes | |
| 1307 | 1311 | ** |
| 1308 | 1312 | ** An instance of the sqlite3_vfs object defines the interface between |
| 1309 | 1313 | ** the SQLite core and the underlying operating system. The "vfs" |
| 1310 | 1314 | ** in the name of the object stands for "virtual file system". |
| 1311 | 1315 | ** |
| @@ -1334,10 +1338,11 @@ | ||
| 1334 | 1338 | ** object once the object has been registered. |
| 1335 | 1339 | ** |
| 1336 | 1340 | ** The zName field holds the name of the VFS module. The name must |
| 1337 | 1341 | ** be unique across all VFS modules. |
| 1338 | 1342 | ** |
| 1343 | +** [[sqlite3_vfs.xOpen]] | |
| 1339 | 1344 | ** ^SQLite guarantees that the zFilename parameter to xOpen |
| 1340 | 1345 | ** is either a NULL pointer or string obtained |
| 1341 | 1346 | ** from xFullPathname() with an optional suffix added. |
| 1342 | 1347 | ** ^If a suffix is added to the zFilename parameter, it will |
| 1343 | 1348 | ** consist of a single "-" character followed by no more than |
| @@ -1411,10 +1416,11 @@ | ||
| 1411 | 1416 | ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do |
| 1412 | 1417 | ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods |
| 1413 | 1418 | ** element will be valid after xOpen returns regardless of the success |
| 1414 | 1419 | ** or failure of the xOpen call. |
| 1415 | 1420 | ** |
| 1421 | +** [[sqlite3_vfs.xAccess]] | |
| 1416 | 1422 | ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] |
| 1417 | 1423 | ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to |
| 1418 | 1424 | ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ] |
| 1419 | 1425 | ** to test whether a file is at least readable. The file can be a |
| 1420 | 1426 | ** directory. |
| @@ -1657,13 +1663,13 @@ | ||
| 1657 | 1663 | ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE. |
| 1658 | 1664 | ** Note, however, that ^sqlite3_config() can be called as part of the |
| 1659 | 1665 | ** implementation of an application-defined [sqlite3_os_init()]. |
| 1660 | 1666 | ** |
| 1661 | 1667 | ** The first argument to sqlite3_config() is an integer |
| 1662 | -** [SQLITE_CONFIG_SINGLETHREAD | configuration option] that determines | |
| 1668 | +** [configuration option] that determines | |
| 1663 | 1669 | ** what property of SQLite is to be configured. Subsequent arguments |
| 1664 | -** vary depending on the [SQLITE_CONFIG_SINGLETHREAD | configuration option] | |
| 1670 | +** vary depending on the [configuration option] | |
| 1665 | 1671 | ** in the first argument. |
| 1666 | 1672 | ** |
| 1667 | 1673 | ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. |
| 1668 | 1674 | ** ^If the option is unknown or SQLite is unable to set the option |
| 1669 | 1675 | ** then this routine returns a non-zero [error code]. |
| @@ -1769,10 +1775,11 @@ | ||
| 1769 | 1775 | void *pAppData; /* Argument to xInit() and xShutdown() */ |
| 1770 | 1776 | }; |
| 1771 | 1777 | |
| 1772 | 1778 | /* |
| 1773 | 1779 | ** CAPI3REF: Configuration Options |
| 1780 | +** KEYWORDS: {configuration option} | |
| 1774 | 1781 | ** |
| 1775 | 1782 | ** These constants are the available integer configuration options that |
| 1776 | 1783 | ** can be passed as the first argument to the [sqlite3_config()] interface. |
| 1777 | 1784 | ** |
| 1778 | 1785 | ** New configuration options may be added in future releases of SQLite. |
| @@ -1781,11 +1788,11 @@ | ||
| 1781 | 1788 | ** the call worked. The [sqlite3_config()] interface will return a |
| 1782 | 1789 | ** non-zero [error code] if a discontinued or unsupported configuration option |
| 1783 | 1790 | ** is invoked. |
| 1784 | 1791 | ** |
| 1785 | 1792 | ** <dl> |
| 1786 | -** <dt>SQLITE_CONFIG_SINGLETHREAD</dt> | |
| 1793 | +** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt> | |
| 1787 | 1794 | ** <dd>There are no arguments to this option. ^This option sets the |
| 1788 | 1795 | ** [threading mode] to Single-thread. In other words, it disables |
| 1789 | 1796 | ** all mutexing and puts SQLite into a mode where it can only be used |
| 1790 | 1797 | ** by a single thread. ^If SQLite is compiled with |
| 1791 | 1798 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| @@ -1792,11 +1799,11 @@ | ||
| 1792 | 1799 | ** it is not possible to change the [threading mode] from its default |
| 1793 | 1800 | ** value of Single-thread and so [sqlite3_config()] will return |
| 1794 | 1801 | ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD |
| 1795 | 1802 | ** configuration option.</dd> |
| 1796 | 1803 | ** |
| 1797 | -** <dt>SQLITE_CONFIG_MULTITHREAD</dt> | |
| 1804 | +** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt> | |
| 1798 | 1805 | ** <dd>There are no arguments to this option. ^This option sets the |
| 1799 | 1806 | ** [threading mode] to Multi-thread. In other words, it disables |
| 1800 | 1807 | ** mutexing on [database connection] and [prepared statement] objects. |
| 1801 | 1808 | ** The application is responsible for serializing access to |
| 1802 | 1809 | ** [database connections] and [prepared statements]. But other mutexes |
| @@ -1806,11 +1813,11 @@ | ||
| 1806 | 1813 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1807 | 1814 | ** it is not possible to set the Multi-thread [threading mode] and |
| 1808 | 1815 | ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
| 1809 | 1816 | ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd> |
| 1810 | 1817 | ** |
| 1811 | -** <dt>SQLITE_CONFIG_SERIALIZED</dt> | |
| 1818 | +** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt> | |
| 1812 | 1819 | ** <dd>There are no arguments to this option. ^This option sets the |
| 1813 | 1820 | ** [threading mode] to Serialized. In other words, this option enables |
| 1814 | 1821 | ** all mutexes including the recursive |
| 1815 | 1822 | ** mutexes on [database connection] and [prepared statement] objects. |
| 1816 | 1823 | ** In this mode (which is the default when SQLite is compiled with |
| @@ -1822,27 +1829,27 @@ | ||
| 1822 | 1829 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1823 | 1830 | ** it is not possible to set the Serialized [threading mode] and |
| 1824 | 1831 | ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
| 1825 | 1832 | ** SQLITE_CONFIG_SERIALIZED configuration option.</dd> |
| 1826 | 1833 | ** |
| 1827 | -** <dt>SQLITE_CONFIG_MALLOC</dt> | |
| 1834 | +** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt> | |
| 1828 | 1835 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1829 | 1836 | ** instance of the [sqlite3_mem_methods] structure. The argument specifies |
| 1830 | 1837 | ** alternative low-level memory allocation routines to be used in place of |
| 1831 | 1838 | ** the memory allocation routines built into SQLite.)^ ^SQLite makes |
| 1832 | 1839 | ** its own private copy of the content of the [sqlite3_mem_methods] structure |
| 1833 | 1840 | ** before the [sqlite3_config()] call returns.</dd> |
| 1834 | 1841 | ** |
| 1835 | -** <dt>SQLITE_CONFIG_GETMALLOC</dt> | |
| 1842 | +** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt> | |
| 1836 | 1843 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1837 | 1844 | ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods] |
| 1838 | 1845 | ** structure is filled with the currently defined memory allocation routines.)^ |
| 1839 | 1846 | ** This option can be used to overload the default memory allocation |
| 1840 | 1847 | ** routines with a wrapper that simulations memory allocation failure or |
| 1841 | 1848 | ** tracks memory usage, for example. </dd> |
| 1842 | 1849 | ** |
| 1843 | -** <dt>SQLITE_CONFIG_MEMSTATUS</dt> | |
| 1850 | +** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> | |
| 1844 | 1851 | ** <dd> ^This option takes single argument of type int, interpreted as a |
| 1845 | 1852 | ** boolean, which enables or disables the collection of memory allocation |
| 1846 | 1853 | ** statistics. ^(When memory allocation statistics are disabled, the |
| 1847 | 1854 | ** following SQLite interfaces become non-operational: |
| 1848 | 1855 | ** <ul> |
| @@ -1854,11 +1861,11 @@ | ||
| 1854 | 1861 | ** ^Memory allocation statistics are enabled by default unless SQLite is |
| 1855 | 1862 | ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory |
| 1856 | 1863 | ** allocation statistics are disabled by default. |
| 1857 | 1864 | ** </dd> |
| 1858 | 1865 | ** |
| 1859 | -** <dt>SQLITE_CONFIG_SCRATCH</dt> | |
| 1866 | +** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt> | |
| 1860 | 1867 | ** <dd> ^This option specifies a static memory buffer that SQLite can use for |
| 1861 | 1868 | ** scratch memory. There are three arguments: A pointer an 8-byte |
| 1862 | 1869 | ** aligned memory buffer from which the scratch allocations will be |
| 1863 | 1870 | ** drawn, the size of each scratch allocation (sz), |
| 1864 | 1871 | ** and the maximum number of scratch allocations (N). The sz |
| @@ -1870,11 +1877,11 @@ | ||
| 1870 | 1877 | ** ^SQLite will never require a scratch buffer that is more than 6 |
| 1871 | 1878 | ** times the database page size. ^If SQLite needs needs additional |
| 1872 | 1879 | ** scratch memory beyond what is provided by this configuration option, then |
| 1873 | 1880 | ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd> |
| 1874 | 1881 | ** |
| 1875 | -** <dt>SQLITE_CONFIG_PAGECACHE</dt> | |
| 1882 | +** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt> | |
| 1876 | 1883 | ** <dd> ^This option specifies a static memory buffer that SQLite can use for |
| 1877 | 1884 | ** the database page cache with the default page cache implemenation. |
| 1878 | 1885 | ** This configuration should not be used if an application-define page |
| 1879 | 1886 | ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option. |
| 1880 | 1887 | ** There are three arguments to this option: A pointer to 8-byte aligned |
| @@ -1891,11 +1898,11 @@ | ||
| 1891 | 1898 | ** SQLite goes to [sqlite3_malloc()] for the additional storage space. |
| 1892 | 1899 | ** The pointer in the first argument must |
| 1893 | 1900 | ** be aligned to an 8-byte boundary or subsequent behavior of SQLite |
| 1894 | 1901 | ** will be undefined.</dd> |
| 1895 | 1902 | ** |
| 1896 | -** <dt>SQLITE_CONFIG_HEAP</dt> | |
| 1903 | +** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> | |
| 1897 | 1904 | ** <dd> ^This option specifies a static memory buffer that SQLite will use |
| 1898 | 1905 | ** for all of its dynamic memory allocation needs beyond those provided |
| 1899 | 1906 | ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. |
| 1900 | 1907 | ** There are three arguments: An 8-byte aligned pointer to the memory, |
| 1901 | 1908 | ** the number of bytes in the memory buffer, and the minimum allocation size. |
| @@ -1908,11 +1915,11 @@ | ||
| 1908 | 1915 | ** The first pointer (the memory pointer) must be aligned to an 8-byte |
| 1909 | 1916 | ** boundary or subsequent behavior of SQLite will be undefined. |
| 1910 | 1917 | ** The minimum allocation size is capped at 2^12. Reasonable values |
| 1911 | 1918 | ** for the minimum allocation size are 2^5 through 2^8.</dd> |
| 1912 | 1919 | ** |
| 1913 | -** <dt>SQLITE_CONFIG_MUTEX</dt> | |
| 1920 | +** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt> | |
| 1914 | 1921 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1915 | 1922 | ** instance of the [sqlite3_mutex_methods] structure. The argument specifies |
| 1916 | 1923 | ** alternative low-level mutex routines to be used in place |
| 1917 | 1924 | ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the |
| 1918 | 1925 | ** content of the [sqlite3_mutex_methods] structure before the call to |
| @@ -1920,11 +1927,11 @@ | ||
| 1920 | 1927 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1921 | 1928 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1922 | 1929 | ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will |
| 1923 | 1930 | ** return [SQLITE_ERROR].</dd> |
| 1924 | 1931 | ** |
| 1925 | -** <dt>SQLITE_CONFIG_GETMUTEX</dt> | |
| 1932 | +** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt> | |
| 1926 | 1933 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1927 | 1934 | ** instance of the [sqlite3_mutex_methods] structure. The |
| 1928 | 1935 | ** [sqlite3_mutex_methods] |
| 1929 | 1936 | ** structure is filled with the currently defined mutex routines.)^ |
| 1930 | 1937 | ** This option can be used to overload the default mutex allocation |
| @@ -1933,32 +1940,32 @@ | ||
| 1933 | 1940 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1934 | 1941 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1935 | 1942 | ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will |
| 1936 | 1943 | ** return [SQLITE_ERROR].</dd> |
| 1937 | 1944 | ** |
| 1938 | -** <dt>SQLITE_CONFIG_LOOKASIDE</dt> | |
| 1945 | +** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt> | |
| 1939 | 1946 | ** <dd> ^(This option takes two arguments that determine the default |
| 1940 | 1947 | ** memory allocation for the lookaside memory allocator on each |
| 1941 | 1948 | ** [database connection]. The first argument is the |
| 1942 | 1949 | ** size of each lookaside buffer slot and the second is the number of |
| 1943 | 1950 | ** slots allocated to each database connection.)^ ^(This option sets the |
| 1944 | 1951 | ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] |
| 1945 | 1952 | ** verb to [sqlite3_db_config()] can be used to change the lookaside |
| 1946 | 1953 | ** configuration on individual connections.)^ </dd> |
| 1947 | 1954 | ** |
| 1948 | -** <dt>SQLITE_CONFIG_PCACHE</dt> | |
| 1955 | +** [[SQLITE_CONFIG_PCACHE]] <dt>SQLITE_CONFIG_PCACHE</dt> | |
| 1949 | 1956 | ** <dd> ^(This option takes a single argument which is a pointer to |
| 1950 | 1957 | ** an [sqlite3_pcache_methods] object. This object specifies the interface |
| 1951 | 1958 | ** to a custom page cache implementation.)^ ^SQLite makes a copy of the |
| 1952 | 1959 | ** object and uses it for page cache memory allocations.</dd> |
| 1953 | 1960 | ** |
| 1954 | -** <dt>SQLITE_CONFIG_GETPCACHE</dt> | |
| 1961 | +** [[SQLITE_CONFIG_GETPCACHE]] <dt>SQLITE_CONFIG_GETPCACHE</dt> | |
| 1955 | 1962 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1956 | 1963 | ** [sqlite3_pcache_methods] object. SQLite copies of the current |
| 1957 | 1964 | ** page cache implementation into that object.)^ </dd> |
| 1958 | 1965 | ** |
| 1959 | -** <dt>SQLITE_CONFIG_LOG</dt> | |
| 1966 | +** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> | |
| 1960 | 1967 | ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a |
| 1961 | 1968 | ** function with a call signature of void(*)(void*,int,const char*), |
| 1962 | 1969 | ** and a pointer to void. ^If the function pointer is not NULL, it is |
| 1963 | 1970 | ** invoked by [sqlite3_log()] to process each logging event. ^If the |
| 1964 | 1971 | ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op. |
| @@ -1972,10 +1979,22 @@ | ||
| 1972 | 1979 | ** The SQLite logging interface is not reentrant; the logger function |
| 1973 | 1980 | ** supplied by the application must not invoke any SQLite interface. |
| 1974 | 1981 | ** In a multi-threaded application, the application-defined logger |
| 1975 | 1982 | ** function must be threadsafe. </dd> |
| 1976 | 1983 | ** |
| 1984 | +** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI | |
| 1985 | +** <dd> This option takes a single argument of type int. If non-zero, then | |
| 1986 | +** URI handling is globally enabled. If the parameter is zero, then URI handling | |
| 1987 | +** is globally disabled. If URI handling is globally enabled, all filenames | |
| 1988 | +** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or | |
| 1989 | +** specified as part of [ATTACH] commands are interpreted as URIs, regardless | |
| 1990 | +** of whether or not the [SQLITE_OPEN_URI] flag is set when the database | |
| 1991 | +** connection is opened. If it is globally disabled, filenames are | |
| 1992 | +** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the | |
| 1993 | +** database connection is opened. By default, URI handling is globally | |
| 1994 | +** disabled. The default value may be changed by compiling with the | |
| 1995 | +** [SQLITE_USE_URI] symbol defined. | |
| 1977 | 1996 | ** </dl> |
| 1978 | 1997 | */ |
| 1979 | 1998 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1980 | 1999 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 1981 | 2000 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| @@ -1990,10 +2009,11 @@ | ||
| 1990 | 2009 | /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ |
| 1991 | 2010 | #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ |
| 1992 | 2011 | #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */ |
| 1993 | 2012 | #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */ |
| 1994 | 2013 | #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ |
| 2014 | +#define SQLITE_CONFIG_URI 17 /* int */ | |
| 1995 | 2015 | |
| 1996 | 2016 | /* |
| 1997 | 2017 | ** CAPI3REF: Database Connection Configuration Options |
| 1998 | 2018 | ** |
| 1999 | 2019 | ** These constants are the available integer configuration options that |
| @@ -2075,17 +2095,21 @@ | ||
| 2075 | 2095 | ** the table has a column of type [INTEGER PRIMARY KEY] then that column |
| 2076 | 2096 | ** is another alias for the rowid. |
| 2077 | 2097 | ** |
| 2078 | 2098 | ** ^This routine returns the [rowid] of the most recent |
| 2079 | 2099 | ** successful [INSERT] into the database from the [database connection] |
| 2080 | -** in the first argument. ^If no successful [INSERT]s | |
| 2100 | +** in the first argument. ^As of SQLite version 3.7.7, this routines | |
| 2101 | +** records the last insert rowid of both ordinary tables and [virtual tables]. | |
| 2102 | +** ^If no successful [INSERT]s | |
| 2081 | 2103 | ** have ever occurred on that database connection, zero is returned. |
| 2082 | 2104 | ** |
| 2083 | -** ^(If an [INSERT] occurs within a trigger, then the [rowid] of the inserted | |
| 2084 | -** row is returned by this routine as long as the trigger is running. | |
| 2085 | -** But once the trigger terminates, the value returned by this routine | |
| 2086 | -** reverts to the last value inserted before the trigger fired.)^ | |
| 2105 | +** ^(If an [INSERT] occurs within a trigger or within a [virtual table] | |
| 2106 | +** method, then this routine will return the [rowid] of the inserted | |
| 2107 | +** row as long as the trigger or virtual table method is running. | |
| 2108 | +** But once the trigger or virtual table method ends, the value returned | |
| 2109 | +** by this routine reverts to what it was before the trigger or virtual | |
| 2110 | +** table method began.)^ | |
| 2087 | 2111 | ** |
| 2088 | 2112 | ** ^An [INSERT] that fails due to a constraint violation is not a |
| 2089 | 2113 | ** successful [INSERT] and does not change the value returned by this |
| 2090 | 2114 | ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK, |
| 2091 | 2115 | ** and INSERT OR ABORT make no changes to the return value of this |
| @@ -2744,10 +2768,13 @@ | ||
| 2744 | 2768 | ** The [sqlite3_set_authorizer | authorizer callback function] must |
| 2745 | 2769 | ** return either [SQLITE_OK] or one of these two constants in order |
| 2746 | 2770 | ** to signal SQLite whether or not the action is permitted. See the |
| 2747 | 2771 | ** [sqlite3_set_authorizer | authorizer documentation] for additional |
| 2748 | 2772 | ** information. |
| 2773 | +** | |
| 2774 | +** Note that SQLITE_IGNORE is also used as a [SQLITE_ROLLBACK | return code] | |
| 2775 | +** from the [sqlite3_vtab_on_conflict()] interface. | |
| 2749 | 2776 | */ |
| 2750 | 2777 | #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ |
| 2751 | 2778 | #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ |
| 2752 | 2779 | |
| 2753 | 2780 | /* |
| @@ -2866,11 +2893,11 @@ | ||
| 2866 | 2893 | SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); |
| 2867 | 2894 | |
| 2868 | 2895 | /* |
| 2869 | 2896 | ** CAPI3REF: Opening A New Database Connection |
| 2870 | 2897 | ** |
| 2871 | -** ^These routines open an SQLite database file whose name is given by the | |
| 2898 | +** ^These routines open an SQLite database file as specified by the | |
| 2872 | 2899 | ** filename argument. ^The filename argument is interpreted as UTF-8 for |
| 2873 | 2900 | ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte |
| 2874 | 2901 | ** order for sqlite3_open16(). ^(A [database connection] handle is usually |
| 2875 | 2902 | ** returned in *ppDb, even if an error occurs. The only exception is that |
| 2876 | 2903 | ** if SQLite is unable to allocate memory to hold the [sqlite3] object, |
| @@ -2893,11 +2920,11 @@ | ||
| 2893 | 2920 | ** except that it accepts two additional parameters for additional control |
| 2894 | 2921 | ** over the new database connection. ^(The flags parameter to |
| 2895 | 2922 | ** sqlite3_open_v2() can take one of |
| 2896 | 2923 | ** the following three values, optionally combined with the |
| 2897 | 2924 | ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE], |
| 2898 | -** and/or [SQLITE_OPEN_PRIVATECACHE] flags:)^ | |
| 2925 | +** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^ | |
| 2899 | 2926 | ** |
| 2900 | 2927 | ** <dl> |
| 2901 | 2928 | ** ^(<dt>[SQLITE_OPEN_READONLY]</dt> |
| 2902 | 2929 | ** <dd>The database is opened in read-only mode. If the database does not |
| 2903 | 2930 | ** already exist, an error is returned.</dd>)^ |
| @@ -2912,13 +2939,12 @@ | ||
| 2912 | 2939 | ** it does not already exist. This is the behavior that is always used for |
| 2913 | 2940 | ** sqlite3_open() and sqlite3_open16().</dd>)^ |
| 2914 | 2941 | ** </dl> |
| 2915 | 2942 | ** |
| 2916 | 2943 | ** If the 3rd parameter to sqlite3_open_v2() is not one of the |
| 2917 | -** combinations shown above or one of the combinations shown above combined | |
| 2918 | -** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], | |
| 2919 | -** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_PRIVATECACHE] flags, | |
| 2944 | +** combinations shown above optionally combined with other | |
| 2945 | +** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits] | |
| 2920 | 2946 | ** then the behavior is undefined. |
| 2921 | 2947 | ** |
| 2922 | 2948 | ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection |
| 2923 | 2949 | ** opens in the multi-thread [threading mode] as long as the single-thread |
| 2924 | 2950 | ** mode has not been set at compile-time or start-time. ^If the |
| @@ -2928,10 +2954,15 @@ | ||
| 2928 | 2954 | ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be |
| 2929 | 2955 | ** eligible to use [shared cache mode], regardless of whether or not shared |
| 2930 | 2956 | ** cache is enabled using [sqlite3_enable_shared_cache()]. ^The |
| 2931 | 2957 | ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not |
| 2932 | 2958 | ** participate in [shared cache mode] even if it is enabled. |
| 2959 | +** | |
| 2960 | +** ^The fourth parameter to sqlite3_open_v2() is the name of the | |
| 2961 | +** [sqlite3_vfs] object that defines the operating system interface that | |
| 2962 | +** the new database connection should use. ^If the fourth parameter is | |
| 2963 | +** a NULL pointer then the default [sqlite3_vfs] object is used. | |
| 2933 | 2964 | ** |
| 2934 | 2965 | ** ^If the filename is ":memory:", then a private, temporary in-memory database |
| 2935 | 2966 | ** is created for the connection. ^This in-memory database will vanish when |
| 2936 | 2967 | ** the database connection is closed. Future versions of SQLite might |
| 2937 | 2968 | ** make use of additional special filenames that begin with the ":" character. |
| @@ -2941,14 +2972,115 @@ | ||
| 2941 | 2972 | ** |
| 2942 | 2973 | ** ^If the filename is an empty string, then a private, temporary |
| 2943 | 2974 | ** on-disk database will be created. ^This private database will be |
| 2944 | 2975 | ** automatically deleted as soon as the database connection is closed. |
| 2945 | 2976 | ** |
| 2946 | -** ^The fourth parameter to sqlite3_open_v2() is the name of the | |
| 2947 | -** [sqlite3_vfs] object that defines the operating system interface that | |
| 2948 | -** the new database connection should use. ^If the fourth parameter is | |
| 2949 | -** a NULL pointer then the default [sqlite3_vfs] object is used. | |
| 2977 | +** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3> | |
| 2978 | +** | |
| 2979 | +** ^If [URI filename] interpretation is enabled, and the filename argument | |
| 2980 | +** begins with "file:", then the filename is interpreted as a URI. ^URI | |
| 2981 | +** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is | |
| 2982 | +** is set in the fourth argument to sqlite3_open_v2(), or if it has | |
| 2983 | +** been enabled globally using the [SQLITE_CONFIG_URI] option with the | |
| 2984 | +** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option. | |
| 2985 | +** As of SQLite version 3.7.7, URI filename interpretation is turned off | |
| 2986 | +** by default, but future releases of SQLite might enable URI filename | |
| 2987 | +** intepretation by default. See "[URI filenames]" for additional | |
| 2988 | +** information. | |
| 2989 | +** | |
| 2990 | +** URI filenames are parsed according to RFC 3986. ^If the URI contains an | |
| 2991 | +** authority, then it must be either an empty string or the string | |
| 2992 | +** "localhost". ^If the authority is not an empty string or "localhost", an | |
| 2993 | +** error is returned to the caller. ^The fragment component of a URI, if | |
| 2994 | +** present, is ignored. | |
| 2995 | +** | |
| 2996 | +** ^SQLite uses the path component of the URI as the name of the disk file | |
| 2997 | +** which contains the database. ^If the path begins with a '/' character, | |
| 2998 | +** then it is interpreted as an absolute path. ^If the path does not begin | |
| 2999 | +** with a '/' (meaning that the authority section is omitted from the URI) | |
| 3000 | +** then the path is interpreted as a relative path. | |
| 3001 | +** ^On windows, the first component of an absolute path | |
| 3002 | +** is a drive specification (e.g. "C:"). | |
| 3003 | +** | |
| 3004 | +** [[core URI query parameters]] | |
| 3005 | +** The query component of a URI may contain parameters that are interpreted | |
| 3006 | +** either by SQLite itself, or by a [VFS | custom VFS implementation]. | |
| 3007 | +** SQLite interprets the following three query parameters: | |
| 3008 | +** | |
| 3009 | +** <ul> | |
| 3010 | +** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of | |
| 3011 | +** a VFS object that provides the operating system interface that should | |
| 3012 | +** be used to access the database file on disk. ^If this option is set to | |
| 3013 | +** an empty string the default VFS object is used. ^Specifying an unknown | |
| 3014 | +** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is | |
| 3015 | +** present, then the VFS specified by the option takes precedence over | |
| 3016 | +** the value passed as the fourth parameter to sqlite3_open_v2(). | |
| 3017 | +** | |
| 3018 | +** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw" or | |
| 3019 | +** "rwc". Attempting to set it to any other value is an error)^. | |
| 3020 | +** ^If "ro" is specified, then the database is opened for read-only | |
| 3021 | +** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the | |
| 3022 | +** third argument to sqlite3_prepare_v2(). ^If the mode option is set to | |
| 3023 | +** "rw", then the database is opened for read-write (but not create) | |
| 3024 | +** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had | |
| 3025 | +** been set. ^Value "rwc" is equivalent to setting both | |
| 3026 | +** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If sqlite3_open_v2() is | |
| 3027 | +** used, it is an error to specify a value for the mode parameter that is | |
| 3028 | +** less restrictive than that specified by the flags passed as the third | |
| 3029 | +** parameter. | |
| 3030 | +** | |
| 3031 | +** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or | |
| 3032 | +** "private". ^Setting it to "shared" is equivalent to setting the | |
| 3033 | +** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to | |
| 3034 | +** sqlite3_open_v2(). ^Setting the cache parameter to "private" is | |
| 3035 | +** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit. | |
| 3036 | +** ^If sqlite3_open_v2() is used and the "cache" parameter is present in | |
| 3037 | +** a URI filename, its value overrides any behaviour requested by setting | |
| 3038 | +** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag. | |
| 3039 | +** </ul> | |
| 3040 | +** | |
| 3041 | +** ^Specifying an unknown parameter in the query component of a URI is not an | |
| 3042 | +** error. Future versions of SQLite might understand additional query | |
| 3043 | +** parameters. See "[query parameters with special meaning to SQLite]" for | |
| 3044 | +** additional information. | |
| 3045 | +** | |
| 3046 | +** [[URI filename examples]] <h3>URI filename examples</h3> | |
| 3047 | +** | |
| 3048 | +** <table border="1" align=center cellpadding=5> | |
| 3049 | +** <tr><th> URI filenames <th> Results | |
| 3050 | +** <tr><td> file:data.db <td> | |
| 3051 | +** Open the file "data.db" in the current directory. | |
| 3052 | +** <tr><td> file:/home/fred/data.db<br> | |
| 3053 | +** file:///home/fred/data.db <br> | |
| 3054 | +** file://localhost/home/fred/data.db <br> <td> | |
| 3055 | +** Open the database file "/home/fred/data.db". | |
| 3056 | +** <tr><td> file://darkstar/home/fred/data.db <td> | |
| 3057 | +** An error. "darkstar" is not a recognized authority. | |
| 3058 | +** <tr><td style="white-space:nowrap"> | |
| 3059 | +** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db | |
| 3060 | +** <td> Windows only: Open the file "data.db" on fred's desktop on drive | |
| 3061 | +** C:. Note that the %20 escaping in this example is not strictly | |
| 3062 | +** necessary - space characters can be used literally | |
| 3063 | +** in URI filenames. | |
| 3064 | +** <tr><td> file:data.db?mode=ro&cache=private <td> | |
| 3065 | +** Open file "data.db" in the current directory for read-only access. | |
| 3066 | +** Regardless of whether or not shared-cache mode is enabled by | |
| 3067 | +** default, use a private cache. | |
| 3068 | +** <tr><td> file:/home/fred/data.db?vfs=unix-nolock <td> | |
| 3069 | +** Open file "/home/fred/data.db". Use the special VFS "unix-nolock". | |
| 3070 | +** <tr><td> file:data.db?mode=readonly <td> | |
| 3071 | +** An error. "readonly" is not a valid option for the "mode" parameter. | |
| 3072 | +** </table> | |
| 3073 | +** | |
| 3074 | +** ^URI hexadecimal escape sequences (%HH) are supported within the path and | |
| 3075 | +** query components of a URI. A hexadecimal escape sequence consists of a | |
| 3076 | +** percent sign - "%" - followed by exactly two hexadecimal digits | |
| 3077 | +** specifying an octet value. ^Before the path or query components of a | |
| 3078 | +** URI filename are interpreted, they are encoded using UTF-8 and all | |
| 3079 | +** hexadecimal escape sequences replaced by a single byte containing the | |
| 3080 | +** corresponding octet. If this process generates an invalid UTF-8 encoding, | |
| 3081 | +** the results are undefined. | |
| 2950 | 3082 | ** |
| 2951 | 3083 | ** <b>Note to Windows users:</b> The encoding used for the filename argument |
| 2952 | 3084 | ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever |
| 2953 | 3085 | ** codepage is currently defined. Filenames containing international |
| 2954 | 3086 | ** characters must be converted to UTF-8 prior to passing them into |
| @@ -2966,10 +3098,30 @@ | ||
| 2966 | 3098 | const char *filename, /* Database filename (UTF-8) */ |
| 2967 | 3099 | sqlite3 **ppDb, /* OUT: SQLite db handle */ |
| 2968 | 3100 | int flags, /* Flags */ |
| 2969 | 3101 | const char *zVfs /* Name of VFS module to use */ |
| 2970 | 3102 | ); |
| 3103 | + | |
| 3104 | +/* | |
| 3105 | +** CAPI3REF: Obtain Values For URI Parameters | |
| 3106 | +** | |
| 3107 | +** This is a utility routine, useful to VFS implementations, that checks | |
| 3108 | +** to see if a database file was a URI that contained a specific query | |
| 3109 | +** parameter, and if so obtains the value of the query parameter. | |
| 3110 | +** | |
| 3111 | +** The zFilename argument is the filename pointer passed into the xOpen() | |
| 3112 | +** method of a VFS implementation. The zParam argument is the name of the | |
| 3113 | +** query parameter we seek. This routine returns the value of the zParam | |
| 3114 | +** parameter if it exists. If the parameter does not exist, this routine | |
| 3115 | +** returns a NULL pointer. | |
| 3116 | +** | |
| 3117 | +** If the zFilename argument to this function is not a pointer that SQLite | |
| 3118 | +** passed into the xOpen VFS method, then the behavior of this routine | |
| 3119 | +** is undefined and probably undesirable. | |
| 3120 | +*/ | |
| 3121 | +SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam); | |
| 3122 | + | |
| 2971 | 3123 | |
| 2972 | 3124 | /* |
| 2973 | 3125 | ** CAPI3REF: Error Codes And Messages |
| 2974 | 3126 | ** |
| 2975 | 3127 | ** ^The sqlite3_errcode() interface returns the numeric [result code] or |
| @@ -3082,47 +3234,49 @@ | ||
| 3082 | 3234 | ** that can be lowered at run-time using [sqlite3_limit()]. |
| 3083 | 3235 | ** The synopsis of the meanings of the various limits is shown below. |
| 3084 | 3236 | ** Additional information is available at [limits | Limits in SQLite]. |
| 3085 | 3237 | ** |
| 3086 | 3238 | ** <dl> |
| 3087 | -** ^(<dt>SQLITE_LIMIT_LENGTH</dt> | |
| 3239 | +** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt> | |
| 3088 | 3240 | ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^ |
| 3089 | 3241 | ** |
| 3090 | -** ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt> | |
| 3242 | +** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt> | |
| 3091 | 3243 | ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^ |
| 3092 | 3244 | ** |
| 3093 | -** ^(<dt>SQLITE_LIMIT_COLUMN</dt> | |
| 3245 | +** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt> | |
| 3094 | 3246 | ** <dd>The maximum number of columns in a table definition or in the |
| 3095 | 3247 | ** result set of a [SELECT] or the maximum number of columns in an index |
| 3096 | 3248 | ** or in an ORDER BY or GROUP BY clause.</dd>)^ |
| 3097 | 3249 | ** |
| 3098 | -** ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> | |
| 3250 | +** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> | |
| 3099 | 3251 | ** <dd>The maximum depth of the parse tree on any expression.</dd>)^ |
| 3100 | 3252 | ** |
| 3101 | -** ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt> | |
| 3253 | +** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt> | |
| 3102 | 3254 | ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^ |
| 3103 | 3255 | ** |
| 3104 | -** ^(<dt>SQLITE_LIMIT_VDBE_OP</dt> | |
| 3256 | +** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt> | |
| 3105 | 3257 | ** <dd>The maximum number of instructions in a virtual machine program |
| 3106 | 3258 | ** used to implement an SQL statement. This limit is not currently |
| 3107 | 3259 | ** enforced, though that might be added in some future release of |
| 3108 | 3260 | ** SQLite.</dd>)^ |
| 3109 | 3261 | ** |
| 3110 | -** ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt> | |
| 3262 | +** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt> | |
| 3111 | 3263 | ** <dd>The maximum number of arguments on a function.</dd>)^ |
| 3112 | 3264 | ** |
| 3113 | -** ^(<dt>SQLITE_LIMIT_ATTACHED</dt> | |
| 3265 | +** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt> | |
| 3114 | 3266 | ** <dd>The maximum number of [ATTACH | attached databases].)^</dd> |
| 3115 | 3267 | ** |
| 3268 | +** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]] | |
| 3116 | 3269 | ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt> |
| 3117 | 3270 | ** <dd>The maximum length of the pattern argument to the [LIKE] or |
| 3118 | 3271 | ** [GLOB] operators.</dd>)^ |
| 3119 | 3272 | ** |
| 3273 | +** [[SQLITE_LIMIT_VARIABLE_NUMBER]] | |
| 3120 | 3274 | ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> |
| 3121 | 3275 | ** <dd>The maximum index number of any [parameter] in an SQL statement.)^ |
| 3122 | 3276 | ** |
| 3123 | -** ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> | |
| 3277 | +** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> | |
| 3124 | 3278 | ** <dd>The maximum depth of recursion for triggers.</dd>)^ |
| 3125 | 3279 | ** </dl> |
| 3126 | 3280 | */ |
| 3127 | 3281 | #define SQLITE_LIMIT_LENGTH 0 |
| 3128 | 3282 | #define SQLITE_LIMIT_SQL_LENGTH 1 |
| @@ -5153,10 +5307,15 @@ | ||
| 5153 | 5307 | int (*xRollback)(sqlite3_vtab *pVTab); |
| 5154 | 5308 | int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName, |
| 5155 | 5309 | void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), |
| 5156 | 5310 | void **ppArg); |
| 5157 | 5311 | int (*xRename)(sqlite3_vtab *pVtab, const char *zNew); |
| 5312 | + /* The methods above are in version 1 of the sqlite_module object. Those | |
| 5313 | + ** below are for version 2 and greater. */ | |
| 5314 | + int (*xSavepoint)(sqlite3_vtab *pVTab, int); | |
| 5315 | + int (*xRelease)(sqlite3_vtab *pVTab, int); | |
| 5316 | + int (*xRollbackTo)(sqlite3_vtab *pVTab, int); | |
| 5158 | 5317 | }; |
| 5159 | 5318 | |
| 5160 | 5319 | /* |
| 5161 | 5320 | ** CAPI3REF: Virtual Table Indexing Information |
| 5162 | 5321 | ** KEYWORDS: sqlite3_index_info |
| @@ -5967,11 +6126,11 @@ | ||
| 5967 | 6126 | ** |
| 5968 | 6127 | ** ^This interface is used to retrieve runtime status information |
| 5969 | 6128 | ** about the performance of SQLite, and optionally to reset various |
| 5970 | 6129 | ** highwater marks. ^The first argument is an integer code for |
| 5971 | 6130 | ** the specific parameter to measure. ^(Recognized integer codes |
| 5972 | -** are of the form [SQLITE_STATUS_MEMORY_USED | SQLITE_STATUS_...].)^ | |
| 6131 | +** are of the form [status parameters | SQLITE_STATUS_...].)^ | |
| 5973 | 6132 | ** ^The current value of the parameter is returned into *pCurrent. |
| 5974 | 6133 | ** ^The highest recorded value is returned in *pHighwater. ^If the |
| 5975 | 6134 | ** resetFlag is true, then the highest record value is reset after |
| 5976 | 6135 | ** *pHighwater is written. ^(Some parameters do not record the highest |
| 5977 | 6136 | ** value. For those parameters |
| @@ -5994,82 +6153,84 @@ | ||
| 5994 | 6153 | SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); |
| 5995 | 6154 | |
| 5996 | 6155 | |
| 5997 | 6156 | /* |
| 5998 | 6157 | ** CAPI3REF: Status Parameters |
| 6158 | +** KEYWORDS: {status parameters} | |
| 5999 | 6159 | ** |
| 6000 | 6160 | ** These integer constants designate various run-time status parameters |
| 6001 | 6161 | ** that can be returned by [sqlite3_status()]. |
| 6002 | 6162 | ** |
| 6003 | 6163 | ** <dl> |
| 6004 | -** ^(<dt>SQLITE_STATUS_MEMORY_USED</dt> | |
| 6164 | +** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt> | |
| 6005 | 6165 | ** <dd>This parameter is the current amount of memory checked out |
| 6006 | 6166 | ** using [sqlite3_malloc()], either directly or indirectly. The |
| 6007 | 6167 | ** figure includes calls made to [sqlite3_malloc()] by the application |
| 6008 | 6168 | ** and internal memory usage by the SQLite library. Scratch memory |
| 6009 | 6169 | ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache |
| 6010 | 6170 | ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in |
| 6011 | 6171 | ** this parameter. The amount returned is the sum of the allocation |
| 6012 | 6172 | ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^ |
| 6013 | 6173 | ** |
| 6014 | -** ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt> | |
| 6174 | +** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt> | |
| 6015 | 6175 | ** <dd>This parameter records the largest memory allocation request |
| 6016 | 6176 | ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their |
| 6017 | 6177 | ** internal equivalents). Only the value returned in the |
| 6018 | 6178 | ** *pHighwater parameter to [sqlite3_status()] is of interest. |
| 6019 | 6179 | ** The value written into the *pCurrent parameter is undefined.</dd>)^ |
| 6020 | 6180 | ** |
| 6021 | -** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt> | |
| 6181 | +** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt> | |
| 6022 | 6182 | ** <dd>This parameter records the number of separate memory allocations |
| 6023 | 6183 | ** currently checked out.</dd>)^ |
| 6024 | 6184 | ** |
| 6025 | -** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt> | |
| 6185 | +** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt> | |
| 6026 | 6186 | ** <dd>This parameter returns the number of pages used out of the |
| 6027 | 6187 | ** [pagecache memory allocator] that was configured using |
| 6028 | 6188 | ** [SQLITE_CONFIG_PAGECACHE]. The |
| 6029 | 6189 | ** value returned is in pages, not in bytes.</dd>)^ |
| 6030 | 6190 | ** |
| 6191 | +** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]] | |
| 6031 | 6192 | ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt> |
| 6032 | 6193 | ** <dd>This parameter returns the number of bytes of page cache |
| 6033 | 6194 | ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE] |
| 6034 | 6195 | ** buffer and where forced to overflow to [sqlite3_malloc()]. The |
| 6035 | 6196 | ** returned value includes allocations that overflowed because they |
| 6036 | 6197 | ** where too large (they were larger than the "sz" parameter to |
| 6037 | 6198 | ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because |
| 6038 | 6199 | ** no space was left in the page cache.</dd>)^ |
| 6039 | 6200 | ** |
| 6040 | -** ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt> | |
| 6201 | +** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt> | |
| 6041 | 6202 | ** <dd>This parameter records the largest memory allocation request |
| 6042 | 6203 | ** handed to [pagecache memory allocator]. Only the value returned in the |
| 6043 | 6204 | ** *pHighwater parameter to [sqlite3_status()] is of interest. |
| 6044 | 6205 | ** The value written into the *pCurrent parameter is undefined.</dd>)^ |
| 6045 | 6206 | ** |
| 6046 | -** ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt> | |
| 6207 | +** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt> | |
| 6047 | 6208 | ** <dd>This parameter returns the number of allocations used out of the |
| 6048 | 6209 | ** [scratch memory allocator] configured using |
| 6049 | 6210 | ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not |
| 6050 | 6211 | ** in bytes. Since a single thread may only have one scratch allocation |
| 6051 | 6212 | ** outstanding at time, this parameter also reports the number of threads |
| 6052 | 6213 | ** using scratch memory at the same time.</dd>)^ |
| 6053 | 6214 | ** |
| 6054 | -** ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt> | |
| 6215 | +** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt> | |
| 6055 | 6216 | ** <dd>This parameter returns the number of bytes of scratch memory |
| 6056 | 6217 | ** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH] |
| 6057 | 6218 | ** buffer and where forced to overflow to [sqlite3_malloc()]. The values |
| 6058 | 6219 | ** returned include overflows because the requested allocation was too |
| 6059 | 6220 | ** larger (that is, because the requested allocation was larger than the |
| 6060 | 6221 | ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer |
| 6061 | 6222 | ** slots were available. |
| 6062 | 6223 | ** </dd>)^ |
| 6063 | 6224 | ** |
| 6064 | -** ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt> | |
| 6225 | +** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt> | |
| 6065 | 6226 | ** <dd>This parameter records the largest memory allocation request |
| 6066 | 6227 | ** handed to [scratch memory allocator]. Only the value returned in the |
| 6067 | 6228 | ** *pHighwater parameter to [sqlite3_status()] is of interest. |
| 6068 | 6229 | ** The value written into the *pCurrent parameter is undefined.</dd>)^ |
| 6069 | 6230 | ** |
| 6070 | -** ^(<dt>SQLITE_STATUS_PARSER_STACK</dt> | |
| 6231 | +** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt> | |
| 6071 | 6232 | ** <dd>This parameter records the deepest parser stack. It is only |
| 6072 | 6233 | ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^ |
| 6073 | 6234 | ** </dl> |
| 6074 | 6235 | ** |
| 6075 | 6236 | ** New status parameters may be added from time to time. |
| @@ -6090,13 +6251,13 @@ | ||
| 6090 | 6251 | ** |
| 6091 | 6252 | ** ^This interface is used to retrieve runtime status information |
| 6092 | 6253 | ** about a single [database connection]. ^The first argument is the |
| 6093 | 6254 | ** database connection object to be interrogated. ^The second argument |
| 6094 | 6255 | ** is an integer constant, taken from the set of |
| 6095 | -** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros, that | |
| 6256 | +** [SQLITE_DBSTATUS options], that | |
| 6096 | 6257 | ** determines the parameter to interrogate. The set of |
| 6097 | -** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros is likely | |
| 6258 | +** [SQLITE_DBSTATUS options] is likely | |
| 6098 | 6259 | ** to grow in future releases of SQLite. |
| 6099 | 6260 | ** |
| 6100 | 6261 | ** ^The current value of the requested parameter is written into *pCur |
| 6101 | 6262 | ** and the highest instantaneous value is written into *pHiwtr. ^If |
| 6102 | 6263 | ** the resetFlg is true, then the highest instantaneous value is |
| @@ -6109,10 +6270,11 @@ | ||
| 6109 | 6270 | */ |
| 6110 | 6271 | SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); |
| 6111 | 6272 | |
| 6112 | 6273 | /* |
| 6113 | 6274 | ** CAPI3REF: Status Parameters for database connections |
| 6275 | +** KEYWORDS: {SQLITE_DBSTATUS options} | |
| 6114 | 6276 | ** |
| 6115 | 6277 | ** These constants are the available integer "verbs" that can be passed as |
| 6116 | 6278 | ** the second argument to the [sqlite3_db_status()] interface. |
| 6117 | 6279 | ** |
| 6118 | 6280 | ** New verbs may be added in future releases of SQLite. Existing verbs |
| @@ -6120,48 +6282,50 @@ | ||
| 6120 | 6282 | ** [sqlite3_db_status()] to make sure that the call worked. |
| 6121 | 6283 | ** The [sqlite3_db_status()] interface will return a non-zero error code |
| 6122 | 6284 | ** if a discontinued or unsupported verb is invoked. |
| 6123 | 6285 | ** |
| 6124 | 6286 | ** <dl> |
| 6125 | -** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt> | |
| 6287 | +** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt> | |
| 6126 | 6288 | ** <dd>This parameter returns the number of lookaside memory slots currently |
| 6127 | 6289 | ** checked out.</dd>)^ |
| 6128 | 6290 | ** |
| 6129 | -** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt> | |
| 6291 | +** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt> | |
| 6130 | 6292 | ** <dd>This parameter returns the number malloc attempts that were |
| 6131 | 6293 | ** satisfied using lookaside memory. Only the high-water value is meaningful; |
| 6132 | 6294 | ** the current value is always zero.)^ |
| 6133 | 6295 | ** |
| 6296 | +** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]] | |
| 6134 | 6297 | ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt> |
| 6135 | 6298 | ** <dd>This parameter returns the number malloc attempts that might have |
| 6136 | 6299 | ** been satisfied using lookaside memory but failed due to the amount of |
| 6137 | 6300 | ** memory requested being larger than the lookaside slot size. |
| 6138 | 6301 | ** Only the high-water value is meaningful; |
| 6139 | 6302 | ** the current value is always zero.)^ |
| 6140 | 6303 | ** |
| 6304 | +** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]] | |
| 6141 | 6305 | ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt> |
| 6142 | 6306 | ** <dd>This parameter returns the number malloc attempts that might have |
| 6143 | 6307 | ** been satisfied using lookaside memory but failed due to all lookaside |
| 6144 | 6308 | ** memory already being in use. |
| 6145 | 6309 | ** Only the high-water value is meaningful; |
| 6146 | 6310 | ** the current value is always zero.)^ |
| 6147 | 6311 | ** |
| 6148 | -** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt> | |
| 6312 | +** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt> | |
| 6149 | 6313 | ** <dd>This parameter returns the approximate number of of bytes of heap |
| 6150 | 6314 | ** memory used by all pager caches associated with the database connection.)^ |
| 6151 | 6315 | ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0. |
| 6152 | 6316 | ** |
| 6153 | -** ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt> | |
| 6317 | +** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt> | |
| 6154 | 6318 | ** <dd>This parameter returns the approximate number of of bytes of heap |
| 6155 | 6319 | ** memory used to store the schema for all databases associated |
| 6156 | 6320 | ** with the connection - main, temp, and any [ATTACH]-ed databases.)^ |
| 6157 | 6321 | ** ^The full amount of memory used by the schemas is reported, even if the |
| 6158 | 6322 | ** schema memory is shared with other database connections due to |
| 6159 | 6323 | ** [shared cache mode] being enabled. |
| 6160 | 6324 | ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0. |
| 6161 | 6325 | ** |
| 6162 | -** ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt> | |
| 6326 | +** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt> | |
| 6163 | 6327 | ** <dd>This parameter returns the approximate number of of bytes of heap |
| 6164 | 6328 | ** and lookaside memory used by all prepared statements associated with |
| 6165 | 6329 | ** the database connection.)^ |
| 6166 | 6330 | ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0. |
| 6167 | 6331 | ** </dd> |
| @@ -6179,11 +6343,11 @@ | ||
| 6179 | 6343 | |
| 6180 | 6344 | /* |
| 6181 | 6345 | ** CAPI3REF: Prepared Statement Status |
| 6182 | 6346 | ** |
| 6183 | 6347 | ** ^(Each prepared statement maintains various |
| 6184 | -** [SQLITE_STMTSTATUS_SORT | counters] that measure the number | |
| 6348 | +** [SQLITE_STMTSTATUS counters] that measure the number | |
| 6185 | 6349 | ** of times it has performed specific operations.)^ These counters can |
| 6186 | 6350 | ** be used to monitor the performance characteristics of the prepared |
| 6187 | 6351 | ** statements. For example, if the number of table steps greatly exceeds |
| 6188 | 6352 | ** the number of table searches or result rows, that would tend to indicate |
| 6189 | 6353 | ** that the prepared statement is using a full table scan rather than |
| @@ -6190,11 +6354,11 @@ | ||
| 6190 | 6354 | ** an index. |
| 6191 | 6355 | ** |
| 6192 | 6356 | ** ^(This interface is used to retrieve and reset counter values from |
| 6193 | 6357 | ** a [prepared statement]. The first argument is the prepared statement |
| 6194 | 6358 | ** object to be interrogated. The second argument |
| 6195 | -** is an integer code for a specific [SQLITE_STMTSTATUS_SORT | counter] | |
| 6359 | +** is an integer code for a specific [SQLITE_STMTSTATUS counter] | |
| 6196 | 6360 | ** to be interrogated.)^ |
| 6197 | 6361 | ** ^The current value of the requested counter is returned. |
| 6198 | 6362 | ** ^If the resetFlg is true, then the counter is reset to zero after this |
| 6199 | 6363 | ** interface call returns. |
| 6200 | 6364 | ** |
| @@ -6202,28 +6366,29 @@ | ||
| 6202 | 6366 | */ |
| 6203 | 6367 | SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); |
| 6204 | 6368 | |
| 6205 | 6369 | /* |
| 6206 | 6370 | ** CAPI3REF: Status Parameters for prepared statements |
| 6371 | +** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters} | |
| 6207 | 6372 | ** |
| 6208 | 6373 | ** These preprocessor macros define integer codes that name counter |
| 6209 | 6374 | ** values associated with the [sqlite3_stmt_status()] interface. |
| 6210 | 6375 | ** The meanings of the various counters are as follows: |
| 6211 | 6376 | ** |
| 6212 | 6377 | ** <dl> |
| 6213 | -** <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt> | |
| 6378 | +** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt> | |
| 6214 | 6379 | ** <dd>^This is the number of times that SQLite has stepped forward in |
| 6215 | 6380 | ** a table as part of a full table scan. Large numbers for this counter |
| 6216 | 6381 | ** may indicate opportunities for performance improvement through |
| 6217 | 6382 | ** careful use of indices.</dd> |
| 6218 | 6383 | ** |
| 6219 | -** <dt>SQLITE_STMTSTATUS_SORT</dt> | |
| 6384 | +** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt> | |
| 6220 | 6385 | ** <dd>^This is the number of sort operations that have occurred. |
| 6221 | 6386 | ** A non-zero value in this counter may indicate an opportunity to |
| 6222 | 6387 | ** improvement performance through careful use of indices.</dd> |
| 6223 | 6388 | ** |
| 6224 | -** <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt> | |
| 6389 | +** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt> | |
| 6225 | 6390 | ** <dd>^This is the number of rows inserted into transient indices that |
| 6226 | 6391 | ** were created automatically in order to help joins run faster. |
| 6227 | 6392 | ** A non-zero value in this counter may indicate an opportunity to |
| 6228 | 6393 | ** improvement performance by adding permanent indices that do not |
| 6229 | 6394 | ** need to be reinitialized each time the statement is run.</dd> |
| @@ -6270,10 +6435,11 @@ | ||
| 6270 | 6435 | ** ^(The contents of the sqlite3_pcache_methods structure are copied to an |
| 6271 | 6436 | ** internal buffer by SQLite within the call to [sqlite3_config]. Hence |
| 6272 | 6437 | ** the application may discard the parameter after the call to |
| 6273 | 6438 | ** [sqlite3_config()] returns.)^ |
| 6274 | 6439 | ** |
| 6440 | +** [[the xInit() page cache method]] | |
| 6275 | 6441 | ** ^(The xInit() method is called once for each effective |
| 6276 | 6442 | ** call to [sqlite3_initialize()])^ |
| 6277 | 6443 | ** (usually only once during the lifetime of the process). ^(The xInit() |
| 6278 | 6444 | ** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^ |
| 6279 | 6445 | ** The intent of the xInit() method is to set up global data structures |
| @@ -6280,10 +6446,11 @@ | ||
| 6280 | 6446 | ** required by the custom page cache implementation. |
| 6281 | 6447 | ** ^(If the xInit() method is NULL, then the |
| 6282 | 6448 | ** built-in default page cache is used instead of the application defined |
| 6283 | 6449 | ** page cache.)^ |
| 6284 | 6450 | ** |
| 6451 | +** [[the xShutdown() page cache method]] | |
| 6285 | 6452 | ** ^The xShutdown() method is called by [sqlite3_shutdown()]. |
| 6286 | 6453 | ** It can be used to clean up |
| 6287 | 6454 | ** any outstanding resources before process shutdown, if required. |
| 6288 | 6455 | ** ^The xShutdown() method may be NULL. |
| 6289 | 6456 | ** |
| @@ -6294,10 +6461,11 @@ | ||
| 6294 | 6461 | ** in multithreaded applications. |
| 6295 | 6462 | ** |
| 6296 | 6463 | ** ^SQLite will never invoke xInit() more than once without an intervening |
| 6297 | 6464 | ** call to xShutdown(). |
| 6298 | 6465 | ** |
| 6466 | +** [[the xCreate() page cache methods]] | |
| 6299 | 6467 | ** ^SQLite invokes the xCreate() method to construct a new cache instance. |
| 6300 | 6468 | ** SQLite will typically create one cache instance for each open database file, |
| 6301 | 6469 | ** though this is not guaranteed. ^The |
| 6302 | 6470 | ** first parameter, szPage, is the size in bytes of the pages that must |
| 6303 | 6471 | ** be allocated by the cache. ^szPage will not be a power of two. ^szPage |
| @@ -6318,20 +6486,23 @@ | ||
| 6318 | 6486 | ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to |
| 6319 | 6487 | ** false will always have the "discard" flag set to true. |
| 6320 | 6488 | ** ^Hence, a cache created with bPurgeable false will |
| 6321 | 6489 | ** never contain any unpinned pages. |
| 6322 | 6490 | ** |
| 6491 | +** [[the xCachesize() page cache method]] | |
| 6323 | 6492 | ** ^(The xCachesize() method may be called at any time by SQLite to set the |
| 6324 | 6493 | ** suggested maximum cache-size (number of pages stored by) the cache |
| 6325 | 6494 | ** instance passed as the first argument. This is the value configured using |
| 6326 | 6495 | ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable |
| 6327 | 6496 | ** parameter, the implementation is not required to do anything with this |
| 6328 | 6497 | ** value; it is advisory only. |
| 6329 | 6498 | ** |
| 6499 | +** [[the xPagecount() page cache methods]] | |
| 6330 | 6500 | ** The xPagecount() method must return the number of pages currently |
| 6331 | 6501 | ** stored in the cache, both pinned and unpinned. |
| 6332 | 6502 | ** |
| 6503 | +** [[the xFetch() page cache methods]] | |
| 6333 | 6504 | ** The xFetch() method locates a page in the cache and returns a pointer to |
| 6334 | 6505 | ** the page, or a NULL pointer. |
| 6335 | 6506 | ** A "page", in this context, means a buffer of szPage bytes aligned at an |
| 6336 | 6507 | ** 8-byte boundary. The page to be fetched is determined by the key. ^The |
| 6337 | 6508 | ** mimimum key value is 1. After it has been retrieved using xFetch, the page |
| @@ -6356,10 +6527,11 @@ | ||
| 6356 | 6527 | ** will only use a createFlag of 2 after a prior call with a createFlag of 1 |
| 6357 | 6528 | ** failed.)^ In between the to xFetch() calls, SQLite may |
| 6358 | 6529 | ** attempt to unpin one or more cache pages by spilling the content of |
| 6359 | 6530 | ** pinned pages to disk and synching the operating system disk cache. |
| 6360 | 6531 | ** |
| 6532 | +** [[the xUnpin() page cache method]] | |
| 6361 | 6533 | ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page |
| 6362 | 6534 | ** as its second argument. If the third parameter, discard, is non-zero, |
| 6363 | 6535 | ** then the page must be evicted from the cache. |
| 6364 | 6536 | ** ^If the discard parameter is |
| 6365 | 6537 | ** zero, then the page may be discarded or retained at the discretion of |
| @@ -6368,10 +6540,11 @@ | ||
| 6368 | 6540 | ** |
| 6369 | 6541 | ** The cache must not perform any reference counting. A single |
| 6370 | 6542 | ** call to xUnpin() unpins the page regardless of the number of prior calls |
| 6371 | 6543 | ** to xFetch(). |
| 6372 | 6544 | ** |
| 6545 | +** [[the xRekey() page cache methods]] | |
| 6373 | 6546 | ** The xRekey() method is used to change the key value associated with the |
| 6374 | 6547 | ** page passed as the second argument. If the cache |
| 6375 | 6548 | ** previously contains an entry associated with newKey, it must be |
| 6376 | 6549 | ** discarded. ^Any prior cache entry associated with newKey is guaranteed not |
| 6377 | 6550 | ** to be pinned. |
| @@ -6380,10 +6553,11 @@ | ||
| 6380 | 6553 | ** existing cache entries with page numbers (keys) greater than or equal |
| 6381 | 6554 | ** to the value of the iLimit parameter passed to xTruncate(). If any |
| 6382 | 6555 | ** of these pages are pinned, they are implicitly unpinned, meaning that |
| 6383 | 6556 | ** they can be safely discarded. |
| 6384 | 6557 | ** |
| 6558 | +** [[the xDestroy() page cache method]] | |
| 6385 | 6559 | ** ^The xDestroy() method is used to delete a cache allocated by xCreate(). |
| 6386 | 6560 | ** All resources associated with the specified cache should be freed. ^After |
| 6387 | 6561 | ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*] |
| 6388 | 6562 | ** handle invalid, and will not use it with any other sqlite3_pcache_methods |
| 6389 | 6563 | ** functions. |
| @@ -6442,11 +6616,11 @@ | ||
| 6442 | 6616 | ** associated with the backup operation. |
| 6443 | 6617 | ** </ol>)^ |
| 6444 | 6618 | ** There should be exactly one call to sqlite3_backup_finish() for each |
| 6445 | 6619 | ** successful call to sqlite3_backup_init(). |
| 6446 | 6620 | ** |
| 6447 | -** <b>sqlite3_backup_init()</b> | |
| 6621 | +** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b> | |
| 6448 | 6622 | ** |
| 6449 | 6623 | ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the |
| 6450 | 6624 | ** [database connection] associated with the destination database |
| 6451 | 6625 | ** and the database name, respectively. |
| 6452 | 6626 | ** ^The database name is "main" for the main database, "temp" for the |
| @@ -6469,11 +6643,11 @@ | ||
| 6469 | 6643 | ** [sqlite3_backup] object. |
| 6470 | 6644 | ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and |
| 6471 | 6645 | ** sqlite3_backup_finish() functions to perform the specified backup |
| 6472 | 6646 | ** operation. |
| 6473 | 6647 | ** |
| 6474 | -** <b>sqlite3_backup_step()</b> | |
| 6648 | +** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b> | |
| 6475 | 6649 | ** |
| 6476 | 6650 | ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between |
| 6477 | 6651 | ** the source and destination databases specified by [sqlite3_backup] object B. |
| 6478 | 6652 | ** ^If N is negative, all remaining source pages are copied. |
| 6479 | 6653 | ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there |
| @@ -6526,11 +6700,11 @@ | ||
| 6526 | 6700 | ** restarted by the next call to sqlite3_backup_step(). ^If the source |
| 6527 | 6701 | ** database is modified by the using the same database connection as is used |
| 6528 | 6702 | ** by the backup operation, then the backup database is automatically |
| 6529 | 6703 | ** updated at the same time. |
| 6530 | 6704 | ** |
| 6531 | -** <b>sqlite3_backup_finish()</b> | |
| 6705 | +** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b> | |
| 6532 | 6706 | ** |
| 6533 | 6707 | ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the |
| 6534 | 6708 | ** application wishes to abandon the backup operation, the application |
| 6535 | 6709 | ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish(). |
| 6536 | 6710 | ** ^The sqlite3_backup_finish() interfaces releases all |
| @@ -6549,11 +6723,12 @@ | ||
| 6549 | 6723 | ** |
| 6550 | 6724 | ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step() |
| 6551 | 6725 | ** is not a permanent error and does not affect the return value of |
| 6552 | 6726 | ** sqlite3_backup_finish(). |
| 6553 | 6727 | ** |
| 6554 | -** <b>sqlite3_backup_remaining(), sqlite3_backup_pagecount()</b> | |
| 6728 | +** [[sqlite3_backup__remaining()]] [[sqlite3_backup_pagecount()]] | |
| 6729 | +** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b> | |
| 6555 | 6730 | ** |
| 6556 | 6731 | ** ^Each call to sqlite3_backup_step() sets two values inside |
| 6557 | 6732 | ** the [sqlite3_backup] object: the number of pages still to be backed |
| 6558 | 6733 | ** up and the total number of pages in the source database file. |
| 6559 | 6734 | ** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces |
| @@ -6934,10 +7109,97 @@ | ||
| 6934 | 7109 | ** each of these values. |
| 6935 | 7110 | */ |
| 6936 | 7111 | #define SQLITE_CHECKPOINT_PASSIVE 0 |
| 6937 | 7112 | #define SQLITE_CHECKPOINT_FULL 1 |
| 6938 | 7113 | #define SQLITE_CHECKPOINT_RESTART 2 |
| 7114 | + | |
| 7115 | +/* | |
| 7116 | +** CAPI3REF: Virtual Table Interface Configuration | |
| 7117 | +** | |
| 7118 | +** This function may be called by either the [xConnect] or [xCreate] method | |
| 7119 | +** of a [virtual table] implementation to configure | |
| 7120 | +** various facets of the virtual table interface. | |
| 7121 | +** | |
| 7122 | +** If this interface is invoked outside the context of an xConnect or | |
| 7123 | +** xCreate virtual table method then the behavior is undefined. | |
| 7124 | +** | |
| 7125 | +** At present, there is only one option that may be configured using | |
| 7126 | +** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].) Further options | |
| 7127 | +** may be added in the future. | |
| 7128 | +*/ | |
| 7129 | +SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...); | |
| 7130 | + | |
| 7131 | +/* | |
| 7132 | +** CAPI3REF: Virtual Table Configuration Options | |
| 7133 | +** | |
| 7134 | +** These macros define the various options to the | |
| 7135 | +** [sqlite3_vtab_config()] interface that [virtual table] implementations | |
| 7136 | +** can use to customize and optimize their behavior. | |
| 7137 | +** | |
| 7138 | +** <dl> | |
| 7139 | +** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT | |
| 7140 | +** <dd>Calls of the form | |
| 7141 | +** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported, | |
| 7142 | +** where X is an integer. If X is zero, then the [virtual table] whose | |
| 7143 | +** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not | |
| 7144 | +** support constraints. In this configuration (which is the default) if | |
| 7145 | +** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire | |
| 7146 | +** statement is rolled back as if [ON CONFLICT | OR ABORT] had been | |
| 7147 | +** specified as part of the users SQL statement, regardless of the actual | |
| 7148 | +** ON CONFLICT mode specified. | |
| 7149 | +** | |
| 7150 | +** If X is non-zero, then the virtual table implementation guarantees | |
| 7151 | +** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before | |
| 7152 | +** any modifications to internal or persistent data structures have been made. | |
| 7153 | +** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite | |
| 7154 | +** is able to roll back a statement or database transaction, and abandon | |
| 7155 | +** or continue processing the current SQL statement as appropriate. | |
| 7156 | +** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns | |
| 7157 | +** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode | |
| 7158 | +** had been ABORT. | |
| 7159 | +** | |
| 7160 | +** Virtual table implementations that are required to handle OR REPLACE | |
| 7161 | +** must do so within the [xUpdate] method. If a call to the | |
| 7162 | +** [sqlite3_vtab_on_conflict()] function indicates that the current ON | |
| 7163 | +** CONFLICT policy is REPLACE, the virtual table implementation should | |
| 7164 | +** silently replace the appropriate rows within the xUpdate callback and | |
| 7165 | +** return SQLITE_OK. Or, if this is not possible, it may return | |
| 7166 | +** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT | |
| 7167 | +** constraint handling. | |
| 7168 | +** </dl> | |
| 7169 | +*/ | |
| 7170 | +#define SQLITE_VTAB_CONSTRAINT_SUPPORT 1 | |
| 7171 | + | |
| 7172 | +/* | |
| 7173 | +** CAPI3REF: Determine The Virtual Table Conflict Policy | |
| 7174 | +** | |
| 7175 | +** This function may only be called from within a call to the [xUpdate] method | |
| 7176 | +** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The | |
| 7177 | +** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL], | |
| 7178 | +** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode | |
| 7179 | +** of the SQL statement that triggered the call to the [xUpdate] method of the | |
| 7180 | +** [virtual table]. | |
| 7181 | +*/ | |
| 7182 | +SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *); | |
| 7183 | + | |
| 7184 | +/* | |
| 7185 | +** CAPI3REF: Conflict resolution modes | |
| 7186 | +** | |
| 7187 | +** These constants are returned by [sqlite3_vtab_on_conflict()] to | |
| 7188 | +** inform a [virtual table] implementation what the [ON CONFLICT] mode | |
| 7189 | +** is for the SQL statement being evaluated. | |
| 7190 | +** | |
| 7191 | +** Note that the [SQLITE_IGNORE] constant is also used as a potential | |
| 7192 | +** return value from the [sqlite3_set_authorizer()] callback and that | |
| 7193 | +** [SQLITE_ABORT] is also a [result code]. | |
| 7194 | +*/ | |
| 7195 | +#define SQLITE_ROLLBACK 1 | |
| 7196 | +/* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */ | |
| 7197 | +#define SQLITE_FAIL 3 | |
| 7198 | +/* #define SQLITE_ABORT 4 // Also an error code */ | |
| 7199 | +#define SQLITE_REPLACE 5 | |
| 7200 | + | |
| 6939 | 7201 | |
| 6940 | 7202 | |
| 6941 | 7203 | /* |
| 6942 | 7204 | ** Undo the hack that converts floating point types to integer for |
| 6943 | 7205 | ** builds on processors without floating point support. |
| @@ -7601,10 +7863,11 @@ | ||
| 7601 | 7863 | typedef struct Trigger Trigger; |
| 7602 | 7864 | typedef struct TriggerPrg TriggerPrg; |
| 7603 | 7865 | typedef struct TriggerStep TriggerStep; |
| 7604 | 7866 | typedef struct UnpackedRecord UnpackedRecord; |
| 7605 | 7867 | typedef struct VTable VTable; |
| 7868 | +typedef struct VtabCtx VtabCtx; | |
| 7606 | 7869 | typedef struct Walker Walker; |
| 7607 | 7870 | typedef struct WherePlan WherePlan; |
| 7608 | 7871 | typedef struct WhereInfo WhereInfo; |
| 7609 | 7872 | typedef struct WhereLevel WhereLevel; |
| 7610 | 7873 | |
| @@ -7657,10 +7920,11 @@ | ||
| 7657 | 7920 | typedef struct BtCursor BtCursor; |
| 7658 | 7921 | typedef struct BtShared BtShared; |
| 7659 | 7922 | |
| 7660 | 7923 | |
| 7661 | 7924 | SQLITE_PRIVATE int sqlite3BtreeOpen( |
| 7925 | + sqlite3_vfs *pVfs, /* VFS to use with this b-tree */ | |
| 7662 | 7926 | const char *zFilename, /* Name of database file to open */ |
| 7663 | 7927 | sqlite3 *db, /* Associated database connection */ |
| 7664 | 7928 | Btree **ppBtree, /* Return open Btree* here */ |
| 7665 | 7929 | int flags, /* Flags */ |
| 7666 | 7930 | int vfsFlags /* Flags passed through to VFS open */ |
| @@ -9136,19 +9400,20 @@ | ||
| 9136 | 9400 | struct sqlite3 { |
| 9137 | 9401 | sqlite3_vfs *pVfs; /* OS Interface */ |
| 9138 | 9402 | int nDb; /* Number of backends currently in use */ |
| 9139 | 9403 | Db *aDb; /* All backends */ |
| 9140 | 9404 | int flags; /* Miscellaneous flags. See below */ |
| 9141 | - int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */ | |
| 9405 | + unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */ | |
| 9142 | 9406 | int errCode; /* Most recent error code (SQLITE_*) */ |
| 9143 | 9407 | int errMask; /* & result codes with this before returning */ |
| 9144 | 9408 | u8 autoCommit; /* The auto-commit flag. */ |
| 9145 | 9409 | u8 temp_store; /* 1: file 2: memory 0: default */ |
| 9146 | 9410 | u8 mallocFailed; /* True if we have seen a malloc failure */ |
| 9147 | 9411 | u8 dfltLockMode; /* Default locking-mode for attached dbs */ |
| 9148 | 9412 | signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */ |
| 9149 | 9413 | u8 suppressErr; /* Do not issue error messages if true */ |
| 9414 | + u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */ | |
| 9150 | 9415 | int nextPagesize; /* Pagesize after VACUUM if >0 */ |
| 9151 | 9416 | int nTable; /* Number of tables in the database */ |
| 9152 | 9417 | CollSeq *pDfltColl; /* The default collating sequence (BINARY) */ |
| 9153 | 9418 | i64 lastRowid; /* ROWID of most recent insert (see above) */ |
| 9154 | 9419 | u32 magic; /* Magic number for detect library misuse */ |
| @@ -9203,11 +9468,11 @@ | ||
| 9203 | 9468 | void *pProgressArg; /* Argument to the progress callback */ |
| 9204 | 9469 | int nProgressOps; /* Number of opcodes for progress callback */ |
| 9205 | 9470 | #endif |
| 9206 | 9471 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 9207 | 9472 | Hash aModule; /* populated by sqlite3_create_module() */ |
| 9208 | - Table *pVTab; /* vtab with active Connect/Create method */ | |
| 9473 | + VtabCtx *pVtabCtx; /* Context for active vtab connect/create */ | |
| 9209 | 9474 | VTable **aVTrans; /* Virtual tables with open transactions */ |
| 9210 | 9475 | int nVTrans; /* Allocated size of aVTrans */ |
| 9211 | 9476 | VTable *pDisconnect; /* Disconnect these in next sqlite3_prepare() */ |
| 9212 | 9477 | #endif |
| 9213 | 9478 | FuncDefHash aFunc; /* Hash table of connection functions */ |
| @@ -9566,10 +9831,11 @@ | ||
| 9566 | 9831 | struct VTable { |
| 9567 | 9832 | sqlite3 *db; /* Database connection associated with this table */ |
| 9568 | 9833 | Module *pMod; /* Pointer to module implementation */ |
| 9569 | 9834 | sqlite3_vtab *pVtab; /* Pointer to vtab instance */ |
| 9570 | 9835 | int nRef; /* Number of pointers to this structure */ |
| 9836 | + u8 bConstraint; /* True if constraints are supported */ | |
| 9571 | 9837 | VTable *pNext; /* Next in linked list (see above) */ |
| 9572 | 9838 | }; |
| 9573 | 9839 | |
| 9574 | 9840 | /* |
| 9575 | 9841 | ** Each SQL table is represented in memory by an instance of the |
| @@ -10754,10 +11020,11 @@ | ||
| 10754 | 11020 | */ |
| 10755 | 11021 | struct Sqlite3Config { |
| 10756 | 11022 | int bMemstat; /* True to enable memory status */ |
| 10757 | 11023 | int bCoreMutex; /* True to enable core mutexing */ |
| 10758 | 11024 | int bFullMutex; /* True to enable full mutexing */ |
| 11025 | + int bOpenUri; /* True to interpret filenames as URIs */ | |
| 10759 | 11026 | int mxStrlen; /* Maximum string length */ |
| 10760 | 11027 | int szLookaside; /* Default lookaside buffer size */ |
| 10761 | 11028 | int nLookaside; /* Default lookaside buffer count */ |
| 10762 | 11029 | sqlite3_mem_methods m; /* Low-level memory allocation interface */ |
| 10763 | 11030 | sqlite3_mutex_methods mutex; /* Low-level mutex interface */ |
| @@ -11003,10 +11270,12 @@ | ||
| 11003 | 11270 | SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*); |
| 11004 | 11271 | SQLITE_PRIVATE void sqlite3AddColumnType(Parse*,Token*); |
| 11005 | 11272 | SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,ExprSpan*); |
| 11006 | 11273 | SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*); |
| 11007 | 11274 | SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,Select*); |
| 11275 | +SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*, | |
| 11276 | + sqlite3_vfs**,char**,char **); | |
| 11008 | 11277 | |
| 11009 | 11278 | SQLITE_PRIVATE Bitvec *sqlite3BitvecCreate(u32); |
| 11010 | 11279 | SQLITE_PRIVATE int sqlite3BitvecTest(Bitvec*, u32); |
| 11011 | 11280 | SQLITE_PRIVATE int sqlite3BitvecSet(Bitvec*, u32); |
| 11012 | 11281 | SQLITE_PRIVATE void sqlite3BitvecClear(Bitvec*, u32, void*); |
| @@ -11253,10 +11522,11 @@ | ||
| 11253 | 11522 | SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity); |
| 11254 | 11523 | SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr); |
| 11255 | 11524 | SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8); |
| 11256 | 11525 | SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...); |
| 11257 | 11526 | SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n); |
| 11527 | +SQLITE_PRIVATE u8 sqlite3HexToInt(int h); | |
| 11258 | 11528 | SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); |
| 11259 | 11529 | SQLITE_PRIVATE const char *sqlite3ErrStr(int); |
| 11260 | 11530 | SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse); |
| 11261 | 11531 | SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int); |
| 11262 | 11532 | SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName); |
| @@ -11268,10 +11538,16 @@ | ||
| 11268 | 11538 | SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int); |
| 11269 | 11539 | SQLITE_PRIVATE int sqlite3AddInt64(i64*,i64); |
| 11270 | 11540 | SQLITE_PRIVATE int sqlite3SubInt64(i64*,i64); |
| 11271 | 11541 | SQLITE_PRIVATE int sqlite3MulInt64(i64*,i64); |
| 11272 | 11542 | SQLITE_PRIVATE int sqlite3AbsInt32(int); |
| 11543 | +#ifdef SQLITE_ENABLE_8_3_NAMES | |
| 11544 | +SQLITE_PRIVATE void sqlite3FileSuffix3(const char*, char*); | |
| 11545 | +#else | |
| 11546 | +# define sqlite3FileSuffix3(X,Y) | |
| 11547 | +#endif | |
| 11548 | +SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z); | |
| 11273 | 11549 | |
| 11274 | 11550 | SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8); |
| 11275 | 11551 | SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8); |
| 11276 | 11552 | SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, |
| 11277 | 11553 | void(*)(void*)); |
| @@ -11377,18 +11653,20 @@ | ||
| 11377 | 11653 | # define sqlite3VtabCommit(X) |
| 11378 | 11654 | # define sqlite3VtabInSync(db) 0 |
| 11379 | 11655 | # define sqlite3VtabLock(X) |
| 11380 | 11656 | # define sqlite3VtabUnlock(X) |
| 11381 | 11657 | # define sqlite3VtabUnlockList(X) |
| 11658 | +# define sqlite3VtabSavepoint(X, Y, Z) SQLITE_OK | |
| 11382 | 11659 | #else |
| 11383 | 11660 | SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*); |
| 11384 | 11661 | SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **); |
| 11385 | 11662 | SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db); |
| 11386 | 11663 | SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db); |
| 11387 | 11664 | SQLITE_PRIVATE void sqlite3VtabLock(VTable *); |
| 11388 | 11665 | SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *); |
| 11389 | 11666 | SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3*); |
| 11667 | +SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *, int, int); | |
| 11390 | 11668 | # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0) |
| 11391 | 11669 | #endif |
| 11392 | 11670 | SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*); |
| 11393 | 11671 | SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*); |
| 11394 | 11672 | SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse*, Token*); |
| @@ -11691,20 +11969,23 @@ | ||
| 11691 | 11969 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* f0..f7 ........ */ |
| 11692 | 11970 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 /* f8..ff ........ */ |
| 11693 | 11971 | }; |
| 11694 | 11972 | #endif |
| 11695 | 11973 | |
| 11696 | - | |
| 11974 | +#ifndef SQLITE_USE_URI | |
| 11975 | +# define SQLITE_USE_URI 0 | |
| 11976 | +#endif | |
| 11697 | 11977 | |
| 11698 | 11978 | /* |
| 11699 | 11979 | ** The following singleton contains the global configuration for |
| 11700 | 11980 | ** the SQLite library. |
| 11701 | 11981 | */ |
| 11702 | 11982 | SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = { |
| 11703 | 11983 | SQLITE_DEFAULT_MEMSTATUS, /* bMemstat */ |
| 11704 | 11984 | 1, /* bCoreMutex */ |
| 11705 | 11985 | SQLITE_THREADSAFE==1, /* bFullMutex */ |
| 11986 | + SQLITE_USE_URI, /* bOpenUri */ | |
| 11706 | 11987 | 0x7ffffffe, /* mxStrlen */ |
| 11707 | 11988 | 100, /* szLookaside */ |
| 11708 | 11989 | 500, /* nLookaside */ |
| 11709 | 11990 | {0,0,0,0,0,0,0,0}, /* m */ |
| 11710 | 11991 | {0,0,0,0,0,0,0,0,0}, /* mutex */ |
| @@ -18217,11 +18498,11 @@ | ||
| 18217 | 18498 | sqlite3_mutex_enter(mem0.mutex); |
| 18218 | 18499 | sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes); |
| 18219 | 18500 | nDiff = nNew - nOld; |
| 18220 | 18501 | if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >= |
| 18221 | 18502 | mem0.alarmThreshold-nDiff ){ |
| 18222 | - sqlite3MallocAlarm(nNew-nOld); | |
| 18503 | + sqlite3MallocAlarm(nDiff); | |
| 18223 | 18504 | } |
| 18224 | 18505 | assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) ); |
| 18225 | 18506 | assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) ); |
| 18226 | 18507 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 18227 | 18508 | if( pNew==0 && mem0.alarmCallback ){ |
| @@ -18228,11 +18509,11 @@ | ||
| 18228 | 18509 | sqlite3MallocAlarm(nBytes); |
| 18229 | 18510 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 18230 | 18511 | } |
| 18231 | 18512 | if( pNew ){ |
| 18232 | 18513 | nNew = sqlite3MallocSize(pNew); |
| 18233 | - sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nDiff); | |
| 18514 | + sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nNew-nOld); | |
| 18234 | 18515 | } |
| 18235 | 18516 | sqlite3_mutex_leave(mem0.mutex); |
| 18236 | 18517 | }else{ |
| 18237 | 18518 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 18238 | 18519 | } |
| @@ -21183,27 +21464,25 @@ | ||
| 21183 | 21464 | p[3] = (u8)v; |
| 21184 | 21465 | } |
| 21185 | 21466 | |
| 21186 | 21467 | |
| 21187 | 21468 | |
| 21188 | -#if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC) | |
| 21189 | 21469 | /* |
| 21190 | 21470 | ** Translate a single byte of Hex into an integer. |
| 21191 | 21471 | ** This routine only works if h really is a valid hexadecimal |
| 21192 | 21472 | ** character: 0..9a..fA..F |
| 21193 | 21473 | */ |
| 21194 | -static u8 hexToInt(int h){ | |
| 21474 | +SQLITE_PRIVATE u8 sqlite3HexToInt(int h){ | |
| 21195 | 21475 | assert( (h>='0' && h<='9') || (h>='a' && h<='f') || (h>='A' && h<='F') ); |
| 21196 | 21476 | #ifdef SQLITE_ASCII |
| 21197 | 21477 | h += 9*(1&(h>>6)); |
| 21198 | 21478 | #endif |
| 21199 | 21479 | #ifdef SQLITE_EBCDIC |
| 21200 | 21480 | h += 9*(1&~(h>>4)); |
| 21201 | 21481 | #endif |
| 21202 | 21482 | return (u8)(h & 0xf); |
| 21203 | 21483 | } |
| 21204 | -#endif /* !SQLITE_OMIT_BLOB_LITERAL || SQLITE_HAS_CODEC */ | |
| 21205 | 21484 | |
| 21206 | 21485 | #if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC) |
| 21207 | 21486 | /* |
| 21208 | 21487 | ** Convert a BLOB literal of the form "x'hhhhhh'" into its binary |
| 21209 | 21488 | ** value. Return a pointer to its binary value. Space to hold the |
| @@ -21216,11 +21495,11 @@ | ||
| 21216 | 21495 | |
| 21217 | 21496 | zBlob = (char *)sqlite3DbMallocRaw(db, n/2 + 1); |
| 21218 | 21497 | n--; |
| 21219 | 21498 | if( zBlob ){ |
| 21220 | 21499 | for(i=0; i<n; i+=2){ |
| 21221 | - zBlob[i/2] = (hexToInt(z[i])<<4) | hexToInt(z[i+1]); | |
| 21500 | + zBlob[i/2] = (sqlite3HexToInt(z[i])<<4) | sqlite3HexToInt(z[i+1]); | |
| 21222 | 21501 | } |
| 21223 | 21502 | zBlob[i/2] = 0; |
| 21224 | 21503 | } |
| 21225 | 21504 | return zBlob; |
| 21226 | 21505 | } |
| @@ -21348,10 +21627,36 @@ | ||
| 21348 | 21627 | SQLITE_PRIVATE int sqlite3AbsInt32(int x){ |
| 21349 | 21628 | if( x>=0 ) return x; |
| 21350 | 21629 | if( x==(int)0x80000000 ) return 0x7fffffff; |
| 21351 | 21630 | return -x; |
| 21352 | 21631 | } |
| 21632 | + | |
| 21633 | +#ifdef SQLITE_ENABLE_8_3_NAMES | |
| 21634 | +/* | |
| 21635 | +** If SQLITE_ENABLE_8_3_NAME is set at compile-time and if the database | |
| 21636 | +** filename in zBaseFilename is a URI with the "8_3_names=1" parameter and | |
| 21637 | +** if filename in z[] has a suffix (a.k.a. "extension") that is longer than | |
| 21638 | +** three characters, then shorten the suffix on z[] to be the last three | |
| 21639 | +** characters of the original suffix. | |
| 21640 | +** | |
| 21641 | +** Examples: | |
| 21642 | +** | |
| 21643 | +** test.db-journal => test.nal | |
| 21644 | +** test.db-wal => test.wal | |
| 21645 | +** test.db-shm => test.shm | |
| 21646 | +*/ | |
| 21647 | +SQLITE_PRIVATE void sqlite3FileSuffix3(const char *zBaseFilename, char *z){ | |
| 21648 | + const char *zOk; | |
| 21649 | + zOk = sqlite3_uri_parameter(zBaseFilename, "8_3_names"); | |
| 21650 | + if( zOk && sqlite3GetBoolean(zOk) ){ | |
| 21651 | + int i, sz; | |
| 21652 | + sz = sqlite3Strlen30(z); | |
| 21653 | + for(i=sz-1; i>0 && z[i]!='/' && z[i]!='.'; i--){} | |
| 21654 | + if( z[i]=='.' && ALWAYS(sz>i+4) ) memcpy(&z[i+1], &z[sz-3], 4); | |
| 21655 | + } | |
| 21656 | +} | |
| 21657 | +#endif | |
| 21353 | 21658 | |
| 21354 | 21659 | /************** End of util.c ************************************************/ |
| 21355 | 21660 | /************** Begin file hash.c ********************************************/ |
| 21356 | 21661 | /* |
| 21357 | 21662 | ** 2001 September 22 |
| @@ -27890,10 +28195,11 @@ | ||
| 27890 | 28195 | sqlite3_snprintf(nShmFilename, zShmFilename, |
| 27891 | 28196 | SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x", |
| 27892 | 28197 | (u32)sStat.st_ino, (u32)sStat.st_dev); |
| 27893 | 28198 | #else |
| 27894 | 28199 | sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", pDbFd->zPath); |
| 28200 | + sqlite3FileSuffix3(pDbFd->zPath, zShmFilename); | |
| 27895 | 28201 | #endif |
| 27896 | 28202 | pShmNode->h = -1; |
| 27897 | 28203 | pDbFd->pInode->pShmNode = pShmNode; |
| 27898 | 28204 | pShmNode->pInode = pDbFd->pInode; |
| 27899 | 28205 | pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); |
| @@ -28923,17 +29229,23 @@ | ||
| 28923 | 29229 | ** Finally, if the file being opened is a WAL or regular journal file, then |
| 28924 | 29230 | ** this function queries the file-system for the permissions on the |
| 28925 | 29231 | ** corresponding database file and sets *pMode to this value. Whenever |
| 28926 | 29232 | ** possible, WAL and journal files are created using the same permissions |
| 28927 | 29233 | ** as the associated database file. |
| 29234 | +** | |
| 29235 | +** If the SQLITE_ENABLE_8_3_NAMES option is enabled, then the | |
| 29236 | +** original filename is unavailable. But 8_3_NAMES is only used for | |
| 29237 | +** FAT filesystems and permissions do not matter there, so just use | |
| 29238 | +** the default permissions. | |
| 28928 | 29239 | */ |
| 28929 | 29240 | static int findCreateFileMode( |
| 28930 | 29241 | const char *zPath, /* Path of file (possibly) being created */ |
| 28931 | 29242 | int flags, /* Flags passed as 4th argument to xOpen() */ |
| 28932 | 29243 | mode_t *pMode /* OUT: Permissions to open file with */ |
| 28933 | 29244 | ){ |
| 28934 | 29245 | int rc = SQLITE_OK; /* Return Code */ |
| 29246 | + *pMode = SQLITE_DEFAULT_FILE_PERMISSIONS; | |
| 28935 | 29247 | if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){ |
| 28936 | 29248 | char zDb[MAX_PATHNAME+1]; /* Database file path */ |
| 28937 | 29249 | int nDb; /* Number of valid bytes in zDb */ |
| 28938 | 29250 | struct stat sStat; /* Output of stat() on database file */ |
| 28939 | 29251 | |
| @@ -28941,19 +29253,19 @@ | ||
| 28941 | 29253 | ** the path to the associated database file from zPath. This block handles |
| 28942 | 29254 | ** the following naming conventions: |
| 28943 | 29255 | ** |
| 28944 | 29256 | ** "<path to db>-journal" |
| 28945 | 29257 | ** "<path to db>-wal" |
| 28946 | - ** "<path to db>-journal-NNNN" | |
| 28947 | - ** "<path to db>-wal-NNNN" | |
| 29258 | + ** "<path to db>-journalNN" | |
| 29259 | + ** "<path to db>-walNN" | |
| 28948 | 29260 | ** |
| 28949 | - ** where NNNN is a 4 digit decimal number. The NNNN naming schemes are | |
| 29261 | + ** where NN is a 4 digit decimal number. The NN naming schemes are | |
| 28950 | 29262 | ** used by the test_multiplex.c module. |
| 28951 | 29263 | */ |
| 28952 | 29264 | nDb = sqlite3Strlen30(zPath) - 1; |
| 28953 | - while( nDb>0 && zPath[nDb]!='l' ) nDb--; | |
| 28954 | - nDb -= ((flags & SQLITE_OPEN_WAL) ? 3 : 7); | |
| 29265 | + while( nDb>0 && zPath[nDb]!='-' ) nDb--; | |
| 29266 | + if( nDb==0 ) return SQLITE_OK; | |
| 28955 | 29267 | memcpy(zDb, zPath, nDb); |
| 28956 | 29268 | zDb[nDb] = '\0'; |
| 28957 | 29269 | |
| 28958 | 29270 | if( 0==stat(zDb, &sStat) ){ |
| 28959 | 29271 | *pMode = sStat.st_mode & 0777; |
| @@ -28960,12 +29272,10 @@ | ||
| 28960 | 29272 | }else{ |
| 28961 | 29273 | rc = SQLITE_IOERR_FSTAT; |
| 28962 | 29274 | } |
| 28963 | 29275 | }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){ |
| 28964 | 29276 | *pMode = 0600; |
| 28965 | - }else{ | |
| 28966 | - *pMode = SQLITE_DEFAULT_FILE_PERMISSIONS; | |
| 28967 | 29277 | } |
| 28968 | 29278 | return rc; |
| 28969 | 29279 | } |
| 28970 | 29280 | |
| 28971 | 29281 | /* |
| @@ -32620,10 +32930,11 @@ | ||
| 32620 | 32930 | return SQLITE_NOMEM; |
| 32621 | 32931 | } |
| 32622 | 32932 | memset(pNew, 0, sizeof(*pNew)); |
| 32623 | 32933 | pNew->zFilename = (char*)&pNew[1]; |
| 32624 | 32934 | sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath); |
| 32935 | + sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename); | |
| 32625 | 32936 | |
| 32626 | 32937 | /* Look to see if there is an existing winShmNode that can be used. |
| 32627 | 32938 | ** If no matching winShmNode currently exists, create a new one. |
| 32628 | 32939 | */ |
| 32629 | 32940 | winShmEnterMutex(); |
| @@ -33514,10 +33825,17 @@ | ||
| 33514 | 33825 | |
| 33515 | 33826 | #if !SQLITE_OS_WINCE && !defined(__CYGWIN__) |
| 33516 | 33827 | int nByte; |
| 33517 | 33828 | void *zConverted; |
| 33518 | 33829 | char *zOut; |
| 33830 | + | |
| 33831 | + /* If this path name begins with "/X:", where "X" is any alphabetic | |
| 33832 | + ** character, discard the initial "/" from the pathname. | |
| 33833 | + */ | |
| 33834 | + if( zRelative[0]=='/' && sqlite3Isalpha(zRelative[1]) && zRelative[2]==':' ){ | |
| 33835 | + zRelative++; | |
| 33836 | + } | |
| 33519 | 33837 | |
| 33520 | 33838 | /* It's odd to simulate an io-error here, but really this is just |
| 33521 | 33839 | ** using the io-error infrastructure to test that SQLite handles this |
| 33522 | 33840 | ** function failing. This function could fail if, for example, the |
| 33523 | 33841 | ** current working directory has been unlinked. |
| @@ -36326,10 +36644,11 @@ | ||
| 36326 | 36644 | #define _WAL_H_ |
| 36327 | 36645 | |
| 36328 | 36646 | |
| 36329 | 36647 | #ifdef SQLITE_OMIT_WAL |
| 36330 | 36648 | # define sqlite3WalOpen(x,y,z) 0 |
| 36649 | +# define sqlite3WalLimit(x,y) | |
| 36331 | 36650 | # define sqlite3WalClose(w,x,y,z) 0 |
| 36332 | 36651 | # define sqlite3WalBeginReadTransaction(y,z) 0 |
| 36333 | 36652 | # define sqlite3WalEndReadTransaction(z) |
| 36334 | 36653 | # define sqlite3WalRead(v,w,x,y,z) 0 |
| 36335 | 36654 | # define sqlite3WalDbsize(y) 0 |
| @@ -36351,13 +36670,16 @@ | ||
| 36351 | 36670 | ** There is one object of this type for each pager. |
| 36352 | 36671 | */ |
| 36353 | 36672 | typedef struct Wal Wal; |
| 36354 | 36673 | |
| 36355 | 36674 | /* Open and close a connection to a write-ahead log. */ |
| 36356 | -SQLITE_PRIVATE int sqlite3WalOpen(sqlite3_vfs*, sqlite3_file*, const char *zName, int, Wal**); | |
| 36675 | +SQLITE_PRIVATE int sqlite3WalOpen(sqlite3_vfs*, sqlite3_file*, const char *, int, i64, Wal**); | |
| 36357 | 36676 | SQLITE_PRIVATE int sqlite3WalClose(Wal *pWal, int sync_flags, int, u8 *); |
| 36358 | 36677 | |
| 36678 | +/* Set the limiting size of a WAL file. */ | |
| 36679 | +SQLITE_PRIVATE void sqlite3WalLimit(Wal*, i64); | |
| 36680 | + | |
| 36359 | 36681 | /* Used by readers to open (lock) and close (unlock) a snapshot. A |
| 36360 | 36682 | ** snapshot is like a read-transaction. It is the state of the database |
| 36361 | 36683 | ** at an instant in time. sqlite3WalOpenSnapshot gets a read lock and |
| 36362 | 36684 | ** preserves the current state even if the other threads or processes |
| 36363 | 36685 | ** write to or checkpoint the WAL. sqlite3WalCloseSnapshot() closes the |
| @@ -40702,10 +41024,12 @@ | ||
| 40702 | 41024 | int nPathname = 0; /* Number of bytes in zPathname */ |
| 40703 | 41025 | int useJournal = (flags & PAGER_OMIT_JOURNAL)==0; /* False to omit journal */ |
| 40704 | 41026 | int noReadlock = (flags & PAGER_NO_READLOCK)!=0; /* True to omit read-lock */ |
| 40705 | 41027 | int pcacheSize = sqlite3PcacheSize(); /* Bytes to allocate for PCache */ |
| 40706 | 41028 | u32 szPageDflt = SQLITE_DEFAULT_PAGE_SIZE; /* Default page size */ |
| 41029 | + const char *zUri = 0; /* URI args to copy */ | |
| 41030 | + int nUri = 0; /* Number of bytes of URI args at *zUri */ | |
| 40707 | 41031 | |
| 40708 | 41032 | /* Figure out how much space is required for each journal file-handle |
| 40709 | 41033 | ** (there are two of them, the main journal and the sub-journal). This |
| 40710 | 41034 | ** is the maximum space required for an in-memory journal file handle |
| 40711 | 41035 | ** and a regular journal file-handle. Note that a "regular journal-handle" |
| @@ -40732,18 +41056,25 @@ | ||
| 40732 | 41056 | /* Compute and store the full pathname in an allocated buffer pointed |
| 40733 | 41057 | ** to by zPathname, length nPathname. Or, if this is a temporary file, |
| 40734 | 41058 | ** leave both nPathname and zPathname set to 0. |
| 40735 | 41059 | */ |
| 40736 | 41060 | if( zFilename && zFilename[0] ){ |
| 41061 | + const char *z; | |
| 40737 | 41062 | nPathname = pVfs->mxPathname+1; |
| 40738 | 41063 | zPathname = sqlite3Malloc(nPathname*2); |
| 40739 | 41064 | if( zPathname==0 ){ |
| 40740 | 41065 | return SQLITE_NOMEM; |
| 40741 | 41066 | } |
| 40742 | 41067 | zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */ |
| 40743 | 41068 | rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname); |
| 40744 | 41069 | nPathname = sqlite3Strlen30(zPathname); |
| 41070 | + z = zUri = &zFilename[sqlite3Strlen30(zFilename)+1]; | |
| 41071 | + while( *z ){ | |
| 41072 | + z += sqlite3Strlen30(z)+1; | |
| 41073 | + z += sqlite3Strlen30(z)+1; | |
| 41074 | + } | |
| 41075 | + nUri = &z[1] - zUri; | |
| 40745 | 41076 | if( rc==SQLITE_OK && nPathname+8>pVfs->mxPathname ){ |
| 40746 | 41077 | /* This branch is taken when the journal path required by |
| 40747 | 41078 | ** the database being opened will be more than pVfs->mxPathname |
| 40748 | 41079 | ** bytes in length. This means the database cannot be opened, |
| 40749 | 41080 | ** as it will not be possible to open the journal file or even |
| @@ -40772,11 +41103,11 @@ | ||
| 40772 | 41103 | pPtr = (u8 *)sqlite3MallocZero( |
| 40773 | 41104 | ROUND8(sizeof(*pPager)) + /* Pager structure */ |
| 40774 | 41105 | ROUND8(pcacheSize) + /* PCache object */ |
| 40775 | 41106 | ROUND8(pVfs->szOsFile) + /* The main db file */ |
| 40776 | 41107 | journalFileSize * 2 + /* The two journal files */ |
| 40777 | - nPathname + 1 + /* zFilename */ | |
| 41108 | + nPathname + 1 + nUri + /* zFilename */ | |
| 40778 | 41109 | nPathname + 8 + 1 /* zJournal */ |
| 40779 | 41110 | #ifndef SQLITE_OMIT_WAL |
| 40780 | 41111 | + nPathname + 4 + 1 /* zWal */ |
| 40781 | 41112 | #endif |
| 40782 | 41113 | ); |
| @@ -40794,18 +41125,21 @@ | ||
| 40794 | 41125 | assert( EIGHT_BYTE_ALIGNMENT(pPager->jfd) ); |
| 40795 | 41126 | |
| 40796 | 41127 | /* Fill in the Pager.zFilename and Pager.zJournal buffers, if required. */ |
| 40797 | 41128 | if( zPathname ){ |
| 40798 | 41129 | assert( nPathname>0 ); |
| 40799 | - pPager->zJournal = (char*)(pPtr += nPathname + 1); | |
| 41130 | + pPager->zJournal = (char*)(pPtr += nPathname + 1 + nUri); | |
| 40800 | 41131 | memcpy(pPager->zFilename, zPathname, nPathname); |
| 41132 | + memcpy(&pPager->zFilename[nPathname+1], zUri, nUri); | |
| 40801 | 41133 | memcpy(pPager->zJournal, zPathname, nPathname); |
| 40802 | 41134 | memcpy(&pPager->zJournal[nPathname], "-journal", 8); |
| 41135 | + sqlite3FileSuffix3(pPager->zFilename, pPager->zJournal); | |
| 40803 | 41136 | #ifndef SQLITE_OMIT_WAL |
| 40804 | 41137 | pPager->zWal = &pPager->zJournal[nPathname+8+1]; |
| 40805 | 41138 | memcpy(pPager->zWal, zPathname, nPathname); |
| 40806 | 41139 | memcpy(&pPager->zWal[nPathname], "-wal", 4); |
| 41140 | + sqlite3FileSuffix3(pPager->zFilename, pPager->zWal); | |
| 40807 | 41141 | #endif |
| 40808 | 41142 | sqlite3_free(zPathname); |
| 40809 | 41143 | } |
| 40810 | 41144 | pPager->pVfs = pVfs; |
| 40811 | 41145 | pPager->vfsFlags = vfsFlags; |
| @@ -43000,10 +43334,11 @@ | ||
| 43000 | 43334 | ** An attempt to set a limit smaller than -1 is a no-op. |
| 43001 | 43335 | */ |
| 43002 | 43336 | SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *pPager, i64 iLimit){ |
| 43003 | 43337 | if( iLimit>=-1 ){ |
| 43004 | 43338 | pPager->journalSizeLimit = iLimit; |
| 43339 | + sqlite3WalLimit(pPager->pWal, iLimit); | |
| 43005 | 43340 | } |
| 43006 | 43341 | return pPager->journalSizeLimit; |
| 43007 | 43342 | } |
| 43008 | 43343 | |
| 43009 | 43344 | /* |
| @@ -43091,11 +43426,12 @@ | ||
| 43091 | 43426 | /* Open the connection to the log file. If this operation fails, |
| 43092 | 43427 | ** (e.g. due to malloc() failure), return an error code. |
| 43093 | 43428 | */ |
| 43094 | 43429 | if( rc==SQLITE_OK ){ |
| 43095 | 43430 | rc = sqlite3WalOpen(pPager->pVfs, |
| 43096 | - pPager->fd, pPager->zWal, pPager->exclusiveMode, &pPager->pWal | |
| 43431 | + pPager->fd, pPager->zWal, pPager->exclusiveMode, | |
| 43432 | + pPager->journalSizeLimit, &pPager->pWal | |
| 43097 | 43433 | ); |
| 43098 | 43434 | } |
| 43099 | 43435 | |
| 43100 | 43436 | return rc; |
| 43101 | 43437 | } |
| @@ -43623,10 +43959,11 @@ | ||
| 43623 | 43959 | struct Wal { |
| 43624 | 43960 | sqlite3_vfs *pVfs; /* The VFS used to create pDbFd */ |
| 43625 | 43961 | sqlite3_file *pDbFd; /* File handle for the database file */ |
| 43626 | 43962 | sqlite3_file *pWalFd; /* File handle for WAL file */ |
| 43627 | 43963 | u32 iCallback; /* Value to pass to log callback (or 0) */ |
| 43964 | + i64 mxWalSize; /* Truncate WAL to this size upon reset */ | |
| 43628 | 43965 | int nWiData; /* Size of array apWiData */ |
| 43629 | 43966 | volatile u32 **apWiData; /* Pointer to wal-index content in memory */ |
| 43630 | 43967 | u32 szPage; /* Database page size */ |
| 43631 | 43968 | i16 readLock; /* Which read lock is being held. -1 for none */ |
| 43632 | 43969 | u8 exclusiveMode; /* Non-zero if connection is in exclusive mode */ |
| @@ -44445,10 +44782,11 @@ | ||
| 44445 | 44782 | SQLITE_PRIVATE int sqlite3WalOpen( |
| 44446 | 44783 | sqlite3_vfs *pVfs, /* vfs module to open wal and wal-index */ |
| 44447 | 44784 | sqlite3_file *pDbFd, /* The open database file */ |
| 44448 | 44785 | const char *zWalName, /* Name of the WAL file */ |
| 44449 | 44786 | int bNoShm, /* True to run in heap-memory mode */ |
| 44787 | + i64 mxWalSize, /* Truncate WAL to this size on reset */ | |
| 44450 | 44788 | Wal **ppWal /* OUT: Allocated Wal handle */ |
| 44451 | 44789 | ){ |
| 44452 | 44790 | int rc; /* Return Code */ |
| 44453 | 44791 | Wal *pRet; /* Object to allocate and return */ |
| 44454 | 44792 | int flags; /* Flags passed to OsOpen() */ |
| @@ -44477,10 +44815,11 @@ | ||
| 44477 | 44815 | |
| 44478 | 44816 | pRet->pVfs = pVfs; |
| 44479 | 44817 | pRet->pWalFd = (sqlite3_file *)&pRet[1]; |
| 44480 | 44818 | pRet->pDbFd = pDbFd; |
| 44481 | 44819 | pRet->readLock = -1; |
| 44820 | + pRet->mxWalSize = mxWalSize; | |
| 44482 | 44821 | pRet->zWalName = zWalName; |
| 44483 | 44822 | pRet->exclusiveMode = (bNoShm ? WAL_HEAPMEMORY_MODE: WAL_NORMAL_MODE); |
| 44484 | 44823 | |
| 44485 | 44824 | /* Open file handle on the write-ahead log file. */ |
| 44486 | 44825 | flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_WAL); |
| @@ -44497,10 +44836,17 @@ | ||
| 44497 | 44836 | *ppWal = pRet; |
| 44498 | 44837 | WALTRACE(("WAL%d: opened\n", pRet)); |
| 44499 | 44838 | } |
| 44500 | 44839 | return rc; |
| 44501 | 44840 | } |
| 44841 | + | |
| 44842 | +/* | |
| 44843 | +** Change the size to which the WAL file is trucated on each reset. | |
| 44844 | +*/ | |
| 44845 | +SQLITE_PRIVATE void sqlite3WalLimit(Wal *pWal, i64 iLimit){ | |
| 44846 | + if( pWal ) pWal->mxWalSize = iLimit; | |
| 44847 | +} | |
| 44502 | 44848 | |
| 44503 | 44849 | /* |
| 44504 | 44850 | ** Find the smallest page number out of all pages held in the WAL that |
| 44505 | 44851 | ** has not been returned by any prior invocation of this method on the |
| 44506 | 44852 | ** same WalIterator object. Write into *piFrame the frame index where |
| @@ -45733,10 +46079,26 @@ | ||
| 45733 | 46079 | ** safe and means there is no special case for sqlite3WalUndo() |
| 45734 | 46080 | ** to handle if this transaction is rolled back. |
| 45735 | 46081 | */ |
| 45736 | 46082 | int i; /* Loop counter */ |
| 45737 | 46083 | u32 *aSalt = pWal->hdr.aSalt; /* Big-endian salt values */ |
| 46084 | + | |
| 46085 | + /* Limit the size of WAL file if the journal_size_limit PRAGMA is | |
| 46086 | + ** set to a non-negative value. Log errors encountered | |
| 46087 | + ** during the truncation attempt. */ | |
| 46088 | + if( pWal->mxWalSize>=0 ){ | |
| 46089 | + i64 sz; | |
| 46090 | + int rx; | |
| 46091 | + rx = sqlite3OsFileSize(pWal->pWalFd, &sz); | |
| 46092 | + if( rx==SQLITE_OK && (sz > pWal->mxWalSize) ){ | |
| 46093 | + rx = sqlite3OsTruncate(pWal->pWalFd, pWal->mxWalSize); | |
| 46094 | + } | |
| 46095 | + if( rx ){ | |
| 46096 | + sqlite3_log(rx, "cannot limit WAL size: %s", pWal->zWalName); | |
| 46097 | + } | |
| 46098 | + } | |
| 46099 | + | |
| 45738 | 46100 | pWal->nCkpt++; |
| 45739 | 46101 | pWal->hdr.mxFrame = 0; |
| 45740 | 46102 | sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0])); |
| 45741 | 46103 | aSalt[1] = salt1; |
| 45742 | 46104 | walIndexWriteHdr(pWal); |
| @@ -47838,10 +48200,11 @@ | ||
| 47838 | 48200 | offset = PTRMAP_PTROFFSET(iPtrmap, key); |
| 47839 | 48201 | if( offset<0 ){ |
| 47840 | 48202 | *pRC = SQLITE_CORRUPT_BKPT; |
| 47841 | 48203 | goto ptrmap_exit; |
| 47842 | 48204 | } |
| 48205 | + assert( offset <= (int)pBt->usableSize-5 ); | |
| 47843 | 48206 | pPtrmap = (u8 *)sqlite3PagerGetData(pDbPage); |
| 47844 | 48207 | |
| 47845 | 48208 | if( eType!=pPtrmap[offset] || get4byte(&pPtrmap[offset+1])!=parent ){ |
| 47846 | 48209 | TRACE(("PTRMAP_UPDATE: %d->(%d,%d)\n", key, eType, parent)); |
| 47847 | 48210 | *pRC= rc = sqlite3PagerWrite(pDbPage); |
| @@ -47877,10 +48240,15 @@ | ||
| 47877 | 48240 | return rc; |
| 47878 | 48241 | } |
| 47879 | 48242 | pPtrmap = (u8 *)sqlite3PagerGetData(pDbPage); |
| 47880 | 48243 | |
| 47881 | 48244 | offset = PTRMAP_PTROFFSET(iPtrmap, key); |
| 48245 | + if( offset<0 ){ | |
| 48246 | + sqlite3PagerUnref(pDbPage); | |
| 48247 | + return SQLITE_CORRUPT_BKPT; | |
| 48248 | + } | |
| 48249 | + assert( offset <= (int)pBt->usableSize-5 ); | |
| 47882 | 48250 | assert( pEType!=0 ); |
| 47883 | 48251 | *pEType = pPtrmap[offset]; |
| 47884 | 48252 | if( pPgno ) *pPgno = get4byte(&pPtrmap[offset+1]); |
| 47885 | 48253 | |
| 47886 | 48254 | sqlite3PagerUnref(pDbPage); |
| @@ -48738,17 +49106,17 @@ | ||
| 48738 | 49106 | ** SQLITE_CONSTRAINT error. We cannot allow two or more BtShared |
| 48739 | 49107 | ** objects in the same database connection since doing so will lead |
| 48740 | 49108 | ** to problems with locking. |
| 48741 | 49109 | */ |
| 48742 | 49110 | SQLITE_PRIVATE int sqlite3BtreeOpen( |
| 49111 | + sqlite3_vfs *pVfs, /* VFS to use for this b-tree */ | |
| 48743 | 49112 | const char *zFilename, /* Name of the file containing the BTree database */ |
| 48744 | 49113 | sqlite3 *db, /* Associated database handle */ |
| 48745 | 49114 | Btree **ppBtree, /* Pointer to new Btree object written here */ |
| 48746 | 49115 | int flags, /* Options */ |
| 48747 | 49116 | int vfsFlags /* Flags passed through to sqlite3_vfs.xOpen() */ |
| 48748 | 49117 | ){ |
| 48749 | - sqlite3_vfs *pVfs; /* The VFS to use for this btree */ | |
| 48750 | 49118 | BtShared *pBt = 0; /* Shared part of btree structure */ |
| 48751 | 49119 | Btree *p; /* Handle to return */ |
| 48752 | 49120 | sqlite3_mutex *mutexOpen = 0; /* Prevents a race condition. Ticket #3537 */ |
| 48753 | 49121 | int rc = SQLITE_OK; /* Result code from this function */ |
| 48754 | 49122 | u8 nReserve; /* Byte of unused space on each page */ |
| @@ -48766,10 +49134,11 @@ | ||
| 48766 | 49134 | const int isMemdb = (zFilename && strcmp(zFilename, ":memory:")==0) |
| 48767 | 49135 | || (isTempDb && sqlite3TempInMemory(db)); |
| 48768 | 49136 | #endif |
| 48769 | 49137 | |
| 48770 | 49138 | assert( db!=0 ); |
| 49139 | + assert( pVfs!=0 ); | |
| 48771 | 49140 | assert( sqlite3_mutex_held(db->mutex) ); |
| 48772 | 49141 | assert( (flags&0xff)==flags ); /* flags fit in 8 bits */ |
| 48773 | 49142 | |
| 48774 | 49143 | /* Only a BTREE_SINGLE database can be BTREE_UNORDERED */ |
| 48775 | 49144 | assert( (flags & BTREE_UNORDERED)==0 || (flags & BTREE_SINGLE)!=0 ); |
| @@ -48784,11 +49153,10 @@ | ||
| 48784 | 49153 | flags |= BTREE_MEMORY; |
| 48785 | 49154 | } |
| 48786 | 49155 | if( (vfsFlags & SQLITE_OPEN_MAIN_DB)!=0 && (isMemdb || isTempDb) ){ |
| 48787 | 49156 | vfsFlags = (vfsFlags & ~SQLITE_OPEN_MAIN_DB) | SQLITE_OPEN_TEMP_DB; |
| 48788 | 49157 | } |
| 48789 | - pVfs = db->pVfs; | |
| 48790 | 49158 | p = sqlite3MallocZero(sizeof(Btree)); |
| 48791 | 49159 | if( !p ){ |
| 48792 | 49160 | return SQLITE_NOMEM; |
| 48793 | 49161 | } |
| 48794 | 49162 | p->inTrans = TRANS_NONE; |
| @@ -58855,10 +59223,11 @@ | ||
| 58855 | 59223 | sqlite3_randomness(sizeof(iRandom), &iRandom); |
| 58856 | 59224 | zMaster = sqlite3MPrintf(db, "%s-mj%08X", zMainFile, iRandom&0x7fffffff); |
| 58857 | 59225 | if( !zMaster ){ |
| 58858 | 59226 | return SQLITE_NOMEM; |
| 58859 | 59227 | } |
| 59228 | + sqlite3FileSuffix3(zMainFile, zMaster); | |
| 58860 | 59229 | rc = sqlite3OsAccess(pVfs, zMaster, SQLITE_ACCESS_EXISTS, &res); |
| 58861 | 59230 | }while( rc==SQLITE_OK && res ); |
| 58862 | 59231 | if( rc==SQLITE_OK ){ |
| 58863 | 59232 | /* Open the master journal. */ |
| 58864 | 59233 | rc = sqlite3OsOpenMalloc(pVfs, zMaster, &pMaster, |
| @@ -59068,10 +59437,19 @@ | ||
| 59068 | 59437 | } |
| 59069 | 59438 | } |
| 59070 | 59439 | } |
| 59071 | 59440 | db->nStatement--; |
| 59072 | 59441 | p->iStatement = 0; |
| 59442 | + | |
| 59443 | + if( rc==SQLITE_OK ){ | |
| 59444 | + if( eOp==SAVEPOINT_ROLLBACK ){ | |
| 59445 | + rc = sqlite3VtabSavepoint(db, SAVEPOINT_ROLLBACK, iSavepoint); | |
| 59446 | + } | |
| 59447 | + if( rc==SQLITE_OK ){ | |
| 59448 | + rc = sqlite3VtabSavepoint(db, SAVEPOINT_RELEASE, iSavepoint); | |
| 59449 | + } | |
| 59450 | + } | |
| 59073 | 59451 | |
| 59074 | 59452 | /* If the statement transaction is being rolled back, also restore the |
| 59075 | 59453 | ** database handles deferred constraint counter to the value it had when |
| 59076 | 59454 | ** the statement transaction was opened. */ |
| 59077 | 59455 | if( eOp==SAVEPOINT_ROLLBACK ){ |
| @@ -62400,10 +62778,11 @@ | ||
| 62400 | 62778 | Mem *pIn2 = 0; /* 2nd input operand */ |
| 62401 | 62779 | Mem *pIn3 = 0; /* 3rd input operand */ |
| 62402 | 62780 | Mem *pOut = 0; /* Output operand */ |
| 62403 | 62781 | int iCompare = 0; /* Result of last OP_Compare operation */ |
| 62404 | 62782 | int *aPermute = 0; /* Permutation of columns for OP_Compare */ |
| 62783 | + i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */ | |
| 62405 | 62784 | #ifdef VDBE_PROFILE |
| 62406 | 62785 | u64 start; /* CPU clock count at start of opcode */ |
| 62407 | 62786 | int origPc; /* Program counter at start of opcode */ |
| 62408 | 62787 | #endif |
| 62409 | 62788 | /******************************************************************** |
| @@ -63078,10 +63457,11 @@ | ||
| 63078 | 63457 | VdbeFrame *pFrame = p->pFrame; |
| 63079 | 63458 | p->pFrame = pFrame->pParent; |
| 63080 | 63459 | p->nFrame--; |
| 63081 | 63460 | sqlite3VdbeSetChanges(db, p->nChange); |
| 63082 | 63461 | pc = sqlite3VdbeFrameRestore(pFrame); |
| 63462 | + lastRowid = db->lastRowid; | |
| 63083 | 63463 | if( pOp->p2==OE_Ignore ){ |
| 63084 | 63464 | /* Instruction pc is the OP_Program that invoked the sub-program |
| 63085 | 63465 | ** currently being halted. If the p2 instruction of this OP_Halt |
| 63086 | 63466 | ** instruction is set to OE_Ignore, then the sub-program is throwing |
| 63087 | 63467 | ** an IGNORE exception. In this case jump to the address specified |
| @@ -63650,11 +64030,13 @@ | ||
| 63650 | 64030 | assert( pOp>aOp ); |
| 63651 | 64031 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 63652 | 64032 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 63653 | 64033 | u.ag.ctx.pColl = pOp[-1].p4.pColl; |
| 63654 | 64034 | } |
| 64035 | + db->lastRowid = lastRowid; | |
| 63655 | 64036 | (*u.ag.ctx.pFunc->xFunc)(&u.ag.ctx, u.ag.n, u.ag.apVal); /* IMP: R-24505-23230 */ |
| 64037 | + lastRowid = db->lastRowid; | |
| 63656 | 64038 | if( db->mallocFailed ){ |
| 63657 | 64039 | /* Even though a malloc() has failed, the implementation of the |
| 63658 | 64040 | ** user function may have called an sqlite3_result_XXX() function |
| 63659 | 64041 | ** to return a value. The following call releases any resources |
| 63660 | 64042 | ** associated with such a value. |
| @@ -64857,10 +65239,18 @@ | ||
| 64857 | 65239 | "SQL statements in progress"); |
| 64858 | 65240 | rc = SQLITE_BUSY; |
| 64859 | 65241 | }else{ |
| 64860 | 65242 | u.aq.nName = sqlite3Strlen30(u.aq.zName); |
| 64861 | 65243 | |
| 65244 | + /* This call is Ok even if this savepoint is actually a transaction | |
| 65245 | + ** savepoint (and therefore should not prompt xSavepoint()) callbacks. | |
| 65246 | + ** If this is a transaction savepoint being opened, it is guaranteed | |
| 65247 | + ** that the db->aVTrans[] array is empty. */ | |
| 65248 | + assert( db->autoCommit==0 || db->nVTrans==0 ); | |
| 65249 | + rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement); | |
| 65250 | + if( rc!=SQLITE_OK ) goto abort_due_to_error; | |
| 65251 | + | |
| 64862 | 65252 | /* Create a new savepoint structure. */ |
| 64863 | 65253 | u.aq.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.aq.nName+1); |
| 64864 | 65254 | if( u.aq.pNew ){ |
| 64865 | 65255 | u.aq.pNew->zName = (char *)&u.aq.pNew[1]; |
| 64866 | 65256 | memcpy(u.aq.pNew->zName, u.aq.zName, u.aq.nName+1); |
| @@ -64963,10 +65353,15 @@ | ||
| 64963 | 65353 | db->nSavepoint--; |
| 64964 | 65354 | } |
| 64965 | 65355 | }else{ |
| 64966 | 65356 | db->nDeferredCons = u.aq.pSavepoint->nDeferredCons; |
| 64967 | 65357 | } |
| 65358 | + | |
| 65359 | + if( !isTransaction ){ | |
| 65360 | + rc = sqlite3VtabSavepoint(db, u.aq.p1, u.aq.iSavepoint); | |
| 65361 | + if( rc!=SQLITE_OK ) goto abort_due_to_error; | |
| 65362 | + } | |
| 64968 | 65363 | } |
| 64969 | 65364 | } |
| 64970 | 65365 | |
| 64971 | 65366 | break; |
| 64972 | 65367 | } |
| @@ -65102,11 +65497,15 @@ | ||
| 65102 | 65497 | if( p->iStatement==0 ){ |
| 65103 | 65498 | assert( db->nStatement>=0 && db->nSavepoint>=0 ); |
| 65104 | 65499 | db->nStatement++; |
| 65105 | 65500 | p->iStatement = db->nSavepoint + db->nStatement; |
| 65106 | 65501 | } |
| 65107 | - rc = sqlite3BtreeBeginStmt(u.as.pBt, p->iStatement); | |
| 65502 | + | |
| 65503 | + rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement); | |
| 65504 | + if( rc==SQLITE_OK ){ | |
| 65505 | + rc = sqlite3BtreeBeginStmt(u.as.pBt, p->iStatement); | |
| 65506 | + } | |
| 65108 | 65507 | |
| 65109 | 65508 | /* Store the current value of the database handles deferred constraint |
| 65110 | 65509 | ** counter. If the statement transaction needs to be rolled back, |
| 65111 | 65510 | ** the value of this counter needs to be restored too. */ |
| 65112 | 65511 | p->nStmtDefCons = db->nDeferredCons; |
| @@ -65423,11 +65822,11 @@ | ||
| 65423 | 65822 | |
| 65424 | 65823 | assert( pOp->p1>=0 ); |
| 65425 | 65824 | u.ax.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1); |
| 65426 | 65825 | if( u.ax.pCx==0 ) goto no_mem; |
| 65427 | 65826 | u.ax.pCx->nullRow = 1; |
| 65428 | - rc = sqlite3BtreeOpen(0, db, &u.ax.pCx->pBt, | |
| 65827 | + rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.ax.pCx->pBt, | |
| 65429 | 65828 | BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags); |
| 65430 | 65829 | if( rc==SQLITE_OK ){ |
| 65431 | 65830 | rc = sqlite3BtreeBeginTrans(u.ax.pCx->pBt, 1); |
| 65432 | 65831 | } |
| 65433 | 65832 | if( rc==SQLITE_OK ){ |
| @@ -66097,11 +66496,11 @@ | ||
| 66097 | 66496 | ** engine starts picking positive candidate ROWIDs at random until |
| 66098 | 66497 | ** it finds one that is not previously used. */ |
| 66099 | 66498 | assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is |
| 66100 | 66499 | ** an AUTOINCREMENT table. */ |
| 66101 | 66500 | /* on the first attempt, simply do one more than previous */ |
| 66102 | - u.be.v = db->lastRowid; | |
| 66501 | + u.be.v = lastRowid; | |
| 66103 | 66502 | u.be.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */ |
| 66104 | 66503 | u.be.v++; /* ensure non-zero */ |
| 66105 | 66504 | u.be.cnt = 0; |
| 66106 | 66505 | while( ((rc = sqlite3BtreeMovetoUnpacked(u.be.pC->pCursor, 0, (u64)u.be.v, |
| 66107 | 66506 | 0, &u.be.res))==SQLITE_OK) |
| @@ -66209,11 +66608,11 @@ | ||
| 66209 | 66608 | assert( pOp->opcode==OP_InsertInt ); |
| 66210 | 66609 | u.bf.iKey = pOp->p3; |
| 66211 | 66610 | } |
| 66212 | 66611 | |
| 66213 | 66612 | if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; |
| 66214 | - if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = u.bf.iKey; | |
| 66613 | + if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = u.bf.iKey; | |
| 66215 | 66614 | if( u.bf.pData->flags & MEM_Null ){ |
| 66216 | 66615 | u.bf.pData->z = 0; |
| 66217 | 66616 | u.bf.pData->n = 0; |
| 66218 | 66617 | }else{ |
| 66219 | 66618 | assert( u.bf.pData->flags & (MEM_Blob|MEM_Str) ); |
| @@ -67335,11 +67734,11 @@ | ||
| 67335 | 67734 | assert( pc==u.by.pFrame->pc ); |
| 67336 | 67735 | } |
| 67337 | 67736 | |
| 67338 | 67737 | p->nFrame++; |
| 67339 | 67738 | u.by.pFrame->pParent = p->pFrame; |
| 67340 | - u.by.pFrame->lastRowid = db->lastRowid; | |
| 67739 | + u.by.pFrame->lastRowid = lastRowid; | |
| 67341 | 67740 | u.by.pFrame->nChange = p->nChange; |
| 67342 | 67741 | p->nChange = 0; |
| 67343 | 67742 | p->pFrame = u.by.pFrame; |
| 67344 | 67743 | p->aMem = aMem = &VdbeFrameMem(u.by.pFrame)[-1]; |
| 67345 | 67744 | p->nMem = u.by.pFrame->nChildMem; |
| @@ -68146,31 +68545,45 @@ | ||
| 68146 | 68545 | sqlite_int64 rowid; |
| 68147 | 68546 | Mem **apArg; |
| 68148 | 68547 | Mem *pX; |
| 68149 | 68548 | #endif /* local variables moved into u.cm */ |
| 68150 | 68549 | |
| 68550 | + assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback | |
| 68551 | + || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace | |
| 68552 | + ); | |
| 68151 | 68553 | u.cm.pVtab = pOp->p4.pVtab->pVtab; |
| 68152 | 68554 | u.cm.pModule = (sqlite3_module *)u.cm.pVtab->pModule; |
| 68153 | 68555 | u.cm.nArg = pOp->p2; |
| 68154 | 68556 | assert( pOp->p4type==P4_VTAB ); |
| 68155 | 68557 | if( ALWAYS(u.cm.pModule->xUpdate) ){ |
| 68558 | + u8 vtabOnConflict = db->vtabOnConflict; | |
| 68156 | 68559 | u.cm.apArg = p->apArg; |
| 68157 | 68560 | u.cm.pX = &aMem[pOp->p3]; |
| 68158 | 68561 | for(u.cm.i=0; u.cm.i<u.cm.nArg; u.cm.i++){ |
| 68159 | 68562 | assert( memIsValid(u.cm.pX) ); |
| 68160 | 68563 | memAboutToChange(p, u.cm.pX); |
| 68161 | 68564 | sqlite3VdbeMemStoreType(u.cm.pX); |
| 68162 | 68565 | u.cm.apArg[u.cm.i] = u.cm.pX; |
| 68163 | 68566 | u.cm.pX++; |
| 68164 | 68567 | } |
| 68568 | + db->vtabOnConflict = pOp->p5; | |
| 68165 | 68569 | rc = u.cm.pModule->xUpdate(u.cm.pVtab, u.cm.nArg, u.cm.apArg, &u.cm.rowid); |
| 68570 | + db->vtabOnConflict = vtabOnConflict; | |
| 68166 | 68571 | importVtabErrMsg(p, u.cm.pVtab); |
| 68167 | 68572 | if( rc==SQLITE_OK && pOp->p1 ){ |
| 68168 | 68573 | assert( u.cm.nArg>1 && u.cm.apArg[0] && (u.cm.apArg[0]->flags&MEM_Null) ); |
| 68169 | - db->lastRowid = u.cm.rowid; | |
| 68574 | + db->lastRowid = lastRowid = u.cm.rowid; | |
| 68170 | 68575 | } |
| 68171 | - p->nChange++; | |
| 68576 | + if( rc==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){ | |
| 68577 | + if( pOp->p5==OE_Ignore ){ | |
| 68578 | + rc = SQLITE_OK; | |
| 68579 | + }else{ | |
| 68580 | + p->errorAction = ((pOp->p5==OE_Replace) ? OE_Abort : pOp->p5); | |
| 68581 | + } | |
| 68582 | + }else{ | |
| 68583 | + p->nChange++; | |
| 68584 | + } | |
| 68172 | 68585 | } |
| 68173 | 68586 | break; |
| 68174 | 68587 | } |
| 68175 | 68588 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 68176 | 68589 | |
| @@ -68316,10 +68729,11 @@ | ||
| 68316 | 68729 | |
| 68317 | 68730 | /* This is the only way out of this procedure. We have to |
| 68318 | 68731 | ** release the mutexes on btrees that were acquired at the |
| 68319 | 68732 | ** top. */ |
| 68320 | 68733 | vdbe_return: |
| 68734 | + db->lastRowid = lastRowid; | |
| 68321 | 68735 | sqlite3VdbeLeave(p); |
| 68322 | 68736 | return rc; |
| 68323 | 68737 | |
| 68324 | 68738 | /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH |
| 68325 | 68739 | ** is encountered. |
| @@ -76044,12 +76458,16 @@ | ||
| 76044 | 76458 | int i; |
| 76045 | 76459 | int rc = 0; |
| 76046 | 76460 | sqlite3 *db = sqlite3_context_db_handle(context); |
| 76047 | 76461 | const char *zName; |
| 76048 | 76462 | const char *zFile; |
| 76463 | + char *zPath = 0; | |
| 76464 | + char *zErr = 0; | |
| 76465 | + unsigned int flags; | |
| 76049 | 76466 | Db *aNew; |
| 76050 | 76467 | char *zErrDyn = 0; |
| 76468 | + sqlite3_vfs *pVfs; | |
| 76051 | 76469 | |
| 76052 | 76470 | UNUSED_PARAMETER(NotUsed); |
| 76053 | 76471 | |
| 76054 | 76472 | zFile = (const char *)sqlite3_value_text(argv[0]); |
| 76055 | 76473 | zName = (const char *)sqlite3_value_text(argv[1]); |
| @@ -76098,12 +76516,22 @@ | ||
| 76098 | 76516 | |
| 76099 | 76517 | /* Open the database file. If the btree is successfully opened, use |
| 76100 | 76518 | ** it to obtain the database schema. At this point the schema may |
| 76101 | 76519 | ** or may not be initialised. |
| 76102 | 76520 | */ |
| 76103 | - rc = sqlite3BtreeOpen(zFile, db, &aNew->pBt, 0, | |
| 76104 | - db->openFlags | SQLITE_OPEN_MAIN_DB); | |
| 76521 | + flags = db->openFlags; | |
| 76522 | + rc = sqlite3ParseUri(db->pVfs->zName, zFile, &flags, &pVfs, &zPath, &zErr); | |
| 76523 | + if( rc!=SQLITE_OK ){ | |
| 76524 | + if( rc==SQLITE_NOMEM ) db->mallocFailed = 1; | |
| 76525 | + sqlite3_result_error(context, zErr, -1); | |
| 76526 | + sqlite3_free(zErr); | |
| 76527 | + return; | |
| 76528 | + } | |
| 76529 | + assert( pVfs ); | |
| 76530 | + flags |= SQLITE_OPEN_MAIN_DB; | |
| 76531 | + rc = sqlite3BtreeOpen(pVfs, zPath, db, &aNew->pBt, 0, flags); | |
| 76532 | + sqlite3_free( zPath ); | |
| 76105 | 76533 | db->nDb++; |
| 76106 | 76534 | if( rc==SQLITE_CONSTRAINT ){ |
| 76107 | 76535 | rc = SQLITE_ERROR; |
| 76108 | 76536 | zErrDyn = sqlite3MPrintf(db, "database is already attached"); |
| 76109 | 76537 | }else if( rc==SQLITE_OK ){ |
| @@ -80213,11 +80641,11 @@ | ||
| 80213 | 80641 | SQLITE_OPEN_CREATE | |
| 80214 | 80642 | SQLITE_OPEN_EXCLUSIVE | |
| 80215 | 80643 | SQLITE_OPEN_DELETEONCLOSE | |
| 80216 | 80644 | SQLITE_OPEN_TEMP_DB; |
| 80217 | 80645 | |
| 80218 | - rc = sqlite3BtreeOpen(0, db, &pBt, 0, flags); | |
| 80646 | + rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pBt, 0, flags); | |
| 80219 | 80647 | if( rc!=SQLITE_OK ){ |
| 80220 | 80648 | sqlite3ErrorMsg(pParse, "unable to open a temporary database " |
| 80221 | 80649 | "file for storing temporary tables"); |
| 80222 | 80650 | pParse->rc = rc; |
| 80223 | 80651 | return 1; |
| @@ -85399,10 +85827,11 @@ | ||
| 85399 | 85827 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 85400 | 85828 | if( IsVirtual(pTab) ){ |
| 85401 | 85829 | const char *pVTab = (const char *)sqlite3GetVTable(db, pTab); |
| 85402 | 85830 | sqlite3VtabMakeWritable(pParse, pTab); |
| 85403 | 85831 | sqlite3VdbeAddOp4(v, OP_VUpdate, 1, pTab->nCol+2, regIns, pVTab, P4_VTAB); |
| 85832 | + sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError); | |
| 85404 | 85833 | sqlite3MayAbort(pParse); |
| 85405 | 85834 | }else |
| 85406 | 85835 | #endif |
| 85407 | 85836 | { |
| 85408 | 85837 | int isReplace; /* Set to true if constraints may cause a replace */ |
| @@ -87544,11 +87973,11 @@ | ||
| 87544 | 87973 | } |
| 87545 | 87974 | |
| 87546 | 87975 | /* |
| 87547 | 87976 | ** Interpret the given string as a boolean value. |
| 87548 | 87977 | */ |
| 87549 | -static u8 getBoolean(const char *z){ | |
| 87978 | +SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z){ | |
| 87550 | 87979 | return getSafetyLevel(z)&1; |
| 87551 | 87980 | } |
| 87552 | 87981 | |
| 87553 | 87982 | /* |
| 87554 | 87983 | ** Interpret the given string as a locking mode value. |
| @@ -87714,11 +88143,11 @@ | ||
| 87714 | 88143 | /* Foreign key support may not be enabled or disabled while not |
| 87715 | 88144 | ** in auto-commit mode. */ |
| 87716 | 88145 | mask &= ~(SQLITE_ForeignKeys); |
| 87717 | 88146 | } |
| 87718 | 88147 | |
| 87719 | - if( getBoolean(zRight) ){ | |
| 88148 | + if( sqlite3GetBoolean(zRight) ){ | |
| 87720 | 88149 | db->flags |= mask; |
| 87721 | 88150 | }else{ |
| 87722 | 88151 | db->flags &= ~mask; |
| 87723 | 88152 | } |
| 87724 | 88153 | |
| @@ -87928,11 +88357,11 @@ | ||
| 87928 | 88357 | if( sqlite3StrICmp(zLeft,"secure_delete")==0 ){ |
| 87929 | 88358 | Btree *pBt = pDb->pBt; |
| 87930 | 88359 | int b = -1; |
| 87931 | 88360 | assert( pBt!=0 ); |
| 87932 | 88361 | if( zRight ){ |
| 87933 | - b = getBoolean(zRight); | |
| 88362 | + b = sqlite3GetBoolean(zRight); | |
| 87934 | 88363 | } |
| 87935 | 88364 | if( pId2->n==0 && b>=0 ){ |
| 87936 | 88365 | int ii; |
| 87937 | 88366 | for(ii=0; ii<db->nDb; ii++){ |
| 87938 | 88367 | sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b); |
| @@ -88528,11 +88957,11 @@ | ||
| 88528 | 88957 | #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */ |
| 88529 | 88958 | |
| 88530 | 88959 | #ifndef NDEBUG |
| 88531 | 88960 | if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){ |
| 88532 | 88961 | if( zRight ){ |
| 88533 | - if( getBoolean(zRight) ){ | |
| 88962 | + if( sqlite3GetBoolean(zRight) ){ | |
| 88534 | 88963 | sqlite3ParserTrace(stderr, "parser: "); |
| 88535 | 88964 | }else{ |
| 88536 | 88965 | sqlite3ParserTrace(0, 0); |
| 88537 | 88966 | } |
| 88538 | 88967 | } |
| @@ -88542,11 +88971,11 @@ | ||
| 88542 | 88971 | /* Reinstall the LIKE and GLOB functions. The variant of LIKE |
| 88543 | 88972 | ** used will be case sensitive or not depending on the RHS. |
| 88544 | 88973 | */ |
| 88545 | 88974 | if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){ |
| 88546 | 88975 | if( zRight ){ |
| 88547 | - sqlite3RegisterLikeFunctions(db, getBoolean(zRight)); | |
| 88976 | + sqlite3RegisterLikeFunctions(db, sqlite3GetBoolean(zRight)); | |
| 88548 | 88977 | } |
| 88549 | 88978 | }else |
| 88550 | 88979 | |
| 88551 | 88980 | #ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX |
| 88552 | 88981 | # define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100 |
| @@ -95683,11 +96112,12 @@ | ||
| 95683 | 96112 | SrcList *pSrc, /* The virtual table to be modified */ |
| 95684 | 96113 | Table *pTab, /* The virtual table */ |
| 95685 | 96114 | ExprList *pChanges, /* The columns to change in the UPDATE statement */ |
| 95686 | 96115 | Expr *pRowidExpr, /* Expression used to recompute the rowid */ |
| 95687 | 96116 | int *aXRef, /* Mapping from columns of pTab to entries in pChanges */ |
| 95688 | - Expr *pWhere /* WHERE clause of the UPDATE statement */ | |
| 96117 | + Expr *pWhere, /* WHERE clause of the UPDATE statement */ | |
| 96118 | + int onError /* ON CONFLICT strategy */ | |
| 95689 | 96119 | ); |
| 95690 | 96120 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 95691 | 96121 | |
| 95692 | 96122 | /* |
| 95693 | 96123 | ** The most recently coded instruction was an OP_Column to retrieve the |
| @@ -95927,11 +96357,11 @@ | ||
| 95927 | 96357 | |
| 95928 | 96358 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 95929 | 96359 | /* Virtual tables must be handled separately */ |
| 95930 | 96360 | if( IsVirtual(pTab) ){ |
| 95931 | 96361 | updateVirtualTable(pParse, pTabList, pTab, pChanges, pRowidExpr, aXRef, |
| 95932 | - pWhere); | |
| 96362 | + pWhere, onError); | |
| 95933 | 96363 | pWhere = 0; |
| 95934 | 96364 | pTabList = 0; |
| 95935 | 96365 | goto update_cleanup; |
| 95936 | 96366 | } |
| 95937 | 96367 | #endif |
| @@ -96257,11 +96687,12 @@ | ||
| 96257 | 96687 | SrcList *pSrc, /* The virtual table to be modified */ |
| 96258 | 96688 | Table *pTab, /* The virtual table */ |
| 96259 | 96689 | ExprList *pChanges, /* The columns to change in the UPDATE statement */ |
| 96260 | 96690 | Expr *pRowid, /* Expression used to recompute the rowid */ |
| 96261 | 96691 | int *aXRef, /* Mapping from columns of pTab to entries in pChanges */ |
| 96262 | - Expr *pWhere /* WHERE clause of the UPDATE statement */ | |
| 96692 | + Expr *pWhere, /* WHERE clause of the UPDATE statement */ | |
| 96693 | + int onError /* ON CONFLICT strategy */ | |
| 96263 | 96694 | ){ |
| 96264 | 96695 | Vdbe *v = pParse->pVdbe; /* Virtual machine under construction */ |
| 96265 | 96696 | ExprList *pEList = 0; /* The result set of the SELECT statement */ |
| 96266 | 96697 | Select *pSelect = 0; /* The SELECT statement */ |
| 96267 | 96698 | Expr *pExpr; /* Temporary expression */ |
| @@ -96314,10 +96745,11 @@ | ||
| 96314 | 96745 | for(i=0; i<pTab->nCol; i++){ |
| 96315 | 96746 | sqlite3VdbeAddOp3(v, OP_Column, ephemTab, i+1+(pRowid!=0), iReg+2+i); |
| 96316 | 96747 | } |
| 96317 | 96748 | sqlite3VtabMakeWritable(pParse, pTab); |
| 96318 | 96749 | sqlite3VdbeAddOp4(v, OP_VUpdate, 0, pTab->nCol+2, iReg, pVTab, P4_VTAB); |
| 96750 | + sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError); | |
| 96319 | 96751 | sqlite3MayAbort(pParse); |
| 96320 | 96752 | sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1); |
| 96321 | 96753 | sqlite3VdbeJumpHere(v, addr); |
| 96322 | 96754 | sqlite3VdbeAddOp2(v, OP_Close, ephemTab, 0); |
| 96323 | 96755 | |
| @@ -96687,10 +97119,22 @@ | ||
| 96687 | 97119 | ************************************************************************* |
| 96688 | 97120 | ** This file contains code used to help implement virtual tables. |
| 96689 | 97121 | */ |
| 96690 | 97122 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 96691 | 97123 | |
| 97124 | +/* | |
| 97125 | +** Before a virtual table xCreate() or xConnect() method is invoked, the | |
| 97126 | +** sqlite3.pVtabCtx member variable is set to point to an instance of | |
| 97127 | +** this struct allocated on the stack. It is used by the implementation of | |
| 97128 | +** the sqlite3_declare_vtab() and sqlite3_vtab_config() APIs, both of which | |
| 97129 | +** are invoked only from within xCreate and xConnect methods. | |
| 97130 | +*/ | |
| 97131 | +struct VtabCtx { | |
| 97132 | + Table *pTab; | |
| 97133 | + VTable *pVTable; | |
| 97134 | +}; | |
| 97135 | + | |
| 96692 | 97136 | /* |
| 96693 | 97137 | ** The actual function that does the work of creating a new module. |
| 96694 | 97138 | ** This function implements the sqlite3_create_module() and |
| 96695 | 97139 | ** sqlite3_create_module_v2() interfaces. |
| 96696 | 97140 | */ |
| @@ -96715,17 +97159,17 @@ | ||
| 96715 | 97159 | pMod->pModule = pModule; |
| 96716 | 97160 | pMod->pAux = pAux; |
| 96717 | 97161 | pMod->xDestroy = xDestroy; |
| 96718 | 97162 | pDel = (Module *)sqlite3HashInsert(&db->aModule, zCopy, nName, (void*)pMod); |
| 96719 | 97163 | if( pDel && pDel->xDestroy ){ |
| 97164 | + sqlite3ResetInternalSchema(db, -1); | |
| 96720 | 97165 | pDel->xDestroy(pDel->pAux); |
| 96721 | 97166 | } |
| 96722 | 97167 | sqlite3DbFree(db, pDel); |
| 96723 | 97168 | if( pDel==pMod ){ |
| 96724 | 97169 | db->mallocFailed = 1; |
| 96725 | 97170 | } |
| 96726 | - sqlite3ResetInternalSchema(db, -1); | |
| 96727 | 97171 | }else if( xDestroy ){ |
| 96728 | 97172 | xDestroy(pAux); |
| 96729 | 97173 | } |
| 96730 | 97174 | rc = sqlite3ApiExit(db, SQLITE_OK); |
| 96731 | 97175 | sqlite3_mutex_leave(db->mutex); |
| @@ -97107,10 +97551,11 @@ | ||
| 97107 | 97551 | Table *pTab, |
| 97108 | 97552 | Module *pMod, |
| 97109 | 97553 | int (*xConstruct)(sqlite3*,void*,int,const char*const*,sqlite3_vtab**,char**), |
| 97110 | 97554 | char **pzErr |
| 97111 | 97555 | ){ |
| 97556 | + VtabCtx sCtx; | |
| 97112 | 97557 | VTable *pVTable; |
| 97113 | 97558 | int rc; |
| 97114 | 97559 | const char *const*azArg = (const char *const*)pTab->azModuleArg; |
| 97115 | 97560 | int nArg = pTab->nModuleArg; |
| 97116 | 97561 | char *zErr = 0; |
| @@ -97126,16 +97571,18 @@ | ||
| 97126 | 97571 | return SQLITE_NOMEM; |
| 97127 | 97572 | } |
| 97128 | 97573 | pVTable->db = db; |
| 97129 | 97574 | pVTable->pMod = pMod; |
| 97130 | 97575 | |
| 97131 | - assert( !db->pVTab ); | |
| 97576 | + /* Invoke the virtual table constructor */ | |
| 97577 | + assert( &db->pVtabCtx ); | |
| 97132 | 97578 | assert( xConstruct ); |
| 97133 | - db->pVTab = pTab; | |
| 97134 | - | |
| 97135 | - /* Invoke the virtual table constructor */ | |
| 97579 | + sCtx.pTab = pTab; | |
| 97580 | + sCtx.pVTable = pVTable; | |
| 97581 | + db->pVtabCtx = &sCtx; | |
| 97136 | 97582 | rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr); |
| 97583 | + db->pVtabCtx = 0; | |
| 97137 | 97584 | if( rc==SQLITE_NOMEM ) db->mallocFailed = 1; |
| 97138 | 97585 | |
| 97139 | 97586 | if( SQLITE_OK!=rc ){ |
| 97140 | 97587 | if( zErr==0 ){ |
| 97141 | 97588 | *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName); |
| @@ -97147,11 +97594,11 @@ | ||
| 97147 | 97594 | }else if( ALWAYS(pVTable->pVtab) ){ |
| 97148 | 97595 | /* Justification of ALWAYS(): A correct vtab constructor must allocate |
| 97149 | 97596 | ** the sqlite3_vtab object if successful. */ |
| 97150 | 97597 | pVTable->pVtab->pModule = pMod->pModule; |
| 97151 | 97598 | pVTable->nRef = 1; |
| 97152 | - if( db->pVTab ){ | |
| 97599 | + if( sCtx.pTab ){ | |
| 97153 | 97600 | const char *zFormat = "vtable constructor did not declare schema: %s"; |
| 97154 | 97601 | *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName); |
| 97155 | 97602 | sqlite3VtabUnlock(pVTable); |
| 97156 | 97603 | rc = SQLITE_ERROR; |
| 97157 | 97604 | }else{ |
| @@ -97195,11 +97642,10 @@ | ||
| 97195 | 97642 | } |
| 97196 | 97643 | } |
| 97197 | 97644 | } |
| 97198 | 97645 | |
| 97199 | 97646 | sqlite3DbFree(db, zModuleName); |
| 97200 | - db->pVTab = 0; | |
| 97201 | 97647 | return rc; |
| 97202 | 97648 | } |
| 97203 | 97649 | |
| 97204 | 97650 | /* |
| 97205 | 97651 | ** This function is invoked by the parser to call the xConnect() method |
| @@ -97315,12 +97761,11 @@ | ||
| 97315 | 97761 | int rc = SQLITE_OK; |
| 97316 | 97762 | Table *pTab; |
| 97317 | 97763 | char *zErr = 0; |
| 97318 | 97764 | |
| 97319 | 97765 | sqlite3_mutex_enter(db->mutex); |
| 97320 | - pTab = db->pVTab; | |
| 97321 | - if( !pTab ){ | |
| 97766 | + if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){ | |
| 97322 | 97767 | sqlite3Error(db, SQLITE_MISUSE, 0); |
| 97323 | 97768 | sqlite3_mutex_leave(db->mutex); |
| 97324 | 97769 | return SQLITE_MISUSE_BKPT; |
| 97325 | 97770 | } |
| 97326 | 97771 | assert( (pTab->tabFlags & TF_Virtual)!=0 ); |
| @@ -97343,11 +97788,11 @@ | ||
| 97343 | 97788 | pTab->aCol = pParse->pNewTable->aCol; |
| 97344 | 97789 | pTab->nCol = pParse->pNewTable->nCol; |
| 97345 | 97790 | pParse->pNewTable->nCol = 0; |
| 97346 | 97791 | pParse->pNewTable->aCol = 0; |
| 97347 | 97792 | } |
| 97348 | - db->pVTab = 0; | |
| 97793 | + db->pVtabCtx->pTab = 0; | |
| 97349 | 97794 | }else{ |
| 97350 | 97795 | sqlite3Error(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr); |
| 97351 | 97796 | sqlite3DbFree(db, zErr); |
| 97352 | 97797 | rc = SQLITE_ERROR; |
| 97353 | 97798 | } |
| @@ -97495,11 +97940,10 @@ | ||
| 97495 | 97940 | pModule = pVTab->pVtab->pModule; |
| 97496 | 97941 | |
| 97497 | 97942 | if( pModule->xBegin ){ |
| 97498 | 97943 | int i; |
| 97499 | 97944 | |
| 97500 | - | |
| 97501 | 97945 | /* If pVtab is already in the aVTrans array, return early */ |
| 97502 | 97946 | for(i=0; i<db->nVTrans; i++){ |
| 97503 | 97947 | if( db->aVTrans[i]==pVTab ){ |
| 97504 | 97948 | return SQLITE_OK; |
| 97505 | 97949 | } |
| @@ -97508,10 +97952,53 @@ | ||
| 97508 | 97952 | /* Invoke the xBegin method */ |
| 97509 | 97953 | rc = pModule->xBegin(pVTab->pVtab); |
| 97510 | 97954 | if( rc==SQLITE_OK ){ |
| 97511 | 97955 | rc = addToVTrans(db, pVTab); |
| 97512 | 97956 | } |
| 97957 | + } | |
| 97958 | + return rc; | |
| 97959 | +} | |
| 97960 | + | |
| 97961 | +/* | |
| 97962 | +** Invoke either the xSavepoint, xRollbackTo or xRelease method of all | |
| 97963 | +** virtual tables that currently have an open transaction. Pass iSavepoint | |
| 97964 | +** as the second argument to the virtual table method invoked. | |
| 97965 | +** | |
| 97966 | +** If op is SAVEPOINT_BEGIN, the xSavepoint method is invoked. If it is | |
| 97967 | +** SAVEPOINT_ROLLBACK, the xRollbackTo method. Otherwise, if op is | |
| 97968 | +** SAVEPOINT_RELEASE, then the xRelease method of each virtual table with | |
| 97969 | +** an open transaction is invoked. | |
| 97970 | +** | |
| 97971 | +** If any virtual table method returns an error code other than SQLITE_OK, | |
| 97972 | +** processing is abandoned and the error returned to the caller of this | |
| 97973 | +** function immediately. If all calls to virtual table methods are successful, | |
| 97974 | +** SQLITE_OK is returned. | |
| 97975 | +*/ | |
| 97976 | +SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){ | |
| 97977 | + int rc = SQLITE_OK; | |
| 97978 | + | |
| 97979 | + assert( op==SAVEPOINT_RELEASE||op==SAVEPOINT_ROLLBACK||op==SAVEPOINT_BEGIN ); | |
| 97980 | + if( db->aVTrans ){ | |
| 97981 | + int i; | |
| 97982 | + for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){ | |
| 97983 | + const sqlite3_module *pMod = db->aVTrans[i]->pMod->pModule; | |
| 97984 | + if( pMod->iVersion>=2 ){ | |
| 97985 | + int (*xMethod)(sqlite3_vtab *, int); | |
| 97986 | + switch( op ){ | |
| 97987 | + case SAVEPOINT_BEGIN: | |
| 97988 | + xMethod = pMod->xSavepoint; | |
| 97989 | + break; | |
| 97990 | + case SAVEPOINT_ROLLBACK: | |
| 97991 | + xMethod = pMod->xRollbackTo; | |
| 97992 | + break; | |
| 97993 | + default: | |
| 97994 | + xMethod = pMod->xRelease; | |
| 97995 | + break; | |
| 97996 | + } | |
| 97997 | + if( xMethod ) rc = xMethod(db->aVTrans[i]->pVtab, iSavepoint); | |
| 97998 | + } | |
| 97999 | + } | |
| 97513 | 98000 | } |
| 97514 | 98001 | return rc; |
| 97515 | 98002 | } |
| 97516 | 98003 | |
| 97517 | 98004 | /* |
| @@ -97609,10 +98096,61 @@ | ||
| 97609 | 98096 | pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab; |
| 97610 | 98097 | }else{ |
| 97611 | 98098 | pToplevel->db->mallocFailed = 1; |
| 97612 | 98099 | } |
| 97613 | 98100 | } |
| 98101 | + | |
| 98102 | +/* | |
| 98103 | +** Return the ON CONFLICT resolution mode in effect for the virtual | |
| 98104 | +** table update operation currently in progress. | |
| 98105 | +** | |
| 98106 | +** The results of this routine are undefined unless it is called from | |
| 98107 | +** within an xUpdate method. | |
| 98108 | +*/ | |
| 98109 | +SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *db){ | |
| 98110 | + static const unsigned char aMap[] = { | |
| 98111 | + SQLITE_ROLLBACK, SQLITE_ABORT, SQLITE_FAIL, SQLITE_IGNORE, SQLITE_REPLACE | |
| 98112 | + }; | |
| 98113 | + assert( OE_Rollback==1 && OE_Abort==2 && OE_Fail==3 ); | |
| 98114 | + assert( OE_Ignore==4 && OE_Replace==5 ); | |
| 98115 | + assert( db->vtabOnConflict>=1 && db->vtabOnConflict<=5 ); | |
| 98116 | + return (int)aMap[db->vtabOnConflict-1]; | |
| 98117 | +} | |
| 98118 | + | |
| 98119 | +/* | |
| 98120 | +** Call from within the xCreate() or xConnect() methods to provide | |
| 98121 | +** the SQLite core with additional information about the behavior | |
| 98122 | +** of the virtual table being implemented. | |
| 98123 | +*/ | |
| 98124 | +SQLITE_API int sqlite3_vtab_config(sqlite3 *db, int op, ...){ | |
| 98125 | + va_list ap; | |
| 98126 | + int rc = SQLITE_OK; | |
| 98127 | + | |
| 98128 | + sqlite3_mutex_enter(db->mutex); | |
| 98129 | + | |
| 98130 | + va_start(ap, op); | |
| 98131 | + switch( op ){ | |
| 98132 | + case SQLITE_VTAB_CONSTRAINT_SUPPORT: { | |
| 98133 | + VtabCtx *p = db->pVtabCtx; | |
| 98134 | + if( !p ){ | |
| 98135 | + rc = SQLITE_MISUSE_BKPT; | |
| 98136 | + }else{ | |
| 98137 | + assert( p->pTab==0 || (p->pTab->tabFlags & TF_Virtual)!=0 ); | |
| 98138 | + p->pVTable->bConstraint = (u8)va_arg(ap, int); | |
| 98139 | + } | |
| 98140 | + break; | |
| 98141 | + } | |
| 98142 | + default: | |
| 98143 | + rc = SQLITE_MISUSE_BKPT; | |
| 98144 | + break; | |
| 98145 | + } | |
| 98146 | + va_end(ap); | |
| 98147 | + | |
| 98148 | + if( rc!=SQLITE_OK ) sqlite3Error(db, rc, 0); | |
| 98149 | + sqlite3_mutex_leave(db->mutex); | |
| 98150 | + return rc; | |
| 98151 | +} | |
| 97614 | 98152 | |
| 97615 | 98153 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 97616 | 98154 | |
| 97617 | 98155 | /************** End of vtab.c ************************************************/ |
| 97618 | 98156 | /************** Begin file where.c *******************************************/ |
| @@ -107631,10 +108169,15 @@ | ||
| 107631 | 108169 | typedef void(*LOGFUNC_t)(void*,int,const char*); |
| 107632 | 108170 | sqlite3GlobalConfig.xLog = va_arg(ap, LOGFUNC_t); |
| 107633 | 108171 | sqlite3GlobalConfig.pLogArg = va_arg(ap, void*); |
| 107634 | 108172 | break; |
| 107635 | 108173 | } |
| 108174 | + | |
| 108175 | + case SQLITE_CONFIG_URI: { | |
| 108176 | + sqlite3GlobalConfig.bOpenUri = va_arg(ap, int); | |
| 108177 | + break; | |
| 108178 | + } | |
| 107636 | 108179 | |
| 107637 | 108180 | default: { |
| 107638 | 108181 | rc = SQLITE_ERROR; |
| 107639 | 108182 | break; |
| 107640 | 108183 | } |
| @@ -108990,25 +109533,257 @@ | ||
| 108990 | 109533 | } |
| 108991 | 109534 | db->aLimit[limitId] = newLimit; |
| 108992 | 109535 | } |
| 108993 | 109536 | return oldLimit; /* IMP: R-53341-35419 */ |
| 108994 | 109537 | } |
| 109538 | + | |
| 109539 | +/* | |
| 109540 | +** This function is used to parse both URIs and non-URI filenames passed by the | |
| 109541 | +** user to API functions sqlite3_open() or sqlite3_open_v2(), and for database | |
| 109542 | +** URIs specified as part of ATTACH statements. | |
| 109543 | +** | |
| 109544 | +** The first argument to this function is the name of the VFS to use (or | |
| 109545 | +** a NULL to signify the default VFS) if the URI does not contain a "vfs=xxx" | |
| 109546 | +** query parameter. The second argument contains the URI (or non-URI filename) | |
| 109547 | +** itself. When this function is called the *pFlags variable should contain | |
| 109548 | +** the default flags to open the database handle with. The value stored in | |
| 109549 | +** *pFlags may be updated before returning if the URI filename contains | |
| 109550 | +** "cache=xxx" or "mode=xxx" query parameters. | |
| 109551 | +** | |
| 109552 | +** If successful, SQLITE_OK is returned. In this case *ppVfs is set to point to | |
| 109553 | +** the VFS that should be used to open the database file. *pzFile is set to | |
| 109554 | +** point to a buffer containing the name of the file to open. It is the | |
| 109555 | +** responsibility of the caller to eventually call sqlite3_free() to release | |
| 109556 | +** this buffer. | |
| 109557 | +** | |
| 109558 | +** If an error occurs, then an SQLite error code is returned and *pzErrMsg | |
| 109559 | +** may be set to point to a buffer containing an English language error | |
| 109560 | +** message. It is the responsibility of the caller to eventually release | |
| 109561 | +** this buffer by calling sqlite3_free(). | |
| 109562 | +*/ | |
| 109563 | +SQLITE_PRIVATE int sqlite3ParseUri( | |
| 109564 | + const char *zDefaultVfs, /* VFS to use if no "vfs=xxx" query option */ | |
| 109565 | + const char *zUri, /* Nul-terminated URI to parse */ | |
| 109566 | + unsigned int *pFlags, /* IN/OUT: SQLITE_OPEN_XXX flags */ | |
| 109567 | + sqlite3_vfs **ppVfs, /* OUT: VFS to use */ | |
| 109568 | + char **pzFile, /* OUT: Filename component of URI */ | |
| 109569 | + char **pzErrMsg /* OUT: Error message (if rc!=SQLITE_OK) */ | |
| 109570 | +){ | |
| 109571 | + int rc = SQLITE_OK; | |
| 109572 | + unsigned int flags = *pFlags; | |
| 109573 | + const char *zVfs = zDefaultVfs; | |
| 109574 | + char *zFile; | |
| 109575 | + char c; | |
| 109576 | + int nUri = sqlite3Strlen30(zUri); | |
| 109577 | + | |
| 109578 | + assert( *pzErrMsg==0 ); | |
| 109579 | + | |
| 109580 | + if( ((flags & SQLITE_OPEN_URI) || sqlite3GlobalConfig.bOpenUri) | |
| 109581 | + && nUri>=5 && memcmp(zUri, "file:", 5)==0 | |
| 109582 | + ){ | |
| 109583 | + char *zOpt; | |
| 109584 | + int eState; /* Parser state when parsing URI */ | |
| 109585 | + int iIn; /* Input character index */ | |
| 109586 | + int iOut = 0; /* Output character index */ | |
| 109587 | + int nByte = nUri+2; /* Bytes of space to allocate */ | |
| 109588 | + | |
| 109589 | + /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen | |
| 109590 | + ** method that there may be extra parameters following the file-name. */ | |
| 109591 | + flags |= SQLITE_OPEN_URI; | |
| 109592 | + | |
| 109593 | + for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&'); | |
| 109594 | + zFile = sqlite3_malloc(nByte); | |
| 109595 | + if( !zFile ) return SQLITE_NOMEM; | |
| 109596 | + | |
| 109597 | + /* Discard the scheme and authority segments of the URI. */ | |
| 109598 | + if( zUri[5]=='/' && zUri[6]=='/' ){ | |
| 109599 | + iIn = 7; | |
| 109600 | + while( zUri[iIn] && zUri[iIn]!='/' ) iIn++; | |
| 109601 | + | |
| 109602 | + if( iIn!=7 && (iIn!=16 || memcmp("localhost", &zUri[7], 9)) ){ | |
| 109603 | + *pzErrMsg = sqlite3_mprintf("invalid uri authority: %.*s", | |
| 109604 | + iIn-7, &zUri[7]); | |
| 109605 | + rc = SQLITE_ERROR; | |
| 109606 | + goto parse_uri_out; | |
| 109607 | + } | |
| 109608 | + }else{ | |
| 109609 | + iIn = 5; | |
| 109610 | + } | |
| 109611 | + | |
| 109612 | + /* Copy the filename and any query parameters into the zFile buffer. | |
| 109613 | + ** Decode %HH escape codes along the way. | |
| 109614 | + ** | |
| 109615 | + ** Within this loop, variable eState may be set to 0, 1 or 2, depending | |
| 109616 | + ** on the parsing context. As follows: | |
| 109617 | + ** | |
| 109618 | + ** 0: Parsing file-name. | |
| 109619 | + ** 1: Parsing name section of a name=value query parameter. | |
| 109620 | + ** 2: Parsing value section of a name=value query parameter. | |
| 109621 | + */ | |
| 109622 | + eState = 0; | |
| 109623 | + while( (c = zUri[iIn])!=0 && c!='#' ){ | |
| 109624 | + iIn++; | |
| 109625 | + if( c=='%' | |
| 109626 | + && sqlite3Isxdigit(zUri[iIn]) | |
| 109627 | + && sqlite3Isxdigit(zUri[iIn+1]) | |
| 109628 | + ){ | |
| 109629 | + int octet = (sqlite3HexToInt(zUri[iIn++]) << 4); | |
| 109630 | + octet += sqlite3HexToInt(zUri[iIn++]); | |
| 109631 | + | |
| 109632 | + assert( octet>=0 && octet<256 ); | |
| 109633 | + if( octet==0 ){ | |
| 109634 | + /* This branch is taken when "%00" appears within the URI. In this | |
| 109635 | + ** case we ignore all text in the remainder of the path, name or | |
| 109636 | + ** value currently being parsed. So ignore the current character | |
| 109637 | + ** and skip to the next "?", "=" or "&", as appropriate. */ | |
| 109638 | + while( (c = zUri[iIn])!=0 && c!='#' | |
| 109639 | + && (eState!=0 || c!='?') | |
| 109640 | + && (eState!=1 || (c!='=' && c!='&')) | |
| 109641 | + && (eState!=2 || c!='&') | |
| 109642 | + ){ | |
| 109643 | + iIn++; | |
| 109644 | + } | |
| 109645 | + continue; | |
| 109646 | + } | |
| 109647 | + c = octet; | |
| 109648 | + }else if( eState==1 && (c=='&' || c=='=') ){ | |
| 109649 | + if( zFile[iOut-1]==0 ){ | |
| 109650 | + /* An empty option name. Ignore this option altogether. */ | |
| 109651 | + while( zUri[iIn] && zUri[iIn]!='#' && zUri[iIn-1]!='&' ) iIn++; | |
| 109652 | + continue; | |
| 109653 | + } | |
| 109654 | + if( c=='&' ){ | |
| 109655 | + zFile[iOut++] = '\0'; | |
| 109656 | + }else{ | |
| 109657 | + eState = 2; | |
| 109658 | + } | |
| 109659 | + c = 0; | |
| 109660 | + }else if( (eState==0 && c=='?') || (eState==2 && c=='&') ){ | |
| 109661 | + c = 0; | |
| 109662 | + eState = 1; | |
| 109663 | + } | |
| 109664 | + zFile[iOut++] = c; | |
| 109665 | + } | |
| 109666 | + if( eState==1 ) zFile[iOut++] = '\0'; | |
| 109667 | + zFile[iOut++] = '\0'; | |
| 109668 | + zFile[iOut++] = '\0'; | |
| 109669 | + | |
| 109670 | + /* Check if there were any options specified that should be interpreted | |
| 109671 | + ** here. Options that are interpreted here include "vfs" and those that | |
| 109672 | + ** correspond to flags that may be passed to the sqlite3_open_v2() | |
| 109673 | + ** method. */ | |
| 109674 | + zOpt = &zFile[sqlite3Strlen30(zFile)+1]; | |
| 109675 | + while( zOpt[0] ){ | |
| 109676 | + int nOpt = sqlite3Strlen30(zOpt); | |
| 109677 | + char *zVal = &zOpt[nOpt+1]; | |
| 109678 | + int nVal = sqlite3Strlen30(zVal); | |
| 109679 | + | |
| 109680 | + if( nOpt==3 && memcmp("vfs", zOpt, 3)==0 ){ | |
| 109681 | + zVfs = zVal; | |
| 109682 | + }else{ | |
| 109683 | + struct OpenMode { | |
| 109684 | + const char *z; | |
| 109685 | + int mode; | |
| 109686 | + } *aMode = 0; | |
| 109687 | + char *zModeType; | |
| 109688 | + int mask; | |
| 109689 | + int limit; | |
| 109690 | + | |
| 109691 | + if( nOpt==5 && memcmp("cache", zOpt, 5)==0 ){ | |
| 109692 | + static struct OpenMode aCacheMode[] = { | |
| 109693 | + { "shared", SQLITE_OPEN_SHAREDCACHE }, | |
| 109694 | + { "private", SQLITE_OPEN_PRIVATECACHE }, | |
| 109695 | + { 0, 0 } | |
| 109696 | + }; | |
| 109697 | + | |
| 109698 | + mask = SQLITE_OPEN_SHAREDCACHE|SQLITE_OPEN_PRIVATECACHE; | |
| 109699 | + aMode = aCacheMode; | |
| 109700 | + limit = mask; | |
| 109701 | + zModeType = "cache"; | |
| 109702 | + } | |
| 109703 | + if( nOpt==4 && memcmp("mode", zOpt, 4)==0 ){ | |
| 109704 | + static struct OpenMode aOpenMode[] = { | |
| 109705 | + { "ro", SQLITE_OPEN_READONLY }, | |
| 109706 | + { "rw", SQLITE_OPEN_READWRITE }, | |
| 109707 | + { "rwc", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE }, | |
| 109708 | + { 0, 0 } | |
| 109709 | + }; | |
| 109710 | + | |
| 109711 | + mask = SQLITE_OPEN_READONLY|SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE; | |
| 109712 | + aMode = aOpenMode; | |
| 109713 | + limit = mask & flags; | |
| 109714 | + zModeType = "access"; | |
| 109715 | + } | |
| 109716 | + | |
| 109717 | + if( aMode ){ | |
| 109718 | + int i; | |
| 109719 | + int mode = 0; | |
| 109720 | + for(i=0; aMode[i].z; i++){ | |
| 109721 | + const char *z = aMode[i].z; | |
| 109722 | + if( nVal==sqlite3Strlen30(z) && 0==memcmp(zVal, z, nVal) ){ | |
| 109723 | + mode = aMode[i].mode; | |
| 109724 | + break; | |
| 109725 | + } | |
| 109726 | + } | |
| 109727 | + if( mode==0 ){ | |
| 109728 | + *pzErrMsg = sqlite3_mprintf("no such %s mode: %s", zModeType, zVal); | |
| 109729 | + rc = SQLITE_ERROR; | |
| 109730 | + goto parse_uri_out; | |
| 109731 | + } | |
| 109732 | + if( mode>limit ){ | |
| 109733 | + *pzErrMsg = sqlite3_mprintf("%s mode not allowed: %s", | |
| 109734 | + zModeType, zVal); | |
| 109735 | + rc = SQLITE_PERM; | |
| 109736 | + goto parse_uri_out; | |
| 109737 | + } | |
| 109738 | + flags = (flags & ~mask) | mode; | |
| 109739 | + } | |
| 109740 | + } | |
| 109741 | + | |
| 109742 | + zOpt = &zVal[nVal+1]; | |
| 109743 | + } | |
| 109744 | + | |
| 109745 | + }else{ | |
| 109746 | + zFile = sqlite3_malloc(nUri+2); | |
| 109747 | + if( !zFile ) return SQLITE_NOMEM; | |
| 109748 | + memcpy(zFile, zUri, nUri); | |
| 109749 | + zFile[nUri] = '\0'; | |
| 109750 | + zFile[nUri+1] = '\0'; | |
| 109751 | + } | |
| 109752 | + | |
| 109753 | + *ppVfs = sqlite3_vfs_find(zVfs); | |
| 109754 | + if( *ppVfs==0 ){ | |
| 109755 | + *pzErrMsg = sqlite3_mprintf("no such vfs: %s", zVfs); | |
| 109756 | + rc = SQLITE_ERROR; | |
| 109757 | + } | |
| 109758 | + parse_uri_out: | |
| 109759 | + if( rc!=SQLITE_OK ){ | |
| 109760 | + sqlite3_free(zFile); | |
| 109761 | + zFile = 0; | |
| 109762 | + } | |
| 109763 | + *pFlags = flags; | |
| 109764 | + *pzFile = zFile; | |
| 109765 | + return rc; | |
| 109766 | +} | |
| 109767 | + | |
| 108995 | 109768 | |
| 108996 | 109769 | /* |
| 108997 | 109770 | ** This routine does the work of opening a database on behalf of |
| 108998 | 109771 | ** sqlite3_open() and sqlite3_open16(). The database filename "zFilename" |
| 108999 | 109772 | ** is UTF-8 encoded. |
| 109000 | 109773 | */ |
| 109001 | 109774 | static int openDatabase( |
| 109002 | 109775 | const char *zFilename, /* Database filename UTF-8 encoded */ |
| 109003 | 109776 | sqlite3 **ppDb, /* OUT: Returned database handle */ |
| 109004 | - unsigned flags, /* Operational flags */ | |
| 109777 | + unsigned int flags, /* Operational flags */ | |
| 109005 | 109778 | const char *zVfs /* Name of the VFS to use */ |
| 109006 | 109779 | ){ |
| 109007 | - sqlite3 *db; | |
| 109008 | - int rc; | |
| 109009 | - int isThreadsafe; | |
| 109780 | + sqlite3 *db; /* Store allocated handle here */ | |
| 109781 | + int rc; /* Return code */ | |
| 109782 | + int isThreadsafe; /* True for threadsafe connections */ | |
| 109783 | + char *zOpen = 0; /* Filename argument to pass to BtreeOpen() */ | |
| 109784 | + char *zErrMsg = 0; /* Error message from sqlite3ParseUri() */ | |
| 109010 | 109785 | |
| 109011 | 109786 | *ppDb = 0; |
| 109012 | 109787 | #ifndef SQLITE_OMIT_AUTOINIT |
| 109013 | 109788 | rc = sqlite3_initialize(); |
| 109014 | 109789 | if( rc ) return rc; |
| @@ -109028,11 +109803,11 @@ | ||
| 109028 | 109803 | assert( SQLITE_OPEN_READWRITE == 0x02 ); |
| 109029 | 109804 | assert( SQLITE_OPEN_CREATE == 0x04 ); |
| 109030 | 109805 | testcase( (1<<(flags&7))==0x02 ); /* READONLY */ |
| 109031 | 109806 | testcase( (1<<(flags&7))==0x04 ); /* READWRITE */ |
| 109032 | 109807 | testcase( (1<<(flags&7))==0x40 ); /* READWRITE | CREATE */ |
| 109033 | - if( ((1<<(flags&7)) & 0x46)==0 ) return SQLITE_MISUSE; | |
| 109808 | + if( ((1<<(flags&7)) & 0x46)==0 ) return SQLITE_MISUSE_BKPT; | |
| 109034 | 109809 | |
| 109035 | 109810 | if( sqlite3GlobalConfig.bCoreMutex==0 ){ |
| 109036 | 109811 | isThreadsafe = 0; |
| 109037 | 109812 | }else if( flags & SQLITE_OPEN_NOMUTEX ){ |
| 109038 | 109813 | isThreadsafe = 0; |
| @@ -109109,17 +109884,10 @@ | ||
| 109109 | 109884 | sqlite3HashInit(&db->aCollSeq); |
| 109110 | 109885 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 109111 | 109886 | sqlite3HashInit(&db->aModule); |
| 109112 | 109887 | #endif |
| 109113 | 109888 | |
| 109114 | - db->pVfs = sqlite3_vfs_find(zVfs); | |
| 109115 | - if( !db->pVfs ){ | |
| 109116 | - rc = SQLITE_ERROR; | |
| 109117 | - sqlite3Error(db, rc, "no such vfs: %s", zVfs); | |
| 109118 | - goto opendb_out; | |
| 109119 | - } | |
| 109120 | - | |
| 109121 | 109889 | /* Add the default collation sequence BINARY. BINARY works for both UTF-8 |
| 109122 | 109890 | ** and UTF-16, so add a version for each to avoid any unnecessary |
| 109123 | 109891 | ** conversions. The only error that can occur here is a malloc() failure. |
| 109124 | 109892 | */ |
| 109125 | 109893 | createCollation(db, "BINARY", SQLITE_UTF8, SQLITE_COLL_BINARY, 0, |
| @@ -109138,13 +109906,22 @@ | ||
| 109138 | 109906 | |
| 109139 | 109907 | /* Also add a UTF-8 case-insensitive collation sequence. */ |
| 109140 | 109908 | createCollation(db, "NOCASE", SQLITE_UTF8, SQLITE_COLL_NOCASE, 0, |
| 109141 | 109909 | nocaseCollatingFunc, 0); |
| 109142 | 109910 | |
| 109143 | - /* Open the backend database driver */ | |
| 109911 | + /* Parse the filename/URI argument. */ | |
| 109144 | 109912 | db->openFlags = flags; |
| 109145 | - rc = sqlite3BtreeOpen(zFilename, db, &db->aDb[0].pBt, 0, | |
| 109913 | + rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg); | |
| 109914 | + if( rc!=SQLITE_OK ){ | |
| 109915 | + if( rc==SQLITE_NOMEM ) db->mallocFailed = 1; | |
| 109916 | + sqlite3Error(db, rc, zErrMsg ? "%s" : 0, zErrMsg); | |
| 109917 | + sqlite3_free(zErrMsg); | |
| 109918 | + goto opendb_out; | |
| 109919 | + } | |
| 109920 | + | |
| 109921 | + /* Open the backend database driver */ | |
| 109922 | + rc = sqlite3BtreeOpen(db->pVfs, zOpen, db, &db->aDb[0].pBt, 0, | |
| 109146 | 109923 | flags | SQLITE_OPEN_MAIN_DB); |
| 109147 | 109924 | if( rc!=SQLITE_OK ){ |
| 109148 | 109925 | if( rc==SQLITE_IOERR_NOMEM ){ |
| 109149 | 109926 | rc = SQLITE_NOMEM; |
| 109150 | 109927 | } |
| @@ -109233,10 +110010,11 @@ | ||
| 109233 | 110010 | sqlite3GlobalConfig.nLookaside); |
| 109234 | 110011 | |
| 109235 | 110012 | sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT); |
| 109236 | 110013 | |
| 109237 | 110014 | opendb_out: |
| 110015 | + sqlite3_free(zOpen); | |
| 109238 | 110016 | if( db ){ |
| 109239 | 110017 | assert( db->mutex!=0 || isThreadsafe==0 || sqlite3GlobalConfig.bFullMutex==0 ); |
| 109240 | 110018 | sqlite3_mutex_leave(db->mutex); |
| 109241 | 110019 | } |
| 109242 | 110020 | rc = sqlite3_errcode(db); |
| @@ -109264,11 +110042,11 @@ | ||
| 109264 | 110042 | const char *filename, /* Database filename (UTF-8) */ |
| 109265 | 110043 | sqlite3 **ppDb, /* OUT: SQLite db handle */ |
| 109266 | 110044 | int flags, /* Flags */ |
| 109267 | 110045 | const char *zVfs /* Name of VFS module to use */ |
| 109268 | 110046 | ){ |
| 109269 | - return openDatabase(filename, ppDb, flags, zVfs); | |
| 110047 | + return openDatabase(filename, ppDb, (unsigned int)flags, zVfs); | |
| 109270 | 110048 | } |
| 109271 | 110049 | |
| 109272 | 110050 | #ifndef SQLITE_OMIT_UTF16 |
| 109273 | 110051 | /* |
| 109274 | 110052 | ** Open a new database handle. |
| @@ -109874,10 +110652,32 @@ | ||
| 109874 | 110652 | } |
| 109875 | 110653 | va_end(ap); |
| 109876 | 110654 | #endif /* SQLITE_OMIT_BUILTIN_TEST */ |
| 109877 | 110655 | return rc; |
| 109878 | 110656 | } |
| 110657 | + | |
| 110658 | +/* | |
| 110659 | +** This is a utility routine, useful to VFS implementations, that checks | |
| 110660 | +** to see if a database file was a URI that contained a specific query | |
| 110661 | +** parameter, and if so obtains the value of the query parameter. | |
| 110662 | +** | |
| 110663 | +** The zFilename argument is the filename pointer passed into the xOpen() | |
| 110664 | +** method of a VFS implementation. The zParam argument is the name of the | |
| 110665 | +** query parameter we seek. This routine returns the value of the zParam | |
| 110666 | +** parameter if it exists. If the parameter does not exist, this routine | |
| 110667 | +** returns a NULL pointer. | |
| 110668 | +*/ | |
| 110669 | +SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){ | |
| 110670 | + zFilename += sqlite3Strlen30(zFilename) + 1; | |
| 110671 | + while( zFilename[0] ){ | |
| 110672 | + int x = strcmp(zFilename, zParam); | |
| 110673 | + zFilename += sqlite3Strlen30(zFilename) + 1; | |
| 110674 | + if( x==0 ) return zFilename; | |
| 110675 | + zFilename += sqlite3Strlen30(zFilename) + 1; | |
| 110676 | + } | |
| 110677 | + return 0; | |
| 110678 | +} | |
| 109879 | 110679 | |
| 109880 | 110680 | /************** End of main.c ************************************************/ |
| 109881 | 110681 | /************** Begin file notify.c ******************************************/ |
| 109882 | 110682 | /* |
| 109883 | 110683 | ** 2009 March 3 |
| @@ -110955,10 +111755,11 @@ | ||
| 110955 | 111755 | Fts3DeferredToken *pDeferred; /* Deferred search tokens, if any */ |
| 110956 | 111756 | sqlite3_int64 iPrevId; /* Previous id read from aDoclist */ |
| 110957 | 111757 | char *pNextId; /* Pointer into the body of aDoclist */ |
| 110958 | 111758 | char *aDoclist; /* List of docids for full-text queries */ |
| 110959 | 111759 | int nDoclist; /* Size of buffer at aDoclist */ |
| 111760 | + int desc; /* True to sort in descending order */ | |
| 110960 | 111761 | int eEvalmode; /* An FTS3_EVAL_XX constant */ |
| 110961 | 111762 | int nRowAvg; /* Average size of database rows, in pages */ |
| 110962 | 111763 | |
| 110963 | 111764 | int isMatchinfoNeeded; /* True when aMatchinfo[] needs filling in */ |
| 110964 | 111765 | u32 *aMatchinfo; /* Information about most recent match */ |
| @@ -111137,11 +111938,11 @@ | ||
| 111137 | 111938 | SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *); |
| 111138 | 111939 | SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *); |
| 111139 | 111940 | SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64); |
| 111140 | 111941 | SQLITE_PRIVATE void sqlite3Fts3Dequote(char *); |
| 111141 | 111942 | |
| 111142 | -SQLITE_PRIVATE char *sqlite3Fts3FindPositions(Fts3Expr *, sqlite3_int64, int); | |
| 111943 | +SQLITE_PRIVATE char *sqlite3Fts3FindPositions(Fts3Cursor *, Fts3Expr *, sqlite3_int64, int); | |
| 111143 | 111944 | SQLITE_PRIVATE int sqlite3Fts3ExprLoadDoclist(Fts3Cursor *, Fts3Expr *); |
| 111144 | 111945 | SQLITE_PRIVATE int sqlite3Fts3ExprLoadFtDoclist(Fts3Cursor *, Fts3Expr *, char **, int *); |
| 111145 | 111946 | SQLITE_PRIVATE int sqlite3Fts3ExprNearTrim(Fts3Expr *, Fts3Expr *, int); |
| 111146 | 111947 | |
| 111147 | 111948 | /* fts3_tokenizer.c */ |
| @@ -111164,10 +111965,11 @@ | ||
| 111164 | 111965 | char **, int, int, const char *, int, Fts3Expr ** |
| 111165 | 111966 | ); |
| 111166 | 111967 | SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *); |
| 111167 | 111968 | #ifdef SQLITE_TEST |
| 111168 | 111969 | SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db); |
| 111970 | +SQLITE_PRIVATE int sqlite3Fts3InitTerm(sqlite3 *db); | |
| 111169 | 111971 | #endif |
| 111170 | 111972 | |
| 111171 | 111973 | /* fts3_aux.c */ |
| 111172 | 111974 | SQLITE_PRIVATE int sqlite3Fts3InitAux(sqlite3 *db); |
| 111173 | 111975 | |
| @@ -111284,10 +112086,38 @@ | ||
| 111284 | 112086 | static void fts3GetDeltaVarint(char **pp, sqlite3_int64 *pVal){ |
| 111285 | 112087 | sqlite3_int64 iVal; |
| 111286 | 112088 | *pp += sqlite3Fts3GetVarint(*pp, &iVal); |
| 111287 | 112089 | *pVal += iVal; |
| 111288 | 112090 | } |
| 112091 | + | |
| 112092 | +/* | |
| 112093 | +** When this function is called, *pp points to the first byte following a | |
| 112094 | +** varint that is part of a doclist (or position-list, or any other list | |
| 112095 | +** of varints). This function moves *pp to point to the start of that varint, | |
| 112096 | +** and decrements the value stored in *pVal by the varint value. | |
| 112097 | +** | |
| 112098 | +** Argument pStart points to the first byte of the doclist that the | |
| 112099 | +** varint is part of. | |
| 112100 | +*/ | |
| 112101 | +static void fts3GetReverseDeltaVarint( | |
| 112102 | + char **pp, | |
| 112103 | + char *pStart, | |
| 112104 | + sqlite3_int64 *pVal | |
| 112105 | +){ | |
| 112106 | + sqlite3_int64 iVal; | |
| 112107 | + char *p = *pp; | |
| 112108 | + | |
| 112109 | + /* Pointer p now points at the first byte past the varint we are | |
| 112110 | + ** interested in. So, unless the doclist is corrupt, the 0x80 bit is | |
| 112111 | + ** clear on character p[-1]. */ | |
| 112112 | + for(p = (*pp)-2; p>=pStart && *p&0x80; p--); | |
| 112113 | + p++; | |
| 112114 | + *pp = p; | |
| 112115 | + | |
| 112116 | + sqlite3Fts3GetVarint(p, &iVal); | |
| 112117 | + *pVal -= iVal; | |
| 112118 | +} | |
| 111289 | 112119 | |
| 111290 | 112120 | /* |
| 111291 | 112121 | ** As long as *pp has not reached its end (pEnd), then do the same |
| 111292 | 112122 | ** as fts3GetDeltaVarint(): read a single varint and add it to *pVal. |
| 111293 | 112123 | ** But if we have reached the end of the varint, just set *pp=0 and |
| @@ -111389,10 +112219,12 @@ | ||
| 111389 | 112219 | if( *pRc==SQLITE_OK ){ |
| 111390 | 112220 | int i; /* Iterator variable */ |
| 111391 | 112221 | int rc; /* Return code */ |
| 111392 | 112222 | char *zSql; /* SQL statement passed to declare_vtab() */ |
| 111393 | 112223 | char *zCols; /* List of user defined columns */ |
| 112224 | + | |
| 112225 | + sqlite3_vtab_config(p->db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1); | |
| 111394 | 112226 | |
| 111395 | 112227 | /* Create a list of user columns for the virtual table */ |
| 111396 | 112228 | zCols = sqlite3_mprintf("%Q, ", p->azColumn[0]); |
| 111397 | 112229 | for(i=1; zCols && i<p->nColumn; i++){ |
| 111398 | 112230 | zCols = sqlite3_mprintf("%z%Q, ", zCols, p->azColumn[i]); |
| @@ -111958,10 +112790,26 @@ | ||
| 111958 | 112790 | |
| 111959 | 112791 | if( iCons>=0 ){ |
| 111960 | 112792 | pInfo->aConstraintUsage[iCons].argvIndex = 1; |
| 111961 | 112793 | pInfo->aConstraintUsage[iCons].omit = 1; |
| 111962 | 112794 | } |
| 112795 | + | |
| 112796 | + /* Regardless of the strategy selected, FTS can deliver rows in rowid (or | |
| 112797 | + ** docid) order. Both ascending and descending are possible. | |
| 112798 | + */ | |
| 112799 | + if( pInfo->nOrderBy==1 ){ | |
| 112800 | + struct sqlite3_index_orderby *pOrder = &pInfo->aOrderBy[0]; | |
| 112801 | + if( pOrder->iColumn<0 || pOrder->iColumn==p->nColumn+1 ){ | |
| 112802 | + if( pOrder->desc ){ | |
| 112803 | + pInfo->idxStr = "DESC"; | |
| 112804 | + }else{ | |
| 112805 | + pInfo->idxStr = "ASC"; | |
| 112806 | + } | |
| 112807 | + } | |
| 112808 | + pInfo->orderByConsumed = 1; | |
| 112809 | + } | |
| 112810 | + | |
| 111963 | 112811 | return SQLITE_OK; |
| 111964 | 112812 | } |
| 111965 | 112813 | |
| 111966 | 112814 | /* |
| 111967 | 112815 | ** Implementation of xOpen method. |
| @@ -112015,11 +112863,11 @@ | ||
| 112015 | 112863 | if( rc==SQLITE_OK ){ |
| 112016 | 112864 | /* If no row was found and no error has occured, then the %_content |
| 112017 | 112865 | ** table is missing a row that is present in the full-text index. |
| 112018 | 112866 | ** The data structures are corrupt. |
| 112019 | 112867 | */ |
| 112020 | - rc = SQLITE_CORRUPT; | |
| 112868 | + rc = SQLITE_CORRUPT_VTAB; | |
| 112021 | 112869 | } |
| 112022 | 112870 | pCsr->isEof = 1; |
| 112023 | 112871 | if( pContext ){ |
| 112024 | 112872 | sqlite3_result_error_code(pContext, rc); |
| 112025 | 112873 | } |
| @@ -112075,11 +112923,11 @@ | ||
| 112075 | 112923 | ** nNode bytes of content (see sqlite3Fts3ReadBlock() for details). |
| 112076 | 112924 | */ |
| 112077 | 112925 | zCsr += sqlite3Fts3GetVarint(zCsr, &iChild); |
| 112078 | 112926 | zCsr += sqlite3Fts3GetVarint(zCsr, &iChild); |
| 112079 | 112927 | if( zCsr>zEnd ){ |
| 112080 | - return SQLITE_CORRUPT; | |
| 112928 | + return SQLITE_CORRUPT_VTAB; | |
| 112081 | 112929 | } |
| 112082 | 112930 | |
| 112083 | 112931 | while( zCsr<zEnd && (piFirst || piLast) ){ |
| 112084 | 112932 | int cmp; /* memcmp() result */ |
| 112085 | 112933 | int nSuffix; /* Size of term suffix */ |
| @@ -112093,11 +112941,11 @@ | ||
| 112093 | 112941 | } |
| 112094 | 112942 | isFirstTerm = 0; |
| 112095 | 112943 | zCsr += sqlite3Fts3GetVarint32(zCsr, &nSuffix); |
| 112096 | 112944 | |
| 112097 | 112945 | if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){ |
| 112098 | - rc = SQLITE_CORRUPT; | |
| 112946 | + rc = SQLITE_CORRUPT_VTAB; | |
| 112099 | 112947 | goto finish_scan; |
| 112100 | 112948 | } |
| 112101 | 112949 | if( nPrefix+nSuffix>nAlloc ){ |
| 112102 | 112950 | char *zNew; |
| 112103 | 112951 | nAlloc = (nPrefix+nSuffix) * 2; |
| @@ -113862,16 +114710,24 @@ | ||
| 113862 | 114710 | rc = sqlite3_reset(pCsr->pStmt); |
| 113863 | 114711 | break; |
| 113864 | 114712 | } |
| 113865 | 114713 | pCsr->iPrevId = sqlite3_column_int64(pCsr->pStmt, 0); |
| 113866 | 114714 | }else{ |
| 113867 | - if( pCsr->pNextId>=&pCsr->aDoclist[pCsr->nDoclist] ){ | |
| 113868 | - pCsr->isEof = 1; | |
| 113869 | - break; | |
| 114715 | + if( pCsr->desc==0 ){ | |
| 114716 | + if( pCsr->pNextId>=&pCsr->aDoclist[pCsr->nDoclist] ){ | |
| 114717 | + pCsr->isEof = 1; | |
| 114718 | + break; | |
| 114719 | + } | |
| 114720 | + fts3GetDeltaVarint(&pCsr->pNextId, &pCsr->iPrevId); | |
| 114721 | + }else{ | |
| 114722 | + fts3GetReverseDeltaVarint(&pCsr->pNextId,pCsr->aDoclist,&pCsr->iPrevId); | |
| 114723 | + if( pCsr->pNextId<=pCsr->aDoclist ){ | |
| 114724 | + pCsr->isEof = 1; | |
| 114725 | + break; | |
| 114726 | + } | |
| 113870 | 114727 | } |
| 113871 | 114728 | sqlite3_reset(pCsr->pStmt); |
| 113872 | - fts3GetDeltaVarint(&pCsr->pNextId, &pCsr->iPrevId); | |
| 113873 | 114729 | pCsr->isRequireSeek = 1; |
| 113874 | 114730 | pCsr->isMatchinfoNeeded = 1; |
| 113875 | 114731 | } |
| 113876 | 114732 | }while( SQLITE_OK==(rc = fts3EvalDeferred(pCsr, &res)) && res==0 ); |
| 113877 | 114733 | |
| @@ -113900,12 +114756,12 @@ | ||
| 113900 | 114756 | const char *idxStr, /* Unused */ |
| 113901 | 114757 | int nVal, /* Number of elements in apVal */ |
| 113902 | 114758 | sqlite3_value **apVal /* Arguments for the indexing scheme */ |
| 113903 | 114759 | ){ |
| 113904 | 114760 | const char *azSql[] = { |
| 113905 | - "SELECT %s FROM %Q.'%q_content' AS x WHERE docid = ?", /* non-full-scan */ | |
| 113906 | - "SELECT %s FROM %Q.'%q_content' AS x ", /* full-scan */ | |
| 114761 | + "SELECT %s FROM %Q.'%q_content' AS x WHERE docid = ?", /* non-full-scan */ | |
| 114762 | + "SELECT %s FROM %Q.'%q_content' AS x ORDER BY docid %s", /* full-scan */ | |
| 113907 | 114763 | }; |
| 113908 | 114764 | int rc; /* Return code */ |
| 113909 | 114765 | char *zSql; /* SQL statement used to access %_content */ |
| 113910 | 114766 | Fts3Table *p = (Fts3Table *)pCursor->pVtab; |
| 113911 | 114767 | Fts3Cursor *pCsr = (Fts3Cursor *)pCursor; |
| @@ -113957,11 +114813,13 @@ | ||
| 113957 | 114813 | ** statement loops through all rows of the %_content table. For a |
| 113958 | 114814 | ** full-text query or docid lookup, the statement retrieves a single |
| 113959 | 114815 | ** row by docid. |
| 113960 | 114816 | */ |
| 113961 | 114817 | zSql = (char *)azSql[idxNum==FTS3_FULLSCAN_SEARCH]; |
| 113962 | - zSql = sqlite3_mprintf(zSql, p->zReadExprlist, p->zDb, p->zName); | |
| 114818 | + zSql = sqlite3_mprintf( | |
| 114819 | + zSql, p->zReadExprlist, p->zDb, p->zName, (idxStr ? idxStr : "ASC") | |
| 114820 | + ); | |
| 113963 | 114821 | if( !zSql ){ |
| 113964 | 114822 | rc = SQLITE_NOMEM; |
| 113965 | 114823 | }else{ |
| 113966 | 114824 | rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0); |
| 113967 | 114825 | sqlite3_free(zSql); |
| @@ -113969,11 +114827,26 @@ | ||
| 113969 | 114827 | if( rc==SQLITE_OK && idxNum==FTS3_DOCID_SEARCH ){ |
| 113970 | 114828 | rc = sqlite3_bind_value(pCsr->pStmt, 1, apVal[0]); |
| 113971 | 114829 | } |
| 113972 | 114830 | pCsr->eSearch = (i16)idxNum; |
| 113973 | 114831 | |
| 114832 | + assert( pCsr->desc==0 ); | |
| 113974 | 114833 | if( rc!=SQLITE_OK ) return rc; |
| 114834 | + if( rc==SQLITE_OK && pCsr->nDoclist>0 && idxStr && idxStr[0]=='D' ){ | |
| 114835 | + sqlite3_int64 iDocid = 0; | |
| 114836 | + char *csr = pCsr->aDoclist; | |
| 114837 | + while( csr<&pCsr->aDoclist[pCsr->nDoclist] ){ | |
| 114838 | + fts3GetDeltaVarint(&csr, &iDocid); | |
| 114839 | + } | |
| 114840 | + pCsr->pNextId = csr; | |
| 114841 | + pCsr->iPrevId = iDocid; | |
| 114842 | + pCsr->desc = 1; | |
| 114843 | + pCsr->isRequireSeek = 1; | |
| 114844 | + pCsr->isMatchinfoNeeded = 1; | |
| 114845 | + pCsr->eEvalmode = FTS3_EVAL_NEXT; | |
| 114846 | + return SQLITE_OK; | |
| 114847 | + } | |
| 113975 | 114848 | return fts3NextMethod(pCursor); |
| 113976 | 114849 | } |
| 113977 | 114850 | |
| 113978 | 114851 | /* |
| 113979 | 114852 | ** This is the xEof method of the virtual table. SQLite calls this |
| @@ -114121,17 +114994,37 @@ | ||
| 114121 | 114994 | pCsr->eEvalmode = FTS3_EVAL_MATCHINFO; |
| 114122 | 114995 | rc = fts3EvalExpr(pCsr, pExpr, paDoclist, pnDoclist, 1); |
| 114123 | 114996 | pCsr->eEvalmode = FTS3_EVAL_NEXT; |
| 114124 | 114997 | return rc; |
| 114125 | 114998 | } |
| 114999 | + | |
| 115000 | + | |
| 115001 | +/* | |
| 115002 | +** When called, *ppPoslist must point to the byte immediately following the | |
| 115003 | +** end of a position-list. i.e. ( (*ppPoslist)[-1]==POS_END ). This function | |
| 115004 | +** moves *ppPoslist so that it instead points to the first byte of the | |
| 115005 | +** same position list. | |
| 115006 | +*/ | |
| 115007 | +static void fts3ReversePoslist(char *pStart, char **ppPoslist){ | |
| 115008 | + char *p = &(*ppPoslist)[-3]; | |
| 115009 | + char c = p[1]; | |
| 115010 | + while( p>pStart && (*p & 0x80) | c ){ | |
| 115011 | + c = *p--; | |
| 115012 | + } | |
| 115013 | + if( p>pStart ){ p = &p[2]; } | |
| 115014 | + while( *p++&0x80 ); | |
| 115015 | + *ppPoslist = p; | |
| 115016 | +} | |
| 115017 | + | |
| 114126 | 115018 | |
| 114127 | 115019 | /* |
| 114128 | 115020 | ** After ExprLoadDoclist() (see above) has been called, this function is |
| 114129 | 115021 | ** used to iterate/search through the position lists that make up the doclist |
| 114130 | 115022 | ** stored in pExpr->aDoclist. |
| 114131 | 115023 | */ |
| 114132 | 115024 | SQLITE_PRIVATE char *sqlite3Fts3FindPositions( |
| 115025 | + Fts3Cursor *pCursor, /* Associate FTS3 cursor */ | |
| 114133 | 115026 | Fts3Expr *pExpr, /* Access this expressions doclist */ |
| 114134 | 115027 | sqlite3_int64 iDocid, /* Docid associated with requested pos-list */ |
| 114135 | 115028 | int iCol /* Column of requested pos-list */ |
| 114136 | 115029 | ){ |
| 114137 | 115030 | assert( pExpr->isLoaded ); |
| @@ -114138,23 +115031,39 @@ | ||
| 114138 | 115031 | if( pExpr->aDoclist ){ |
| 114139 | 115032 | char *pEnd = &pExpr->aDoclist[pExpr->nDoclist]; |
| 114140 | 115033 | char *pCsr; |
| 114141 | 115034 | |
| 114142 | 115035 | if( pExpr->pCurrent==0 ){ |
| 114143 | - pExpr->pCurrent = pExpr->aDoclist; | |
| 114144 | - pExpr->iCurrent = 0; | |
| 114145 | - pExpr->pCurrent += sqlite3Fts3GetVarint(pExpr->pCurrent,&pExpr->iCurrent); | |
| 115036 | + if( pCursor->desc==0 ){ | |
| 115037 | + pExpr->pCurrent = pExpr->aDoclist; | |
| 115038 | + pExpr->iCurrent = 0; | |
| 115039 | + fts3GetDeltaVarint(&pExpr->pCurrent, &pExpr->iCurrent); | |
| 115040 | + }else{ | |
| 115041 | + pCsr = pExpr->aDoclist; | |
| 115042 | + while( pCsr<pEnd ){ | |
| 115043 | + fts3GetDeltaVarint(&pCsr, &pExpr->iCurrent); | |
| 115044 | + fts3PoslistCopy(0, &pCsr); | |
| 115045 | + } | |
| 115046 | + fts3ReversePoslist(pExpr->aDoclist, &pCsr); | |
| 115047 | + pExpr->pCurrent = pCsr; | |
| 115048 | + } | |
| 114146 | 115049 | } |
| 114147 | 115050 | pCsr = pExpr->pCurrent; |
| 114148 | 115051 | assert( pCsr ); |
| 114149 | 115052 | |
| 114150 | - while( pCsr<pEnd ){ | |
| 114151 | - if( pExpr->iCurrent<iDocid ){ | |
| 115053 | + while( (pCursor->desc==0 && pCsr<pEnd) | |
| 115054 | + || (pCursor->desc && pCsr>pExpr->aDoclist) | |
| 115055 | + ){ | |
| 115056 | + if( pCursor->desc==0 && pExpr->iCurrent<iDocid ){ | |
| 114152 | 115057 | fts3PoslistCopy(0, &pCsr); |
| 114153 | 115058 | if( pCsr<pEnd ){ |
| 114154 | 115059 | fts3GetDeltaVarint(&pCsr, &pExpr->iCurrent); |
| 114155 | 115060 | } |
| 115061 | + pExpr->pCurrent = pCsr; | |
| 115062 | + }else if( pCursor->desc && pExpr->iCurrent>iDocid ){ | |
| 115063 | + fts3GetReverseDeltaVarint(&pCsr, pExpr->aDoclist, &pExpr->iCurrent); | |
| 115064 | + fts3ReversePoslist(pExpr->aDoclist, &pCsr); | |
| 114156 | 115065 | pExpr->pCurrent = pCsr; |
| 114157 | 115066 | }else{ |
| 114158 | 115067 | if( pExpr->iCurrent==iDocid ){ |
| 114159 | 115068 | int iThis = 0; |
| 114160 | 115069 | if( iCol<0 ){ |
| @@ -114407,13 +115316,24 @@ | ||
| 114407 | 115316 | "ALTER TABLE %Q.'%q_segdir' RENAME TO '%q_segdir';", |
| 114408 | 115317 | p->zDb, p->zName, zName |
| 114409 | 115318 | ); |
| 114410 | 115319 | return rc; |
| 114411 | 115320 | } |
| 115321 | + | |
| 115322 | +static int fts3SavepointMethod(sqlite3_vtab *pVtab, int iSavepoint){ | |
| 115323 | + return sqlite3Fts3PendingTermsFlush((Fts3Table *)pVtab); | |
| 115324 | +} | |
| 115325 | +static int fts3ReleaseMethod(sqlite3_vtab *pVtab, int iSavepoint){ | |
| 115326 | + return SQLITE_OK; | |
| 115327 | +} | |
| 115328 | +static int fts3RollbackToMethod(sqlite3_vtab *pVtab, int iSavepoint){ | |
| 115329 | + sqlite3Fts3PendingTermsClear((Fts3Table *)pVtab); | |
| 115330 | + return SQLITE_OK; | |
| 115331 | +} | |
| 114412 | 115332 | |
| 114413 | 115333 | static const sqlite3_module fts3Module = { |
| 114414 | - /* iVersion */ 0, | |
| 115334 | + /* iVersion */ 2, | |
| 114415 | 115335 | /* xCreate */ fts3CreateMethod, |
| 114416 | 115336 | /* xConnect */ fts3ConnectMethod, |
| 114417 | 115337 | /* xBestIndex */ fts3BestIndexMethod, |
| 114418 | 115338 | /* xDisconnect */ fts3DisconnectMethod, |
| 114419 | 115339 | /* xDestroy */ fts3DestroyMethod, |
| @@ -114429,10 +115349,13 @@ | ||
| 114429 | 115349 | /* xSync */ fts3SyncMethod, |
| 114430 | 115350 | /* xCommit */ fts3CommitMethod, |
| 114431 | 115351 | /* xRollback */ fts3RollbackMethod, |
| 114432 | 115352 | /* xFindFunction */ fts3FindFunctionMethod, |
| 114433 | 115353 | /* xRename */ fts3RenameMethod, |
| 115354 | + /* xSavepoint */ fts3SavepointMethod, | |
| 115355 | + /* xRelease */ fts3ReleaseMethod, | |
| 115356 | + /* xRollbackTo */ fts3RollbackToMethod, | |
| 114434 | 115357 | }; |
| 114435 | 115358 | |
| 114436 | 115359 | /* |
| 114437 | 115360 | ** This function is registered as the module destructor (called when an |
| 114438 | 115361 | ** FTS3 enabled database connection is closed). It frees the memory |
| @@ -114474,10 +115397,15 @@ | ||
| 114474 | 115397 | |
| 114475 | 115398 | #ifdef SQLITE_ENABLE_ICU |
| 114476 | 115399 | const sqlite3_tokenizer_module *pIcu = 0; |
| 114477 | 115400 | sqlite3Fts3IcuTokenizerModule(&pIcu); |
| 114478 | 115401 | #endif |
| 115402 | + | |
| 115403 | +#ifdef SQLITE_TEST | |
| 115404 | + rc = sqlite3Fts3InitTerm(db); | |
| 115405 | + if( rc!=SQLITE_OK ) return rc; | |
| 115406 | +#endif | |
| 114479 | 115407 | |
| 114480 | 115408 | rc = sqlite3Fts3InitAux(db); |
| 114481 | 115409 | if( rc!=SQLITE_OK ) return rc; |
| 114482 | 115410 | |
| 114483 | 115411 | sqlite3Fts3SimpleTokenizerModule(&pSimple); |
| @@ -117995,11 +118923,11 @@ | ||
| 117995 | 118923 | sqlite3_bind_int64(pStmt, 1, iDocid); |
| 117996 | 118924 | } |
| 117997 | 118925 | rc = sqlite3_step(pStmt); |
| 117998 | 118926 | if( rc!=SQLITE_ROW || sqlite3_column_type(pStmt, 0)!=SQLITE_BLOB ){ |
| 117999 | 118927 | rc = sqlite3_reset(pStmt); |
| 118000 | - if( rc==SQLITE_OK ) rc = SQLITE_CORRUPT; | |
| 118928 | + if( rc==SQLITE_OK ) rc = SQLITE_CORRUPT_VTAB; | |
| 118001 | 118929 | pStmt = 0; |
| 118002 | 118930 | }else{ |
| 118003 | 118931 | rc = SQLITE_OK; |
| 118004 | 118932 | } |
| 118005 | 118933 | } |
| @@ -118451,18 +119379,18 @@ | ||
| 118451 | 119379 | ** full-text index. |
| 118452 | 119380 | */ |
| 118453 | 119381 | static void fts3DeleteTerms( |
| 118454 | 119382 | int *pRC, /* Result code */ |
| 118455 | 119383 | Fts3Table *p, /* The FTS table to delete from */ |
| 118456 | - sqlite3_value **apVal, /* apVal[] contains the docid to be deleted */ | |
| 119384 | + sqlite3_value *pRowid, /* The docid to be deleted */ | |
| 118457 | 119385 | u32 *aSz /* Sizes of deleted document written here */ |
| 118458 | 119386 | ){ |
| 118459 | 119387 | int rc; |
| 118460 | 119388 | sqlite3_stmt *pSelect; |
| 118461 | 119389 | |
| 118462 | 119390 | if( *pRC ) return; |
| 118463 | - rc = fts3SqlStmt(p, SQL_SELECT_CONTENT_BY_ROWID, &pSelect, apVal); | |
| 119391 | + rc = fts3SqlStmt(p, SQL_SELECT_CONTENT_BY_ROWID, &pSelect, &pRowid); | |
| 118464 | 119392 | if( rc==SQLITE_OK ){ |
| 118465 | 119393 | if( SQLITE_ROW==sqlite3_step(pSelect) ){ |
| 118466 | 119394 | int i; |
| 118467 | 119395 | for(i=1; i<=p->nColumn; i++){ |
| 118468 | 119396 | const char *zText = (const char *)sqlite3_column_text(pSelect, i); |
| @@ -118676,11 +119604,11 @@ | ||
| 118676 | 119604 | pNext += sqlite3Fts3GetVarint32(pNext, &nPrefix); |
| 118677 | 119605 | pNext += sqlite3Fts3GetVarint32(pNext, &nSuffix); |
| 118678 | 119606 | if( nPrefix<0 || nSuffix<=0 |
| 118679 | 119607 | || &pNext[nSuffix]>&pReader->aNode[pReader->nNode] |
| 118680 | 119608 | ){ |
| 118681 | - return SQLITE_CORRUPT; | |
| 119609 | + return SQLITE_CORRUPT_VTAB; | |
| 118682 | 119610 | } |
| 118683 | 119611 | |
| 118684 | 119612 | if( nPrefix+nSuffix>pReader->nTermAlloc ){ |
| 118685 | 119613 | int nNew = (nPrefix+nSuffix)*2; |
| 118686 | 119614 | char *zNew = sqlite3_realloc(pReader->zTerm, nNew); |
| @@ -118702,11 +119630,11 @@ | ||
| 118702 | 119630 | ** of these statements is untrue, then the data structure is corrupt. |
| 118703 | 119631 | */ |
| 118704 | 119632 | if( &pReader->aDoclist[pReader->nDoclist]>&pReader->aNode[pReader->nNode] |
| 118705 | 119633 | || pReader->aDoclist[pReader->nDoclist-1] |
| 118706 | 119634 | ){ |
| 118707 | - return SQLITE_CORRUPT; | |
| 119635 | + return SQLITE_CORRUPT_VTAB; | |
| 118708 | 119636 | } |
| 118709 | 119637 | return SQLITE_OK; |
| 118710 | 119638 | } |
| 118711 | 119639 | |
| 118712 | 119640 | /* |
| @@ -118827,11 +119755,11 @@ | ||
| 118827 | 119755 | while( a<pEnd ){ |
| 118828 | 119756 | a += sqlite3Fts3GetVarint(a, &nByte); |
| 118829 | 119757 | } |
| 118830 | 119758 | if( nDoc==0 || nByte==0 ){ |
| 118831 | 119759 | sqlite3_reset(pStmt); |
| 118832 | - return SQLITE_CORRUPT; | |
| 119760 | + return SQLITE_CORRUPT_VTAB; | |
| 118833 | 119761 | } |
| 118834 | 119762 | |
| 118835 | 119763 | pCsr->nRowAvg = (int)(((nByte / nDoc) + pgsz) / pgsz); |
| 118836 | 119764 | assert( pCsr->nRowAvg>0 ); |
| 118837 | 119765 | rc = sqlite3_reset(pStmt); |
| @@ -119598,20 +120526,20 @@ | ||
| 119598 | 120526 | |
| 119599 | 120527 | /* |
| 119600 | 120528 | ** The first value in the apVal[] array is assumed to contain an integer. |
| 119601 | 120529 | ** This function tests if there exist any documents with docid values that |
| 119602 | 120530 | ** are different from that integer. i.e. if deleting the document with docid |
| 119603 | -** apVal[0] would mean the FTS3 table were empty. | |
| 120531 | +** pRowid would mean the FTS3 table were empty. | |
| 119604 | 120532 | ** |
| 119605 | 120533 | ** If successful, *pisEmpty is set to true if the table is empty except for |
| 119606 | -** document apVal[0], or false otherwise, and SQLITE_OK is returned. If an | |
| 120534 | +** document pRowid, or false otherwise, and SQLITE_OK is returned. If an | |
| 119607 | 120535 | ** error occurs, an SQLite error code is returned. |
| 119608 | 120536 | */ |
| 119609 | -static int fts3IsEmpty(Fts3Table *p, sqlite3_value **apVal, int *pisEmpty){ | |
| 120537 | +static int fts3IsEmpty(Fts3Table *p, sqlite3_value *pRowid, int *pisEmpty){ | |
| 119610 | 120538 | sqlite3_stmt *pStmt; |
| 119611 | 120539 | int rc; |
| 119612 | - rc = fts3SqlStmt(p, SQL_IS_EMPTY, &pStmt, apVal); | |
| 120540 | + rc = fts3SqlStmt(p, SQL_IS_EMPTY, &pStmt, &pRowid); | |
| 119613 | 120541 | if( rc==SQLITE_OK ){ |
| 119614 | 120542 | if( SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 119615 | 120543 | *pisEmpty = sqlite3_column_int(pStmt, 0); |
| 119616 | 120544 | } |
| 119617 | 120545 | rc = sqlite3_reset(pStmt); |
| @@ -120331,10 +121259,44 @@ | ||
| 120331 | 121259 | pToken->pDeferred = pDeferred; |
| 120332 | 121260 | |
| 120333 | 121261 | return SQLITE_OK; |
| 120334 | 121262 | } |
| 120335 | 121263 | |
| 121264 | +/* | |
| 121265 | +** SQLite value pRowid contains the rowid of a row that may or may not be | |
| 121266 | +** present in the FTS3 table. If it is, delete it and adjust the contents | |
| 121267 | +** of subsiduary data structures accordingly. | |
| 121268 | +*/ | |
| 121269 | +static int fts3DeleteByRowid( | |
| 121270 | + Fts3Table *p, | |
| 121271 | + sqlite3_value *pRowid, | |
| 121272 | + int *pnDoc, | |
| 121273 | + u32 *aSzDel | |
| 121274 | +){ | |
| 121275 | + int isEmpty = 0; | |
| 121276 | + int rc = fts3IsEmpty(p, pRowid, &isEmpty); | |
| 121277 | + if( rc==SQLITE_OK ){ | |
| 121278 | + if( isEmpty ){ | |
| 121279 | + /* Deleting this row means the whole table is empty. In this case | |
| 121280 | + ** delete the contents of all three tables and throw away any | |
| 121281 | + ** data in the pendingTerms hash table. */ | |
| 121282 | + rc = fts3DeleteAll(p); | |
| 121283 | + *pnDoc = *pnDoc - 1; | |
| 121284 | + }else{ | |
| 121285 | + sqlite3_int64 iRemove = sqlite3_value_int64(pRowid); | |
| 121286 | + rc = fts3PendingTermsDocid(p, iRemove); | |
| 121287 | + fts3DeleteTerms(&rc, p, pRowid, aSzDel); | |
| 121288 | + fts3SqlExec(&rc, p, SQL_DELETE_CONTENT, &pRowid); | |
| 121289 | + if( sqlite3_changes(p->db) ) *pnDoc = *pnDoc - 1; | |
| 121290 | + if( p->bHasDocsize ){ | |
| 121291 | + fts3SqlExec(&rc, p, SQL_DELETE_DOCSIZE, &pRowid); | |
| 121292 | + } | |
| 121293 | + } | |
| 121294 | + } | |
| 121295 | + | |
| 121296 | + return rc; | |
| 121297 | +} | |
| 120336 | 121298 | |
| 120337 | 121299 | /* |
| 120338 | 121300 | ** This function does the work for the xUpdate method of FTS3 virtual |
| 120339 | 121301 | ** tables. |
| 120340 | 121302 | */ |
| @@ -120349,50 +121311,95 @@ | ||
| 120349 | 121311 | int isRemove = 0; /* True for an UPDATE or DELETE */ |
| 120350 | 121312 | sqlite3_int64 iRemove = 0; /* Rowid removed by UPDATE or DELETE */ |
| 120351 | 121313 | u32 *aSzIns; /* Sizes of inserted documents */ |
| 120352 | 121314 | u32 *aSzDel; /* Sizes of deleted documents */ |
| 120353 | 121315 | int nChng = 0; /* Net change in number of documents */ |
| 121316 | + int bInsertDone = 0; | |
| 120354 | 121317 | |
| 120355 | 121318 | assert( p->pSegments==0 ); |
| 121319 | + | |
| 121320 | + /* Check for a "special" INSERT operation. One of the form: | |
| 121321 | + ** | |
| 121322 | + ** INSERT INTO xyz(xyz) VALUES('command'); | |
| 121323 | + */ | |
| 121324 | + if( nArg>1 | |
| 121325 | + && sqlite3_value_type(apVal[0])==SQLITE_NULL | |
| 121326 | + && sqlite3_value_type(apVal[p->nColumn+2])!=SQLITE_NULL | |
| 121327 | + ){ | |
| 121328 | + return fts3SpecialInsert(p, apVal[p->nColumn+2]); | |
| 121329 | + } | |
| 120356 | 121330 | |
| 120357 | 121331 | /* Allocate space to hold the change in document sizes */ |
| 120358 | 121332 | aSzIns = sqlite3_malloc( sizeof(aSzIns[0])*(p->nColumn+1)*2 ); |
| 120359 | 121333 | if( aSzIns==0 ) return SQLITE_NOMEM; |
| 120360 | 121334 | aSzDel = &aSzIns[p->nColumn+1]; |
| 120361 | 121335 | memset(aSzIns, 0, sizeof(aSzIns[0])*(p->nColumn+1)*2); |
| 121336 | + | |
| 121337 | + /* If this is an INSERT operation, or an UPDATE that modifies the rowid | |
| 121338 | + ** value, then this operation requires constraint handling. | |
| 121339 | + ** | |
| 121340 | + ** If the on-conflict mode is REPLACE, this means that the existing row | |
| 121341 | + ** should be deleted from the database before inserting the new row. Or, | |
| 121342 | + ** if the on-conflict mode is other than REPLACE, then this method must | |
| 121343 | + ** detect the conflict and return SQLITE_CONSTRAINT before beginning to | |
| 121344 | + ** modify the database file. | |
| 121345 | + */ | |
| 121346 | + if( nArg>1 ){ | |
| 121347 | + /* Find the value object that holds the new rowid value. */ | |
| 121348 | + sqlite3_value *pNewRowid = apVal[3+p->nColumn]; | |
| 121349 | + if( sqlite3_value_type(pNewRowid)==SQLITE_NULL ){ | |
| 121350 | + pNewRowid = apVal[1]; | |
| 121351 | + } | |
| 121352 | + | |
| 121353 | + if( sqlite3_value_type(pNewRowid)!=SQLITE_NULL && ( | |
| 121354 | + sqlite3_value_type(apVal[0])==SQLITE_NULL | |
| 121355 | + || sqlite3_value_int64(apVal[0])!=sqlite3_value_int64(pNewRowid) | |
| 121356 | + )){ | |
| 121357 | + /* The new rowid is not NULL (in this case the rowid will be | |
| 121358 | + ** automatically assigned and there is no chance of a conflict), and | |
| 121359 | + ** the statement is either an INSERT or an UPDATE that modifies the | |
| 121360 | + ** rowid column. So if the conflict mode is REPLACE, then delete any | |
| 121361 | + ** existing row with rowid=pNewRowid. | |
| 121362 | + ** | |
| 121363 | + ** Or, if the conflict mode is not REPLACE, insert the new record into | |
| 121364 | + ** the %_content table. If we hit the duplicate rowid constraint (or any | |
| 121365 | + ** other error) while doing so, return immediately. | |
| 121366 | + ** | |
| 121367 | + ** This branch may also run if pNewRowid contains a value that cannot | |
| 121368 | + ** be losslessly converted to an integer. In this case, the eventual | |
| 121369 | + ** call to fts3InsertData() (either just below or further on in this | |
| 121370 | + ** function) will return SQLITE_MISMATCH. If fts3DeleteByRowid is | |
| 121371 | + ** invoked, it will delete zero rows (since no row will have | |
| 121372 | + ** docid=$pNewRowid if $pNewRowid is not an integer value). | |
| 121373 | + */ | |
| 121374 | + if( sqlite3_vtab_on_conflict(p->db)==SQLITE_REPLACE ){ | |
| 121375 | + rc = fts3DeleteByRowid(p, pNewRowid, &nChng, aSzDel); | |
| 121376 | + }else{ | |
| 121377 | + rc = fts3InsertData(p, apVal, pRowid); | |
| 121378 | + bInsertDone = 1; | |
| 121379 | + } | |
| 121380 | + } | |
| 121381 | + } | |
| 121382 | + if( rc!=SQLITE_OK ){ | |
| 121383 | + sqlite3_free(aSzIns); | |
| 121384 | + return rc; | |
| 121385 | + } | |
| 120362 | 121386 | |
| 120363 | 121387 | /* If this is a DELETE or UPDATE operation, remove the old record. */ |
| 120364 | 121388 | if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){ |
| 120365 | - int isEmpty = 0; | |
| 120366 | - rc = fts3IsEmpty(p, apVal, &isEmpty); | |
| 120367 | - if( rc==SQLITE_OK ){ | |
| 120368 | - if( isEmpty ){ | |
| 120369 | - /* Deleting this row means the whole table is empty. In this case | |
| 120370 | - ** delete the contents of all three tables and throw away any | |
| 120371 | - ** data in the pendingTerms hash table. | |
| 120372 | - */ | |
| 120373 | - rc = fts3DeleteAll(p); | |
| 120374 | - }else{ | |
| 120375 | - isRemove = 1; | |
| 120376 | - iRemove = sqlite3_value_int64(apVal[0]); | |
| 120377 | - rc = fts3PendingTermsDocid(p, iRemove); | |
| 120378 | - fts3DeleteTerms(&rc, p, apVal, aSzDel); | |
| 120379 | - fts3SqlExec(&rc, p, SQL_DELETE_CONTENT, apVal); | |
| 120380 | - if( p->bHasDocsize ){ | |
| 120381 | - fts3SqlExec(&rc, p, SQL_DELETE_DOCSIZE, apVal); | |
| 120382 | - } | |
| 120383 | - nChng--; | |
| 120384 | - } | |
| 120385 | - } | |
| 120386 | - }else if( sqlite3_value_type(apVal[p->nColumn+2])!=SQLITE_NULL ){ | |
| 120387 | - sqlite3_free(aSzIns); | |
| 120388 | - return fts3SpecialInsert(p, apVal[p->nColumn+2]); | |
| 121389 | + assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER ); | |
| 121390 | + rc = fts3DeleteByRowid(p, apVal[0], &nChng, aSzDel); | |
| 121391 | + isRemove = 1; | |
| 121392 | + iRemove = sqlite3_value_int64(apVal[0]); | |
| 120389 | 121393 | } |
| 120390 | 121394 | |
| 120391 | 121395 | /* If this is an INSERT or UPDATE operation, insert the new record. */ |
| 120392 | 121396 | if( nArg>1 && rc==SQLITE_OK ){ |
| 120393 | - rc = fts3InsertData(p, apVal, pRowid); | |
| 121397 | + if( bInsertDone==0 ){ | |
| 121398 | + rc = fts3InsertData(p, apVal, pRowid); | |
| 121399 | + if( rc==SQLITE_CONSTRAINT ) rc = SQLITE_CORRUPT_VTAB; | |
| 121400 | + } | |
| 120394 | 121401 | if( rc==SQLITE_OK && (!isRemove || *pRowid!=iRemove) ){ |
| 120395 | 121402 | rc = fts3PendingTermsDocid(p, *pRowid); |
| 120396 | 121403 | } |
| 120397 | 121404 | if( rc==SQLITE_OK ){ |
| 120398 | 121405 | rc = fts3InsertTerms(p, apVal, aSzIns); |
| @@ -120852,11 +121859,11 @@ | ||
| 120852 | 121859 | SnippetPhrase *pPhrase = &p->aPhrase[iPhrase]; |
| 120853 | 121860 | char *pCsr; |
| 120854 | 121861 | |
| 120855 | 121862 | pPhrase->nToken = pExpr->pPhrase->nToken; |
| 120856 | 121863 | |
| 120857 | - pCsr = sqlite3Fts3FindPositions(pExpr, p->pCsr->iPrevId, p->iCol); | |
| 121864 | + pCsr = sqlite3Fts3FindPositions(p->pCsr, pExpr, p->pCsr->iPrevId, p->iCol); | |
| 120858 | 121865 | if( pCsr ){ |
| 120859 | 121866 | int iFirst = 0; |
| 120860 | 121867 | pPhrase->pList = pCsr; |
| 120861 | 121868 | fts3GetDeltaPosition(&pCsr, &iFirst); |
| 120862 | 121869 | pPhrase->pHead = pCsr; |
| @@ -121325,11 +122332,11 @@ | ||
| 121325 | 122332 | for(i=0; i<p->nCol; i++) p->aMatchinfo[iStart+i*3] = 0; |
| 121326 | 122333 | |
| 121327 | 122334 | if( pExpr->aDoclist ){ |
| 121328 | 122335 | char *pCsr; |
| 121329 | 122336 | |
| 121330 | - pCsr = sqlite3Fts3FindPositions(pExpr, p->pCursor->iPrevId, -1); | |
| 122337 | + pCsr = sqlite3Fts3FindPositions(p->pCursor, pExpr, p->pCursor->iPrevId, -1); | |
| 121331 | 122338 | if( pCsr ){ |
| 121332 | 122339 | fts3LoadColumnlistCounts(&pCsr, &p->aMatchinfo[iStart], 0); |
| 121333 | 122340 | } |
| 121334 | 122341 | } |
| 121335 | 122342 | |
| @@ -121397,11 +122404,11 @@ | ||
| 121397 | 122404 | pStmt = *ppStmt; |
| 121398 | 122405 | assert( sqlite3_data_count(pStmt)==1 ); |
| 121399 | 122406 | |
| 121400 | 122407 | a = sqlite3_column_blob(pStmt, 0); |
| 121401 | 122408 | a += sqlite3Fts3GetVarint(a, &nDoc); |
| 121402 | - if( nDoc==0 ) return SQLITE_CORRUPT; | |
| 122409 | + if( nDoc==0 ) return SQLITE_CORRUPT_VTAB; | |
| 121403 | 122410 | *pnDoc = (u32)nDoc; |
| 121404 | 122411 | |
| 121405 | 122412 | if( paLen ) *paLen = a; |
| 121406 | 122413 | return SQLITE_OK; |
| 121407 | 122414 | } |
| @@ -121492,11 +122499,11 @@ | ||
| 121492 | 122499 | (void)fts3ExprIterate(pCsr->pExpr, fts3MatchinfoLcsCb, (void*)aIter); |
| 121493 | 122500 | for(i=0; i<pInfo->nPhrase; i++){ |
| 121494 | 122501 | LcsIterator *pIter = &aIter[i]; |
| 121495 | 122502 | nToken -= pIter->pExpr->pPhrase->nToken; |
| 121496 | 122503 | pIter->iPosOffset = nToken; |
| 121497 | - pIter->pRead = sqlite3Fts3FindPositions(pIter->pExpr, pCsr->iPrevId, -1); | |
| 122504 | + pIter->pRead = sqlite3Fts3FindPositions(pCsr,pIter->pExpr,pCsr->iPrevId,-1); | |
| 121498 | 122505 | if( pIter->pRead ){ |
| 121499 | 122506 | pIter->iPos = pIter->iPosOffset; |
| 121500 | 122507 | fts3LcsIteratorAdvance(&aIter[i]); |
| 121501 | 122508 | }else{ |
| 121502 | 122509 | pIter->iCol = LCS_ITERATOR_FINISHED; |
| @@ -121845,10 +122852,11 @@ | ||
| 121845 | 122852 | int iPos; /* Position just read from pList */ |
| 121846 | 122853 | int iOff; /* Offset of this term from read positions */ |
| 121847 | 122854 | }; |
| 121848 | 122855 | |
| 121849 | 122856 | struct TermOffsetCtx { |
| 122857 | + Fts3Cursor *pCsr; | |
| 121850 | 122858 | int iCol; /* Column of table to populate aTerm for */ |
| 121851 | 122859 | int iTerm; |
| 121852 | 122860 | sqlite3_int64 iDocid; |
| 121853 | 122861 | TermOffset *aTerm; |
| 121854 | 122862 | }; |
| @@ -121862,11 +122870,11 @@ | ||
| 121862 | 122870 | int iTerm; /* For looping through nTerm phrase terms */ |
| 121863 | 122871 | char *pList; /* Pointer to position list for phrase */ |
| 121864 | 122872 | int iPos = 0; /* First position in position-list */ |
| 121865 | 122873 | |
| 121866 | 122874 | UNUSED_PARAMETER(iPhrase); |
| 121867 | - pList = sqlite3Fts3FindPositions(pExpr, p->iDocid, p->iCol); | |
| 122875 | + pList = sqlite3Fts3FindPositions(p->pCsr, pExpr, p->iDocid, p->iCol); | |
| 121868 | 122876 | nTerm = pExpr->pPhrase->nToken; |
| 121869 | 122877 | if( pList ){ |
| 121870 | 122878 | fts3GetDeltaPosition(&pList, &iPos); |
| 121871 | 122879 | assert( iPos>=0 ); |
| 121872 | 122880 | } |
| @@ -121915,10 +122923,11 @@ | ||
| 121915 | 122923 | if( 0==sCtx.aTerm ){ |
| 121916 | 122924 | rc = SQLITE_NOMEM; |
| 121917 | 122925 | goto offsets_out; |
| 121918 | 122926 | } |
| 121919 | 122927 | sCtx.iDocid = pCsr->iPrevId; |
| 122928 | + sCtx.pCsr = pCsr; | |
| 121920 | 122929 | |
| 121921 | 122930 | /* Loop through the table columns, appending offset information to |
| 121922 | 122931 | ** string-buffer res for each column. |
| 121923 | 122932 | */ |
| 121924 | 122933 | for(iCol=0; iCol<pTab->nColumn; iCol++){ |
| @@ -121990,11 +122999,11 @@ | ||
| 121990 | 122999 | sqlite3_snprintf(sizeof(aBuffer), aBuffer, |
| 121991 | 123000 | "%d %d %d %d ", iCol, pTerm-sCtx.aTerm, iStart, iEnd-iStart |
| 121992 | 123001 | ); |
| 121993 | 123002 | rc = fts3StringAppend(&res, aBuffer, -1); |
| 121994 | 123003 | }else if( rc==SQLITE_DONE ){ |
| 121995 | - rc = SQLITE_CORRUPT; | |
| 123004 | + rc = SQLITE_CORRUPT_VTAB; | |
| 121996 | 123005 | } |
| 121997 | 123006 | } |
| 121998 | 123007 | } |
| 121999 | 123008 | if( rc==SQLITE_DONE ){ |
| 122000 | 123009 | rc = SQLITE_OK; |
| @@ -122578,29 +123587,29 @@ | ||
| 122578 | 123587 | ** is greater than RTREE_MAX_DEPTH, the r-tree structure must be corrupt. |
| 122579 | 123588 | */ |
| 122580 | 123589 | if( pNode && iNode==1 ){ |
| 122581 | 123590 | pRtree->iDepth = readInt16(pNode->zData); |
| 122582 | 123591 | if( pRtree->iDepth>RTREE_MAX_DEPTH ){ |
| 122583 | - rc = SQLITE_CORRUPT; | |
| 123592 | + rc = SQLITE_CORRUPT_VTAB; | |
| 122584 | 123593 | } |
| 122585 | 123594 | } |
| 122586 | 123595 | |
| 122587 | 123596 | /* If no error has occurred so far, check if the "number of entries" |
| 122588 | 123597 | ** field on the node is too large. If so, set the return code to |
| 122589 | - ** SQLITE_CORRUPT. | |
| 123598 | + ** SQLITE_CORRUPT_VTAB. | |
| 122590 | 123599 | */ |
| 122591 | 123600 | if( pNode && rc==SQLITE_OK ){ |
| 122592 | 123601 | if( NCELL(pNode)>((pRtree->iNodeSize-4)/pRtree->nBytesPerCell) ){ |
| 122593 | - rc = SQLITE_CORRUPT; | |
| 123602 | + rc = SQLITE_CORRUPT_VTAB; | |
| 122594 | 123603 | } |
| 122595 | 123604 | } |
| 122596 | 123605 | |
| 122597 | 123606 | if( rc==SQLITE_OK ){ |
| 122598 | 123607 | if( pNode!=0 ){ |
| 122599 | 123608 | nodeHashInsert(pRtree, pNode); |
| 122600 | 123609 | }else{ |
| 122601 | - rc = SQLITE_CORRUPT; | |
| 123610 | + rc = SQLITE_CORRUPT_VTAB; | |
| 122602 | 123611 | } |
| 122603 | 123612 | *ppNode = pNode; |
| 122604 | 123613 | }else{ |
| 122605 | 123614 | sqlite3_free(pNode); |
| 122606 | 123615 | *ppNode = 0; |
| @@ -123123,11 +124132,11 @@ | ||
| 123123 | 124132 | if( nodeGetRowid(pRtree, pNode, ii)==iRowid ){ |
| 123124 | 124133 | *piIndex = ii; |
| 123125 | 124134 | return SQLITE_OK; |
| 123126 | 124135 | } |
| 123127 | 124136 | } |
| 123128 | - return SQLITE_CORRUPT; | |
| 124137 | + return SQLITE_CORRUPT_VTAB; | |
| 123129 | 124138 | } |
| 123130 | 124139 | |
| 123131 | 124140 | /* |
| 123132 | 124141 | ** Return the index of the cell containing a pointer to node pNode |
| 123133 | 124142 | ** in its parent. If pNode is the root node, return -1. |
| @@ -123718,11 +124727,11 @@ | ||
| 123718 | 124727 | RtreeNode *pParent = p->pParent; |
| 123719 | 124728 | RtreeCell cell; |
| 123720 | 124729 | int iCell; |
| 123721 | 124730 | |
| 123722 | 124731 | if( nodeParentIndex(pRtree, p, &iCell) ){ |
| 123723 | - return SQLITE_CORRUPT; | |
| 124732 | + return SQLITE_CORRUPT_VTAB; | |
| 123724 | 124733 | } |
| 123725 | 124734 | |
| 123726 | 124735 | nodeGetCell(pRtree, pParent, iCell, &cell); |
| 123727 | 124736 | if( !cellContains(pRtree, &cell, pCell) ){ |
| 123728 | 124737 | cellUnion(pRtree, &cell, pCell); |
| @@ -124390,11 +125399,11 @@ | ||
| 124390 | 125399 | rc2 = nodeAcquire(pRtree, iNode, 0, &pChild->pParent); |
| 124391 | 125400 | } |
| 124392 | 125401 | } |
| 124393 | 125402 | rc = sqlite3_reset(pRtree->pReadParent); |
| 124394 | 125403 | if( rc==SQLITE_OK ) rc = rc2; |
| 124395 | - if( rc==SQLITE_OK && !pChild->pParent ) rc = SQLITE_CORRUPT; | |
| 125404 | + if( rc==SQLITE_OK && !pChild->pParent ) rc = SQLITE_CORRUPT_VTAB; | |
| 124396 | 125405 | pChild = pChild->pParent; |
| 124397 | 125406 | } |
| 124398 | 125407 | return rc; |
| 124399 | 125408 | } |
| 124400 | 125409 | |
| @@ -124685,10 +125694,94 @@ | ||
| 124685 | 125694 | sqlite3_step(pRtree->pWriteRowid); |
| 124686 | 125695 | rc = sqlite3_reset(pRtree->pWriteRowid); |
| 124687 | 125696 | *piRowid = sqlite3_last_insert_rowid(pRtree->db); |
| 124688 | 125697 | return rc; |
| 124689 | 125698 | } |
| 125699 | + | |
| 125700 | +/* | |
| 125701 | +** Remove the entry with rowid=iDelete from the r-tree structure. | |
| 125702 | +*/ | |
| 125703 | +static int rtreeDeleteRowid(Rtree *pRtree, sqlite3_int64 iDelete){ | |
| 125704 | + int rc; /* Return code */ | |
| 125705 | + RtreeNode *pLeaf; /* Leaf node containing record iDelete */ | |
| 125706 | + int iCell; /* Index of iDelete cell in pLeaf */ | |
| 125707 | + RtreeNode *pRoot; /* Root node of rtree structure */ | |
| 125708 | + | |
| 125709 | + | |
| 125710 | + /* Obtain a reference to the root node to initialise Rtree.iDepth */ | |
| 125711 | + rc = nodeAcquire(pRtree, 1, 0, &pRoot); | |
| 125712 | + | |
| 125713 | + /* Obtain a reference to the leaf node that contains the entry | |
| 125714 | + ** about to be deleted. | |
| 125715 | + */ | |
| 125716 | + if( rc==SQLITE_OK ){ | |
| 125717 | + rc = findLeafNode(pRtree, iDelete, &pLeaf); | |
| 125718 | + } | |
| 125719 | + | |
| 125720 | + /* Delete the cell in question from the leaf node. */ | |
| 125721 | + if( rc==SQLITE_OK ){ | |
| 125722 | + int rc2; | |
| 125723 | + rc = nodeRowidIndex(pRtree, pLeaf, iDelete, &iCell); | |
| 125724 | + if( rc==SQLITE_OK ){ | |
| 125725 | + rc = deleteCell(pRtree, pLeaf, iCell, 0); | |
| 125726 | + } | |
| 125727 | + rc2 = nodeRelease(pRtree, pLeaf); | |
| 125728 | + if( rc==SQLITE_OK ){ | |
| 125729 | + rc = rc2; | |
| 125730 | + } | |
| 125731 | + } | |
| 125732 | + | |
| 125733 | + /* Delete the corresponding entry in the <rtree>_rowid table. */ | |
| 125734 | + if( rc==SQLITE_OK ){ | |
| 125735 | + sqlite3_bind_int64(pRtree->pDeleteRowid, 1, iDelete); | |
| 125736 | + sqlite3_step(pRtree->pDeleteRowid); | |
| 125737 | + rc = sqlite3_reset(pRtree->pDeleteRowid); | |
| 125738 | + } | |
| 125739 | + | |
| 125740 | + /* Check if the root node now has exactly one child. If so, remove | |
| 125741 | + ** it, schedule the contents of the child for reinsertion and | |
| 125742 | + ** reduce the tree height by one. | |
| 125743 | + ** | |
| 125744 | + ** This is equivalent to copying the contents of the child into | |
| 125745 | + ** the root node (the operation that Gutman's paper says to perform | |
| 125746 | + ** in this scenario). | |
| 125747 | + */ | |
| 125748 | + if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){ | |
| 125749 | + int rc2; | |
| 125750 | + RtreeNode *pChild; | |
| 125751 | + i64 iChild = nodeGetRowid(pRtree, pRoot, 0); | |
| 125752 | + rc = nodeAcquire(pRtree, iChild, pRoot, &pChild); | |
| 125753 | + if( rc==SQLITE_OK ){ | |
| 125754 | + rc = removeNode(pRtree, pChild, pRtree->iDepth-1); | |
| 125755 | + } | |
| 125756 | + rc2 = nodeRelease(pRtree, pChild); | |
| 125757 | + if( rc==SQLITE_OK ) rc = rc2; | |
| 125758 | + if( rc==SQLITE_OK ){ | |
| 125759 | + pRtree->iDepth--; | |
| 125760 | + writeInt16(pRoot->zData, pRtree->iDepth); | |
| 125761 | + pRoot->isDirty = 1; | |
| 125762 | + } | |
| 125763 | + } | |
| 125764 | + | |
| 125765 | + /* Re-insert the contents of any underfull nodes removed from the tree. */ | |
| 125766 | + for(pLeaf=pRtree->pDeleted; pLeaf; pLeaf=pRtree->pDeleted){ | |
| 125767 | + if( rc==SQLITE_OK ){ | |
| 125768 | + rc = reinsertNodeContent(pRtree, pLeaf); | |
| 125769 | + } | |
| 125770 | + pRtree->pDeleted = pLeaf->pNext; | |
| 125771 | + sqlite3_free(pLeaf); | |
| 125772 | + } | |
| 125773 | + | |
| 125774 | + /* Release the reference to the root node. */ | |
| 125775 | + if( rc==SQLITE_OK ){ | |
| 125776 | + rc = nodeRelease(pRtree, pRoot); | |
| 125777 | + }else{ | |
| 125778 | + nodeRelease(pRtree, pRoot); | |
| 125779 | + } | |
| 125780 | + | |
| 125781 | + return rc; | |
| 125782 | +} | |
| 124690 | 125783 | |
| 124691 | 125784 | /* |
| 124692 | 125785 | ** The xUpdate method for rtree module virtual tables. |
| 124693 | 125786 | */ |
| 124694 | 125787 | static int rtreeUpdate( |
| @@ -124697,107 +125790,29 @@ | ||
| 124697 | 125790 | sqlite3_value **azData, |
| 124698 | 125791 | sqlite_int64 *pRowid |
| 124699 | 125792 | ){ |
| 124700 | 125793 | Rtree *pRtree = (Rtree *)pVtab; |
| 124701 | 125794 | int rc = SQLITE_OK; |
| 125795 | + RtreeCell cell; /* New cell to insert if nData>1 */ | |
| 125796 | + int bHaveRowid = 0; /* Set to 1 after new rowid is determined */ | |
| 124702 | 125797 | |
| 124703 | 125798 | rtreeReference(pRtree); |
| 124704 | - | |
| 124705 | 125799 | assert(nData>=1); |
| 124706 | 125800 | |
| 124707 | - /* If azData[0] is not an SQL NULL value, it is the rowid of a | |
| 124708 | - ** record to delete from the r-tree table. The following block does | |
| 124709 | - ** just that. | |
| 124710 | - */ | |
| 124711 | - if( sqlite3_value_type(azData[0])!=SQLITE_NULL ){ | |
| 124712 | - i64 iDelete; /* The rowid to delete */ | |
| 124713 | - RtreeNode *pLeaf; /* Leaf node containing record iDelete */ | |
| 124714 | - int iCell; /* Index of iDelete cell in pLeaf */ | |
| 124715 | - RtreeNode *pRoot; | |
| 124716 | - | |
| 124717 | - /* Obtain a reference to the root node to initialise Rtree.iDepth */ | |
| 124718 | - rc = nodeAcquire(pRtree, 1, 0, &pRoot); | |
| 124719 | - | |
| 124720 | - /* Obtain a reference to the leaf node that contains the entry | |
| 124721 | - ** about to be deleted. | |
| 124722 | - */ | |
| 124723 | - if( rc==SQLITE_OK ){ | |
| 124724 | - iDelete = sqlite3_value_int64(azData[0]); | |
| 124725 | - rc = findLeafNode(pRtree, iDelete, &pLeaf); | |
| 124726 | - } | |
| 124727 | - | |
| 124728 | - /* Delete the cell in question from the leaf node. */ | |
| 124729 | - if( rc==SQLITE_OK ){ | |
| 124730 | - int rc2; | |
| 124731 | - rc = nodeRowidIndex(pRtree, pLeaf, iDelete, &iCell); | |
| 124732 | - if( rc==SQLITE_OK ){ | |
| 124733 | - rc = deleteCell(pRtree, pLeaf, iCell, 0); | |
| 124734 | - } | |
| 124735 | - rc2 = nodeRelease(pRtree, pLeaf); | |
| 124736 | - if( rc==SQLITE_OK ){ | |
| 124737 | - rc = rc2; | |
| 124738 | - } | |
| 124739 | - } | |
| 124740 | - | |
| 124741 | - /* Delete the corresponding entry in the <rtree>_rowid table. */ | |
| 124742 | - if( rc==SQLITE_OK ){ | |
| 124743 | - sqlite3_bind_int64(pRtree->pDeleteRowid, 1, iDelete); | |
| 124744 | - sqlite3_step(pRtree->pDeleteRowid); | |
| 124745 | - rc = sqlite3_reset(pRtree->pDeleteRowid); | |
| 124746 | - } | |
| 124747 | - | |
| 124748 | - /* Check if the root node now has exactly one child. If so, remove | |
| 124749 | - ** it, schedule the contents of the child for reinsertion and | |
| 124750 | - ** reduce the tree height by one. | |
| 124751 | - ** | |
| 124752 | - ** This is equivalent to copying the contents of the child into | |
| 124753 | - ** the root node (the operation that Gutman's paper says to perform | |
| 124754 | - ** in this scenario). | |
| 124755 | - */ | |
| 124756 | - if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){ | |
| 124757 | - int rc2; | |
| 124758 | - RtreeNode *pChild; | |
| 124759 | - i64 iChild = nodeGetRowid(pRtree, pRoot, 0); | |
| 124760 | - rc = nodeAcquire(pRtree, iChild, pRoot, &pChild); | |
| 124761 | - if( rc==SQLITE_OK ){ | |
| 124762 | - rc = removeNode(pRtree, pChild, pRtree->iDepth-1); | |
| 124763 | - } | |
| 124764 | - rc2 = nodeRelease(pRtree, pChild); | |
| 124765 | - if( rc==SQLITE_OK ) rc = rc2; | |
| 124766 | - if( rc==SQLITE_OK ){ | |
| 124767 | - pRtree->iDepth--; | |
| 124768 | - writeInt16(pRoot->zData, pRtree->iDepth); | |
| 124769 | - pRoot->isDirty = 1; | |
| 124770 | - } | |
| 124771 | - } | |
| 124772 | - | |
| 124773 | - /* Re-insert the contents of any underfull nodes removed from the tree. */ | |
| 124774 | - for(pLeaf=pRtree->pDeleted; pLeaf; pLeaf=pRtree->pDeleted){ | |
| 124775 | - if( rc==SQLITE_OK ){ | |
| 124776 | - rc = reinsertNodeContent(pRtree, pLeaf); | |
| 124777 | - } | |
| 124778 | - pRtree->pDeleted = pLeaf->pNext; | |
| 124779 | - sqlite3_free(pLeaf); | |
| 124780 | - } | |
| 124781 | - | |
| 124782 | - /* Release the reference to the root node. */ | |
| 124783 | - if( rc==SQLITE_OK ){ | |
| 124784 | - rc = nodeRelease(pRtree, pRoot); | |
| 124785 | - }else{ | |
| 124786 | - nodeRelease(pRtree, pRoot); | |
| 124787 | - } | |
| 124788 | - } | |
| 124789 | - | |
| 124790 | - /* If the azData[] array contains more than one element, elements | |
| 124791 | - ** (azData[2]..azData[argc-1]) contain a new record to insert into | |
| 124792 | - ** the r-tree structure. | |
| 124793 | - */ | |
| 124794 | - if( rc==SQLITE_OK && nData>1 ){ | |
| 124795 | - /* Insert a new record into the r-tree */ | |
| 124796 | - RtreeCell cell; | |
| 124797 | - int ii; | |
| 124798 | - RtreeNode *pLeaf; | |
| 125801 | + /* Constraint handling. A write operation on an r-tree table may return | |
| 125802 | + ** SQLITE_CONSTRAINT for two reasons: | |
| 125803 | + ** | |
| 125804 | + ** 1. A duplicate rowid value, or | |
| 125805 | + ** 2. The supplied data violates the "x2>=x1" constraint. | |
| 125806 | + ** | |
| 125807 | + ** In the first case, if the conflict-handling mode is REPLACE, then | |
| 125808 | + ** the conflicting row can be removed before proceeding. In the second | |
| 125809 | + ** case, SQLITE_CONSTRAINT must be returned regardless of the | |
| 125810 | + ** conflict-handling mode specified by the user. | |
| 125811 | + */ | |
| 125812 | + if( nData>1 ){ | |
| 125813 | + int ii; | |
| 124799 | 125814 | |
| 124800 | 125815 | /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */ |
| 124801 | 125816 | assert( nData==(pRtree->nDim*2 + 3) ); |
| 124802 | 125817 | if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ |
| 124803 | 125818 | for(ii=0; ii<(pRtree->nDim*2); ii+=2){ |
| @@ -124817,22 +125832,53 @@ | ||
| 124817 | 125832 | goto constraint; |
| 124818 | 125833 | } |
| 124819 | 125834 | } |
| 124820 | 125835 | } |
| 124821 | 125836 | |
| 124822 | - /* Figure out the rowid of the new row. */ | |
| 124823 | - if( sqlite3_value_type(azData[2])==SQLITE_NULL ){ | |
| 124824 | - rc = newRowid(pRtree, &cell.iRowid); | |
| 124825 | - }else{ | |
| 125837 | + /* If a rowid value was supplied, check if it is already present in | |
| 125838 | + ** the table. If so, the constraint has failed. */ | |
| 125839 | + if( sqlite3_value_type(azData[2])!=SQLITE_NULL ){ | |
| 124826 | 125840 | cell.iRowid = sqlite3_value_int64(azData[2]); |
| 124827 | - sqlite3_bind_int64(pRtree->pReadRowid, 1, cell.iRowid); | |
| 124828 | - if( SQLITE_ROW==sqlite3_step(pRtree->pReadRowid) ){ | |
| 124829 | - sqlite3_reset(pRtree->pReadRowid); | |
| 124830 | - rc = SQLITE_CONSTRAINT; | |
| 124831 | - goto constraint; | |
| 125841 | + if( sqlite3_value_type(azData[0])==SQLITE_NULL | |
| 125842 | + || sqlite3_value_int64(azData[0])!=cell.iRowid | |
| 125843 | + ){ | |
| 125844 | + int steprc; | |
| 125845 | + sqlite3_bind_int64(pRtree->pReadRowid, 1, cell.iRowid); | |
| 125846 | + steprc = sqlite3_step(pRtree->pReadRowid); | |
| 125847 | + rc = sqlite3_reset(pRtree->pReadRowid); | |
| 125848 | + if( SQLITE_ROW==steprc ){ | |
| 125849 | + if( sqlite3_vtab_on_conflict(pRtree->db)==SQLITE_REPLACE ){ | |
| 125850 | + rc = rtreeDeleteRowid(pRtree, cell.iRowid); | |
| 125851 | + }else{ | |
| 125852 | + rc = SQLITE_CONSTRAINT; | |
| 125853 | + goto constraint; | |
| 125854 | + } | |
| 125855 | + } | |
| 124832 | 125856 | } |
| 124833 | - rc = sqlite3_reset(pRtree->pReadRowid); | |
| 125857 | + bHaveRowid = 1; | |
| 125858 | + } | |
| 125859 | + } | |
| 125860 | + | |
| 125861 | + /* If azData[0] is not an SQL NULL value, it is the rowid of a | |
| 125862 | + ** record to delete from the r-tree table. The following block does | |
| 125863 | + ** just that. | |
| 125864 | + */ | |
| 125865 | + if( sqlite3_value_type(azData[0])!=SQLITE_NULL ){ | |
| 125866 | + rc = rtreeDeleteRowid(pRtree, sqlite3_value_int64(azData[0])); | |
| 125867 | + } | |
| 125868 | + | |
| 125869 | + /* If the azData[] array contains more than one element, elements | |
| 125870 | + ** (azData[2]..azData[argc-1]) contain a new record to insert into | |
| 125871 | + ** the r-tree structure. | |
| 125872 | + */ | |
| 125873 | + if( rc==SQLITE_OK && nData>1 ){ | |
| 125874 | + /* Insert the new record into the r-tree */ | |
| 125875 | + RtreeNode *pLeaf; | |
| 125876 | + | |
| 125877 | + /* Figure out the rowid of the new row. */ | |
| 125878 | + if( bHaveRowid==0 ){ | |
| 125879 | + rc = newRowid(pRtree, &cell.iRowid); | |
| 124834 | 125880 | } |
| 124835 | 125881 | *pRowid = cell.iRowid; |
| 124836 | 125882 | |
| 124837 | 125883 | if( rc==SQLITE_OK ){ |
| 124838 | 125884 | rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf); |
| @@ -125068,10 +126114,12 @@ | ||
| 125068 | 126114 | int iErr = (argc<6) ? 2 : argc>(RTREE_MAX_DIMENSIONS*2+4) ? 3 : argc%2; |
| 125069 | 126115 | if( aErrMsg[iErr] ){ |
| 125070 | 126116 | *pzErr = sqlite3_mprintf("%s", aErrMsg[iErr]); |
| 125071 | 126117 | return SQLITE_ERROR; |
| 125072 | 126118 | } |
| 126119 | + | |
| 126120 | + sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1); | |
| 125073 | 126121 | |
| 125074 | 126122 | /* Allocate the sqlite3_vtab structure */ |
| 125075 | 126123 | nDb = strlen(argv[1]); |
| 125076 | 126124 | nName = strlen(argv[2]); |
| 125077 | 126125 | pRtree = (Rtree *)sqlite3_malloc(sizeof(Rtree)+nDb+nName+2); |
| 125078 | 126126 |
| --- 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.7.6.1. 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. |
| @@ -648,13 +648,13 @@ | |
| 648 | ** |
| 649 | ** See also: [sqlite3_libversion()], |
| 650 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 651 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 652 | */ |
| 653 | #define SQLITE_VERSION "3.7.6.1" |
| 654 | #define SQLITE_VERSION_NUMBER 3007006 |
| 655 | #define SQLITE_SOURCE_ID "2011-04-27 19:54:44 f55156c5194e85c47728b8a97fde3e5f0a5c9b56" |
| 656 | |
| 657 | /* |
| 658 | ** CAPI3REF: Run-Time Library Version Numbers |
| 659 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 660 | ** |
| @@ -916,11 +916,12 @@ | |
| 916 | ** Many SQLite functions return an integer result code from the set shown |
| 917 | ** here in order to indicates success or failure. |
| 918 | ** |
| 919 | ** New error codes may be added in future versions of SQLite. |
| 920 | ** |
| 921 | ** See also: [SQLITE_IOERR_READ | extended result codes] |
| 922 | */ |
| 923 | #define SQLITE_OK 0 /* Successful result */ |
| 924 | /* beginning-of-error-codes */ |
| 925 | #define SQLITE_ERROR 1 /* SQL error or missing database */ |
| 926 | #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ |
| @@ -998,25 +999,26 @@ | |
| 998 | #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) |
| 999 | #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) |
| 1000 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 1001 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 1002 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 1003 | |
| 1004 | /* |
| 1005 | ** CAPI3REF: Flags For File Open Operations |
| 1006 | ** |
| 1007 | ** These bit values are intended for use in the |
| 1008 | ** 3rd parameter to the [sqlite3_open_v2()] interface and |
| 1009 | ** in the 4th parameter to the xOpen method of the |
| 1010 | ** [sqlite3_vfs] object. |
| 1011 | */ |
| 1012 | #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ |
| 1013 | #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ |
| 1014 | #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ |
| 1015 | #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ |
| 1016 | #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ |
| 1017 | #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ |
| 1018 | #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ |
| 1019 | #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ |
| 1020 | #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ |
| 1021 | #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ |
| 1022 | #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ |
| @@ -1123,21 +1125,22 @@ | |
| 1123 | }; |
| 1124 | |
| 1125 | /* |
| 1126 | ** CAPI3REF: OS Interface File Virtual Methods Object |
| 1127 | ** |
| 1128 | ** Every file opened by the [sqlite3_vfs] xOpen method populates an |
| 1129 | ** [sqlite3_file] object (or, more commonly, a subclass of the |
| 1130 | ** [sqlite3_file] object) with a pointer to an instance of this object. |
| 1131 | ** This object defines the methods used to perform various operations |
| 1132 | ** against the open file represented by the [sqlite3_file] object. |
| 1133 | ** |
| 1134 | ** If the xOpen method sets the sqlite3_file.pMethods element |
| 1135 | ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method |
| 1136 | ** may be invoked even if the xOpen reported that it failed. The |
| 1137 | ** only way to prevent a call to xClose following a failed xOpen |
| 1138 | ** is for the xOpen to set the sqlite3_file.pMethods element to NULL. |
| 1139 | ** |
| 1140 | ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or |
| 1141 | ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync(). |
| 1142 | ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY] |
| 1143 | ** flag may be ORed in to indicate that only the data of the file |
| @@ -1302,10 +1305,11 @@ | |
| 1302 | */ |
| 1303 | typedef struct sqlite3_mutex sqlite3_mutex; |
| 1304 | |
| 1305 | /* |
| 1306 | ** CAPI3REF: OS Interface Object |
| 1307 | ** |
| 1308 | ** An instance of the sqlite3_vfs object defines the interface between |
| 1309 | ** the SQLite core and the underlying operating system. The "vfs" |
| 1310 | ** in the name of the object stands for "virtual file system". |
| 1311 | ** |
| @@ -1334,10 +1338,11 @@ | |
| 1334 | ** object once the object has been registered. |
| 1335 | ** |
| 1336 | ** The zName field holds the name of the VFS module. The name must |
| 1337 | ** be unique across all VFS modules. |
| 1338 | ** |
| 1339 | ** ^SQLite guarantees that the zFilename parameter to xOpen |
| 1340 | ** is either a NULL pointer or string obtained |
| 1341 | ** from xFullPathname() with an optional suffix added. |
| 1342 | ** ^If a suffix is added to the zFilename parameter, it will |
| 1343 | ** consist of a single "-" character followed by no more than |
| @@ -1411,10 +1416,11 @@ | |
| 1411 | ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do |
| 1412 | ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods |
| 1413 | ** element will be valid after xOpen returns regardless of the success |
| 1414 | ** or failure of the xOpen call. |
| 1415 | ** |
| 1416 | ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] |
| 1417 | ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to |
| 1418 | ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ] |
| 1419 | ** to test whether a file is at least readable. The file can be a |
| 1420 | ** directory. |
| @@ -1657,13 +1663,13 @@ | |
| 1657 | ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE. |
| 1658 | ** Note, however, that ^sqlite3_config() can be called as part of the |
| 1659 | ** implementation of an application-defined [sqlite3_os_init()]. |
| 1660 | ** |
| 1661 | ** The first argument to sqlite3_config() is an integer |
| 1662 | ** [SQLITE_CONFIG_SINGLETHREAD | configuration option] that determines |
| 1663 | ** what property of SQLite is to be configured. Subsequent arguments |
| 1664 | ** vary depending on the [SQLITE_CONFIG_SINGLETHREAD | configuration option] |
| 1665 | ** in the first argument. |
| 1666 | ** |
| 1667 | ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. |
| 1668 | ** ^If the option is unknown or SQLite is unable to set the option |
| 1669 | ** then this routine returns a non-zero [error code]. |
| @@ -1769,10 +1775,11 @@ | |
| 1769 | void *pAppData; /* Argument to xInit() and xShutdown() */ |
| 1770 | }; |
| 1771 | |
| 1772 | /* |
| 1773 | ** CAPI3REF: Configuration Options |
| 1774 | ** |
| 1775 | ** These constants are the available integer configuration options that |
| 1776 | ** can be passed as the first argument to the [sqlite3_config()] interface. |
| 1777 | ** |
| 1778 | ** New configuration options may be added in future releases of SQLite. |
| @@ -1781,11 +1788,11 @@ | |
| 1781 | ** the call worked. The [sqlite3_config()] interface will return a |
| 1782 | ** non-zero [error code] if a discontinued or unsupported configuration option |
| 1783 | ** is invoked. |
| 1784 | ** |
| 1785 | ** <dl> |
| 1786 | ** <dt>SQLITE_CONFIG_SINGLETHREAD</dt> |
| 1787 | ** <dd>There are no arguments to this option. ^This option sets the |
| 1788 | ** [threading mode] to Single-thread. In other words, it disables |
| 1789 | ** all mutexing and puts SQLite into a mode where it can only be used |
| 1790 | ** by a single thread. ^If SQLite is compiled with |
| 1791 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| @@ -1792,11 +1799,11 @@ | |
| 1792 | ** it is not possible to change the [threading mode] from its default |
| 1793 | ** value of Single-thread and so [sqlite3_config()] will return |
| 1794 | ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD |
| 1795 | ** configuration option.</dd> |
| 1796 | ** |
| 1797 | ** <dt>SQLITE_CONFIG_MULTITHREAD</dt> |
| 1798 | ** <dd>There are no arguments to this option. ^This option sets the |
| 1799 | ** [threading mode] to Multi-thread. In other words, it disables |
| 1800 | ** mutexing on [database connection] and [prepared statement] objects. |
| 1801 | ** The application is responsible for serializing access to |
| 1802 | ** [database connections] and [prepared statements]. But other mutexes |
| @@ -1806,11 +1813,11 @@ | |
| 1806 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1807 | ** it is not possible to set the Multi-thread [threading mode] and |
| 1808 | ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
| 1809 | ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd> |
| 1810 | ** |
| 1811 | ** <dt>SQLITE_CONFIG_SERIALIZED</dt> |
| 1812 | ** <dd>There are no arguments to this option. ^This option sets the |
| 1813 | ** [threading mode] to Serialized. In other words, this option enables |
| 1814 | ** all mutexes including the recursive |
| 1815 | ** mutexes on [database connection] and [prepared statement] objects. |
| 1816 | ** In this mode (which is the default when SQLite is compiled with |
| @@ -1822,27 +1829,27 @@ | |
| 1822 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1823 | ** it is not possible to set the Serialized [threading mode] and |
| 1824 | ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
| 1825 | ** SQLITE_CONFIG_SERIALIZED configuration option.</dd> |
| 1826 | ** |
| 1827 | ** <dt>SQLITE_CONFIG_MALLOC</dt> |
| 1828 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1829 | ** instance of the [sqlite3_mem_methods] structure. The argument specifies |
| 1830 | ** alternative low-level memory allocation routines to be used in place of |
| 1831 | ** the memory allocation routines built into SQLite.)^ ^SQLite makes |
| 1832 | ** its own private copy of the content of the [sqlite3_mem_methods] structure |
| 1833 | ** before the [sqlite3_config()] call returns.</dd> |
| 1834 | ** |
| 1835 | ** <dt>SQLITE_CONFIG_GETMALLOC</dt> |
| 1836 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1837 | ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods] |
| 1838 | ** structure is filled with the currently defined memory allocation routines.)^ |
| 1839 | ** This option can be used to overload the default memory allocation |
| 1840 | ** routines with a wrapper that simulations memory allocation failure or |
| 1841 | ** tracks memory usage, for example. </dd> |
| 1842 | ** |
| 1843 | ** <dt>SQLITE_CONFIG_MEMSTATUS</dt> |
| 1844 | ** <dd> ^This option takes single argument of type int, interpreted as a |
| 1845 | ** boolean, which enables or disables the collection of memory allocation |
| 1846 | ** statistics. ^(When memory allocation statistics are disabled, the |
| 1847 | ** following SQLite interfaces become non-operational: |
| 1848 | ** <ul> |
| @@ -1854,11 +1861,11 @@ | |
| 1854 | ** ^Memory allocation statistics are enabled by default unless SQLite is |
| 1855 | ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory |
| 1856 | ** allocation statistics are disabled by default. |
| 1857 | ** </dd> |
| 1858 | ** |
| 1859 | ** <dt>SQLITE_CONFIG_SCRATCH</dt> |
| 1860 | ** <dd> ^This option specifies a static memory buffer that SQLite can use for |
| 1861 | ** scratch memory. There are three arguments: A pointer an 8-byte |
| 1862 | ** aligned memory buffer from which the scratch allocations will be |
| 1863 | ** drawn, the size of each scratch allocation (sz), |
| 1864 | ** and the maximum number of scratch allocations (N). The sz |
| @@ -1870,11 +1877,11 @@ | |
| 1870 | ** ^SQLite will never require a scratch buffer that is more than 6 |
| 1871 | ** times the database page size. ^If SQLite needs needs additional |
| 1872 | ** scratch memory beyond what is provided by this configuration option, then |
| 1873 | ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd> |
| 1874 | ** |
| 1875 | ** <dt>SQLITE_CONFIG_PAGECACHE</dt> |
| 1876 | ** <dd> ^This option specifies a static memory buffer that SQLite can use for |
| 1877 | ** the database page cache with the default page cache implemenation. |
| 1878 | ** This configuration should not be used if an application-define page |
| 1879 | ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option. |
| 1880 | ** There are three arguments to this option: A pointer to 8-byte aligned |
| @@ -1891,11 +1898,11 @@ | |
| 1891 | ** SQLite goes to [sqlite3_malloc()] for the additional storage space. |
| 1892 | ** The pointer in the first argument must |
| 1893 | ** be aligned to an 8-byte boundary or subsequent behavior of SQLite |
| 1894 | ** will be undefined.</dd> |
| 1895 | ** |
| 1896 | ** <dt>SQLITE_CONFIG_HEAP</dt> |
| 1897 | ** <dd> ^This option specifies a static memory buffer that SQLite will use |
| 1898 | ** for all of its dynamic memory allocation needs beyond those provided |
| 1899 | ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. |
| 1900 | ** There are three arguments: An 8-byte aligned pointer to the memory, |
| 1901 | ** the number of bytes in the memory buffer, and the minimum allocation size. |
| @@ -1908,11 +1915,11 @@ | |
| 1908 | ** The first pointer (the memory pointer) must be aligned to an 8-byte |
| 1909 | ** boundary or subsequent behavior of SQLite will be undefined. |
| 1910 | ** The minimum allocation size is capped at 2^12. Reasonable values |
| 1911 | ** for the minimum allocation size are 2^5 through 2^8.</dd> |
| 1912 | ** |
| 1913 | ** <dt>SQLITE_CONFIG_MUTEX</dt> |
| 1914 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1915 | ** instance of the [sqlite3_mutex_methods] structure. The argument specifies |
| 1916 | ** alternative low-level mutex routines to be used in place |
| 1917 | ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the |
| 1918 | ** content of the [sqlite3_mutex_methods] structure before the call to |
| @@ -1920,11 +1927,11 @@ | |
| 1920 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1921 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1922 | ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will |
| 1923 | ** return [SQLITE_ERROR].</dd> |
| 1924 | ** |
| 1925 | ** <dt>SQLITE_CONFIG_GETMUTEX</dt> |
| 1926 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1927 | ** instance of the [sqlite3_mutex_methods] structure. The |
| 1928 | ** [sqlite3_mutex_methods] |
| 1929 | ** structure is filled with the currently defined mutex routines.)^ |
| 1930 | ** This option can be used to overload the default mutex allocation |
| @@ -1933,32 +1940,32 @@ | |
| 1933 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1934 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1935 | ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will |
| 1936 | ** return [SQLITE_ERROR].</dd> |
| 1937 | ** |
| 1938 | ** <dt>SQLITE_CONFIG_LOOKASIDE</dt> |
| 1939 | ** <dd> ^(This option takes two arguments that determine the default |
| 1940 | ** memory allocation for the lookaside memory allocator on each |
| 1941 | ** [database connection]. The first argument is the |
| 1942 | ** size of each lookaside buffer slot and the second is the number of |
| 1943 | ** slots allocated to each database connection.)^ ^(This option sets the |
| 1944 | ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] |
| 1945 | ** verb to [sqlite3_db_config()] can be used to change the lookaside |
| 1946 | ** configuration on individual connections.)^ </dd> |
| 1947 | ** |
| 1948 | ** <dt>SQLITE_CONFIG_PCACHE</dt> |
| 1949 | ** <dd> ^(This option takes a single argument which is a pointer to |
| 1950 | ** an [sqlite3_pcache_methods] object. This object specifies the interface |
| 1951 | ** to a custom page cache implementation.)^ ^SQLite makes a copy of the |
| 1952 | ** object and uses it for page cache memory allocations.</dd> |
| 1953 | ** |
| 1954 | ** <dt>SQLITE_CONFIG_GETPCACHE</dt> |
| 1955 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1956 | ** [sqlite3_pcache_methods] object. SQLite copies of the current |
| 1957 | ** page cache implementation into that object.)^ </dd> |
| 1958 | ** |
| 1959 | ** <dt>SQLITE_CONFIG_LOG</dt> |
| 1960 | ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a |
| 1961 | ** function with a call signature of void(*)(void*,int,const char*), |
| 1962 | ** and a pointer to void. ^If the function pointer is not NULL, it is |
| 1963 | ** invoked by [sqlite3_log()] to process each logging event. ^If the |
| 1964 | ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op. |
| @@ -1972,10 +1979,22 @@ | |
| 1972 | ** The SQLite logging interface is not reentrant; the logger function |
| 1973 | ** supplied by the application must not invoke any SQLite interface. |
| 1974 | ** In a multi-threaded application, the application-defined logger |
| 1975 | ** function must be threadsafe. </dd> |
| 1976 | ** |
| 1977 | ** </dl> |
| 1978 | */ |
| 1979 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1980 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 1981 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| @@ -1990,10 +2009,11 @@ | |
| 1990 | /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ |
| 1991 | #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ |
| 1992 | #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */ |
| 1993 | #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */ |
| 1994 | #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ |
| 1995 | |
| 1996 | /* |
| 1997 | ** CAPI3REF: Database Connection Configuration Options |
| 1998 | ** |
| 1999 | ** These constants are the available integer configuration options that |
| @@ -2075,17 +2095,21 @@ | |
| 2075 | ** the table has a column of type [INTEGER PRIMARY KEY] then that column |
| 2076 | ** is another alias for the rowid. |
| 2077 | ** |
| 2078 | ** ^This routine returns the [rowid] of the most recent |
| 2079 | ** successful [INSERT] into the database from the [database connection] |
| 2080 | ** in the first argument. ^If no successful [INSERT]s |
| 2081 | ** have ever occurred on that database connection, zero is returned. |
| 2082 | ** |
| 2083 | ** ^(If an [INSERT] occurs within a trigger, then the [rowid] of the inserted |
| 2084 | ** row is returned by this routine as long as the trigger is running. |
| 2085 | ** But once the trigger terminates, the value returned by this routine |
| 2086 | ** reverts to the last value inserted before the trigger fired.)^ |
| 2087 | ** |
| 2088 | ** ^An [INSERT] that fails due to a constraint violation is not a |
| 2089 | ** successful [INSERT] and does not change the value returned by this |
| 2090 | ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK, |
| 2091 | ** and INSERT OR ABORT make no changes to the return value of this |
| @@ -2744,10 +2768,13 @@ | |
| 2744 | ** The [sqlite3_set_authorizer | authorizer callback function] must |
| 2745 | ** return either [SQLITE_OK] or one of these two constants in order |
| 2746 | ** to signal SQLite whether or not the action is permitted. See the |
| 2747 | ** [sqlite3_set_authorizer | authorizer documentation] for additional |
| 2748 | ** information. |
| 2749 | */ |
| 2750 | #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ |
| 2751 | #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ |
| 2752 | |
| 2753 | /* |
| @@ -2866,11 +2893,11 @@ | |
| 2866 | SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); |
| 2867 | |
| 2868 | /* |
| 2869 | ** CAPI3REF: Opening A New Database Connection |
| 2870 | ** |
| 2871 | ** ^These routines open an SQLite database file whose name is given by the |
| 2872 | ** filename argument. ^The filename argument is interpreted as UTF-8 for |
| 2873 | ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte |
| 2874 | ** order for sqlite3_open16(). ^(A [database connection] handle is usually |
| 2875 | ** returned in *ppDb, even if an error occurs. The only exception is that |
| 2876 | ** if SQLite is unable to allocate memory to hold the [sqlite3] object, |
| @@ -2893,11 +2920,11 @@ | |
| 2893 | ** except that it accepts two additional parameters for additional control |
| 2894 | ** over the new database connection. ^(The flags parameter to |
| 2895 | ** sqlite3_open_v2() can take one of |
| 2896 | ** the following three values, optionally combined with the |
| 2897 | ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE], |
| 2898 | ** and/or [SQLITE_OPEN_PRIVATECACHE] flags:)^ |
| 2899 | ** |
| 2900 | ** <dl> |
| 2901 | ** ^(<dt>[SQLITE_OPEN_READONLY]</dt> |
| 2902 | ** <dd>The database is opened in read-only mode. If the database does not |
| 2903 | ** already exist, an error is returned.</dd>)^ |
| @@ -2912,13 +2939,12 @@ | |
| 2912 | ** it does not already exist. This is the behavior that is always used for |
| 2913 | ** sqlite3_open() and sqlite3_open16().</dd>)^ |
| 2914 | ** </dl> |
| 2915 | ** |
| 2916 | ** If the 3rd parameter to sqlite3_open_v2() is not one of the |
| 2917 | ** combinations shown above or one of the combinations shown above combined |
| 2918 | ** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], |
| 2919 | ** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_PRIVATECACHE] flags, |
| 2920 | ** then the behavior is undefined. |
| 2921 | ** |
| 2922 | ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection |
| 2923 | ** opens in the multi-thread [threading mode] as long as the single-thread |
| 2924 | ** mode has not been set at compile-time or start-time. ^If the |
| @@ -2928,10 +2954,15 @@ | |
| 2928 | ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be |
| 2929 | ** eligible to use [shared cache mode], regardless of whether or not shared |
| 2930 | ** cache is enabled using [sqlite3_enable_shared_cache()]. ^The |
| 2931 | ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not |
| 2932 | ** participate in [shared cache mode] even if it is enabled. |
| 2933 | ** |
| 2934 | ** ^If the filename is ":memory:", then a private, temporary in-memory database |
| 2935 | ** is created for the connection. ^This in-memory database will vanish when |
| 2936 | ** the database connection is closed. Future versions of SQLite might |
| 2937 | ** make use of additional special filenames that begin with the ":" character. |
| @@ -2941,14 +2972,115 @@ | |
| 2941 | ** |
| 2942 | ** ^If the filename is an empty string, then a private, temporary |
| 2943 | ** on-disk database will be created. ^This private database will be |
| 2944 | ** automatically deleted as soon as the database connection is closed. |
| 2945 | ** |
| 2946 | ** ^The fourth parameter to sqlite3_open_v2() is the name of the |
| 2947 | ** [sqlite3_vfs] object that defines the operating system interface that |
| 2948 | ** the new database connection should use. ^If the fourth parameter is |
| 2949 | ** a NULL pointer then the default [sqlite3_vfs] object is used. |
| 2950 | ** |
| 2951 | ** <b>Note to Windows users:</b> The encoding used for the filename argument |
| 2952 | ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever |
| 2953 | ** codepage is currently defined. Filenames containing international |
| 2954 | ** characters must be converted to UTF-8 prior to passing them into |
| @@ -2966,10 +3098,30 @@ | |
| 2966 | const char *filename, /* Database filename (UTF-8) */ |
| 2967 | sqlite3 **ppDb, /* OUT: SQLite db handle */ |
| 2968 | int flags, /* Flags */ |
| 2969 | const char *zVfs /* Name of VFS module to use */ |
| 2970 | ); |
| 2971 | |
| 2972 | /* |
| 2973 | ** CAPI3REF: Error Codes And Messages |
| 2974 | ** |
| 2975 | ** ^The sqlite3_errcode() interface returns the numeric [result code] or |
| @@ -3082,47 +3234,49 @@ | |
| 3082 | ** that can be lowered at run-time using [sqlite3_limit()]. |
| 3083 | ** The synopsis of the meanings of the various limits is shown below. |
| 3084 | ** Additional information is available at [limits | Limits in SQLite]. |
| 3085 | ** |
| 3086 | ** <dl> |
| 3087 | ** ^(<dt>SQLITE_LIMIT_LENGTH</dt> |
| 3088 | ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^ |
| 3089 | ** |
| 3090 | ** ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt> |
| 3091 | ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^ |
| 3092 | ** |
| 3093 | ** ^(<dt>SQLITE_LIMIT_COLUMN</dt> |
| 3094 | ** <dd>The maximum number of columns in a table definition or in the |
| 3095 | ** result set of a [SELECT] or the maximum number of columns in an index |
| 3096 | ** or in an ORDER BY or GROUP BY clause.</dd>)^ |
| 3097 | ** |
| 3098 | ** ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> |
| 3099 | ** <dd>The maximum depth of the parse tree on any expression.</dd>)^ |
| 3100 | ** |
| 3101 | ** ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt> |
| 3102 | ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^ |
| 3103 | ** |
| 3104 | ** ^(<dt>SQLITE_LIMIT_VDBE_OP</dt> |
| 3105 | ** <dd>The maximum number of instructions in a virtual machine program |
| 3106 | ** used to implement an SQL statement. This limit is not currently |
| 3107 | ** enforced, though that might be added in some future release of |
| 3108 | ** SQLite.</dd>)^ |
| 3109 | ** |
| 3110 | ** ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt> |
| 3111 | ** <dd>The maximum number of arguments on a function.</dd>)^ |
| 3112 | ** |
| 3113 | ** ^(<dt>SQLITE_LIMIT_ATTACHED</dt> |
| 3114 | ** <dd>The maximum number of [ATTACH | attached databases].)^</dd> |
| 3115 | ** |
| 3116 | ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt> |
| 3117 | ** <dd>The maximum length of the pattern argument to the [LIKE] or |
| 3118 | ** [GLOB] operators.</dd>)^ |
| 3119 | ** |
| 3120 | ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> |
| 3121 | ** <dd>The maximum index number of any [parameter] in an SQL statement.)^ |
| 3122 | ** |
| 3123 | ** ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> |
| 3124 | ** <dd>The maximum depth of recursion for triggers.</dd>)^ |
| 3125 | ** </dl> |
| 3126 | */ |
| 3127 | #define SQLITE_LIMIT_LENGTH 0 |
| 3128 | #define SQLITE_LIMIT_SQL_LENGTH 1 |
| @@ -5153,10 +5307,15 @@ | |
| 5153 | int (*xRollback)(sqlite3_vtab *pVTab); |
| 5154 | int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName, |
| 5155 | void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), |
| 5156 | void **ppArg); |
| 5157 | int (*xRename)(sqlite3_vtab *pVtab, const char *zNew); |
| 5158 | }; |
| 5159 | |
| 5160 | /* |
| 5161 | ** CAPI3REF: Virtual Table Indexing Information |
| 5162 | ** KEYWORDS: sqlite3_index_info |
| @@ -5967,11 +6126,11 @@ | |
| 5967 | ** |
| 5968 | ** ^This interface is used to retrieve runtime status information |
| 5969 | ** about the performance of SQLite, and optionally to reset various |
| 5970 | ** highwater marks. ^The first argument is an integer code for |
| 5971 | ** the specific parameter to measure. ^(Recognized integer codes |
| 5972 | ** are of the form [SQLITE_STATUS_MEMORY_USED | SQLITE_STATUS_...].)^ |
| 5973 | ** ^The current value of the parameter is returned into *pCurrent. |
| 5974 | ** ^The highest recorded value is returned in *pHighwater. ^If the |
| 5975 | ** resetFlag is true, then the highest record value is reset after |
| 5976 | ** *pHighwater is written. ^(Some parameters do not record the highest |
| 5977 | ** value. For those parameters |
| @@ -5994,82 +6153,84 @@ | |
| 5994 | SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); |
| 5995 | |
| 5996 | |
| 5997 | /* |
| 5998 | ** CAPI3REF: Status Parameters |
| 5999 | ** |
| 6000 | ** These integer constants designate various run-time status parameters |
| 6001 | ** that can be returned by [sqlite3_status()]. |
| 6002 | ** |
| 6003 | ** <dl> |
| 6004 | ** ^(<dt>SQLITE_STATUS_MEMORY_USED</dt> |
| 6005 | ** <dd>This parameter is the current amount of memory checked out |
| 6006 | ** using [sqlite3_malloc()], either directly or indirectly. The |
| 6007 | ** figure includes calls made to [sqlite3_malloc()] by the application |
| 6008 | ** and internal memory usage by the SQLite library. Scratch memory |
| 6009 | ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache |
| 6010 | ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in |
| 6011 | ** this parameter. The amount returned is the sum of the allocation |
| 6012 | ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^ |
| 6013 | ** |
| 6014 | ** ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt> |
| 6015 | ** <dd>This parameter records the largest memory allocation request |
| 6016 | ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their |
| 6017 | ** internal equivalents). Only the value returned in the |
| 6018 | ** *pHighwater parameter to [sqlite3_status()] is of interest. |
| 6019 | ** The value written into the *pCurrent parameter is undefined.</dd>)^ |
| 6020 | ** |
| 6021 | ** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt> |
| 6022 | ** <dd>This parameter records the number of separate memory allocations |
| 6023 | ** currently checked out.</dd>)^ |
| 6024 | ** |
| 6025 | ** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt> |
| 6026 | ** <dd>This parameter returns the number of pages used out of the |
| 6027 | ** [pagecache memory allocator] that was configured using |
| 6028 | ** [SQLITE_CONFIG_PAGECACHE]. The |
| 6029 | ** value returned is in pages, not in bytes.</dd>)^ |
| 6030 | ** |
| 6031 | ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt> |
| 6032 | ** <dd>This parameter returns the number of bytes of page cache |
| 6033 | ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE] |
| 6034 | ** buffer and where forced to overflow to [sqlite3_malloc()]. The |
| 6035 | ** returned value includes allocations that overflowed because they |
| 6036 | ** where too large (they were larger than the "sz" parameter to |
| 6037 | ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because |
| 6038 | ** no space was left in the page cache.</dd>)^ |
| 6039 | ** |
| 6040 | ** ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt> |
| 6041 | ** <dd>This parameter records the largest memory allocation request |
| 6042 | ** handed to [pagecache memory allocator]. Only the value returned in the |
| 6043 | ** *pHighwater parameter to [sqlite3_status()] is of interest. |
| 6044 | ** The value written into the *pCurrent parameter is undefined.</dd>)^ |
| 6045 | ** |
| 6046 | ** ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt> |
| 6047 | ** <dd>This parameter returns the number of allocations used out of the |
| 6048 | ** [scratch memory allocator] configured using |
| 6049 | ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not |
| 6050 | ** in bytes. Since a single thread may only have one scratch allocation |
| 6051 | ** outstanding at time, this parameter also reports the number of threads |
| 6052 | ** using scratch memory at the same time.</dd>)^ |
| 6053 | ** |
| 6054 | ** ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt> |
| 6055 | ** <dd>This parameter returns the number of bytes of scratch memory |
| 6056 | ** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH] |
| 6057 | ** buffer and where forced to overflow to [sqlite3_malloc()]. The values |
| 6058 | ** returned include overflows because the requested allocation was too |
| 6059 | ** larger (that is, because the requested allocation was larger than the |
| 6060 | ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer |
| 6061 | ** slots were available. |
| 6062 | ** </dd>)^ |
| 6063 | ** |
| 6064 | ** ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt> |
| 6065 | ** <dd>This parameter records the largest memory allocation request |
| 6066 | ** handed to [scratch memory allocator]. Only the value returned in the |
| 6067 | ** *pHighwater parameter to [sqlite3_status()] is of interest. |
| 6068 | ** The value written into the *pCurrent parameter is undefined.</dd>)^ |
| 6069 | ** |
| 6070 | ** ^(<dt>SQLITE_STATUS_PARSER_STACK</dt> |
| 6071 | ** <dd>This parameter records the deepest parser stack. It is only |
| 6072 | ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^ |
| 6073 | ** </dl> |
| 6074 | ** |
| 6075 | ** New status parameters may be added from time to time. |
| @@ -6090,13 +6251,13 @@ | |
| 6090 | ** |
| 6091 | ** ^This interface is used to retrieve runtime status information |
| 6092 | ** about a single [database connection]. ^The first argument is the |
| 6093 | ** database connection object to be interrogated. ^The second argument |
| 6094 | ** is an integer constant, taken from the set of |
| 6095 | ** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros, that |
| 6096 | ** determines the parameter to interrogate. The set of |
| 6097 | ** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros is likely |
| 6098 | ** to grow in future releases of SQLite. |
| 6099 | ** |
| 6100 | ** ^The current value of the requested parameter is written into *pCur |
| 6101 | ** and the highest instantaneous value is written into *pHiwtr. ^If |
| 6102 | ** the resetFlg is true, then the highest instantaneous value is |
| @@ -6109,10 +6270,11 @@ | |
| 6109 | */ |
| 6110 | SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); |
| 6111 | |
| 6112 | /* |
| 6113 | ** CAPI3REF: Status Parameters for database connections |
| 6114 | ** |
| 6115 | ** These constants are the available integer "verbs" that can be passed as |
| 6116 | ** the second argument to the [sqlite3_db_status()] interface. |
| 6117 | ** |
| 6118 | ** New verbs may be added in future releases of SQLite. Existing verbs |
| @@ -6120,48 +6282,50 @@ | |
| 6120 | ** [sqlite3_db_status()] to make sure that the call worked. |
| 6121 | ** The [sqlite3_db_status()] interface will return a non-zero error code |
| 6122 | ** if a discontinued or unsupported verb is invoked. |
| 6123 | ** |
| 6124 | ** <dl> |
| 6125 | ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt> |
| 6126 | ** <dd>This parameter returns the number of lookaside memory slots currently |
| 6127 | ** checked out.</dd>)^ |
| 6128 | ** |
| 6129 | ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt> |
| 6130 | ** <dd>This parameter returns the number malloc attempts that were |
| 6131 | ** satisfied using lookaside memory. Only the high-water value is meaningful; |
| 6132 | ** the current value is always zero.)^ |
| 6133 | ** |
| 6134 | ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt> |
| 6135 | ** <dd>This parameter returns the number malloc attempts that might have |
| 6136 | ** been satisfied using lookaside memory but failed due to the amount of |
| 6137 | ** memory requested being larger than the lookaside slot size. |
| 6138 | ** Only the high-water value is meaningful; |
| 6139 | ** the current value is always zero.)^ |
| 6140 | ** |
| 6141 | ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt> |
| 6142 | ** <dd>This parameter returns the number malloc attempts that might have |
| 6143 | ** been satisfied using lookaside memory but failed due to all lookaside |
| 6144 | ** memory already being in use. |
| 6145 | ** Only the high-water value is meaningful; |
| 6146 | ** the current value is always zero.)^ |
| 6147 | ** |
| 6148 | ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt> |
| 6149 | ** <dd>This parameter returns the approximate number of of bytes of heap |
| 6150 | ** memory used by all pager caches associated with the database connection.)^ |
| 6151 | ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0. |
| 6152 | ** |
| 6153 | ** ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt> |
| 6154 | ** <dd>This parameter returns the approximate number of of bytes of heap |
| 6155 | ** memory used to store the schema for all databases associated |
| 6156 | ** with the connection - main, temp, and any [ATTACH]-ed databases.)^ |
| 6157 | ** ^The full amount of memory used by the schemas is reported, even if the |
| 6158 | ** schema memory is shared with other database connections due to |
| 6159 | ** [shared cache mode] being enabled. |
| 6160 | ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0. |
| 6161 | ** |
| 6162 | ** ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt> |
| 6163 | ** <dd>This parameter returns the approximate number of of bytes of heap |
| 6164 | ** and lookaside memory used by all prepared statements associated with |
| 6165 | ** the database connection.)^ |
| 6166 | ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0. |
| 6167 | ** </dd> |
| @@ -6179,11 +6343,11 @@ | |
| 6179 | |
| 6180 | /* |
| 6181 | ** CAPI3REF: Prepared Statement Status |
| 6182 | ** |
| 6183 | ** ^(Each prepared statement maintains various |
| 6184 | ** [SQLITE_STMTSTATUS_SORT | counters] that measure the number |
| 6185 | ** of times it has performed specific operations.)^ These counters can |
| 6186 | ** be used to monitor the performance characteristics of the prepared |
| 6187 | ** statements. For example, if the number of table steps greatly exceeds |
| 6188 | ** the number of table searches or result rows, that would tend to indicate |
| 6189 | ** that the prepared statement is using a full table scan rather than |
| @@ -6190,11 +6354,11 @@ | |
| 6190 | ** an index. |
| 6191 | ** |
| 6192 | ** ^(This interface is used to retrieve and reset counter values from |
| 6193 | ** a [prepared statement]. The first argument is the prepared statement |
| 6194 | ** object to be interrogated. The second argument |
| 6195 | ** is an integer code for a specific [SQLITE_STMTSTATUS_SORT | counter] |
| 6196 | ** to be interrogated.)^ |
| 6197 | ** ^The current value of the requested counter is returned. |
| 6198 | ** ^If the resetFlg is true, then the counter is reset to zero after this |
| 6199 | ** interface call returns. |
| 6200 | ** |
| @@ -6202,28 +6366,29 @@ | |
| 6202 | */ |
| 6203 | SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); |
| 6204 | |
| 6205 | /* |
| 6206 | ** CAPI3REF: Status Parameters for prepared statements |
| 6207 | ** |
| 6208 | ** These preprocessor macros define integer codes that name counter |
| 6209 | ** values associated with the [sqlite3_stmt_status()] interface. |
| 6210 | ** The meanings of the various counters are as follows: |
| 6211 | ** |
| 6212 | ** <dl> |
| 6213 | ** <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt> |
| 6214 | ** <dd>^This is the number of times that SQLite has stepped forward in |
| 6215 | ** a table as part of a full table scan. Large numbers for this counter |
| 6216 | ** may indicate opportunities for performance improvement through |
| 6217 | ** careful use of indices.</dd> |
| 6218 | ** |
| 6219 | ** <dt>SQLITE_STMTSTATUS_SORT</dt> |
| 6220 | ** <dd>^This is the number of sort operations that have occurred. |
| 6221 | ** A non-zero value in this counter may indicate an opportunity to |
| 6222 | ** improvement performance through careful use of indices.</dd> |
| 6223 | ** |
| 6224 | ** <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt> |
| 6225 | ** <dd>^This is the number of rows inserted into transient indices that |
| 6226 | ** were created automatically in order to help joins run faster. |
| 6227 | ** A non-zero value in this counter may indicate an opportunity to |
| 6228 | ** improvement performance by adding permanent indices that do not |
| 6229 | ** need to be reinitialized each time the statement is run.</dd> |
| @@ -6270,10 +6435,11 @@ | |
| 6270 | ** ^(The contents of the sqlite3_pcache_methods structure are copied to an |
| 6271 | ** internal buffer by SQLite within the call to [sqlite3_config]. Hence |
| 6272 | ** the application may discard the parameter after the call to |
| 6273 | ** [sqlite3_config()] returns.)^ |
| 6274 | ** |
| 6275 | ** ^(The xInit() method is called once for each effective |
| 6276 | ** call to [sqlite3_initialize()])^ |
| 6277 | ** (usually only once during the lifetime of the process). ^(The xInit() |
| 6278 | ** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^ |
| 6279 | ** The intent of the xInit() method is to set up global data structures |
| @@ -6280,10 +6446,11 @@ | |
| 6280 | ** required by the custom page cache implementation. |
| 6281 | ** ^(If the xInit() method is NULL, then the |
| 6282 | ** built-in default page cache is used instead of the application defined |
| 6283 | ** page cache.)^ |
| 6284 | ** |
| 6285 | ** ^The xShutdown() method is called by [sqlite3_shutdown()]. |
| 6286 | ** It can be used to clean up |
| 6287 | ** any outstanding resources before process shutdown, if required. |
| 6288 | ** ^The xShutdown() method may be NULL. |
| 6289 | ** |
| @@ -6294,10 +6461,11 @@ | |
| 6294 | ** in multithreaded applications. |
| 6295 | ** |
| 6296 | ** ^SQLite will never invoke xInit() more than once without an intervening |
| 6297 | ** call to xShutdown(). |
| 6298 | ** |
| 6299 | ** ^SQLite invokes the xCreate() method to construct a new cache instance. |
| 6300 | ** SQLite will typically create one cache instance for each open database file, |
| 6301 | ** though this is not guaranteed. ^The |
| 6302 | ** first parameter, szPage, is the size in bytes of the pages that must |
| 6303 | ** be allocated by the cache. ^szPage will not be a power of two. ^szPage |
| @@ -6318,20 +6486,23 @@ | |
| 6318 | ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to |
| 6319 | ** false will always have the "discard" flag set to true. |
| 6320 | ** ^Hence, a cache created with bPurgeable false will |
| 6321 | ** never contain any unpinned pages. |
| 6322 | ** |
| 6323 | ** ^(The xCachesize() method may be called at any time by SQLite to set the |
| 6324 | ** suggested maximum cache-size (number of pages stored by) the cache |
| 6325 | ** instance passed as the first argument. This is the value configured using |
| 6326 | ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable |
| 6327 | ** parameter, the implementation is not required to do anything with this |
| 6328 | ** value; it is advisory only. |
| 6329 | ** |
| 6330 | ** The xPagecount() method must return the number of pages currently |
| 6331 | ** stored in the cache, both pinned and unpinned. |
| 6332 | ** |
| 6333 | ** The xFetch() method locates a page in the cache and returns a pointer to |
| 6334 | ** the page, or a NULL pointer. |
| 6335 | ** A "page", in this context, means a buffer of szPage bytes aligned at an |
| 6336 | ** 8-byte boundary. The page to be fetched is determined by the key. ^The |
| 6337 | ** mimimum key value is 1. After it has been retrieved using xFetch, the page |
| @@ -6356,10 +6527,11 @@ | |
| 6356 | ** will only use a createFlag of 2 after a prior call with a createFlag of 1 |
| 6357 | ** failed.)^ In between the to xFetch() calls, SQLite may |
| 6358 | ** attempt to unpin one or more cache pages by spilling the content of |
| 6359 | ** pinned pages to disk and synching the operating system disk cache. |
| 6360 | ** |
| 6361 | ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page |
| 6362 | ** as its second argument. If the third parameter, discard, is non-zero, |
| 6363 | ** then the page must be evicted from the cache. |
| 6364 | ** ^If the discard parameter is |
| 6365 | ** zero, then the page may be discarded or retained at the discretion of |
| @@ -6368,10 +6540,11 @@ | |
| 6368 | ** |
| 6369 | ** The cache must not perform any reference counting. A single |
| 6370 | ** call to xUnpin() unpins the page regardless of the number of prior calls |
| 6371 | ** to xFetch(). |
| 6372 | ** |
| 6373 | ** The xRekey() method is used to change the key value associated with the |
| 6374 | ** page passed as the second argument. If the cache |
| 6375 | ** previously contains an entry associated with newKey, it must be |
| 6376 | ** discarded. ^Any prior cache entry associated with newKey is guaranteed not |
| 6377 | ** to be pinned. |
| @@ -6380,10 +6553,11 @@ | |
| 6380 | ** existing cache entries with page numbers (keys) greater than or equal |
| 6381 | ** to the value of the iLimit parameter passed to xTruncate(). If any |
| 6382 | ** of these pages are pinned, they are implicitly unpinned, meaning that |
| 6383 | ** they can be safely discarded. |
| 6384 | ** |
| 6385 | ** ^The xDestroy() method is used to delete a cache allocated by xCreate(). |
| 6386 | ** All resources associated with the specified cache should be freed. ^After |
| 6387 | ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*] |
| 6388 | ** handle invalid, and will not use it with any other sqlite3_pcache_methods |
| 6389 | ** functions. |
| @@ -6442,11 +6616,11 @@ | |
| 6442 | ** associated with the backup operation. |
| 6443 | ** </ol>)^ |
| 6444 | ** There should be exactly one call to sqlite3_backup_finish() for each |
| 6445 | ** successful call to sqlite3_backup_init(). |
| 6446 | ** |
| 6447 | ** <b>sqlite3_backup_init()</b> |
| 6448 | ** |
| 6449 | ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the |
| 6450 | ** [database connection] associated with the destination database |
| 6451 | ** and the database name, respectively. |
| 6452 | ** ^The database name is "main" for the main database, "temp" for the |
| @@ -6469,11 +6643,11 @@ | |
| 6469 | ** [sqlite3_backup] object. |
| 6470 | ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and |
| 6471 | ** sqlite3_backup_finish() functions to perform the specified backup |
| 6472 | ** operation. |
| 6473 | ** |
| 6474 | ** <b>sqlite3_backup_step()</b> |
| 6475 | ** |
| 6476 | ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between |
| 6477 | ** the source and destination databases specified by [sqlite3_backup] object B. |
| 6478 | ** ^If N is negative, all remaining source pages are copied. |
| 6479 | ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there |
| @@ -6526,11 +6700,11 @@ | |
| 6526 | ** restarted by the next call to sqlite3_backup_step(). ^If the source |
| 6527 | ** database is modified by the using the same database connection as is used |
| 6528 | ** by the backup operation, then the backup database is automatically |
| 6529 | ** updated at the same time. |
| 6530 | ** |
| 6531 | ** <b>sqlite3_backup_finish()</b> |
| 6532 | ** |
| 6533 | ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the |
| 6534 | ** application wishes to abandon the backup operation, the application |
| 6535 | ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish(). |
| 6536 | ** ^The sqlite3_backup_finish() interfaces releases all |
| @@ -6549,11 +6723,12 @@ | |
| 6549 | ** |
| 6550 | ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step() |
| 6551 | ** is not a permanent error and does not affect the return value of |
| 6552 | ** sqlite3_backup_finish(). |
| 6553 | ** |
| 6554 | ** <b>sqlite3_backup_remaining(), sqlite3_backup_pagecount()</b> |
| 6555 | ** |
| 6556 | ** ^Each call to sqlite3_backup_step() sets two values inside |
| 6557 | ** the [sqlite3_backup] object: the number of pages still to be backed |
| 6558 | ** up and the total number of pages in the source database file. |
| 6559 | ** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces |
| @@ -6934,10 +7109,97 @@ | |
| 6934 | ** each of these values. |
| 6935 | */ |
| 6936 | #define SQLITE_CHECKPOINT_PASSIVE 0 |
| 6937 | #define SQLITE_CHECKPOINT_FULL 1 |
| 6938 | #define SQLITE_CHECKPOINT_RESTART 2 |
| 6939 | |
| 6940 | |
| 6941 | /* |
| 6942 | ** Undo the hack that converts floating point types to integer for |
| 6943 | ** builds on processors without floating point support. |
| @@ -7601,10 +7863,11 @@ | |
| 7601 | typedef struct Trigger Trigger; |
| 7602 | typedef struct TriggerPrg TriggerPrg; |
| 7603 | typedef struct TriggerStep TriggerStep; |
| 7604 | typedef struct UnpackedRecord UnpackedRecord; |
| 7605 | typedef struct VTable VTable; |
| 7606 | typedef struct Walker Walker; |
| 7607 | typedef struct WherePlan WherePlan; |
| 7608 | typedef struct WhereInfo WhereInfo; |
| 7609 | typedef struct WhereLevel WhereLevel; |
| 7610 | |
| @@ -7657,10 +7920,11 @@ | |
| 7657 | typedef struct BtCursor BtCursor; |
| 7658 | typedef struct BtShared BtShared; |
| 7659 | |
| 7660 | |
| 7661 | SQLITE_PRIVATE int sqlite3BtreeOpen( |
| 7662 | const char *zFilename, /* Name of database file to open */ |
| 7663 | sqlite3 *db, /* Associated database connection */ |
| 7664 | Btree **ppBtree, /* Return open Btree* here */ |
| 7665 | int flags, /* Flags */ |
| 7666 | int vfsFlags /* Flags passed through to VFS open */ |
| @@ -9136,19 +9400,20 @@ | |
| 9136 | struct sqlite3 { |
| 9137 | sqlite3_vfs *pVfs; /* OS Interface */ |
| 9138 | int nDb; /* Number of backends currently in use */ |
| 9139 | Db *aDb; /* All backends */ |
| 9140 | int flags; /* Miscellaneous flags. See below */ |
| 9141 | int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */ |
| 9142 | int errCode; /* Most recent error code (SQLITE_*) */ |
| 9143 | int errMask; /* & result codes with this before returning */ |
| 9144 | u8 autoCommit; /* The auto-commit flag. */ |
| 9145 | u8 temp_store; /* 1: file 2: memory 0: default */ |
| 9146 | u8 mallocFailed; /* True if we have seen a malloc failure */ |
| 9147 | u8 dfltLockMode; /* Default locking-mode for attached dbs */ |
| 9148 | signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */ |
| 9149 | u8 suppressErr; /* Do not issue error messages if true */ |
| 9150 | int nextPagesize; /* Pagesize after VACUUM if >0 */ |
| 9151 | int nTable; /* Number of tables in the database */ |
| 9152 | CollSeq *pDfltColl; /* The default collating sequence (BINARY) */ |
| 9153 | i64 lastRowid; /* ROWID of most recent insert (see above) */ |
| 9154 | u32 magic; /* Magic number for detect library misuse */ |
| @@ -9203,11 +9468,11 @@ | |
| 9203 | void *pProgressArg; /* Argument to the progress callback */ |
| 9204 | int nProgressOps; /* Number of opcodes for progress callback */ |
| 9205 | #endif |
| 9206 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 9207 | Hash aModule; /* populated by sqlite3_create_module() */ |
| 9208 | Table *pVTab; /* vtab with active Connect/Create method */ |
| 9209 | VTable **aVTrans; /* Virtual tables with open transactions */ |
| 9210 | int nVTrans; /* Allocated size of aVTrans */ |
| 9211 | VTable *pDisconnect; /* Disconnect these in next sqlite3_prepare() */ |
| 9212 | #endif |
| 9213 | FuncDefHash aFunc; /* Hash table of connection functions */ |
| @@ -9566,10 +9831,11 @@ | |
| 9566 | struct VTable { |
| 9567 | sqlite3 *db; /* Database connection associated with this table */ |
| 9568 | Module *pMod; /* Pointer to module implementation */ |
| 9569 | sqlite3_vtab *pVtab; /* Pointer to vtab instance */ |
| 9570 | int nRef; /* Number of pointers to this structure */ |
| 9571 | VTable *pNext; /* Next in linked list (see above) */ |
| 9572 | }; |
| 9573 | |
| 9574 | /* |
| 9575 | ** Each SQL table is represented in memory by an instance of the |
| @@ -10754,10 +11020,11 @@ | |
| 10754 | */ |
| 10755 | struct Sqlite3Config { |
| 10756 | int bMemstat; /* True to enable memory status */ |
| 10757 | int bCoreMutex; /* True to enable core mutexing */ |
| 10758 | int bFullMutex; /* True to enable full mutexing */ |
| 10759 | int mxStrlen; /* Maximum string length */ |
| 10760 | int szLookaside; /* Default lookaside buffer size */ |
| 10761 | int nLookaside; /* Default lookaside buffer count */ |
| 10762 | sqlite3_mem_methods m; /* Low-level memory allocation interface */ |
| 10763 | sqlite3_mutex_methods mutex; /* Low-level mutex interface */ |
| @@ -11003,10 +11270,12 @@ | |
| 11003 | SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*); |
| 11004 | SQLITE_PRIVATE void sqlite3AddColumnType(Parse*,Token*); |
| 11005 | SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,ExprSpan*); |
| 11006 | SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*); |
| 11007 | SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,Select*); |
| 11008 | |
| 11009 | SQLITE_PRIVATE Bitvec *sqlite3BitvecCreate(u32); |
| 11010 | SQLITE_PRIVATE int sqlite3BitvecTest(Bitvec*, u32); |
| 11011 | SQLITE_PRIVATE int sqlite3BitvecSet(Bitvec*, u32); |
| 11012 | SQLITE_PRIVATE void sqlite3BitvecClear(Bitvec*, u32, void*); |
| @@ -11253,10 +11522,11 @@ | |
| 11253 | SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity); |
| 11254 | SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr); |
| 11255 | SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8); |
| 11256 | SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...); |
| 11257 | SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n); |
| 11258 | SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); |
| 11259 | SQLITE_PRIVATE const char *sqlite3ErrStr(int); |
| 11260 | SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse); |
| 11261 | SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int); |
| 11262 | SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName); |
| @@ -11268,10 +11538,16 @@ | |
| 11268 | SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int); |
| 11269 | SQLITE_PRIVATE int sqlite3AddInt64(i64*,i64); |
| 11270 | SQLITE_PRIVATE int sqlite3SubInt64(i64*,i64); |
| 11271 | SQLITE_PRIVATE int sqlite3MulInt64(i64*,i64); |
| 11272 | SQLITE_PRIVATE int sqlite3AbsInt32(int); |
| 11273 | |
| 11274 | SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8); |
| 11275 | SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8); |
| 11276 | SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, |
| 11277 | void(*)(void*)); |
| @@ -11377,18 +11653,20 @@ | |
| 11377 | # define sqlite3VtabCommit(X) |
| 11378 | # define sqlite3VtabInSync(db) 0 |
| 11379 | # define sqlite3VtabLock(X) |
| 11380 | # define sqlite3VtabUnlock(X) |
| 11381 | # define sqlite3VtabUnlockList(X) |
| 11382 | #else |
| 11383 | SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*); |
| 11384 | SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **); |
| 11385 | SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db); |
| 11386 | SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db); |
| 11387 | SQLITE_PRIVATE void sqlite3VtabLock(VTable *); |
| 11388 | SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *); |
| 11389 | SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3*); |
| 11390 | # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0) |
| 11391 | #endif |
| 11392 | SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*); |
| 11393 | SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*); |
| 11394 | SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse*, Token*); |
| @@ -11691,20 +11969,23 @@ | |
| 11691 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* f0..f7 ........ */ |
| 11692 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 /* f8..ff ........ */ |
| 11693 | }; |
| 11694 | #endif |
| 11695 | |
| 11696 | |
| 11697 | |
| 11698 | /* |
| 11699 | ** The following singleton contains the global configuration for |
| 11700 | ** the SQLite library. |
| 11701 | */ |
| 11702 | SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = { |
| 11703 | SQLITE_DEFAULT_MEMSTATUS, /* bMemstat */ |
| 11704 | 1, /* bCoreMutex */ |
| 11705 | SQLITE_THREADSAFE==1, /* bFullMutex */ |
| 11706 | 0x7ffffffe, /* mxStrlen */ |
| 11707 | 100, /* szLookaside */ |
| 11708 | 500, /* nLookaside */ |
| 11709 | {0,0,0,0,0,0,0,0}, /* m */ |
| 11710 | {0,0,0,0,0,0,0,0,0}, /* mutex */ |
| @@ -18217,11 +18498,11 @@ | |
| 18217 | sqlite3_mutex_enter(mem0.mutex); |
| 18218 | sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes); |
| 18219 | nDiff = nNew - nOld; |
| 18220 | if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >= |
| 18221 | mem0.alarmThreshold-nDiff ){ |
| 18222 | sqlite3MallocAlarm(nNew-nOld); |
| 18223 | } |
| 18224 | assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) ); |
| 18225 | assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) ); |
| 18226 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 18227 | if( pNew==0 && mem0.alarmCallback ){ |
| @@ -18228,11 +18509,11 @@ | |
| 18228 | sqlite3MallocAlarm(nBytes); |
| 18229 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 18230 | } |
| 18231 | if( pNew ){ |
| 18232 | nNew = sqlite3MallocSize(pNew); |
| 18233 | sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nDiff); |
| 18234 | } |
| 18235 | sqlite3_mutex_leave(mem0.mutex); |
| 18236 | }else{ |
| 18237 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 18238 | } |
| @@ -21183,27 +21464,25 @@ | |
| 21183 | p[3] = (u8)v; |
| 21184 | } |
| 21185 | |
| 21186 | |
| 21187 | |
| 21188 | #if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC) |
| 21189 | /* |
| 21190 | ** Translate a single byte of Hex into an integer. |
| 21191 | ** This routine only works if h really is a valid hexadecimal |
| 21192 | ** character: 0..9a..fA..F |
| 21193 | */ |
| 21194 | static u8 hexToInt(int h){ |
| 21195 | assert( (h>='0' && h<='9') || (h>='a' && h<='f') || (h>='A' && h<='F') ); |
| 21196 | #ifdef SQLITE_ASCII |
| 21197 | h += 9*(1&(h>>6)); |
| 21198 | #endif |
| 21199 | #ifdef SQLITE_EBCDIC |
| 21200 | h += 9*(1&~(h>>4)); |
| 21201 | #endif |
| 21202 | return (u8)(h & 0xf); |
| 21203 | } |
| 21204 | #endif /* !SQLITE_OMIT_BLOB_LITERAL || SQLITE_HAS_CODEC */ |
| 21205 | |
| 21206 | #if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC) |
| 21207 | /* |
| 21208 | ** Convert a BLOB literal of the form "x'hhhhhh'" into its binary |
| 21209 | ** value. Return a pointer to its binary value. Space to hold the |
| @@ -21216,11 +21495,11 @@ | |
| 21216 | |
| 21217 | zBlob = (char *)sqlite3DbMallocRaw(db, n/2 + 1); |
| 21218 | n--; |
| 21219 | if( zBlob ){ |
| 21220 | for(i=0; i<n; i+=2){ |
| 21221 | zBlob[i/2] = (hexToInt(z[i])<<4) | hexToInt(z[i+1]); |
| 21222 | } |
| 21223 | zBlob[i/2] = 0; |
| 21224 | } |
| 21225 | return zBlob; |
| 21226 | } |
| @@ -21348,10 +21627,36 @@ | |
| 21348 | SQLITE_PRIVATE int sqlite3AbsInt32(int x){ |
| 21349 | if( x>=0 ) return x; |
| 21350 | if( x==(int)0x80000000 ) return 0x7fffffff; |
| 21351 | return -x; |
| 21352 | } |
| 21353 | |
| 21354 | /************** End of util.c ************************************************/ |
| 21355 | /************** Begin file hash.c ********************************************/ |
| 21356 | /* |
| 21357 | ** 2001 September 22 |
| @@ -27890,10 +28195,11 @@ | |
| 27890 | sqlite3_snprintf(nShmFilename, zShmFilename, |
| 27891 | SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x", |
| 27892 | (u32)sStat.st_ino, (u32)sStat.st_dev); |
| 27893 | #else |
| 27894 | sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", pDbFd->zPath); |
| 27895 | #endif |
| 27896 | pShmNode->h = -1; |
| 27897 | pDbFd->pInode->pShmNode = pShmNode; |
| 27898 | pShmNode->pInode = pDbFd->pInode; |
| 27899 | pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); |
| @@ -28923,17 +29229,23 @@ | |
| 28923 | ** Finally, if the file being opened is a WAL or regular journal file, then |
| 28924 | ** this function queries the file-system for the permissions on the |
| 28925 | ** corresponding database file and sets *pMode to this value. Whenever |
| 28926 | ** possible, WAL and journal files are created using the same permissions |
| 28927 | ** as the associated database file. |
| 28928 | */ |
| 28929 | static int findCreateFileMode( |
| 28930 | const char *zPath, /* Path of file (possibly) being created */ |
| 28931 | int flags, /* Flags passed as 4th argument to xOpen() */ |
| 28932 | mode_t *pMode /* OUT: Permissions to open file with */ |
| 28933 | ){ |
| 28934 | int rc = SQLITE_OK; /* Return Code */ |
| 28935 | if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){ |
| 28936 | char zDb[MAX_PATHNAME+1]; /* Database file path */ |
| 28937 | int nDb; /* Number of valid bytes in zDb */ |
| 28938 | struct stat sStat; /* Output of stat() on database file */ |
| 28939 | |
| @@ -28941,19 +29253,19 @@ | |
| 28941 | ** the path to the associated database file from zPath. This block handles |
| 28942 | ** the following naming conventions: |
| 28943 | ** |
| 28944 | ** "<path to db>-journal" |
| 28945 | ** "<path to db>-wal" |
| 28946 | ** "<path to db>-journal-NNNN" |
| 28947 | ** "<path to db>-wal-NNNN" |
| 28948 | ** |
| 28949 | ** where NNNN is a 4 digit decimal number. The NNNN naming schemes are |
| 28950 | ** used by the test_multiplex.c module. |
| 28951 | */ |
| 28952 | nDb = sqlite3Strlen30(zPath) - 1; |
| 28953 | while( nDb>0 && zPath[nDb]!='l' ) nDb--; |
| 28954 | nDb -= ((flags & SQLITE_OPEN_WAL) ? 3 : 7); |
| 28955 | memcpy(zDb, zPath, nDb); |
| 28956 | zDb[nDb] = '\0'; |
| 28957 | |
| 28958 | if( 0==stat(zDb, &sStat) ){ |
| 28959 | *pMode = sStat.st_mode & 0777; |
| @@ -28960,12 +29272,10 @@ | |
| 28960 | }else{ |
| 28961 | rc = SQLITE_IOERR_FSTAT; |
| 28962 | } |
| 28963 | }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){ |
| 28964 | *pMode = 0600; |
| 28965 | }else{ |
| 28966 | *pMode = SQLITE_DEFAULT_FILE_PERMISSIONS; |
| 28967 | } |
| 28968 | return rc; |
| 28969 | } |
| 28970 | |
| 28971 | /* |
| @@ -32620,10 +32930,11 @@ | |
| 32620 | return SQLITE_NOMEM; |
| 32621 | } |
| 32622 | memset(pNew, 0, sizeof(*pNew)); |
| 32623 | pNew->zFilename = (char*)&pNew[1]; |
| 32624 | sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath); |
| 32625 | |
| 32626 | /* Look to see if there is an existing winShmNode that can be used. |
| 32627 | ** If no matching winShmNode currently exists, create a new one. |
| 32628 | */ |
| 32629 | winShmEnterMutex(); |
| @@ -33514,10 +33825,17 @@ | |
| 33514 | |
| 33515 | #if !SQLITE_OS_WINCE && !defined(__CYGWIN__) |
| 33516 | int nByte; |
| 33517 | void *zConverted; |
| 33518 | char *zOut; |
| 33519 | |
| 33520 | /* It's odd to simulate an io-error here, but really this is just |
| 33521 | ** using the io-error infrastructure to test that SQLite handles this |
| 33522 | ** function failing. This function could fail if, for example, the |
| 33523 | ** current working directory has been unlinked. |
| @@ -36326,10 +36644,11 @@ | |
| 36326 | #define _WAL_H_ |
| 36327 | |
| 36328 | |
| 36329 | #ifdef SQLITE_OMIT_WAL |
| 36330 | # define sqlite3WalOpen(x,y,z) 0 |
| 36331 | # define sqlite3WalClose(w,x,y,z) 0 |
| 36332 | # define sqlite3WalBeginReadTransaction(y,z) 0 |
| 36333 | # define sqlite3WalEndReadTransaction(z) |
| 36334 | # define sqlite3WalRead(v,w,x,y,z) 0 |
| 36335 | # define sqlite3WalDbsize(y) 0 |
| @@ -36351,13 +36670,16 @@ | |
| 36351 | ** There is one object of this type for each pager. |
| 36352 | */ |
| 36353 | typedef struct Wal Wal; |
| 36354 | |
| 36355 | /* Open and close a connection to a write-ahead log. */ |
| 36356 | SQLITE_PRIVATE int sqlite3WalOpen(sqlite3_vfs*, sqlite3_file*, const char *zName, int, Wal**); |
| 36357 | SQLITE_PRIVATE int sqlite3WalClose(Wal *pWal, int sync_flags, int, u8 *); |
| 36358 | |
| 36359 | /* Used by readers to open (lock) and close (unlock) a snapshot. A |
| 36360 | ** snapshot is like a read-transaction. It is the state of the database |
| 36361 | ** at an instant in time. sqlite3WalOpenSnapshot gets a read lock and |
| 36362 | ** preserves the current state even if the other threads or processes |
| 36363 | ** write to or checkpoint the WAL. sqlite3WalCloseSnapshot() closes the |
| @@ -40702,10 +41024,12 @@ | |
| 40702 | int nPathname = 0; /* Number of bytes in zPathname */ |
| 40703 | int useJournal = (flags & PAGER_OMIT_JOURNAL)==0; /* False to omit journal */ |
| 40704 | int noReadlock = (flags & PAGER_NO_READLOCK)!=0; /* True to omit read-lock */ |
| 40705 | int pcacheSize = sqlite3PcacheSize(); /* Bytes to allocate for PCache */ |
| 40706 | u32 szPageDflt = SQLITE_DEFAULT_PAGE_SIZE; /* Default page size */ |
| 40707 | |
| 40708 | /* Figure out how much space is required for each journal file-handle |
| 40709 | ** (there are two of them, the main journal and the sub-journal). This |
| 40710 | ** is the maximum space required for an in-memory journal file handle |
| 40711 | ** and a regular journal file-handle. Note that a "regular journal-handle" |
| @@ -40732,18 +41056,25 @@ | |
| 40732 | /* Compute and store the full pathname in an allocated buffer pointed |
| 40733 | ** to by zPathname, length nPathname. Or, if this is a temporary file, |
| 40734 | ** leave both nPathname and zPathname set to 0. |
| 40735 | */ |
| 40736 | if( zFilename && zFilename[0] ){ |
| 40737 | nPathname = pVfs->mxPathname+1; |
| 40738 | zPathname = sqlite3Malloc(nPathname*2); |
| 40739 | if( zPathname==0 ){ |
| 40740 | return SQLITE_NOMEM; |
| 40741 | } |
| 40742 | zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */ |
| 40743 | rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname); |
| 40744 | nPathname = sqlite3Strlen30(zPathname); |
| 40745 | if( rc==SQLITE_OK && nPathname+8>pVfs->mxPathname ){ |
| 40746 | /* This branch is taken when the journal path required by |
| 40747 | ** the database being opened will be more than pVfs->mxPathname |
| 40748 | ** bytes in length. This means the database cannot be opened, |
| 40749 | ** as it will not be possible to open the journal file or even |
| @@ -40772,11 +41103,11 @@ | |
| 40772 | pPtr = (u8 *)sqlite3MallocZero( |
| 40773 | ROUND8(sizeof(*pPager)) + /* Pager structure */ |
| 40774 | ROUND8(pcacheSize) + /* PCache object */ |
| 40775 | ROUND8(pVfs->szOsFile) + /* The main db file */ |
| 40776 | journalFileSize * 2 + /* The two journal files */ |
| 40777 | nPathname + 1 + /* zFilename */ |
| 40778 | nPathname + 8 + 1 /* zJournal */ |
| 40779 | #ifndef SQLITE_OMIT_WAL |
| 40780 | + nPathname + 4 + 1 /* zWal */ |
| 40781 | #endif |
| 40782 | ); |
| @@ -40794,18 +41125,21 @@ | |
| 40794 | assert( EIGHT_BYTE_ALIGNMENT(pPager->jfd) ); |
| 40795 | |
| 40796 | /* Fill in the Pager.zFilename and Pager.zJournal buffers, if required. */ |
| 40797 | if( zPathname ){ |
| 40798 | assert( nPathname>0 ); |
| 40799 | pPager->zJournal = (char*)(pPtr += nPathname + 1); |
| 40800 | memcpy(pPager->zFilename, zPathname, nPathname); |
| 40801 | memcpy(pPager->zJournal, zPathname, nPathname); |
| 40802 | memcpy(&pPager->zJournal[nPathname], "-journal", 8); |
| 40803 | #ifndef SQLITE_OMIT_WAL |
| 40804 | pPager->zWal = &pPager->zJournal[nPathname+8+1]; |
| 40805 | memcpy(pPager->zWal, zPathname, nPathname); |
| 40806 | memcpy(&pPager->zWal[nPathname], "-wal", 4); |
| 40807 | #endif |
| 40808 | sqlite3_free(zPathname); |
| 40809 | } |
| 40810 | pPager->pVfs = pVfs; |
| 40811 | pPager->vfsFlags = vfsFlags; |
| @@ -43000,10 +43334,11 @@ | |
| 43000 | ** An attempt to set a limit smaller than -1 is a no-op. |
| 43001 | */ |
| 43002 | SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *pPager, i64 iLimit){ |
| 43003 | if( iLimit>=-1 ){ |
| 43004 | pPager->journalSizeLimit = iLimit; |
| 43005 | } |
| 43006 | return pPager->journalSizeLimit; |
| 43007 | } |
| 43008 | |
| 43009 | /* |
| @@ -43091,11 +43426,12 @@ | |
| 43091 | /* Open the connection to the log file. If this operation fails, |
| 43092 | ** (e.g. due to malloc() failure), return an error code. |
| 43093 | */ |
| 43094 | if( rc==SQLITE_OK ){ |
| 43095 | rc = sqlite3WalOpen(pPager->pVfs, |
| 43096 | pPager->fd, pPager->zWal, pPager->exclusiveMode, &pPager->pWal |
| 43097 | ); |
| 43098 | } |
| 43099 | |
| 43100 | return rc; |
| 43101 | } |
| @@ -43623,10 +43959,11 @@ | |
| 43623 | struct Wal { |
| 43624 | sqlite3_vfs *pVfs; /* The VFS used to create pDbFd */ |
| 43625 | sqlite3_file *pDbFd; /* File handle for the database file */ |
| 43626 | sqlite3_file *pWalFd; /* File handle for WAL file */ |
| 43627 | u32 iCallback; /* Value to pass to log callback (or 0) */ |
| 43628 | int nWiData; /* Size of array apWiData */ |
| 43629 | volatile u32 **apWiData; /* Pointer to wal-index content in memory */ |
| 43630 | u32 szPage; /* Database page size */ |
| 43631 | i16 readLock; /* Which read lock is being held. -1 for none */ |
| 43632 | u8 exclusiveMode; /* Non-zero if connection is in exclusive mode */ |
| @@ -44445,10 +44782,11 @@ | |
| 44445 | SQLITE_PRIVATE int sqlite3WalOpen( |
| 44446 | sqlite3_vfs *pVfs, /* vfs module to open wal and wal-index */ |
| 44447 | sqlite3_file *pDbFd, /* The open database file */ |
| 44448 | const char *zWalName, /* Name of the WAL file */ |
| 44449 | int bNoShm, /* True to run in heap-memory mode */ |
| 44450 | Wal **ppWal /* OUT: Allocated Wal handle */ |
| 44451 | ){ |
| 44452 | int rc; /* Return Code */ |
| 44453 | Wal *pRet; /* Object to allocate and return */ |
| 44454 | int flags; /* Flags passed to OsOpen() */ |
| @@ -44477,10 +44815,11 @@ | |
| 44477 | |
| 44478 | pRet->pVfs = pVfs; |
| 44479 | pRet->pWalFd = (sqlite3_file *)&pRet[1]; |
| 44480 | pRet->pDbFd = pDbFd; |
| 44481 | pRet->readLock = -1; |
| 44482 | pRet->zWalName = zWalName; |
| 44483 | pRet->exclusiveMode = (bNoShm ? WAL_HEAPMEMORY_MODE: WAL_NORMAL_MODE); |
| 44484 | |
| 44485 | /* Open file handle on the write-ahead log file. */ |
| 44486 | flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_WAL); |
| @@ -44497,10 +44836,17 @@ | |
| 44497 | *ppWal = pRet; |
| 44498 | WALTRACE(("WAL%d: opened\n", pRet)); |
| 44499 | } |
| 44500 | return rc; |
| 44501 | } |
| 44502 | |
| 44503 | /* |
| 44504 | ** Find the smallest page number out of all pages held in the WAL that |
| 44505 | ** has not been returned by any prior invocation of this method on the |
| 44506 | ** same WalIterator object. Write into *piFrame the frame index where |
| @@ -45733,10 +46079,26 @@ | |
| 45733 | ** safe and means there is no special case for sqlite3WalUndo() |
| 45734 | ** to handle if this transaction is rolled back. |
| 45735 | */ |
| 45736 | int i; /* Loop counter */ |
| 45737 | u32 *aSalt = pWal->hdr.aSalt; /* Big-endian salt values */ |
| 45738 | pWal->nCkpt++; |
| 45739 | pWal->hdr.mxFrame = 0; |
| 45740 | sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0])); |
| 45741 | aSalt[1] = salt1; |
| 45742 | walIndexWriteHdr(pWal); |
| @@ -47838,10 +48200,11 @@ | |
| 47838 | offset = PTRMAP_PTROFFSET(iPtrmap, key); |
| 47839 | if( offset<0 ){ |
| 47840 | *pRC = SQLITE_CORRUPT_BKPT; |
| 47841 | goto ptrmap_exit; |
| 47842 | } |
| 47843 | pPtrmap = (u8 *)sqlite3PagerGetData(pDbPage); |
| 47844 | |
| 47845 | if( eType!=pPtrmap[offset] || get4byte(&pPtrmap[offset+1])!=parent ){ |
| 47846 | TRACE(("PTRMAP_UPDATE: %d->(%d,%d)\n", key, eType, parent)); |
| 47847 | *pRC= rc = sqlite3PagerWrite(pDbPage); |
| @@ -47877,10 +48240,15 @@ | |
| 47877 | return rc; |
| 47878 | } |
| 47879 | pPtrmap = (u8 *)sqlite3PagerGetData(pDbPage); |
| 47880 | |
| 47881 | offset = PTRMAP_PTROFFSET(iPtrmap, key); |
| 47882 | assert( pEType!=0 ); |
| 47883 | *pEType = pPtrmap[offset]; |
| 47884 | if( pPgno ) *pPgno = get4byte(&pPtrmap[offset+1]); |
| 47885 | |
| 47886 | sqlite3PagerUnref(pDbPage); |
| @@ -48738,17 +49106,17 @@ | |
| 48738 | ** SQLITE_CONSTRAINT error. We cannot allow two or more BtShared |
| 48739 | ** objects in the same database connection since doing so will lead |
| 48740 | ** to problems with locking. |
| 48741 | */ |
| 48742 | SQLITE_PRIVATE int sqlite3BtreeOpen( |
| 48743 | const char *zFilename, /* Name of the file containing the BTree database */ |
| 48744 | sqlite3 *db, /* Associated database handle */ |
| 48745 | Btree **ppBtree, /* Pointer to new Btree object written here */ |
| 48746 | int flags, /* Options */ |
| 48747 | int vfsFlags /* Flags passed through to sqlite3_vfs.xOpen() */ |
| 48748 | ){ |
| 48749 | sqlite3_vfs *pVfs; /* The VFS to use for this btree */ |
| 48750 | BtShared *pBt = 0; /* Shared part of btree structure */ |
| 48751 | Btree *p; /* Handle to return */ |
| 48752 | sqlite3_mutex *mutexOpen = 0; /* Prevents a race condition. Ticket #3537 */ |
| 48753 | int rc = SQLITE_OK; /* Result code from this function */ |
| 48754 | u8 nReserve; /* Byte of unused space on each page */ |
| @@ -48766,10 +49134,11 @@ | |
| 48766 | const int isMemdb = (zFilename && strcmp(zFilename, ":memory:")==0) |
| 48767 | || (isTempDb && sqlite3TempInMemory(db)); |
| 48768 | #endif |
| 48769 | |
| 48770 | assert( db!=0 ); |
| 48771 | assert( sqlite3_mutex_held(db->mutex) ); |
| 48772 | assert( (flags&0xff)==flags ); /* flags fit in 8 bits */ |
| 48773 | |
| 48774 | /* Only a BTREE_SINGLE database can be BTREE_UNORDERED */ |
| 48775 | assert( (flags & BTREE_UNORDERED)==0 || (flags & BTREE_SINGLE)!=0 ); |
| @@ -48784,11 +49153,10 @@ | |
| 48784 | flags |= BTREE_MEMORY; |
| 48785 | } |
| 48786 | if( (vfsFlags & SQLITE_OPEN_MAIN_DB)!=0 && (isMemdb || isTempDb) ){ |
| 48787 | vfsFlags = (vfsFlags & ~SQLITE_OPEN_MAIN_DB) | SQLITE_OPEN_TEMP_DB; |
| 48788 | } |
| 48789 | pVfs = db->pVfs; |
| 48790 | p = sqlite3MallocZero(sizeof(Btree)); |
| 48791 | if( !p ){ |
| 48792 | return SQLITE_NOMEM; |
| 48793 | } |
| 48794 | p->inTrans = TRANS_NONE; |
| @@ -58855,10 +59223,11 @@ | |
| 58855 | sqlite3_randomness(sizeof(iRandom), &iRandom); |
| 58856 | zMaster = sqlite3MPrintf(db, "%s-mj%08X", zMainFile, iRandom&0x7fffffff); |
| 58857 | if( !zMaster ){ |
| 58858 | return SQLITE_NOMEM; |
| 58859 | } |
| 58860 | rc = sqlite3OsAccess(pVfs, zMaster, SQLITE_ACCESS_EXISTS, &res); |
| 58861 | }while( rc==SQLITE_OK && res ); |
| 58862 | if( rc==SQLITE_OK ){ |
| 58863 | /* Open the master journal. */ |
| 58864 | rc = sqlite3OsOpenMalloc(pVfs, zMaster, &pMaster, |
| @@ -59068,10 +59437,19 @@ | |
| 59068 | } |
| 59069 | } |
| 59070 | } |
| 59071 | db->nStatement--; |
| 59072 | p->iStatement = 0; |
| 59073 | |
| 59074 | /* If the statement transaction is being rolled back, also restore the |
| 59075 | ** database handles deferred constraint counter to the value it had when |
| 59076 | ** the statement transaction was opened. */ |
| 59077 | if( eOp==SAVEPOINT_ROLLBACK ){ |
| @@ -62400,10 +62778,11 @@ | |
| 62400 | Mem *pIn2 = 0; /* 2nd input operand */ |
| 62401 | Mem *pIn3 = 0; /* 3rd input operand */ |
| 62402 | Mem *pOut = 0; /* Output operand */ |
| 62403 | int iCompare = 0; /* Result of last OP_Compare operation */ |
| 62404 | int *aPermute = 0; /* Permutation of columns for OP_Compare */ |
| 62405 | #ifdef VDBE_PROFILE |
| 62406 | u64 start; /* CPU clock count at start of opcode */ |
| 62407 | int origPc; /* Program counter at start of opcode */ |
| 62408 | #endif |
| 62409 | /******************************************************************** |
| @@ -63078,10 +63457,11 @@ | |
| 63078 | VdbeFrame *pFrame = p->pFrame; |
| 63079 | p->pFrame = pFrame->pParent; |
| 63080 | p->nFrame--; |
| 63081 | sqlite3VdbeSetChanges(db, p->nChange); |
| 63082 | pc = sqlite3VdbeFrameRestore(pFrame); |
| 63083 | if( pOp->p2==OE_Ignore ){ |
| 63084 | /* Instruction pc is the OP_Program that invoked the sub-program |
| 63085 | ** currently being halted. If the p2 instruction of this OP_Halt |
| 63086 | ** instruction is set to OE_Ignore, then the sub-program is throwing |
| 63087 | ** an IGNORE exception. In this case jump to the address specified |
| @@ -63650,11 +64030,13 @@ | |
| 63650 | assert( pOp>aOp ); |
| 63651 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 63652 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 63653 | u.ag.ctx.pColl = pOp[-1].p4.pColl; |
| 63654 | } |
| 63655 | (*u.ag.ctx.pFunc->xFunc)(&u.ag.ctx, u.ag.n, u.ag.apVal); /* IMP: R-24505-23230 */ |
| 63656 | if( db->mallocFailed ){ |
| 63657 | /* Even though a malloc() has failed, the implementation of the |
| 63658 | ** user function may have called an sqlite3_result_XXX() function |
| 63659 | ** to return a value. The following call releases any resources |
| 63660 | ** associated with such a value. |
| @@ -64857,10 +65239,18 @@ | |
| 64857 | "SQL statements in progress"); |
| 64858 | rc = SQLITE_BUSY; |
| 64859 | }else{ |
| 64860 | u.aq.nName = sqlite3Strlen30(u.aq.zName); |
| 64861 | |
| 64862 | /* Create a new savepoint structure. */ |
| 64863 | u.aq.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.aq.nName+1); |
| 64864 | if( u.aq.pNew ){ |
| 64865 | u.aq.pNew->zName = (char *)&u.aq.pNew[1]; |
| 64866 | memcpy(u.aq.pNew->zName, u.aq.zName, u.aq.nName+1); |
| @@ -64963,10 +65353,15 @@ | |
| 64963 | db->nSavepoint--; |
| 64964 | } |
| 64965 | }else{ |
| 64966 | db->nDeferredCons = u.aq.pSavepoint->nDeferredCons; |
| 64967 | } |
| 64968 | } |
| 64969 | } |
| 64970 | |
| 64971 | break; |
| 64972 | } |
| @@ -65102,11 +65497,15 @@ | |
| 65102 | if( p->iStatement==0 ){ |
| 65103 | assert( db->nStatement>=0 && db->nSavepoint>=0 ); |
| 65104 | db->nStatement++; |
| 65105 | p->iStatement = db->nSavepoint + db->nStatement; |
| 65106 | } |
| 65107 | rc = sqlite3BtreeBeginStmt(u.as.pBt, p->iStatement); |
| 65108 | |
| 65109 | /* Store the current value of the database handles deferred constraint |
| 65110 | ** counter. If the statement transaction needs to be rolled back, |
| 65111 | ** the value of this counter needs to be restored too. */ |
| 65112 | p->nStmtDefCons = db->nDeferredCons; |
| @@ -65423,11 +65822,11 @@ | |
| 65423 | |
| 65424 | assert( pOp->p1>=0 ); |
| 65425 | u.ax.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1); |
| 65426 | if( u.ax.pCx==0 ) goto no_mem; |
| 65427 | u.ax.pCx->nullRow = 1; |
| 65428 | rc = sqlite3BtreeOpen(0, db, &u.ax.pCx->pBt, |
| 65429 | BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags); |
| 65430 | if( rc==SQLITE_OK ){ |
| 65431 | rc = sqlite3BtreeBeginTrans(u.ax.pCx->pBt, 1); |
| 65432 | } |
| 65433 | if( rc==SQLITE_OK ){ |
| @@ -66097,11 +66496,11 @@ | |
| 66097 | ** engine starts picking positive candidate ROWIDs at random until |
| 66098 | ** it finds one that is not previously used. */ |
| 66099 | assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is |
| 66100 | ** an AUTOINCREMENT table. */ |
| 66101 | /* on the first attempt, simply do one more than previous */ |
| 66102 | u.be.v = db->lastRowid; |
| 66103 | u.be.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */ |
| 66104 | u.be.v++; /* ensure non-zero */ |
| 66105 | u.be.cnt = 0; |
| 66106 | while( ((rc = sqlite3BtreeMovetoUnpacked(u.be.pC->pCursor, 0, (u64)u.be.v, |
| 66107 | 0, &u.be.res))==SQLITE_OK) |
| @@ -66209,11 +66608,11 @@ | |
| 66209 | assert( pOp->opcode==OP_InsertInt ); |
| 66210 | u.bf.iKey = pOp->p3; |
| 66211 | } |
| 66212 | |
| 66213 | if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; |
| 66214 | if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = u.bf.iKey; |
| 66215 | if( u.bf.pData->flags & MEM_Null ){ |
| 66216 | u.bf.pData->z = 0; |
| 66217 | u.bf.pData->n = 0; |
| 66218 | }else{ |
| 66219 | assert( u.bf.pData->flags & (MEM_Blob|MEM_Str) ); |
| @@ -67335,11 +67734,11 @@ | |
| 67335 | assert( pc==u.by.pFrame->pc ); |
| 67336 | } |
| 67337 | |
| 67338 | p->nFrame++; |
| 67339 | u.by.pFrame->pParent = p->pFrame; |
| 67340 | u.by.pFrame->lastRowid = db->lastRowid; |
| 67341 | u.by.pFrame->nChange = p->nChange; |
| 67342 | p->nChange = 0; |
| 67343 | p->pFrame = u.by.pFrame; |
| 67344 | p->aMem = aMem = &VdbeFrameMem(u.by.pFrame)[-1]; |
| 67345 | p->nMem = u.by.pFrame->nChildMem; |
| @@ -68146,31 +68545,45 @@ | |
| 68146 | sqlite_int64 rowid; |
| 68147 | Mem **apArg; |
| 68148 | Mem *pX; |
| 68149 | #endif /* local variables moved into u.cm */ |
| 68150 | |
| 68151 | u.cm.pVtab = pOp->p4.pVtab->pVtab; |
| 68152 | u.cm.pModule = (sqlite3_module *)u.cm.pVtab->pModule; |
| 68153 | u.cm.nArg = pOp->p2; |
| 68154 | assert( pOp->p4type==P4_VTAB ); |
| 68155 | if( ALWAYS(u.cm.pModule->xUpdate) ){ |
| 68156 | u.cm.apArg = p->apArg; |
| 68157 | u.cm.pX = &aMem[pOp->p3]; |
| 68158 | for(u.cm.i=0; u.cm.i<u.cm.nArg; u.cm.i++){ |
| 68159 | assert( memIsValid(u.cm.pX) ); |
| 68160 | memAboutToChange(p, u.cm.pX); |
| 68161 | sqlite3VdbeMemStoreType(u.cm.pX); |
| 68162 | u.cm.apArg[u.cm.i] = u.cm.pX; |
| 68163 | u.cm.pX++; |
| 68164 | } |
| 68165 | rc = u.cm.pModule->xUpdate(u.cm.pVtab, u.cm.nArg, u.cm.apArg, &u.cm.rowid); |
| 68166 | importVtabErrMsg(p, u.cm.pVtab); |
| 68167 | if( rc==SQLITE_OK && pOp->p1 ){ |
| 68168 | assert( u.cm.nArg>1 && u.cm.apArg[0] && (u.cm.apArg[0]->flags&MEM_Null) ); |
| 68169 | db->lastRowid = u.cm.rowid; |
| 68170 | } |
| 68171 | p->nChange++; |
| 68172 | } |
| 68173 | break; |
| 68174 | } |
| 68175 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 68176 | |
| @@ -68316,10 +68729,11 @@ | |
| 68316 | |
| 68317 | /* This is the only way out of this procedure. We have to |
| 68318 | ** release the mutexes on btrees that were acquired at the |
| 68319 | ** top. */ |
| 68320 | vdbe_return: |
| 68321 | sqlite3VdbeLeave(p); |
| 68322 | return rc; |
| 68323 | |
| 68324 | /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH |
| 68325 | ** is encountered. |
| @@ -76044,12 +76458,16 @@ | |
| 76044 | int i; |
| 76045 | int rc = 0; |
| 76046 | sqlite3 *db = sqlite3_context_db_handle(context); |
| 76047 | const char *zName; |
| 76048 | const char *zFile; |
| 76049 | Db *aNew; |
| 76050 | char *zErrDyn = 0; |
| 76051 | |
| 76052 | UNUSED_PARAMETER(NotUsed); |
| 76053 | |
| 76054 | zFile = (const char *)sqlite3_value_text(argv[0]); |
| 76055 | zName = (const char *)sqlite3_value_text(argv[1]); |
| @@ -76098,12 +76516,22 @@ | |
| 76098 | |
| 76099 | /* Open the database file. If the btree is successfully opened, use |
| 76100 | ** it to obtain the database schema. At this point the schema may |
| 76101 | ** or may not be initialised. |
| 76102 | */ |
| 76103 | rc = sqlite3BtreeOpen(zFile, db, &aNew->pBt, 0, |
| 76104 | db->openFlags | SQLITE_OPEN_MAIN_DB); |
| 76105 | db->nDb++; |
| 76106 | if( rc==SQLITE_CONSTRAINT ){ |
| 76107 | rc = SQLITE_ERROR; |
| 76108 | zErrDyn = sqlite3MPrintf(db, "database is already attached"); |
| 76109 | }else if( rc==SQLITE_OK ){ |
| @@ -80213,11 +80641,11 @@ | |
| 80213 | SQLITE_OPEN_CREATE | |
| 80214 | SQLITE_OPEN_EXCLUSIVE | |
| 80215 | SQLITE_OPEN_DELETEONCLOSE | |
| 80216 | SQLITE_OPEN_TEMP_DB; |
| 80217 | |
| 80218 | rc = sqlite3BtreeOpen(0, db, &pBt, 0, flags); |
| 80219 | if( rc!=SQLITE_OK ){ |
| 80220 | sqlite3ErrorMsg(pParse, "unable to open a temporary database " |
| 80221 | "file for storing temporary tables"); |
| 80222 | pParse->rc = rc; |
| 80223 | return 1; |
| @@ -85399,10 +85827,11 @@ | |
| 85399 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 85400 | if( IsVirtual(pTab) ){ |
| 85401 | const char *pVTab = (const char *)sqlite3GetVTable(db, pTab); |
| 85402 | sqlite3VtabMakeWritable(pParse, pTab); |
| 85403 | sqlite3VdbeAddOp4(v, OP_VUpdate, 1, pTab->nCol+2, regIns, pVTab, P4_VTAB); |
| 85404 | sqlite3MayAbort(pParse); |
| 85405 | }else |
| 85406 | #endif |
| 85407 | { |
| 85408 | int isReplace; /* Set to true if constraints may cause a replace */ |
| @@ -87544,11 +87973,11 @@ | |
| 87544 | } |
| 87545 | |
| 87546 | /* |
| 87547 | ** Interpret the given string as a boolean value. |
| 87548 | */ |
| 87549 | static u8 getBoolean(const char *z){ |
| 87550 | return getSafetyLevel(z)&1; |
| 87551 | } |
| 87552 | |
| 87553 | /* |
| 87554 | ** Interpret the given string as a locking mode value. |
| @@ -87714,11 +88143,11 @@ | |
| 87714 | /* Foreign key support may not be enabled or disabled while not |
| 87715 | ** in auto-commit mode. */ |
| 87716 | mask &= ~(SQLITE_ForeignKeys); |
| 87717 | } |
| 87718 | |
| 87719 | if( getBoolean(zRight) ){ |
| 87720 | db->flags |= mask; |
| 87721 | }else{ |
| 87722 | db->flags &= ~mask; |
| 87723 | } |
| 87724 | |
| @@ -87928,11 +88357,11 @@ | |
| 87928 | if( sqlite3StrICmp(zLeft,"secure_delete")==0 ){ |
| 87929 | Btree *pBt = pDb->pBt; |
| 87930 | int b = -1; |
| 87931 | assert( pBt!=0 ); |
| 87932 | if( zRight ){ |
| 87933 | b = getBoolean(zRight); |
| 87934 | } |
| 87935 | if( pId2->n==0 && b>=0 ){ |
| 87936 | int ii; |
| 87937 | for(ii=0; ii<db->nDb; ii++){ |
| 87938 | sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b); |
| @@ -88528,11 +88957,11 @@ | |
| 88528 | #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */ |
| 88529 | |
| 88530 | #ifndef NDEBUG |
| 88531 | if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){ |
| 88532 | if( zRight ){ |
| 88533 | if( getBoolean(zRight) ){ |
| 88534 | sqlite3ParserTrace(stderr, "parser: "); |
| 88535 | }else{ |
| 88536 | sqlite3ParserTrace(0, 0); |
| 88537 | } |
| 88538 | } |
| @@ -88542,11 +88971,11 @@ | |
| 88542 | /* Reinstall the LIKE and GLOB functions. The variant of LIKE |
| 88543 | ** used will be case sensitive or not depending on the RHS. |
| 88544 | */ |
| 88545 | if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){ |
| 88546 | if( zRight ){ |
| 88547 | sqlite3RegisterLikeFunctions(db, getBoolean(zRight)); |
| 88548 | } |
| 88549 | }else |
| 88550 | |
| 88551 | #ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX |
| 88552 | # define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100 |
| @@ -95683,11 +96112,12 @@ | |
| 95683 | SrcList *pSrc, /* The virtual table to be modified */ |
| 95684 | Table *pTab, /* The virtual table */ |
| 95685 | ExprList *pChanges, /* The columns to change in the UPDATE statement */ |
| 95686 | Expr *pRowidExpr, /* Expression used to recompute the rowid */ |
| 95687 | int *aXRef, /* Mapping from columns of pTab to entries in pChanges */ |
| 95688 | Expr *pWhere /* WHERE clause of the UPDATE statement */ |
| 95689 | ); |
| 95690 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 95691 | |
| 95692 | /* |
| 95693 | ** The most recently coded instruction was an OP_Column to retrieve the |
| @@ -95927,11 +96357,11 @@ | |
| 95927 | |
| 95928 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 95929 | /* Virtual tables must be handled separately */ |
| 95930 | if( IsVirtual(pTab) ){ |
| 95931 | updateVirtualTable(pParse, pTabList, pTab, pChanges, pRowidExpr, aXRef, |
| 95932 | pWhere); |
| 95933 | pWhere = 0; |
| 95934 | pTabList = 0; |
| 95935 | goto update_cleanup; |
| 95936 | } |
| 95937 | #endif |
| @@ -96257,11 +96687,12 @@ | |
| 96257 | SrcList *pSrc, /* The virtual table to be modified */ |
| 96258 | Table *pTab, /* The virtual table */ |
| 96259 | ExprList *pChanges, /* The columns to change in the UPDATE statement */ |
| 96260 | Expr *pRowid, /* Expression used to recompute the rowid */ |
| 96261 | int *aXRef, /* Mapping from columns of pTab to entries in pChanges */ |
| 96262 | Expr *pWhere /* WHERE clause of the UPDATE statement */ |
| 96263 | ){ |
| 96264 | Vdbe *v = pParse->pVdbe; /* Virtual machine under construction */ |
| 96265 | ExprList *pEList = 0; /* The result set of the SELECT statement */ |
| 96266 | Select *pSelect = 0; /* The SELECT statement */ |
| 96267 | Expr *pExpr; /* Temporary expression */ |
| @@ -96314,10 +96745,11 @@ | |
| 96314 | for(i=0; i<pTab->nCol; i++){ |
| 96315 | sqlite3VdbeAddOp3(v, OP_Column, ephemTab, i+1+(pRowid!=0), iReg+2+i); |
| 96316 | } |
| 96317 | sqlite3VtabMakeWritable(pParse, pTab); |
| 96318 | sqlite3VdbeAddOp4(v, OP_VUpdate, 0, pTab->nCol+2, iReg, pVTab, P4_VTAB); |
| 96319 | sqlite3MayAbort(pParse); |
| 96320 | sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1); |
| 96321 | sqlite3VdbeJumpHere(v, addr); |
| 96322 | sqlite3VdbeAddOp2(v, OP_Close, ephemTab, 0); |
| 96323 | |
| @@ -96687,10 +97119,22 @@ | |
| 96687 | ************************************************************************* |
| 96688 | ** This file contains code used to help implement virtual tables. |
| 96689 | */ |
| 96690 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 96691 | |
| 96692 | /* |
| 96693 | ** The actual function that does the work of creating a new module. |
| 96694 | ** This function implements the sqlite3_create_module() and |
| 96695 | ** sqlite3_create_module_v2() interfaces. |
| 96696 | */ |
| @@ -96715,17 +97159,17 @@ | |
| 96715 | pMod->pModule = pModule; |
| 96716 | pMod->pAux = pAux; |
| 96717 | pMod->xDestroy = xDestroy; |
| 96718 | pDel = (Module *)sqlite3HashInsert(&db->aModule, zCopy, nName, (void*)pMod); |
| 96719 | if( pDel && pDel->xDestroy ){ |
| 96720 | pDel->xDestroy(pDel->pAux); |
| 96721 | } |
| 96722 | sqlite3DbFree(db, pDel); |
| 96723 | if( pDel==pMod ){ |
| 96724 | db->mallocFailed = 1; |
| 96725 | } |
| 96726 | sqlite3ResetInternalSchema(db, -1); |
| 96727 | }else if( xDestroy ){ |
| 96728 | xDestroy(pAux); |
| 96729 | } |
| 96730 | rc = sqlite3ApiExit(db, SQLITE_OK); |
| 96731 | sqlite3_mutex_leave(db->mutex); |
| @@ -97107,10 +97551,11 @@ | |
| 97107 | Table *pTab, |
| 97108 | Module *pMod, |
| 97109 | int (*xConstruct)(sqlite3*,void*,int,const char*const*,sqlite3_vtab**,char**), |
| 97110 | char **pzErr |
| 97111 | ){ |
| 97112 | VTable *pVTable; |
| 97113 | int rc; |
| 97114 | const char *const*azArg = (const char *const*)pTab->azModuleArg; |
| 97115 | int nArg = pTab->nModuleArg; |
| 97116 | char *zErr = 0; |
| @@ -97126,16 +97571,18 @@ | |
| 97126 | return SQLITE_NOMEM; |
| 97127 | } |
| 97128 | pVTable->db = db; |
| 97129 | pVTable->pMod = pMod; |
| 97130 | |
| 97131 | assert( !db->pVTab ); |
| 97132 | assert( xConstruct ); |
| 97133 | db->pVTab = pTab; |
| 97134 | |
| 97135 | /* Invoke the virtual table constructor */ |
| 97136 | rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr); |
| 97137 | if( rc==SQLITE_NOMEM ) db->mallocFailed = 1; |
| 97138 | |
| 97139 | if( SQLITE_OK!=rc ){ |
| 97140 | if( zErr==0 ){ |
| 97141 | *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName); |
| @@ -97147,11 +97594,11 @@ | |
| 97147 | }else if( ALWAYS(pVTable->pVtab) ){ |
| 97148 | /* Justification of ALWAYS(): A correct vtab constructor must allocate |
| 97149 | ** the sqlite3_vtab object if successful. */ |
| 97150 | pVTable->pVtab->pModule = pMod->pModule; |
| 97151 | pVTable->nRef = 1; |
| 97152 | if( db->pVTab ){ |
| 97153 | const char *zFormat = "vtable constructor did not declare schema: %s"; |
| 97154 | *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName); |
| 97155 | sqlite3VtabUnlock(pVTable); |
| 97156 | rc = SQLITE_ERROR; |
| 97157 | }else{ |
| @@ -97195,11 +97642,10 @@ | |
| 97195 | } |
| 97196 | } |
| 97197 | } |
| 97198 | |
| 97199 | sqlite3DbFree(db, zModuleName); |
| 97200 | db->pVTab = 0; |
| 97201 | return rc; |
| 97202 | } |
| 97203 | |
| 97204 | /* |
| 97205 | ** This function is invoked by the parser to call the xConnect() method |
| @@ -97315,12 +97761,11 @@ | |
| 97315 | int rc = SQLITE_OK; |
| 97316 | Table *pTab; |
| 97317 | char *zErr = 0; |
| 97318 | |
| 97319 | sqlite3_mutex_enter(db->mutex); |
| 97320 | pTab = db->pVTab; |
| 97321 | if( !pTab ){ |
| 97322 | sqlite3Error(db, SQLITE_MISUSE, 0); |
| 97323 | sqlite3_mutex_leave(db->mutex); |
| 97324 | return SQLITE_MISUSE_BKPT; |
| 97325 | } |
| 97326 | assert( (pTab->tabFlags & TF_Virtual)!=0 ); |
| @@ -97343,11 +97788,11 @@ | |
| 97343 | pTab->aCol = pParse->pNewTable->aCol; |
| 97344 | pTab->nCol = pParse->pNewTable->nCol; |
| 97345 | pParse->pNewTable->nCol = 0; |
| 97346 | pParse->pNewTable->aCol = 0; |
| 97347 | } |
| 97348 | db->pVTab = 0; |
| 97349 | }else{ |
| 97350 | sqlite3Error(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr); |
| 97351 | sqlite3DbFree(db, zErr); |
| 97352 | rc = SQLITE_ERROR; |
| 97353 | } |
| @@ -97495,11 +97940,10 @@ | |
| 97495 | pModule = pVTab->pVtab->pModule; |
| 97496 | |
| 97497 | if( pModule->xBegin ){ |
| 97498 | int i; |
| 97499 | |
| 97500 | |
| 97501 | /* If pVtab is already in the aVTrans array, return early */ |
| 97502 | for(i=0; i<db->nVTrans; i++){ |
| 97503 | if( db->aVTrans[i]==pVTab ){ |
| 97504 | return SQLITE_OK; |
| 97505 | } |
| @@ -97508,10 +97952,53 @@ | |
| 97508 | /* Invoke the xBegin method */ |
| 97509 | rc = pModule->xBegin(pVTab->pVtab); |
| 97510 | if( rc==SQLITE_OK ){ |
| 97511 | rc = addToVTrans(db, pVTab); |
| 97512 | } |
| 97513 | } |
| 97514 | return rc; |
| 97515 | } |
| 97516 | |
| 97517 | /* |
| @@ -97609,10 +98096,61 @@ | |
| 97609 | pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab; |
| 97610 | }else{ |
| 97611 | pToplevel->db->mallocFailed = 1; |
| 97612 | } |
| 97613 | } |
| 97614 | |
| 97615 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 97616 | |
| 97617 | /************** End of vtab.c ************************************************/ |
| 97618 | /************** Begin file where.c *******************************************/ |
| @@ -107631,10 +108169,15 @@ | |
| 107631 | typedef void(*LOGFUNC_t)(void*,int,const char*); |
| 107632 | sqlite3GlobalConfig.xLog = va_arg(ap, LOGFUNC_t); |
| 107633 | sqlite3GlobalConfig.pLogArg = va_arg(ap, void*); |
| 107634 | break; |
| 107635 | } |
| 107636 | |
| 107637 | default: { |
| 107638 | rc = SQLITE_ERROR; |
| 107639 | break; |
| 107640 | } |
| @@ -108990,25 +109533,257 @@ | |
| 108990 | } |
| 108991 | db->aLimit[limitId] = newLimit; |
| 108992 | } |
| 108993 | return oldLimit; /* IMP: R-53341-35419 */ |
| 108994 | } |
| 108995 | |
| 108996 | /* |
| 108997 | ** This routine does the work of opening a database on behalf of |
| 108998 | ** sqlite3_open() and sqlite3_open16(). The database filename "zFilename" |
| 108999 | ** is UTF-8 encoded. |
| 109000 | */ |
| 109001 | static int openDatabase( |
| 109002 | const char *zFilename, /* Database filename UTF-8 encoded */ |
| 109003 | sqlite3 **ppDb, /* OUT: Returned database handle */ |
| 109004 | unsigned flags, /* Operational flags */ |
| 109005 | const char *zVfs /* Name of the VFS to use */ |
| 109006 | ){ |
| 109007 | sqlite3 *db; |
| 109008 | int rc; |
| 109009 | int isThreadsafe; |
| 109010 | |
| 109011 | *ppDb = 0; |
| 109012 | #ifndef SQLITE_OMIT_AUTOINIT |
| 109013 | rc = sqlite3_initialize(); |
| 109014 | if( rc ) return rc; |
| @@ -109028,11 +109803,11 @@ | |
| 109028 | assert( SQLITE_OPEN_READWRITE == 0x02 ); |
| 109029 | assert( SQLITE_OPEN_CREATE == 0x04 ); |
| 109030 | testcase( (1<<(flags&7))==0x02 ); /* READONLY */ |
| 109031 | testcase( (1<<(flags&7))==0x04 ); /* READWRITE */ |
| 109032 | testcase( (1<<(flags&7))==0x40 ); /* READWRITE | CREATE */ |
| 109033 | if( ((1<<(flags&7)) & 0x46)==0 ) return SQLITE_MISUSE; |
| 109034 | |
| 109035 | if( sqlite3GlobalConfig.bCoreMutex==0 ){ |
| 109036 | isThreadsafe = 0; |
| 109037 | }else if( flags & SQLITE_OPEN_NOMUTEX ){ |
| 109038 | isThreadsafe = 0; |
| @@ -109109,17 +109884,10 @@ | |
| 109109 | sqlite3HashInit(&db->aCollSeq); |
| 109110 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 109111 | sqlite3HashInit(&db->aModule); |
| 109112 | #endif |
| 109113 | |
| 109114 | db->pVfs = sqlite3_vfs_find(zVfs); |
| 109115 | if( !db->pVfs ){ |
| 109116 | rc = SQLITE_ERROR; |
| 109117 | sqlite3Error(db, rc, "no such vfs: %s", zVfs); |
| 109118 | goto opendb_out; |
| 109119 | } |
| 109120 | |
| 109121 | /* Add the default collation sequence BINARY. BINARY works for both UTF-8 |
| 109122 | ** and UTF-16, so add a version for each to avoid any unnecessary |
| 109123 | ** conversions. The only error that can occur here is a malloc() failure. |
| 109124 | */ |
| 109125 | createCollation(db, "BINARY", SQLITE_UTF8, SQLITE_COLL_BINARY, 0, |
| @@ -109138,13 +109906,22 @@ | |
| 109138 | |
| 109139 | /* Also add a UTF-8 case-insensitive collation sequence. */ |
| 109140 | createCollation(db, "NOCASE", SQLITE_UTF8, SQLITE_COLL_NOCASE, 0, |
| 109141 | nocaseCollatingFunc, 0); |
| 109142 | |
| 109143 | /* Open the backend database driver */ |
| 109144 | db->openFlags = flags; |
| 109145 | rc = sqlite3BtreeOpen(zFilename, db, &db->aDb[0].pBt, 0, |
| 109146 | flags | SQLITE_OPEN_MAIN_DB); |
| 109147 | if( rc!=SQLITE_OK ){ |
| 109148 | if( rc==SQLITE_IOERR_NOMEM ){ |
| 109149 | rc = SQLITE_NOMEM; |
| 109150 | } |
| @@ -109233,10 +110010,11 @@ | |
| 109233 | sqlite3GlobalConfig.nLookaside); |
| 109234 | |
| 109235 | sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT); |
| 109236 | |
| 109237 | opendb_out: |
| 109238 | if( db ){ |
| 109239 | assert( db->mutex!=0 || isThreadsafe==0 || sqlite3GlobalConfig.bFullMutex==0 ); |
| 109240 | sqlite3_mutex_leave(db->mutex); |
| 109241 | } |
| 109242 | rc = sqlite3_errcode(db); |
| @@ -109264,11 +110042,11 @@ | |
| 109264 | const char *filename, /* Database filename (UTF-8) */ |
| 109265 | sqlite3 **ppDb, /* OUT: SQLite db handle */ |
| 109266 | int flags, /* Flags */ |
| 109267 | const char *zVfs /* Name of VFS module to use */ |
| 109268 | ){ |
| 109269 | return openDatabase(filename, ppDb, flags, zVfs); |
| 109270 | } |
| 109271 | |
| 109272 | #ifndef SQLITE_OMIT_UTF16 |
| 109273 | /* |
| 109274 | ** Open a new database handle. |
| @@ -109874,10 +110652,32 @@ | |
| 109874 | } |
| 109875 | va_end(ap); |
| 109876 | #endif /* SQLITE_OMIT_BUILTIN_TEST */ |
| 109877 | return rc; |
| 109878 | } |
| 109879 | |
| 109880 | /************** End of main.c ************************************************/ |
| 109881 | /************** Begin file notify.c ******************************************/ |
| 109882 | /* |
| 109883 | ** 2009 March 3 |
| @@ -110955,10 +111755,11 @@ | |
| 110955 | Fts3DeferredToken *pDeferred; /* Deferred search tokens, if any */ |
| 110956 | sqlite3_int64 iPrevId; /* Previous id read from aDoclist */ |
| 110957 | char *pNextId; /* Pointer into the body of aDoclist */ |
| 110958 | char *aDoclist; /* List of docids for full-text queries */ |
| 110959 | int nDoclist; /* Size of buffer at aDoclist */ |
| 110960 | int eEvalmode; /* An FTS3_EVAL_XX constant */ |
| 110961 | int nRowAvg; /* Average size of database rows, in pages */ |
| 110962 | |
| 110963 | int isMatchinfoNeeded; /* True when aMatchinfo[] needs filling in */ |
| 110964 | u32 *aMatchinfo; /* Information about most recent match */ |
| @@ -111137,11 +111938,11 @@ | |
| 111137 | SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *); |
| 111138 | SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *); |
| 111139 | SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64); |
| 111140 | SQLITE_PRIVATE void sqlite3Fts3Dequote(char *); |
| 111141 | |
| 111142 | SQLITE_PRIVATE char *sqlite3Fts3FindPositions(Fts3Expr *, sqlite3_int64, int); |
| 111143 | SQLITE_PRIVATE int sqlite3Fts3ExprLoadDoclist(Fts3Cursor *, Fts3Expr *); |
| 111144 | SQLITE_PRIVATE int sqlite3Fts3ExprLoadFtDoclist(Fts3Cursor *, Fts3Expr *, char **, int *); |
| 111145 | SQLITE_PRIVATE int sqlite3Fts3ExprNearTrim(Fts3Expr *, Fts3Expr *, int); |
| 111146 | |
| 111147 | /* fts3_tokenizer.c */ |
| @@ -111164,10 +111965,11 @@ | |
| 111164 | char **, int, int, const char *, int, Fts3Expr ** |
| 111165 | ); |
| 111166 | SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *); |
| 111167 | #ifdef SQLITE_TEST |
| 111168 | SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db); |
| 111169 | #endif |
| 111170 | |
| 111171 | /* fts3_aux.c */ |
| 111172 | SQLITE_PRIVATE int sqlite3Fts3InitAux(sqlite3 *db); |
| 111173 | |
| @@ -111284,10 +112086,38 @@ | |
| 111284 | static void fts3GetDeltaVarint(char **pp, sqlite3_int64 *pVal){ |
| 111285 | sqlite3_int64 iVal; |
| 111286 | *pp += sqlite3Fts3GetVarint(*pp, &iVal); |
| 111287 | *pVal += iVal; |
| 111288 | } |
| 111289 | |
| 111290 | /* |
| 111291 | ** As long as *pp has not reached its end (pEnd), then do the same |
| 111292 | ** as fts3GetDeltaVarint(): read a single varint and add it to *pVal. |
| 111293 | ** But if we have reached the end of the varint, just set *pp=0 and |
| @@ -111389,10 +112219,12 @@ | |
| 111389 | if( *pRc==SQLITE_OK ){ |
| 111390 | int i; /* Iterator variable */ |
| 111391 | int rc; /* Return code */ |
| 111392 | char *zSql; /* SQL statement passed to declare_vtab() */ |
| 111393 | char *zCols; /* List of user defined columns */ |
| 111394 | |
| 111395 | /* Create a list of user columns for the virtual table */ |
| 111396 | zCols = sqlite3_mprintf("%Q, ", p->azColumn[0]); |
| 111397 | for(i=1; zCols && i<p->nColumn; i++){ |
| 111398 | zCols = sqlite3_mprintf("%z%Q, ", zCols, p->azColumn[i]); |
| @@ -111958,10 +112790,26 @@ | |
| 111958 | |
| 111959 | if( iCons>=0 ){ |
| 111960 | pInfo->aConstraintUsage[iCons].argvIndex = 1; |
| 111961 | pInfo->aConstraintUsage[iCons].omit = 1; |
| 111962 | } |
| 111963 | return SQLITE_OK; |
| 111964 | } |
| 111965 | |
| 111966 | /* |
| 111967 | ** Implementation of xOpen method. |
| @@ -112015,11 +112863,11 @@ | |
| 112015 | if( rc==SQLITE_OK ){ |
| 112016 | /* If no row was found and no error has occured, then the %_content |
| 112017 | ** table is missing a row that is present in the full-text index. |
| 112018 | ** The data structures are corrupt. |
| 112019 | */ |
| 112020 | rc = SQLITE_CORRUPT; |
| 112021 | } |
| 112022 | pCsr->isEof = 1; |
| 112023 | if( pContext ){ |
| 112024 | sqlite3_result_error_code(pContext, rc); |
| 112025 | } |
| @@ -112075,11 +112923,11 @@ | |
| 112075 | ** nNode bytes of content (see sqlite3Fts3ReadBlock() for details). |
| 112076 | */ |
| 112077 | zCsr += sqlite3Fts3GetVarint(zCsr, &iChild); |
| 112078 | zCsr += sqlite3Fts3GetVarint(zCsr, &iChild); |
| 112079 | if( zCsr>zEnd ){ |
| 112080 | return SQLITE_CORRUPT; |
| 112081 | } |
| 112082 | |
| 112083 | while( zCsr<zEnd && (piFirst || piLast) ){ |
| 112084 | int cmp; /* memcmp() result */ |
| 112085 | int nSuffix; /* Size of term suffix */ |
| @@ -112093,11 +112941,11 @@ | |
| 112093 | } |
| 112094 | isFirstTerm = 0; |
| 112095 | zCsr += sqlite3Fts3GetVarint32(zCsr, &nSuffix); |
| 112096 | |
| 112097 | if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){ |
| 112098 | rc = SQLITE_CORRUPT; |
| 112099 | goto finish_scan; |
| 112100 | } |
| 112101 | if( nPrefix+nSuffix>nAlloc ){ |
| 112102 | char *zNew; |
| 112103 | nAlloc = (nPrefix+nSuffix) * 2; |
| @@ -113862,16 +114710,24 @@ | |
| 113862 | rc = sqlite3_reset(pCsr->pStmt); |
| 113863 | break; |
| 113864 | } |
| 113865 | pCsr->iPrevId = sqlite3_column_int64(pCsr->pStmt, 0); |
| 113866 | }else{ |
| 113867 | if( pCsr->pNextId>=&pCsr->aDoclist[pCsr->nDoclist] ){ |
| 113868 | pCsr->isEof = 1; |
| 113869 | break; |
| 113870 | } |
| 113871 | sqlite3_reset(pCsr->pStmt); |
| 113872 | fts3GetDeltaVarint(&pCsr->pNextId, &pCsr->iPrevId); |
| 113873 | pCsr->isRequireSeek = 1; |
| 113874 | pCsr->isMatchinfoNeeded = 1; |
| 113875 | } |
| 113876 | }while( SQLITE_OK==(rc = fts3EvalDeferred(pCsr, &res)) && res==0 ); |
| 113877 | |
| @@ -113900,12 +114756,12 @@ | |
| 113900 | const char *idxStr, /* Unused */ |
| 113901 | int nVal, /* Number of elements in apVal */ |
| 113902 | sqlite3_value **apVal /* Arguments for the indexing scheme */ |
| 113903 | ){ |
| 113904 | const char *azSql[] = { |
| 113905 | "SELECT %s FROM %Q.'%q_content' AS x WHERE docid = ?", /* non-full-scan */ |
| 113906 | "SELECT %s FROM %Q.'%q_content' AS x ", /* full-scan */ |
| 113907 | }; |
| 113908 | int rc; /* Return code */ |
| 113909 | char *zSql; /* SQL statement used to access %_content */ |
| 113910 | Fts3Table *p = (Fts3Table *)pCursor->pVtab; |
| 113911 | Fts3Cursor *pCsr = (Fts3Cursor *)pCursor; |
| @@ -113957,11 +114813,13 @@ | |
| 113957 | ** statement loops through all rows of the %_content table. For a |
| 113958 | ** full-text query or docid lookup, the statement retrieves a single |
| 113959 | ** row by docid. |
| 113960 | */ |
| 113961 | zSql = (char *)azSql[idxNum==FTS3_FULLSCAN_SEARCH]; |
| 113962 | zSql = sqlite3_mprintf(zSql, p->zReadExprlist, p->zDb, p->zName); |
| 113963 | if( !zSql ){ |
| 113964 | rc = SQLITE_NOMEM; |
| 113965 | }else{ |
| 113966 | rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0); |
| 113967 | sqlite3_free(zSql); |
| @@ -113969,11 +114827,26 @@ | |
| 113969 | if( rc==SQLITE_OK && idxNum==FTS3_DOCID_SEARCH ){ |
| 113970 | rc = sqlite3_bind_value(pCsr->pStmt, 1, apVal[0]); |
| 113971 | } |
| 113972 | pCsr->eSearch = (i16)idxNum; |
| 113973 | |
| 113974 | if( rc!=SQLITE_OK ) return rc; |
| 113975 | return fts3NextMethod(pCursor); |
| 113976 | } |
| 113977 | |
| 113978 | /* |
| 113979 | ** This is the xEof method of the virtual table. SQLite calls this |
| @@ -114121,17 +114994,37 @@ | |
| 114121 | pCsr->eEvalmode = FTS3_EVAL_MATCHINFO; |
| 114122 | rc = fts3EvalExpr(pCsr, pExpr, paDoclist, pnDoclist, 1); |
| 114123 | pCsr->eEvalmode = FTS3_EVAL_NEXT; |
| 114124 | return rc; |
| 114125 | } |
| 114126 | |
| 114127 | /* |
| 114128 | ** After ExprLoadDoclist() (see above) has been called, this function is |
| 114129 | ** used to iterate/search through the position lists that make up the doclist |
| 114130 | ** stored in pExpr->aDoclist. |
| 114131 | */ |
| 114132 | SQLITE_PRIVATE char *sqlite3Fts3FindPositions( |
| 114133 | Fts3Expr *pExpr, /* Access this expressions doclist */ |
| 114134 | sqlite3_int64 iDocid, /* Docid associated with requested pos-list */ |
| 114135 | int iCol /* Column of requested pos-list */ |
| 114136 | ){ |
| 114137 | assert( pExpr->isLoaded ); |
| @@ -114138,23 +115031,39 @@ | |
| 114138 | if( pExpr->aDoclist ){ |
| 114139 | char *pEnd = &pExpr->aDoclist[pExpr->nDoclist]; |
| 114140 | char *pCsr; |
| 114141 | |
| 114142 | if( pExpr->pCurrent==0 ){ |
| 114143 | pExpr->pCurrent = pExpr->aDoclist; |
| 114144 | pExpr->iCurrent = 0; |
| 114145 | pExpr->pCurrent += sqlite3Fts3GetVarint(pExpr->pCurrent,&pExpr->iCurrent); |
| 114146 | } |
| 114147 | pCsr = pExpr->pCurrent; |
| 114148 | assert( pCsr ); |
| 114149 | |
| 114150 | while( pCsr<pEnd ){ |
| 114151 | if( pExpr->iCurrent<iDocid ){ |
| 114152 | fts3PoslistCopy(0, &pCsr); |
| 114153 | if( pCsr<pEnd ){ |
| 114154 | fts3GetDeltaVarint(&pCsr, &pExpr->iCurrent); |
| 114155 | } |
| 114156 | pExpr->pCurrent = pCsr; |
| 114157 | }else{ |
| 114158 | if( pExpr->iCurrent==iDocid ){ |
| 114159 | int iThis = 0; |
| 114160 | if( iCol<0 ){ |
| @@ -114407,13 +115316,24 @@ | |
| 114407 | "ALTER TABLE %Q.'%q_segdir' RENAME TO '%q_segdir';", |
| 114408 | p->zDb, p->zName, zName |
| 114409 | ); |
| 114410 | return rc; |
| 114411 | } |
| 114412 | |
| 114413 | static const sqlite3_module fts3Module = { |
| 114414 | /* iVersion */ 0, |
| 114415 | /* xCreate */ fts3CreateMethod, |
| 114416 | /* xConnect */ fts3ConnectMethod, |
| 114417 | /* xBestIndex */ fts3BestIndexMethod, |
| 114418 | /* xDisconnect */ fts3DisconnectMethod, |
| 114419 | /* xDestroy */ fts3DestroyMethod, |
| @@ -114429,10 +115349,13 @@ | |
| 114429 | /* xSync */ fts3SyncMethod, |
| 114430 | /* xCommit */ fts3CommitMethod, |
| 114431 | /* xRollback */ fts3RollbackMethod, |
| 114432 | /* xFindFunction */ fts3FindFunctionMethod, |
| 114433 | /* xRename */ fts3RenameMethod, |
| 114434 | }; |
| 114435 | |
| 114436 | /* |
| 114437 | ** This function is registered as the module destructor (called when an |
| 114438 | ** FTS3 enabled database connection is closed). It frees the memory |
| @@ -114474,10 +115397,15 @@ | |
| 114474 | |
| 114475 | #ifdef SQLITE_ENABLE_ICU |
| 114476 | const sqlite3_tokenizer_module *pIcu = 0; |
| 114477 | sqlite3Fts3IcuTokenizerModule(&pIcu); |
| 114478 | #endif |
| 114479 | |
| 114480 | rc = sqlite3Fts3InitAux(db); |
| 114481 | if( rc!=SQLITE_OK ) return rc; |
| 114482 | |
| 114483 | sqlite3Fts3SimpleTokenizerModule(&pSimple); |
| @@ -117995,11 +118923,11 @@ | |
| 117995 | sqlite3_bind_int64(pStmt, 1, iDocid); |
| 117996 | } |
| 117997 | rc = sqlite3_step(pStmt); |
| 117998 | if( rc!=SQLITE_ROW || sqlite3_column_type(pStmt, 0)!=SQLITE_BLOB ){ |
| 117999 | rc = sqlite3_reset(pStmt); |
| 118000 | if( rc==SQLITE_OK ) rc = SQLITE_CORRUPT; |
| 118001 | pStmt = 0; |
| 118002 | }else{ |
| 118003 | rc = SQLITE_OK; |
| 118004 | } |
| 118005 | } |
| @@ -118451,18 +119379,18 @@ | |
| 118451 | ** full-text index. |
| 118452 | */ |
| 118453 | static void fts3DeleteTerms( |
| 118454 | int *pRC, /* Result code */ |
| 118455 | Fts3Table *p, /* The FTS table to delete from */ |
| 118456 | sqlite3_value **apVal, /* apVal[] contains the docid to be deleted */ |
| 118457 | u32 *aSz /* Sizes of deleted document written here */ |
| 118458 | ){ |
| 118459 | int rc; |
| 118460 | sqlite3_stmt *pSelect; |
| 118461 | |
| 118462 | if( *pRC ) return; |
| 118463 | rc = fts3SqlStmt(p, SQL_SELECT_CONTENT_BY_ROWID, &pSelect, apVal); |
| 118464 | if( rc==SQLITE_OK ){ |
| 118465 | if( SQLITE_ROW==sqlite3_step(pSelect) ){ |
| 118466 | int i; |
| 118467 | for(i=1; i<=p->nColumn; i++){ |
| 118468 | const char *zText = (const char *)sqlite3_column_text(pSelect, i); |
| @@ -118676,11 +119604,11 @@ | |
| 118676 | pNext += sqlite3Fts3GetVarint32(pNext, &nPrefix); |
| 118677 | pNext += sqlite3Fts3GetVarint32(pNext, &nSuffix); |
| 118678 | if( nPrefix<0 || nSuffix<=0 |
| 118679 | || &pNext[nSuffix]>&pReader->aNode[pReader->nNode] |
| 118680 | ){ |
| 118681 | return SQLITE_CORRUPT; |
| 118682 | } |
| 118683 | |
| 118684 | if( nPrefix+nSuffix>pReader->nTermAlloc ){ |
| 118685 | int nNew = (nPrefix+nSuffix)*2; |
| 118686 | char *zNew = sqlite3_realloc(pReader->zTerm, nNew); |
| @@ -118702,11 +119630,11 @@ | |
| 118702 | ** of these statements is untrue, then the data structure is corrupt. |
| 118703 | */ |
| 118704 | if( &pReader->aDoclist[pReader->nDoclist]>&pReader->aNode[pReader->nNode] |
| 118705 | || pReader->aDoclist[pReader->nDoclist-1] |
| 118706 | ){ |
| 118707 | return SQLITE_CORRUPT; |
| 118708 | } |
| 118709 | return SQLITE_OK; |
| 118710 | } |
| 118711 | |
| 118712 | /* |
| @@ -118827,11 +119755,11 @@ | |
| 118827 | while( a<pEnd ){ |
| 118828 | a += sqlite3Fts3GetVarint(a, &nByte); |
| 118829 | } |
| 118830 | if( nDoc==0 || nByte==0 ){ |
| 118831 | sqlite3_reset(pStmt); |
| 118832 | return SQLITE_CORRUPT; |
| 118833 | } |
| 118834 | |
| 118835 | pCsr->nRowAvg = (int)(((nByte / nDoc) + pgsz) / pgsz); |
| 118836 | assert( pCsr->nRowAvg>0 ); |
| 118837 | rc = sqlite3_reset(pStmt); |
| @@ -119598,20 +120526,20 @@ | |
| 119598 | |
| 119599 | /* |
| 119600 | ** The first value in the apVal[] array is assumed to contain an integer. |
| 119601 | ** This function tests if there exist any documents with docid values that |
| 119602 | ** are different from that integer. i.e. if deleting the document with docid |
| 119603 | ** apVal[0] would mean the FTS3 table were empty. |
| 119604 | ** |
| 119605 | ** If successful, *pisEmpty is set to true if the table is empty except for |
| 119606 | ** document apVal[0], or false otherwise, and SQLITE_OK is returned. If an |
| 119607 | ** error occurs, an SQLite error code is returned. |
| 119608 | */ |
| 119609 | static int fts3IsEmpty(Fts3Table *p, sqlite3_value **apVal, int *pisEmpty){ |
| 119610 | sqlite3_stmt *pStmt; |
| 119611 | int rc; |
| 119612 | rc = fts3SqlStmt(p, SQL_IS_EMPTY, &pStmt, apVal); |
| 119613 | if( rc==SQLITE_OK ){ |
| 119614 | if( SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 119615 | *pisEmpty = sqlite3_column_int(pStmt, 0); |
| 119616 | } |
| 119617 | rc = sqlite3_reset(pStmt); |
| @@ -120331,10 +121259,44 @@ | |
| 120331 | pToken->pDeferred = pDeferred; |
| 120332 | |
| 120333 | return SQLITE_OK; |
| 120334 | } |
| 120335 | |
| 120336 | |
| 120337 | /* |
| 120338 | ** This function does the work for the xUpdate method of FTS3 virtual |
| 120339 | ** tables. |
| 120340 | */ |
| @@ -120349,50 +121311,95 @@ | |
| 120349 | int isRemove = 0; /* True for an UPDATE or DELETE */ |
| 120350 | sqlite3_int64 iRemove = 0; /* Rowid removed by UPDATE or DELETE */ |
| 120351 | u32 *aSzIns; /* Sizes of inserted documents */ |
| 120352 | u32 *aSzDel; /* Sizes of deleted documents */ |
| 120353 | int nChng = 0; /* Net change in number of documents */ |
| 120354 | |
| 120355 | assert( p->pSegments==0 ); |
| 120356 | |
| 120357 | /* Allocate space to hold the change in document sizes */ |
| 120358 | aSzIns = sqlite3_malloc( sizeof(aSzIns[0])*(p->nColumn+1)*2 ); |
| 120359 | if( aSzIns==0 ) return SQLITE_NOMEM; |
| 120360 | aSzDel = &aSzIns[p->nColumn+1]; |
| 120361 | memset(aSzIns, 0, sizeof(aSzIns[0])*(p->nColumn+1)*2); |
| 120362 | |
| 120363 | /* If this is a DELETE or UPDATE operation, remove the old record. */ |
| 120364 | if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){ |
| 120365 | int isEmpty = 0; |
| 120366 | rc = fts3IsEmpty(p, apVal, &isEmpty); |
| 120367 | if( rc==SQLITE_OK ){ |
| 120368 | if( isEmpty ){ |
| 120369 | /* Deleting this row means the whole table is empty. In this case |
| 120370 | ** delete the contents of all three tables and throw away any |
| 120371 | ** data in the pendingTerms hash table. |
| 120372 | */ |
| 120373 | rc = fts3DeleteAll(p); |
| 120374 | }else{ |
| 120375 | isRemove = 1; |
| 120376 | iRemove = sqlite3_value_int64(apVal[0]); |
| 120377 | rc = fts3PendingTermsDocid(p, iRemove); |
| 120378 | fts3DeleteTerms(&rc, p, apVal, aSzDel); |
| 120379 | fts3SqlExec(&rc, p, SQL_DELETE_CONTENT, apVal); |
| 120380 | if( p->bHasDocsize ){ |
| 120381 | fts3SqlExec(&rc, p, SQL_DELETE_DOCSIZE, apVal); |
| 120382 | } |
| 120383 | nChng--; |
| 120384 | } |
| 120385 | } |
| 120386 | }else if( sqlite3_value_type(apVal[p->nColumn+2])!=SQLITE_NULL ){ |
| 120387 | sqlite3_free(aSzIns); |
| 120388 | return fts3SpecialInsert(p, apVal[p->nColumn+2]); |
| 120389 | } |
| 120390 | |
| 120391 | /* If this is an INSERT or UPDATE operation, insert the new record. */ |
| 120392 | if( nArg>1 && rc==SQLITE_OK ){ |
| 120393 | rc = fts3InsertData(p, apVal, pRowid); |
| 120394 | if( rc==SQLITE_OK && (!isRemove || *pRowid!=iRemove) ){ |
| 120395 | rc = fts3PendingTermsDocid(p, *pRowid); |
| 120396 | } |
| 120397 | if( rc==SQLITE_OK ){ |
| 120398 | rc = fts3InsertTerms(p, apVal, aSzIns); |
| @@ -120852,11 +121859,11 @@ | |
| 120852 | SnippetPhrase *pPhrase = &p->aPhrase[iPhrase]; |
| 120853 | char *pCsr; |
| 120854 | |
| 120855 | pPhrase->nToken = pExpr->pPhrase->nToken; |
| 120856 | |
| 120857 | pCsr = sqlite3Fts3FindPositions(pExpr, p->pCsr->iPrevId, p->iCol); |
| 120858 | if( pCsr ){ |
| 120859 | int iFirst = 0; |
| 120860 | pPhrase->pList = pCsr; |
| 120861 | fts3GetDeltaPosition(&pCsr, &iFirst); |
| 120862 | pPhrase->pHead = pCsr; |
| @@ -121325,11 +122332,11 @@ | |
| 121325 | for(i=0; i<p->nCol; i++) p->aMatchinfo[iStart+i*3] = 0; |
| 121326 | |
| 121327 | if( pExpr->aDoclist ){ |
| 121328 | char *pCsr; |
| 121329 | |
| 121330 | pCsr = sqlite3Fts3FindPositions(pExpr, p->pCursor->iPrevId, -1); |
| 121331 | if( pCsr ){ |
| 121332 | fts3LoadColumnlistCounts(&pCsr, &p->aMatchinfo[iStart], 0); |
| 121333 | } |
| 121334 | } |
| 121335 | |
| @@ -121397,11 +122404,11 @@ | |
| 121397 | pStmt = *ppStmt; |
| 121398 | assert( sqlite3_data_count(pStmt)==1 ); |
| 121399 | |
| 121400 | a = sqlite3_column_blob(pStmt, 0); |
| 121401 | a += sqlite3Fts3GetVarint(a, &nDoc); |
| 121402 | if( nDoc==0 ) return SQLITE_CORRUPT; |
| 121403 | *pnDoc = (u32)nDoc; |
| 121404 | |
| 121405 | if( paLen ) *paLen = a; |
| 121406 | return SQLITE_OK; |
| 121407 | } |
| @@ -121492,11 +122499,11 @@ | |
| 121492 | (void)fts3ExprIterate(pCsr->pExpr, fts3MatchinfoLcsCb, (void*)aIter); |
| 121493 | for(i=0; i<pInfo->nPhrase; i++){ |
| 121494 | LcsIterator *pIter = &aIter[i]; |
| 121495 | nToken -= pIter->pExpr->pPhrase->nToken; |
| 121496 | pIter->iPosOffset = nToken; |
| 121497 | pIter->pRead = sqlite3Fts3FindPositions(pIter->pExpr, pCsr->iPrevId, -1); |
| 121498 | if( pIter->pRead ){ |
| 121499 | pIter->iPos = pIter->iPosOffset; |
| 121500 | fts3LcsIteratorAdvance(&aIter[i]); |
| 121501 | }else{ |
| 121502 | pIter->iCol = LCS_ITERATOR_FINISHED; |
| @@ -121845,10 +122852,11 @@ | |
| 121845 | int iPos; /* Position just read from pList */ |
| 121846 | int iOff; /* Offset of this term from read positions */ |
| 121847 | }; |
| 121848 | |
| 121849 | struct TermOffsetCtx { |
| 121850 | int iCol; /* Column of table to populate aTerm for */ |
| 121851 | int iTerm; |
| 121852 | sqlite3_int64 iDocid; |
| 121853 | TermOffset *aTerm; |
| 121854 | }; |
| @@ -121862,11 +122870,11 @@ | |
| 121862 | int iTerm; /* For looping through nTerm phrase terms */ |
| 121863 | char *pList; /* Pointer to position list for phrase */ |
| 121864 | int iPos = 0; /* First position in position-list */ |
| 121865 | |
| 121866 | UNUSED_PARAMETER(iPhrase); |
| 121867 | pList = sqlite3Fts3FindPositions(pExpr, p->iDocid, p->iCol); |
| 121868 | nTerm = pExpr->pPhrase->nToken; |
| 121869 | if( pList ){ |
| 121870 | fts3GetDeltaPosition(&pList, &iPos); |
| 121871 | assert( iPos>=0 ); |
| 121872 | } |
| @@ -121915,10 +122923,11 @@ | |
| 121915 | if( 0==sCtx.aTerm ){ |
| 121916 | rc = SQLITE_NOMEM; |
| 121917 | goto offsets_out; |
| 121918 | } |
| 121919 | sCtx.iDocid = pCsr->iPrevId; |
| 121920 | |
| 121921 | /* Loop through the table columns, appending offset information to |
| 121922 | ** string-buffer res for each column. |
| 121923 | */ |
| 121924 | for(iCol=0; iCol<pTab->nColumn; iCol++){ |
| @@ -121990,11 +122999,11 @@ | |
| 121990 | sqlite3_snprintf(sizeof(aBuffer), aBuffer, |
| 121991 | "%d %d %d %d ", iCol, pTerm-sCtx.aTerm, iStart, iEnd-iStart |
| 121992 | ); |
| 121993 | rc = fts3StringAppend(&res, aBuffer, -1); |
| 121994 | }else if( rc==SQLITE_DONE ){ |
| 121995 | rc = SQLITE_CORRUPT; |
| 121996 | } |
| 121997 | } |
| 121998 | } |
| 121999 | if( rc==SQLITE_DONE ){ |
| 122000 | rc = SQLITE_OK; |
| @@ -122578,29 +123587,29 @@ | |
| 122578 | ** is greater than RTREE_MAX_DEPTH, the r-tree structure must be corrupt. |
| 122579 | */ |
| 122580 | if( pNode && iNode==1 ){ |
| 122581 | pRtree->iDepth = readInt16(pNode->zData); |
| 122582 | if( pRtree->iDepth>RTREE_MAX_DEPTH ){ |
| 122583 | rc = SQLITE_CORRUPT; |
| 122584 | } |
| 122585 | } |
| 122586 | |
| 122587 | /* If no error has occurred so far, check if the "number of entries" |
| 122588 | ** field on the node is too large. If so, set the return code to |
| 122589 | ** SQLITE_CORRUPT. |
| 122590 | */ |
| 122591 | if( pNode && rc==SQLITE_OK ){ |
| 122592 | if( NCELL(pNode)>((pRtree->iNodeSize-4)/pRtree->nBytesPerCell) ){ |
| 122593 | rc = SQLITE_CORRUPT; |
| 122594 | } |
| 122595 | } |
| 122596 | |
| 122597 | if( rc==SQLITE_OK ){ |
| 122598 | if( pNode!=0 ){ |
| 122599 | nodeHashInsert(pRtree, pNode); |
| 122600 | }else{ |
| 122601 | rc = SQLITE_CORRUPT; |
| 122602 | } |
| 122603 | *ppNode = pNode; |
| 122604 | }else{ |
| 122605 | sqlite3_free(pNode); |
| 122606 | *ppNode = 0; |
| @@ -123123,11 +124132,11 @@ | |
| 123123 | if( nodeGetRowid(pRtree, pNode, ii)==iRowid ){ |
| 123124 | *piIndex = ii; |
| 123125 | return SQLITE_OK; |
| 123126 | } |
| 123127 | } |
| 123128 | return SQLITE_CORRUPT; |
| 123129 | } |
| 123130 | |
| 123131 | /* |
| 123132 | ** Return the index of the cell containing a pointer to node pNode |
| 123133 | ** in its parent. If pNode is the root node, return -1. |
| @@ -123718,11 +124727,11 @@ | |
| 123718 | RtreeNode *pParent = p->pParent; |
| 123719 | RtreeCell cell; |
| 123720 | int iCell; |
| 123721 | |
| 123722 | if( nodeParentIndex(pRtree, p, &iCell) ){ |
| 123723 | return SQLITE_CORRUPT; |
| 123724 | } |
| 123725 | |
| 123726 | nodeGetCell(pRtree, pParent, iCell, &cell); |
| 123727 | if( !cellContains(pRtree, &cell, pCell) ){ |
| 123728 | cellUnion(pRtree, &cell, pCell); |
| @@ -124390,11 +125399,11 @@ | |
| 124390 | rc2 = nodeAcquire(pRtree, iNode, 0, &pChild->pParent); |
| 124391 | } |
| 124392 | } |
| 124393 | rc = sqlite3_reset(pRtree->pReadParent); |
| 124394 | if( rc==SQLITE_OK ) rc = rc2; |
| 124395 | if( rc==SQLITE_OK && !pChild->pParent ) rc = SQLITE_CORRUPT; |
| 124396 | pChild = pChild->pParent; |
| 124397 | } |
| 124398 | return rc; |
| 124399 | } |
| 124400 | |
| @@ -124685,10 +125694,94 @@ | |
| 124685 | sqlite3_step(pRtree->pWriteRowid); |
| 124686 | rc = sqlite3_reset(pRtree->pWriteRowid); |
| 124687 | *piRowid = sqlite3_last_insert_rowid(pRtree->db); |
| 124688 | return rc; |
| 124689 | } |
| 124690 | |
| 124691 | /* |
| 124692 | ** The xUpdate method for rtree module virtual tables. |
| 124693 | */ |
| 124694 | static int rtreeUpdate( |
| @@ -124697,107 +125790,29 @@ | |
| 124697 | sqlite3_value **azData, |
| 124698 | sqlite_int64 *pRowid |
| 124699 | ){ |
| 124700 | Rtree *pRtree = (Rtree *)pVtab; |
| 124701 | int rc = SQLITE_OK; |
| 124702 | |
| 124703 | rtreeReference(pRtree); |
| 124704 | |
| 124705 | assert(nData>=1); |
| 124706 | |
| 124707 | /* If azData[0] is not an SQL NULL value, it is the rowid of a |
| 124708 | ** record to delete from the r-tree table. The following block does |
| 124709 | ** just that. |
| 124710 | */ |
| 124711 | if( sqlite3_value_type(azData[0])!=SQLITE_NULL ){ |
| 124712 | i64 iDelete; /* The rowid to delete */ |
| 124713 | RtreeNode *pLeaf; /* Leaf node containing record iDelete */ |
| 124714 | int iCell; /* Index of iDelete cell in pLeaf */ |
| 124715 | RtreeNode *pRoot; |
| 124716 | |
| 124717 | /* Obtain a reference to the root node to initialise Rtree.iDepth */ |
| 124718 | rc = nodeAcquire(pRtree, 1, 0, &pRoot); |
| 124719 | |
| 124720 | /* Obtain a reference to the leaf node that contains the entry |
| 124721 | ** about to be deleted. |
| 124722 | */ |
| 124723 | if( rc==SQLITE_OK ){ |
| 124724 | iDelete = sqlite3_value_int64(azData[0]); |
| 124725 | rc = findLeafNode(pRtree, iDelete, &pLeaf); |
| 124726 | } |
| 124727 | |
| 124728 | /* Delete the cell in question from the leaf node. */ |
| 124729 | if( rc==SQLITE_OK ){ |
| 124730 | int rc2; |
| 124731 | rc = nodeRowidIndex(pRtree, pLeaf, iDelete, &iCell); |
| 124732 | if( rc==SQLITE_OK ){ |
| 124733 | rc = deleteCell(pRtree, pLeaf, iCell, 0); |
| 124734 | } |
| 124735 | rc2 = nodeRelease(pRtree, pLeaf); |
| 124736 | if( rc==SQLITE_OK ){ |
| 124737 | rc = rc2; |
| 124738 | } |
| 124739 | } |
| 124740 | |
| 124741 | /* Delete the corresponding entry in the <rtree>_rowid table. */ |
| 124742 | if( rc==SQLITE_OK ){ |
| 124743 | sqlite3_bind_int64(pRtree->pDeleteRowid, 1, iDelete); |
| 124744 | sqlite3_step(pRtree->pDeleteRowid); |
| 124745 | rc = sqlite3_reset(pRtree->pDeleteRowid); |
| 124746 | } |
| 124747 | |
| 124748 | /* Check if the root node now has exactly one child. If so, remove |
| 124749 | ** it, schedule the contents of the child for reinsertion and |
| 124750 | ** reduce the tree height by one. |
| 124751 | ** |
| 124752 | ** This is equivalent to copying the contents of the child into |
| 124753 | ** the root node (the operation that Gutman's paper says to perform |
| 124754 | ** in this scenario). |
| 124755 | */ |
| 124756 | if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){ |
| 124757 | int rc2; |
| 124758 | RtreeNode *pChild; |
| 124759 | i64 iChild = nodeGetRowid(pRtree, pRoot, 0); |
| 124760 | rc = nodeAcquire(pRtree, iChild, pRoot, &pChild); |
| 124761 | if( rc==SQLITE_OK ){ |
| 124762 | rc = removeNode(pRtree, pChild, pRtree->iDepth-1); |
| 124763 | } |
| 124764 | rc2 = nodeRelease(pRtree, pChild); |
| 124765 | if( rc==SQLITE_OK ) rc = rc2; |
| 124766 | if( rc==SQLITE_OK ){ |
| 124767 | pRtree->iDepth--; |
| 124768 | writeInt16(pRoot->zData, pRtree->iDepth); |
| 124769 | pRoot->isDirty = 1; |
| 124770 | } |
| 124771 | } |
| 124772 | |
| 124773 | /* Re-insert the contents of any underfull nodes removed from the tree. */ |
| 124774 | for(pLeaf=pRtree->pDeleted; pLeaf; pLeaf=pRtree->pDeleted){ |
| 124775 | if( rc==SQLITE_OK ){ |
| 124776 | rc = reinsertNodeContent(pRtree, pLeaf); |
| 124777 | } |
| 124778 | pRtree->pDeleted = pLeaf->pNext; |
| 124779 | sqlite3_free(pLeaf); |
| 124780 | } |
| 124781 | |
| 124782 | /* Release the reference to the root node. */ |
| 124783 | if( rc==SQLITE_OK ){ |
| 124784 | rc = nodeRelease(pRtree, pRoot); |
| 124785 | }else{ |
| 124786 | nodeRelease(pRtree, pRoot); |
| 124787 | } |
| 124788 | } |
| 124789 | |
| 124790 | /* If the azData[] array contains more than one element, elements |
| 124791 | ** (azData[2]..azData[argc-1]) contain a new record to insert into |
| 124792 | ** the r-tree structure. |
| 124793 | */ |
| 124794 | if( rc==SQLITE_OK && nData>1 ){ |
| 124795 | /* Insert a new record into the r-tree */ |
| 124796 | RtreeCell cell; |
| 124797 | int ii; |
| 124798 | RtreeNode *pLeaf; |
| 124799 | |
| 124800 | /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */ |
| 124801 | assert( nData==(pRtree->nDim*2 + 3) ); |
| 124802 | if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ |
| 124803 | for(ii=0; ii<(pRtree->nDim*2); ii+=2){ |
| @@ -124817,22 +125832,53 @@ | |
| 124817 | goto constraint; |
| 124818 | } |
| 124819 | } |
| 124820 | } |
| 124821 | |
| 124822 | /* Figure out the rowid of the new row. */ |
| 124823 | if( sqlite3_value_type(azData[2])==SQLITE_NULL ){ |
| 124824 | rc = newRowid(pRtree, &cell.iRowid); |
| 124825 | }else{ |
| 124826 | cell.iRowid = sqlite3_value_int64(azData[2]); |
| 124827 | sqlite3_bind_int64(pRtree->pReadRowid, 1, cell.iRowid); |
| 124828 | if( SQLITE_ROW==sqlite3_step(pRtree->pReadRowid) ){ |
| 124829 | sqlite3_reset(pRtree->pReadRowid); |
| 124830 | rc = SQLITE_CONSTRAINT; |
| 124831 | goto constraint; |
| 124832 | } |
| 124833 | rc = sqlite3_reset(pRtree->pReadRowid); |
| 124834 | } |
| 124835 | *pRowid = cell.iRowid; |
| 124836 | |
| 124837 | if( rc==SQLITE_OK ){ |
| 124838 | rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf); |
| @@ -125068,10 +126114,12 @@ | |
| 125068 | int iErr = (argc<6) ? 2 : argc>(RTREE_MAX_DIMENSIONS*2+4) ? 3 : argc%2; |
| 125069 | if( aErrMsg[iErr] ){ |
| 125070 | *pzErr = sqlite3_mprintf("%s", aErrMsg[iErr]); |
| 125071 | return SQLITE_ERROR; |
| 125072 | } |
| 125073 | |
| 125074 | /* Allocate the sqlite3_vtab structure */ |
| 125075 | nDb = strlen(argv[1]); |
| 125076 | nName = strlen(argv[2]); |
| 125077 | pRtree = (Rtree *)sqlite3_malloc(sizeof(Rtree)+nDb+nName+2); |
| 125078 |
| --- 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.7.7. 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. |
| @@ -648,13 +648,13 @@ | |
| 648 | ** |
| 649 | ** See also: [sqlite3_libversion()], |
| 650 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 651 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 652 | */ |
| 653 | #define SQLITE_VERSION "3.7.7" |
| 654 | #define SQLITE_VERSION_NUMBER 3007007 |
| 655 | #define SQLITE_SOURCE_ID "2011-05-18 03:02:10 186d7ff1d9804d508e472e4939608bf2be67bdc2" |
| 656 | |
| 657 | /* |
| 658 | ** CAPI3REF: Run-Time Library Version Numbers |
| 659 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 660 | ** |
| @@ -916,11 +916,12 @@ | |
| 916 | ** Many SQLite functions return an integer result code from the set shown |
| 917 | ** here in order to indicates success or failure. |
| 918 | ** |
| 919 | ** New error codes may be added in future versions of SQLite. |
| 920 | ** |
| 921 | ** See also: [SQLITE_IOERR_READ | extended result codes], |
| 922 | ** [sqlite3_vtab_on_conflict()] [SQLITE_ROLLBACK | result codes]. |
| 923 | */ |
| 924 | #define SQLITE_OK 0 /* Successful result */ |
| 925 | /* beginning-of-error-codes */ |
| 926 | #define SQLITE_ERROR 1 /* SQL error or missing database */ |
| 927 | #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ |
| @@ -998,25 +999,26 @@ | |
| 999 | #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) |
| 1000 | #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) |
| 1001 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 1002 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 1003 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 1004 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 1005 | |
| 1006 | /* |
| 1007 | ** CAPI3REF: Flags For File Open Operations |
| 1008 | ** |
| 1009 | ** These bit values are intended for use in the |
| 1010 | ** 3rd parameter to the [sqlite3_open_v2()] interface and |
| 1011 | ** in the 4th parameter to the [sqlite3_vfs.xOpen] method. |
| 1012 | */ |
| 1013 | #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ |
| 1014 | #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ |
| 1015 | #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ |
| 1016 | #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ |
| 1017 | #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ |
| 1018 | #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ |
| 1019 | #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */ |
| 1020 | #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ |
| 1021 | #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ |
| 1022 | #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ |
| 1023 | #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ |
| 1024 | #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ |
| @@ -1123,21 +1125,22 @@ | |
| 1125 | }; |
| 1126 | |
| 1127 | /* |
| 1128 | ** CAPI3REF: OS Interface File Virtual Methods Object |
| 1129 | ** |
| 1130 | ** Every file opened by the [sqlite3_vfs.xOpen] method populates an |
| 1131 | ** [sqlite3_file] object (or, more commonly, a subclass of the |
| 1132 | ** [sqlite3_file] object) with a pointer to an instance of this object. |
| 1133 | ** This object defines the methods used to perform various operations |
| 1134 | ** against the open file represented by the [sqlite3_file] object. |
| 1135 | ** |
| 1136 | ** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element |
| 1137 | ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method |
| 1138 | ** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The |
| 1139 | ** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen] |
| 1140 | ** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element |
| 1141 | ** to NULL. |
| 1142 | ** |
| 1143 | ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or |
| 1144 | ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync(). |
| 1145 | ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY] |
| 1146 | ** flag may be ORed in to indicate that only the data of the file |
| @@ -1302,10 +1305,11 @@ | |
| 1305 | */ |
| 1306 | typedef struct sqlite3_mutex sqlite3_mutex; |
| 1307 | |
| 1308 | /* |
| 1309 | ** CAPI3REF: OS Interface Object |
| 1310 | ** KEYWORDS: VFS VFSes |
| 1311 | ** |
| 1312 | ** An instance of the sqlite3_vfs object defines the interface between |
| 1313 | ** the SQLite core and the underlying operating system. The "vfs" |
| 1314 | ** in the name of the object stands for "virtual file system". |
| 1315 | ** |
| @@ -1334,10 +1338,11 @@ | |
| 1338 | ** object once the object has been registered. |
| 1339 | ** |
| 1340 | ** The zName field holds the name of the VFS module. The name must |
| 1341 | ** be unique across all VFS modules. |
| 1342 | ** |
| 1343 | ** [[sqlite3_vfs.xOpen]] |
| 1344 | ** ^SQLite guarantees that the zFilename parameter to xOpen |
| 1345 | ** is either a NULL pointer or string obtained |
| 1346 | ** from xFullPathname() with an optional suffix added. |
| 1347 | ** ^If a suffix is added to the zFilename parameter, it will |
| 1348 | ** consist of a single "-" character followed by no more than |
| @@ -1411,10 +1416,11 @@ | |
| 1416 | ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do |
| 1417 | ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods |
| 1418 | ** element will be valid after xOpen returns regardless of the success |
| 1419 | ** or failure of the xOpen call. |
| 1420 | ** |
| 1421 | ** [[sqlite3_vfs.xAccess]] |
| 1422 | ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] |
| 1423 | ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to |
| 1424 | ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ] |
| 1425 | ** to test whether a file is at least readable. The file can be a |
| 1426 | ** directory. |
| @@ -1657,13 +1663,13 @@ | |
| 1663 | ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE. |
| 1664 | ** Note, however, that ^sqlite3_config() can be called as part of the |
| 1665 | ** implementation of an application-defined [sqlite3_os_init()]. |
| 1666 | ** |
| 1667 | ** The first argument to sqlite3_config() is an integer |
| 1668 | ** [configuration option] that determines |
| 1669 | ** what property of SQLite is to be configured. Subsequent arguments |
| 1670 | ** vary depending on the [configuration option] |
| 1671 | ** in the first argument. |
| 1672 | ** |
| 1673 | ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. |
| 1674 | ** ^If the option is unknown or SQLite is unable to set the option |
| 1675 | ** then this routine returns a non-zero [error code]. |
| @@ -1769,10 +1775,11 @@ | |
| 1775 | void *pAppData; /* Argument to xInit() and xShutdown() */ |
| 1776 | }; |
| 1777 | |
| 1778 | /* |
| 1779 | ** CAPI3REF: Configuration Options |
| 1780 | ** KEYWORDS: {configuration option} |
| 1781 | ** |
| 1782 | ** These constants are the available integer configuration options that |
| 1783 | ** can be passed as the first argument to the [sqlite3_config()] interface. |
| 1784 | ** |
| 1785 | ** New configuration options may be added in future releases of SQLite. |
| @@ -1781,11 +1788,11 @@ | |
| 1788 | ** the call worked. The [sqlite3_config()] interface will return a |
| 1789 | ** non-zero [error code] if a discontinued or unsupported configuration option |
| 1790 | ** is invoked. |
| 1791 | ** |
| 1792 | ** <dl> |
| 1793 | ** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt> |
| 1794 | ** <dd>There are no arguments to this option. ^This option sets the |
| 1795 | ** [threading mode] to Single-thread. In other words, it disables |
| 1796 | ** all mutexing and puts SQLite into a mode where it can only be used |
| 1797 | ** by a single thread. ^If SQLite is compiled with |
| 1798 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| @@ -1792,11 +1799,11 @@ | |
| 1799 | ** it is not possible to change the [threading mode] from its default |
| 1800 | ** value of Single-thread and so [sqlite3_config()] will return |
| 1801 | ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD |
| 1802 | ** configuration option.</dd> |
| 1803 | ** |
| 1804 | ** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt> |
| 1805 | ** <dd>There are no arguments to this option. ^This option sets the |
| 1806 | ** [threading mode] to Multi-thread. In other words, it disables |
| 1807 | ** mutexing on [database connection] and [prepared statement] objects. |
| 1808 | ** The application is responsible for serializing access to |
| 1809 | ** [database connections] and [prepared statements]. But other mutexes |
| @@ -1806,11 +1813,11 @@ | |
| 1813 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1814 | ** it is not possible to set the Multi-thread [threading mode] and |
| 1815 | ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
| 1816 | ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd> |
| 1817 | ** |
| 1818 | ** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt> |
| 1819 | ** <dd>There are no arguments to this option. ^This option sets the |
| 1820 | ** [threading mode] to Serialized. In other words, this option enables |
| 1821 | ** all mutexes including the recursive |
| 1822 | ** mutexes on [database connection] and [prepared statement] objects. |
| 1823 | ** In this mode (which is the default when SQLite is compiled with |
| @@ -1822,27 +1829,27 @@ | |
| 1829 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1830 | ** it is not possible to set the Serialized [threading mode] and |
| 1831 | ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
| 1832 | ** SQLITE_CONFIG_SERIALIZED configuration option.</dd> |
| 1833 | ** |
| 1834 | ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt> |
| 1835 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1836 | ** instance of the [sqlite3_mem_methods] structure. The argument specifies |
| 1837 | ** alternative low-level memory allocation routines to be used in place of |
| 1838 | ** the memory allocation routines built into SQLite.)^ ^SQLite makes |
| 1839 | ** its own private copy of the content of the [sqlite3_mem_methods] structure |
| 1840 | ** before the [sqlite3_config()] call returns.</dd> |
| 1841 | ** |
| 1842 | ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt> |
| 1843 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1844 | ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods] |
| 1845 | ** structure is filled with the currently defined memory allocation routines.)^ |
| 1846 | ** This option can be used to overload the default memory allocation |
| 1847 | ** routines with a wrapper that simulations memory allocation failure or |
| 1848 | ** tracks memory usage, for example. </dd> |
| 1849 | ** |
| 1850 | ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> |
| 1851 | ** <dd> ^This option takes single argument of type int, interpreted as a |
| 1852 | ** boolean, which enables or disables the collection of memory allocation |
| 1853 | ** statistics. ^(When memory allocation statistics are disabled, the |
| 1854 | ** following SQLite interfaces become non-operational: |
| 1855 | ** <ul> |
| @@ -1854,11 +1861,11 @@ | |
| 1861 | ** ^Memory allocation statistics are enabled by default unless SQLite is |
| 1862 | ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory |
| 1863 | ** allocation statistics are disabled by default. |
| 1864 | ** </dd> |
| 1865 | ** |
| 1866 | ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt> |
| 1867 | ** <dd> ^This option specifies a static memory buffer that SQLite can use for |
| 1868 | ** scratch memory. There are three arguments: A pointer an 8-byte |
| 1869 | ** aligned memory buffer from which the scratch allocations will be |
| 1870 | ** drawn, the size of each scratch allocation (sz), |
| 1871 | ** and the maximum number of scratch allocations (N). The sz |
| @@ -1870,11 +1877,11 @@ | |
| 1877 | ** ^SQLite will never require a scratch buffer that is more than 6 |
| 1878 | ** times the database page size. ^If SQLite needs needs additional |
| 1879 | ** scratch memory beyond what is provided by this configuration option, then |
| 1880 | ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd> |
| 1881 | ** |
| 1882 | ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt> |
| 1883 | ** <dd> ^This option specifies a static memory buffer that SQLite can use for |
| 1884 | ** the database page cache with the default page cache implemenation. |
| 1885 | ** This configuration should not be used if an application-define page |
| 1886 | ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option. |
| 1887 | ** There are three arguments to this option: A pointer to 8-byte aligned |
| @@ -1891,11 +1898,11 @@ | |
| 1898 | ** SQLite goes to [sqlite3_malloc()] for the additional storage space. |
| 1899 | ** The pointer in the first argument must |
| 1900 | ** be aligned to an 8-byte boundary or subsequent behavior of SQLite |
| 1901 | ** will be undefined.</dd> |
| 1902 | ** |
| 1903 | ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> |
| 1904 | ** <dd> ^This option specifies a static memory buffer that SQLite will use |
| 1905 | ** for all of its dynamic memory allocation needs beyond those provided |
| 1906 | ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. |
| 1907 | ** There are three arguments: An 8-byte aligned pointer to the memory, |
| 1908 | ** the number of bytes in the memory buffer, and the minimum allocation size. |
| @@ -1908,11 +1915,11 @@ | |
| 1915 | ** The first pointer (the memory pointer) must be aligned to an 8-byte |
| 1916 | ** boundary or subsequent behavior of SQLite will be undefined. |
| 1917 | ** The minimum allocation size is capped at 2^12. Reasonable values |
| 1918 | ** for the minimum allocation size are 2^5 through 2^8.</dd> |
| 1919 | ** |
| 1920 | ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt> |
| 1921 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1922 | ** instance of the [sqlite3_mutex_methods] structure. The argument specifies |
| 1923 | ** alternative low-level mutex routines to be used in place |
| 1924 | ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the |
| 1925 | ** content of the [sqlite3_mutex_methods] structure before the call to |
| @@ -1920,11 +1927,11 @@ | |
| 1927 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1928 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1929 | ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will |
| 1930 | ** return [SQLITE_ERROR].</dd> |
| 1931 | ** |
| 1932 | ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt> |
| 1933 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1934 | ** instance of the [sqlite3_mutex_methods] structure. The |
| 1935 | ** [sqlite3_mutex_methods] |
| 1936 | ** structure is filled with the currently defined mutex routines.)^ |
| 1937 | ** This option can be used to overload the default mutex allocation |
| @@ -1933,32 +1940,32 @@ | |
| 1940 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1941 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1942 | ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will |
| 1943 | ** return [SQLITE_ERROR].</dd> |
| 1944 | ** |
| 1945 | ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt> |
| 1946 | ** <dd> ^(This option takes two arguments that determine the default |
| 1947 | ** memory allocation for the lookaside memory allocator on each |
| 1948 | ** [database connection]. The first argument is the |
| 1949 | ** size of each lookaside buffer slot and the second is the number of |
| 1950 | ** slots allocated to each database connection.)^ ^(This option sets the |
| 1951 | ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] |
| 1952 | ** verb to [sqlite3_db_config()] can be used to change the lookaside |
| 1953 | ** configuration on individual connections.)^ </dd> |
| 1954 | ** |
| 1955 | ** [[SQLITE_CONFIG_PCACHE]] <dt>SQLITE_CONFIG_PCACHE</dt> |
| 1956 | ** <dd> ^(This option takes a single argument which is a pointer to |
| 1957 | ** an [sqlite3_pcache_methods] object. This object specifies the interface |
| 1958 | ** to a custom page cache implementation.)^ ^SQLite makes a copy of the |
| 1959 | ** object and uses it for page cache memory allocations.</dd> |
| 1960 | ** |
| 1961 | ** [[SQLITE_CONFIG_GETPCACHE]] <dt>SQLITE_CONFIG_GETPCACHE</dt> |
| 1962 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1963 | ** [sqlite3_pcache_methods] object. SQLite copies of the current |
| 1964 | ** page cache implementation into that object.)^ </dd> |
| 1965 | ** |
| 1966 | ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> |
| 1967 | ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a |
| 1968 | ** function with a call signature of void(*)(void*,int,const char*), |
| 1969 | ** and a pointer to void. ^If the function pointer is not NULL, it is |
| 1970 | ** invoked by [sqlite3_log()] to process each logging event. ^If the |
| 1971 | ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op. |
| @@ -1972,10 +1979,22 @@ | |
| 1979 | ** The SQLite logging interface is not reentrant; the logger function |
| 1980 | ** supplied by the application must not invoke any SQLite interface. |
| 1981 | ** In a multi-threaded application, the application-defined logger |
| 1982 | ** function must be threadsafe. </dd> |
| 1983 | ** |
| 1984 | ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI |
| 1985 | ** <dd> This option takes a single argument of type int. If non-zero, then |
| 1986 | ** URI handling is globally enabled. If the parameter is zero, then URI handling |
| 1987 | ** is globally disabled. If URI handling is globally enabled, all filenames |
| 1988 | ** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or |
| 1989 | ** specified as part of [ATTACH] commands are interpreted as URIs, regardless |
| 1990 | ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database |
| 1991 | ** connection is opened. If it is globally disabled, filenames are |
| 1992 | ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the |
| 1993 | ** database connection is opened. By default, URI handling is globally |
| 1994 | ** disabled. The default value may be changed by compiling with the |
| 1995 | ** [SQLITE_USE_URI] symbol defined. |
| 1996 | ** </dl> |
| 1997 | */ |
| 1998 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1999 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 2000 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| @@ -1990,10 +2009,11 @@ | |
| 2009 | /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ |
| 2010 | #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ |
| 2011 | #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */ |
| 2012 | #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */ |
| 2013 | #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ |
| 2014 | #define SQLITE_CONFIG_URI 17 /* int */ |
| 2015 | |
| 2016 | /* |
| 2017 | ** CAPI3REF: Database Connection Configuration Options |
| 2018 | ** |
| 2019 | ** These constants are the available integer configuration options that |
| @@ -2075,17 +2095,21 @@ | |
| 2095 | ** the table has a column of type [INTEGER PRIMARY KEY] then that column |
| 2096 | ** is another alias for the rowid. |
| 2097 | ** |
| 2098 | ** ^This routine returns the [rowid] of the most recent |
| 2099 | ** successful [INSERT] into the database from the [database connection] |
| 2100 | ** in the first argument. ^As of SQLite version 3.7.7, this routines |
| 2101 | ** records the last insert rowid of both ordinary tables and [virtual tables]. |
| 2102 | ** ^If no successful [INSERT]s |
| 2103 | ** have ever occurred on that database connection, zero is returned. |
| 2104 | ** |
| 2105 | ** ^(If an [INSERT] occurs within a trigger or within a [virtual table] |
| 2106 | ** method, then this routine will return the [rowid] of the inserted |
| 2107 | ** row as long as the trigger or virtual table method is running. |
| 2108 | ** But once the trigger or virtual table method ends, the value returned |
| 2109 | ** by this routine reverts to what it was before the trigger or virtual |
| 2110 | ** table method began.)^ |
| 2111 | ** |
| 2112 | ** ^An [INSERT] that fails due to a constraint violation is not a |
| 2113 | ** successful [INSERT] and does not change the value returned by this |
| 2114 | ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK, |
| 2115 | ** and INSERT OR ABORT make no changes to the return value of this |
| @@ -2744,10 +2768,13 @@ | |
| 2768 | ** The [sqlite3_set_authorizer | authorizer callback function] must |
| 2769 | ** return either [SQLITE_OK] or one of these two constants in order |
| 2770 | ** to signal SQLite whether or not the action is permitted. See the |
| 2771 | ** [sqlite3_set_authorizer | authorizer documentation] for additional |
| 2772 | ** information. |
| 2773 | ** |
| 2774 | ** Note that SQLITE_IGNORE is also used as a [SQLITE_ROLLBACK | return code] |
| 2775 | ** from the [sqlite3_vtab_on_conflict()] interface. |
| 2776 | */ |
| 2777 | #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ |
| 2778 | #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ |
| 2779 | |
| 2780 | /* |
| @@ -2866,11 +2893,11 @@ | |
| 2893 | SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); |
| 2894 | |
| 2895 | /* |
| 2896 | ** CAPI3REF: Opening A New Database Connection |
| 2897 | ** |
| 2898 | ** ^These routines open an SQLite database file as specified by the |
| 2899 | ** filename argument. ^The filename argument is interpreted as UTF-8 for |
| 2900 | ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte |
| 2901 | ** order for sqlite3_open16(). ^(A [database connection] handle is usually |
| 2902 | ** returned in *ppDb, even if an error occurs. The only exception is that |
| 2903 | ** if SQLite is unable to allocate memory to hold the [sqlite3] object, |
| @@ -2893,11 +2920,11 @@ | |
| 2920 | ** except that it accepts two additional parameters for additional control |
| 2921 | ** over the new database connection. ^(The flags parameter to |
| 2922 | ** sqlite3_open_v2() can take one of |
| 2923 | ** the following three values, optionally combined with the |
| 2924 | ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE], |
| 2925 | ** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^ |
| 2926 | ** |
| 2927 | ** <dl> |
| 2928 | ** ^(<dt>[SQLITE_OPEN_READONLY]</dt> |
| 2929 | ** <dd>The database is opened in read-only mode. If the database does not |
| 2930 | ** already exist, an error is returned.</dd>)^ |
| @@ -2912,13 +2939,12 @@ | |
| 2939 | ** it does not already exist. This is the behavior that is always used for |
| 2940 | ** sqlite3_open() and sqlite3_open16().</dd>)^ |
| 2941 | ** </dl> |
| 2942 | ** |
| 2943 | ** If the 3rd parameter to sqlite3_open_v2() is not one of the |
| 2944 | ** combinations shown above optionally combined with other |
| 2945 | ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits] |
| 2946 | ** then the behavior is undefined. |
| 2947 | ** |
| 2948 | ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection |
| 2949 | ** opens in the multi-thread [threading mode] as long as the single-thread |
| 2950 | ** mode has not been set at compile-time or start-time. ^If the |
| @@ -2928,10 +2954,15 @@ | |
| 2954 | ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be |
| 2955 | ** eligible to use [shared cache mode], regardless of whether or not shared |
| 2956 | ** cache is enabled using [sqlite3_enable_shared_cache()]. ^The |
| 2957 | ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not |
| 2958 | ** participate in [shared cache mode] even if it is enabled. |
| 2959 | ** |
| 2960 | ** ^The fourth parameter to sqlite3_open_v2() is the name of the |
| 2961 | ** [sqlite3_vfs] object that defines the operating system interface that |
| 2962 | ** the new database connection should use. ^If the fourth parameter is |
| 2963 | ** a NULL pointer then the default [sqlite3_vfs] object is used. |
| 2964 | ** |
| 2965 | ** ^If the filename is ":memory:", then a private, temporary in-memory database |
| 2966 | ** is created for the connection. ^This in-memory database will vanish when |
| 2967 | ** the database connection is closed. Future versions of SQLite might |
| 2968 | ** make use of additional special filenames that begin with the ":" character. |
| @@ -2941,14 +2972,115 @@ | |
| 2972 | ** |
| 2973 | ** ^If the filename is an empty string, then a private, temporary |
| 2974 | ** on-disk database will be created. ^This private database will be |
| 2975 | ** automatically deleted as soon as the database connection is closed. |
| 2976 | ** |
| 2977 | ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3> |
| 2978 | ** |
| 2979 | ** ^If [URI filename] interpretation is enabled, and the filename argument |
| 2980 | ** begins with "file:", then the filename is interpreted as a URI. ^URI |
| 2981 | ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is |
| 2982 | ** is set in the fourth argument to sqlite3_open_v2(), or if it has |
| 2983 | ** been enabled globally using the [SQLITE_CONFIG_URI] option with the |
| 2984 | ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option. |
| 2985 | ** As of SQLite version 3.7.7, URI filename interpretation is turned off |
| 2986 | ** by default, but future releases of SQLite might enable URI filename |
| 2987 | ** intepretation by default. See "[URI filenames]" for additional |
| 2988 | ** information. |
| 2989 | ** |
| 2990 | ** URI filenames are parsed according to RFC 3986. ^If the URI contains an |
| 2991 | ** authority, then it must be either an empty string or the string |
| 2992 | ** "localhost". ^If the authority is not an empty string or "localhost", an |
| 2993 | ** error is returned to the caller. ^The fragment component of a URI, if |
| 2994 | ** present, is ignored. |
| 2995 | ** |
| 2996 | ** ^SQLite uses the path component of the URI as the name of the disk file |
| 2997 | ** which contains the database. ^If the path begins with a '/' character, |
| 2998 | ** then it is interpreted as an absolute path. ^If the path does not begin |
| 2999 | ** with a '/' (meaning that the authority section is omitted from the URI) |
| 3000 | ** then the path is interpreted as a relative path. |
| 3001 | ** ^On windows, the first component of an absolute path |
| 3002 | ** is a drive specification (e.g. "C:"). |
| 3003 | ** |
| 3004 | ** [[core URI query parameters]] |
| 3005 | ** The query component of a URI may contain parameters that are interpreted |
| 3006 | ** either by SQLite itself, or by a [VFS | custom VFS implementation]. |
| 3007 | ** SQLite interprets the following three query parameters: |
| 3008 | ** |
| 3009 | ** <ul> |
| 3010 | ** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of |
| 3011 | ** a VFS object that provides the operating system interface that should |
| 3012 | ** be used to access the database file on disk. ^If this option is set to |
| 3013 | ** an empty string the default VFS object is used. ^Specifying an unknown |
| 3014 | ** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is |
| 3015 | ** present, then the VFS specified by the option takes precedence over |
| 3016 | ** the value passed as the fourth parameter to sqlite3_open_v2(). |
| 3017 | ** |
| 3018 | ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw" or |
| 3019 | ** "rwc". Attempting to set it to any other value is an error)^. |
| 3020 | ** ^If "ro" is specified, then the database is opened for read-only |
| 3021 | ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the |
| 3022 | ** third argument to sqlite3_prepare_v2(). ^If the mode option is set to |
| 3023 | ** "rw", then the database is opened for read-write (but not create) |
| 3024 | ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had |
| 3025 | ** been set. ^Value "rwc" is equivalent to setting both |
| 3026 | ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If sqlite3_open_v2() is |
| 3027 | ** used, it is an error to specify a value for the mode parameter that is |
| 3028 | ** less restrictive than that specified by the flags passed as the third |
| 3029 | ** parameter. |
| 3030 | ** |
| 3031 | ** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or |
| 3032 | ** "private". ^Setting it to "shared" is equivalent to setting the |
| 3033 | ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to |
| 3034 | ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is |
| 3035 | ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit. |
| 3036 | ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in |
| 3037 | ** a URI filename, its value overrides any behaviour requested by setting |
| 3038 | ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag. |
| 3039 | ** </ul> |
| 3040 | ** |
| 3041 | ** ^Specifying an unknown parameter in the query component of a URI is not an |
| 3042 | ** error. Future versions of SQLite might understand additional query |
| 3043 | ** parameters. See "[query parameters with special meaning to SQLite]" for |
| 3044 | ** additional information. |
| 3045 | ** |
| 3046 | ** [[URI filename examples]] <h3>URI filename examples</h3> |
| 3047 | ** |
| 3048 | ** <table border="1" align=center cellpadding=5> |
| 3049 | ** <tr><th> URI filenames <th> Results |
| 3050 | ** <tr><td> file:data.db <td> |
| 3051 | ** Open the file "data.db" in the current directory. |
| 3052 | ** <tr><td> file:/home/fred/data.db<br> |
| 3053 | ** file:///home/fred/data.db <br> |
| 3054 | ** file://localhost/home/fred/data.db <br> <td> |
| 3055 | ** Open the database file "/home/fred/data.db". |
| 3056 | ** <tr><td> file://darkstar/home/fred/data.db <td> |
| 3057 | ** An error. "darkstar" is not a recognized authority. |
| 3058 | ** <tr><td style="white-space:nowrap"> |
| 3059 | ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db |
| 3060 | ** <td> Windows only: Open the file "data.db" on fred's desktop on drive |
| 3061 | ** C:. Note that the %20 escaping in this example is not strictly |
| 3062 | ** necessary - space characters can be used literally |
| 3063 | ** in URI filenames. |
| 3064 | ** <tr><td> file:data.db?mode=ro&cache=private <td> |
| 3065 | ** Open file "data.db" in the current directory for read-only access. |
| 3066 | ** Regardless of whether or not shared-cache mode is enabled by |
| 3067 | ** default, use a private cache. |
| 3068 | ** <tr><td> file:/home/fred/data.db?vfs=unix-nolock <td> |
| 3069 | ** Open file "/home/fred/data.db". Use the special VFS "unix-nolock". |
| 3070 | ** <tr><td> file:data.db?mode=readonly <td> |
| 3071 | ** An error. "readonly" is not a valid option for the "mode" parameter. |
| 3072 | ** </table> |
| 3073 | ** |
| 3074 | ** ^URI hexadecimal escape sequences (%HH) are supported within the path and |
| 3075 | ** query components of a URI. A hexadecimal escape sequence consists of a |
| 3076 | ** percent sign - "%" - followed by exactly two hexadecimal digits |
| 3077 | ** specifying an octet value. ^Before the path or query components of a |
| 3078 | ** URI filename are interpreted, they are encoded using UTF-8 and all |
| 3079 | ** hexadecimal escape sequences replaced by a single byte containing the |
| 3080 | ** corresponding octet. If this process generates an invalid UTF-8 encoding, |
| 3081 | ** the results are undefined. |
| 3082 | ** |
| 3083 | ** <b>Note to Windows users:</b> The encoding used for the filename argument |
| 3084 | ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever |
| 3085 | ** codepage is currently defined. Filenames containing international |
| 3086 | ** characters must be converted to UTF-8 prior to passing them into |
| @@ -2966,10 +3098,30 @@ | |
| 3098 | const char *filename, /* Database filename (UTF-8) */ |
| 3099 | sqlite3 **ppDb, /* OUT: SQLite db handle */ |
| 3100 | int flags, /* Flags */ |
| 3101 | const char *zVfs /* Name of VFS module to use */ |
| 3102 | ); |
| 3103 | |
| 3104 | /* |
| 3105 | ** CAPI3REF: Obtain Values For URI Parameters |
| 3106 | ** |
| 3107 | ** This is a utility routine, useful to VFS implementations, that checks |
| 3108 | ** to see if a database file was a URI that contained a specific query |
| 3109 | ** parameter, and if so obtains the value of the query parameter. |
| 3110 | ** |
| 3111 | ** The zFilename argument is the filename pointer passed into the xOpen() |
| 3112 | ** method of a VFS implementation. The zParam argument is the name of the |
| 3113 | ** query parameter we seek. This routine returns the value of the zParam |
| 3114 | ** parameter if it exists. If the parameter does not exist, this routine |
| 3115 | ** returns a NULL pointer. |
| 3116 | ** |
| 3117 | ** If the zFilename argument to this function is not a pointer that SQLite |
| 3118 | ** passed into the xOpen VFS method, then the behavior of this routine |
| 3119 | ** is undefined and probably undesirable. |
| 3120 | */ |
| 3121 | SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam); |
| 3122 | |
| 3123 | |
| 3124 | /* |
| 3125 | ** CAPI3REF: Error Codes And Messages |
| 3126 | ** |
| 3127 | ** ^The sqlite3_errcode() interface returns the numeric [result code] or |
| @@ -3082,47 +3234,49 @@ | |
| 3234 | ** that can be lowered at run-time using [sqlite3_limit()]. |
| 3235 | ** The synopsis of the meanings of the various limits is shown below. |
| 3236 | ** Additional information is available at [limits | Limits in SQLite]. |
| 3237 | ** |
| 3238 | ** <dl> |
| 3239 | ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt> |
| 3240 | ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^ |
| 3241 | ** |
| 3242 | ** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt> |
| 3243 | ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^ |
| 3244 | ** |
| 3245 | ** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt> |
| 3246 | ** <dd>The maximum number of columns in a table definition or in the |
| 3247 | ** result set of a [SELECT] or the maximum number of columns in an index |
| 3248 | ** or in an ORDER BY or GROUP BY clause.</dd>)^ |
| 3249 | ** |
| 3250 | ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> |
| 3251 | ** <dd>The maximum depth of the parse tree on any expression.</dd>)^ |
| 3252 | ** |
| 3253 | ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt> |
| 3254 | ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^ |
| 3255 | ** |
| 3256 | ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt> |
| 3257 | ** <dd>The maximum number of instructions in a virtual machine program |
| 3258 | ** used to implement an SQL statement. This limit is not currently |
| 3259 | ** enforced, though that might be added in some future release of |
| 3260 | ** SQLite.</dd>)^ |
| 3261 | ** |
| 3262 | ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt> |
| 3263 | ** <dd>The maximum number of arguments on a function.</dd>)^ |
| 3264 | ** |
| 3265 | ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt> |
| 3266 | ** <dd>The maximum number of [ATTACH | attached databases].)^</dd> |
| 3267 | ** |
| 3268 | ** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]] |
| 3269 | ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt> |
| 3270 | ** <dd>The maximum length of the pattern argument to the [LIKE] or |
| 3271 | ** [GLOB] operators.</dd>)^ |
| 3272 | ** |
| 3273 | ** [[SQLITE_LIMIT_VARIABLE_NUMBER]] |
| 3274 | ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> |
| 3275 | ** <dd>The maximum index number of any [parameter] in an SQL statement.)^ |
| 3276 | ** |
| 3277 | ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> |
| 3278 | ** <dd>The maximum depth of recursion for triggers.</dd>)^ |
| 3279 | ** </dl> |
| 3280 | */ |
| 3281 | #define SQLITE_LIMIT_LENGTH 0 |
| 3282 | #define SQLITE_LIMIT_SQL_LENGTH 1 |
| @@ -5153,10 +5307,15 @@ | |
| 5307 | int (*xRollback)(sqlite3_vtab *pVTab); |
| 5308 | int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName, |
| 5309 | void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), |
| 5310 | void **ppArg); |
| 5311 | int (*xRename)(sqlite3_vtab *pVtab, const char *zNew); |
| 5312 | /* The methods above are in version 1 of the sqlite_module object. Those |
| 5313 | ** below are for version 2 and greater. */ |
| 5314 | int (*xSavepoint)(sqlite3_vtab *pVTab, int); |
| 5315 | int (*xRelease)(sqlite3_vtab *pVTab, int); |
| 5316 | int (*xRollbackTo)(sqlite3_vtab *pVTab, int); |
| 5317 | }; |
| 5318 | |
| 5319 | /* |
| 5320 | ** CAPI3REF: Virtual Table Indexing Information |
| 5321 | ** KEYWORDS: sqlite3_index_info |
| @@ -5967,11 +6126,11 @@ | |
| 6126 | ** |
| 6127 | ** ^This interface is used to retrieve runtime status information |
| 6128 | ** about the performance of SQLite, and optionally to reset various |
| 6129 | ** highwater marks. ^The first argument is an integer code for |
| 6130 | ** the specific parameter to measure. ^(Recognized integer codes |
| 6131 | ** are of the form [status parameters | SQLITE_STATUS_...].)^ |
| 6132 | ** ^The current value of the parameter is returned into *pCurrent. |
| 6133 | ** ^The highest recorded value is returned in *pHighwater. ^If the |
| 6134 | ** resetFlag is true, then the highest record value is reset after |
| 6135 | ** *pHighwater is written. ^(Some parameters do not record the highest |
| 6136 | ** value. For those parameters |
| @@ -5994,82 +6153,84 @@ | |
| 6153 | SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); |
| 6154 | |
| 6155 | |
| 6156 | /* |
| 6157 | ** CAPI3REF: Status Parameters |
| 6158 | ** KEYWORDS: {status parameters} |
| 6159 | ** |
| 6160 | ** These integer constants designate various run-time status parameters |
| 6161 | ** that can be returned by [sqlite3_status()]. |
| 6162 | ** |
| 6163 | ** <dl> |
| 6164 | ** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt> |
| 6165 | ** <dd>This parameter is the current amount of memory checked out |
| 6166 | ** using [sqlite3_malloc()], either directly or indirectly. The |
| 6167 | ** figure includes calls made to [sqlite3_malloc()] by the application |
| 6168 | ** and internal memory usage by the SQLite library. Scratch memory |
| 6169 | ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache |
| 6170 | ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in |
| 6171 | ** this parameter. The amount returned is the sum of the allocation |
| 6172 | ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^ |
| 6173 | ** |
| 6174 | ** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt> |
| 6175 | ** <dd>This parameter records the largest memory allocation request |
| 6176 | ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their |
| 6177 | ** internal equivalents). Only the value returned in the |
| 6178 | ** *pHighwater parameter to [sqlite3_status()] is of interest. |
| 6179 | ** The value written into the *pCurrent parameter is undefined.</dd>)^ |
| 6180 | ** |
| 6181 | ** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt> |
| 6182 | ** <dd>This parameter records the number of separate memory allocations |
| 6183 | ** currently checked out.</dd>)^ |
| 6184 | ** |
| 6185 | ** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt> |
| 6186 | ** <dd>This parameter returns the number of pages used out of the |
| 6187 | ** [pagecache memory allocator] that was configured using |
| 6188 | ** [SQLITE_CONFIG_PAGECACHE]. The |
| 6189 | ** value returned is in pages, not in bytes.</dd>)^ |
| 6190 | ** |
| 6191 | ** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]] |
| 6192 | ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt> |
| 6193 | ** <dd>This parameter returns the number of bytes of page cache |
| 6194 | ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE] |
| 6195 | ** buffer and where forced to overflow to [sqlite3_malloc()]. The |
| 6196 | ** returned value includes allocations that overflowed because they |
| 6197 | ** where too large (they were larger than the "sz" parameter to |
| 6198 | ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because |
| 6199 | ** no space was left in the page cache.</dd>)^ |
| 6200 | ** |
| 6201 | ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt> |
| 6202 | ** <dd>This parameter records the largest memory allocation request |
| 6203 | ** handed to [pagecache memory allocator]. Only the value returned in the |
| 6204 | ** *pHighwater parameter to [sqlite3_status()] is of interest. |
| 6205 | ** The value written into the *pCurrent parameter is undefined.</dd>)^ |
| 6206 | ** |
| 6207 | ** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt> |
| 6208 | ** <dd>This parameter returns the number of allocations used out of the |
| 6209 | ** [scratch memory allocator] configured using |
| 6210 | ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not |
| 6211 | ** in bytes. Since a single thread may only have one scratch allocation |
| 6212 | ** outstanding at time, this parameter also reports the number of threads |
| 6213 | ** using scratch memory at the same time.</dd>)^ |
| 6214 | ** |
| 6215 | ** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt> |
| 6216 | ** <dd>This parameter returns the number of bytes of scratch memory |
| 6217 | ** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH] |
| 6218 | ** buffer and where forced to overflow to [sqlite3_malloc()]. The values |
| 6219 | ** returned include overflows because the requested allocation was too |
| 6220 | ** larger (that is, because the requested allocation was larger than the |
| 6221 | ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer |
| 6222 | ** slots were available. |
| 6223 | ** </dd>)^ |
| 6224 | ** |
| 6225 | ** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt> |
| 6226 | ** <dd>This parameter records the largest memory allocation request |
| 6227 | ** handed to [scratch memory allocator]. Only the value returned in the |
| 6228 | ** *pHighwater parameter to [sqlite3_status()] is of interest. |
| 6229 | ** The value written into the *pCurrent parameter is undefined.</dd>)^ |
| 6230 | ** |
| 6231 | ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt> |
| 6232 | ** <dd>This parameter records the deepest parser stack. It is only |
| 6233 | ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^ |
| 6234 | ** </dl> |
| 6235 | ** |
| 6236 | ** New status parameters may be added from time to time. |
| @@ -6090,13 +6251,13 @@ | |
| 6251 | ** |
| 6252 | ** ^This interface is used to retrieve runtime status information |
| 6253 | ** about a single [database connection]. ^The first argument is the |
| 6254 | ** database connection object to be interrogated. ^The second argument |
| 6255 | ** is an integer constant, taken from the set of |
| 6256 | ** [SQLITE_DBSTATUS options], that |
| 6257 | ** determines the parameter to interrogate. The set of |
| 6258 | ** [SQLITE_DBSTATUS options] is likely |
| 6259 | ** to grow in future releases of SQLite. |
| 6260 | ** |
| 6261 | ** ^The current value of the requested parameter is written into *pCur |
| 6262 | ** and the highest instantaneous value is written into *pHiwtr. ^If |
| 6263 | ** the resetFlg is true, then the highest instantaneous value is |
| @@ -6109,10 +6270,11 @@ | |
| 6270 | */ |
| 6271 | SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); |
| 6272 | |
| 6273 | /* |
| 6274 | ** CAPI3REF: Status Parameters for database connections |
| 6275 | ** KEYWORDS: {SQLITE_DBSTATUS options} |
| 6276 | ** |
| 6277 | ** These constants are the available integer "verbs" that can be passed as |
| 6278 | ** the second argument to the [sqlite3_db_status()] interface. |
| 6279 | ** |
| 6280 | ** New verbs may be added in future releases of SQLite. Existing verbs |
| @@ -6120,48 +6282,50 @@ | |
| 6282 | ** [sqlite3_db_status()] to make sure that the call worked. |
| 6283 | ** The [sqlite3_db_status()] interface will return a non-zero error code |
| 6284 | ** if a discontinued or unsupported verb is invoked. |
| 6285 | ** |
| 6286 | ** <dl> |
| 6287 | ** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt> |
| 6288 | ** <dd>This parameter returns the number of lookaside memory slots currently |
| 6289 | ** checked out.</dd>)^ |
| 6290 | ** |
| 6291 | ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt> |
| 6292 | ** <dd>This parameter returns the number malloc attempts that were |
| 6293 | ** satisfied using lookaside memory. Only the high-water value is meaningful; |
| 6294 | ** the current value is always zero.)^ |
| 6295 | ** |
| 6296 | ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]] |
| 6297 | ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt> |
| 6298 | ** <dd>This parameter returns the number malloc attempts that might have |
| 6299 | ** been satisfied using lookaside memory but failed due to the amount of |
| 6300 | ** memory requested being larger than the lookaside slot size. |
| 6301 | ** Only the high-water value is meaningful; |
| 6302 | ** the current value is always zero.)^ |
| 6303 | ** |
| 6304 | ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]] |
| 6305 | ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt> |
| 6306 | ** <dd>This parameter returns the number malloc attempts that might have |
| 6307 | ** been satisfied using lookaside memory but failed due to all lookaside |
| 6308 | ** memory already being in use. |
| 6309 | ** Only the high-water value is meaningful; |
| 6310 | ** the current value is always zero.)^ |
| 6311 | ** |
| 6312 | ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt> |
| 6313 | ** <dd>This parameter returns the approximate number of of bytes of heap |
| 6314 | ** memory used by all pager caches associated with the database connection.)^ |
| 6315 | ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0. |
| 6316 | ** |
| 6317 | ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt> |
| 6318 | ** <dd>This parameter returns the approximate number of of bytes of heap |
| 6319 | ** memory used to store the schema for all databases associated |
| 6320 | ** with the connection - main, temp, and any [ATTACH]-ed databases.)^ |
| 6321 | ** ^The full amount of memory used by the schemas is reported, even if the |
| 6322 | ** schema memory is shared with other database connections due to |
| 6323 | ** [shared cache mode] being enabled. |
| 6324 | ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0. |
| 6325 | ** |
| 6326 | ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt> |
| 6327 | ** <dd>This parameter returns the approximate number of of bytes of heap |
| 6328 | ** and lookaside memory used by all prepared statements associated with |
| 6329 | ** the database connection.)^ |
| 6330 | ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0. |
| 6331 | ** </dd> |
| @@ -6179,11 +6343,11 @@ | |
| 6343 | |
| 6344 | /* |
| 6345 | ** CAPI3REF: Prepared Statement Status |
| 6346 | ** |
| 6347 | ** ^(Each prepared statement maintains various |
| 6348 | ** [SQLITE_STMTSTATUS counters] that measure the number |
| 6349 | ** of times it has performed specific operations.)^ These counters can |
| 6350 | ** be used to monitor the performance characteristics of the prepared |
| 6351 | ** statements. For example, if the number of table steps greatly exceeds |
| 6352 | ** the number of table searches or result rows, that would tend to indicate |
| 6353 | ** that the prepared statement is using a full table scan rather than |
| @@ -6190,11 +6354,11 @@ | |
| 6354 | ** an index. |
| 6355 | ** |
| 6356 | ** ^(This interface is used to retrieve and reset counter values from |
| 6357 | ** a [prepared statement]. The first argument is the prepared statement |
| 6358 | ** object to be interrogated. The second argument |
| 6359 | ** is an integer code for a specific [SQLITE_STMTSTATUS counter] |
| 6360 | ** to be interrogated.)^ |
| 6361 | ** ^The current value of the requested counter is returned. |
| 6362 | ** ^If the resetFlg is true, then the counter is reset to zero after this |
| 6363 | ** interface call returns. |
| 6364 | ** |
| @@ -6202,28 +6366,29 @@ | |
| 6366 | */ |
| 6367 | SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); |
| 6368 | |
| 6369 | /* |
| 6370 | ** CAPI3REF: Status Parameters for prepared statements |
| 6371 | ** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters} |
| 6372 | ** |
| 6373 | ** These preprocessor macros define integer codes that name counter |
| 6374 | ** values associated with the [sqlite3_stmt_status()] interface. |
| 6375 | ** The meanings of the various counters are as follows: |
| 6376 | ** |
| 6377 | ** <dl> |
| 6378 | ** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt> |
| 6379 | ** <dd>^This is the number of times that SQLite has stepped forward in |
| 6380 | ** a table as part of a full table scan. Large numbers for this counter |
| 6381 | ** may indicate opportunities for performance improvement through |
| 6382 | ** careful use of indices.</dd> |
| 6383 | ** |
| 6384 | ** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt> |
| 6385 | ** <dd>^This is the number of sort operations that have occurred. |
| 6386 | ** A non-zero value in this counter may indicate an opportunity to |
| 6387 | ** improvement performance through careful use of indices.</dd> |
| 6388 | ** |
| 6389 | ** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt> |
| 6390 | ** <dd>^This is the number of rows inserted into transient indices that |
| 6391 | ** were created automatically in order to help joins run faster. |
| 6392 | ** A non-zero value in this counter may indicate an opportunity to |
| 6393 | ** improvement performance by adding permanent indices that do not |
| 6394 | ** need to be reinitialized each time the statement is run.</dd> |
| @@ -6270,10 +6435,11 @@ | |
| 6435 | ** ^(The contents of the sqlite3_pcache_methods structure are copied to an |
| 6436 | ** internal buffer by SQLite within the call to [sqlite3_config]. Hence |
| 6437 | ** the application may discard the parameter after the call to |
| 6438 | ** [sqlite3_config()] returns.)^ |
| 6439 | ** |
| 6440 | ** [[the xInit() page cache method]] |
| 6441 | ** ^(The xInit() method is called once for each effective |
| 6442 | ** call to [sqlite3_initialize()])^ |
| 6443 | ** (usually only once during the lifetime of the process). ^(The xInit() |
| 6444 | ** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^ |
| 6445 | ** The intent of the xInit() method is to set up global data structures |
| @@ -6280,10 +6446,11 @@ | |
| 6446 | ** required by the custom page cache implementation. |
| 6447 | ** ^(If the xInit() method is NULL, then the |
| 6448 | ** built-in default page cache is used instead of the application defined |
| 6449 | ** page cache.)^ |
| 6450 | ** |
| 6451 | ** [[the xShutdown() page cache method]] |
| 6452 | ** ^The xShutdown() method is called by [sqlite3_shutdown()]. |
| 6453 | ** It can be used to clean up |
| 6454 | ** any outstanding resources before process shutdown, if required. |
| 6455 | ** ^The xShutdown() method may be NULL. |
| 6456 | ** |
| @@ -6294,10 +6461,11 @@ | |
| 6461 | ** in multithreaded applications. |
| 6462 | ** |
| 6463 | ** ^SQLite will never invoke xInit() more than once without an intervening |
| 6464 | ** call to xShutdown(). |
| 6465 | ** |
| 6466 | ** [[the xCreate() page cache methods]] |
| 6467 | ** ^SQLite invokes the xCreate() method to construct a new cache instance. |
| 6468 | ** SQLite will typically create one cache instance for each open database file, |
| 6469 | ** though this is not guaranteed. ^The |
| 6470 | ** first parameter, szPage, is the size in bytes of the pages that must |
| 6471 | ** be allocated by the cache. ^szPage will not be a power of two. ^szPage |
| @@ -6318,20 +6486,23 @@ | |
| 6486 | ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to |
| 6487 | ** false will always have the "discard" flag set to true. |
| 6488 | ** ^Hence, a cache created with bPurgeable false will |
| 6489 | ** never contain any unpinned pages. |
| 6490 | ** |
| 6491 | ** [[the xCachesize() page cache method]] |
| 6492 | ** ^(The xCachesize() method may be called at any time by SQLite to set the |
| 6493 | ** suggested maximum cache-size (number of pages stored by) the cache |
| 6494 | ** instance passed as the first argument. This is the value configured using |
| 6495 | ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable |
| 6496 | ** parameter, the implementation is not required to do anything with this |
| 6497 | ** value; it is advisory only. |
| 6498 | ** |
| 6499 | ** [[the xPagecount() page cache methods]] |
| 6500 | ** The xPagecount() method must return the number of pages currently |
| 6501 | ** stored in the cache, both pinned and unpinned. |
| 6502 | ** |
| 6503 | ** [[the xFetch() page cache methods]] |
| 6504 | ** The xFetch() method locates a page in the cache and returns a pointer to |
| 6505 | ** the page, or a NULL pointer. |
| 6506 | ** A "page", in this context, means a buffer of szPage bytes aligned at an |
| 6507 | ** 8-byte boundary. The page to be fetched is determined by the key. ^The |
| 6508 | ** mimimum key value is 1. After it has been retrieved using xFetch, the page |
| @@ -6356,10 +6527,11 @@ | |
| 6527 | ** will only use a createFlag of 2 after a prior call with a createFlag of 1 |
| 6528 | ** failed.)^ In between the to xFetch() calls, SQLite may |
| 6529 | ** attempt to unpin one or more cache pages by spilling the content of |
| 6530 | ** pinned pages to disk and synching the operating system disk cache. |
| 6531 | ** |
| 6532 | ** [[the xUnpin() page cache method]] |
| 6533 | ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page |
| 6534 | ** as its second argument. If the third parameter, discard, is non-zero, |
| 6535 | ** then the page must be evicted from the cache. |
| 6536 | ** ^If the discard parameter is |
| 6537 | ** zero, then the page may be discarded or retained at the discretion of |
| @@ -6368,10 +6540,11 @@ | |
| 6540 | ** |
| 6541 | ** The cache must not perform any reference counting. A single |
| 6542 | ** call to xUnpin() unpins the page regardless of the number of prior calls |
| 6543 | ** to xFetch(). |
| 6544 | ** |
| 6545 | ** [[the xRekey() page cache methods]] |
| 6546 | ** The xRekey() method is used to change the key value associated with the |
| 6547 | ** page passed as the second argument. If the cache |
| 6548 | ** previously contains an entry associated with newKey, it must be |
| 6549 | ** discarded. ^Any prior cache entry associated with newKey is guaranteed not |
| 6550 | ** to be pinned. |
| @@ -6380,10 +6553,11 @@ | |
| 6553 | ** existing cache entries with page numbers (keys) greater than or equal |
| 6554 | ** to the value of the iLimit parameter passed to xTruncate(). If any |
| 6555 | ** of these pages are pinned, they are implicitly unpinned, meaning that |
| 6556 | ** they can be safely discarded. |
| 6557 | ** |
| 6558 | ** [[the xDestroy() page cache method]] |
| 6559 | ** ^The xDestroy() method is used to delete a cache allocated by xCreate(). |
| 6560 | ** All resources associated with the specified cache should be freed. ^After |
| 6561 | ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*] |
| 6562 | ** handle invalid, and will not use it with any other sqlite3_pcache_methods |
| 6563 | ** functions. |
| @@ -6442,11 +6616,11 @@ | |
| 6616 | ** associated with the backup operation. |
| 6617 | ** </ol>)^ |
| 6618 | ** There should be exactly one call to sqlite3_backup_finish() for each |
| 6619 | ** successful call to sqlite3_backup_init(). |
| 6620 | ** |
| 6621 | ** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b> |
| 6622 | ** |
| 6623 | ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the |
| 6624 | ** [database connection] associated with the destination database |
| 6625 | ** and the database name, respectively. |
| 6626 | ** ^The database name is "main" for the main database, "temp" for the |
| @@ -6469,11 +6643,11 @@ | |
| 6643 | ** [sqlite3_backup] object. |
| 6644 | ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and |
| 6645 | ** sqlite3_backup_finish() functions to perform the specified backup |
| 6646 | ** operation. |
| 6647 | ** |
| 6648 | ** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b> |
| 6649 | ** |
| 6650 | ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between |
| 6651 | ** the source and destination databases specified by [sqlite3_backup] object B. |
| 6652 | ** ^If N is negative, all remaining source pages are copied. |
| 6653 | ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there |
| @@ -6526,11 +6700,11 @@ | |
| 6700 | ** restarted by the next call to sqlite3_backup_step(). ^If the source |
| 6701 | ** database is modified by the using the same database connection as is used |
| 6702 | ** by the backup operation, then the backup database is automatically |
| 6703 | ** updated at the same time. |
| 6704 | ** |
| 6705 | ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b> |
| 6706 | ** |
| 6707 | ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the |
| 6708 | ** application wishes to abandon the backup operation, the application |
| 6709 | ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish(). |
| 6710 | ** ^The sqlite3_backup_finish() interfaces releases all |
| @@ -6549,11 +6723,12 @@ | |
| 6723 | ** |
| 6724 | ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step() |
| 6725 | ** is not a permanent error and does not affect the return value of |
| 6726 | ** sqlite3_backup_finish(). |
| 6727 | ** |
| 6728 | ** [[sqlite3_backup__remaining()]] [[sqlite3_backup_pagecount()]] |
| 6729 | ** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b> |
| 6730 | ** |
| 6731 | ** ^Each call to sqlite3_backup_step() sets two values inside |
| 6732 | ** the [sqlite3_backup] object: the number of pages still to be backed |
| 6733 | ** up and the total number of pages in the source database file. |
| 6734 | ** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces |
| @@ -6934,10 +7109,97 @@ | |
| 7109 | ** each of these values. |
| 7110 | */ |
| 7111 | #define SQLITE_CHECKPOINT_PASSIVE 0 |
| 7112 | #define SQLITE_CHECKPOINT_FULL 1 |
| 7113 | #define SQLITE_CHECKPOINT_RESTART 2 |
| 7114 | |
| 7115 | /* |
| 7116 | ** CAPI3REF: Virtual Table Interface Configuration |
| 7117 | ** |
| 7118 | ** This function may be called by either the [xConnect] or [xCreate] method |
| 7119 | ** of a [virtual table] implementation to configure |
| 7120 | ** various facets of the virtual table interface. |
| 7121 | ** |
| 7122 | ** If this interface is invoked outside the context of an xConnect or |
| 7123 | ** xCreate virtual table method then the behavior is undefined. |
| 7124 | ** |
| 7125 | ** At present, there is only one option that may be configured using |
| 7126 | ** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].) Further options |
| 7127 | ** may be added in the future. |
| 7128 | */ |
| 7129 | SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...); |
| 7130 | |
| 7131 | /* |
| 7132 | ** CAPI3REF: Virtual Table Configuration Options |
| 7133 | ** |
| 7134 | ** These macros define the various options to the |
| 7135 | ** [sqlite3_vtab_config()] interface that [virtual table] implementations |
| 7136 | ** can use to customize and optimize their behavior. |
| 7137 | ** |
| 7138 | ** <dl> |
| 7139 | ** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT |
| 7140 | ** <dd>Calls of the form |
| 7141 | ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported, |
| 7142 | ** where X is an integer. If X is zero, then the [virtual table] whose |
| 7143 | ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not |
| 7144 | ** support constraints. In this configuration (which is the default) if |
| 7145 | ** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire |
| 7146 | ** statement is rolled back as if [ON CONFLICT | OR ABORT] had been |
| 7147 | ** specified as part of the users SQL statement, regardless of the actual |
| 7148 | ** ON CONFLICT mode specified. |
| 7149 | ** |
| 7150 | ** If X is non-zero, then the virtual table implementation guarantees |
| 7151 | ** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before |
| 7152 | ** any modifications to internal or persistent data structures have been made. |
| 7153 | ** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite |
| 7154 | ** is able to roll back a statement or database transaction, and abandon |
| 7155 | ** or continue processing the current SQL statement as appropriate. |
| 7156 | ** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns |
| 7157 | ** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode |
| 7158 | ** had been ABORT. |
| 7159 | ** |
| 7160 | ** Virtual table implementations that are required to handle OR REPLACE |
| 7161 | ** must do so within the [xUpdate] method. If a call to the |
| 7162 | ** [sqlite3_vtab_on_conflict()] function indicates that the current ON |
| 7163 | ** CONFLICT policy is REPLACE, the virtual table implementation should |
| 7164 | ** silently replace the appropriate rows within the xUpdate callback and |
| 7165 | ** return SQLITE_OK. Or, if this is not possible, it may return |
| 7166 | ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT |
| 7167 | ** constraint handling. |
| 7168 | ** </dl> |
| 7169 | */ |
| 7170 | #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1 |
| 7171 | |
| 7172 | /* |
| 7173 | ** CAPI3REF: Determine The Virtual Table Conflict Policy |
| 7174 | ** |
| 7175 | ** This function may only be called from within a call to the [xUpdate] method |
| 7176 | ** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The |
| 7177 | ** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL], |
| 7178 | ** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode |
| 7179 | ** of the SQL statement that triggered the call to the [xUpdate] method of the |
| 7180 | ** [virtual table]. |
| 7181 | */ |
| 7182 | SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *); |
| 7183 | |
| 7184 | /* |
| 7185 | ** CAPI3REF: Conflict resolution modes |
| 7186 | ** |
| 7187 | ** These constants are returned by [sqlite3_vtab_on_conflict()] to |
| 7188 | ** inform a [virtual table] implementation what the [ON CONFLICT] mode |
| 7189 | ** is for the SQL statement being evaluated. |
| 7190 | ** |
| 7191 | ** Note that the [SQLITE_IGNORE] constant is also used as a potential |
| 7192 | ** return value from the [sqlite3_set_authorizer()] callback and that |
| 7193 | ** [SQLITE_ABORT] is also a [result code]. |
| 7194 | */ |
| 7195 | #define SQLITE_ROLLBACK 1 |
| 7196 | /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */ |
| 7197 | #define SQLITE_FAIL 3 |
| 7198 | /* #define SQLITE_ABORT 4 // Also an error code */ |
| 7199 | #define SQLITE_REPLACE 5 |
| 7200 | |
| 7201 | |
| 7202 | |
| 7203 | /* |
| 7204 | ** Undo the hack that converts floating point types to integer for |
| 7205 | ** builds on processors without floating point support. |
| @@ -7601,10 +7863,11 @@ | |
| 7863 | typedef struct Trigger Trigger; |
| 7864 | typedef struct TriggerPrg TriggerPrg; |
| 7865 | typedef struct TriggerStep TriggerStep; |
| 7866 | typedef struct UnpackedRecord UnpackedRecord; |
| 7867 | typedef struct VTable VTable; |
| 7868 | typedef struct VtabCtx VtabCtx; |
| 7869 | typedef struct Walker Walker; |
| 7870 | typedef struct WherePlan WherePlan; |
| 7871 | typedef struct WhereInfo WhereInfo; |
| 7872 | typedef struct WhereLevel WhereLevel; |
| 7873 | |
| @@ -7657,10 +7920,11 @@ | |
| 7920 | typedef struct BtCursor BtCursor; |
| 7921 | typedef struct BtShared BtShared; |
| 7922 | |
| 7923 | |
| 7924 | SQLITE_PRIVATE int sqlite3BtreeOpen( |
| 7925 | sqlite3_vfs *pVfs, /* VFS to use with this b-tree */ |
| 7926 | const char *zFilename, /* Name of database file to open */ |
| 7927 | sqlite3 *db, /* Associated database connection */ |
| 7928 | Btree **ppBtree, /* Return open Btree* here */ |
| 7929 | int flags, /* Flags */ |
| 7930 | int vfsFlags /* Flags passed through to VFS open */ |
| @@ -9136,19 +9400,20 @@ | |
| 9400 | struct sqlite3 { |
| 9401 | sqlite3_vfs *pVfs; /* OS Interface */ |
| 9402 | int nDb; /* Number of backends currently in use */ |
| 9403 | Db *aDb; /* All backends */ |
| 9404 | int flags; /* Miscellaneous flags. See below */ |
| 9405 | unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */ |
| 9406 | int errCode; /* Most recent error code (SQLITE_*) */ |
| 9407 | int errMask; /* & result codes with this before returning */ |
| 9408 | u8 autoCommit; /* The auto-commit flag. */ |
| 9409 | u8 temp_store; /* 1: file 2: memory 0: default */ |
| 9410 | u8 mallocFailed; /* True if we have seen a malloc failure */ |
| 9411 | u8 dfltLockMode; /* Default locking-mode for attached dbs */ |
| 9412 | signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */ |
| 9413 | u8 suppressErr; /* Do not issue error messages if true */ |
| 9414 | u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */ |
| 9415 | int nextPagesize; /* Pagesize after VACUUM if >0 */ |
| 9416 | int nTable; /* Number of tables in the database */ |
| 9417 | CollSeq *pDfltColl; /* The default collating sequence (BINARY) */ |
| 9418 | i64 lastRowid; /* ROWID of most recent insert (see above) */ |
| 9419 | u32 magic; /* Magic number for detect library misuse */ |
| @@ -9203,11 +9468,11 @@ | |
| 9468 | void *pProgressArg; /* Argument to the progress callback */ |
| 9469 | int nProgressOps; /* Number of opcodes for progress callback */ |
| 9470 | #endif |
| 9471 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 9472 | Hash aModule; /* populated by sqlite3_create_module() */ |
| 9473 | VtabCtx *pVtabCtx; /* Context for active vtab connect/create */ |
| 9474 | VTable **aVTrans; /* Virtual tables with open transactions */ |
| 9475 | int nVTrans; /* Allocated size of aVTrans */ |
| 9476 | VTable *pDisconnect; /* Disconnect these in next sqlite3_prepare() */ |
| 9477 | #endif |
| 9478 | FuncDefHash aFunc; /* Hash table of connection functions */ |
| @@ -9566,10 +9831,11 @@ | |
| 9831 | struct VTable { |
| 9832 | sqlite3 *db; /* Database connection associated with this table */ |
| 9833 | Module *pMod; /* Pointer to module implementation */ |
| 9834 | sqlite3_vtab *pVtab; /* Pointer to vtab instance */ |
| 9835 | int nRef; /* Number of pointers to this structure */ |
| 9836 | u8 bConstraint; /* True if constraints are supported */ |
| 9837 | VTable *pNext; /* Next in linked list (see above) */ |
| 9838 | }; |
| 9839 | |
| 9840 | /* |
| 9841 | ** Each SQL table is represented in memory by an instance of the |
| @@ -10754,10 +11020,11 @@ | |
| 11020 | */ |
| 11021 | struct Sqlite3Config { |
| 11022 | int bMemstat; /* True to enable memory status */ |
| 11023 | int bCoreMutex; /* True to enable core mutexing */ |
| 11024 | int bFullMutex; /* True to enable full mutexing */ |
| 11025 | int bOpenUri; /* True to interpret filenames as URIs */ |
| 11026 | int mxStrlen; /* Maximum string length */ |
| 11027 | int szLookaside; /* Default lookaside buffer size */ |
| 11028 | int nLookaside; /* Default lookaside buffer count */ |
| 11029 | sqlite3_mem_methods m; /* Low-level memory allocation interface */ |
| 11030 | sqlite3_mutex_methods mutex; /* Low-level mutex interface */ |
| @@ -11003,10 +11270,12 @@ | |
| 11270 | SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*); |
| 11271 | SQLITE_PRIVATE void sqlite3AddColumnType(Parse*,Token*); |
| 11272 | SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,ExprSpan*); |
| 11273 | SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*); |
| 11274 | SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,Select*); |
| 11275 | SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*, |
| 11276 | sqlite3_vfs**,char**,char **); |
| 11277 | |
| 11278 | SQLITE_PRIVATE Bitvec *sqlite3BitvecCreate(u32); |
| 11279 | SQLITE_PRIVATE int sqlite3BitvecTest(Bitvec*, u32); |
| 11280 | SQLITE_PRIVATE int sqlite3BitvecSet(Bitvec*, u32); |
| 11281 | SQLITE_PRIVATE void sqlite3BitvecClear(Bitvec*, u32, void*); |
| @@ -11253,10 +11522,11 @@ | |
| 11522 | SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity); |
| 11523 | SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr); |
| 11524 | SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8); |
| 11525 | SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...); |
| 11526 | SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n); |
| 11527 | SQLITE_PRIVATE u8 sqlite3HexToInt(int h); |
| 11528 | SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); |
| 11529 | SQLITE_PRIVATE const char *sqlite3ErrStr(int); |
| 11530 | SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse); |
| 11531 | SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int); |
| 11532 | SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName); |
| @@ -11268,10 +11538,16 @@ | |
| 11538 | SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int); |
| 11539 | SQLITE_PRIVATE int sqlite3AddInt64(i64*,i64); |
| 11540 | SQLITE_PRIVATE int sqlite3SubInt64(i64*,i64); |
| 11541 | SQLITE_PRIVATE int sqlite3MulInt64(i64*,i64); |
| 11542 | SQLITE_PRIVATE int sqlite3AbsInt32(int); |
| 11543 | #ifdef SQLITE_ENABLE_8_3_NAMES |
| 11544 | SQLITE_PRIVATE void sqlite3FileSuffix3(const char*, char*); |
| 11545 | #else |
| 11546 | # define sqlite3FileSuffix3(X,Y) |
| 11547 | #endif |
| 11548 | SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z); |
| 11549 | |
| 11550 | SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8); |
| 11551 | SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8); |
| 11552 | SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, |
| 11553 | void(*)(void*)); |
| @@ -11377,18 +11653,20 @@ | |
| 11653 | # define sqlite3VtabCommit(X) |
| 11654 | # define sqlite3VtabInSync(db) 0 |
| 11655 | # define sqlite3VtabLock(X) |
| 11656 | # define sqlite3VtabUnlock(X) |
| 11657 | # define sqlite3VtabUnlockList(X) |
| 11658 | # define sqlite3VtabSavepoint(X, Y, Z) SQLITE_OK |
| 11659 | #else |
| 11660 | SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*); |
| 11661 | SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **); |
| 11662 | SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db); |
| 11663 | SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db); |
| 11664 | SQLITE_PRIVATE void sqlite3VtabLock(VTable *); |
| 11665 | SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *); |
| 11666 | SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3*); |
| 11667 | SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *, int, int); |
| 11668 | # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0) |
| 11669 | #endif |
| 11670 | SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*); |
| 11671 | SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*); |
| 11672 | SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse*, Token*); |
| @@ -11691,20 +11969,23 @@ | |
| 11969 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* f0..f7 ........ */ |
| 11970 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 /* f8..ff ........ */ |
| 11971 | }; |
| 11972 | #endif |
| 11973 | |
| 11974 | #ifndef SQLITE_USE_URI |
| 11975 | # define SQLITE_USE_URI 0 |
| 11976 | #endif |
| 11977 | |
| 11978 | /* |
| 11979 | ** The following singleton contains the global configuration for |
| 11980 | ** the SQLite library. |
| 11981 | */ |
| 11982 | SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = { |
| 11983 | SQLITE_DEFAULT_MEMSTATUS, /* bMemstat */ |
| 11984 | 1, /* bCoreMutex */ |
| 11985 | SQLITE_THREADSAFE==1, /* bFullMutex */ |
| 11986 | SQLITE_USE_URI, /* bOpenUri */ |
| 11987 | 0x7ffffffe, /* mxStrlen */ |
| 11988 | 100, /* szLookaside */ |
| 11989 | 500, /* nLookaside */ |
| 11990 | {0,0,0,0,0,0,0,0}, /* m */ |
| 11991 | {0,0,0,0,0,0,0,0,0}, /* mutex */ |
| @@ -18217,11 +18498,11 @@ | |
| 18498 | sqlite3_mutex_enter(mem0.mutex); |
| 18499 | sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes); |
| 18500 | nDiff = nNew - nOld; |
| 18501 | if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >= |
| 18502 | mem0.alarmThreshold-nDiff ){ |
| 18503 | sqlite3MallocAlarm(nDiff); |
| 18504 | } |
| 18505 | assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) ); |
| 18506 | assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) ); |
| 18507 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 18508 | if( pNew==0 && mem0.alarmCallback ){ |
| @@ -18228,11 +18509,11 @@ | |
| 18509 | sqlite3MallocAlarm(nBytes); |
| 18510 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 18511 | } |
| 18512 | if( pNew ){ |
| 18513 | nNew = sqlite3MallocSize(pNew); |
| 18514 | sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nNew-nOld); |
| 18515 | } |
| 18516 | sqlite3_mutex_leave(mem0.mutex); |
| 18517 | }else{ |
| 18518 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 18519 | } |
| @@ -21183,27 +21464,25 @@ | |
| 21464 | p[3] = (u8)v; |
| 21465 | } |
| 21466 | |
| 21467 | |
| 21468 | |
| 21469 | /* |
| 21470 | ** Translate a single byte of Hex into an integer. |
| 21471 | ** This routine only works if h really is a valid hexadecimal |
| 21472 | ** character: 0..9a..fA..F |
| 21473 | */ |
| 21474 | SQLITE_PRIVATE u8 sqlite3HexToInt(int h){ |
| 21475 | assert( (h>='0' && h<='9') || (h>='a' && h<='f') || (h>='A' && h<='F') ); |
| 21476 | #ifdef SQLITE_ASCII |
| 21477 | h += 9*(1&(h>>6)); |
| 21478 | #endif |
| 21479 | #ifdef SQLITE_EBCDIC |
| 21480 | h += 9*(1&~(h>>4)); |
| 21481 | #endif |
| 21482 | return (u8)(h & 0xf); |
| 21483 | } |
| 21484 | |
| 21485 | #if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC) |
| 21486 | /* |
| 21487 | ** Convert a BLOB literal of the form "x'hhhhhh'" into its binary |
| 21488 | ** value. Return a pointer to its binary value. Space to hold the |
| @@ -21216,11 +21495,11 @@ | |
| 21495 | |
| 21496 | zBlob = (char *)sqlite3DbMallocRaw(db, n/2 + 1); |
| 21497 | n--; |
| 21498 | if( zBlob ){ |
| 21499 | for(i=0; i<n; i+=2){ |
| 21500 | zBlob[i/2] = (sqlite3HexToInt(z[i])<<4) | sqlite3HexToInt(z[i+1]); |
| 21501 | } |
| 21502 | zBlob[i/2] = 0; |
| 21503 | } |
| 21504 | return zBlob; |
| 21505 | } |
| @@ -21348,10 +21627,36 @@ | |
| 21627 | SQLITE_PRIVATE int sqlite3AbsInt32(int x){ |
| 21628 | if( x>=0 ) return x; |
| 21629 | if( x==(int)0x80000000 ) return 0x7fffffff; |
| 21630 | return -x; |
| 21631 | } |
| 21632 | |
| 21633 | #ifdef SQLITE_ENABLE_8_3_NAMES |
| 21634 | /* |
| 21635 | ** If SQLITE_ENABLE_8_3_NAME is set at compile-time and if the database |
| 21636 | ** filename in zBaseFilename is a URI with the "8_3_names=1" parameter and |
| 21637 | ** if filename in z[] has a suffix (a.k.a. "extension") that is longer than |
| 21638 | ** three characters, then shorten the suffix on z[] to be the last three |
| 21639 | ** characters of the original suffix. |
| 21640 | ** |
| 21641 | ** Examples: |
| 21642 | ** |
| 21643 | ** test.db-journal => test.nal |
| 21644 | ** test.db-wal => test.wal |
| 21645 | ** test.db-shm => test.shm |
| 21646 | */ |
| 21647 | SQLITE_PRIVATE void sqlite3FileSuffix3(const char *zBaseFilename, char *z){ |
| 21648 | const char *zOk; |
| 21649 | zOk = sqlite3_uri_parameter(zBaseFilename, "8_3_names"); |
| 21650 | if( zOk && sqlite3GetBoolean(zOk) ){ |
| 21651 | int i, sz; |
| 21652 | sz = sqlite3Strlen30(z); |
| 21653 | for(i=sz-1; i>0 && z[i]!='/' && z[i]!='.'; i--){} |
| 21654 | if( z[i]=='.' && ALWAYS(sz>i+4) ) memcpy(&z[i+1], &z[sz-3], 4); |
| 21655 | } |
| 21656 | } |
| 21657 | #endif |
| 21658 | |
| 21659 | /************** End of util.c ************************************************/ |
| 21660 | /************** Begin file hash.c ********************************************/ |
| 21661 | /* |
| 21662 | ** 2001 September 22 |
| @@ -27890,10 +28195,11 @@ | |
| 28195 | sqlite3_snprintf(nShmFilename, zShmFilename, |
| 28196 | SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x", |
| 28197 | (u32)sStat.st_ino, (u32)sStat.st_dev); |
| 28198 | #else |
| 28199 | sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", pDbFd->zPath); |
| 28200 | sqlite3FileSuffix3(pDbFd->zPath, zShmFilename); |
| 28201 | #endif |
| 28202 | pShmNode->h = -1; |
| 28203 | pDbFd->pInode->pShmNode = pShmNode; |
| 28204 | pShmNode->pInode = pDbFd->pInode; |
| 28205 | pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); |
| @@ -28923,17 +29229,23 @@ | |
| 29229 | ** Finally, if the file being opened is a WAL or regular journal file, then |
| 29230 | ** this function queries the file-system for the permissions on the |
| 29231 | ** corresponding database file and sets *pMode to this value. Whenever |
| 29232 | ** possible, WAL and journal files are created using the same permissions |
| 29233 | ** as the associated database file. |
| 29234 | ** |
| 29235 | ** If the SQLITE_ENABLE_8_3_NAMES option is enabled, then the |
| 29236 | ** original filename is unavailable. But 8_3_NAMES is only used for |
| 29237 | ** FAT filesystems and permissions do not matter there, so just use |
| 29238 | ** the default permissions. |
| 29239 | */ |
| 29240 | static int findCreateFileMode( |
| 29241 | const char *zPath, /* Path of file (possibly) being created */ |
| 29242 | int flags, /* Flags passed as 4th argument to xOpen() */ |
| 29243 | mode_t *pMode /* OUT: Permissions to open file with */ |
| 29244 | ){ |
| 29245 | int rc = SQLITE_OK; /* Return Code */ |
| 29246 | *pMode = SQLITE_DEFAULT_FILE_PERMISSIONS; |
| 29247 | if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){ |
| 29248 | char zDb[MAX_PATHNAME+1]; /* Database file path */ |
| 29249 | int nDb; /* Number of valid bytes in zDb */ |
| 29250 | struct stat sStat; /* Output of stat() on database file */ |
| 29251 | |
| @@ -28941,19 +29253,19 @@ | |
| 29253 | ** the path to the associated database file from zPath. This block handles |
| 29254 | ** the following naming conventions: |
| 29255 | ** |
| 29256 | ** "<path to db>-journal" |
| 29257 | ** "<path to db>-wal" |
| 29258 | ** "<path to db>-journalNN" |
| 29259 | ** "<path to db>-walNN" |
| 29260 | ** |
| 29261 | ** where NN is a 4 digit decimal number. The NN naming schemes are |
| 29262 | ** used by the test_multiplex.c module. |
| 29263 | */ |
| 29264 | nDb = sqlite3Strlen30(zPath) - 1; |
| 29265 | while( nDb>0 && zPath[nDb]!='-' ) nDb--; |
| 29266 | if( nDb==0 ) return SQLITE_OK; |
| 29267 | memcpy(zDb, zPath, nDb); |
| 29268 | zDb[nDb] = '\0'; |
| 29269 | |
| 29270 | if( 0==stat(zDb, &sStat) ){ |
| 29271 | *pMode = sStat.st_mode & 0777; |
| @@ -28960,12 +29272,10 @@ | |
| 29272 | }else{ |
| 29273 | rc = SQLITE_IOERR_FSTAT; |
| 29274 | } |
| 29275 | }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){ |
| 29276 | *pMode = 0600; |
| 29277 | } |
| 29278 | return rc; |
| 29279 | } |
| 29280 | |
| 29281 | /* |
| @@ -32620,10 +32930,11 @@ | |
| 32930 | return SQLITE_NOMEM; |
| 32931 | } |
| 32932 | memset(pNew, 0, sizeof(*pNew)); |
| 32933 | pNew->zFilename = (char*)&pNew[1]; |
| 32934 | sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath); |
| 32935 | sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename); |
| 32936 | |
| 32937 | /* Look to see if there is an existing winShmNode that can be used. |
| 32938 | ** If no matching winShmNode currently exists, create a new one. |
| 32939 | */ |
| 32940 | winShmEnterMutex(); |
| @@ -33514,10 +33825,17 @@ | |
| 33825 | |
| 33826 | #if !SQLITE_OS_WINCE && !defined(__CYGWIN__) |
| 33827 | int nByte; |
| 33828 | void *zConverted; |
| 33829 | char *zOut; |
| 33830 | |
| 33831 | /* If this path name begins with "/X:", where "X" is any alphabetic |
| 33832 | ** character, discard the initial "/" from the pathname. |
| 33833 | */ |
| 33834 | if( zRelative[0]=='/' && sqlite3Isalpha(zRelative[1]) && zRelative[2]==':' ){ |
| 33835 | zRelative++; |
| 33836 | } |
| 33837 | |
| 33838 | /* It's odd to simulate an io-error here, but really this is just |
| 33839 | ** using the io-error infrastructure to test that SQLite handles this |
| 33840 | ** function failing. This function could fail if, for example, the |
| 33841 | ** current working directory has been unlinked. |
| @@ -36326,10 +36644,11 @@ | |
| 36644 | #define _WAL_H_ |
| 36645 | |
| 36646 | |
| 36647 | #ifdef SQLITE_OMIT_WAL |
| 36648 | # define sqlite3WalOpen(x,y,z) 0 |
| 36649 | # define sqlite3WalLimit(x,y) |
| 36650 | # define sqlite3WalClose(w,x,y,z) 0 |
| 36651 | # define sqlite3WalBeginReadTransaction(y,z) 0 |
| 36652 | # define sqlite3WalEndReadTransaction(z) |
| 36653 | # define sqlite3WalRead(v,w,x,y,z) 0 |
| 36654 | # define sqlite3WalDbsize(y) 0 |
| @@ -36351,13 +36670,16 @@ | |
| 36670 | ** There is one object of this type for each pager. |
| 36671 | */ |
| 36672 | typedef struct Wal Wal; |
| 36673 | |
| 36674 | /* Open and close a connection to a write-ahead log. */ |
| 36675 | SQLITE_PRIVATE int sqlite3WalOpen(sqlite3_vfs*, sqlite3_file*, const char *, int, i64, Wal**); |
| 36676 | SQLITE_PRIVATE int sqlite3WalClose(Wal *pWal, int sync_flags, int, u8 *); |
| 36677 | |
| 36678 | /* Set the limiting size of a WAL file. */ |
| 36679 | SQLITE_PRIVATE void sqlite3WalLimit(Wal*, i64); |
| 36680 | |
| 36681 | /* Used by readers to open (lock) and close (unlock) a snapshot. A |
| 36682 | ** snapshot is like a read-transaction. It is the state of the database |
| 36683 | ** at an instant in time. sqlite3WalOpenSnapshot gets a read lock and |
| 36684 | ** preserves the current state even if the other threads or processes |
| 36685 | ** write to or checkpoint the WAL. sqlite3WalCloseSnapshot() closes the |
| @@ -40702,10 +41024,12 @@ | |
| 41024 | int nPathname = 0; /* Number of bytes in zPathname */ |
| 41025 | int useJournal = (flags & PAGER_OMIT_JOURNAL)==0; /* False to omit journal */ |
| 41026 | int noReadlock = (flags & PAGER_NO_READLOCK)!=0; /* True to omit read-lock */ |
| 41027 | int pcacheSize = sqlite3PcacheSize(); /* Bytes to allocate for PCache */ |
| 41028 | u32 szPageDflt = SQLITE_DEFAULT_PAGE_SIZE; /* Default page size */ |
| 41029 | const char *zUri = 0; /* URI args to copy */ |
| 41030 | int nUri = 0; /* Number of bytes of URI args at *zUri */ |
| 41031 | |
| 41032 | /* Figure out how much space is required for each journal file-handle |
| 41033 | ** (there are two of them, the main journal and the sub-journal). This |
| 41034 | ** is the maximum space required for an in-memory journal file handle |
| 41035 | ** and a regular journal file-handle. Note that a "regular journal-handle" |
| @@ -40732,18 +41056,25 @@ | |
| 41056 | /* Compute and store the full pathname in an allocated buffer pointed |
| 41057 | ** to by zPathname, length nPathname. Or, if this is a temporary file, |
| 41058 | ** leave both nPathname and zPathname set to 0. |
| 41059 | */ |
| 41060 | if( zFilename && zFilename[0] ){ |
| 41061 | const char *z; |
| 41062 | nPathname = pVfs->mxPathname+1; |
| 41063 | zPathname = sqlite3Malloc(nPathname*2); |
| 41064 | if( zPathname==0 ){ |
| 41065 | return SQLITE_NOMEM; |
| 41066 | } |
| 41067 | zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */ |
| 41068 | rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname); |
| 41069 | nPathname = sqlite3Strlen30(zPathname); |
| 41070 | z = zUri = &zFilename[sqlite3Strlen30(zFilename)+1]; |
| 41071 | while( *z ){ |
| 41072 | z += sqlite3Strlen30(z)+1; |
| 41073 | z += sqlite3Strlen30(z)+1; |
| 41074 | } |
| 41075 | nUri = &z[1] - zUri; |
| 41076 | if( rc==SQLITE_OK && nPathname+8>pVfs->mxPathname ){ |
| 41077 | /* This branch is taken when the journal path required by |
| 41078 | ** the database being opened will be more than pVfs->mxPathname |
| 41079 | ** bytes in length. This means the database cannot be opened, |
| 41080 | ** as it will not be possible to open the journal file or even |
| @@ -40772,11 +41103,11 @@ | |
| 41103 | pPtr = (u8 *)sqlite3MallocZero( |
| 41104 | ROUND8(sizeof(*pPager)) + /* Pager structure */ |
| 41105 | ROUND8(pcacheSize) + /* PCache object */ |
| 41106 | ROUND8(pVfs->szOsFile) + /* The main db file */ |
| 41107 | journalFileSize * 2 + /* The two journal files */ |
| 41108 | nPathname + 1 + nUri + /* zFilename */ |
| 41109 | nPathname + 8 + 1 /* zJournal */ |
| 41110 | #ifndef SQLITE_OMIT_WAL |
| 41111 | + nPathname + 4 + 1 /* zWal */ |
| 41112 | #endif |
| 41113 | ); |
| @@ -40794,18 +41125,21 @@ | |
| 41125 | assert( EIGHT_BYTE_ALIGNMENT(pPager->jfd) ); |
| 41126 | |
| 41127 | /* Fill in the Pager.zFilename and Pager.zJournal buffers, if required. */ |
| 41128 | if( zPathname ){ |
| 41129 | assert( nPathname>0 ); |
| 41130 | pPager->zJournal = (char*)(pPtr += nPathname + 1 + nUri); |
| 41131 | memcpy(pPager->zFilename, zPathname, nPathname); |
| 41132 | memcpy(&pPager->zFilename[nPathname+1], zUri, nUri); |
| 41133 | memcpy(pPager->zJournal, zPathname, nPathname); |
| 41134 | memcpy(&pPager->zJournal[nPathname], "-journal", 8); |
| 41135 | sqlite3FileSuffix3(pPager->zFilename, pPager->zJournal); |
| 41136 | #ifndef SQLITE_OMIT_WAL |
| 41137 | pPager->zWal = &pPager->zJournal[nPathname+8+1]; |
| 41138 | memcpy(pPager->zWal, zPathname, nPathname); |
| 41139 | memcpy(&pPager->zWal[nPathname], "-wal", 4); |
| 41140 | sqlite3FileSuffix3(pPager->zFilename, pPager->zWal); |
| 41141 | #endif |
| 41142 | sqlite3_free(zPathname); |
| 41143 | } |
| 41144 | pPager->pVfs = pVfs; |
| 41145 | pPager->vfsFlags = vfsFlags; |
| @@ -43000,10 +43334,11 @@ | |
| 43334 | ** An attempt to set a limit smaller than -1 is a no-op. |
| 43335 | */ |
| 43336 | SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *pPager, i64 iLimit){ |
| 43337 | if( iLimit>=-1 ){ |
| 43338 | pPager->journalSizeLimit = iLimit; |
| 43339 | sqlite3WalLimit(pPager->pWal, iLimit); |
| 43340 | } |
| 43341 | return pPager->journalSizeLimit; |
| 43342 | } |
| 43343 | |
| 43344 | /* |
| @@ -43091,11 +43426,12 @@ | |
| 43426 | /* Open the connection to the log file. If this operation fails, |
| 43427 | ** (e.g. due to malloc() failure), return an error code. |
| 43428 | */ |
| 43429 | if( rc==SQLITE_OK ){ |
| 43430 | rc = sqlite3WalOpen(pPager->pVfs, |
| 43431 | pPager->fd, pPager->zWal, pPager->exclusiveMode, |
| 43432 | pPager->journalSizeLimit, &pPager->pWal |
| 43433 | ); |
| 43434 | } |
| 43435 | |
| 43436 | return rc; |
| 43437 | } |
| @@ -43623,10 +43959,11 @@ | |
| 43959 | struct Wal { |
| 43960 | sqlite3_vfs *pVfs; /* The VFS used to create pDbFd */ |
| 43961 | sqlite3_file *pDbFd; /* File handle for the database file */ |
| 43962 | sqlite3_file *pWalFd; /* File handle for WAL file */ |
| 43963 | u32 iCallback; /* Value to pass to log callback (or 0) */ |
| 43964 | i64 mxWalSize; /* Truncate WAL to this size upon reset */ |
| 43965 | int nWiData; /* Size of array apWiData */ |
| 43966 | volatile u32 **apWiData; /* Pointer to wal-index content in memory */ |
| 43967 | u32 szPage; /* Database page size */ |
| 43968 | i16 readLock; /* Which read lock is being held. -1 for none */ |
| 43969 | u8 exclusiveMode; /* Non-zero if connection is in exclusive mode */ |
| @@ -44445,10 +44782,11 @@ | |
| 44782 | SQLITE_PRIVATE int sqlite3WalOpen( |
| 44783 | sqlite3_vfs *pVfs, /* vfs module to open wal and wal-index */ |
| 44784 | sqlite3_file *pDbFd, /* The open database file */ |
| 44785 | const char *zWalName, /* Name of the WAL file */ |
| 44786 | int bNoShm, /* True to run in heap-memory mode */ |
| 44787 | i64 mxWalSize, /* Truncate WAL to this size on reset */ |
| 44788 | Wal **ppWal /* OUT: Allocated Wal handle */ |
| 44789 | ){ |
| 44790 | int rc; /* Return Code */ |
| 44791 | Wal *pRet; /* Object to allocate and return */ |
| 44792 | int flags; /* Flags passed to OsOpen() */ |
| @@ -44477,10 +44815,11 @@ | |
| 44815 | |
| 44816 | pRet->pVfs = pVfs; |
| 44817 | pRet->pWalFd = (sqlite3_file *)&pRet[1]; |
| 44818 | pRet->pDbFd = pDbFd; |
| 44819 | pRet->readLock = -1; |
| 44820 | pRet->mxWalSize = mxWalSize; |
| 44821 | pRet->zWalName = zWalName; |
| 44822 | pRet->exclusiveMode = (bNoShm ? WAL_HEAPMEMORY_MODE: WAL_NORMAL_MODE); |
| 44823 | |
| 44824 | /* Open file handle on the write-ahead log file. */ |
| 44825 | flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_WAL); |
| @@ -44497,10 +44836,17 @@ | |
| 44836 | *ppWal = pRet; |
| 44837 | WALTRACE(("WAL%d: opened\n", pRet)); |
| 44838 | } |
| 44839 | return rc; |
| 44840 | } |
| 44841 | |
| 44842 | /* |
| 44843 | ** Change the size to which the WAL file is trucated on each reset. |
| 44844 | */ |
| 44845 | SQLITE_PRIVATE void sqlite3WalLimit(Wal *pWal, i64 iLimit){ |
| 44846 | if( pWal ) pWal->mxWalSize = iLimit; |
| 44847 | } |
| 44848 | |
| 44849 | /* |
| 44850 | ** Find the smallest page number out of all pages held in the WAL that |
| 44851 | ** has not been returned by any prior invocation of this method on the |
| 44852 | ** same WalIterator object. Write into *piFrame the frame index where |
| @@ -45733,10 +46079,26 @@ | |
| 46079 | ** safe and means there is no special case for sqlite3WalUndo() |
| 46080 | ** to handle if this transaction is rolled back. |
| 46081 | */ |
| 46082 | int i; /* Loop counter */ |
| 46083 | u32 *aSalt = pWal->hdr.aSalt; /* Big-endian salt values */ |
| 46084 | |
| 46085 | /* Limit the size of WAL file if the journal_size_limit PRAGMA is |
| 46086 | ** set to a non-negative value. Log errors encountered |
| 46087 | ** during the truncation attempt. */ |
| 46088 | if( pWal->mxWalSize>=0 ){ |
| 46089 | i64 sz; |
| 46090 | int rx; |
| 46091 | rx = sqlite3OsFileSize(pWal->pWalFd, &sz); |
| 46092 | if( rx==SQLITE_OK && (sz > pWal->mxWalSize) ){ |
| 46093 | rx = sqlite3OsTruncate(pWal->pWalFd, pWal->mxWalSize); |
| 46094 | } |
| 46095 | if( rx ){ |
| 46096 | sqlite3_log(rx, "cannot limit WAL size: %s", pWal->zWalName); |
| 46097 | } |
| 46098 | } |
| 46099 | |
| 46100 | pWal->nCkpt++; |
| 46101 | pWal->hdr.mxFrame = 0; |
| 46102 | sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0])); |
| 46103 | aSalt[1] = salt1; |
| 46104 | walIndexWriteHdr(pWal); |
| @@ -47838,10 +48200,11 @@ | |
| 48200 | offset = PTRMAP_PTROFFSET(iPtrmap, key); |
| 48201 | if( offset<0 ){ |
| 48202 | *pRC = SQLITE_CORRUPT_BKPT; |
| 48203 | goto ptrmap_exit; |
| 48204 | } |
| 48205 | assert( offset <= (int)pBt->usableSize-5 ); |
| 48206 | pPtrmap = (u8 *)sqlite3PagerGetData(pDbPage); |
| 48207 | |
| 48208 | if( eType!=pPtrmap[offset] || get4byte(&pPtrmap[offset+1])!=parent ){ |
| 48209 | TRACE(("PTRMAP_UPDATE: %d->(%d,%d)\n", key, eType, parent)); |
| 48210 | *pRC= rc = sqlite3PagerWrite(pDbPage); |
| @@ -47877,10 +48240,15 @@ | |
| 48240 | return rc; |
| 48241 | } |
| 48242 | pPtrmap = (u8 *)sqlite3PagerGetData(pDbPage); |
| 48243 | |
| 48244 | offset = PTRMAP_PTROFFSET(iPtrmap, key); |
| 48245 | if( offset<0 ){ |
| 48246 | sqlite3PagerUnref(pDbPage); |
| 48247 | return SQLITE_CORRUPT_BKPT; |
| 48248 | } |
| 48249 | assert( offset <= (int)pBt->usableSize-5 ); |
| 48250 | assert( pEType!=0 ); |
| 48251 | *pEType = pPtrmap[offset]; |
| 48252 | if( pPgno ) *pPgno = get4byte(&pPtrmap[offset+1]); |
| 48253 | |
| 48254 | sqlite3PagerUnref(pDbPage); |
| @@ -48738,17 +49106,17 @@ | |
| 49106 | ** SQLITE_CONSTRAINT error. We cannot allow two or more BtShared |
| 49107 | ** objects in the same database connection since doing so will lead |
| 49108 | ** to problems with locking. |
| 49109 | */ |
| 49110 | SQLITE_PRIVATE int sqlite3BtreeOpen( |
| 49111 | sqlite3_vfs *pVfs, /* VFS to use for this b-tree */ |
| 49112 | const char *zFilename, /* Name of the file containing the BTree database */ |
| 49113 | sqlite3 *db, /* Associated database handle */ |
| 49114 | Btree **ppBtree, /* Pointer to new Btree object written here */ |
| 49115 | int flags, /* Options */ |
| 49116 | int vfsFlags /* Flags passed through to sqlite3_vfs.xOpen() */ |
| 49117 | ){ |
| 49118 | BtShared *pBt = 0; /* Shared part of btree structure */ |
| 49119 | Btree *p; /* Handle to return */ |
| 49120 | sqlite3_mutex *mutexOpen = 0; /* Prevents a race condition. Ticket #3537 */ |
| 49121 | int rc = SQLITE_OK; /* Result code from this function */ |
| 49122 | u8 nReserve; /* Byte of unused space on each page */ |
| @@ -48766,10 +49134,11 @@ | |
| 49134 | const int isMemdb = (zFilename && strcmp(zFilename, ":memory:")==0) |
| 49135 | || (isTempDb && sqlite3TempInMemory(db)); |
| 49136 | #endif |
| 49137 | |
| 49138 | assert( db!=0 ); |
| 49139 | assert( pVfs!=0 ); |
| 49140 | assert( sqlite3_mutex_held(db->mutex) ); |
| 49141 | assert( (flags&0xff)==flags ); /* flags fit in 8 bits */ |
| 49142 | |
| 49143 | /* Only a BTREE_SINGLE database can be BTREE_UNORDERED */ |
| 49144 | assert( (flags & BTREE_UNORDERED)==0 || (flags & BTREE_SINGLE)!=0 ); |
| @@ -48784,11 +49153,10 @@ | |
| 49153 | flags |= BTREE_MEMORY; |
| 49154 | } |
| 49155 | if( (vfsFlags & SQLITE_OPEN_MAIN_DB)!=0 && (isMemdb || isTempDb) ){ |
| 49156 | vfsFlags = (vfsFlags & ~SQLITE_OPEN_MAIN_DB) | SQLITE_OPEN_TEMP_DB; |
| 49157 | } |
| 49158 | p = sqlite3MallocZero(sizeof(Btree)); |
| 49159 | if( !p ){ |
| 49160 | return SQLITE_NOMEM; |
| 49161 | } |
| 49162 | p->inTrans = TRANS_NONE; |
| @@ -58855,10 +59223,11 @@ | |
| 59223 | sqlite3_randomness(sizeof(iRandom), &iRandom); |
| 59224 | zMaster = sqlite3MPrintf(db, "%s-mj%08X", zMainFile, iRandom&0x7fffffff); |
| 59225 | if( !zMaster ){ |
| 59226 | return SQLITE_NOMEM; |
| 59227 | } |
| 59228 | sqlite3FileSuffix3(zMainFile, zMaster); |
| 59229 | rc = sqlite3OsAccess(pVfs, zMaster, SQLITE_ACCESS_EXISTS, &res); |
| 59230 | }while( rc==SQLITE_OK && res ); |
| 59231 | if( rc==SQLITE_OK ){ |
| 59232 | /* Open the master journal. */ |
| 59233 | rc = sqlite3OsOpenMalloc(pVfs, zMaster, &pMaster, |
| @@ -59068,10 +59437,19 @@ | |
| 59437 | } |
| 59438 | } |
| 59439 | } |
| 59440 | db->nStatement--; |
| 59441 | p->iStatement = 0; |
| 59442 | |
| 59443 | if( rc==SQLITE_OK ){ |
| 59444 | if( eOp==SAVEPOINT_ROLLBACK ){ |
| 59445 | rc = sqlite3VtabSavepoint(db, SAVEPOINT_ROLLBACK, iSavepoint); |
| 59446 | } |
| 59447 | if( rc==SQLITE_OK ){ |
| 59448 | rc = sqlite3VtabSavepoint(db, SAVEPOINT_RELEASE, iSavepoint); |
| 59449 | } |
| 59450 | } |
| 59451 | |
| 59452 | /* If the statement transaction is being rolled back, also restore the |
| 59453 | ** database handles deferred constraint counter to the value it had when |
| 59454 | ** the statement transaction was opened. */ |
| 59455 | if( eOp==SAVEPOINT_ROLLBACK ){ |
| @@ -62400,10 +62778,11 @@ | |
| 62778 | Mem *pIn2 = 0; /* 2nd input operand */ |
| 62779 | Mem *pIn3 = 0; /* 3rd input operand */ |
| 62780 | Mem *pOut = 0; /* Output operand */ |
| 62781 | int iCompare = 0; /* Result of last OP_Compare operation */ |
| 62782 | int *aPermute = 0; /* Permutation of columns for OP_Compare */ |
| 62783 | i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */ |
| 62784 | #ifdef VDBE_PROFILE |
| 62785 | u64 start; /* CPU clock count at start of opcode */ |
| 62786 | int origPc; /* Program counter at start of opcode */ |
| 62787 | #endif |
| 62788 | /******************************************************************** |
| @@ -63078,10 +63457,11 @@ | |
| 63457 | VdbeFrame *pFrame = p->pFrame; |
| 63458 | p->pFrame = pFrame->pParent; |
| 63459 | p->nFrame--; |
| 63460 | sqlite3VdbeSetChanges(db, p->nChange); |
| 63461 | pc = sqlite3VdbeFrameRestore(pFrame); |
| 63462 | lastRowid = db->lastRowid; |
| 63463 | if( pOp->p2==OE_Ignore ){ |
| 63464 | /* Instruction pc is the OP_Program that invoked the sub-program |
| 63465 | ** currently being halted. If the p2 instruction of this OP_Halt |
| 63466 | ** instruction is set to OE_Ignore, then the sub-program is throwing |
| 63467 | ** an IGNORE exception. In this case jump to the address specified |
| @@ -63650,11 +64030,13 @@ | |
| 64030 | assert( pOp>aOp ); |
| 64031 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 64032 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 64033 | u.ag.ctx.pColl = pOp[-1].p4.pColl; |
| 64034 | } |
| 64035 | db->lastRowid = lastRowid; |
| 64036 | (*u.ag.ctx.pFunc->xFunc)(&u.ag.ctx, u.ag.n, u.ag.apVal); /* IMP: R-24505-23230 */ |
| 64037 | lastRowid = db->lastRowid; |
| 64038 | if( db->mallocFailed ){ |
| 64039 | /* Even though a malloc() has failed, the implementation of the |
| 64040 | ** user function may have called an sqlite3_result_XXX() function |
| 64041 | ** to return a value. The following call releases any resources |
| 64042 | ** associated with such a value. |
| @@ -64857,10 +65239,18 @@ | |
| 65239 | "SQL statements in progress"); |
| 65240 | rc = SQLITE_BUSY; |
| 65241 | }else{ |
| 65242 | u.aq.nName = sqlite3Strlen30(u.aq.zName); |
| 65243 | |
| 65244 | /* This call is Ok even if this savepoint is actually a transaction |
| 65245 | ** savepoint (and therefore should not prompt xSavepoint()) callbacks. |
| 65246 | ** If this is a transaction savepoint being opened, it is guaranteed |
| 65247 | ** that the db->aVTrans[] array is empty. */ |
| 65248 | assert( db->autoCommit==0 || db->nVTrans==0 ); |
| 65249 | rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement); |
| 65250 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 65251 | |
| 65252 | /* Create a new savepoint structure. */ |
| 65253 | u.aq.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.aq.nName+1); |
| 65254 | if( u.aq.pNew ){ |
| 65255 | u.aq.pNew->zName = (char *)&u.aq.pNew[1]; |
| 65256 | memcpy(u.aq.pNew->zName, u.aq.zName, u.aq.nName+1); |
| @@ -64963,10 +65353,15 @@ | |
| 65353 | db->nSavepoint--; |
| 65354 | } |
| 65355 | }else{ |
| 65356 | db->nDeferredCons = u.aq.pSavepoint->nDeferredCons; |
| 65357 | } |
| 65358 | |
| 65359 | if( !isTransaction ){ |
| 65360 | rc = sqlite3VtabSavepoint(db, u.aq.p1, u.aq.iSavepoint); |
| 65361 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 65362 | } |
| 65363 | } |
| 65364 | } |
| 65365 | |
| 65366 | break; |
| 65367 | } |
| @@ -65102,11 +65497,15 @@ | |
| 65497 | if( p->iStatement==0 ){ |
| 65498 | assert( db->nStatement>=0 && db->nSavepoint>=0 ); |
| 65499 | db->nStatement++; |
| 65500 | p->iStatement = db->nSavepoint + db->nStatement; |
| 65501 | } |
| 65502 | |
| 65503 | rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement); |
| 65504 | if( rc==SQLITE_OK ){ |
| 65505 | rc = sqlite3BtreeBeginStmt(u.as.pBt, p->iStatement); |
| 65506 | } |
| 65507 | |
| 65508 | /* Store the current value of the database handles deferred constraint |
| 65509 | ** counter. If the statement transaction needs to be rolled back, |
| 65510 | ** the value of this counter needs to be restored too. */ |
| 65511 | p->nStmtDefCons = db->nDeferredCons; |
| @@ -65423,11 +65822,11 @@ | |
| 65822 | |
| 65823 | assert( pOp->p1>=0 ); |
| 65824 | u.ax.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1); |
| 65825 | if( u.ax.pCx==0 ) goto no_mem; |
| 65826 | u.ax.pCx->nullRow = 1; |
| 65827 | rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.ax.pCx->pBt, |
| 65828 | BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags); |
| 65829 | if( rc==SQLITE_OK ){ |
| 65830 | rc = sqlite3BtreeBeginTrans(u.ax.pCx->pBt, 1); |
| 65831 | } |
| 65832 | if( rc==SQLITE_OK ){ |
| @@ -66097,11 +66496,11 @@ | |
| 66496 | ** engine starts picking positive candidate ROWIDs at random until |
| 66497 | ** it finds one that is not previously used. */ |
| 66498 | assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is |
| 66499 | ** an AUTOINCREMENT table. */ |
| 66500 | /* on the first attempt, simply do one more than previous */ |
| 66501 | u.be.v = lastRowid; |
| 66502 | u.be.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */ |
| 66503 | u.be.v++; /* ensure non-zero */ |
| 66504 | u.be.cnt = 0; |
| 66505 | while( ((rc = sqlite3BtreeMovetoUnpacked(u.be.pC->pCursor, 0, (u64)u.be.v, |
| 66506 | 0, &u.be.res))==SQLITE_OK) |
| @@ -66209,11 +66608,11 @@ | |
| 66608 | assert( pOp->opcode==OP_InsertInt ); |
| 66609 | u.bf.iKey = pOp->p3; |
| 66610 | } |
| 66611 | |
| 66612 | if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; |
| 66613 | if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = u.bf.iKey; |
| 66614 | if( u.bf.pData->flags & MEM_Null ){ |
| 66615 | u.bf.pData->z = 0; |
| 66616 | u.bf.pData->n = 0; |
| 66617 | }else{ |
| 66618 | assert( u.bf.pData->flags & (MEM_Blob|MEM_Str) ); |
| @@ -67335,11 +67734,11 @@ | |
| 67734 | assert( pc==u.by.pFrame->pc ); |
| 67735 | } |
| 67736 | |
| 67737 | p->nFrame++; |
| 67738 | u.by.pFrame->pParent = p->pFrame; |
| 67739 | u.by.pFrame->lastRowid = lastRowid; |
| 67740 | u.by.pFrame->nChange = p->nChange; |
| 67741 | p->nChange = 0; |
| 67742 | p->pFrame = u.by.pFrame; |
| 67743 | p->aMem = aMem = &VdbeFrameMem(u.by.pFrame)[-1]; |
| 67744 | p->nMem = u.by.pFrame->nChildMem; |
| @@ -68146,31 +68545,45 @@ | |
| 68545 | sqlite_int64 rowid; |
| 68546 | Mem **apArg; |
| 68547 | Mem *pX; |
| 68548 | #endif /* local variables moved into u.cm */ |
| 68549 | |
| 68550 | assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback |
| 68551 | || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace |
| 68552 | ); |
| 68553 | u.cm.pVtab = pOp->p4.pVtab->pVtab; |
| 68554 | u.cm.pModule = (sqlite3_module *)u.cm.pVtab->pModule; |
| 68555 | u.cm.nArg = pOp->p2; |
| 68556 | assert( pOp->p4type==P4_VTAB ); |
| 68557 | if( ALWAYS(u.cm.pModule->xUpdate) ){ |
| 68558 | u8 vtabOnConflict = db->vtabOnConflict; |
| 68559 | u.cm.apArg = p->apArg; |
| 68560 | u.cm.pX = &aMem[pOp->p3]; |
| 68561 | for(u.cm.i=0; u.cm.i<u.cm.nArg; u.cm.i++){ |
| 68562 | assert( memIsValid(u.cm.pX) ); |
| 68563 | memAboutToChange(p, u.cm.pX); |
| 68564 | sqlite3VdbeMemStoreType(u.cm.pX); |
| 68565 | u.cm.apArg[u.cm.i] = u.cm.pX; |
| 68566 | u.cm.pX++; |
| 68567 | } |
| 68568 | db->vtabOnConflict = pOp->p5; |
| 68569 | rc = u.cm.pModule->xUpdate(u.cm.pVtab, u.cm.nArg, u.cm.apArg, &u.cm.rowid); |
| 68570 | db->vtabOnConflict = vtabOnConflict; |
| 68571 | importVtabErrMsg(p, u.cm.pVtab); |
| 68572 | if( rc==SQLITE_OK && pOp->p1 ){ |
| 68573 | assert( u.cm.nArg>1 && u.cm.apArg[0] && (u.cm.apArg[0]->flags&MEM_Null) ); |
| 68574 | db->lastRowid = lastRowid = u.cm.rowid; |
| 68575 | } |
| 68576 | if( rc==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){ |
| 68577 | if( pOp->p5==OE_Ignore ){ |
| 68578 | rc = SQLITE_OK; |
| 68579 | }else{ |
| 68580 | p->errorAction = ((pOp->p5==OE_Replace) ? OE_Abort : pOp->p5); |
| 68581 | } |
| 68582 | }else{ |
| 68583 | p->nChange++; |
| 68584 | } |
| 68585 | } |
| 68586 | break; |
| 68587 | } |
| 68588 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 68589 | |
| @@ -68316,10 +68729,11 @@ | |
| 68729 | |
| 68730 | /* This is the only way out of this procedure. We have to |
| 68731 | ** release the mutexes on btrees that were acquired at the |
| 68732 | ** top. */ |
| 68733 | vdbe_return: |
| 68734 | db->lastRowid = lastRowid; |
| 68735 | sqlite3VdbeLeave(p); |
| 68736 | return rc; |
| 68737 | |
| 68738 | /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH |
| 68739 | ** is encountered. |
| @@ -76044,12 +76458,16 @@ | |
| 76458 | int i; |
| 76459 | int rc = 0; |
| 76460 | sqlite3 *db = sqlite3_context_db_handle(context); |
| 76461 | const char *zName; |
| 76462 | const char *zFile; |
| 76463 | char *zPath = 0; |
| 76464 | char *zErr = 0; |
| 76465 | unsigned int flags; |
| 76466 | Db *aNew; |
| 76467 | char *zErrDyn = 0; |
| 76468 | sqlite3_vfs *pVfs; |
| 76469 | |
| 76470 | UNUSED_PARAMETER(NotUsed); |
| 76471 | |
| 76472 | zFile = (const char *)sqlite3_value_text(argv[0]); |
| 76473 | zName = (const char *)sqlite3_value_text(argv[1]); |
| @@ -76098,12 +76516,22 @@ | |
| 76516 | |
| 76517 | /* Open the database file. If the btree is successfully opened, use |
| 76518 | ** it to obtain the database schema. At this point the schema may |
| 76519 | ** or may not be initialised. |
| 76520 | */ |
| 76521 | flags = db->openFlags; |
| 76522 | rc = sqlite3ParseUri(db->pVfs->zName, zFile, &flags, &pVfs, &zPath, &zErr); |
| 76523 | if( rc!=SQLITE_OK ){ |
| 76524 | if( rc==SQLITE_NOMEM ) db->mallocFailed = 1; |
| 76525 | sqlite3_result_error(context, zErr, -1); |
| 76526 | sqlite3_free(zErr); |
| 76527 | return; |
| 76528 | } |
| 76529 | assert( pVfs ); |
| 76530 | flags |= SQLITE_OPEN_MAIN_DB; |
| 76531 | rc = sqlite3BtreeOpen(pVfs, zPath, db, &aNew->pBt, 0, flags); |
| 76532 | sqlite3_free( zPath ); |
| 76533 | db->nDb++; |
| 76534 | if( rc==SQLITE_CONSTRAINT ){ |
| 76535 | rc = SQLITE_ERROR; |
| 76536 | zErrDyn = sqlite3MPrintf(db, "database is already attached"); |
| 76537 | }else if( rc==SQLITE_OK ){ |
| @@ -80213,11 +80641,11 @@ | |
| 80641 | SQLITE_OPEN_CREATE | |
| 80642 | SQLITE_OPEN_EXCLUSIVE | |
| 80643 | SQLITE_OPEN_DELETEONCLOSE | |
| 80644 | SQLITE_OPEN_TEMP_DB; |
| 80645 | |
| 80646 | rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pBt, 0, flags); |
| 80647 | if( rc!=SQLITE_OK ){ |
| 80648 | sqlite3ErrorMsg(pParse, "unable to open a temporary database " |
| 80649 | "file for storing temporary tables"); |
| 80650 | pParse->rc = rc; |
| 80651 | return 1; |
| @@ -85399,10 +85827,11 @@ | |
| 85827 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 85828 | if( IsVirtual(pTab) ){ |
| 85829 | const char *pVTab = (const char *)sqlite3GetVTable(db, pTab); |
| 85830 | sqlite3VtabMakeWritable(pParse, pTab); |
| 85831 | sqlite3VdbeAddOp4(v, OP_VUpdate, 1, pTab->nCol+2, regIns, pVTab, P4_VTAB); |
| 85832 | sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError); |
| 85833 | sqlite3MayAbort(pParse); |
| 85834 | }else |
| 85835 | #endif |
| 85836 | { |
| 85837 | int isReplace; /* Set to true if constraints may cause a replace */ |
| @@ -87544,11 +87973,11 @@ | |
| 87973 | } |
| 87974 | |
| 87975 | /* |
| 87976 | ** Interpret the given string as a boolean value. |
| 87977 | */ |
| 87978 | SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z){ |
| 87979 | return getSafetyLevel(z)&1; |
| 87980 | } |
| 87981 | |
| 87982 | /* |
| 87983 | ** Interpret the given string as a locking mode value. |
| @@ -87714,11 +88143,11 @@ | |
| 88143 | /* Foreign key support may not be enabled or disabled while not |
| 88144 | ** in auto-commit mode. */ |
| 88145 | mask &= ~(SQLITE_ForeignKeys); |
| 88146 | } |
| 88147 | |
| 88148 | if( sqlite3GetBoolean(zRight) ){ |
| 88149 | db->flags |= mask; |
| 88150 | }else{ |
| 88151 | db->flags &= ~mask; |
| 88152 | } |
| 88153 | |
| @@ -87928,11 +88357,11 @@ | |
| 88357 | if( sqlite3StrICmp(zLeft,"secure_delete")==0 ){ |
| 88358 | Btree *pBt = pDb->pBt; |
| 88359 | int b = -1; |
| 88360 | assert( pBt!=0 ); |
| 88361 | if( zRight ){ |
| 88362 | b = sqlite3GetBoolean(zRight); |
| 88363 | } |
| 88364 | if( pId2->n==0 && b>=0 ){ |
| 88365 | int ii; |
| 88366 | for(ii=0; ii<db->nDb; ii++){ |
| 88367 | sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b); |
| @@ -88528,11 +88957,11 @@ | |
| 88957 | #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */ |
| 88958 | |
| 88959 | #ifndef NDEBUG |
| 88960 | if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){ |
| 88961 | if( zRight ){ |
| 88962 | if( sqlite3GetBoolean(zRight) ){ |
| 88963 | sqlite3ParserTrace(stderr, "parser: "); |
| 88964 | }else{ |
| 88965 | sqlite3ParserTrace(0, 0); |
| 88966 | } |
| 88967 | } |
| @@ -88542,11 +88971,11 @@ | |
| 88971 | /* Reinstall the LIKE and GLOB functions. The variant of LIKE |
| 88972 | ** used will be case sensitive or not depending on the RHS. |
| 88973 | */ |
| 88974 | if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){ |
| 88975 | if( zRight ){ |
| 88976 | sqlite3RegisterLikeFunctions(db, sqlite3GetBoolean(zRight)); |
| 88977 | } |
| 88978 | }else |
| 88979 | |
| 88980 | #ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX |
| 88981 | # define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100 |
| @@ -95683,11 +96112,12 @@ | |
| 96112 | SrcList *pSrc, /* The virtual table to be modified */ |
| 96113 | Table *pTab, /* The virtual table */ |
| 96114 | ExprList *pChanges, /* The columns to change in the UPDATE statement */ |
| 96115 | Expr *pRowidExpr, /* Expression used to recompute the rowid */ |
| 96116 | int *aXRef, /* Mapping from columns of pTab to entries in pChanges */ |
| 96117 | Expr *pWhere, /* WHERE clause of the UPDATE statement */ |
| 96118 | int onError /* ON CONFLICT strategy */ |
| 96119 | ); |
| 96120 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 96121 | |
| 96122 | /* |
| 96123 | ** The most recently coded instruction was an OP_Column to retrieve the |
| @@ -95927,11 +96357,11 @@ | |
| 96357 | |
| 96358 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 96359 | /* Virtual tables must be handled separately */ |
| 96360 | if( IsVirtual(pTab) ){ |
| 96361 | updateVirtualTable(pParse, pTabList, pTab, pChanges, pRowidExpr, aXRef, |
| 96362 | pWhere, onError); |
| 96363 | pWhere = 0; |
| 96364 | pTabList = 0; |
| 96365 | goto update_cleanup; |
| 96366 | } |
| 96367 | #endif |
| @@ -96257,11 +96687,12 @@ | |
| 96687 | SrcList *pSrc, /* The virtual table to be modified */ |
| 96688 | Table *pTab, /* The virtual table */ |
| 96689 | ExprList *pChanges, /* The columns to change in the UPDATE statement */ |
| 96690 | Expr *pRowid, /* Expression used to recompute the rowid */ |
| 96691 | int *aXRef, /* Mapping from columns of pTab to entries in pChanges */ |
| 96692 | Expr *pWhere, /* WHERE clause of the UPDATE statement */ |
| 96693 | int onError /* ON CONFLICT strategy */ |
| 96694 | ){ |
| 96695 | Vdbe *v = pParse->pVdbe; /* Virtual machine under construction */ |
| 96696 | ExprList *pEList = 0; /* The result set of the SELECT statement */ |
| 96697 | Select *pSelect = 0; /* The SELECT statement */ |
| 96698 | Expr *pExpr; /* Temporary expression */ |
| @@ -96314,10 +96745,11 @@ | |
| 96745 | for(i=0; i<pTab->nCol; i++){ |
| 96746 | sqlite3VdbeAddOp3(v, OP_Column, ephemTab, i+1+(pRowid!=0), iReg+2+i); |
| 96747 | } |
| 96748 | sqlite3VtabMakeWritable(pParse, pTab); |
| 96749 | sqlite3VdbeAddOp4(v, OP_VUpdate, 0, pTab->nCol+2, iReg, pVTab, P4_VTAB); |
| 96750 | sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError); |
| 96751 | sqlite3MayAbort(pParse); |
| 96752 | sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1); |
| 96753 | sqlite3VdbeJumpHere(v, addr); |
| 96754 | sqlite3VdbeAddOp2(v, OP_Close, ephemTab, 0); |
| 96755 | |
| @@ -96687,10 +97119,22 @@ | |
| 97119 | ************************************************************************* |
| 97120 | ** This file contains code used to help implement virtual tables. |
| 97121 | */ |
| 97122 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 97123 | |
| 97124 | /* |
| 97125 | ** Before a virtual table xCreate() or xConnect() method is invoked, the |
| 97126 | ** sqlite3.pVtabCtx member variable is set to point to an instance of |
| 97127 | ** this struct allocated on the stack. It is used by the implementation of |
| 97128 | ** the sqlite3_declare_vtab() and sqlite3_vtab_config() APIs, both of which |
| 97129 | ** are invoked only from within xCreate and xConnect methods. |
| 97130 | */ |
| 97131 | struct VtabCtx { |
| 97132 | Table *pTab; |
| 97133 | VTable *pVTable; |
| 97134 | }; |
| 97135 | |
| 97136 | /* |
| 97137 | ** The actual function that does the work of creating a new module. |
| 97138 | ** This function implements the sqlite3_create_module() and |
| 97139 | ** sqlite3_create_module_v2() interfaces. |
| 97140 | */ |
| @@ -96715,17 +97159,17 @@ | |
| 97159 | pMod->pModule = pModule; |
| 97160 | pMod->pAux = pAux; |
| 97161 | pMod->xDestroy = xDestroy; |
| 97162 | pDel = (Module *)sqlite3HashInsert(&db->aModule, zCopy, nName, (void*)pMod); |
| 97163 | if( pDel && pDel->xDestroy ){ |
| 97164 | sqlite3ResetInternalSchema(db, -1); |
| 97165 | pDel->xDestroy(pDel->pAux); |
| 97166 | } |
| 97167 | sqlite3DbFree(db, pDel); |
| 97168 | if( pDel==pMod ){ |
| 97169 | db->mallocFailed = 1; |
| 97170 | } |
| 97171 | }else if( xDestroy ){ |
| 97172 | xDestroy(pAux); |
| 97173 | } |
| 97174 | rc = sqlite3ApiExit(db, SQLITE_OK); |
| 97175 | sqlite3_mutex_leave(db->mutex); |
| @@ -97107,10 +97551,11 @@ | |
| 97551 | Table *pTab, |
| 97552 | Module *pMod, |
| 97553 | int (*xConstruct)(sqlite3*,void*,int,const char*const*,sqlite3_vtab**,char**), |
| 97554 | char **pzErr |
| 97555 | ){ |
| 97556 | VtabCtx sCtx; |
| 97557 | VTable *pVTable; |
| 97558 | int rc; |
| 97559 | const char *const*azArg = (const char *const*)pTab->azModuleArg; |
| 97560 | int nArg = pTab->nModuleArg; |
| 97561 | char *zErr = 0; |
| @@ -97126,16 +97571,18 @@ | |
| 97571 | return SQLITE_NOMEM; |
| 97572 | } |
| 97573 | pVTable->db = db; |
| 97574 | pVTable->pMod = pMod; |
| 97575 | |
| 97576 | /* Invoke the virtual table constructor */ |
| 97577 | assert( &db->pVtabCtx ); |
| 97578 | assert( xConstruct ); |
| 97579 | sCtx.pTab = pTab; |
| 97580 | sCtx.pVTable = pVTable; |
| 97581 | db->pVtabCtx = &sCtx; |
| 97582 | rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr); |
| 97583 | db->pVtabCtx = 0; |
| 97584 | if( rc==SQLITE_NOMEM ) db->mallocFailed = 1; |
| 97585 | |
| 97586 | if( SQLITE_OK!=rc ){ |
| 97587 | if( zErr==0 ){ |
| 97588 | *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName); |
| @@ -97147,11 +97594,11 @@ | |
| 97594 | }else if( ALWAYS(pVTable->pVtab) ){ |
| 97595 | /* Justification of ALWAYS(): A correct vtab constructor must allocate |
| 97596 | ** the sqlite3_vtab object if successful. */ |
| 97597 | pVTable->pVtab->pModule = pMod->pModule; |
| 97598 | pVTable->nRef = 1; |
| 97599 | if( sCtx.pTab ){ |
| 97600 | const char *zFormat = "vtable constructor did not declare schema: %s"; |
| 97601 | *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName); |
| 97602 | sqlite3VtabUnlock(pVTable); |
| 97603 | rc = SQLITE_ERROR; |
| 97604 | }else{ |
| @@ -97195,11 +97642,10 @@ | |
| 97642 | } |
| 97643 | } |
| 97644 | } |
| 97645 | |
| 97646 | sqlite3DbFree(db, zModuleName); |
| 97647 | return rc; |
| 97648 | } |
| 97649 | |
| 97650 | /* |
| 97651 | ** This function is invoked by the parser to call the xConnect() method |
| @@ -97315,12 +97761,11 @@ | |
| 97761 | int rc = SQLITE_OK; |
| 97762 | Table *pTab; |
| 97763 | char *zErr = 0; |
| 97764 | |
| 97765 | sqlite3_mutex_enter(db->mutex); |
| 97766 | if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){ |
| 97767 | sqlite3Error(db, SQLITE_MISUSE, 0); |
| 97768 | sqlite3_mutex_leave(db->mutex); |
| 97769 | return SQLITE_MISUSE_BKPT; |
| 97770 | } |
| 97771 | assert( (pTab->tabFlags & TF_Virtual)!=0 ); |
| @@ -97343,11 +97788,11 @@ | |
| 97788 | pTab->aCol = pParse->pNewTable->aCol; |
| 97789 | pTab->nCol = pParse->pNewTable->nCol; |
| 97790 | pParse->pNewTable->nCol = 0; |
| 97791 | pParse->pNewTable->aCol = 0; |
| 97792 | } |
| 97793 | db->pVtabCtx->pTab = 0; |
| 97794 | }else{ |
| 97795 | sqlite3Error(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr); |
| 97796 | sqlite3DbFree(db, zErr); |
| 97797 | rc = SQLITE_ERROR; |
| 97798 | } |
| @@ -97495,11 +97940,10 @@ | |
| 97940 | pModule = pVTab->pVtab->pModule; |
| 97941 | |
| 97942 | if( pModule->xBegin ){ |
| 97943 | int i; |
| 97944 | |
| 97945 | /* If pVtab is already in the aVTrans array, return early */ |
| 97946 | for(i=0; i<db->nVTrans; i++){ |
| 97947 | if( db->aVTrans[i]==pVTab ){ |
| 97948 | return SQLITE_OK; |
| 97949 | } |
| @@ -97508,10 +97952,53 @@ | |
| 97952 | /* Invoke the xBegin method */ |
| 97953 | rc = pModule->xBegin(pVTab->pVtab); |
| 97954 | if( rc==SQLITE_OK ){ |
| 97955 | rc = addToVTrans(db, pVTab); |
| 97956 | } |
| 97957 | } |
| 97958 | return rc; |
| 97959 | } |
| 97960 | |
| 97961 | /* |
| 97962 | ** Invoke either the xSavepoint, xRollbackTo or xRelease method of all |
| 97963 | ** virtual tables that currently have an open transaction. Pass iSavepoint |
| 97964 | ** as the second argument to the virtual table method invoked. |
| 97965 | ** |
| 97966 | ** If op is SAVEPOINT_BEGIN, the xSavepoint method is invoked. If it is |
| 97967 | ** SAVEPOINT_ROLLBACK, the xRollbackTo method. Otherwise, if op is |
| 97968 | ** SAVEPOINT_RELEASE, then the xRelease method of each virtual table with |
| 97969 | ** an open transaction is invoked. |
| 97970 | ** |
| 97971 | ** If any virtual table method returns an error code other than SQLITE_OK, |
| 97972 | ** processing is abandoned and the error returned to the caller of this |
| 97973 | ** function immediately. If all calls to virtual table methods are successful, |
| 97974 | ** SQLITE_OK is returned. |
| 97975 | */ |
| 97976 | SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){ |
| 97977 | int rc = SQLITE_OK; |
| 97978 | |
| 97979 | assert( op==SAVEPOINT_RELEASE||op==SAVEPOINT_ROLLBACK||op==SAVEPOINT_BEGIN ); |
| 97980 | if( db->aVTrans ){ |
| 97981 | int i; |
| 97982 | for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){ |
| 97983 | const sqlite3_module *pMod = db->aVTrans[i]->pMod->pModule; |
| 97984 | if( pMod->iVersion>=2 ){ |
| 97985 | int (*xMethod)(sqlite3_vtab *, int); |
| 97986 | switch( op ){ |
| 97987 | case SAVEPOINT_BEGIN: |
| 97988 | xMethod = pMod->xSavepoint; |
| 97989 | break; |
| 97990 | case SAVEPOINT_ROLLBACK: |
| 97991 | xMethod = pMod->xRollbackTo; |
| 97992 | break; |
| 97993 | default: |
| 97994 | xMethod = pMod->xRelease; |
| 97995 | break; |
| 97996 | } |
| 97997 | if( xMethod ) rc = xMethod(db->aVTrans[i]->pVtab, iSavepoint); |
| 97998 | } |
| 97999 | } |
| 98000 | } |
| 98001 | return rc; |
| 98002 | } |
| 98003 | |
| 98004 | /* |
| @@ -97609,10 +98096,61 @@ | |
| 98096 | pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab; |
| 98097 | }else{ |
| 98098 | pToplevel->db->mallocFailed = 1; |
| 98099 | } |
| 98100 | } |
| 98101 | |
| 98102 | /* |
| 98103 | ** Return the ON CONFLICT resolution mode in effect for the virtual |
| 98104 | ** table update operation currently in progress. |
| 98105 | ** |
| 98106 | ** The results of this routine are undefined unless it is called from |
| 98107 | ** within an xUpdate method. |
| 98108 | */ |
| 98109 | SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *db){ |
| 98110 | static const unsigned char aMap[] = { |
| 98111 | SQLITE_ROLLBACK, SQLITE_ABORT, SQLITE_FAIL, SQLITE_IGNORE, SQLITE_REPLACE |
| 98112 | }; |
| 98113 | assert( OE_Rollback==1 && OE_Abort==2 && OE_Fail==3 ); |
| 98114 | assert( OE_Ignore==4 && OE_Replace==5 ); |
| 98115 | assert( db->vtabOnConflict>=1 && db->vtabOnConflict<=5 ); |
| 98116 | return (int)aMap[db->vtabOnConflict-1]; |
| 98117 | } |
| 98118 | |
| 98119 | /* |
| 98120 | ** Call from within the xCreate() or xConnect() methods to provide |
| 98121 | ** the SQLite core with additional information about the behavior |
| 98122 | ** of the virtual table being implemented. |
| 98123 | */ |
| 98124 | SQLITE_API int sqlite3_vtab_config(sqlite3 *db, int op, ...){ |
| 98125 | va_list ap; |
| 98126 | int rc = SQLITE_OK; |
| 98127 | |
| 98128 | sqlite3_mutex_enter(db->mutex); |
| 98129 | |
| 98130 | va_start(ap, op); |
| 98131 | switch( op ){ |
| 98132 | case SQLITE_VTAB_CONSTRAINT_SUPPORT: { |
| 98133 | VtabCtx *p = db->pVtabCtx; |
| 98134 | if( !p ){ |
| 98135 | rc = SQLITE_MISUSE_BKPT; |
| 98136 | }else{ |
| 98137 | assert( p->pTab==0 || (p->pTab->tabFlags & TF_Virtual)!=0 ); |
| 98138 | p->pVTable->bConstraint = (u8)va_arg(ap, int); |
| 98139 | } |
| 98140 | break; |
| 98141 | } |
| 98142 | default: |
| 98143 | rc = SQLITE_MISUSE_BKPT; |
| 98144 | break; |
| 98145 | } |
| 98146 | va_end(ap); |
| 98147 | |
| 98148 | if( rc!=SQLITE_OK ) sqlite3Error(db, rc, 0); |
| 98149 | sqlite3_mutex_leave(db->mutex); |
| 98150 | return rc; |
| 98151 | } |
| 98152 | |
| 98153 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 98154 | |
| 98155 | /************** End of vtab.c ************************************************/ |
| 98156 | /************** Begin file where.c *******************************************/ |
| @@ -107631,10 +108169,15 @@ | |
| 108169 | typedef void(*LOGFUNC_t)(void*,int,const char*); |
| 108170 | sqlite3GlobalConfig.xLog = va_arg(ap, LOGFUNC_t); |
| 108171 | sqlite3GlobalConfig.pLogArg = va_arg(ap, void*); |
| 108172 | break; |
| 108173 | } |
| 108174 | |
| 108175 | case SQLITE_CONFIG_URI: { |
| 108176 | sqlite3GlobalConfig.bOpenUri = va_arg(ap, int); |
| 108177 | break; |
| 108178 | } |
| 108179 | |
| 108180 | default: { |
| 108181 | rc = SQLITE_ERROR; |
| 108182 | break; |
| 108183 | } |
| @@ -108990,25 +109533,257 @@ | |
| 109533 | } |
| 109534 | db->aLimit[limitId] = newLimit; |
| 109535 | } |
| 109536 | return oldLimit; /* IMP: R-53341-35419 */ |
| 109537 | } |
| 109538 | |
| 109539 | /* |
| 109540 | ** This function is used to parse both URIs and non-URI filenames passed by the |
| 109541 | ** user to API functions sqlite3_open() or sqlite3_open_v2(), and for database |
| 109542 | ** URIs specified as part of ATTACH statements. |
| 109543 | ** |
| 109544 | ** The first argument to this function is the name of the VFS to use (or |
| 109545 | ** a NULL to signify the default VFS) if the URI does not contain a "vfs=xxx" |
| 109546 | ** query parameter. The second argument contains the URI (or non-URI filename) |
| 109547 | ** itself. When this function is called the *pFlags variable should contain |
| 109548 | ** the default flags to open the database handle with. The value stored in |
| 109549 | ** *pFlags may be updated before returning if the URI filename contains |
| 109550 | ** "cache=xxx" or "mode=xxx" query parameters. |
| 109551 | ** |
| 109552 | ** If successful, SQLITE_OK is returned. In this case *ppVfs is set to point to |
| 109553 | ** the VFS that should be used to open the database file. *pzFile is set to |
| 109554 | ** point to a buffer containing the name of the file to open. It is the |
| 109555 | ** responsibility of the caller to eventually call sqlite3_free() to release |
| 109556 | ** this buffer. |
| 109557 | ** |
| 109558 | ** If an error occurs, then an SQLite error code is returned and *pzErrMsg |
| 109559 | ** may be set to point to a buffer containing an English language error |
| 109560 | ** message. It is the responsibility of the caller to eventually release |
| 109561 | ** this buffer by calling sqlite3_free(). |
| 109562 | */ |
| 109563 | SQLITE_PRIVATE int sqlite3ParseUri( |
| 109564 | const char *zDefaultVfs, /* VFS to use if no "vfs=xxx" query option */ |
| 109565 | const char *zUri, /* Nul-terminated URI to parse */ |
| 109566 | unsigned int *pFlags, /* IN/OUT: SQLITE_OPEN_XXX flags */ |
| 109567 | sqlite3_vfs **ppVfs, /* OUT: VFS to use */ |
| 109568 | char **pzFile, /* OUT: Filename component of URI */ |
| 109569 | char **pzErrMsg /* OUT: Error message (if rc!=SQLITE_OK) */ |
| 109570 | ){ |
| 109571 | int rc = SQLITE_OK; |
| 109572 | unsigned int flags = *pFlags; |
| 109573 | const char *zVfs = zDefaultVfs; |
| 109574 | char *zFile; |
| 109575 | char c; |
| 109576 | int nUri = sqlite3Strlen30(zUri); |
| 109577 | |
| 109578 | assert( *pzErrMsg==0 ); |
| 109579 | |
| 109580 | if( ((flags & SQLITE_OPEN_URI) || sqlite3GlobalConfig.bOpenUri) |
| 109581 | && nUri>=5 && memcmp(zUri, "file:", 5)==0 |
| 109582 | ){ |
| 109583 | char *zOpt; |
| 109584 | int eState; /* Parser state when parsing URI */ |
| 109585 | int iIn; /* Input character index */ |
| 109586 | int iOut = 0; /* Output character index */ |
| 109587 | int nByte = nUri+2; /* Bytes of space to allocate */ |
| 109588 | |
| 109589 | /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen |
| 109590 | ** method that there may be extra parameters following the file-name. */ |
| 109591 | flags |= SQLITE_OPEN_URI; |
| 109592 | |
| 109593 | for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&'); |
| 109594 | zFile = sqlite3_malloc(nByte); |
| 109595 | if( !zFile ) return SQLITE_NOMEM; |
| 109596 | |
| 109597 | /* Discard the scheme and authority segments of the URI. */ |
| 109598 | if( zUri[5]=='/' && zUri[6]=='/' ){ |
| 109599 | iIn = 7; |
| 109600 | while( zUri[iIn] && zUri[iIn]!='/' ) iIn++; |
| 109601 | |
| 109602 | if( iIn!=7 && (iIn!=16 || memcmp("localhost", &zUri[7], 9)) ){ |
| 109603 | *pzErrMsg = sqlite3_mprintf("invalid uri authority: %.*s", |
| 109604 | iIn-7, &zUri[7]); |
| 109605 | rc = SQLITE_ERROR; |
| 109606 | goto parse_uri_out; |
| 109607 | } |
| 109608 | }else{ |
| 109609 | iIn = 5; |
| 109610 | } |
| 109611 | |
| 109612 | /* Copy the filename and any query parameters into the zFile buffer. |
| 109613 | ** Decode %HH escape codes along the way. |
| 109614 | ** |
| 109615 | ** Within this loop, variable eState may be set to 0, 1 or 2, depending |
| 109616 | ** on the parsing context. As follows: |
| 109617 | ** |
| 109618 | ** 0: Parsing file-name. |
| 109619 | ** 1: Parsing name section of a name=value query parameter. |
| 109620 | ** 2: Parsing value section of a name=value query parameter. |
| 109621 | */ |
| 109622 | eState = 0; |
| 109623 | while( (c = zUri[iIn])!=0 && c!='#' ){ |
| 109624 | iIn++; |
| 109625 | if( c=='%' |
| 109626 | && sqlite3Isxdigit(zUri[iIn]) |
| 109627 | && sqlite3Isxdigit(zUri[iIn+1]) |
| 109628 | ){ |
| 109629 | int octet = (sqlite3HexToInt(zUri[iIn++]) << 4); |
| 109630 | octet += sqlite3HexToInt(zUri[iIn++]); |
| 109631 | |
| 109632 | assert( octet>=0 && octet<256 ); |
| 109633 | if( octet==0 ){ |
| 109634 | /* This branch is taken when "%00" appears within the URI. In this |
| 109635 | ** case we ignore all text in the remainder of the path, name or |
| 109636 | ** value currently being parsed. So ignore the current character |
| 109637 | ** and skip to the next "?", "=" or "&", as appropriate. */ |
| 109638 | while( (c = zUri[iIn])!=0 && c!='#' |
| 109639 | && (eState!=0 || c!='?') |
| 109640 | && (eState!=1 || (c!='=' && c!='&')) |
| 109641 | && (eState!=2 || c!='&') |
| 109642 | ){ |
| 109643 | iIn++; |
| 109644 | } |
| 109645 | continue; |
| 109646 | } |
| 109647 | c = octet; |
| 109648 | }else if( eState==1 && (c=='&' || c=='=') ){ |
| 109649 | if( zFile[iOut-1]==0 ){ |
| 109650 | /* An empty option name. Ignore this option altogether. */ |
| 109651 | while( zUri[iIn] && zUri[iIn]!='#' && zUri[iIn-1]!='&' ) iIn++; |
| 109652 | continue; |
| 109653 | } |
| 109654 | if( c=='&' ){ |
| 109655 | zFile[iOut++] = '\0'; |
| 109656 | }else{ |
| 109657 | eState = 2; |
| 109658 | } |
| 109659 | c = 0; |
| 109660 | }else if( (eState==0 && c=='?') || (eState==2 && c=='&') ){ |
| 109661 | c = 0; |
| 109662 | eState = 1; |
| 109663 | } |
| 109664 | zFile[iOut++] = c; |
| 109665 | } |
| 109666 | if( eState==1 ) zFile[iOut++] = '\0'; |
| 109667 | zFile[iOut++] = '\0'; |
| 109668 | zFile[iOut++] = '\0'; |
| 109669 | |
| 109670 | /* Check if there were any options specified that should be interpreted |
| 109671 | ** here. Options that are interpreted here include "vfs" and those that |
| 109672 | ** correspond to flags that may be passed to the sqlite3_open_v2() |
| 109673 | ** method. */ |
| 109674 | zOpt = &zFile[sqlite3Strlen30(zFile)+1]; |
| 109675 | while( zOpt[0] ){ |
| 109676 | int nOpt = sqlite3Strlen30(zOpt); |
| 109677 | char *zVal = &zOpt[nOpt+1]; |
| 109678 | int nVal = sqlite3Strlen30(zVal); |
| 109679 | |
| 109680 | if( nOpt==3 && memcmp("vfs", zOpt, 3)==0 ){ |
| 109681 | zVfs = zVal; |
| 109682 | }else{ |
| 109683 | struct OpenMode { |
| 109684 | const char *z; |
| 109685 | int mode; |
| 109686 | } *aMode = 0; |
| 109687 | char *zModeType; |
| 109688 | int mask; |
| 109689 | int limit; |
| 109690 | |
| 109691 | if( nOpt==5 && memcmp("cache", zOpt, 5)==0 ){ |
| 109692 | static struct OpenMode aCacheMode[] = { |
| 109693 | { "shared", SQLITE_OPEN_SHAREDCACHE }, |
| 109694 | { "private", SQLITE_OPEN_PRIVATECACHE }, |
| 109695 | { 0, 0 } |
| 109696 | }; |
| 109697 | |
| 109698 | mask = SQLITE_OPEN_SHAREDCACHE|SQLITE_OPEN_PRIVATECACHE; |
| 109699 | aMode = aCacheMode; |
| 109700 | limit = mask; |
| 109701 | zModeType = "cache"; |
| 109702 | } |
| 109703 | if( nOpt==4 && memcmp("mode", zOpt, 4)==0 ){ |
| 109704 | static struct OpenMode aOpenMode[] = { |
| 109705 | { "ro", SQLITE_OPEN_READONLY }, |
| 109706 | { "rw", SQLITE_OPEN_READWRITE }, |
| 109707 | { "rwc", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE }, |
| 109708 | { 0, 0 } |
| 109709 | }; |
| 109710 | |
| 109711 | mask = SQLITE_OPEN_READONLY|SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE; |
| 109712 | aMode = aOpenMode; |
| 109713 | limit = mask & flags; |
| 109714 | zModeType = "access"; |
| 109715 | } |
| 109716 | |
| 109717 | if( aMode ){ |
| 109718 | int i; |
| 109719 | int mode = 0; |
| 109720 | for(i=0; aMode[i].z; i++){ |
| 109721 | const char *z = aMode[i].z; |
| 109722 | if( nVal==sqlite3Strlen30(z) && 0==memcmp(zVal, z, nVal) ){ |
| 109723 | mode = aMode[i].mode; |
| 109724 | break; |
| 109725 | } |
| 109726 | } |
| 109727 | if( mode==0 ){ |
| 109728 | *pzErrMsg = sqlite3_mprintf("no such %s mode: %s", zModeType, zVal); |
| 109729 | rc = SQLITE_ERROR; |
| 109730 | goto parse_uri_out; |
| 109731 | } |
| 109732 | if( mode>limit ){ |
| 109733 | *pzErrMsg = sqlite3_mprintf("%s mode not allowed: %s", |
| 109734 | zModeType, zVal); |
| 109735 | rc = SQLITE_PERM; |
| 109736 | goto parse_uri_out; |
| 109737 | } |
| 109738 | flags = (flags & ~mask) | mode; |
| 109739 | } |
| 109740 | } |
| 109741 | |
| 109742 | zOpt = &zVal[nVal+1]; |
| 109743 | } |
| 109744 | |
| 109745 | }else{ |
| 109746 | zFile = sqlite3_malloc(nUri+2); |
| 109747 | if( !zFile ) return SQLITE_NOMEM; |
| 109748 | memcpy(zFile, zUri, nUri); |
| 109749 | zFile[nUri] = '\0'; |
| 109750 | zFile[nUri+1] = '\0'; |
| 109751 | } |
| 109752 | |
| 109753 | *ppVfs = sqlite3_vfs_find(zVfs); |
| 109754 | if( *ppVfs==0 ){ |
| 109755 | *pzErrMsg = sqlite3_mprintf("no such vfs: %s", zVfs); |
| 109756 | rc = SQLITE_ERROR; |
| 109757 | } |
| 109758 | parse_uri_out: |
| 109759 | if( rc!=SQLITE_OK ){ |
| 109760 | sqlite3_free(zFile); |
| 109761 | zFile = 0; |
| 109762 | } |
| 109763 | *pFlags = flags; |
| 109764 | *pzFile = zFile; |
| 109765 | return rc; |
| 109766 | } |
| 109767 | |
| 109768 | |
| 109769 | /* |
| 109770 | ** This routine does the work of opening a database on behalf of |
| 109771 | ** sqlite3_open() and sqlite3_open16(). The database filename "zFilename" |
| 109772 | ** is UTF-8 encoded. |
| 109773 | */ |
| 109774 | static int openDatabase( |
| 109775 | const char *zFilename, /* Database filename UTF-8 encoded */ |
| 109776 | sqlite3 **ppDb, /* OUT: Returned database handle */ |
| 109777 | unsigned int flags, /* Operational flags */ |
| 109778 | const char *zVfs /* Name of the VFS to use */ |
| 109779 | ){ |
| 109780 | sqlite3 *db; /* Store allocated handle here */ |
| 109781 | int rc; /* Return code */ |
| 109782 | int isThreadsafe; /* True for threadsafe connections */ |
| 109783 | char *zOpen = 0; /* Filename argument to pass to BtreeOpen() */ |
| 109784 | char *zErrMsg = 0; /* Error message from sqlite3ParseUri() */ |
| 109785 | |
| 109786 | *ppDb = 0; |
| 109787 | #ifndef SQLITE_OMIT_AUTOINIT |
| 109788 | rc = sqlite3_initialize(); |
| 109789 | if( rc ) return rc; |
| @@ -109028,11 +109803,11 @@ | |
| 109803 | assert( SQLITE_OPEN_READWRITE == 0x02 ); |
| 109804 | assert( SQLITE_OPEN_CREATE == 0x04 ); |
| 109805 | testcase( (1<<(flags&7))==0x02 ); /* READONLY */ |
| 109806 | testcase( (1<<(flags&7))==0x04 ); /* READWRITE */ |
| 109807 | testcase( (1<<(flags&7))==0x40 ); /* READWRITE | CREATE */ |
| 109808 | if( ((1<<(flags&7)) & 0x46)==0 ) return SQLITE_MISUSE_BKPT; |
| 109809 | |
| 109810 | if( sqlite3GlobalConfig.bCoreMutex==0 ){ |
| 109811 | isThreadsafe = 0; |
| 109812 | }else if( flags & SQLITE_OPEN_NOMUTEX ){ |
| 109813 | isThreadsafe = 0; |
| @@ -109109,17 +109884,10 @@ | |
| 109884 | sqlite3HashInit(&db->aCollSeq); |
| 109885 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 109886 | sqlite3HashInit(&db->aModule); |
| 109887 | #endif |
| 109888 | |
| 109889 | /* Add the default collation sequence BINARY. BINARY works for both UTF-8 |
| 109890 | ** and UTF-16, so add a version for each to avoid any unnecessary |
| 109891 | ** conversions. The only error that can occur here is a malloc() failure. |
| 109892 | */ |
| 109893 | createCollation(db, "BINARY", SQLITE_UTF8, SQLITE_COLL_BINARY, 0, |
| @@ -109138,13 +109906,22 @@ | |
| 109906 | |
| 109907 | /* Also add a UTF-8 case-insensitive collation sequence. */ |
| 109908 | createCollation(db, "NOCASE", SQLITE_UTF8, SQLITE_COLL_NOCASE, 0, |
| 109909 | nocaseCollatingFunc, 0); |
| 109910 | |
| 109911 | /* Parse the filename/URI argument. */ |
| 109912 | db->openFlags = flags; |
| 109913 | rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg); |
| 109914 | if( rc!=SQLITE_OK ){ |
| 109915 | if( rc==SQLITE_NOMEM ) db->mallocFailed = 1; |
| 109916 | sqlite3Error(db, rc, zErrMsg ? "%s" : 0, zErrMsg); |
| 109917 | sqlite3_free(zErrMsg); |
| 109918 | goto opendb_out; |
| 109919 | } |
| 109920 | |
| 109921 | /* Open the backend database driver */ |
| 109922 | rc = sqlite3BtreeOpen(db->pVfs, zOpen, db, &db->aDb[0].pBt, 0, |
| 109923 | flags | SQLITE_OPEN_MAIN_DB); |
| 109924 | if( rc!=SQLITE_OK ){ |
| 109925 | if( rc==SQLITE_IOERR_NOMEM ){ |
| 109926 | rc = SQLITE_NOMEM; |
| 109927 | } |
| @@ -109233,10 +110010,11 @@ | |
| 110010 | sqlite3GlobalConfig.nLookaside); |
| 110011 | |
| 110012 | sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT); |
| 110013 | |
| 110014 | opendb_out: |
| 110015 | sqlite3_free(zOpen); |
| 110016 | if( db ){ |
| 110017 | assert( db->mutex!=0 || isThreadsafe==0 || sqlite3GlobalConfig.bFullMutex==0 ); |
| 110018 | sqlite3_mutex_leave(db->mutex); |
| 110019 | } |
| 110020 | rc = sqlite3_errcode(db); |
| @@ -109264,11 +110042,11 @@ | |
| 110042 | const char *filename, /* Database filename (UTF-8) */ |
| 110043 | sqlite3 **ppDb, /* OUT: SQLite db handle */ |
| 110044 | int flags, /* Flags */ |
| 110045 | const char *zVfs /* Name of VFS module to use */ |
| 110046 | ){ |
| 110047 | return openDatabase(filename, ppDb, (unsigned int)flags, zVfs); |
| 110048 | } |
| 110049 | |
| 110050 | #ifndef SQLITE_OMIT_UTF16 |
| 110051 | /* |
| 110052 | ** Open a new database handle. |
| @@ -109874,10 +110652,32 @@ | |
| 110652 | } |
| 110653 | va_end(ap); |
| 110654 | #endif /* SQLITE_OMIT_BUILTIN_TEST */ |
| 110655 | return rc; |
| 110656 | } |
| 110657 | |
| 110658 | /* |
| 110659 | ** This is a utility routine, useful to VFS implementations, that checks |
| 110660 | ** to see if a database file was a URI that contained a specific query |
| 110661 | ** parameter, and if so obtains the value of the query parameter. |
| 110662 | ** |
| 110663 | ** The zFilename argument is the filename pointer passed into the xOpen() |
| 110664 | ** method of a VFS implementation. The zParam argument is the name of the |
| 110665 | ** query parameter we seek. This routine returns the value of the zParam |
| 110666 | ** parameter if it exists. If the parameter does not exist, this routine |
| 110667 | ** returns a NULL pointer. |
| 110668 | */ |
| 110669 | SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){ |
| 110670 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 110671 | while( zFilename[0] ){ |
| 110672 | int x = strcmp(zFilename, zParam); |
| 110673 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 110674 | if( x==0 ) return zFilename; |
| 110675 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 110676 | } |
| 110677 | return 0; |
| 110678 | } |
| 110679 | |
| 110680 | /************** End of main.c ************************************************/ |
| 110681 | /************** Begin file notify.c ******************************************/ |
| 110682 | /* |
| 110683 | ** 2009 March 3 |
| @@ -110955,10 +111755,11 @@ | |
| 111755 | Fts3DeferredToken *pDeferred; /* Deferred search tokens, if any */ |
| 111756 | sqlite3_int64 iPrevId; /* Previous id read from aDoclist */ |
| 111757 | char *pNextId; /* Pointer into the body of aDoclist */ |
| 111758 | char *aDoclist; /* List of docids for full-text queries */ |
| 111759 | int nDoclist; /* Size of buffer at aDoclist */ |
| 111760 | int desc; /* True to sort in descending order */ |
| 111761 | int eEvalmode; /* An FTS3_EVAL_XX constant */ |
| 111762 | int nRowAvg; /* Average size of database rows, in pages */ |
| 111763 | |
| 111764 | int isMatchinfoNeeded; /* True when aMatchinfo[] needs filling in */ |
| 111765 | u32 *aMatchinfo; /* Information about most recent match */ |
| @@ -111137,11 +111938,11 @@ | |
| 111938 | SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *); |
| 111939 | SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *); |
| 111940 | SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64); |
| 111941 | SQLITE_PRIVATE void sqlite3Fts3Dequote(char *); |
| 111942 | |
| 111943 | SQLITE_PRIVATE char *sqlite3Fts3FindPositions(Fts3Cursor *, Fts3Expr *, sqlite3_int64, int); |
| 111944 | SQLITE_PRIVATE int sqlite3Fts3ExprLoadDoclist(Fts3Cursor *, Fts3Expr *); |
| 111945 | SQLITE_PRIVATE int sqlite3Fts3ExprLoadFtDoclist(Fts3Cursor *, Fts3Expr *, char **, int *); |
| 111946 | SQLITE_PRIVATE int sqlite3Fts3ExprNearTrim(Fts3Expr *, Fts3Expr *, int); |
| 111947 | |
| 111948 | /* fts3_tokenizer.c */ |
| @@ -111164,10 +111965,11 @@ | |
| 111965 | char **, int, int, const char *, int, Fts3Expr ** |
| 111966 | ); |
| 111967 | SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *); |
| 111968 | #ifdef SQLITE_TEST |
| 111969 | SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db); |
| 111970 | SQLITE_PRIVATE int sqlite3Fts3InitTerm(sqlite3 *db); |
| 111971 | #endif |
| 111972 | |
| 111973 | /* fts3_aux.c */ |
| 111974 | SQLITE_PRIVATE int sqlite3Fts3InitAux(sqlite3 *db); |
| 111975 | |
| @@ -111284,10 +112086,38 @@ | |
| 112086 | static void fts3GetDeltaVarint(char **pp, sqlite3_int64 *pVal){ |
| 112087 | sqlite3_int64 iVal; |
| 112088 | *pp += sqlite3Fts3GetVarint(*pp, &iVal); |
| 112089 | *pVal += iVal; |
| 112090 | } |
| 112091 | |
| 112092 | /* |
| 112093 | ** When this function is called, *pp points to the first byte following a |
| 112094 | ** varint that is part of a doclist (or position-list, or any other list |
| 112095 | ** of varints). This function moves *pp to point to the start of that varint, |
| 112096 | ** and decrements the value stored in *pVal by the varint value. |
| 112097 | ** |
| 112098 | ** Argument pStart points to the first byte of the doclist that the |
| 112099 | ** varint is part of. |
| 112100 | */ |
| 112101 | static void fts3GetReverseDeltaVarint( |
| 112102 | char **pp, |
| 112103 | char *pStart, |
| 112104 | sqlite3_int64 *pVal |
| 112105 | ){ |
| 112106 | sqlite3_int64 iVal; |
| 112107 | char *p = *pp; |
| 112108 | |
| 112109 | /* Pointer p now points at the first byte past the varint we are |
| 112110 | ** interested in. So, unless the doclist is corrupt, the 0x80 bit is |
| 112111 | ** clear on character p[-1]. */ |
| 112112 | for(p = (*pp)-2; p>=pStart && *p&0x80; p--); |
| 112113 | p++; |
| 112114 | *pp = p; |
| 112115 | |
| 112116 | sqlite3Fts3GetVarint(p, &iVal); |
| 112117 | *pVal -= iVal; |
| 112118 | } |
| 112119 | |
| 112120 | /* |
| 112121 | ** As long as *pp has not reached its end (pEnd), then do the same |
| 112122 | ** as fts3GetDeltaVarint(): read a single varint and add it to *pVal. |
| 112123 | ** But if we have reached the end of the varint, just set *pp=0 and |
| @@ -111389,10 +112219,12 @@ | |
| 112219 | if( *pRc==SQLITE_OK ){ |
| 112220 | int i; /* Iterator variable */ |
| 112221 | int rc; /* Return code */ |
| 112222 | char *zSql; /* SQL statement passed to declare_vtab() */ |
| 112223 | char *zCols; /* List of user defined columns */ |
| 112224 | |
| 112225 | sqlite3_vtab_config(p->db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1); |
| 112226 | |
| 112227 | /* Create a list of user columns for the virtual table */ |
| 112228 | zCols = sqlite3_mprintf("%Q, ", p->azColumn[0]); |
| 112229 | for(i=1; zCols && i<p->nColumn; i++){ |
| 112230 | zCols = sqlite3_mprintf("%z%Q, ", zCols, p->azColumn[i]); |
| @@ -111958,10 +112790,26 @@ | |
| 112790 | |
| 112791 | if( iCons>=0 ){ |
| 112792 | pInfo->aConstraintUsage[iCons].argvIndex = 1; |
| 112793 | pInfo->aConstraintUsage[iCons].omit = 1; |
| 112794 | } |
| 112795 | |
| 112796 | /* Regardless of the strategy selected, FTS can deliver rows in rowid (or |
| 112797 | ** docid) order. Both ascending and descending are possible. |
| 112798 | */ |
| 112799 | if( pInfo->nOrderBy==1 ){ |
| 112800 | struct sqlite3_index_orderby *pOrder = &pInfo->aOrderBy[0]; |
| 112801 | if( pOrder->iColumn<0 || pOrder->iColumn==p->nColumn+1 ){ |
| 112802 | if( pOrder->desc ){ |
| 112803 | pInfo->idxStr = "DESC"; |
| 112804 | }else{ |
| 112805 | pInfo->idxStr = "ASC"; |
| 112806 | } |
| 112807 | } |
| 112808 | pInfo->orderByConsumed = 1; |
| 112809 | } |
| 112810 | |
| 112811 | return SQLITE_OK; |
| 112812 | } |
| 112813 | |
| 112814 | /* |
| 112815 | ** Implementation of xOpen method. |
| @@ -112015,11 +112863,11 @@ | |
| 112863 | if( rc==SQLITE_OK ){ |
| 112864 | /* If no row was found and no error has occured, then the %_content |
| 112865 | ** table is missing a row that is present in the full-text index. |
| 112866 | ** The data structures are corrupt. |
| 112867 | */ |
| 112868 | rc = SQLITE_CORRUPT_VTAB; |
| 112869 | } |
| 112870 | pCsr->isEof = 1; |
| 112871 | if( pContext ){ |
| 112872 | sqlite3_result_error_code(pContext, rc); |
| 112873 | } |
| @@ -112075,11 +112923,11 @@ | |
| 112923 | ** nNode bytes of content (see sqlite3Fts3ReadBlock() for details). |
| 112924 | */ |
| 112925 | zCsr += sqlite3Fts3GetVarint(zCsr, &iChild); |
| 112926 | zCsr += sqlite3Fts3GetVarint(zCsr, &iChild); |
| 112927 | if( zCsr>zEnd ){ |
| 112928 | return SQLITE_CORRUPT_VTAB; |
| 112929 | } |
| 112930 | |
| 112931 | while( zCsr<zEnd && (piFirst || piLast) ){ |
| 112932 | int cmp; /* memcmp() result */ |
| 112933 | int nSuffix; /* Size of term suffix */ |
| @@ -112093,11 +112941,11 @@ | |
| 112941 | } |
| 112942 | isFirstTerm = 0; |
| 112943 | zCsr += sqlite3Fts3GetVarint32(zCsr, &nSuffix); |
| 112944 | |
| 112945 | if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){ |
| 112946 | rc = SQLITE_CORRUPT_VTAB; |
| 112947 | goto finish_scan; |
| 112948 | } |
| 112949 | if( nPrefix+nSuffix>nAlloc ){ |
| 112950 | char *zNew; |
| 112951 | nAlloc = (nPrefix+nSuffix) * 2; |
| @@ -113862,16 +114710,24 @@ | |
| 114710 | rc = sqlite3_reset(pCsr->pStmt); |
| 114711 | break; |
| 114712 | } |
| 114713 | pCsr->iPrevId = sqlite3_column_int64(pCsr->pStmt, 0); |
| 114714 | }else{ |
| 114715 | if( pCsr->desc==0 ){ |
| 114716 | if( pCsr->pNextId>=&pCsr->aDoclist[pCsr->nDoclist] ){ |
| 114717 | pCsr->isEof = 1; |
| 114718 | break; |
| 114719 | } |
| 114720 | fts3GetDeltaVarint(&pCsr->pNextId, &pCsr->iPrevId); |
| 114721 | }else{ |
| 114722 | fts3GetReverseDeltaVarint(&pCsr->pNextId,pCsr->aDoclist,&pCsr->iPrevId); |
| 114723 | if( pCsr->pNextId<=pCsr->aDoclist ){ |
| 114724 | pCsr->isEof = 1; |
| 114725 | break; |
| 114726 | } |
| 114727 | } |
| 114728 | sqlite3_reset(pCsr->pStmt); |
| 114729 | pCsr->isRequireSeek = 1; |
| 114730 | pCsr->isMatchinfoNeeded = 1; |
| 114731 | } |
| 114732 | }while( SQLITE_OK==(rc = fts3EvalDeferred(pCsr, &res)) && res==0 ); |
| 114733 | |
| @@ -113900,12 +114756,12 @@ | |
| 114756 | const char *idxStr, /* Unused */ |
| 114757 | int nVal, /* Number of elements in apVal */ |
| 114758 | sqlite3_value **apVal /* Arguments for the indexing scheme */ |
| 114759 | ){ |
| 114760 | const char *azSql[] = { |
| 114761 | "SELECT %s FROM %Q.'%q_content' AS x WHERE docid = ?", /* non-full-scan */ |
| 114762 | "SELECT %s FROM %Q.'%q_content' AS x ORDER BY docid %s", /* full-scan */ |
| 114763 | }; |
| 114764 | int rc; /* Return code */ |
| 114765 | char *zSql; /* SQL statement used to access %_content */ |
| 114766 | Fts3Table *p = (Fts3Table *)pCursor->pVtab; |
| 114767 | Fts3Cursor *pCsr = (Fts3Cursor *)pCursor; |
| @@ -113957,11 +114813,13 @@ | |
| 114813 | ** statement loops through all rows of the %_content table. For a |
| 114814 | ** full-text query or docid lookup, the statement retrieves a single |
| 114815 | ** row by docid. |
| 114816 | */ |
| 114817 | zSql = (char *)azSql[idxNum==FTS3_FULLSCAN_SEARCH]; |
| 114818 | zSql = sqlite3_mprintf( |
| 114819 | zSql, p->zReadExprlist, p->zDb, p->zName, (idxStr ? idxStr : "ASC") |
| 114820 | ); |
| 114821 | if( !zSql ){ |
| 114822 | rc = SQLITE_NOMEM; |
| 114823 | }else{ |
| 114824 | rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0); |
| 114825 | sqlite3_free(zSql); |
| @@ -113969,11 +114827,26 @@ | |
| 114827 | if( rc==SQLITE_OK && idxNum==FTS3_DOCID_SEARCH ){ |
| 114828 | rc = sqlite3_bind_value(pCsr->pStmt, 1, apVal[0]); |
| 114829 | } |
| 114830 | pCsr->eSearch = (i16)idxNum; |
| 114831 | |
| 114832 | assert( pCsr->desc==0 ); |
| 114833 | if( rc!=SQLITE_OK ) return rc; |
| 114834 | if( rc==SQLITE_OK && pCsr->nDoclist>0 && idxStr && idxStr[0]=='D' ){ |
| 114835 | sqlite3_int64 iDocid = 0; |
| 114836 | char *csr = pCsr->aDoclist; |
| 114837 | while( csr<&pCsr->aDoclist[pCsr->nDoclist] ){ |
| 114838 | fts3GetDeltaVarint(&csr, &iDocid); |
| 114839 | } |
| 114840 | pCsr->pNextId = csr; |
| 114841 | pCsr->iPrevId = iDocid; |
| 114842 | pCsr->desc = 1; |
| 114843 | pCsr->isRequireSeek = 1; |
| 114844 | pCsr->isMatchinfoNeeded = 1; |
| 114845 | pCsr->eEvalmode = FTS3_EVAL_NEXT; |
| 114846 | return SQLITE_OK; |
| 114847 | } |
| 114848 | return fts3NextMethod(pCursor); |
| 114849 | } |
| 114850 | |
| 114851 | /* |
| 114852 | ** This is the xEof method of the virtual table. SQLite calls this |
| @@ -114121,17 +114994,37 @@ | |
| 114994 | pCsr->eEvalmode = FTS3_EVAL_MATCHINFO; |
| 114995 | rc = fts3EvalExpr(pCsr, pExpr, paDoclist, pnDoclist, 1); |
| 114996 | pCsr->eEvalmode = FTS3_EVAL_NEXT; |
| 114997 | return rc; |
| 114998 | } |
| 114999 | |
| 115000 | |
| 115001 | /* |
| 115002 | ** When called, *ppPoslist must point to the byte immediately following the |
| 115003 | ** end of a position-list. i.e. ( (*ppPoslist)[-1]==POS_END ). This function |
| 115004 | ** moves *ppPoslist so that it instead points to the first byte of the |
| 115005 | ** same position list. |
| 115006 | */ |
| 115007 | static void fts3ReversePoslist(char *pStart, char **ppPoslist){ |
| 115008 | char *p = &(*ppPoslist)[-3]; |
| 115009 | char c = p[1]; |
| 115010 | while( p>pStart && (*p & 0x80) | c ){ |
| 115011 | c = *p--; |
| 115012 | } |
| 115013 | if( p>pStart ){ p = &p[2]; } |
| 115014 | while( *p++&0x80 ); |
| 115015 | *ppPoslist = p; |
| 115016 | } |
| 115017 | |
| 115018 | |
| 115019 | /* |
| 115020 | ** After ExprLoadDoclist() (see above) has been called, this function is |
| 115021 | ** used to iterate/search through the position lists that make up the doclist |
| 115022 | ** stored in pExpr->aDoclist. |
| 115023 | */ |
| 115024 | SQLITE_PRIVATE char *sqlite3Fts3FindPositions( |
| 115025 | Fts3Cursor *pCursor, /* Associate FTS3 cursor */ |
| 115026 | Fts3Expr *pExpr, /* Access this expressions doclist */ |
| 115027 | sqlite3_int64 iDocid, /* Docid associated with requested pos-list */ |
| 115028 | int iCol /* Column of requested pos-list */ |
| 115029 | ){ |
| 115030 | assert( pExpr->isLoaded ); |
| @@ -114138,23 +115031,39 @@ | |
| 115031 | if( pExpr->aDoclist ){ |
| 115032 | char *pEnd = &pExpr->aDoclist[pExpr->nDoclist]; |
| 115033 | char *pCsr; |
| 115034 | |
| 115035 | if( pExpr->pCurrent==0 ){ |
| 115036 | if( pCursor->desc==0 ){ |
| 115037 | pExpr->pCurrent = pExpr->aDoclist; |
| 115038 | pExpr->iCurrent = 0; |
| 115039 | fts3GetDeltaVarint(&pExpr->pCurrent, &pExpr->iCurrent); |
| 115040 | }else{ |
| 115041 | pCsr = pExpr->aDoclist; |
| 115042 | while( pCsr<pEnd ){ |
| 115043 | fts3GetDeltaVarint(&pCsr, &pExpr->iCurrent); |
| 115044 | fts3PoslistCopy(0, &pCsr); |
| 115045 | } |
| 115046 | fts3ReversePoslist(pExpr->aDoclist, &pCsr); |
| 115047 | pExpr->pCurrent = pCsr; |
| 115048 | } |
| 115049 | } |
| 115050 | pCsr = pExpr->pCurrent; |
| 115051 | assert( pCsr ); |
| 115052 | |
| 115053 | while( (pCursor->desc==0 && pCsr<pEnd) |
| 115054 | || (pCursor->desc && pCsr>pExpr->aDoclist) |
| 115055 | ){ |
| 115056 | if( pCursor->desc==0 && pExpr->iCurrent<iDocid ){ |
| 115057 | fts3PoslistCopy(0, &pCsr); |
| 115058 | if( pCsr<pEnd ){ |
| 115059 | fts3GetDeltaVarint(&pCsr, &pExpr->iCurrent); |
| 115060 | } |
| 115061 | pExpr->pCurrent = pCsr; |
| 115062 | }else if( pCursor->desc && pExpr->iCurrent>iDocid ){ |
| 115063 | fts3GetReverseDeltaVarint(&pCsr, pExpr->aDoclist, &pExpr->iCurrent); |
| 115064 | fts3ReversePoslist(pExpr->aDoclist, &pCsr); |
| 115065 | pExpr->pCurrent = pCsr; |
| 115066 | }else{ |
| 115067 | if( pExpr->iCurrent==iDocid ){ |
| 115068 | int iThis = 0; |
| 115069 | if( iCol<0 ){ |
| @@ -114407,13 +115316,24 @@ | |
| 115316 | "ALTER TABLE %Q.'%q_segdir' RENAME TO '%q_segdir';", |
| 115317 | p->zDb, p->zName, zName |
| 115318 | ); |
| 115319 | return rc; |
| 115320 | } |
| 115321 | |
| 115322 | static int fts3SavepointMethod(sqlite3_vtab *pVtab, int iSavepoint){ |
| 115323 | return sqlite3Fts3PendingTermsFlush((Fts3Table *)pVtab); |
| 115324 | } |
| 115325 | static int fts3ReleaseMethod(sqlite3_vtab *pVtab, int iSavepoint){ |
| 115326 | return SQLITE_OK; |
| 115327 | } |
| 115328 | static int fts3RollbackToMethod(sqlite3_vtab *pVtab, int iSavepoint){ |
| 115329 | sqlite3Fts3PendingTermsClear((Fts3Table *)pVtab); |
| 115330 | return SQLITE_OK; |
| 115331 | } |
| 115332 | |
| 115333 | static const sqlite3_module fts3Module = { |
| 115334 | /* iVersion */ 2, |
| 115335 | /* xCreate */ fts3CreateMethod, |
| 115336 | /* xConnect */ fts3ConnectMethod, |
| 115337 | /* xBestIndex */ fts3BestIndexMethod, |
| 115338 | /* xDisconnect */ fts3DisconnectMethod, |
| 115339 | /* xDestroy */ fts3DestroyMethod, |
| @@ -114429,10 +115349,13 @@ | |
| 115349 | /* xSync */ fts3SyncMethod, |
| 115350 | /* xCommit */ fts3CommitMethod, |
| 115351 | /* xRollback */ fts3RollbackMethod, |
| 115352 | /* xFindFunction */ fts3FindFunctionMethod, |
| 115353 | /* xRename */ fts3RenameMethod, |
| 115354 | /* xSavepoint */ fts3SavepointMethod, |
| 115355 | /* xRelease */ fts3ReleaseMethod, |
| 115356 | /* xRollbackTo */ fts3RollbackToMethod, |
| 115357 | }; |
| 115358 | |
| 115359 | /* |
| 115360 | ** This function is registered as the module destructor (called when an |
| 115361 | ** FTS3 enabled database connection is closed). It frees the memory |
| @@ -114474,10 +115397,15 @@ | |
| 115397 | |
| 115398 | #ifdef SQLITE_ENABLE_ICU |
| 115399 | const sqlite3_tokenizer_module *pIcu = 0; |
| 115400 | sqlite3Fts3IcuTokenizerModule(&pIcu); |
| 115401 | #endif |
| 115402 | |
| 115403 | #ifdef SQLITE_TEST |
| 115404 | rc = sqlite3Fts3InitTerm(db); |
| 115405 | if( rc!=SQLITE_OK ) return rc; |
| 115406 | #endif |
| 115407 | |
| 115408 | rc = sqlite3Fts3InitAux(db); |
| 115409 | if( rc!=SQLITE_OK ) return rc; |
| 115410 | |
| 115411 | sqlite3Fts3SimpleTokenizerModule(&pSimple); |
| @@ -117995,11 +118923,11 @@ | |
| 118923 | sqlite3_bind_int64(pStmt, 1, iDocid); |
| 118924 | } |
| 118925 | rc = sqlite3_step(pStmt); |
| 118926 | if( rc!=SQLITE_ROW || sqlite3_column_type(pStmt, 0)!=SQLITE_BLOB ){ |
| 118927 | rc = sqlite3_reset(pStmt); |
| 118928 | if( rc==SQLITE_OK ) rc = SQLITE_CORRUPT_VTAB; |
| 118929 | pStmt = 0; |
| 118930 | }else{ |
| 118931 | rc = SQLITE_OK; |
| 118932 | } |
| 118933 | } |
| @@ -118451,18 +119379,18 @@ | |
| 119379 | ** full-text index. |
| 119380 | */ |
| 119381 | static void fts3DeleteTerms( |
| 119382 | int *pRC, /* Result code */ |
| 119383 | Fts3Table *p, /* The FTS table to delete from */ |
| 119384 | sqlite3_value *pRowid, /* The docid to be deleted */ |
| 119385 | u32 *aSz /* Sizes of deleted document written here */ |
| 119386 | ){ |
| 119387 | int rc; |
| 119388 | sqlite3_stmt *pSelect; |
| 119389 | |
| 119390 | if( *pRC ) return; |
| 119391 | rc = fts3SqlStmt(p, SQL_SELECT_CONTENT_BY_ROWID, &pSelect, &pRowid); |
| 119392 | if( rc==SQLITE_OK ){ |
| 119393 | if( SQLITE_ROW==sqlite3_step(pSelect) ){ |
| 119394 | int i; |
| 119395 | for(i=1; i<=p->nColumn; i++){ |
| 119396 | const char *zText = (const char *)sqlite3_column_text(pSelect, i); |
| @@ -118676,11 +119604,11 @@ | |
| 119604 | pNext += sqlite3Fts3GetVarint32(pNext, &nPrefix); |
| 119605 | pNext += sqlite3Fts3GetVarint32(pNext, &nSuffix); |
| 119606 | if( nPrefix<0 || nSuffix<=0 |
| 119607 | || &pNext[nSuffix]>&pReader->aNode[pReader->nNode] |
| 119608 | ){ |
| 119609 | return SQLITE_CORRUPT_VTAB; |
| 119610 | } |
| 119611 | |
| 119612 | if( nPrefix+nSuffix>pReader->nTermAlloc ){ |
| 119613 | int nNew = (nPrefix+nSuffix)*2; |
| 119614 | char *zNew = sqlite3_realloc(pReader->zTerm, nNew); |
| @@ -118702,11 +119630,11 @@ | |
| 119630 | ** of these statements is untrue, then the data structure is corrupt. |
| 119631 | */ |
| 119632 | if( &pReader->aDoclist[pReader->nDoclist]>&pReader->aNode[pReader->nNode] |
| 119633 | || pReader->aDoclist[pReader->nDoclist-1] |
| 119634 | ){ |
| 119635 | return SQLITE_CORRUPT_VTAB; |
| 119636 | } |
| 119637 | return SQLITE_OK; |
| 119638 | } |
| 119639 | |
| 119640 | /* |
| @@ -118827,11 +119755,11 @@ | |
| 119755 | while( a<pEnd ){ |
| 119756 | a += sqlite3Fts3GetVarint(a, &nByte); |
| 119757 | } |
| 119758 | if( nDoc==0 || nByte==0 ){ |
| 119759 | sqlite3_reset(pStmt); |
| 119760 | return SQLITE_CORRUPT_VTAB; |
| 119761 | } |
| 119762 | |
| 119763 | pCsr->nRowAvg = (int)(((nByte / nDoc) + pgsz) / pgsz); |
| 119764 | assert( pCsr->nRowAvg>0 ); |
| 119765 | rc = sqlite3_reset(pStmt); |
| @@ -119598,20 +120526,20 @@ | |
| 120526 | |
| 120527 | /* |
| 120528 | ** The first value in the apVal[] array is assumed to contain an integer. |
| 120529 | ** This function tests if there exist any documents with docid values that |
| 120530 | ** are different from that integer. i.e. if deleting the document with docid |
| 120531 | ** pRowid would mean the FTS3 table were empty. |
| 120532 | ** |
| 120533 | ** If successful, *pisEmpty is set to true if the table is empty except for |
| 120534 | ** document pRowid, or false otherwise, and SQLITE_OK is returned. If an |
| 120535 | ** error occurs, an SQLite error code is returned. |
| 120536 | */ |
| 120537 | static int fts3IsEmpty(Fts3Table *p, sqlite3_value *pRowid, int *pisEmpty){ |
| 120538 | sqlite3_stmt *pStmt; |
| 120539 | int rc; |
| 120540 | rc = fts3SqlStmt(p, SQL_IS_EMPTY, &pStmt, &pRowid); |
| 120541 | if( rc==SQLITE_OK ){ |
| 120542 | if( SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 120543 | *pisEmpty = sqlite3_column_int(pStmt, 0); |
| 120544 | } |
| 120545 | rc = sqlite3_reset(pStmt); |
| @@ -120331,10 +121259,44 @@ | |
| 121259 | pToken->pDeferred = pDeferred; |
| 121260 | |
| 121261 | return SQLITE_OK; |
| 121262 | } |
| 121263 | |
| 121264 | /* |
| 121265 | ** SQLite value pRowid contains the rowid of a row that may or may not be |
| 121266 | ** present in the FTS3 table. If it is, delete it and adjust the contents |
| 121267 | ** of subsiduary data structures accordingly. |
| 121268 | */ |
| 121269 | static int fts3DeleteByRowid( |
| 121270 | Fts3Table *p, |
| 121271 | sqlite3_value *pRowid, |
| 121272 | int *pnDoc, |
| 121273 | u32 *aSzDel |
| 121274 | ){ |
| 121275 | int isEmpty = 0; |
| 121276 | int rc = fts3IsEmpty(p, pRowid, &isEmpty); |
| 121277 | if( rc==SQLITE_OK ){ |
| 121278 | if( isEmpty ){ |
| 121279 | /* Deleting this row means the whole table is empty. In this case |
| 121280 | ** delete the contents of all three tables and throw away any |
| 121281 | ** data in the pendingTerms hash table. */ |
| 121282 | rc = fts3DeleteAll(p); |
| 121283 | *pnDoc = *pnDoc - 1; |
| 121284 | }else{ |
| 121285 | sqlite3_int64 iRemove = sqlite3_value_int64(pRowid); |
| 121286 | rc = fts3PendingTermsDocid(p, iRemove); |
| 121287 | fts3DeleteTerms(&rc, p, pRowid, aSzDel); |
| 121288 | fts3SqlExec(&rc, p, SQL_DELETE_CONTENT, &pRowid); |
| 121289 | if( sqlite3_changes(p->db) ) *pnDoc = *pnDoc - 1; |
| 121290 | if( p->bHasDocsize ){ |
| 121291 | fts3SqlExec(&rc, p, SQL_DELETE_DOCSIZE, &pRowid); |
| 121292 | } |
| 121293 | } |
| 121294 | } |
| 121295 | |
| 121296 | return rc; |
| 121297 | } |
| 121298 | |
| 121299 | /* |
| 121300 | ** This function does the work for the xUpdate method of FTS3 virtual |
| 121301 | ** tables. |
| 121302 | */ |
| @@ -120349,50 +121311,95 @@ | |
| 121311 | int isRemove = 0; /* True for an UPDATE or DELETE */ |
| 121312 | sqlite3_int64 iRemove = 0; /* Rowid removed by UPDATE or DELETE */ |
| 121313 | u32 *aSzIns; /* Sizes of inserted documents */ |
| 121314 | u32 *aSzDel; /* Sizes of deleted documents */ |
| 121315 | int nChng = 0; /* Net change in number of documents */ |
| 121316 | int bInsertDone = 0; |
| 121317 | |
| 121318 | assert( p->pSegments==0 ); |
| 121319 | |
| 121320 | /* Check for a "special" INSERT operation. One of the form: |
| 121321 | ** |
| 121322 | ** INSERT INTO xyz(xyz) VALUES('command'); |
| 121323 | */ |
| 121324 | if( nArg>1 |
| 121325 | && sqlite3_value_type(apVal[0])==SQLITE_NULL |
| 121326 | && sqlite3_value_type(apVal[p->nColumn+2])!=SQLITE_NULL |
| 121327 | ){ |
| 121328 | return fts3SpecialInsert(p, apVal[p->nColumn+2]); |
| 121329 | } |
| 121330 | |
| 121331 | /* Allocate space to hold the change in document sizes */ |
| 121332 | aSzIns = sqlite3_malloc( sizeof(aSzIns[0])*(p->nColumn+1)*2 ); |
| 121333 | if( aSzIns==0 ) return SQLITE_NOMEM; |
| 121334 | aSzDel = &aSzIns[p->nColumn+1]; |
| 121335 | memset(aSzIns, 0, sizeof(aSzIns[0])*(p->nColumn+1)*2); |
| 121336 | |
| 121337 | /* If this is an INSERT operation, or an UPDATE that modifies the rowid |
| 121338 | ** value, then this operation requires constraint handling. |
| 121339 | ** |
| 121340 | ** If the on-conflict mode is REPLACE, this means that the existing row |
| 121341 | ** should be deleted from the database before inserting the new row. Or, |
| 121342 | ** if the on-conflict mode is other than REPLACE, then this method must |
| 121343 | ** detect the conflict and return SQLITE_CONSTRAINT before beginning to |
| 121344 | ** modify the database file. |
| 121345 | */ |
| 121346 | if( nArg>1 ){ |
| 121347 | /* Find the value object that holds the new rowid value. */ |
| 121348 | sqlite3_value *pNewRowid = apVal[3+p->nColumn]; |
| 121349 | if( sqlite3_value_type(pNewRowid)==SQLITE_NULL ){ |
| 121350 | pNewRowid = apVal[1]; |
| 121351 | } |
| 121352 | |
| 121353 | if( sqlite3_value_type(pNewRowid)!=SQLITE_NULL && ( |
| 121354 | sqlite3_value_type(apVal[0])==SQLITE_NULL |
| 121355 | || sqlite3_value_int64(apVal[0])!=sqlite3_value_int64(pNewRowid) |
| 121356 | )){ |
| 121357 | /* The new rowid is not NULL (in this case the rowid will be |
| 121358 | ** automatically assigned and there is no chance of a conflict), and |
| 121359 | ** the statement is either an INSERT or an UPDATE that modifies the |
| 121360 | ** rowid column. So if the conflict mode is REPLACE, then delete any |
| 121361 | ** existing row with rowid=pNewRowid. |
| 121362 | ** |
| 121363 | ** Or, if the conflict mode is not REPLACE, insert the new record into |
| 121364 | ** the %_content table. If we hit the duplicate rowid constraint (or any |
| 121365 | ** other error) while doing so, return immediately. |
| 121366 | ** |
| 121367 | ** This branch may also run if pNewRowid contains a value that cannot |
| 121368 | ** be losslessly converted to an integer. In this case, the eventual |
| 121369 | ** call to fts3InsertData() (either just below or further on in this |
| 121370 | ** function) will return SQLITE_MISMATCH. If fts3DeleteByRowid is |
| 121371 | ** invoked, it will delete zero rows (since no row will have |
| 121372 | ** docid=$pNewRowid if $pNewRowid is not an integer value). |
| 121373 | */ |
| 121374 | if( sqlite3_vtab_on_conflict(p->db)==SQLITE_REPLACE ){ |
| 121375 | rc = fts3DeleteByRowid(p, pNewRowid, &nChng, aSzDel); |
| 121376 | }else{ |
| 121377 | rc = fts3InsertData(p, apVal, pRowid); |
| 121378 | bInsertDone = 1; |
| 121379 | } |
| 121380 | } |
| 121381 | } |
| 121382 | if( rc!=SQLITE_OK ){ |
| 121383 | sqlite3_free(aSzIns); |
| 121384 | return rc; |
| 121385 | } |
| 121386 | |
| 121387 | /* If this is a DELETE or UPDATE operation, remove the old record. */ |
| 121388 | if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){ |
| 121389 | assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER ); |
| 121390 | rc = fts3DeleteByRowid(p, apVal[0], &nChng, aSzDel); |
| 121391 | isRemove = 1; |
| 121392 | iRemove = sqlite3_value_int64(apVal[0]); |
| 121393 | } |
| 121394 | |
| 121395 | /* If this is an INSERT or UPDATE operation, insert the new record. */ |
| 121396 | if( nArg>1 && rc==SQLITE_OK ){ |
| 121397 | if( bInsertDone==0 ){ |
| 121398 | rc = fts3InsertData(p, apVal, pRowid); |
| 121399 | if( rc==SQLITE_CONSTRAINT ) rc = SQLITE_CORRUPT_VTAB; |
| 121400 | } |
| 121401 | if( rc==SQLITE_OK && (!isRemove || *pRowid!=iRemove) ){ |
| 121402 | rc = fts3PendingTermsDocid(p, *pRowid); |
| 121403 | } |
| 121404 | if( rc==SQLITE_OK ){ |
| 121405 | rc = fts3InsertTerms(p, apVal, aSzIns); |
| @@ -120852,11 +121859,11 @@ | |
| 121859 | SnippetPhrase *pPhrase = &p->aPhrase[iPhrase]; |
| 121860 | char *pCsr; |
| 121861 | |
| 121862 | pPhrase->nToken = pExpr->pPhrase->nToken; |
| 121863 | |
| 121864 | pCsr = sqlite3Fts3FindPositions(p->pCsr, pExpr, p->pCsr->iPrevId, p->iCol); |
| 121865 | if( pCsr ){ |
| 121866 | int iFirst = 0; |
| 121867 | pPhrase->pList = pCsr; |
| 121868 | fts3GetDeltaPosition(&pCsr, &iFirst); |
| 121869 | pPhrase->pHead = pCsr; |
| @@ -121325,11 +122332,11 @@ | |
| 122332 | for(i=0; i<p->nCol; i++) p->aMatchinfo[iStart+i*3] = 0; |
| 122333 | |
| 122334 | if( pExpr->aDoclist ){ |
| 122335 | char *pCsr; |
| 122336 | |
| 122337 | pCsr = sqlite3Fts3FindPositions(p->pCursor, pExpr, p->pCursor->iPrevId, -1); |
| 122338 | if( pCsr ){ |
| 122339 | fts3LoadColumnlistCounts(&pCsr, &p->aMatchinfo[iStart], 0); |
| 122340 | } |
| 122341 | } |
| 122342 | |
| @@ -121397,11 +122404,11 @@ | |
| 122404 | pStmt = *ppStmt; |
| 122405 | assert( sqlite3_data_count(pStmt)==1 ); |
| 122406 | |
| 122407 | a = sqlite3_column_blob(pStmt, 0); |
| 122408 | a += sqlite3Fts3GetVarint(a, &nDoc); |
| 122409 | if( nDoc==0 ) return SQLITE_CORRUPT_VTAB; |
| 122410 | *pnDoc = (u32)nDoc; |
| 122411 | |
| 122412 | if( paLen ) *paLen = a; |
| 122413 | return SQLITE_OK; |
| 122414 | } |
| @@ -121492,11 +122499,11 @@ | |
| 122499 | (void)fts3ExprIterate(pCsr->pExpr, fts3MatchinfoLcsCb, (void*)aIter); |
| 122500 | for(i=0; i<pInfo->nPhrase; i++){ |
| 122501 | LcsIterator *pIter = &aIter[i]; |
| 122502 | nToken -= pIter->pExpr->pPhrase->nToken; |
| 122503 | pIter->iPosOffset = nToken; |
| 122504 | pIter->pRead = sqlite3Fts3FindPositions(pCsr,pIter->pExpr,pCsr->iPrevId,-1); |
| 122505 | if( pIter->pRead ){ |
| 122506 | pIter->iPos = pIter->iPosOffset; |
| 122507 | fts3LcsIteratorAdvance(&aIter[i]); |
| 122508 | }else{ |
| 122509 | pIter->iCol = LCS_ITERATOR_FINISHED; |
| @@ -121845,10 +122852,11 @@ | |
| 122852 | int iPos; /* Position just read from pList */ |
| 122853 | int iOff; /* Offset of this term from read positions */ |
| 122854 | }; |
| 122855 | |
| 122856 | struct TermOffsetCtx { |
| 122857 | Fts3Cursor *pCsr; |
| 122858 | int iCol; /* Column of table to populate aTerm for */ |
| 122859 | int iTerm; |
| 122860 | sqlite3_int64 iDocid; |
| 122861 | TermOffset *aTerm; |
| 122862 | }; |
| @@ -121862,11 +122870,11 @@ | |
| 122870 | int iTerm; /* For looping through nTerm phrase terms */ |
| 122871 | char *pList; /* Pointer to position list for phrase */ |
| 122872 | int iPos = 0; /* First position in position-list */ |
| 122873 | |
| 122874 | UNUSED_PARAMETER(iPhrase); |
| 122875 | pList = sqlite3Fts3FindPositions(p->pCsr, pExpr, p->iDocid, p->iCol); |
| 122876 | nTerm = pExpr->pPhrase->nToken; |
| 122877 | if( pList ){ |
| 122878 | fts3GetDeltaPosition(&pList, &iPos); |
| 122879 | assert( iPos>=0 ); |
| 122880 | } |
| @@ -121915,10 +122923,11 @@ | |
| 122923 | if( 0==sCtx.aTerm ){ |
| 122924 | rc = SQLITE_NOMEM; |
| 122925 | goto offsets_out; |
| 122926 | } |
| 122927 | sCtx.iDocid = pCsr->iPrevId; |
| 122928 | sCtx.pCsr = pCsr; |
| 122929 | |
| 122930 | /* Loop through the table columns, appending offset information to |
| 122931 | ** string-buffer res for each column. |
| 122932 | */ |
| 122933 | for(iCol=0; iCol<pTab->nColumn; iCol++){ |
| @@ -121990,11 +122999,11 @@ | |
| 122999 | sqlite3_snprintf(sizeof(aBuffer), aBuffer, |
| 123000 | "%d %d %d %d ", iCol, pTerm-sCtx.aTerm, iStart, iEnd-iStart |
| 123001 | ); |
| 123002 | rc = fts3StringAppend(&res, aBuffer, -1); |
| 123003 | }else if( rc==SQLITE_DONE ){ |
| 123004 | rc = SQLITE_CORRUPT_VTAB; |
| 123005 | } |
| 123006 | } |
| 123007 | } |
| 123008 | if( rc==SQLITE_DONE ){ |
| 123009 | rc = SQLITE_OK; |
| @@ -122578,29 +123587,29 @@ | |
| 123587 | ** is greater than RTREE_MAX_DEPTH, the r-tree structure must be corrupt. |
| 123588 | */ |
| 123589 | if( pNode && iNode==1 ){ |
| 123590 | pRtree->iDepth = readInt16(pNode->zData); |
| 123591 | if( pRtree->iDepth>RTREE_MAX_DEPTH ){ |
| 123592 | rc = SQLITE_CORRUPT_VTAB; |
| 123593 | } |
| 123594 | } |
| 123595 | |
| 123596 | /* If no error has occurred so far, check if the "number of entries" |
| 123597 | ** field on the node is too large. If so, set the return code to |
| 123598 | ** SQLITE_CORRUPT_VTAB. |
| 123599 | */ |
| 123600 | if( pNode && rc==SQLITE_OK ){ |
| 123601 | if( NCELL(pNode)>((pRtree->iNodeSize-4)/pRtree->nBytesPerCell) ){ |
| 123602 | rc = SQLITE_CORRUPT_VTAB; |
| 123603 | } |
| 123604 | } |
| 123605 | |
| 123606 | if( rc==SQLITE_OK ){ |
| 123607 | if( pNode!=0 ){ |
| 123608 | nodeHashInsert(pRtree, pNode); |
| 123609 | }else{ |
| 123610 | rc = SQLITE_CORRUPT_VTAB; |
| 123611 | } |
| 123612 | *ppNode = pNode; |
| 123613 | }else{ |
| 123614 | sqlite3_free(pNode); |
| 123615 | *ppNode = 0; |
| @@ -123123,11 +124132,11 @@ | |
| 124132 | if( nodeGetRowid(pRtree, pNode, ii)==iRowid ){ |
| 124133 | *piIndex = ii; |
| 124134 | return SQLITE_OK; |
| 124135 | } |
| 124136 | } |
| 124137 | return SQLITE_CORRUPT_VTAB; |
| 124138 | } |
| 124139 | |
| 124140 | /* |
| 124141 | ** Return the index of the cell containing a pointer to node pNode |
| 124142 | ** in its parent. If pNode is the root node, return -1. |
| @@ -123718,11 +124727,11 @@ | |
| 124727 | RtreeNode *pParent = p->pParent; |
| 124728 | RtreeCell cell; |
| 124729 | int iCell; |
| 124730 | |
| 124731 | if( nodeParentIndex(pRtree, p, &iCell) ){ |
| 124732 | return SQLITE_CORRUPT_VTAB; |
| 124733 | } |
| 124734 | |
| 124735 | nodeGetCell(pRtree, pParent, iCell, &cell); |
| 124736 | if( !cellContains(pRtree, &cell, pCell) ){ |
| 124737 | cellUnion(pRtree, &cell, pCell); |
| @@ -124390,11 +125399,11 @@ | |
| 125399 | rc2 = nodeAcquire(pRtree, iNode, 0, &pChild->pParent); |
| 125400 | } |
| 125401 | } |
| 125402 | rc = sqlite3_reset(pRtree->pReadParent); |
| 125403 | if( rc==SQLITE_OK ) rc = rc2; |
| 125404 | if( rc==SQLITE_OK && !pChild->pParent ) rc = SQLITE_CORRUPT_VTAB; |
| 125405 | pChild = pChild->pParent; |
| 125406 | } |
| 125407 | return rc; |
| 125408 | } |
| 125409 | |
| @@ -124685,10 +125694,94 @@ | |
| 125694 | sqlite3_step(pRtree->pWriteRowid); |
| 125695 | rc = sqlite3_reset(pRtree->pWriteRowid); |
| 125696 | *piRowid = sqlite3_last_insert_rowid(pRtree->db); |
| 125697 | return rc; |
| 125698 | } |
| 125699 | |
| 125700 | /* |
| 125701 | ** Remove the entry with rowid=iDelete from the r-tree structure. |
| 125702 | */ |
| 125703 | static int rtreeDeleteRowid(Rtree *pRtree, sqlite3_int64 iDelete){ |
| 125704 | int rc; /* Return code */ |
| 125705 | RtreeNode *pLeaf; /* Leaf node containing record iDelete */ |
| 125706 | int iCell; /* Index of iDelete cell in pLeaf */ |
| 125707 | RtreeNode *pRoot; /* Root node of rtree structure */ |
| 125708 | |
| 125709 | |
| 125710 | /* Obtain a reference to the root node to initialise Rtree.iDepth */ |
| 125711 | rc = nodeAcquire(pRtree, 1, 0, &pRoot); |
| 125712 | |
| 125713 | /* Obtain a reference to the leaf node that contains the entry |
| 125714 | ** about to be deleted. |
| 125715 | */ |
| 125716 | if( rc==SQLITE_OK ){ |
| 125717 | rc = findLeafNode(pRtree, iDelete, &pLeaf); |
| 125718 | } |
| 125719 | |
| 125720 | /* Delete the cell in question from the leaf node. */ |
| 125721 | if( rc==SQLITE_OK ){ |
| 125722 | int rc2; |
| 125723 | rc = nodeRowidIndex(pRtree, pLeaf, iDelete, &iCell); |
| 125724 | if( rc==SQLITE_OK ){ |
| 125725 | rc = deleteCell(pRtree, pLeaf, iCell, 0); |
| 125726 | } |
| 125727 | rc2 = nodeRelease(pRtree, pLeaf); |
| 125728 | if( rc==SQLITE_OK ){ |
| 125729 | rc = rc2; |
| 125730 | } |
| 125731 | } |
| 125732 | |
| 125733 | /* Delete the corresponding entry in the <rtree>_rowid table. */ |
| 125734 | if( rc==SQLITE_OK ){ |
| 125735 | sqlite3_bind_int64(pRtree->pDeleteRowid, 1, iDelete); |
| 125736 | sqlite3_step(pRtree->pDeleteRowid); |
| 125737 | rc = sqlite3_reset(pRtree->pDeleteRowid); |
| 125738 | } |
| 125739 | |
| 125740 | /* Check if the root node now has exactly one child. If so, remove |
| 125741 | ** it, schedule the contents of the child for reinsertion and |
| 125742 | ** reduce the tree height by one. |
| 125743 | ** |
| 125744 | ** This is equivalent to copying the contents of the child into |
| 125745 | ** the root node (the operation that Gutman's paper says to perform |
| 125746 | ** in this scenario). |
| 125747 | */ |
| 125748 | if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){ |
| 125749 | int rc2; |
| 125750 | RtreeNode *pChild; |
| 125751 | i64 iChild = nodeGetRowid(pRtree, pRoot, 0); |
| 125752 | rc = nodeAcquire(pRtree, iChild, pRoot, &pChild); |
| 125753 | if( rc==SQLITE_OK ){ |
| 125754 | rc = removeNode(pRtree, pChild, pRtree->iDepth-1); |
| 125755 | } |
| 125756 | rc2 = nodeRelease(pRtree, pChild); |
| 125757 | if( rc==SQLITE_OK ) rc = rc2; |
| 125758 | if( rc==SQLITE_OK ){ |
| 125759 | pRtree->iDepth--; |
| 125760 | writeInt16(pRoot->zData, pRtree->iDepth); |
| 125761 | pRoot->isDirty = 1; |
| 125762 | } |
| 125763 | } |
| 125764 | |
| 125765 | /* Re-insert the contents of any underfull nodes removed from the tree. */ |
| 125766 | for(pLeaf=pRtree->pDeleted; pLeaf; pLeaf=pRtree->pDeleted){ |
| 125767 | if( rc==SQLITE_OK ){ |
| 125768 | rc = reinsertNodeContent(pRtree, pLeaf); |
| 125769 | } |
| 125770 | pRtree->pDeleted = pLeaf->pNext; |
| 125771 | sqlite3_free(pLeaf); |
| 125772 | } |
| 125773 | |
| 125774 | /* Release the reference to the root node. */ |
| 125775 | if( rc==SQLITE_OK ){ |
| 125776 | rc = nodeRelease(pRtree, pRoot); |
| 125777 | }else{ |
| 125778 | nodeRelease(pRtree, pRoot); |
| 125779 | } |
| 125780 | |
| 125781 | return rc; |
| 125782 | } |
| 125783 | |
| 125784 | /* |
| 125785 | ** The xUpdate method for rtree module virtual tables. |
| 125786 | */ |
| 125787 | static int rtreeUpdate( |
| @@ -124697,107 +125790,29 @@ | |
| 125790 | sqlite3_value **azData, |
| 125791 | sqlite_int64 *pRowid |
| 125792 | ){ |
| 125793 | Rtree *pRtree = (Rtree *)pVtab; |
| 125794 | int rc = SQLITE_OK; |
| 125795 | RtreeCell cell; /* New cell to insert if nData>1 */ |
| 125796 | int bHaveRowid = 0; /* Set to 1 after new rowid is determined */ |
| 125797 | |
| 125798 | rtreeReference(pRtree); |
| 125799 | assert(nData>=1); |
| 125800 | |
| 125801 | /* Constraint handling. A write operation on an r-tree table may return |
| 125802 | ** SQLITE_CONSTRAINT for two reasons: |
| 125803 | ** |
| 125804 | ** 1. A duplicate rowid value, or |
| 125805 | ** 2. The supplied data violates the "x2>=x1" constraint. |
| 125806 | ** |
| 125807 | ** In the first case, if the conflict-handling mode is REPLACE, then |
| 125808 | ** the conflicting row can be removed before proceeding. In the second |
| 125809 | ** case, SQLITE_CONSTRAINT must be returned regardless of the |
| 125810 | ** conflict-handling mode specified by the user. |
| 125811 | */ |
| 125812 | if( nData>1 ){ |
| 125813 | int ii; |
| 125814 | |
| 125815 | /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */ |
| 125816 | assert( nData==(pRtree->nDim*2 + 3) ); |
| 125817 | if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ |
| 125818 | for(ii=0; ii<(pRtree->nDim*2); ii+=2){ |
| @@ -124817,22 +125832,53 @@ | |
| 125832 | goto constraint; |
| 125833 | } |
| 125834 | } |
| 125835 | } |
| 125836 | |
| 125837 | /* If a rowid value was supplied, check if it is already present in |
| 125838 | ** the table. If so, the constraint has failed. */ |
| 125839 | if( sqlite3_value_type(azData[2])!=SQLITE_NULL ){ |
| 125840 | cell.iRowid = sqlite3_value_int64(azData[2]); |
| 125841 | if( sqlite3_value_type(azData[0])==SQLITE_NULL |
| 125842 | || sqlite3_value_int64(azData[0])!=cell.iRowid |
| 125843 | ){ |
| 125844 | int steprc; |
| 125845 | sqlite3_bind_int64(pRtree->pReadRowid, 1, cell.iRowid); |
| 125846 | steprc = sqlite3_step(pRtree->pReadRowid); |
| 125847 | rc = sqlite3_reset(pRtree->pReadRowid); |
| 125848 | if( SQLITE_ROW==steprc ){ |
| 125849 | if( sqlite3_vtab_on_conflict(pRtree->db)==SQLITE_REPLACE ){ |
| 125850 | rc = rtreeDeleteRowid(pRtree, cell.iRowid); |
| 125851 | }else{ |
| 125852 | rc = SQLITE_CONSTRAINT; |
| 125853 | goto constraint; |
| 125854 | } |
| 125855 | } |
| 125856 | } |
| 125857 | bHaveRowid = 1; |
| 125858 | } |
| 125859 | } |
| 125860 | |
| 125861 | /* If azData[0] is not an SQL NULL value, it is the rowid of a |
| 125862 | ** record to delete from the r-tree table. The following block does |
| 125863 | ** just that. |
| 125864 | */ |
| 125865 | if( sqlite3_value_type(azData[0])!=SQLITE_NULL ){ |
| 125866 | rc = rtreeDeleteRowid(pRtree, sqlite3_value_int64(azData[0])); |
| 125867 | } |
| 125868 | |
| 125869 | /* If the azData[] array contains more than one element, elements |
| 125870 | ** (azData[2]..azData[argc-1]) contain a new record to insert into |
| 125871 | ** the r-tree structure. |
| 125872 | */ |
| 125873 | if( rc==SQLITE_OK && nData>1 ){ |
| 125874 | /* Insert the new record into the r-tree */ |
| 125875 | RtreeNode *pLeaf; |
| 125876 | |
| 125877 | /* Figure out the rowid of the new row. */ |
| 125878 | if( bHaveRowid==0 ){ |
| 125879 | rc = newRowid(pRtree, &cell.iRowid); |
| 125880 | } |
| 125881 | *pRowid = cell.iRowid; |
| 125882 | |
| 125883 | if( rc==SQLITE_OK ){ |
| 125884 | rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf); |
| @@ -125068,10 +126114,12 @@ | |
| 126114 | int iErr = (argc<6) ? 2 : argc>(RTREE_MAX_DIMENSIONS*2+4) ? 3 : argc%2; |
| 126115 | if( aErrMsg[iErr] ){ |
| 126116 | *pzErr = sqlite3_mprintf("%s", aErrMsg[iErr]); |
| 126117 | return SQLITE_ERROR; |
| 126118 | } |
| 126119 | |
| 126120 | sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1); |
| 126121 | |
| 126122 | /* Allocate the sqlite3_vtab structure */ |
| 126123 | nDb = strlen(argv[1]); |
| 126124 | nName = strlen(argv[2]); |
| 126125 | pRtree = (Rtree *)sqlite3_malloc(sizeof(Rtree)+nDb+nName+2); |
| 126126 |
+339
-77
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -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.7.6.1" | |
| 111 | -#define SQLITE_VERSION_NUMBER 3007006 | |
| 112 | -#define SQLITE_SOURCE_ID "2011-04-27 19:54:44 f55156c5194e85c47728b8a97fde3e5f0a5c9b56" | |
| 110 | +#define SQLITE_VERSION "3.7.7" | |
| 111 | +#define SQLITE_VERSION_NUMBER 3007007 | |
| 112 | +#define SQLITE_SOURCE_ID "2011-05-18 03:02:10 186d7ff1d9804d508e472e4939608bf2be67bdc2" | |
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| @@ -373,11 +373,12 @@ | ||
| 373 | 373 | ** Many SQLite functions return an integer result code from the set shown |
| 374 | 374 | ** here in order to indicates success or failure. |
| 375 | 375 | ** |
| 376 | 376 | ** New error codes may be added in future versions of SQLite. |
| 377 | 377 | ** |
| 378 | -** See also: [SQLITE_IOERR_READ | extended result codes] | |
| 378 | +** See also: [SQLITE_IOERR_READ | extended result codes], | |
| 379 | +** [sqlite3_vtab_on_conflict()] [SQLITE_ROLLBACK | result codes]. | |
| 379 | 380 | */ |
| 380 | 381 | #define SQLITE_OK 0 /* Successful result */ |
| 381 | 382 | /* beginning-of-error-codes */ |
| 382 | 383 | #define SQLITE_ERROR 1 /* SQL error or missing database */ |
| 383 | 384 | #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ |
| @@ -455,25 +456,26 @@ | ||
| 455 | 456 | #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) |
| 456 | 457 | #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) |
| 457 | 458 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 458 | 459 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 459 | 460 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 461 | +#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) | |
| 460 | 462 | |
| 461 | 463 | /* |
| 462 | 464 | ** CAPI3REF: Flags For File Open Operations |
| 463 | 465 | ** |
| 464 | 466 | ** These bit values are intended for use in the |
| 465 | 467 | ** 3rd parameter to the [sqlite3_open_v2()] interface and |
| 466 | -** in the 4th parameter to the xOpen method of the | |
| 467 | -** [sqlite3_vfs] object. | |
| 468 | +** in the 4th parameter to the [sqlite3_vfs.xOpen] method. | |
| 468 | 469 | */ |
| 469 | 470 | #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ |
| 470 | 471 | #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ |
| 471 | 472 | #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ |
| 472 | 473 | #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ |
| 473 | 474 | #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ |
| 474 | 475 | #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ |
| 476 | +#define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */ | |
| 475 | 477 | #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ |
| 476 | 478 | #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ |
| 477 | 479 | #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ |
| 478 | 480 | #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ |
| 479 | 481 | #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ |
| @@ -580,21 +582,22 @@ | ||
| 580 | 582 | }; |
| 581 | 583 | |
| 582 | 584 | /* |
| 583 | 585 | ** CAPI3REF: OS Interface File Virtual Methods Object |
| 584 | 586 | ** |
| 585 | -** Every file opened by the [sqlite3_vfs] xOpen method populates an | |
| 587 | +** Every file opened by the [sqlite3_vfs.xOpen] method populates an | |
| 586 | 588 | ** [sqlite3_file] object (or, more commonly, a subclass of the |
| 587 | 589 | ** [sqlite3_file] object) with a pointer to an instance of this object. |
| 588 | 590 | ** This object defines the methods used to perform various operations |
| 589 | 591 | ** against the open file represented by the [sqlite3_file] object. |
| 590 | 592 | ** |
| 591 | -** If the xOpen method sets the sqlite3_file.pMethods element | |
| 593 | +** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element | |
| 592 | 594 | ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method |
| 593 | -** may be invoked even if the xOpen reported that it failed. The | |
| 594 | -** only way to prevent a call to xClose following a failed xOpen | |
| 595 | -** is for the xOpen to set the sqlite3_file.pMethods element to NULL. | |
| 595 | +** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The | |
| 596 | +** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen] | |
| 597 | +** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element | |
| 598 | +** to NULL. | |
| 596 | 599 | ** |
| 597 | 600 | ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or |
| 598 | 601 | ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync(). |
| 599 | 602 | ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY] |
| 600 | 603 | ** flag may be ORed in to indicate that only the data of the file |
| @@ -759,10 +762,11 @@ | ||
| 759 | 762 | */ |
| 760 | 763 | typedef struct sqlite3_mutex sqlite3_mutex; |
| 761 | 764 | |
| 762 | 765 | /* |
| 763 | 766 | ** CAPI3REF: OS Interface Object |
| 767 | +** KEYWORDS: VFS VFSes | |
| 764 | 768 | ** |
| 765 | 769 | ** An instance of the sqlite3_vfs object defines the interface between |
| 766 | 770 | ** the SQLite core and the underlying operating system. The "vfs" |
| 767 | 771 | ** in the name of the object stands for "virtual file system". |
| 768 | 772 | ** |
| @@ -791,10 +795,11 @@ | ||
| 791 | 795 | ** object once the object has been registered. |
| 792 | 796 | ** |
| 793 | 797 | ** The zName field holds the name of the VFS module. The name must |
| 794 | 798 | ** be unique across all VFS modules. |
| 795 | 799 | ** |
| 800 | +** [[sqlite3_vfs.xOpen]] | |
| 796 | 801 | ** ^SQLite guarantees that the zFilename parameter to xOpen |
| 797 | 802 | ** is either a NULL pointer or string obtained |
| 798 | 803 | ** from xFullPathname() with an optional suffix added. |
| 799 | 804 | ** ^If a suffix is added to the zFilename parameter, it will |
| 800 | 805 | ** consist of a single "-" character followed by no more than |
| @@ -868,10 +873,11 @@ | ||
| 868 | 873 | ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do |
| 869 | 874 | ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods |
| 870 | 875 | ** element will be valid after xOpen returns regardless of the success |
| 871 | 876 | ** or failure of the xOpen call. |
| 872 | 877 | ** |
| 878 | +** [[sqlite3_vfs.xAccess]] | |
| 873 | 879 | ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] |
| 874 | 880 | ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to |
| 875 | 881 | ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ] |
| 876 | 882 | ** to test whether a file is at least readable. The file can be a |
| 877 | 883 | ** directory. |
| @@ -1114,13 +1120,13 @@ | ||
| 1114 | 1120 | ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE. |
| 1115 | 1121 | ** Note, however, that ^sqlite3_config() can be called as part of the |
| 1116 | 1122 | ** implementation of an application-defined [sqlite3_os_init()]. |
| 1117 | 1123 | ** |
| 1118 | 1124 | ** The first argument to sqlite3_config() is an integer |
| 1119 | -** [SQLITE_CONFIG_SINGLETHREAD | configuration option] that determines | |
| 1125 | +** [configuration option] that determines | |
| 1120 | 1126 | ** what property of SQLite is to be configured. Subsequent arguments |
| 1121 | -** vary depending on the [SQLITE_CONFIG_SINGLETHREAD | configuration option] | |
| 1127 | +** vary depending on the [configuration option] | |
| 1122 | 1128 | ** in the first argument. |
| 1123 | 1129 | ** |
| 1124 | 1130 | ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. |
| 1125 | 1131 | ** ^If the option is unknown or SQLite is unable to set the option |
| 1126 | 1132 | ** then this routine returns a non-zero [error code]. |
| @@ -1226,10 +1232,11 @@ | ||
| 1226 | 1232 | void *pAppData; /* Argument to xInit() and xShutdown() */ |
| 1227 | 1233 | }; |
| 1228 | 1234 | |
| 1229 | 1235 | /* |
| 1230 | 1236 | ** CAPI3REF: Configuration Options |
| 1237 | +** KEYWORDS: {configuration option} | |
| 1231 | 1238 | ** |
| 1232 | 1239 | ** These constants are the available integer configuration options that |
| 1233 | 1240 | ** can be passed as the first argument to the [sqlite3_config()] interface. |
| 1234 | 1241 | ** |
| 1235 | 1242 | ** New configuration options may be added in future releases of SQLite. |
| @@ -1238,11 +1245,11 @@ | ||
| 1238 | 1245 | ** the call worked. The [sqlite3_config()] interface will return a |
| 1239 | 1246 | ** non-zero [error code] if a discontinued or unsupported configuration option |
| 1240 | 1247 | ** is invoked. |
| 1241 | 1248 | ** |
| 1242 | 1249 | ** <dl> |
| 1243 | -** <dt>SQLITE_CONFIG_SINGLETHREAD</dt> | |
| 1250 | +** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt> | |
| 1244 | 1251 | ** <dd>There are no arguments to this option. ^This option sets the |
| 1245 | 1252 | ** [threading mode] to Single-thread. In other words, it disables |
| 1246 | 1253 | ** all mutexing and puts SQLite into a mode where it can only be used |
| 1247 | 1254 | ** by a single thread. ^If SQLite is compiled with |
| 1248 | 1255 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| @@ -1249,11 +1256,11 @@ | ||
| 1249 | 1256 | ** it is not possible to change the [threading mode] from its default |
| 1250 | 1257 | ** value of Single-thread and so [sqlite3_config()] will return |
| 1251 | 1258 | ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD |
| 1252 | 1259 | ** configuration option.</dd> |
| 1253 | 1260 | ** |
| 1254 | -** <dt>SQLITE_CONFIG_MULTITHREAD</dt> | |
| 1261 | +** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt> | |
| 1255 | 1262 | ** <dd>There are no arguments to this option. ^This option sets the |
| 1256 | 1263 | ** [threading mode] to Multi-thread. In other words, it disables |
| 1257 | 1264 | ** mutexing on [database connection] and [prepared statement] objects. |
| 1258 | 1265 | ** The application is responsible for serializing access to |
| 1259 | 1266 | ** [database connections] and [prepared statements]. But other mutexes |
| @@ -1263,11 +1270,11 @@ | ||
| 1263 | 1270 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1264 | 1271 | ** it is not possible to set the Multi-thread [threading mode] and |
| 1265 | 1272 | ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
| 1266 | 1273 | ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd> |
| 1267 | 1274 | ** |
| 1268 | -** <dt>SQLITE_CONFIG_SERIALIZED</dt> | |
| 1275 | +** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt> | |
| 1269 | 1276 | ** <dd>There are no arguments to this option. ^This option sets the |
| 1270 | 1277 | ** [threading mode] to Serialized. In other words, this option enables |
| 1271 | 1278 | ** all mutexes including the recursive |
| 1272 | 1279 | ** mutexes on [database connection] and [prepared statement] objects. |
| 1273 | 1280 | ** In this mode (which is the default when SQLite is compiled with |
| @@ -1279,27 +1286,27 @@ | ||
| 1279 | 1286 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1280 | 1287 | ** it is not possible to set the Serialized [threading mode] and |
| 1281 | 1288 | ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
| 1282 | 1289 | ** SQLITE_CONFIG_SERIALIZED configuration option.</dd> |
| 1283 | 1290 | ** |
| 1284 | -** <dt>SQLITE_CONFIG_MALLOC</dt> | |
| 1291 | +** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt> | |
| 1285 | 1292 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1286 | 1293 | ** instance of the [sqlite3_mem_methods] structure. The argument specifies |
| 1287 | 1294 | ** alternative low-level memory allocation routines to be used in place of |
| 1288 | 1295 | ** the memory allocation routines built into SQLite.)^ ^SQLite makes |
| 1289 | 1296 | ** its own private copy of the content of the [sqlite3_mem_methods] structure |
| 1290 | 1297 | ** before the [sqlite3_config()] call returns.</dd> |
| 1291 | 1298 | ** |
| 1292 | -** <dt>SQLITE_CONFIG_GETMALLOC</dt> | |
| 1299 | +** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt> | |
| 1293 | 1300 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1294 | 1301 | ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods] |
| 1295 | 1302 | ** structure is filled with the currently defined memory allocation routines.)^ |
| 1296 | 1303 | ** This option can be used to overload the default memory allocation |
| 1297 | 1304 | ** routines with a wrapper that simulations memory allocation failure or |
| 1298 | 1305 | ** tracks memory usage, for example. </dd> |
| 1299 | 1306 | ** |
| 1300 | -** <dt>SQLITE_CONFIG_MEMSTATUS</dt> | |
| 1307 | +** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> | |
| 1301 | 1308 | ** <dd> ^This option takes single argument of type int, interpreted as a |
| 1302 | 1309 | ** boolean, which enables or disables the collection of memory allocation |
| 1303 | 1310 | ** statistics. ^(When memory allocation statistics are disabled, the |
| 1304 | 1311 | ** following SQLite interfaces become non-operational: |
| 1305 | 1312 | ** <ul> |
| @@ -1311,11 +1318,11 @@ | ||
| 1311 | 1318 | ** ^Memory allocation statistics are enabled by default unless SQLite is |
| 1312 | 1319 | ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory |
| 1313 | 1320 | ** allocation statistics are disabled by default. |
| 1314 | 1321 | ** </dd> |
| 1315 | 1322 | ** |
| 1316 | -** <dt>SQLITE_CONFIG_SCRATCH</dt> | |
| 1323 | +** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt> | |
| 1317 | 1324 | ** <dd> ^This option specifies a static memory buffer that SQLite can use for |
| 1318 | 1325 | ** scratch memory. There are three arguments: A pointer an 8-byte |
| 1319 | 1326 | ** aligned memory buffer from which the scratch allocations will be |
| 1320 | 1327 | ** drawn, the size of each scratch allocation (sz), |
| 1321 | 1328 | ** and the maximum number of scratch allocations (N). The sz |
| @@ -1327,11 +1334,11 @@ | ||
| 1327 | 1334 | ** ^SQLite will never require a scratch buffer that is more than 6 |
| 1328 | 1335 | ** times the database page size. ^If SQLite needs needs additional |
| 1329 | 1336 | ** scratch memory beyond what is provided by this configuration option, then |
| 1330 | 1337 | ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd> |
| 1331 | 1338 | ** |
| 1332 | -** <dt>SQLITE_CONFIG_PAGECACHE</dt> | |
| 1339 | +** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt> | |
| 1333 | 1340 | ** <dd> ^This option specifies a static memory buffer that SQLite can use for |
| 1334 | 1341 | ** the database page cache with the default page cache implemenation. |
| 1335 | 1342 | ** This configuration should not be used if an application-define page |
| 1336 | 1343 | ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option. |
| 1337 | 1344 | ** There are three arguments to this option: A pointer to 8-byte aligned |
| @@ -1348,11 +1355,11 @@ | ||
| 1348 | 1355 | ** SQLite goes to [sqlite3_malloc()] for the additional storage space. |
| 1349 | 1356 | ** The pointer in the first argument must |
| 1350 | 1357 | ** be aligned to an 8-byte boundary or subsequent behavior of SQLite |
| 1351 | 1358 | ** will be undefined.</dd> |
| 1352 | 1359 | ** |
| 1353 | -** <dt>SQLITE_CONFIG_HEAP</dt> | |
| 1360 | +** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> | |
| 1354 | 1361 | ** <dd> ^This option specifies a static memory buffer that SQLite will use |
| 1355 | 1362 | ** for all of its dynamic memory allocation needs beyond those provided |
| 1356 | 1363 | ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. |
| 1357 | 1364 | ** There are three arguments: An 8-byte aligned pointer to the memory, |
| 1358 | 1365 | ** the number of bytes in the memory buffer, and the minimum allocation size. |
| @@ -1365,11 +1372,11 @@ | ||
| 1365 | 1372 | ** The first pointer (the memory pointer) must be aligned to an 8-byte |
| 1366 | 1373 | ** boundary or subsequent behavior of SQLite will be undefined. |
| 1367 | 1374 | ** The minimum allocation size is capped at 2^12. Reasonable values |
| 1368 | 1375 | ** for the minimum allocation size are 2^5 through 2^8.</dd> |
| 1369 | 1376 | ** |
| 1370 | -** <dt>SQLITE_CONFIG_MUTEX</dt> | |
| 1377 | +** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt> | |
| 1371 | 1378 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1372 | 1379 | ** instance of the [sqlite3_mutex_methods] structure. The argument specifies |
| 1373 | 1380 | ** alternative low-level mutex routines to be used in place |
| 1374 | 1381 | ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the |
| 1375 | 1382 | ** content of the [sqlite3_mutex_methods] structure before the call to |
| @@ -1377,11 +1384,11 @@ | ||
| 1377 | 1384 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1378 | 1385 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1379 | 1386 | ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will |
| 1380 | 1387 | ** return [SQLITE_ERROR].</dd> |
| 1381 | 1388 | ** |
| 1382 | -** <dt>SQLITE_CONFIG_GETMUTEX</dt> | |
| 1389 | +** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt> | |
| 1383 | 1390 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1384 | 1391 | ** instance of the [sqlite3_mutex_methods] structure. The |
| 1385 | 1392 | ** [sqlite3_mutex_methods] |
| 1386 | 1393 | ** structure is filled with the currently defined mutex routines.)^ |
| 1387 | 1394 | ** This option can be used to overload the default mutex allocation |
| @@ -1390,32 +1397,32 @@ | ||
| 1390 | 1397 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1391 | 1398 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1392 | 1399 | ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will |
| 1393 | 1400 | ** return [SQLITE_ERROR].</dd> |
| 1394 | 1401 | ** |
| 1395 | -** <dt>SQLITE_CONFIG_LOOKASIDE</dt> | |
| 1402 | +** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt> | |
| 1396 | 1403 | ** <dd> ^(This option takes two arguments that determine the default |
| 1397 | 1404 | ** memory allocation for the lookaside memory allocator on each |
| 1398 | 1405 | ** [database connection]. The first argument is the |
| 1399 | 1406 | ** size of each lookaside buffer slot and the second is the number of |
| 1400 | 1407 | ** slots allocated to each database connection.)^ ^(This option sets the |
| 1401 | 1408 | ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] |
| 1402 | 1409 | ** verb to [sqlite3_db_config()] can be used to change the lookaside |
| 1403 | 1410 | ** configuration on individual connections.)^ </dd> |
| 1404 | 1411 | ** |
| 1405 | -** <dt>SQLITE_CONFIG_PCACHE</dt> | |
| 1412 | +** [[SQLITE_CONFIG_PCACHE]] <dt>SQLITE_CONFIG_PCACHE</dt> | |
| 1406 | 1413 | ** <dd> ^(This option takes a single argument which is a pointer to |
| 1407 | 1414 | ** an [sqlite3_pcache_methods] object. This object specifies the interface |
| 1408 | 1415 | ** to a custom page cache implementation.)^ ^SQLite makes a copy of the |
| 1409 | 1416 | ** object and uses it for page cache memory allocations.</dd> |
| 1410 | 1417 | ** |
| 1411 | -** <dt>SQLITE_CONFIG_GETPCACHE</dt> | |
| 1418 | +** [[SQLITE_CONFIG_GETPCACHE]] <dt>SQLITE_CONFIG_GETPCACHE</dt> | |
| 1412 | 1419 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1413 | 1420 | ** [sqlite3_pcache_methods] object. SQLite copies of the current |
| 1414 | 1421 | ** page cache implementation into that object.)^ </dd> |
| 1415 | 1422 | ** |
| 1416 | -** <dt>SQLITE_CONFIG_LOG</dt> | |
| 1423 | +** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> | |
| 1417 | 1424 | ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a |
| 1418 | 1425 | ** function with a call signature of void(*)(void*,int,const char*), |
| 1419 | 1426 | ** and a pointer to void. ^If the function pointer is not NULL, it is |
| 1420 | 1427 | ** invoked by [sqlite3_log()] to process each logging event. ^If the |
| 1421 | 1428 | ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op. |
| @@ -1429,10 +1436,22 @@ | ||
| 1429 | 1436 | ** The SQLite logging interface is not reentrant; the logger function |
| 1430 | 1437 | ** supplied by the application must not invoke any SQLite interface. |
| 1431 | 1438 | ** In a multi-threaded application, the application-defined logger |
| 1432 | 1439 | ** function must be threadsafe. </dd> |
| 1433 | 1440 | ** |
| 1441 | +** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI | |
| 1442 | +** <dd> This option takes a single argument of type int. If non-zero, then | |
| 1443 | +** URI handling is globally enabled. If the parameter is zero, then URI handling | |
| 1444 | +** is globally disabled. If URI handling is globally enabled, all filenames | |
| 1445 | +** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or | |
| 1446 | +** specified as part of [ATTACH] commands are interpreted as URIs, regardless | |
| 1447 | +** of whether or not the [SQLITE_OPEN_URI] flag is set when the database | |
| 1448 | +** connection is opened. If it is globally disabled, filenames are | |
| 1449 | +** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the | |
| 1450 | +** database connection is opened. By default, URI handling is globally | |
| 1451 | +** disabled. The default value may be changed by compiling with the | |
| 1452 | +** [SQLITE_USE_URI] symbol defined. | |
| 1434 | 1453 | ** </dl> |
| 1435 | 1454 | */ |
| 1436 | 1455 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1437 | 1456 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 1438 | 1457 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| @@ -1447,10 +1466,11 @@ | ||
| 1447 | 1466 | /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ |
| 1448 | 1467 | #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ |
| 1449 | 1468 | #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */ |
| 1450 | 1469 | #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */ |
| 1451 | 1470 | #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ |
| 1471 | +#define SQLITE_CONFIG_URI 17 /* int */ | |
| 1452 | 1472 | |
| 1453 | 1473 | /* |
| 1454 | 1474 | ** CAPI3REF: Database Connection Configuration Options |
| 1455 | 1475 | ** |
| 1456 | 1476 | ** These constants are the available integer configuration options that |
| @@ -1532,17 +1552,21 @@ | ||
| 1532 | 1552 | ** the table has a column of type [INTEGER PRIMARY KEY] then that column |
| 1533 | 1553 | ** is another alias for the rowid. |
| 1534 | 1554 | ** |
| 1535 | 1555 | ** ^This routine returns the [rowid] of the most recent |
| 1536 | 1556 | ** successful [INSERT] into the database from the [database connection] |
| 1537 | -** in the first argument. ^If no successful [INSERT]s | |
| 1557 | +** in the first argument. ^As of SQLite version 3.7.7, this routines | |
| 1558 | +** records the last insert rowid of both ordinary tables and [virtual tables]. | |
| 1559 | +** ^If no successful [INSERT]s | |
| 1538 | 1560 | ** have ever occurred on that database connection, zero is returned. |
| 1539 | 1561 | ** |
| 1540 | -** ^(If an [INSERT] occurs within a trigger, then the [rowid] of the inserted | |
| 1541 | -** row is returned by this routine as long as the trigger is running. | |
| 1542 | -** But once the trigger terminates, the value returned by this routine | |
| 1543 | -** reverts to the last value inserted before the trigger fired.)^ | |
| 1562 | +** ^(If an [INSERT] occurs within a trigger or within a [virtual table] | |
| 1563 | +** method, then this routine will return the [rowid] of the inserted | |
| 1564 | +** row as long as the trigger or virtual table method is running. | |
| 1565 | +** But once the trigger or virtual table method ends, the value returned | |
| 1566 | +** by this routine reverts to what it was before the trigger or virtual | |
| 1567 | +** table method began.)^ | |
| 1544 | 1568 | ** |
| 1545 | 1569 | ** ^An [INSERT] that fails due to a constraint violation is not a |
| 1546 | 1570 | ** successful [INSERT] and does not change the value returned by this |
| 1547 | 1571 | ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK, |
| 1548 | 1572 | ** and INSERT OR ABORT make no changes to the return value of this |
| @@ -2201,10 +2225,13 @@ | ||
| 2201 | 2225 | ** The [sqlite3_set_authorizer | authorizer callback function] must |
| 2202 | 2226 | ** return either [SQLITE_OK] or one of these two constants in order |
| 2203 | 2227 | ** to signal SQLite whether or not the action is permitted. See the |
| 2204 | 2228 | ** [sqlite3_set_authorizer | authorizer documentation] for additional |
| 2205 | 2229 | ** information. |
| 2230 | +** | |
| 2231 | +** Note that SQLITE_IGNORE is also used as a [SQLITE_ROLLBACK | return code] | |
| 2232 | +** from the [sqlite3_vtab_on_conflict()] interface. | |
| 2206 | 2233 | */ |
| 2207 | 2234 | #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ |
| 2208 | 2235 | #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ |
| 2209 | 2236 | |
| 2210 | 2237 | /* |
| @@ -2323,11 +2350,11 @@ | ||
| 2323 | 2350 | SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); |
| 2324 | 2351 | |
| 2325 | 2352 | /* |
| 2326 | 2353 | ** CAPI3REF: Opening A New Database Connection |
| 2327 | 2354 | ** |
| 2328 | -** ^These routines open an SQLite database file whose name is given by the | |
| 2355 | +** ^These routines open an SQLite database file as specified by the | |
| 2329 | 2356 | ** filename argument. ^The filename argument is interpreted as UTF-8 for |
| 2330 | 2357 | ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte |
| 2331 | 2358 | ** order for sqlite3_open16(). ^(A [database connection] handle is usually |
| 2332 | 2359 | ** returned in *ppDb, even if an error occurs. The only exception is that |
| 2333 | 2360 | ** if SQLite is unable to allocate memory to hold the [sqlite3] object, |
| @@ -2350,11 +2377,11 @@ | ||
| 2350 | 2377 | ** except that it accepts two additional parameters for additional control |
| 2351 | 2378 | ** over the new database connection. ^(The flags parameter to |
| 2352 | 2379 | ** sqlite3_open_v2() can take one of |
| 2353 | 2380 | ** the following three values, optionally combined with the |
| 2354 | 2381 | ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE], |
| 2355 | -** and/or [SQLITE_OPEN_PRIVATECACHE] flags:)^ | |
| 2382 | +** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^ | |
| 2356 | 2383 | ** |
| 2357 | 2384 | ** <dl> |
| 2358 | 2385 | ** ^(<dt>[SQLITE_OPEN_READONLY]</dt> |
| 2359 | 2386 | ** <dd>The database is opened in read-only mode. If the database does not |
| 2360 | 2387 | ** already exist, an error is returned.</dd>)^ |
| @@ -2369,13 +2396,12 @@ | ||
| 2369 | 2396 | ** it does not already exist. This is the behavior that is always used for |
| 2370 | 2397 | ** sqlite3_open() and sqlite3_open16().</dd>)^ |
| 2371 | 2398 | ** </dl> |
| 2372 | 2399 | ** |
| 2373 | 2400 | ** If the 3rd parameter to sqlite3_open_v2() is not one of the |
| 2374 | -** combinations shown above or one of the combinations shown above combined | |
| 2375 | -** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], | |
| 2376 | -** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_PRIVATECACHE] flags, | |
| 2401 | +** combinations shown above optionally combined with other | |
| 2402 | +** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits] | |
| 2377 | 2403 | ** then the behavior is undefined. |
| 2378 | 2404 | ** |
| 2379 | 2405 | ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection |
| 2380 | 2406 | ** opens in the multi-thread [threading mode] as long as the single-thread |
| 2381 | 2407 | ** mode has not been set at compile-time or start-time. ^If the |
| @@ -2385,10 +2411,15 @@ | ||
| 2385 | 2411 | ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be |
| 2386 | 2412 | ** eligible to use [shared cache mode], regardless of whether or not shared |
| 2387 | 2413 | ** cache is enabled using [sqlite3_enable_shared_cache()]. ^The |
| 2388 | 2414 | ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not |
| 2389 | 2415 | ** participate in [shared cache mode] even if it is enabled. |
| 2416 | +** | |
| 2417 | +** ^The fourth parameter to sqlite3_open_v2() is the name of the | |
| 2418 | +** [sqlite3_vfs] object that defines the operating system interface that | |
| 2419 | +** the new database connection should use. ^If the fourth parameter is | |
| 2420 | +** a NULL pointer then the default [sqlite3_vfs] object is used. | |
| 2390 | 2421 | ** |
| 2391 | 2422 | ** ^If the filename is ":memory:", then a private, temporary in-memory database |
| 2392 | 2423 | ** is created for the connection. ^This in-memory database will vanish when |
| 2393 | 2424 | ** the database connection is closed. Future versions of SQLite might |
| 2394 | 2425 | ** make use of additional special filenames that begin with the ":" character. |
| @@ -2398,14 +2429,115 @@ | ||
| 2398 | 2429 | ** |
| 2399 | 2430 | ** ^If the filename is an empty string, then a private, temporary |
| 2400 | 2431 | ** on-disk database will be created. ^This private database will be |
| 2401 | 2432 | ** automatically deleted as soon as the database connection is closed. |
| 2402 | 2433 | ** |
| 2403 | -** ^The fourth parameter to sqlite3_open_v2() is the name of the | |
| 2404 | -** [sqlite3_vfs] object that defines the operating system interface that | |
| 2405 | -** the new database connection should use. ^If the fourth parameter is | |
| 2406 | -** a NULL pointer then the default [sqlite3_vfs] object is used. | |
| 2434 | +** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3> | |
| 2435 | +** | |
| 2436 | +** ^If [URI filename] interpretation is enabled, and the filename argument | |
| 2437 | +** begins with "file:", then the filename is interpreted as a URI. ^URI | |
| 2438 | +** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is | |
| 2439 | +** is set in the fourth argument to sqlite3_open_v2(), or if it has | |
| 2440 | +** been enabled globally using the [SQLITE_CONFIG_URI] option with the | |
| 2441 | +** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option. | |
| 2442 | +** As of SQLite version 3.7.7, URI filename interpretation is turned off | |
| 2443 | +** by default, but future releases of SQLite might enable URI filename | |
| 2444 | +** intepretation by default. See "[URI filenames]" for additional | |
| 2445 | +** information. | |
| 2446 | +** | |
| 2447 | +** URI filenames are parsed according to RFC 3986. ^If the URI contains an | |
| 2448 | +** authority, then it must be either an empty string or the string | |
| 2449 | +** "localhost". ^If the authority is not an empty string or "localhost", an | |
| 2450 | +** error is returned to the caller. ^The fragment component of a URI, if | |
| 2451 | +** present, is ignored. | |
| 2452 | +** | |
| 2453 | +** ^SQLite uses the path component of the URI as the name of the disk file | |
| 2454 | +** which contains the database. ^If the path begins with a '/' character, | |
| 2455 | +** then it is interpreted as an absolute path. ^If the path does not begin | |
| 2456 | +** with a '/' (meaning that the authority section is omitted from the URI) | |
| 2457 | +** then the path is interpreted as a relative path. | |
| 2458 | +** ^On windows, the first component of an absolute path | |
| 2459 | +** is a drive specification (e.g. "C:"). | |
| 2460 | +** | |
| 2461 | +** [[core URI query parameters]] | |
| 2462 | +** The query component of a URI may contain parameters that are interpreted | |
| 2463 | +** either by SQLite itself, or by a [VFS | custom VFS implementation]. | |
| 2464 | +** SQLite interprets the following three query parameters: | |
| 2465 | +** | |
| 2466 | +** <ul> | |
| 2467 | +** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of | |
| 2468 | +** a VFS object that provides the operating system interface that should | |
| 2469 | +** be used to access the database file on disk. ^If this option is set to | |
| 2470 | +** an empty string the default VFS object is used. ^Specifying an unknown | |
| 2471 | +** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is | |
| 2472 | +** present, then the VFS specified by the option takes precedence over | |
| 2473 | +** the value passed as the fourth parameter to sqlite3_open_v2(). | |
| 2474 | +** | |
| 2475 | +** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw" or | |
| 2476 | +** "rwc". Attempting to set it to any other value is an error)^. | |
| 2477 | +** ^If "ro" is specified, then the database is opened for read-only | |
| 2478 | +** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the | |
| 2479 | +** third argument to sqlite3_prepare_v2(). ^If the mode option is set to | |
| 2480 | +** "rw", then the database is opened for read-write (but not create) | |
| 2481 | +** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had | |
| 2482 | +** been set. ^Value "rwc" is equivalent to setting both | |
| 2483 | +** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If sqlite3_open_v2() is | |
| 2484 | +** used, it is an error to specify a value for the mode parameter that is | |
| 2485 | +** less restrictive than that specified by the flags passed as the third | |
| 2486 | +** parameter. | |
| 2487 | +** | |
| 2488 | +** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or | |
| 2489 | +** "private". ^Setting it to "shared" is equivalent to setting the | |
| 2490 | +** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to | |
| 2491 | +** sqlite3_open_v2(). ^Setting the cache parameter to "private" is | |
| 2492 | +** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit. | |
| 2493 | +** ^If sqlite3_open_v2() is used and the "cache" parameter is present in | |
| 2494 | +** a URI filename, its value overrides any behaviour requested by setting | |
| 2495 | +** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag. | |
| 2496 | +** </ul> | |
| 2497 | +** | |
| 2498 | +** ^Specifying an unknown parameter in the query component of a URI is not an | |
| 2499 | +** error. Future versions of SQLite might understand additional query | |
| 2500 | +** parameters. See "[query parameters with special meaning to SQLite]" for | |
| 2501 | +** additional information. | |
| 2502 | +** | |
| 2503 | +** [[URI filename examples]] <h3>URI filename examples</h3> | |
| 2504 | +** | |
| 2505 | +** <table border="1" align=center cellpadding=5> | |
| 2506 | +** <tr><th> URI filenames <th> Results | |
| 2507 | +** <tr><td> file:data.db <td> | |
| 2508 | +** Open the file "data.db" in the current directory. | |
| 2509 | +** <tr><td> file:/home/fred/data.db<br> | |
| 2510 | +** file:///home/fred/data.db <br> | |
| 2511 | +** file://localhost/home/fred/data.db <br> <td> | |
| 2512 | +** Open the database file "/home/fred/data.db". | |
| 2513 | +** <tr><td> file://darkstar/home/fred/data.db <td> | |
| 2514 | +** An error. "darkstar" is not a recognized authority. | |
| 2515 | +** <tr><td style="white-space:nowrap"> | |
| 2516 | +** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db | |
| 2517 | +** <td> Windows only: Open the file "data.db" on fred's desktop on drive | |
| 2518 | +** C:. Note that the %20 escaping in this example is not strictly | |
| 2519 | +** necessary - space characters can be used literally | |
| 2520 | +** in URI filenames. | |
| 2521 | +** <tr><td> file:data.db?mode=ro&cache=private <td> | |
| 2522 | +** Open file "data.db" in the current directory for read-only access. | |
| 2523 | +** Regardless of whether or not shared-cache mode is enabled by | |
| 2524 | +** default, use a private cache. | |
| 2525 | +** <tr><td> file:/home/fred/data.db?vfs=unix-nolock <td> | |
| 2526 | +** Open file "/home/fred/data.db". Use the special VFS "unix-nolock". | |
| 2527 | +** <tr><td> file:data.db?mode=readonly <td> | |
| 2528 | +** An error. "readonly" is not a valid option for the "mode" parameter. | |
| 2529 | +** </table> | |
| 2530 | +** | |
| 2531 | +** ^URI hexadecimal escape sequences (%HH) are supported within the path and | |
| 2532 | +** query components of a URI. A hexadecimal escape sequence consists of a | |
| 2533 | +** percent sign - "%" - followed by exactly two hexadecimal digits | |
| 2534 | +** specifying an octet value. ^Before the path or query components of a | |
| 2535 | +** URI filename are interpreted, they are encoded using UTF-8 and all | |
| 2536 | +** hexadecimal escape sequences replaced by a single byte containing the | |
| 2537 | +** corresponding octet. If this process generates an invalid UTF-8 encoding, | |
| 2538 | +** the results are undefined. | |
| 2407 | 2539 | ** |
| 2408 | 2540 | ** <b>Note to Windows users:</b> The encoding used for the filename argument |
| 2409 | 2541 | ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever |
| 2410 | 2542 | ** codepage is currently defined. Filenames containing international |
| 2411 | 2543 | ** characters must be converted to UTF-8 prior to passing them into |
| @@ -2423,10 +2555,30 @@ | ||
| 2423 | 2555 | const char *filename, /* Database filename (UTF-8) */ |
| 2424 | 2556 | sqlite3 **ppDb, /* OUT: SQLite db handle */ |
| 2425 | 2557 | int flags, /* Flags */ |
| 2426 | 2558 | const char *zVfs /* Name of VFS module to use */ |
| 2427 | 2559 | ); |
| 2560 | + | |
| 2561 | +/* | |
| 2562 | +** CAPI3REF: Obtain Values For URI Parameters | |
| 2563 | +** | |
| 2564 | +** This is a utility routine, useful to VFS implementations, that checks | |
| 2565 | +** to see if a database file was a URI that contained a specific query | |
| 2566 | +** parameter, and if so obtains the value of the query parameter. | |
| 2567 | +** | |
| 2568 | +** The zFilename argument is the filename pointer passed into the xOpen() | |
| 2569 | +** method of a VFS implementation. The zParam argument is the name of the | |
| 2570 | +** query parameter we seek. This routine returns the value of the zParam | |
| 2571 | +** parameter if it exists. If the parameter does not exist, this routine | |
| 2572 | +** returns a NULL pointer. | |
| 2573 | +** | |
| 2574 | +** If the zFilename argument to this function is not a pointer that SQLite | |
| 2575 | +** passed into the xOpen VFS method, then the behavior of this routine | |
| 2576 | +** is undefined and probably undesirable. | |
| 2577 | +*/ | |
| 2578 | +SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam); | |
| 2579 | + | |
| 2428 | 2580 | |
| 2429 | 2581 | /* |
| 2430 | 2582 | ** CAPI3REF: Error Codes And Messages |
| 2431 | 2583 | ** |
| 2432 | 2584 | ** ^The sqlite3_errcode() interface returns the numeric [result code] or |
| @@ -2539,47 +2691,49 @@ | ||
| 2539 | 2691 | ** that can be lowered at run-time using [sqlite3_limit()]. |
| 2540 | 2692 | ** The synopsis of the meanings of the various limits is shown below. |
| 2541 | 2693 | ** Additional information is available at [limits | Limits in SQLite]. |
| 2542 | 2694 | ** |
| 2543 | 2695 | ** <dl> |
| 2544 | -** ^(<dt>SQLITE_LIMIT_LENGTH</dt> | |
| 2696 | +** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt> | |
| 2545 | 2697 | ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^ |
| 2546 | 2698 | ** |
| 2547 | -** ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt> | |
| 2699 | +** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt> | |
| 2548 | 2700 | ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^ |
| 2549 | 2701 | ** |
| 2550 | -** ^(<dt>SQLITE_LIMIT_COLUMN</dt> | |
| 2702 | +** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt> | |
| 2551 | 2703 | ** <dd>The maximum number of columns in a table definition or in the |
| 2552 | 2704 | ** result set of a [SELECT] or the maximum number of columns in an index |
| 2553 | 2705 | ** or in an ORDER BY or GROUP BY clause.</dd>)^ |
| 2554 | 2706 | ** |
| 2555 | -** ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> | |
| 2707 | +** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> | |
| 2556 | 2708 | ** <dd>The maximum depth of the parse tree on any expression.</dd>)^ |
| 2557 | 2709 | ** |
| 2558 | -** ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt> | |
| 2710 | +** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt> | |
| 2559 | 2711 | ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^ |
| 2560 | 2712 | ** |
| 2561 | -** ^(<dt>SQLITE_LIMIT_VDBE_OP</dt> | |
| 2713 | +** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt> | |
| 2562 | 2714 | ** <dd>The maximum number of instructions in a virtual machine program |
| 2563 | 2715 | ** used to implement an SQL statement. This limit is not currently |
| 2564 | 2716 | ** enforced, though that might be added in some future release of |
| 2565 | 2717 | ** SQLite.</dd>)^ |
| 2566 | 2718 | ** |
| 2567 | -** ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt> | |
| 2719 | +** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt> | |
| 2568 | 2720 | ** <dd>The maximum number of arguments on a function.</dd>)^ |
| 2569 | 2721 | ** |
| 2570 | -** ^(<dt>SQLITE_LIMIT_ATTACHED</dt> | |
| 2722 | +** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt> | |
| 2571 | 2723 | ** <dd>The maximum number of [ATTACH | attached databases].)^</dd> |
| 2572 | 2724 | ** |
| 2725 | +** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]] | |
| 2573 | 2726 | ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt> |
| 2574 | 2727 | ** <dd>The maximum length of the pattern argument to the [LIKE] or |
| 2575 | 2728 | ** [GLOB] operators.</dd>)^ |
| 2576 | 2729 | ** |
| 2730 | +** [[SQLITE_LIMIT_VARIABLE_NUMBER]] | |
| 2577 | 2731 | ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> |
| 2578 | 2732 | ** <dd>The maximum index number of any [parameter] in an SQL statement.)^ |
| 2579 | 2733 | ** |
| 2580 | -** ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> | |
| 2734 | +** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> | |
| 2581 | 2735 | ** <dd>The maximum depth of recursion for triggers.</dd>)^ |
| 2582 | 2736 | ** </dl> |
| 2583 | 2737 | */ |
| 2584 | 2738 | #define SQLITE_LIMIT_LENGTH 0 |
| 2585 | 2739 | #define SQLITE_LIMIT_SQL_LENGTH 1 |
| @@ -4610,10 +4764,15 @@ | ||
| 4610 | 4764 | int (*xRollback)(sqlite3_vtab *pVTab); |
| 4611 | 4765 | int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName, |
| 4612 | 4766 | void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), |
| 4613 | 4767 | void **ppArg); |
| 4614 | 4768 | int (*xRename)(sqlite3_vtab *pVtab, const char *zNew); |
| 4769 | + /* The methods above are in version 1 of the sqlite_module object. Those | |
| 4770 | + ** below are for version 2 and greater. */ | |
| 4771 | + int (*xSavepoint)(sqlite3_vtab *pVTab, int); | |
| 4772 | + int (*xRelease)(sqlite3_vtab *pVTab, int); | |
| 4773 | + int (*xRollbackTo)(sqlite3_vtab *pVTab, int); | |
| 4615 | 4774 | }; |
| 4616 | 4775 | |
| 4617 | 4776 | /* |
| 4618 | 4777 | ** CAPI3REF: Virtual Table Indexing Information |
| 4619 | 4778 | ** KEYWORDS: sqlite3_index_info |
| @@ -5424,11 +5583,11 @@ | ||
| 5424 | 5583 | ** |
| 5425 | 5584 | ** ^This interface is used to retrieve runtime status information |
| 5426 | 5585 | ** about the performance of SQLite, and optionally to reset various |
| 5427 | 5586 | ** highwater marks. ^The first argument is an integer code for |
| 5428 | 5587 | ** the specific parameter to measure. ^(Recognized integer codes |
| 5429 | -** are of the form [SQLITE_STATUS_MEMORY_USED | SQLITE_STATUS_...].)^ | |
| 5588 | +** are of the form [status parameters | SQLITE_STATUS_...].)^ | |
| 5430 | 5589 | ** ^The current value of the parameter is returned into *pCurrent. |
| 5431 | 5590 | ** ^The highest recorded value is returned in *pHighwater. ^If the |
| 5432 | 5591 | ** resetFlag is true, then the highest record value is reset after |
| 5433 | 5592 | ** *pHighwater is written. ^(Some parameters do not record the highest |
| 5434 | 5593 | ** value. For those parameters |
| @@ -5451,82 +5610,84 @@ | ||
| 5451 | 5610 | SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); |
| 5452 | 5611 | |
| 5453 | 5612 | |
| 5454 | 5613 | /* |
| 5455 | 5614 | ** CAPI3REF: Status Parameters |
| 5615 | +** KEYWORDS: {status parameters} | |
| 5456 | 5616 | ** |
| 5457 | 5617 | ** These integer constants designate various run-time status parameters |
| 5458 | 5618 | ** that can be returned by [sqlite3_status()]. |
| 5459 | 5619 | ** |
| 5460 | 5620 | ** <dl> |
| 5461 | -** ^(<dt>SQLITE_STATUS_MEMORY_USED</dt> | |
| 5621 | +** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt> | |
| 5462 | 5622 | ** <dd>This parameter is the current amount of memory checked out |
| 5463 | 5623 | ** using [sqlite3_malloc()], either directly or indirectly. The |
| 5464 | 5624 | ** figure includes calls made to [sqlite3_malloc()] by the application |
| 5465 | 5625 | ** and internal memory usage by the SQLite library. Scratch memory |
| 5466 | 5626 | ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache |
| 5467 | 5627 | ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in |
| 5468 | 5628 | ** this parameter. The amount returned is the sum of the allocation |
| 5469 | 5629 | ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^ |
| 5470 | 5630 | ** |
| 5471 | -** ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt> | |
| 5631 | +** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt> | |
| 5472 | 5632 | ** <dd>This parameter records the largest memory allocation request |
| 5473 | 5633 | ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their |
| 5474 | 5634 | ** internal equivalents). Only the value returned in the |
| 5475 | 5635 | ** *pHighwater parameter to [sqlite3_status()] is of interest. |
| 5476 | 5636 | ** The value written into the *pCurrent parameter is undefined.</dd>)^ |
| 5477 | 5637 | ** |
| 5478 | -** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt> | |
| 5638 | +** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt> | |
| 5479 | 5639 | ** <dd>This parameter records the number of separate memory allocations |
| 5480 | 5640 | ** currently checked out.</dd>)^ |
| 5481 | 5641 | ** |
| 5482 | -** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt> | |
| 5642 | +** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt> | |
| 5483 | 5643 | ** <dd>This parameter returns the number of pages used out of the |
| 5484 | 5644 | ** [pagecache memory allocator] that was configured using |
| 5485 | 5645 | ** [SQLITE_CONFIG_PAGECACHE]. The |
| 5486 | 5646 | ** value returned is in pages, not in bytes.</dd>)^ |
| 5487 | 5647 | ** |
| 5648 | +** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]] | |
| 5488 | 5649 | ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt> |
| 5489 | 5650 | ** <dd>This parameter returns the number of bytes of page cache |
| 5490 | 5651 | ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE] |
| 5491 | 5652 | ** buffer and where forced to overflow to [sqlite3_malloc()]. The |
| 5492 | 5653 | ** returned value includes allocations that overflowed because they |
| 5493 | 5654 | ** where too large (they were larger than the "sz" parameter to |
| 5494 | 5655 | ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because |
| 5495 | 5656 | ** no space was left in the page cache.</dd>)^ |
| 5496 | 5657 | ** |
| 5497 | -** ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt> | |
| 5658 | +** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt> | |
| 5498 | 5659 | ** <dd>This parameter records the largest memory allocation request |
| 5499 | 5660 | ** handed to [pagecache memory allocator]. Only the value returned in the |
| 5500 | 5661 | ** *pHighwater parameter to [sqlite3_status()] is of interest. |
| 5501 | 5662 | ** The value written into the *pCurrent parameter is undefined.</dd>)^ |
| 5502 | 5663 | ** |
| 5503 | -** ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt> | |
| 5664 | +** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt> | |
| 5504 | 5665 | ** <dd>This parameter returns the number of allocations used out of the |
| 5505 | 5666 | ** [scratch memory allocator] configured using |
| 5506 | 5667 | ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not |
| 5507 | 5668 | ** in bytes. Since a single thread may only have one scratch allocation |
| 5508 | 5669 | ** outstanding at time, this parameter also reports the number of threads |
| 5509 | 5670 | ** using scratch memory at the same time.</dd>)^ |
| 5510 | 5671 | ** |
| 5511 | -** ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt> | |
| 5672 | +** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt> | |
| 5512 | 5673 | ** <dd>This parameter returns the number of bytes of scratch memory |
| 5513 | 5674 | ** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH] |
| 5514 | 5675 | ** buffer and where forced to overflow to [sqlite3_malloc()]. The values |
| 5515 | 5676 | ** returned include overflows because the requested allocation was too |
| 5516 | 5677 | ** larger (that is, because the requested allocation was larger than the |
| 5517 | 5678 | ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer |
| 5518 | 5679 | ** slots were available. |
| 5519 | 5680 | ** </dd>)^ |
| 5520 | 5681 | ** |
| 5521 | -** ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt> | |
| 5682 | +** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt> | |
| 5522 | 5683 | ** <dd>This parameter records the largest memory allocation request |
| 5523 | 5684 | ** handed to [scratch memory allocator]. Only the value returned in the |
| 5524 | 5685 | ** *pHighwater parameter to [sqlite3_status()] is of interest. |
| 5525 | 5686 | ** The value written into the *pCurrent parameter is undefined.</dd>)^ |
| 5526 | 5687 | ** |
| 5527 | -** ^(<dt>SQLITE_STATUS_PARSER_STACK</dt> | |
| 5688 | +** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt> | |
| 5528 | 5689 | ** <dd>This parameter records the deepest parser stack. It is only |
| 5529 | 5690 | ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^ |
| 5530 | 5691 | ** </dl> |
| 5531 | 5692 | ** |
| 5532 | 5693 | ** New status parameters may be added from time to time. |
| @@ -5547,13 +5708,13 @@ | ||
| 5547 | 5708 | ** |
| 5548 | 5709 | ** ^This interface is used to retrieve runtime status information |
| 5549 | 5710 | ** about a single [database connection]. ^The first argument is the |
| 5550 | 5711 | ** database connection object to be interrogated. ^The second argument |
| 5551 | 5712 | ** is an integer constant, taken from the set of |
| 5552 | -** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros, that | |
| 5713 | +** [SQLITE_DBSTATUS options], that | |
| 5553 | 5714 | ** determines the parameter to interrogate. The set of |
| 5554 | -** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros is likely | |
| 5715 | +** [SQLITE_DBSTATUS options] is likely | |
| 5555 | 5716 | ** to grow in future releases of SQLite. |
| 5556 | 5717 | ** |
| 5557 | 5718 | ** ^The current value of the requested parameter is written into *pCur |
| 5558 | 5719 | ** and the highest instantaneous value is written into *pHiwtr. ^If |
| 5559 | 5720 | ** the resetFlg is true, then the highest instantaneous value is |
| @@ -5566,10 +5727,11 @@ | ||
| 5566 | 5727 | */ |
| 5567 | 5728 | SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); |
| 5568 | 5729 | |
| 5569 | 5730 | /* |
| 5570 | 5731 | ** CAPI3REF: Status Parameters for database connections |
| 5732 | +** KEYWORDS: {SQLITE_DBSTATUS options} | |
| 5571 | 5733 | ** |
| 5572 | 5734 | ** These constants are the available integer "verbs" that can be passed as |
| 5573 | 5735 | ** the second argument to the [sqlite3_db_status()] interface. |
| 5574 | 5736 | ** |
| 5575 | 5737 | ** New verbs may be added in future releases of SQLite. Existing verbs |
| @@ -5577,48 +5739,50 @@ | ||
| 5577 | 5739 | ** [sqlite3_db_status()] to make sure that the call worked. |
| 5578 | 5740 | ** The [sqlite3_db_status()] interface will return a non-zero error code |
| 5579 | 5741 | ** if a discontinued or unsupported verb is invoked. |
| 5580 | 5742 | ** |
| 5581 | 5743 | ** <dl> |
| 5582 | -** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt> | |
| 5744 | +** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt> | |
| 5583 | 5745 | ** <dd>This parameter returns the number of lookaside memory slots currently |
| 5584 | 5746 | ** checked out.</dd>)^ |
| 5585 | 5747 | ** |
| 5586 | -** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt> | |
| 5748 | +** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt> | |
| 5587 | 5749 | ** <dd>This parameter returns the number malloc attempts that were |
| 5588 | 5750 | ** satisfied using lookaside memory. Only the high-water value is meaningful; |
| 5589 | 5751 | ** the current value is always zero.)^ |
| 5590 | 5752 | ** |
| 5753 | +** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]] | |
| 5591 | 5754 | ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt> |
| 5592 | 5755 | ** <dd>This parameter returns the number malloc attempts that might have |
| 5593 | 5756 | ** been satisfied using lookaside memory but failed due to the amount of |
| 5594 | 5757 | ** memory requested being larger than the lookaside slot size. |
| 5595 | 5758 | ** Only the high-water value is meaningful; |
| 5596 | 5759 | ** the current value is always zero.)^ |
| 5597 | 5760 | ** |
| 5761 | +** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]] | |
| 5598 | 5762 | ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt> |
| 5599 | 5763 | ** <dd>This parameter returns the number malloc attempts that might have |
| 5600 | 5764 | ** been satisfied using lookaside memory but failed due to all lookaside |
| 5601 | 5765 | ** memory already being in use. |
| 5602 | 5766 | ** Only the high-water value is meaningful; |
| 5603 | 5767 | ** the current value is always zero.)^ |
| 5604 | 5768 | ** |
| 5605 | -** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt> | |
| 5769 | +** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt> | |
| 5606 | 5770 | ** <dd>This parameter returns the approximate number of of bytes of heap |
| 5607 | 5771 | ** memory used by all pager caches associated with the database connection.)^ |
| 5608 | 5772 | ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0. |
| 5609 | 5773 | ** |
| 5610 | -** ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt> | |
| 5774 | +** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt> | |
| 5611 | 5775 | ** <dd>This parameter returns the approximate number of of bytes of heap |
| 5612 | 5776 | ** memory used to store the schema for all databases associated |
| 5613 | 5777 | ** with the connection - main, temp, and any [ATTACH]-ed databases.)^ |
| 5614 | 5778 | ** ^The full amount of memory used by the schemas is reported, even if the |
| 5615 | 5779 | ** schema memory is shared with other database connections due to |
| 5616 | 5780 | ** [shared cache mode] being enabled. |
| 5617 | 5781 | ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0. |
| 5618 | 5782 | ** |
| 5619 | -** ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt> | |
| 5783 | +** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt> | |
| 5620 | 5784 | ** <dd>This parameter returns the approximate number of of bytes of heap |
| 5621 | 5785 | ** and lookaside memory used by all prepared statements associated with |
| 5622 | 5786 | ** the database connection.)^ |
| 5623 | 5787 | ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0. |
| 5624 | 5788 | ** </dd> |
| @@ -5636,11 +5800,11 @@ | ||
| 5636 | 5800 | |
| 5637 | 5801 | /* |
| 5638 | 5802 | ** CAPI3REF: Prepared Statement Status |
| 5639 | 5803 | ** |
| 5640 | 5804 | ** ^(Each prepared statement maintains various |
| 5641 | -** [SQLITE_STMTSTATUS_SORT | counters] that measure the number | |
| 5805 | +** [SQLITE_STMTSTATUS counters] that measure the number | |
| 5642 | 5806 | ** of times it has performed specific operations.)^ These counters can |
| 5643 | 5807 | ** be used to monitor the performance characteristics of the prepared |
| 5644 | 5808 | ** statements. For example, if the number of table steps greatly exceeds |
| 5645 | 5809 | ** the number of table searches or result rows, that would tend to indicate |
| 5646 | 5810 | ** that the prepared statement is using a full table scan rather than |
| @@ -5647,11 +5811,11 @@ | ||
| 5647 | 5811 | ** an index. |
| 5648 | 5812 | ** |
| 5649 | 5813 | ** ^(This interface is used to retrieve and reset counter values from |
| 5650 | 5814 | ** a [prepared statement]. The first argument is the prepared statement |
| 5651 | 5815 | ** object to be interrogated. The second argument |
| 5652 | -** is an integer code for a specific [SQLITE_STMTSTATUS_SORT | counter] | |
| 5816 | +** is an integer code for a specific [SQLITE_STMTSTATUS counter] | |
| 5653 | 5817 | ** to be interrogated.)^ |
| 5654 | 5818 | ** ^The current value of the requested counter is returned. |
| 5655 | 5819 | ** ^If the resetFlg is true, then the counter is reset to zero after this |
| 5656 | 5820 | ** interface call returns. |
| 5657 | 5821 | ** |
| @@ -5659,28 +5823,29 @@ | ||
| 5659 | 5823 | */ |
| 5660 | 5824 | SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); |
| 5661 | 5825 | |
| 5662 | 5826 | /* |
| 5663 | 5827 | ** CAPI3REF: Status Parameters for prepared statements |
| 5828 | +** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters} | |
| 5664 | 5829 | ** |
| 5665 | 5830 | ** These preprocessor macros define integer codes that name counter |
| 5666 | 5831 | ** values associated with the [sqlite3_stmt_status()] interface. |
| 5667 | 5832 | ** The meanings of the various counters are as follows: |
| 5668 | 5833 | ** |
| 5669 | 5834 | ** <dl> |
| 5670 | -** <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt> | |
| 5835 | +** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt> | |
| 5671 | 5836 | ** <dd>^This is the number of times that SQLite has stepped forward in |
| 5672 | 5837 | ** a table as part of a full table scan. Large numbers for this counter |
| 5673 | 5838 | ** may indicate opportunities for performance improvement through |
| 5674 | 5839 | ** careful use of indices.</dd> |
| 5675 | 5840 | ** |
| 5676 | -** <dt>SQLITE_STMTSTATUS_SORT</dt> | |
| 5841 | +** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt> | |
| 5677 | 5842 | ** <dd>^This is the number of sort operations that have occurred. |
| 5678 | 5843 | ** A non-zero value in this counter may indicate an opportunity to |
| 5679 | 5844 | ** improvement performance through careful use of indices.</dd> |
| 5680 | 5845 | ** |
| 5681 | -** <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt> | |
| 5846 | +** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt> | |
| 5682 | 5847 | ** <dd>^This is the number of rows inserted into transient indices that |
| 5683 | 5848 | ** were created automatically in order to help joins run faster. |
| 5684 | 5849 | ** A non-zero value in this counter may indicate an opportunity to |
| 5685 | 5850 | ** improvement performance by adding permanent indices that do not |
| 5686 | 5851 | ** need to be reinitialized each time the statement is run.</dd> |
| @@ -5727,10 +5892,11 @@ | ||
| 5727 | 5892 | ** ^(The contents of the sqlite3_pcache_methods structure are copied to an |
| 5728 | 5893 | ** internal buffer by SQLite within the call to [sqlite3_config]. Hence |
| 5729 | 5894 | ** the application may discard the parameter after the call to |
| 5730 | 5895 | ** [sqlite3_config()] returns.)^ |
| 5731 | 5896 | ** |
| 5897 | +** [[the xInit() page cache method]] | |
| 5732 | 5898 | ** ^(The xInit() method is called once for each effective |
| 5733 | 5899 | ** call to [sqlite3_initialize()])^ |
| 5734 | 5900 | ** (usually only once during the lifetime of the process). ^(The xInit() |
| 5735 | 5901 | ** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^ |
| 5736 | 5902 | ** The intent of the xInit() method is to set up global data structures |
| @@ -5737,10 +5903,11 @@ | ||
| 5737 | 5903 | ** required by the custom page cache implementation. |
| 5738 | 5904 | ** ^(If the xInit() method is NULL, then the |
| 5739 | 5905 | ** built-in default page cache is used instead of the application defined |
| 5740 | 5906 | ** page cache.)^ |
| 5741 | 5907 | ** |
| 5908 | +** [[the xShutdown() page cache method]] | |
| 5742 | 5909 | ** ^The xShutdown() method is called by [sqlite3_shutdown()]. |
| 5743 | 5910 | ** It can be used to clean up |
| 5744 | 5911 | ** any outstanding resources before process shutdown, if required. |
| 5745 | 5912 | ** ^The xShutdown() method may be NULL. |
| 5746 | 5913 | ** |
| @@ -5751,10 +5918,11 @@ | ||
| 5751 | 5918 | ** in multithreaded applications. |
| 5752 | 5919 | ** |
| 5753 | 5920 | ** ^SQLite will never invoke xInit() more than once without an intervening |
| 5754 | 5921 | ** call to xShutdown(). |
| 5755 | 5922 | ** |
| 5923 | +** [[the xCreate() page cache methods]] | |
| 5756 | 5924 | ** ^SQLite invokes the xCreate() method to construct a new cache instance. |
| 5757 | 5925 | ** SQLite will typically create one cache instance for each open database file, |
| 5758 | 5926 | ** though this is not guaranteed. ^The |
| 5759 | 5927 | ** first parameter, szPage, is the size in bytes of the pages that must |
| 5760 | 5928 | ** be allocated by the cache. ^szPage will not be a power of two. ^szPage |
| @@ -5775,20 +5943,23 @@ | ||
| 5775 | 5943 | ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to |
| 5776 | 5944 | ** false will always have the "discard" flag set to true. |
| 5777 | 5945 | ** ^Hence, a cache created with bPurgeable false will |
| 5778 | 5946 | ** never contain any unpinned pages. |
| 5779 | 5947 | ** |
| 5948 | +** [[the xCachesize() page cache method]] | |
| 5780 | 5949 | ** ^(The xCachesize() method may be called at any time by SQLite to set the |
| 5781 | 5950 | ** suggested maximum cache-size (number of pages stored by) the cache |
| 5782 | 5951 | ** instance passed as the first argument. This is the value configured using |
| 5783 | 5952 | ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable |
| 5784 | 5953 | ** parameter, the implementation is not required to do anything with this |
| 5785 | 5954 | ** value; it is advisory only. |
| 5786 | 5955 | ** |
| 5956 | +** [[the xPagecount() page cache methods]] | |
| 5787 | 5957 | ** The xPagecount() method must return the number of pages currently |
| 5788 | 5958 | ** stored in the cache, both pinned and unpinned. |
| 5789 | 5959 | ** |
| 5960 | +** [[the xFetch() page cache methods]] | |
| 5790 | 5961 | ** The xFetch() method locates a page in the cache and returns a pointer to |
| 5791 | 5962 | ** the page, or a NULL pointer. |
| 5792 | 5963 | ** A "page", in this context, means a buffer of szPage bytes aligned at an |
| 5793 | 5964 | ** 8-byte boundary. The page to be fetched is determined by the key. ^The |
| 5794 | 5965 | ** mimimum key value is 1. After it has been retrieved using xFetch, the page |
| @@ -5813,10 +5984,11 @@ | ||
| 5813 | 5984 | ** will only use a createFlag of 2 after a prior call with a createFlag of 1 |
| 5814 | 5985 | ** failed.)^ In between the to xFetch() calls, SQLite may |
| 5815 | 5986 | ** attempt to unpin one or more cache pages by spilling the content of |
| 5816 | 5987 | ** pinned pages to disk and synching the operating system disk cache. |
| 5817 | 5988 | ** |
| 5989 | +** [[the xUnpin() page cache method]] | |
| 5818 | 5990 | ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page |
| 5819 | 5991 | ** as its second argument. If the third parameter, discard, is non-zero, |
| 5820 | 5992 | ** then the page must be evicted from the cache. |
| 5821 | 5993 | ** ^If the discard parameter is |
| 5822 | 5994 | ** zero, then the page may be discarded or retained at the discretion of |
| @@ -5825,10 +5997,11 @@ | ||
| 5825 | 5997 | ** |
| 5826 | 5998 | ** The cache must not perform any reference counting. A single |
| 5827 | 5999 | ** call to xUnpin() unpins the page regardless of the number of prior calls |
| 5828 | 6000 | ** to xFetch(). |
| 5829 | 6001 | ** |
| 6002 | +** [[the xRekey() page cache methods]] | |
| 5830 | 6003 | ** The xRekey() method is used to change the key value associated with the |
| 5831 | 6004 | ** page passed as the second argument. If the cache |
| 5832 | 6005 | ** previously contains an entry associated with newKey, it must be |
| 5833 | 6006 | ** discarded. ^Any prior cache entry associated with newKey is guaranteed not |
| 5834 | 6007 | ** to be pinned. |
| @@ -5837,10 +6010,11 @@ | ||
| 5837 | 6010 | ** existing cache entries with page numbers (keys) greater than or equal |
| 5838 | 6011 | ** to the value of the iLimit parameter passed to xTruncate(). If any |
| 5839 | 6012 | ** of these pages are pinned, they are implicitly unpinned, meaning that |
| 5840 | 6013 | ** they can be safely discarded. |
| 5841 | 6014 | ** |
| 6015 | +** [[the xDestroy() page cache method]] | |
| 5842 | 6016 | ** ^The xDestroy() method is used to delete a cache allocated by xCreate(). |
| 5843 | 6017 | ** All resources associated with the specified cache should be freed. ^After |
| 5844 | 6018 | ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*] |
| 5845 | 6019 | ** handle invalid, and will not use it with any other sqlite3_pcache_methods |
| 5846 | 6020 | ** functions. |
| @@ -5899,11 +6073,11 @@ | ||
| 5899 | 6073 | ** associated with the backup operation. |
| 5900 | 6074 | ** </ol>)^ |
| 5901 | 6075 | ** There should be exactly one call to sqlite3_backup_finish() for each |
| 5902 | 6076 | ** successful call to sqlite3_backup_init(). |
| 5903 | 6077 | ** |
| 5904 | -** <b>sqlite3_backup_init()</b> | |
| 6078 | +** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b> | |
| 5905 | 6079 | ** |
| 5906 | 6080 | ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the |
| 5907 | 6081 | ** [database connection] associated with the destination database |
| 5908 | 6082 | ** and the database name, respectively. |
| 5909 | 6083 | ** ^The database name is "main" for the main database, "temp" for the |
| @@ -5926,11 +6100,11 @@ | ||
| 5926 | 6100 | ** [sqlite3_backup] object. |
| 5927 | 6101 | ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and |
| 5928 | 6102 | ** sqlite3_backup_finish() functions to perform the specified backup |
| 5929 | 6103 | ** operation. |
| 5930 | 6104 | ** |
| 5931 | -** <b>sqlite3_backup_step()</b> | |
| 6105 | +** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b> | |
| 5932 | 6106 | ** |
| 5933 | 6107 | ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between |
| 5934 | 6108 | ** the source and destination databases specified by [sqlite3_backup] object B. |
| 5935 | 6109 | ** ^If N is negative, all remaining source pages are copied. |
| 5936 | 6110 | ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there |
| @@ -5983,11 +6157,11 @@ | ||
| 5983 | 6157 | ** restarted by the next call to sqlite3_backup_step(). ^If the source |
| 5984 | 6158 | ** database is modified by the using the same database connection as is used |
| 5985 | 6159 | ** by the backup operation, then the backup database is automatically |
| 5986 | 6160 | ** updated at the same time. |
| 5987 | 6161 | ** |
| 5988 | -** <b>sqlite3_backup_finish()</b> | |
| 6162 | +** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b> | |
| 5989 | 6163 | ** |
| 5990 | 6164 | ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the |
| 5991 | 6165 | ** application wishes to abandon the backup operation, the application |
| 5992 | 6166 | ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish(). |
| 5993 | 6167 | ** ^The sqlite3_backup_finish() interfaces releases all |
| @@ -6006,11 +6180,12 @@ | ||
| 6006 | 6180 | ** |
| 6007 | 6181 | ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step() |
| 6008 | 6182 | ** is not a permanent error and does not affect the return value of |
| 6009 | 6183 | ** sqlite3_backup_finish(). |
| 6010 | 6184 | ** |
| 6011 | -** <b>sqlite3_backup_remaining(), sqlite3_backup_pagecount()</b> | |
| 6185 | +** [[sqlite3_backup__remaining()]] [[sqlite3_backup_pagecount()]] | |
| 6186 | +** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b> | |
| 6012 | 6187 | ** |
| 6013 | 6188 | ** ^Each call to sqlite3_backup_step() sets two values inside |
| 6014 | 6189 | ** the [sqlite3_backup] object: the number of pages still to be backed |
| 6015 | 6190 | ** up and the total number of pages in the source database file. |
| 6016 | 6191 | ** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces |
| @@ -6391,10 +6566,97 @@ | ||
| 6391 | 6566 | ** each of these values. |
| 6392 | 6567 | */ |
| 6393 | 6568 | #define SQLITE_CHECKPOINT_PASSIVE 0 |
| 6394 | 6569 | #define SQLITE_CHECKPOINT_FULL 1 |
| 6395 | 6570 | #define SQLITE_CHECKPOINT_RESTART 2 |
| 6571 | + | |
| 6572 | +/* | |
| 6573 | +** CAPI3REF: Virtual Table Interface Configuration | |
| 6574 | +** | |
| 6575 | +** This function may be called by either the [xConnect] or [xCreate] method | |
| 6576 | +** of a [virtual table] implementation to configure | |
| 6577 | +** various facets of the virtual table interface. | |
| 6578 | +** | |
| 6579 | +** If this interface is invoked outside the context of an xConnect or | |
| 6580 | +** xCreate virtual table method then the behavior is undefined. | |
| 6581 | +** | |
| 6582 | +** At present, there is only one option that may be configured using | |
| 6583 | +** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].) Further options | |
| 6584 | +** may be added in the future. | |
| 6585 | +*/ | |
| 6586 | +SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...); | |
| 6587 | + | |
| 6588 | +/* | |
| 6589 | +** CAPI3REF: Virtual Table Configuration Options | |
| 6590 | +** | |
| 6591 | +** These macros define the various options to the | |
| 6592 | +** [sqlite3_vtab_config()] interface that [virtual table] implementations | |
| 6593 | +** can use to customize and optimize their behavior. | |
| 6594 | +** | |
| 6595 | +** <dl> | |
| 6596 | +** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT | |
| 6597 | +** <dd>Calls of the form | |
| 6598 | +** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported, | |
| 6599 | +** where X is an integer. If X is zero, then the [virtual table] whose | |
| 6600 | +** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not | |
| 6601 | +** support constraints. In this configuration (which is the default) if | |
| 6602 | +** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire | |
| 6603 | +** statement is rolled back as if [ON CONFLICT | OR ABORT] had been | |
| 6604 | +** specified as part of the users SQL statement, regardless of the actual | |
| 6605 | +** ON CONFLICT mode specified. | |
| 6606 | +** | |
| 6607 | +** If X is non-zero, then the virtual table implementation guarantees | |
| 6608 | +** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before | |
| 6609 | +** any modifications to internal or persistent data structures have been made. | |
| 6610 | +** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite | |
| 6611 | +** is able to roll back a statement or database transaction, and abandon | |
| 6612 | +** or continue processing the current SQL statement as appropriate. | |
| 6613 | +** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns | |
| 6614 | +** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode | |
| 6615 | +** had been ABORT. | |
| 6616 | +** | |
| 6617 | +** Virtual table implementations that are required to handle OR REPLACE | |
| 6618 | +** must do so within the [xUpdate] method. If a call to the | |
| 6619 | +** [sqlite3_vtab_on_conflict()] function indicates that the current ON | |
| 6620 | +** CONFLICT policy is REPLACE, the virtual table implementation should | |
| 6621 | +** silently replace the appropriate rows within the xUpdate callback and | |
| 6622 | +** return SQLITE_OK. Or, if this is not possible, it may return | |
| 6623 | +** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT | |
| 6624 | +** constraint handling. | |
| 6625 | +** </dl> | |
| 6626 | +*/ | |
| 6627 | +#define SQLITE_VTAB_CONSTRAINT_SUPPORT 1 | |
| 6628 | + | |
| 6629 | +/* | |
| 6630 | +** CAPI3REF: Determine The Virtual Table Conflict Policy | |
| 6631 | +** | |
| 6632 | +** This function may only be called from within a call to the [xUpdate] method | |
| 6633 | +** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The | |
| 6634 | +** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL], | |
| 6635 | +** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode | |
| 6636 | +** of the SQL statement that triggered the call to the [xUpdate] method of the | |
| 6637 | +** [virtual table]. | |
| 6638 | +*/ | |
| 6639 | +SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *); | |
| 6640 | + | |
| 6641 | +/* | |
| 6642 | +** CAPI3REF: Conflict resolution modes | |
| 6643 | +** | |
| 6644 | +** These constants are returned by [sqlite3_vtab_on_conflict()] to | |
| 6645 | +** inform a [virtual table] implementation what the [ON CONFLICT] mode | |
| 6646 | +** is for the SQL statement being evaluated. | |
| 6647 | +** | |
| 6648 | +** Note that the [SQLITE_IGNORE] constant is also used as a potential | |
| 6649 | +** return value from the [sqlite3_set_authorizer()] callback and that | |
| 6650 | +** [SQLITE_ABORT] is also a [result code]. | |
| 6651 | +*/ | |
| 6652 | +#define SQLITE_ROLLBACK 1 | |
| 6653 | +/* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */ | |
| 6654 | +#define SQLITE_FAIL 3 | |
| 6655 | +/* #define SQLITE_ABORT 4 // Also an error code */ | |
| 6656 | +#define SQLITE_REPLACE 5 | |
| 6657 | + | |
| 6396 | 6658 | |
| 6397 | 6659 | |
| 6398 | 6660 | /* |
| 6399 | 6661 | ** Undo the hack that converts floating point types to integer for |
| 6400 | 6662 | ** builds on processors without floating point support. |
| 6401 | 6663 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -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.7.6.1" |
| 111 | #define SQLITE_VERSION_NUMBER 3007006 |
| 112 | #define SQLITE_SOURCE_ID "2011-04-27 19:54:44 f55156c5194e85c47728b8a97fde3e5f0a5c9b56" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -373,11 +373,12 @@ | |
| 373 | ** Many SQLite functions return an integer result code from the set shown |
| 374 | ** here in order to indicates success or failure. |
| 375 | ** |
| 376 | ** New error codes may be added in future versions of SQLite. |
| 377 | ** |
| 378 | ** See also: [SQLITE_IOERR_READ | extended result codes] |
| 379 | */ |
| 380 | #define SQLITE_OK 0 /* Successful result */ |
| 381 | /* beginning-of-error-codes */ |
| 382 | #define SQLITE_ERROR 1 /* SQL error or missing database */ |
| 383 | #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ |
| @@ -455,25 +456,26 @@ | |
| 455 | #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) |
| 456 | #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) |
| 457 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 458 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 459 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 460 | |
| 461 | /* |
| 462 | ** CAPI3REF: Flags For File Open Operations |
| 463 | ** |
| 464 | ** These bit values are intended for use in the |
| 465 | ** 3rd parameter to the [sqlite3_open_v2()] interface and |
| 466 | ** in the 4th parameter to the xOpen method of the |
| 467 | ** [sqlite3_vfs] object. |
| 468 | */ |
| 469 | #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ |
| 470 | #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ |
| 471 | #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ |
| 472 | #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ |
| 473 | #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ |
| 474 | #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ |
| 475 | #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ |
| 476 | #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ |
| 477 | #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ |
| 478 | #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ |
| 479 | #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ |
| @@ -580,21 +582,22 @@ | |
| 580 | }; |
| 581 | |
| 582 | /* |
| 583 | ** CAPI3REF: OS Interface File Virtual Methods Object |
| 584 | ** |
| 585 | ** Every file opened by the [sqlite3_vfs] xOpen method populates an |
| 586 | ** [sqlite3_file] object (or, more commonly, a subclass of the |
| 587 | ** [sqlite3_file] object) with a pointer to an instance of this object. |
| 588 | ** This object defines the methods used to perform various operations |
| 589 | ** against the open file represented by the [sqlite3_file] object. |
| 590 | ** |
| 591 | ** If the xOpen method sets the sqlite3_file.pMethods element |
| 592 | ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method |
| 593 | ** may be invoked even if the xOpen reported that it failed. The |
| 594 | ** only way to prevent a call to xClose following a failed xOpen |
| 595 | ** is for the xOpen to set the sqlite3_file.pMethods element to NULL. |
| 596 | ** |
| 597 | ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or |
| 598 | ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync(). |
| 599 | ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY] |
| 600 | ** flag may be ORed in to indicate that only the data of the file |
| @@ -759,10 +762,11 @@ | |
| 759 | */ |
| 760 | typedef struct sqlite3_mutex sqlite3_mutex; |
| 761 | |
| 762 | /* |
| 763 | ** CAPI3REF: OS Interface Object |
| 764 | ** |
| 765 | ** An instance of the sqlite3_vfs object defines the interface between |
| 766 | ** the SQLite core and the underlying operating system. The "vfs" |
| 767 | ** in the name of the object stands for "virtual file system". |
| 768 | ** |
| @@ -791,10 +795,11 @@ | |
| 791 | ** object once the object has been registered. |
| 792 | ** |
| 793 | ** The zName field holds the name of the VFS module. The name must |
| 794 | ** be unique across all VFS modules. |
| 795 | ** |
| 796 | ** ^SQLite guarantees that the zFilename parameter to xOpen |
| 797 | ** is either a NULL pointer or string obtained |
| 798 | ** from xFullPathname() with an optional suffix added. |
| 799 | ** ^If a suffix is added to the zFilename parameter, it will |
| 800 | ** consist of a single "-" character followed by no more than |
| @@ -868,10 +873,11 @@ | |
| 868 | ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do |
| 869 | ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods |
| 870 | ** element will be valid after xOpen returns regardless of the success |
| 871 | ** or failure of the xOpen call. |
| 872 | ** |
| 873 | ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] |
| 874 | ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to |
| 875 | ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ] |
| 876 | ** to test whether a file is at least readable. The file can be a |
| 877 | ** directory. |
| @@ -1114,13 +1120,13 @@ | |
| 1114 | ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE. |
| 1115 | ** Note, however, that ^sqlite3_config() can be called as part of the |
| 1116 | ** implementation of an application-defined [sqlite3_os_init()]. |
| 1117 | ** |
| 1118 | ** The first argument to sqlite3_config() is an integer |
| 1119 | ** [SQLITE_CONFIG_SINGLETHREAD | configuration option] that determines |
| 1120 | ** what property of SQLite is to be configured. Subsequent arguments |
| 1121 | ** vary depending on the [SQLITE_CONFIG_SINGLETHREAD | configuration option] |
| 1122 | ** in the first argument. |
| 1123 | ** |
| 1124 | ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. |
| 1125 | ** ^If the option is unknown or SQLite is unable to set the option |
| 1126 | ** then this routine returns a non-zero [error code]. |
| @@ -1226,10 +1232,11 @@ | |
| 1226 | void *pAppData; /* Argument to xInit() and xShutdown() */ |
| 1227 | }; |
| 1228 | |
| 1229 | /* |
| 1230 | ** CAPI3REF: Configuration Options |
| 1231 | ** |
| 1232 | ** These constants are the available integer configuration options that |
| 1233 | ** can be passed as the first argument to the [sqlite3_config()] interface. |
| 1234 | ** |
| 1235 | ** New configuration options may be added in future releases of SQLite. |
| @@ -1238,11 +1245,11 @@ | |
| 1238 | ** the call worked. The [sqlite3_config()] interface will return a |
| 1239 | ** non-zero [error code] if a discontinued or unsupported configuration option |
| 1240 | ** is invoked. |
| 1241 | ** |
| 1242 | ** <dl> |
| 1243 | ** <dt>SQLITE_CONFIG_SINGLETHREAD</dt> |
| 1244 | ** <dd>There are no arguments to this option. ^This option sets the |
| 1245 | ** [threading mode] to Single-thread. In other words, it disables |
| 1246 | ** all mutexing and puts SQLite into a mode where it can only be used |
| 1247 | ** by a single thread. ^If SQLite is compiled with |
| 1248 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| @@ -1249,11 +1256,11 @@ | |
| 1249 | ** it is not possible to change the [threading mode] from its default |
| 1250 | ** value of Single-thread and so [sqlite3_config()] will return |
| 1251 | ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD |
| 1252 | ** configuration option.</dd> |
| 1253 | ** |
| 1254 | ** <dt>SQLITE_CONFIG_MULTITHREAD</dt> |
| 1255 | ** <dd>There are no arguments to this option. ^This option sets the |
| 1256 | ** [threading mode] to Multi-thread. In other words, it disables |
| 1257 | ** mutexing on [database connection] and [prepared statement] objects. |
| 1258 | ** The application is responsible for serializing access to |
| 1259 | ** [database connections] and [prepared statements]. But other mutexes |
| @@ -1263,11 +1270,11 @@ | |
| 1263 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1264 | ** it is not possible to set the Multi-thread [threading mode] and |
| 1265 | ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
| 1266 | ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd> |
| 1267 | ** |
| 1268 | ** <dt>SQLITE_CONFIG_SERIALIZED</dt> |
| 1269 | ** <dd>There are no arguments to this option. ^This option sets the |
| 1270 | ** [threading mode] to Serialized. In other words, this option enables |
| 1271 | ** all mutexes including the recursive |
| 1272 | ** mutexes on [database connection] and [prepared statement] objects. |
| 1273 | ** In this mode (which is the default when SQLite is compiled with |
| @@ -1279,27 +1286,27 @@ | |
| 1279 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1280 | ** it is not possible to set the Serialized [threading mode] and |
| 1281 | ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
| 1282 | ** SQLITE_CONFIG_SERIALIZED configuration option.</dd> |
| 1283 | ** |
| 1284 | ** <dt>SQLITE_CONFIG_MALLOC</dt> |
| 1285 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1286 | ** instance of the [sqlite3_mem_methods] structure. The argument specifies |
| 1287 | ** alternative low-level memory allocation routines to be used in place of |
| 1288 | ** the memory allocation routines built into SQLite.)^ ^SQLite makes |
| 1289 | ** its own private copy of the content of the [sqlite3_mem_methods] structure |
| 1290 | ** before the [sqlite3_config()] call returns.</dd> |
| 1291 | ** |
| 1292 | ** <dt>SQLITE_CONFIG_GETMALLOC</dt> |
| 1293 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1294 | ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods] |
| 1295 | ** structure is filled with the currently defined memory allocation routines.)^ |
| 1296 | ** This option can be used to overload the default memory allocation |
| 1297 | ** routines with a wrapper that simulations memory allocation failure or |
| 1298 | ** tracks memory usage, for example. </dd> |
| 1299 | ** |
| 1300 | ** <dt>SQLITE_CONFIG_MEMSTATUS</dt> |
| 1301 | ** <dd> ^This option takes single argument of type int, interpreted as a |
| 1302 | ** boolean, which enables or disables the collection of memory allocation |
| 1303 | ** statistics. ^(When memory allocation statistics are disabled, the |
| 1304 | ** following SQLite interfaces become non-operational: |
| 1305 | ** <ul> |
| @@ -1311,11 +1318,11 @@ | |
| 1311 | ** ^Memory allocation statistics are enabled by default unless SQLite is |
| 1312 | ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory |
| 1313 | ** allocation statistics are disabled by default. |
| 1314 | ** </dd> |
| 1315 | ** |
| 1316 | ** <dt>SQLITE_CONFIG_SCRATCH</dt> |
| 1317 | ** <dd> ^This option specifies a static memory buffer that SQLite can use for |
| 1318 | ** scratch memory. There are three arguments: A pointer an 8-byte |
| 1319 | ** aligned memory buffer from which the scratch allocations will be |
| 1320 | ** drawn, the size of each scratch allocation (sz), |
| 1321 | ** and the maximum number of scratch allocations (N). The sz |
| @@ -1327,11 +1334,11 @@ | |
| 1327 | ** ^SQLite will never require a scratch buffer that is more than 6 |
| 1328 | ** times the database page size. ^If SQLite needs needs additional |
| 1329 | ** scratch memory beyond what is provided by this configuration option, then |
| 1330 | ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd> |
| 1331 | ** |
| 1332 | ** <dt>SQLITE_CONFIG_PAGECACHE</dt> |
| 1333 | ** <dd> ^This option specifies a static memory buffer that SQLite can use for |
| 1334 | ** the database page cache with the default page cache implemenation. |
| 1335 | ** This configuration should not be used if an application-define page |
| 1336 | ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option. |
| 1337 | ** There are three arguments to this option: A pointer to 8-byte aligned |
| @@ -1348,11 +1355,11 @@ | |
| 1348 | ** SQLite goes to [sqlite3_malloc()] for the additional storage space. |
| 1349 | ** The pointer in the first argument must |
| 1350 | ** be aligned to an 8-byte boundary or subsequent behavior of SQLite |
| 1351 | ** will be undefined.</dd> |
| 1352 | ** |
| 1353 | ** <dt>SQLITE_CONFIG_HEAP</dt> |
| 1354 | ** <dd> ^This option specifies a static memory buffer that SQLite will use |
| 1355 | ** for all of its dynamic memory allocation needs beyond those provided |
| 1356 | ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. |
| 1357 | ** There are three arguments: An 8-byte aligned pointer to the memory, |
| 1358 | ** the number of bytes in the memory buffer, and the minimum allocation size. |
| @@ -1365,11 +1372,11 @@ | |
| 1365 | ** The first pointer (the memory pointer) must be aligned to an 8-byte |
| 1366 | ** boundary or subsequent behavior of SQLite will be undefined. |
| 1367 | ** The minimum allocation size is capped at 2^12. Reasonable values |
| 1368 | ** for the minimum allocation size are 2^5 through 2^8.</dd> |
| 1369 | ** |
| 1370 | ** <dt>SQLITE_CONFIG_MUTEX</dt> |
| 1371 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1372 | ** instance of the [sqlite3_mutex_methods] structure. The argument specifies |
| 1373 | ** alternative low-level mutex routines to be used in place |
| 1374 | ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the |
| 1375 | ** content of the [sqlite3_mutex_methods] structure before the call to |
| @@ -1377,11 +1384,11 @@ | |
| 1377 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1378 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1379 | ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will |
| 1380 | ** return [SQLITE_ERROR].</dd> |
| 1381 | ** |
| 1382 | ** <dt>SQLITE_CONFIG_GETMUTEX</dt> |
| 1383 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1384 | ** instance of the [sqlite3_mutex_methods] structure. The |
| 1385 | ** [sqlite3_mutex_methods] |
| 1386 | ** structure is filled with the currently defined mutex routines.)^ |
| 1387 | ** This option can be used to overload the default mutex allocation |
| @@ -1390,32 +1397,32 @@ | |
| 1390 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1391 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1392 | ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will |
| 1393 | ** return [SQLITE_ERROR].</dd> |
| 1394 | ** |
| 1395 | ** <dt>SQLITE_CONFIG_LOOKASIDE</dt> |
| 1396 | ** <dd> ^(This option takes two arguments that determine the default |
| 1397 | ** memory allocation for the lookaside memory allocator on each |
| 1398 | ** [database connection]. The first argument is the |
| 1399 | ** size of each lookaside buffer slot and the second is the number of |
| 1400 | ** slots allocated to each database connection.)^ ^(This option sets the |
| 1401 | ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] |
| 1402 | ** verb to [sqlite3_db_config()] can be used to change the lookaside |
| 1403 | ** configuration on individual connections.)^ </dd> |
| 1404 | ** |
| 1405 | ** <dt>SQLITE_CONFIG_PCACHE</dt> |
| 1406 | ** <dd> ^(This option takes a single argument which is a pointer to |
| 1407 | ** an [sqlite3_pcache_methods] object. This object specifies the interface |
| 1408 | ** to a custom page cache implementation.)^ ^SQLite makes a copy of the |
| 1409 | ** object and uses it for page cache memory allocations.</dd> |
| 1410 | ** |
| 1411 | ** <dt>SQLITE_CONFIG_GETPCACHE</dt> |
| 1412 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1413 | ** [sqlite3_pcache_methods] object. SQLite copies of the current |
| 1414 | ** page cache implementation into that object.)^ </dd> |
| 1415 | ** |
| 1416 | ** <dt>SQLITE_CONFIG_LOG</dt> |
| 1417 | ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a |
| 1418 | ** function with a call signature of void(*)(void*,int,const char*), |
| 1419 | ** and a pointer to void. ^If the function pointer is not NULL, it is |
| 1420 | ** invoked by [sqlite3_log()] to process each logging event. ^If the |
| 1421 | ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op. |
| @@ -1429,10 +1436,22 @@ | |
| 1429 | ** The SQLite logging interface is not reentrant; the logger function |
| 1430 | ** supplied by the application must not invoke any SQLite interface. |
| 1431 | ** In a multi-threaded application, the application-defined logger |
| 1432 | ** function must be threadsafe. </dd> |
| 1433 | ** |
| 1434 | ** </dl> |
| 1435 | */ |
| 1436 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1437 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 1438 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| @@ -1447,10 +1466,11 @@ | |
| 1447 | /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ |
| 1448 | #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ |
| 1449 | #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */ |
| 1450 | #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */ |
| 1451 | #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ |
| 1452 | |
| 1453 | /* |
| 1454 | ** CAPI3REF: Database Connection Configuration Options |
| 1455 | ** |
| 1456 | ** These constants are the available integer configuration options that |
| @@ -1532,17 +1552,21 @@ | |
| 1532 | ** the table has a column of type [INTEGER PRIMARY KEY] then that column |
| 1533 | ** is another alias for the rowid. |
| 1534 | ** |
| 1535 | ** ^This routine returns the [rowid] of the most recent |
| 1536 | ** successful [INSERT] into the database from the [database connection] |
| 1537 | ** in the first argument. ^If no successful [INSERT]s |
| 1538 | ** have ever occurred on that database connection, zero is returned. |
| 1539 | ** |
| 1540 | ** ^(If an [INSERT] occurs within a trigger, then the [rowid] of the inserted |
| 1541 | ** row is returned by this routine as long as the trigger is running. |
| 1542 | ** But once the trigger terminates, the value returned by this routine |
| 1543 | ** reverts to the last value inserted before the trigger fired.)^ |
| 1544 | ** |
| 1545 | ** ^An [INSERT] that fails due to a constraint violation is not a |
| 1546 | ** successful [INSERT] and does not change the value returned by this |
| 1547 | ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK, |
| 1548 | ** and INSERT OR ABORT make no changes to the return value of this |
| @@ -2201,10 +2225,13 @@ | |
| 2201 | ** The [sqlite3_set_authorizer | authorizer callback function] must |
| 2202 | ** return either [SQLITE_OK] or one of these two constants in order |
| 2203 | ** to signal SQLite whether or not the action is permitted. See the |
| 2204 | ** [sqlite3_set_authorizer | authorizer documentation] for additional |
| 2205 | ** information. |
| 2206 | */ |
| 2207 | #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ |
| 2208 | #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ |
| 2209 | |
| 2210 | /* |
| @@ -2323,11 +2350,11 @@ | |
| 2323 | SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); |
| 2324 | |
| 2325 | /* |
| 2326 | ** CAPI3REF: Opening A New Database Connection |
| 2327 | ** |
| 2328 | ** ^These routines open an SQLite database file whose name is given by the |
| 2329 | ** filename argument. ^The filename argument is interpreted as UTF-8 for |
| 2330 | ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte |
| 2331 | ** order for sqlite3_open16(). ^(A [database connection] handle is usually |
| 2332 | ** returned in *ppDb, even if an error occurs. The only exception is that |
| 2333 | ** if SQLite is unable to allocate memory to hold the [sqlite3] object, |
| @@ -2350,11 +2377,11 @@ | |
| 2350 | ** except that it accepts two additional parameters for additional control |
| 2351 | ** over the new database connection. ^(The flags parameter to |
| 2352 | ** sqlite3_open_v2() can take one of |
| 2353 | ** the following three values, optionally combined with the |
| 2354 | ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE], |
| 2355 | ** and/or [SQLITE_OPEN_PRIVATECACHE] flags:)^ |
| 2356 | ** |
| 2357 | ** <dl> |
| 2358 | ** ^(<dt>[SQLITE_OPEN_READONLY]</dt> |
| 2359 | ** <dd>The database is opened in read-only mode. If the database does not |
| 2360 | ** already exist, an error is returned.</dd>)^ |
| @@ -2369,13 +2396,12 @@ | |
| 2369 | ** it does not already exist. This is the behavior that is always used for |
| 2370 | ** sqlite3_open() and sqlite3_open16().</dd>)^ |
| 2371 | ** </dl> |
| 2372 | ** |
| 2373 | ** If the 3rd parameter to sqlite3_open_v2() is not one of the |
| 2374 | ** combinations shown above or one of the combinations shown above combined |
| 2375 | ** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], |
| 2376 | ** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_PRIVATECACHE] flags, |
| 2377 | ** then the behavior is undefined. |
| 2378 | ** |
| 2379 | ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection |
| 2380 | ** opens in the multi-thread [threading mode] as long as the single-thread |
| 2381 | ** mode has not been set at compile-time or start-time. ^If the |
| @@ -2385,10 +2411,15 @@ | |
| 2385 | ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be |
| 2386 | ** eligible to use [shared cache mode], regardless of whether or not shared |
| 2387 | ** cache is enabled using [sqlite3_enable_shared_cache()]. ^The |
| 2388 | ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not |
| 2389 | ** participate in [shared cache mode] even if it is enabled. |
| 2390 | ** |
| 2391 | ** ^If the filename is ":memory:", then a private, temporary in-memory database |
| 2392 | ** is created for the connection. ^This in-memory database will vanish when |
| 2393 | ** the database connection is closed. Future versions of SQLite might |
| 2394 | ** make use of additional special filenames that begin with the ":" character. |
| @@ -2398,14 +2429,115 @@ | |
| 2398 | ** |
| 2399 | ** ^If the filename is an empty string, then a private, temporary |
| 2400 | ** on-disk database will be created. ^This private database will be |
| 2401 | ** automatically deleted as soon as the database connection is closed. |
| 2402 | ** |
| 2403 | ** ^The fourth parameter to sqlite3_open_v2() is the name of the |
| 2404 | ** [sqlite3_vfs] object that defines the operating system interface that |
| 2405 | ** the new database connection should use. ^If the fourth parameter is |
| 2406 | ** a NULL pointer then the default [sqlite3_vfs] object is used. |
| 2407 | ** |
| 2408 | ** <b>Note to Windows users:</b> The encoding used for the filename argument |
| 2409 | ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever |
| 2410 | ** codepage is currently defined. Filenames containing international |
| 2411 | ** characters must be converted to UTF-8 prior to passing them into |
| @@ -2423,10 +2555,30 @@ | |
| 2423 | const char *filename, /* Database filename (UTF-8) */ |
| 2424 | sqlite3 **ppDb, /* OUT: SQLite db handle */ |
| 2425 | int flags, /* Flags */ |
| 2426 | const char *zVfs /* Name of VFS module to use */ |
| 2427 | ); |
| 2428 | |
| 2429 | /* |
| 2430 | ** CAPI3REF: Error Codes And Messages |
| 2431 | ** |
| 2432 | ** ^The sqlite3_errcode() interface returns the numeric [result code] or |
| @@ -2539,47 +2691,49 @@ | |
| 2539 | ** that can be lowered at run-time using [sqlite3_limit()]. |
| 2540 | ** The synopsis of the meanings of the various limits is shown below. |
| 2541 | ** Additional information is available at [limits | Limits in SQLite]. |
| 2542 | ** |
| 2543 | ** <dl> |
| 2544 | ** ^(<dt>SQLITE_LIMIT_LENGTH</dt> |
| 2545 | ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^ |
| 2546 | ** |
| 2547 | ** ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt> |
| 2548 | ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^ |
| 2549 | ** |
| 2550 | ** ^(<dt>SQLITE_LIMIT_COLUMN</dt> |
| 2551 | ** <dd>The maximum number of columns in a table definition or in the |
| 2552 | ** result set of a [SELECT] or the maximum number of columns in an index |
| 2553 | ** or in an ORDER BY or GROUP BY clause.</dd>)^ |
| 2554 | ** |
| 2555 | ** ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> |
| 2556 | ** <dd>The maximum depth of the parse tree on any expression.</dd>)^ |
| 2557 | ** |
| 2558 | ** ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt> |
| 2559 | ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^ |
| 2560 | ** |
| 2561 | ** ^(<dt>SQLITE_LIMIT_VDBE_OP</dt> |
| 2562 | ** <dd>The maximum number of instructions in a virtual machine program |
| 2563 | ** used to implement an SQL statement. This limit is not currently |
| 2564 | ** enforced, though that might be added in some future release of |
| 2565 | ** SQLite.</dd>)^ |
| 2566 | ** |
| 2567 | ** ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt> |
| 2568 | ** <dd>The maximum number of arguments on a function.</dd>)^ |
| 2569 | ** |
| 2570 | ** ^(<dt>SQLITE_LIMIT_ATTACHED</dt> |
| 2571 | ** <dd>The maximum number of [ATTACH | attached databases].)^</dd> |
| 2572 | ** |
| 2573 | ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt> |
| 2574 | ** <dd>The maximum length of the pattern argument to the [LIKE] or |
| 2575 | ** [GLOB] operators.</dd>)^ |
| 2576 | ** |
| 2577 | ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> |
| 2578 | ** <dd>The maximum index number of any [parameter] in an SQL statement.)^ |
| 2579 | ** |
| 2580 | ** ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> |
| 2581 | ** <dd>The maximum depth of recursion for triggers.</dd>)^ |
| 2582 | ** </dl> |
| 2583 | */ |
| 2584 | #define SQLITE_LIMIT_LENGTH 0 |
| 2585 | #define SQLITE_LIMIT_SQL_LENGTH 1 |
| @@ -4610,10 +4764,15 @@ | |
| 4610 | int (*xRollback)(sqlite3_vtab *pVTab); |
| 4611 | int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName, |
| 4612 | void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), |
| 4613 | void **ppArg); |
| 4614 | int (*xRename)(sqlite3_vtab *pVtab, const char *zNew); |
| 4615 | }; |
| 4616 | |
| 4617 | /* |
| 4618 | ** CAPI3REF: Virtual Table Indexing Information |
| 4619 | ** KEYWORDS: sqlite3_index_info |
| @@ -5424,11 +5583,11 @@ | |
| 5424 | ** |
| 5425 | ** ^This interface is used to retrieve runtime status information |
| 5426 | ** about the performance of SQLite, and optionally to reset various |
| 5427 | ** highwater marks. ^The first argument is an integer code for |
| 5428 | ** the specific parameter to measure. ^(Recognized integer codes |
| 5429 | ** are of the form [SQLITE_STATUS_MEMORY_USED | SQLITE_STATUS_...].)^ |
| 5430 | ** ^The current value of the parameter is returned into *pCurrent. |
| 5431 | ** ^The highest recorded value is returned in *pHighwater. ^If the |
| 5432 | ** resetFlag is true, then the highest record value is reset after |
| 5433 | ** *pHighwater is written. ^(Some parameters do not record the highest |
| 5434 | ** value. For those parameters |
| @@ -5451,82 +5610,84 @@ | |
| 5451 | SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); |
| 5452 | |
| 5453 | |
| 5454 | /* |
| 5455 | ** CAPI3REF: Status Parameters |
| 5456 | ** |
| 5457 | ** These integer constants designate various run-time status parameters |
| 5458 | ** that can be returned by [sqlite3_status()]. |
| 5459 | ** |
| 5460 | ** <dl> |
| 5461 | ** ^(<dt>SQLITE_STATUS_MEMORY_USED</dt> |
| 5462 | ** <dd>This parameter is the current amount of memory checked out |
| 5463 | ** using [sqlite3_malloc()], either directly or indirectly. The |
| 5464 | ** figure includes calls made to [sqlite3_malloc()] by the application |
| 5465 | ** and internal memory usage by the SQLite library. Scratch memory |
| 5466 | ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache |
| 5467 | ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in |
| 5468 | ** this parameter. The amount returned is the sum of the allocation |
| 5469 | ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^ |
| 5470 | ** |
| 5471 | ** ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt> |
| 5472 | ** <dd>This parameter records the largest memory allocation request |
| 5473 | ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their |
| 5474 | ** internal equivalents). Only the value returned in the |
| 5475 | ** *pHighwater parameter to [sqlite3_status()] is of interest. |
| 5476 | ** The value written into the *pCurrent parameter is undefined.</dd>)^ |
| 5477 | ** |
| 5478 | ** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt> |
| 5479 | ** <dd>This parameter records the number of separate memory allocations |
| 5480 | ** currently checked out.</dd>)^ |
| 5481 | ** |
| 5482 | ** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt> |
| 5483 | ** <dd>This parameter returns the number of pages used out of the |
| 5484 | ** [pagecache memory allocator] that was configured using |
| 5485 | ** [SQLITE_CONFIG_PAGECACHE]. The |
| 5486 | ** value returned is in pages, not in bytes.</dd>)^ |
| 5487 | ** |
| 5488 | ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt> |
| 5489 | ** <dd>This parameter returns the number of bytes of page cache |
| 5490 | ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE] |
| 5491 | ** buffer and where forced to overflow to [sqlite3_malloc()]. The |
| 5492 | ** returned value includes allocations that overflowed because they |
| 5493 | ** where too large (they were larger than the "sz" parameter to |
| 5494 | ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because |
| 5495 | ** no space was left in the page cache.</dd>)^ |
| 5496 | ** |
| 5497 | ** ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt> |
| 5498 | ** <dd>This parameter records the largest memory allocation request |
| 5499 | ** handed to [pagecache memory allocator]. Only the value returned in the |
| 5500 | ** *pHighwater parameter to [sqlite3_status()] is of interest. |
| 5501 | ** The value written into the *pCurrent parameter is undefined.</dd>)^ |
| 5502 | ** |
| 5503 | ** ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt> |
| 5504 | ** <dd>This parameter returns the number of allocations used out of the |
| 5505 | ** [scratch memory allocator] configured using |
| 5506 | ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not |
| 5507 | ** in bytes. Since a single thread may only have one scratch allocation |
| 5508 | ** outstanding at time, this parameter also reports the number of threads |
| 5509 | ** using scratch memory at the same time.</dd>)^ |
| 5510 | ** |
| 5511 | ** ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt> |
| 5512 | ** <dd>This parameter returns the number of bytes of scratch memory |
| 5513 | ** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH] |
| 5514 | ** buffer and where forced to overflow to [sqlite3_malloc()]. The values |
| 5515 | ** returned include overflows because the requested allocation was too |
| 5516 | ** larger (that is, because the requested allocation was larger than the |
| 5517 | ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer |
| 5518 | ** slots were available. |
| 5519 | ** </dd>)^ |
| 5520 | ** |
| 5521 | ** ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt> |
| 5522 | ** <dd>This parameter records the largest memory allocation request |
| 5523 | ** handed to [scratch memory allocator]. Only the value returned in the |
| 5524 | ** *pHighwater parameter to [sqlite3_status()] is of interest. |
| 5525 | ** The value written into the *pCurrent parameter is undefined.</dd>)^ |
| 5526 | ** |
| 5527 | ** ^(<dt>SQLITE_STATUS_PARSER_STACK</dt> |
| 5528 | ** <dd>This parameter records the deepest parser stack. It is only |
| 5529 | ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^ |
| 5530 | ** </dl> |
| 5531 | ** |
| 5532 | ** New status parameters may be added from time to time. |
| @@ -5547,13 +5708,13 @@ | |
| 5547 | ** |
| 5548 | ** ^This interface is used to retrieve runtime status information |
| 5549 | ** about a single [database connection]. ^The first argument is the |
| 5550 | ** database connection object to be interrogated. ^The second argument |
| 5551 | ** is an integer constant, taken from the set of |
| 5552 | ** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros, that |
| 5553 | ** determines the parameter to interrogate. The set of |
| 5554 | ** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros is likely |
| 5555 | ** to grow in future releases of SQLite. |
| 5556 | ** |
| 5557 | ** ^The current value of the requested parameter is written into *pCur |
| 5558 | ** and the highest instantaneous value is written into *pHiwtr. ^If |
| 5559 | ** the resetFlg is true, then the highest instantaneous value is |
| @@ -5566,10 +5727,11 @@ | |
| 5566 | */ |
| 5567 | SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); |
| 5568 | |
| 5569 | /* |
| 5570 | ** CAPI3REF: Status Parameters for database connections |
| 5571 | ** |
| 5572 | ** These constants are the available integer "verbs" that can be passed as |
| 5573 | ** the second argument to the [sqlite3_db_status()] interface. |
| 5574 | ** |
| 5575 | ** New verbs may be added in future releases of SQLite. Existing verbs |
| @@ -5577,48 +5739,50 @@ | |
| 5577 | ** [sqlite3_db_status()] to make sure that the call worked. |
| 5578 | ** The [sqlite3_db_status()] interface will return a non-zero error code |
| 5579 | ** if a discontinued or unsupported verb is invoked. |
| 5580 | ** |
| 5581 | ** <dl> |
| 5582 | ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt> |
| 5583 | ** <dd>This parameter returns the number of lookaside memory slots currently |
| 5584 | ** checked out.</dd>)^ |
| 5585 | ** |
| 5586 | ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt> |
| 5587 | ** <dd>This parameter returns the number malloc attempts that were |
| 5588 | ** satisfied using lookaside memory. Only the high-water value is meaningful; |
| 5589 | ** the current value is always zero.)^ |
| 5590 | ** |
| 5591 | ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt> |
| 5592 | ** <dd>This parameter returns the number malloc attempts that might have |
| 5593 | ** been satisfied using lookaside memory but failed due to the amount of |
| 5594 | ** memory requested being larger than the lookaside slot size. |
| 5595 | ** Only the high-water value is meaningful; |
| 5596 | ** the current value is always zero.)^ |
| 5597 | ** |
| 5598 | ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt> |
| 5599 | ** <dd>This parameter returns the number malloc attempts that might have |
| 5600 | ** been satisfied using lookaside memory but failed due to all lookaside |
| 5601 | ** memory already being in use. |
| 5602 | ** Only the high-water value is meaningful; |
| 5603 | ** the current value is always zero.)^ |
| 5604 | ** |
| 5605 | ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt> |
| 5606 | ** <dd>This parameter returns the approximate number of of bytes of heap |
| 5607 | ** memory used by all pager caches associated with the database connection.)^ |
| 5608 | ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0. |
| 5609 | ** |
| 5610 | ** ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt> |
| 5611 | ** <dd>This parameter returns the approximate number of of bytes of heap |
| 5612 | ** memory used to store the schema for all databases associated |
| 5613 | ** with the connection - main, temp, and any [ATTACH]-ed databases.)^ |
| 5614 | ** ^The full amount of memory used by the schemas is reported, even if the |
| 5615 | ** schema memory is shared with other database connections due to |
| 5616 | ** [shared cache mode] being enabled. |
| 5617 | ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0. |
| 5618 | ** |
| 5619 | ** ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt> |
| 5620 | ** <dd>This parameter returns the approximate number of of bytes of heap |
| 5621 | ** and lookaside memory used by all prepared statements associated with |
| 5622 | ** the database connection.)^ |
| 5623 | ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0. |
| 5624 | ** </dd> |
| @@ -5636,11 +5800,11 @@ | |
| 5636 | |
| 5637 | /* |
| 5638 | ** CAPI3REF: Prepared Statement Status |
| 5639 | ** |
| 5640 | ** ^(Each prepared statement maintains various |
| 5641 | ** [SQLITE_STMTSTATUS_SORT | counters] that measure the number |
| 5642 | ** of times it has performed specific operations.)^ These counters can |
| 5643 | ** be used to monitor the performance characteristics of the prepared |
| 5644 | ** statements. For example, if the number of table steps greatly exceeds |
| 5645 | ** the number of table searches or result rows, that would tend to indicate |
| 5646 | ** that the prepared statement is using a full table scan rather than |
| @@ -5647,11 +5811,11 @@ | |
| 5647 | ** an index. |
| 5648 | ** |
| 5649 | ** ^(This interface is used to retrieve and reset counter values from |
| 5650 | ** a [prepared statement]. The first argument is the prepared statement |
| 5651 | ** object to be interrogated. The second argument |
| 5652 | ** is an integer code for a specific [SQLITE_STMTSTATUS_SORT | counter] |
| 5653 | ** to be interrogated.)^ |
| 5654 | ** ^The current value of the requested counter is returned. |
| 5655 | ** ^If the resetFlg is true, then the counter is reset to zero after this |
| 5656 | ** interface call returns. |
| 5657 | ** |
| @@ -5659,28 +5823,29 @@ | |
| 5659 | */ |
| 5660 | SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); |
| 5661 | |
| 5662 | /* |
| 5663 | ** CAPI3REF: Status Parameters for prepared statements |
| 5664 | ** |
| 5665 | ** These preprocessor macros define integer codes that name counter |
| 5666 | ** values associated with the [sqlite3_stmt_status()] interface. |
| 5667 | ** The meanings of the various counters are as follows: |
| 5668 | ** |
| 5669 | ** <dl> |
| 5670 | ** <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt> |
| 5671 | ** <dd>^This is the number of times that SQLite has stepped forward in |
| 5672 | ** a table as part of a full table scan. Large numbers for this counter |
| 5673 | ** may indicate opportunities for performance improvement through |
| 5674 | ** careful use of indices.</dd> |
| 5675 | ** |
| 5676 | ** <dt>SQLITE_STMTSTATUS_SORT</dt> |
| 5677 | ** <dd>^This is the number of sort operations that have occurred. |
| 5678 | ** A non-zero value in this counter may indicate an opportunity to |
| 5679 | ** improvement performance through careful use of indices.</dd> |
| 5680 | ** |
| 5681 | ** <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt> |
| 5682 | ** <dd>^This is the number of rows inserted into transient indices that |
| 5683 | ** were created automatically in order to help joins run faster. |
| 5684 | ** A non-zero value in this counter may indicate an opportunity to |
| 5685 | ** improvement performance by adding permanent indices that do not |
| 5686 | ** need to be reinitialized each time the statement is run.</dd> |
| @@ -5727,10 +5892,11 @@ | |
| 5727 | ** ^(The contents of the sqlite3_pcache_methods structure are copied to an |
| 5728 | ** internal buffer by SQLite within the call to [sqlite3_config]. Hence |
| 5729 | ** the application may discard the parameter after the call to |
| 5730 | ** [sqlite3_config()] returns.)^ |
| 5731 | ** |
| 5732 | ** ^(The xInit() method is called once for each effective |
| 5733 | ** call to [sqlite3_initialize()])^ |
| 5734 | ** (usually only once during the lifetime of the process). ^(The xInit() |
| 5735 | ** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^ |
| 5736 | ** The intent of the xInit() method is to set up global data structures |
| @@ -5737,10 +5903,11 @@ | |
| 5737 | ** required by the custom page cache implementation. |
| 5738 | ** ^(If the xInit() method is NULL, then the |
| 5739 | ** built-in default page cache is used instead of the application defined |
| 5740 | ** page cache.)^ |
| 5741 | ** |
| 5742 | ** ^The xShutdown() method is called by [sqlite3_shutdown()]. |
| 5743 | ** It can be used to clean up |
| 5744 | ** any outstanding resources before process shutdown, if required. |
| 5745 | ** ^The xShutdown() method may be NULL. |
| 5746 | ** |
| @@ -5751,10 +5918,11 @@ | |
| 5751 | ** in multithreaded applications. |
| 5752 | ** |
| 5753 | ** ^SQLite will never invoke xInit() more than once without an intervening |
| 5754 | ** call to xShutdown(). |
| 5755 | ** |
| 5756 | ** ^SQLite invokes the xCreate() method to construct a new cache instance. |
| 5757 | ** SQLite will typically create one cache instance for each open database file, |
| 5758 | ** though this is not guaranteed. ^The |
| 5759 | ** first parameter, szPage, is the size in bytes of the pages that must |
| 5760 | ** be allocated by the cache. ^szPage will not be a power of two. ^szPage |
| @@ -5775,20 +5943,23 @@ | |
| 5775 | ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to |
| 5776 | ** false will always have the "discard" flag set to true. |
| 5777 | ** ^Hence, a cache created with bPurgeable false will |
| 5778 | ** never contain any unpinned pages. |
| 5779 | ** |
| 5780 | ** ^(The xCachesize() method may be called at any time by SQLite to set the |
| 5781 | ** suggested maximum cache-size (number of pages stored by) the cache |
| 5782 | ** instance passed as the first argument. This is the value configured using |
| 5783 | ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable |
| 5784 | ** parameter, the implementation is not required to do anything with this |
| 5785 | ** value; it is advisory only. |
| 5786 | ** |
| 5787 | ** The xPagecount() method must return the number of pages currently |
| 5788 | ** stored in the cache, both pinned and unpinned. |
| 5789 | ** |
| 5790 | ** The xFetch() method locates a page in the cache and returns a pointer to |
| 5791 | ** the page, or a NULL pointer. |
| 5792 | ** A "page", in this context, means a buffer of szPage bytes aligned at an |
| 5793 | ** 8-byte boundary. The page to be fetched is determined by the key. ^The |
| 5794 | ** mimimum key value is 1. After it has been retrieved using xFetch, the page |
| @@ -5813,10 +5984,11 @@ | |
| 5813 | ** will only use a createFlag of 2 after a prior call with a createFlag of 1 |
| 5814 | ** failed.)^ In between the to xFetch() calls, SQLite may |
| 5815 | ** attempt to unpin one or more cache pages by spilling the content of |
| 5816 | ** pinned pages to disk and synching the operating system disk cache. |
| 5817 | ** |
| 5818 | ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page |
| 5819 | ** as its second argument. If the third parameter, discard, is non-zero, |
| 5820 | ** then the page must be evicted from the cache. |
| 5821 | ** ^If the discard parameter is |
| 5822 | ** zero, then the page may be discarded or retained at the discretion of |
| @@ -5825,10 +5997,11 @@ | |
| 5825 | ** |
| 5826 | ** The cache must not perform any reference counting. A single |
| 5827 | ** call to xUnpin() unpins the page regardless of the number of prior calls |
| 5828 | ** to xFetch(). |
| 5829 | ** |
| 5830 | ** The xRekey() method is used to change the key value associated with the |
| 5831 | ** page passed as the second argument. If the cache |
| 5832 | ** previously contains an entry associated with newKey, it must be |
| 5833 | ** discarded. ^Any prior cache entry associated with newKey is guaranteed not |
| 5834 | ** to be pinned. |
| @@ -5837,10 +6010,11 @@ | |
| 5837 | ** existing cache entries with page numbers (keys) greater than or equal |
| 5838 | ** to the value of the iLimit parameter passed to xTruncate(). If any |
| 5839 | ** of these pages are pinned, they are implicitly unpinned, meaning that |
| 5840 | ** they can be safely discarded. |
| 5841 | ** |
| 5842 | ** ^The xDestroy() method is used to delete a cache allocated by xCreate(). |
| 5843 | ** All resources associated with the specified cache should be freed. ^After |
| 5844 | ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*] |
| 5845 | ** handle invalid, and will not use it with any other sqlite3_pcache_methods |
| 5846 | ** functions. |
| @@ -5899,11 +6073,11 @@ | |
| 5899 | ** associated with the backup operation. |
| 5900 | ** </ol>)^ |
| 5901 | ** There should be exactly one call to sqlite3_backup_finish() for each |
| 5902 | ** successful call to sqlite3_backup_init(). |
| 5903 | ** |
| 5904 | ** <b>sqlite3_backup_init()</b> |
| 5905 | ** |
| 5906 | ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the |
| 5907 | ** [database connection] associated with the destination database |
| 5908 | ** and the database name, respectively. |
| 5909 | ** ^The database name is "main" for the main database, "temp" for the |
| @@ -5926,11 +6100,11 @@ | |
| 5926 | ** [sqlite3_backup] object. |
| 5927 | ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and |
| 5928 | ** sqlite3_backup_finish() functions to perform the specified backup |
| 5929 | ** operation. |
| 5930 | ** |
| 5931 | ** <b>sqlite3_backup_step()</b> |
| 5932 | ** |
| 5933 | ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between |
| 5934 | ** the source and destination databases specified by [sqlite3_backup] object B. |
| 5935 | ** ^If N is negative, all remaining source pages are copied. |
| 5936 | ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there |
| @@ -5983,11 +6157,11 @@ | |
| 5983 | ** restarted by the next call to sqlite3_backup_step(). ^If the source |
| 5984 | ** database is modified by the using the same database connection as is used |
| 5985 | ** by the backup operation, then the backup database is automatically |
| 5986 | ** updated at the same time. |
| 5987 | ** |
| 5988 | ** <b>sqlite3_backup_finish()</b> |
| 5989 | ** |
| 5990 | ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the |
| 5991 | ** application wishes to abandon the backup operation, the application |
| 5992 | ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish(). |
| 5993 | ** ^The sqlite3_backup_finish() interfaces releases all |
| @@ -6006,11 +6180,12 @@ | |
| 6006 | ** |
| 6007 | ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step() |
| 6008 | ** is not a permanent error and does not affect the return value of |
| 6009 | ** sqlite3_backup_finish(). |
| 6010 | ** |
| 6011 | ** <b>sqlite3_backup_remaining(), sqlite3_backup_pagecount()</b> |
| 6012 | ** |
| 6013 | ** ^Each call to sqlite3_backup_step() sets two values inside |
| 6014 | ** the [sqlite3_backup] object: the number of pages still to be backed |
| 6015 | ** up and the total number of pages in the source database file. |
| 6016 | ** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces |
| @@ -6391,10 +6566,97 @@ | |
| 6391 | ** each of these values. |
| 6392 | */ |
| 6393 | #define SQLITE_CHECKPOINT_PASSIVE 0 |
| 6394 | #define SQLITE_CHECKPOINT_FULL 1 |
| 6395 | #define SQLITE_CHECKPOINT_RESTART 2 |
| 6396 | |
| 6397 | |
| 6398 | /* |
| 6399 | ** Undo the hack that converts floating point types to integer for |
| 6400 | ** builds on processors without floating point support. |
| 6401 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -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.7.7" |
| 111 | #define SQLITE_VERSION_NUMBER 3007007 |
| 112 | #define SQLITE_SOURCE_ID "2011-05-18 03:02:10 186d7ff1d9804d508e472e4939608bf2be67bdc2" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -373,11 +373,12 @@ | |
| 373 | ** Many SQLite functions return an integer result code from the set shown |
| 374 | ** here in order to indicates success or failure. |
| 375 | ** |
| 376 | ** New error codes may be added in future versions of SQLite. |
| 377 | ** |
| 378 | ** See also: [SQLITE_IOERR_READ | extended result codes], |
| 379 | ** [sqlite3_vtab_on_conflict()] [SQLITE_ROLLBACK | result codes]. |
| 380 | */ |
| 381 | #define SQLITE_OK 0 /* Successful result */ |
| 382 | /* beginning-of-error-codes */ |
| 383 | #define SQLITE_ERROR 1 /* SQL error or missing database */ |
| 384 | #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ |
| @@ -455,25 +456,26 @@ | |
| 456 | #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) |
| 457 | #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) |
| 458 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 459 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 460 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 461 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 462 | |
| 463 | /* |
| 464 | ** CAPI3REF: Flags For File Open Operations |
| 465 | ** |
| 466 | ** These bit values are intended for use in the |
| 467 | ** 3rd parameter to the [sqlite3_open_v2()] interface and |
| 468 | ** in the 4th parameter to the [sqlite3_vfs.xOpen] method. |
| 469 | */ |
| 470 | #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ |
| 471 | #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ |
| 472 | #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ |
| 473 | #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ |
| 474 | #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ |
| 475 | #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ |
| 476 | #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */ |
| 477 | #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ |
| 478 | #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ |
| 479 | #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ |
| 480 | #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ |
| 481 | #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ |
| @@ -580,21 +582,22 @@ | |
| 582 | }; |
| 583 | |
| 584 | /* |
| 585 | ** CAPI3REF: OS Interface File Virtual Methods Object |
| 586 | ** |
| 587 | ** Every file opened by the [sqlite3_vfs.xOpen] method populates an |
| 588 | ** [sqlite3_file] object (or, more commonly, a subclass of the |
| 589 | ** [sqlite3_file] object) with a pointer to an instance of this object. |
| 590 | ** This object defines the methods used to perform various operations |
| 591 | ** against the open file represented by the [sqlite3_file] object. |
| 592 | ** |
| 593 | ** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element |
| 594 | ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method |
| 595 | ** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The |
| 596 | ** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen] |
| 597 | ** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element |
| 598 | ** to NULL. |
| 599 | ** |
| 600 | ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or |
| 601 | ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync(). |
| 602 | ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY] |
| 603 | ** flag may be ORed in to indicate that only the data of the file |
| @@ -759,10 +762,11 @@ | |
| 762 | */ |
| 763 | typedef struct sqlite3_mutex sqlite3_mutex; |
| 764 | |
| 765 | /* |
| 766 | ** CAPI3REF: OS Interface Object |
| 767 | ** KEYWORDS: VFS VFSes |
| 768 | ** |
| 769 | ** An instance of the sqlite3_vfs object defines the interface between |
| 770 | ** the SQLite core and the underlying operating system. The "vfs" |
| 771 | ** in the name of the object stands for "virtual file system". |
| 772 | ** |
| @@ -791,10 +795,11 @@ | |
| 795 | ** object once the object has been registered. |
| 796 | ** |
| 797 | ** The zName field holds the name of the VFS module. The name must |
| 798 | ** be unique across all VFS modules. |
| 799 | ** |
| 800 | ** [[sqlite3_vfs.xOpen]] |
| 801 | ** ^SQLite guarantees that the zFilename parameter to xOpen |
| 802 | ** is either a NULL pointer or string obtained |
| 803 | ** from xFullPathname() with an optional suffix added. |
| 804 | ** ^If a suffix is added to the zFilename parameter, it will |
| 805 | ** consist of a single "-" character followed by no more than |
| @@ -868,10 +873,11 @@ | |
| 873 | ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do |
| 874 | ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods |
| 875 | ** element will be valid after xOpen returns regardless of the success |
| 876 | ** or failure of the xOpen call. |
| 877 | ** |
| 878 | ** [[sqlite3_vfs.xAccess]] |
| 879 | ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] |
| 880 | ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to |
| 881 | ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ] |
| 882 | ** to test whether a file is at least readable. The file can be a |
| 883 | ** directory. |
| @@ -1114,13 +1120,13 @@ | |
| 1120 | ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE. |
| 1121 | ** Note, however, that ^sqlite3_config() can be called as part of the |
| 1122 | ** implementation of an application-defined [sqlite3_os_init()]. |
| 1123 | ** |
| 1124 | ** The first argument to sqlite3_config() is an integer |
| 1125 | ** [configuration option] that determines |
| 1126 | ** what property of SQLite is to be configured. Subsequent arguments |
| 1127 | ** vary depending on the [configuration option] |
| 1128 | ** in the first argument. |
| 1129 | ** |
| 1130 | ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. |
| 1131 | ** ^If the option is unknown or SQLite is unable to set the option |
| 1132 | ** then this routine returns a non-zero [error code]. |
| @@ -1226,10 +1232,11 @@ | |
| 1232 | void *pAppData; /* Argument to xInit() and xShutdown() */ |
| 1233 | }; |
| 1234 | |
| 1235 | /* |
| 1236 | ** CAPI3REF: Configuration Options |
| 1237 | ** KEYWORDS: {configuration option} |
| 1238 | ** |
| 1239 | ** These constants are the available integer configuration options that |
| 1240 | ** can be passed as the first argument to the [sqlite3_config()] interface. |
| 1241 | ** |
| 1242 | ** New configuration options may be added in future releases of SQLite. |
| @@ -1238,11 +1245,11 @@ | |
| 1245 | ** the call worked. The [sqlite3_config()] interface will return a |
| 1246 | ** non-zero [error code] if a discontinued or unsupported configuration option |
| 1247 | ** is invoked. |
| 1248 | ** |
| 1249 | ** <dl> |
| 1250 | ** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt> |
| 1251 | ** <dd>There are no arguments to this option. ^This option sets the |
| 1252 | ** [threading mode] to Single-thread. In other words, it disables |
| 1253 | ** all mutexing and puts SQLite into a mode where it can only be used |
| 1254 | ** by a single thread. ^If SQLite is compiled with |
| 1255 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| @@ -1249,11 +1256,11 @@ | |
| 1256 | ** it is not possible to change the [threading mode] from its default |
| 1257 | ** value of Single-thread and so [sqlite3_config()] will return |
| 1258 | ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD |
| 1259 | ** configuration option.</dd> |
| 1260 | ** |
| 1261 | ** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt> |
| 1262 | ** <dd>There are no arguments to this option. ^This option sets the |
| 1263 | ** [threading mode] to Multi-thread. In other words, it disables |
| 1264 | ** mutexing on [database connection] and [prepared statement] objects. |
| 1265 | ** The application is responsible for serializing access to |
| 1266 | ** [database connections] and [prepared statements]. But other mutexes |
| @@ -1263,11 +1270,11 @@ | |
| 1270 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1271 | ** it is not possible to set the Multi-thread [threading mode] and |
| 1272 | ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
| 1273 | ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd> |
| 1274 | ** |
| 1275 | ** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt> |
| 1276 | ** <dd>There are no arguments to this option. ^This option sets the |
| 1277 | ** [threading mode] to Serialized. In other words, this option enables |
| 1278 | ** all mutexes including the recursive |
| 1279 | ** mutexes on [database connection] and [prepared statement] objects. |
| 1280 | ** In this mode (which is the default when SQLite is compiled with |
| @@ -1279,27 +1286,27 @@ | |
| 1286 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1287 | ** it is not possible to set the Serialized [threading mode] and |
| 1288 | ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
| 1289 | ** SQLITE_CONFIG_SERIALIZED configuration option.</dd> |
| 1290 | ** |
| 1291 | ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt> |
| 1292 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1293 | ** instance of the [sqlite3_mem_methods] structure. The argument specifies |
| 1294 | ** alternative low-level memory allocation routines to be used in place of |
| 1295 | ** the memory allocation routines built into SQLite.)^ ^SQLite makes |
| 1296 | ** its own private copy of the content of the [sqlite3_mem_methods] structure |
| 1297 | ** before the [sqlite3_config()] call returns.</dd> |
| 1298 | ** |
| 1299 | ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt> |
| 1300 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1301 | ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods] |
| 1302 | ** structure is filled with the currently defined memory allocation routines.)^ |
| 1303 | ** This option can be used to overload the default memory allocation |
| 1304 | ** routines with a wrapper that simulations memory allocation failure or |
| 1305 | ** tracks memory usage, for example. </dd> |
| 1306 | ** |
| 1307 | ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> |
| 1308 | ** <dd> ^This option takes single argument of type int, interpreted as a |
| 1309 | ** boolean, which enables or disables the collection of memory allocation |
| 1310 | ** statistics. ^(When memory allocation statistics are disabled, the |
| 1311 | ** following SQLite interfaces become non-operational: |
| 1312 | ** <ul> |
| @@ -1311,11 +1318,11 @@ | |
| 1318 | ** ^Memory allocation statistics are enabled by default unless SQLite is |
| 1319 | ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory |
| 1320 | ** allocation statistics are disabled by default. |
| 1321 | ** </dd> |
| 1322 | ** |
| 1323 | ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt> |
| 1324 | ** <dd> ^This option specifies a static memory buffer that SQLite can use for |
| 1325 | ** scratch memory. There are three arguments: A pointer an 8-byte |
| 1326 | ** aligned memory buffer from which the scratch allocations will be |
| 1327 | ** drawn, the size of each scratch allocation (sz), |
| 1328 | ** and the maximum number of scratch allocations (N). The sz |
| @@ -1327,11 +1334,11 @@ | |
| 1334 | ** ^SQLite will never require a scratch buffer that is more than 6 |
| 1335 | ** times the database page size. ^If SQLite needs needs additional |
| 1336 | ** scratch memory beyond what is provided by this configuration option, then |
| 1337 | ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd> |
| 1338 | ** |
| 1339 | ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt> |
| 1340 | ** <dd> ^This option specifies a static memory buffer that SQLite can use for |
| 1341 | ** the database page cache with the default page cache implemenation. |
| 1342 | ** This configuration should not be used if an application-define page |
| 1343 | ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option. |
| 1344 | ** There are three arguments to this option: A pointer to 8-byte aligned |
| @@ -1348,11 +1355,11 @@ | |
| 1355 | ** SQLite goes to [sqlite3_malloc()] for the additional storage space. |
| 1356 | ** The pointer in the first argument must |
| 1357 | ** be aligned to an 8-byte boundary or subsequent behavior of SQLite |
| 1358 | ** will be undefined.</dd> |
| 1359 | ** |
| 1360 | ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> |
| 1361 | ** <dd> ^This option specifies a static memory buffer that SQLite will use |
| 1362 | ** for all of its dynamic memory allocation needs beyond those provided |
| 1363 | ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. |
| 1364 | ** There are three arguments: An 8-byte aligned pointer to the memory, |
| 1365 | ** the number of bytes in the memory buffer, and the minimum allocation size. |
| @@ -1365,11 +1372,11 @@ | |
| 1372 | ** The first pointer (the memory pointer) must be aligned to an 8-byte |
| 1373 | ** boundary or subsequent behavior of SQLite will be undefined. |
| 1374 | ** The minimum allocation size is capped at 2^12. Reasonable values |
| 1375 | ** for the minimum allocation size are 2^5 through 2^8.</dd> |
| 1376 | ** |
| 1377 | ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt> |
| 1378 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1379 | ** instance of the [sqlite3_mutex_methods] structure. The argument specifies |
| 1380 | ** alternative low-level mutex routines to be used in place |
| 1381 | ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the |
| 1382 | ** content of the [sqlite3_mutex_methods] structure before the call to |
| @@ -1377,11 +1384,11 @@ | |
| 1384 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1385 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1386 | ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will |
| 1387 | ** return [SQLITE_ERROR].</dd> |
| 1388 | ** |
| 1389 | ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt> |
| 1390 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1391 | ** instance of the [sqlite3_mutex_methods] structure. The |
| 1392 | ** [sqlite3_mutex_methods] |
| 1393 | ** structure is filled with the currently defined mutex routines.)^ |
| 1394 | ** This option can be used to overload the default mutex allocation |
| @@ -1390,32 +1397,32 @@ | |
| 1397 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1398 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1399 | ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will |
| 1400 | ** return [SQLITE_ERROR].</dd> |
| 1401 | ** |
| 1402 | ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt> |
| 1403 | ** <dd> ^(This option takes two arguments that determine the default |
| 1404 | ** memory allocation for the lookaside memory allocator on each |
| 1405 | ** [database connection]. The first argument is the |
| 1406 | ** size of each lookaside buffer slot and the second is the number of |
| 1407 | ** slots allocated to each database connection.)^ ^(This option sets the |
| 1408 | ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] |
| 1409 | ** verb to [sqlite3_db_config()] can be used to change the lookaside |
| 1410 | ** configuration on individual connections.)^ </dd> |
| 1411 | ** |
| 1412 | ** [[SQLITE_CONFIG_PCACHE]] <dt>SQLITE_CONFIG_PCACHE</dt> |
| 1413 | ** <dd> ^(This option takes a single argument which is a pointer to |
| 1414 | ** an [sqlite3_pcache_methods] object. This object specifies the interface |
| 1415 | ** to a custom page cache implementation.)^ ^SQLite makes a copy of the |
| 1416 | ** object and uses it for page cache memory allocations.</dd> |
| 1417 | ** |
| 1418 | ** [[SQLITE_CONFIG_GETPCACHE]] <dt>SQLITE_CONFIG_GETPCACHE</dt> |
| 1419 | ** <dd> ^(This option takes a single argument which is a pointer to an |
| 1420 | ** [sqlite3_pcache_methods] object. SQLite copies of the current |
| 1421 | ** page cache implementation into that object.)^ </dd> |
| 1422 | ** |
| 1423 | ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> |
| 1424 | ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a |
| 1425 | ** function with a call signature of void(*)(void*,int,const char*), |
| 1426 | ** and a pointer to void. ^If the function pointer is not NULL, it is |
| 1427 | ** invoked by [sqlite3_log()] to process each logging event. ^If the |
| 1428 | ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op. |
| @@ -1429,10 +1436,22 @@ | |
| 1436 | ** The SQLite logging interface is not reentrant; the logger function |
| 1437 | ** supplied by the application must not invoke any SQLite interface. |
| 1438 | ** In a multi-threaded application, the application-defined logger |
| 1439 | ** function must be threadsafe. </dd> |
| 1440 | ** |
| 1441 | ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI |
| 1442 | ** <dd> This option takes a single argument of type int. If non-zero, then |
| 1443 | ** URI handling is globally enabled. If the parameter is zero, then URI handling |
| 1444 | ** is globally disabled. If URI handling is globally enabled, all filenames |
| 1445 | ** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or |
| 1446 | ** specified as part of [ATTACH] commands are interpreted as URIs, regardless |
| 1447 | ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database |
| 1448 | ** connection is opened. If it is globally disabled, filenames are |
| 1449 | ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the |
| 1450 | ** database connection is opened. By default, URI handling is globally |
| 1451 | ** disabled. The default value may be changed by compiling with the |
| 1452 | ** [SQLITE_USE_URI] symbol defined. |
| 1453 | ** </dl> |
| 1454 | */ |
| 1455 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1456 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 1457 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| @@ -1447,10 +1466,11 @@ | |
| 1466 | /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ |
| 1467 | #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ |
| 1468 | #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */ |
| 1469 | #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */ |
| 1470 | #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ |
| 1471 | #define SQLITE_CONFIG_URI 17 /* int */ |
| 1472 | |
| 1473 | /* |
| 1474 | ** CAPI3REF: Database Connection Configuration Options |
| 1475 | ** |
| 1476 | ** These constants are the available integer configuration options that |
| @@ -1532,17 +1552,21 @@ | |
| 1552 | ** the table has a column of type [INTEGER PRIMARY KEY] then that column |
| 1553 | ** is another alias for the rowid. |
| 1554 | ** |
| 1555 | ** ^This routine returns the [rowid] of the most recent |
| 1556 | ** successful [INSERT] into the database from the [database connection] |
| 1557 | ** in the first argument. ^As of SQLite version 3.7.7, this routines |
| 1558 | ** records the last insert rowid of both ordinary tables and [virtual tables]. |
| 1559 | ** ^If no successful [INSERT]s |
| 1560 | ** have ever occurred on that database connection, zero is returned. |
| 1561 | ** |
| 1562 | ** ^(If an [INSERT] occurs within a trigger or within a [virtual table] |
| 1563 | ** method, then this routine will return the [rowid] of the inserted |
| 1564 | ** row as long as the trigger or virtual table method is running. |
| 1565 | ** But once the trigger or virtual table method ends, the value returned |
| 1566 | ** by this routine reverts to what it was before the trigger or virtual |
| 1567 | ** table method began.)^ |
| 1568 | ** |
| 1569 | ** ^An [INSERT] that fails due to a constraint violation is not a |
| 1570 | ** successful [INSERT] and does not change the value returned by this |
| 1571 | ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK, |
| 1572 | ** and INSERT OR ABORT make no changes to the return value of this |
| @@ -2201,10 +2225,13 @@ | |
| 2225 | ** The [sqlite3_set_authorizer | authorizer callback function] must |
| 2226 | ** return either [SQLITE_OK] or one of these two constants in order |
| 2227 | ** to signal SQLite whether or not the action is permitted. See the |
| 2228 | ** [sqlite3_set_authorizer | authorizer documentation] for additional |
| 2229 | ** information. |
| 2230 | ** |
| 2231 | ** Note that SQLITE_IGNORE is also used as a [SQLITE_ROLLBACK | return code] |
| 2232 | ** from the [sqlite3_vtab_on_conflict()] interface. |
| 2233 | */ |
| 2234 | #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ |
| 2235 | #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ |
| 2236 | |
| 2237 | /* |
| @@ -2323,11 +2350,11 @@ | |
| 2350 | SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); |
| 2351 | |
| 2352 | /* |
| 2353 | ** CAPI3REF: Opening A New Database Connection |
| 2354 | ** |
| 2355 | ** ^These routines open an SQLite database file as specified by the |
| 2356 | ** filename argument. ^The filename argument is interpreted as UTF-8 for |
| 2357 | ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte |
| 2358 | ** order for sqlite3_open16(). ^(A [database connection] handle is usually |
| 2359 | ** returned in *ppDb, even if an error occurs. The only exception is that |
| 2360 | ** if SQLite is unable to allocate memory to hold the [sqlite3] object, |
| @@ -2350,11 +2377,11 @@ | |
| 2377 | ** except that it accepts two additional parameters for additional control |
| 2378 | ** over the new database connection. ^(The flags parameter to |
| 2379 | ** sqlite3_open_v2() can take one of |
| 2380 | ** the following three values, optionally combined with the |
| 2381 | ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE], |
| 2382 | ** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^ |
| 2383 | ** |
| 2384 | ** <dl> |
| 2385 | ** ^(<dt>[SQLITE_OPEN_READONLY]</dt> |
| 2386 | ** <dd>The database is opened in read-only mode. If the database does not |
| 2387 | ** already exist, an error is returned.</dd>)^ |
| @@ -2369,13 +2396,12 @@ | |
| 2396 | ** it does not already exist. This is the behavior that is always used for |
| 2397 | ** sqlite3_open() and sqlite3_open16().</dd>)^ |
| 2398 | ** </dl> |
| 2399 | ** |
| 2400 | ** If the 3rd parameter to sqlite3_open_v2() is not one of the |
| 2401 | ** combinations shown above optionally combined with other |
| 2402 | ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits] |
| 2403 | ** then the behavior is undefined. |
| 2404 | ** |
| 2405 | ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection |
| 2406 | ** opens in the multi-thread [threading mode] as long as the single-thread |
| 2407 | ** mode has not been set at compile-time or start-time. ^If the |
| @@ -2385,10 +2411,15 @@ | |
| 2411 | ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be |
| 2412 | ** eligible to use [shared cache mode], regardless of whether or not shared |
| 2413 | ** cache is enabled using [sqlite3_enable_shared_cache()]. ^The |
| 2414 | ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not |
| 2415 | ** participate in [shared cache mode] even if it is enabled. |
| 2416 | ** |
| 2417 | ** ^The fourth parameter to sqlite3_open_v2() is the name of the |
| 2418 | ** [sqlite3_vfs] object that defines the operating system interface that |
| 2419 | ** the new database connection should use. ^If the fourth parameter is |
| 2420 | ** a NULL pointer then the default [sqlite3_vfs] object is used. |
| 2421 | ** |
| 2422 | ** ^If the filename is ":memory:", then a private, temporary in-memory database |
| 2423 | ** is created for the connection. ^This in-memory database will vanish when |
| 2424 | ** the database connection is closed. Future versions of SQLite might |
| 2425 | ** make use of additional special filenames that begin with the ":" character. |
| @@ -2398,14 +2429,115 @@ | |
| 2429 | ** |
| 2430 | ** ^If the filename is an empty string, then a private, temporary |
| 2431 | ** on-disk database will be created. ^This private database will be |
| 2432 | ** automatically deleted as soon as the database connection is closed. |
| 2433 | ** |
| 2434 | ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3> |
| 2435 | ** |
| 2436 | ** ^If [URI filename] interpretation is enabled, and the filename argument |
| 2437 | ** begins with "file:", then the filename is interpreted as a URI. ^URI |
| 2438 | ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is |
| 2439 | ** is set in the fourth argument to sqlite3_open_v2(), or if it has |
| 2440 | ** been enabled globally using the [SQLITE_CONFIG_URI] option with the |
| 2441 | ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option. |
| 2442 | ** As of SQLite version 3.7.7, URI filename interpretation is turned off |
| 2443 | ** by default, but future releases of SQLite might enable URI filename |
| 2444 | ** intepretation by default. See "[URI filenames]" for additional |
| 2445 | ** information. |
| 2446 | ** |
| 2447 | ** URI filenames are parsed according to RFC 3986. ^If the URI contains an |
| 2448 | ** authority, then it must be either an empty string or the string |
| 2449 | ** "localhost". ^If the authority is not an empty string or "localhost", an |
| 2450 | ** error is returned to the caller. ^The fragment component of a URI, if |
| 2451 | ** present, is ignored. |
| 2452 | ** |
| 2453 | ** ^SQLite uses the path component of the URI as the name of the disk file |
| 2454 | ** which contains the database. ^If the path begins with a '/' character, |
| 2455 | ** then it is interpreted as an absolute path. ^If the path does not begin |
| 2456 | ** with a '/' (meaning that the authority section is omitted from the URI) |
| 2457 | ** then the path is interpreted as a relative path. |
| 2458 | ** ^On windows, the first component of an absolute path |
| 2459 | ** is a drive specification (e.g. "C:"). |
| 2460 | ** |
| 2461 | ** [[core URI query parameters]] |
| 2462 | ** The query component of a URI may contain parameters that are interpreted |
| 2463 | ** either by SQLite itself, or by a [VFS | custom VFS implementation]. |
| 2464 | ** SQLite interprets the following three query parameters: |
| 2465 | ** |
| 2466 | ** <ul> |
| 2467 | ** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of |
| 2468 | ** a VFS object that provides the operating system interface that should |
| 2469 | ** be used to access the database file on disk. ^If this option is set to |
| 2470 | ** an empty string the default VFS object is used. ^Specifying an unknown |
| 2471 | ** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is |
| 2472 | ** present, then the VFS specified by the option takes precedence over |
| 2473 | ** the value passed as the fourth parameter to sqlite3_open_v2(). |
| 2474 | ** |
| 2475 | ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw" or |
| 2476 | ** "rwc". Attempting to set it to any other value is an error)^. |
| 2477 | ** ^If "ro" is specified, then the database is opened for read-only |
| 2478 | ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the |
| 2479 | ** third argument to sqlite3_prepare_v2(). ^If the mode option is set to |
| 2480 | ** "rw", then the database is opened for read-write (but not create) |
| 2481 | ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had |
| 2482 | ** been set. ^Value "rwc" is equivalent to setting both |
| 2483 | ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If sqlite3_open_v2() is |
| 2484 | ** used, it is an error to specify a value for the mode parameter that is |
| 2485 | ** less restrictive than that specified by the flags passed as the third |
| 2486 | ** parameter. |
| 2487 | ** |
| 2488 | ** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or |
| 2489 | ** "private". ^Setting it to "shared" is equivalent to setting the |
| 2490 | ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to |
| 2491 | ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is |
| 2492 | ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit. |
| 2493 | ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in |
| 2494 | ** a URI filename, its value overrides any behaviour requested by setting |
| 2495 | ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag. |
| 2496 | ** </ul> |
| 2497 | ** |
| 2498 | ** ^Specifying an unknown parameter in the query component of a URI is not an |
| 2499 | ** error. Future versions of SQLite might understand additional query |
| 2500 | ** parameters. See "[query parameters with special meaning to SQLite]" for |
| 2501 | ** additional information. |
| 2502 | ** |
| 2503 | ** [[URI filename examples]] <h3>URI filename examples</h3> |
| 2504 | ** |
| 2505 | ** <table border="1" align=center cellpadding=5> |
| 2506 | ** <tr><th> URI filenames <th> Results |
| 2507 | ** <tr><td> file:data.db <td> |
| 2508 | ** Open the file "data.db" in the current directory. |
| 2509 | ** <tr><td> file:/home/fred/data.db<br> |
| 2510 | ** file:///home/fred/data.db <br> |
| 2511 | ** file://localhost/home/fred/data.db <br> <td> |
| 2512 | ** Open the database file "/home/fred/data.db". |
| 2513 | ** <tr><td> file://darkstar/home/fred/data.db <td> |
| 2514 | ** An error. "darkstar" is not a recognized authority. |
| 2515 | ** <tr><td style="white-space:nowrap"> |
| 2516 | ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db |
| 2517 | ** <td> Windows only: Open the file "data.db" on fred's desktop on drive |
| 2518 | ** C:. Note that the %20 escaping in this example is not strictly |
| 2519 | ** necessary - space characters can be used literally |
| 2520 | ** in URI filenames. |
| 2521 | ** <tr><td> file:data.db?mode=ro&cache=private <td> |
| 2522 | ** Open file "data.db" in the current directory for read-only access. |
| 2523 | ** Regardless of whether or not shared-cache mode is enabled by |
| 2524 | ** default, use a private cache. |
| 2525 | ** <tr><td> file:/home/fred/data.db?vfs=unix-nolock <td> |
| 2526 | ** Open file "/home/fred/data.db". Use the special VFS "unix-nolock". |
| 2527 | ** <tr><td> file:data.db?mode=readonly <td> |
| 2528 | ** An error. "readonly" is not a valid option for the "mode" parameter. |
| 2529 | ** </table> |
| 2530 | ** |
| 2531 | ** ^URI hexadecimal escape sequences (%HH) are supported within the path and |
| 2532 | ** query components of a URI. A hexadecimal escape sequence consists of a |
| 2533 | ** percent sign - "%" - followed by exactly two hexadecimal digits |
| 2534 | ** specifying an octet value. ^Before the path or query components of a |
| 2535 | ** URI filename are interpreted, they are encoded using UTF-8 and all |
| 2536 | ** hexadecimal escape sequences replaced by a single byte containing the |
| 2537 | ** corresponding octet. If this process generates an invalid UTF-8 encoding, |
| 2538 | ** the results are undefined. |
| 2539 | ** |
| 2540 | ** <b>Note to Windows users:</b> The encoding used for the filename argument |
| 2541 | ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever |
| 2542 | ** codepage is currently defined. Filenames containing international |
| 2543 | ** characters must be converted to UTF-8 prior to passing them into |
| @@ -2423,10 +2555,30 @@ | |
| 2555 | const char *filename, /* Database filename (UTF-8) */ |
| 2556 | sqlite3 **ppDb, /* OUT: SQLite db handle */ |
| 2557 | int flags, /* Flags */ |
| 2558 | const char *zVfs /* Name of VFS module to use */ |
| 2559 | ); |
| 2560 | |
| 2561 | /* |
| 2562 | ** CAPI3REF: Obtain Values For URI Parameters |
| 2563 | ** |
| 2564 | ** This is a utility routine, useful to VFS implementations, that checks |
| 2565 | ** to see if a database file was a URI that contained a specific query |
| 2566 | ** parameter, and if so obtains the value of the query parameter. |
| 2567 | ** |
| 2568 | ** The zFilename argument is the filename pointer passed into the xOpen() |
| 2569 | ** method of a VFS implementation. The zParam argument is the name of the |
| 2570 | ** query parameter we seek. This routine returns the value of the zParam |
| 2571 | ** parameter if it exists. If the parameter does not exist, this routine |
| 2572 | ** returns a NULL pointer. |
| 2573 | ** |
| 2574 | ** If the zFilename argument to this function is not a pointer that SQLite |
| 2575 | ** passed into the xOpen VFS method, then the behavior of this routine |
| 2576 | ** is undefined and probably undesirable. |
| 2577 | */ |
| 2578 | SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam); |
| 2579 | |
| 2580 | |
| 2581 | /* |
| 2582 | ** CAPI3REF: Error Codes And Messages |
| 2583 | ** |
| 2584 | ** ^The sqlite3_errcode() interface returns the numeric [result code] or |
| @@ -2539,47 +2691,49 @@ | |
| 2691 | ** that can be lowered at run-time using [sqlite3_limit()]. |
| 2692 | ** The synopsis of the meanings of the various limits is shown below. |
| 2693 | ** Additional information is available at [limits | Limits in SQLite]. |
| 2694 | ** |
| 2695 | ** <dl> |
| 2696 | ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt> |
| 2697 | ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^ |
| 2698 | ** |
| 2699 | ** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt> |
| 2700 | ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^ |
| 2701 | ** |
| 2702 | ** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt> |
| 2703 | ** <dd>The maximum number of columns in a table definition or in the |
| 2704 | ** result set of a [SELECT] or the maximum number of columns in an index |
| 2705 | ** or in an ORDER BY or GROUP BY clause.</dd>)^ |
| 2706 | ** |
| 2707 | ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> |
| 2708 | ** <dd>The maximum depth of the parse tree on any expression.</dd>)^ |
| 2709 | ** |
| 2710 | ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt> |
| 2711 | ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^ |
| 2712 | ** |
| 2713 | ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt> |
| 2714 | ** <dd>The maximum number of instructions in a virtual machine program |
| 2715 | ** used to implement an SQL statement. This limit is not currently |
| 2716 | ** enforced, though that might be added in some future release of |
| 2717 | ** SQLite.</dd>)^ |
| 2718 | ** |
| 2719 | ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt> |
| 2720 | ** <dd>The maximum number of arguments on a function.</dd>)^ |
| 2721 | ** |
| 2722 | ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt> |
| 2723 | ** <dd>The maximum number of [ATTACH | attached databases].)^</dd> |
| 2724 | ** |
| 2725 | ** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]] |
| 2726 | ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt> |
| 2727 | ** <dd>The maximum length of the pattern argument to the [LIKE] or |
| 2728 | ** [GLOB] operators.</dd>)^ |
| 2729 | ** |
| 2730 | ** [[SQLITE_LIMIT_VARIABLE_NUMBER]] |
| 2731 | ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> |
| 2732 | ** <dd>The maximum index number of any [parameter] in an SQL statement.)^ |
| 2733 | ** |
| 2734 | ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> |
| 2735 | ** <dd>The maximum depth of recursion for triggers.</dd>)^ |
| 2736 | ** </dl> |
| 2737 | */ |
| 2738 | #define SQLITE_LIMIT_LENGTH 0 |
| 2739 | #define SQLITE_LIMIT_SQL_LENGTH 1 |
| @@ -4610,10 +4764,15 @@ | |
| 4764 | int (*xRollback)(sqlite3_vtab *pVTab); |
| 4765 | int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName, |
| 4766 | void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), |
| 4767 | void **ppArg); |
| 4768 | int (*xRename)(sqlite3_vtab *pVtab, const char *zNew); |
| 4769 | /* The methods above are in version 1 of the sqlite_module object. Those |
| 4770 | ** below are for version 2 and greater. */ |
| 4771 | int (*xSavepoint)(sqlite3_vtab *pVTab, int); |
| 4772 | int (*xRelease)(sqlite3_vtab *pVTab, int); |
| 4773 | int (*xRollbackTo)(sqlite3_vtab *pVTab, int); |
| 4774 | }; |
| 4775 | |
| 4776 | /* |
| 4777 | ** CAPI3REF: Virtual Table Indexing Information |
| 4778 | ** KEYWORDS: sqlite3_index_info |
| @@ -5424,11 +5583,11 @@ | |
| 5583 | ** |
| 5584 | ** ^This interface is used to retrieve runtime status information |
| 5585 | ** about the performance of SQLite, and optionally to reset various |
| 5586 | ** highwater marks. ^The first argument is an integer code for |
| 5587 | ** the specific parameter to measure. ^(Recognized integer codes |
| 5588 | ** are of the form [status parameters | SQLITE_STATUS_...].)^ |
| 5589 | ** ^The current value of the parameter is returned into *pCurrent. |
| 5590 | ** ^The highest recorded value is returned in *pHighwater. ^If the |
| 5591 | ** resetFlag is true, then the highest record value is reset after |
| 5592 | ** *pHighwater is written. ^(Some parameters do not record the highest |
| 5593 | ** value. For those parameters |
| @@ -5451,82 +5610,84 @@ | |
| 5610 | SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); |
| 5611 | |
| 5612 | |
| 5613 | /* |
| 5614 | ** CAPI3REF: Status Parameters |
| 5615 | ** KEYWORDS: {status parameters} |
| 5616 | ** |
| 5617 | ** These integer constants designate various run-time status parameters |
| 5618 | ** that can be returned by [sqlite3_status()]. |
| 5619 | ** |
| 5620 | ** <dl> |
| 5621 | ** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt> |
| 5622 | ** <dd>This parameter is the current amount of memory checked out |
| 5623 | ** using [sqlite3_malloc()], either directly or indirectly. The |
| 5624 | ** figure includes calls made to [sqlite3_malloc()] by the application |
| 5625 | ** and internal memory usage by the SQLite library. Scratch memory |
| 5626 | ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache |
| 5627 | ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in |
| 5628 | ** this parameter. The amount returned is the sum of the allocation |
| 5629 | ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^ |
| 5630 | ** |
| 5631 | ** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt> |
| 5632 | ** <dd>This parameter records the largest memory allocation request |
| 5633 | ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their |
| 5634 | ** internal equivalents). Only the value returned in the |
| 5635 | ** *pHighwater parameter to [sqlite3_status()] is of interest. |
| 5636 | ** The value written into the *pCurrent parameter is undefined.</dd>)^ |
| 5637 | ** |
| 5638 | ** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt> |
| 5639 | ** <dd>This parameter records the number of separate memory allocations |
| 5640 | ** currently checked out.</dd>)^ |
| 5641 | ** |
| 5642 | ** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt> |
| 5643 | ** <dd>This parameter returns the number of pages used out of the |
| 5644 | ** [pagecache memory allocator] that was configured using |
| 5645 | ** [SQLITE_CONFIG_PAGECACHE]. The |
| 5646 | ** value returned is in pages, not in bytes.</dd>)^ |
| 5647 | ** |
| 5648 | ** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]] |
| 5649 | ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt> |
| 5650 | ** <dd>This parameter returns the number of bytes of page cache |
| 5651 | ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE] |
| 5652 | ** buffer and where forced to overflow to [sqlite3_malloc()]. The |
| 5653 | ** returned value includes allocations that overflowed because they |
| 5654 | ** where too large (they were larger than the "sz" parameter to |
| 5655 | ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because |
| 5656 | ** no space was left in the page cache.</dd>)^ |
| 5657 | ** |
| 5658 | ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt> |
| 5659 | ** <dd>This parameter records the largest memory allocation request |
| 5660 | ** handed to [pagecache memory allocator]. Only the value returned in the |
| 5661 | ** *pHighwater parameter to [sqlite3_status()] is of interest. |
| 5662 | ** The value written into the *pCurrent parameter is undefined.</dd>)^ |
| 5663 | ** |
| 5664 | ** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt> |
| 5665 | ** <dd>This parameter returns the number of allocations used out of the |
| 5666 | ** [scratch memory allocator] configured using |
| 5667 | ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not |
| 5668 | ** in bytes. Since a single thread may only have one scratch allocation |
| 5669 | ** outstanding at time, this parameter also reports the number of threads |
| 5670 | ** using scratch memory at the same time.</dd>)^ |
| 5671 | ** |
| 5672 | ** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt> |
| 5673 | ** <dd>This parameter returns the number of bytes of scratch memory |
| 5674 | ** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH] |
| 5675 | ** buffer and where forced to overflow to [sqlite3_malloc()]. The values |
| 5676 | ** returned include overflows because the requested allocation was too |
| 5677 | ** larger (that is, because the requested allocation was larger than the |
| 5678 | ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer |
| 5679 | ** slots were available. |
| 5680 | ** </dd>)^ |
| 5681 | ** |
| 5682 | ** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt> |
| 5683 | ** <dd>This parameter records the largest memory allocation request |
| 5684 | ** handed to [scratch memory allocator]. Only the value returned in the |
| 5685 | ** *pHighwater parameter to [sqlite3_status()] is of interest. |
| 5686 | ** The value written into the *pCurrent parameter is undefined.</dd>)^ |
| 5687 | ** |
| 5688 | ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt> |
| 5689 | ** <dd>This parameter records the deepest parser stack. It is only |
| 5690 | ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^ |
| 5691 | ** </dl> |
| 5692 | ** |
| 5693 | ** New status parameters may be added from time to time. |
| @@ -5547,13 +5708,13 @@ | |
| 5708 | ** |
| 5709 | ** ^This interface is used to retrieve runtime status information |
| 5710 | ** about a single [database connection]. ^The first argument is the |
| 5711 | ** database connection object to be interrogated. ^The second argument |
| 5712 | ** is an integer constant, taken from the set of |
| 5713 | ** [SQLITE_DBSTATUS options], that |
| 5714 | ** determines the parameter to interrogate. The set of |
| 5715 | ** [SQLITE_DBSTATUS options] is likely |
| 5716 | ** to grow in future releases of SQLite. |
| 5717 | ** |
| 5718 | ** ^The current value of the requested parameter is written into *pCur |
| 5719 | ** and the highest instantaneous value is written into *pHiwtr. ^If |
| 5720 | ** the resetFlg is true, then the highest instantaneous value is |
| @@ -5566,10 +5727,11 @@ | |
| 5727 | */ |
| 5728 | SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); |
| 5729 | |
| 5730 | /* |
| 5731 | ** CAPI3REF: Status Parameters for database connections |
| 5732 | ** KEYWORDS: {SQLITE_DBSTATUS options} |
| 5733 | ** |
| 5734 | ** These constants are the available integer "verbs" that can be passed as |
| 5735 | ** the second argument to the [sqlite3_db_status()] interface. |
| 5736 | ** |
| 5737 | ** New verbs may be added in future releases of SQLite. Existing verbs |
| @@ -5577,48 +5739,50 @@ | |
| 5739 | ** [sqlite3_db_status()] to make sure that the call worked. |
| 5740 | ** The [sqlite3_db_status()] interface will return a non-zero error code |
| 5741 | ** if a discontinued or unsupported verb is invoked. |
| 5742 | ** |
| 5743 | ** <dl> |
| 5744 | ** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt> |
| 5745 | ** <dd>This parameter returns the number of lookaside memory slots currently |
| 5746 | ** checked out.</dd>)^ |
| 5747 | ** |
| 5748 | ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt> |
| 5749 | ** <dd>This parameter returns the number malloc attempts that were |
| 5750 | ** satisfied using lookaside memory. Only the high-water value is meaningful; |
| 5751 | ** the current value is always zero.)^ |
| 5752 | ** |
| 5753 | ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]] |
| 5754 | ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt> |
| 5755 | ** <dd>This parameter returns the number malloc attempts that might have |
| 5756 | ** been satisfied using lookaside memory but failed due to the amount of |
| 5757 | ** memory requested being larger than the lookaside slot size. |
| 5758 | ** Only the high-water value is meaningful; |
| 5759 | ** the current value is always zero.)^ |
| 5760 | ** |
| 5761 | ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]] |
| 5762 | ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt> |
| 5763 | ** <dd>This parameter returns the number malloc attempts that might have |
| 5764 | ** been satisfied using lookaside memory but failed due to all lookaside |
| 5765 | ** memory already being in use. |
| 5766 | ** Only the high-water value is meaningful; |
| 5767 | ** the current value is always zero.)^ |
| 5768 | ** |
| 5769 | ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt> |
| 5770 | ** <dd>This parameter returns the approximate number of of bytes of heap |
| 5771 | ** memory used by all pager caches associated with the database connection.)^ |
| 5772 | ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0. |
| 5773 | ** |
| 5774 | ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt> |
| 5775 | ** <dd>This parameter returns the approximate number of of bytes of heap |
| 5776 | ** memory used to store the schema for all databases associated |
| 5777 | ** with the connection - main, temp, and any [ATTACH]-ed databases.)^ |
| 5778 | ** ^The full amount of memory used by the schemas is reported, even if the |
| 5779 | ** schema memory is shared with other database connections due to |
| 5780 | ** [shared cache mode] being enabled. |
| 5781 | ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0. |
| 5782 | ** |
| 5783 | ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt> |
| 5784 | ** <dd>This parameter returns the approximate number of of bytes of heap |
| 5785 | ** and lookaside memory used by all prepared statements associated with |
| 5786 | ** the database connection.)^ |
| 5787 | ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0. |
| 5788 | ** </dd> |
| @@ -5636,11 +5800,11 @@ | |
| 5800 | |
| 5801 | /* |
| 5802 | ** CAPI3REF: Prepared Statement Status |
| 5803 | ** |
| 5804 | ** ^(Each prepared statement maintains various |
| 5805 | ** [SQLITE_STMTSTATUS counters] that measure the number |
| 5806 | ** of times it has performed specific operations.)^ These counters can |
| 5807 | ** be used to monitor the performance characteristics of the prepared |
| 5808 | ** statements. For example, if the number of table steps greatly exceeds |
| 5809 | ** the number of table searches or result rows, that would tend to indicate |
| 5810 | ** that the prepared statement is using a full table scan rather than |
| @@ -5647,11 +5811,11 @@ | |
| 5811 | ** an index. |
| 5812 | ** |
| 5813 | ** ^(This interface is used to retrieve and reset counter values from |
| 5814 | ** a [prepared statement]. The first argument is the prepared statement |
| 5815 | ** object to be interrogated. The second argument |
| 5816 | ** is an integer code for a specific [SQLITE_STMTSTATUS counter] |
| 5817 | ** to be interrogated.)^ |
| 5818 | ** ^The current value of the requested counter is returned. |
| 5819 | ** ^If the resetFlg is true, then the counter is reset to zero after this |
| 5820 | ** interface call returns. |
| 5821 | ** |
| @@ -5659,28 +5823,29 @@ | |
| 5823 | */ |
| 5824 | SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); |
| 5825 | |
| 5826 | /* |
| 5827 | ** CAPI3REF: Status Parameters for prepared statements |
| 5828 | ** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters} |
| 5829 | ** |
| 5830 | ** These preprocessor macros define integer codes that name counter |
| 5831 | ** values associated with the [sqlite3_stmt_status()] interface. |
| 5832 | ** The meanings of the various counters are as follows: |
| 5833 | ** |
| 5834 | ** <dl> |
| 5835 | ** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt> |
| 5836 | ** <dd>^This is the number of times that SQLite has stepped forward in |
| 5837 | ** a table as part of a full table scan. Large numbers for this counter |
| 5838 | ** may indicate opportunities for performance improvement through |
| 5839 | ** careful use of indices.</dd> |
| 5840 | ** |
| 5841 | ** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt> |
| 5842 | ** <dd>^This is the number of sort operations that have occurred. |
| 5843 | ** A non-zero value in this counter may indicate an opportunity to |
| 5844 | ** improvement performance through careful use of indices.</dd> |
| 5845 | ** |
| 5846 | ** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt> |
| 5847 | ** <dd>^This is the number of rows inserted into transient indices that |
| 5848 | ** were created automatically in order to help joins run faster. |
| 5849 | ** A non-zero value in this counter may indicate an opportunity to |
| 5850 | ** improvement performance by adding permanent indices that do not |
| 5851 | ** need to be reinitialized each time the statement is run.</dd> |
| @@ -5727,10 +5892,11 @@ | |
| 5892 | ** ^(The contents of the sqlite3_pcache_methods structure are copied to an |
| 5893 | ** internal buffer by SQLite within the call to [sqlite3_config]. Hence |
| 5894 | ** the application may discard the parameter after the call to |
| 5895 | ** [sqlite3_config()] returns.)^ |
| 5896 | ** |
| 5897 | ** [[the xInit() page cache method]] |
| 5898 | ** ^(The xInit() method is called once for each effective |
| 5899 | ** call to [sqlite3_initialize()])^ |
| 5900 | ** (usually only once during the lifetime of the process). ^(The xInit() |
| 5901 | ** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^ |
| 5902 | ** The intent of the xInit() method is to set up global data structures |
| @@ -5737,10 +5903,11 @@ | |
| 5903 | ** required by the custom page cache implementation. |
| 5904 | ** ^(If the xInit() method is NULL, then the |
| 5905 | ** built-in default page cache is used instead of the application defined |
| 5906 | ** page cache.)^ |
| 5907 | ** |
| 5908 | ** [[the xShutdown() page cache method]] |
| 5909 | ** ^The xShutdown() method is called by [sqlite3_shutdown()]. |
| 5910 | ** It can be used to clean up |
| 5911 | ** any outstanding resources before process shutdown, if required. |
| 5912 | ** ^The xShutdown() method may be NULL. |
| 5913 | ** |
| @@ -5751,10 +5918,11 @@ | |
| 5918 | ** in multithreaded applications. |
| 5919 | ** |
| 5920 | ** ^SQLite will never invoke xInit() more than once without an intervening |
| 5921 | ** call to xShutdown(). |
| 5922 | ** |
| 5923 | ** [[the xCreate() page cache methods]] |
| 5924 | ** ^SQLite invokes the xCreate() method to construct a new cache instance. |
| 5925 | ** SQLite will typically create one cache instance for each open database file, |
| 5926 | ** though this is not guaranteed. ^The |
| 5927 | ** first parameter, szPage, is the size in bytes of the pages that must |
| 5928 | ** be allocated by the cache. ^szPage will not be a power of two. ^szPage |
| @@ -5775,20 +5943,23 @@ | |
| 5943 | ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to |
| 5944 | ** false will always have the "discard" flag set to true. |
| 5945 | ** ^Hence, a cache created with bPurgeable false will |
| 5946 | ** never contain any unpinned pages. |
| 5947 | ** |
| 5948 | ** [[the xCachesize() page cache method]] |
| 5949 | ** ^(The xCachesize() method may be called at any time by SQLite to set the |
| 5950 | ** suggested maximum cache-size (number of pages stored by) the cache |
| 5951 | ** instance passed as the first argument. This is the value configured using |
| 5952 | ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable |
| 5953 | ** parameter, the implementation is not required to do anything with this |
| 5954 | ** value; it is advisory only. |
| 5955 | ** |
| 5956 | ** [[the xPagecount() page cache methods]] |
| 5957 | ** The xPagecount() method must return the number of pages currently |
| 5958 | ** stored in the cache, both pinned and unpinned. |
| 5959 | ** |
| 5960 | ** [[the xFetch() page cache methods]] |
| 5961 | ** The xFetch() method locates a page in the cache and returns a pointer to |
| 5962 | ** the page, or a NULL pointer. |
| 5963 | ** A "page", in this context, means a buffer of szPage bytes aligned at an |
| 5964 | ** 8-byte boundary. The page to be fetched is determined by the key. ^The |
| 5965 | ** mimimum key value is 1. After it has been retrieved using xFetch, the page |
| @@ -5813,10 +5984,11 @@ | |
| 5984 | ** will only use a createFlag of 2 after a prior call with a createFlag of 1 |
| 5985 | ** failed.)^ In between the to xFetch() calls, SQLite may |
| 5986 | ** attempt to unpin one or more cache pages by spilling the content of |
| 5987 | ** pinned pages to disk and synching the operating system disk cache. |
| 5988 | ** |
| 5989 | ** [[the xUnpin() page cache method]] |
| 5990 | ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page |
| 5991 | ** as its second argument. If the third parameter, discard, is non-zero, |
| 5992 | ** then the page must be evicted from the cache. |
| 5993 | ** ^If the discard parameter is |
| 5994 | ** zero, then the page may be discarded or retained at the discretion of |
| @@ -5825,10 +5997,11 @@ | |
| 5997 | ** |
| 5998 | ** The cache must not perform any reference counting. A single |
| 5999 | ** call to xUnpin() unpins the page regardless of the number of prior calls |
| 6000 | ** to xFetch(). |
| 6001 | ** |
| 6002 | ** [[the xRekey() page cache methods]] |
| 6003 | ** The xRekey() method is used to change the key value associated with the |
| 6004 | ** page passed as the second argument. If the cache |
| 6005 | ** previously contains an entry associated with newKey, it must be |
| 6006 | ** discarded. ^Any prior cache entry associated with newKey is guaranteed not |
| 6007 | ** to be pinned. |
| @@ -5837,10 +6010,11 @@ | |
| 6010 | ** existing cache entries with page numbers (keys) greater than or equal |
| 6011 | ** to the value of the iLimit parameter passed to xTruncate(). If any |
| 6012 | ** of these pages are pinned, they are implicitly unpinned, meaning that |
| 6013 | ** they can be safely discarded. |
| 6014 | ** |
| 6015 | ** [[the xDestroy() page cache method]] |
| 6016 | ** ^The xDestroy() method is used to delete a cache allocated by xCreate(). |
| 6017 | ** All resources associated with the specified cache should be freed. ^After |
| 6018 | ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*] |
| 6019 | ** handle invalid, and will not use it with any other sqlite3_pcache_methods |
| 6020 | ** functions. |
| @@ -5899,11 +6073,11 @@ | |
| 6073 | ** associated with the backup operation. |
| 6074 | ** </ol>)^ |
| 6075 | ** There should be exactly one call to sqlite3_backup_finish() for each |
| 6076 | ** successful call to sqlite3_backup_init(). |
| 6077 | ** |
| 6078 | ** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b> |
| 6079 | ** |
| 6080 | ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the |
| 6081 | ** [database connection] associated with the destination database |
| 6082 | ** and the database name, respectively. |
| 6083 | ** ^The database name is "main" for the main database, "temp" for the |
| @@ -5926,11 +6100,11 @@ | |
| 6100 | ** [sqlite3_backup] object. |
| 6101 | ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and |
| 6102 | ** sqlite3_backup_finish() functions to perform the specified backup |
| 6103 | ** operation. |
| 6104 | ** |
| 6105 | ** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b> |
| 6106 | ** |
| 6107 | ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between |
| 6108 | ** the source and destination databases specified by [sqlite3_backup] object B. |
| 6109 | ** ^If N is negative, all remaining source pages are copied. |
| 6110 | ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there |
| @@ -5983,11 +6157,11 @@ | |
| 6157 | ** restarted by the next call to sqlite3_backup_step(). ^If the source |
| 6158 | ** database is modified by the using the same database connection as is used |
| 6159 | ** by the backup operation, then the backup database is automatically |
| 6160 | ** updated at the same time. |
| 6161 | ** |
| 6162 | ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b> |
| 6163 | ** |
| 6164 | ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the |
| 6165 | ** application wishes to abandon the backup operation, the application |
| 6166 | ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish(). |
| 6167 | ** ^The sqlite3_backup_finish() interfaces releases all |
| @@ -6006,11 +6180,12 @@ | |
| 6180 | ** |
| 6181 | ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step() |
| 6182 | ** is not a permanent error and does not affect the return value of |
| 6183 | ** sqlite3_backup_finish(). |
| 6184 | ** |
| 6185 | ** [[sqlite3_backup__remaining()]] [[sqlite3_backup_pagecount()]] |
| 6186 | ** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b> |
| 6187 | ** |
| 6188 | ** ^Each call to sqlite3_backup_step() sets two values inside |
| 6189 | ** the [sqlite3_backup] object: the number of pages still to be backed |
| 6190 | ** up and the total number of pages in the source database file. |
| 6191 | ** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces |
| @@ -6391,10 +6566,97 @@ | |
| 6566 | ** each of these values. |
| 6567 | */ |
| 6568 | #define SQLITE_CHECKPOINT_PASSIVE 0 |
| 6569 | #define SQLITE_CHECKPOINT_FULL 1 |
| 6570 | #define SQLITE_CHECKPOINT_RESTART 2 |
| 6571 | |
| 6572 | /* |
| 6573 | ** CAPI3REF: Virtual Table Interface Configuration |
| 6574 | ** |
| 6575 | ** This function may be called by either the [xConnect] or [xCreate] method |
| 6576 | ** of a [virtual table] implementation to configure |
| 6577 | ** various facets of the virtual table interface. |
| 6578 | ** |
| 6579 | ** If this interface is invoked outside the context of an xConnect or |
| 6580 | ** xCreate virtual table method then the behavior is undefined. |
| 6581 | ** |
| 6582 | ** At present, there is only one option that may be configured using |
| 6583 | ** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].) Further options |
| 6584 | ** may be added in the future. |
| 6585 | */ |
| 6586 | SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...); |
| 6587 | |
| 6588 | /* |
| 6589 | ** CAPI3REF: Virtual Table Configuration Options |
| 6590 | ** |
| 6591 | ** These macros define the various options to the |
| 6592 | ** [sqlite3_vtab_config()] interface that [virtual table] implementations |
| 6593 | ** can use to customize and optimize their behavior. |
| 6594 | ** |
| 6595 | ** <dl> |
| 6596 | ** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT |
| 6597 | ** <dd>Calls of the form |
| 6598 | ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported, |
| 6599 | ** where X is an integer. If X is zero, then the [virtual table] whose |
| 6600 | ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not |
| 6601 | ** support constraints. In this configuration (which is the default) if |
| 6602 | ** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire |
| 6603 | ** statement is rolled back as if [ON CONFLICT | OR ABORT] had been |
| 6604 | ** specified as part of the users SQL statement, regardless of the actual |
| 6605 | ** ON CONFLICT mode specified. |
| 6606 | ** |
| 6607 | ** If X is non-zero, then the virtual table implementation guarantees |
| 6608 | ** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before |
| 6609 | ** any modifications to internal or persistent data structures have been made. |
| 6610 | ** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite |
| 6611 | ** is able to roll back a statement or database transaction, and abandon |
| 6612 | ** or continue processing the current SQL statement as appropriate. |
| 6613 | ** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns |
| 6614 | ** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode |
| 6615 | ** had been ABORT. |
| 6616 | ** |
| 6617 | ** Virtual table implementations that are required to handle OR REPLACE |
| 6618 | ** must do so within the [xUpdate] method. If a call to the |
| 6619 | ** [sqlite3_vtab_on_conflict()] function indicates that the current ON |
| 6620 | ** CONFLICT policy is REPLACE, the virtual table implementation should |
| 6621 | ** silently replace the appropriate rows within the xUpdate callback and |
| 6622 | ** return SQLITE_OK. Or, if this is not possible, it may return |
| 6623 | ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT |
| 6624 | ** constraint handling. |
| 6625 | ** </dl> |
| 6626 | */ |
| 6627 | #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1 |
| 6628 | |
| 6629 | /* |
| 6630 | ** CAPI3REF: Determine The Virtual Table Conflict Policy |
| 6631 | ** |
| 6632 | ** This function may only be called from within a call to the [xUpdate] method |
| 6633 | ** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The |
| 6634 | ** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL], |
| 6635 | ** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode |
| 6636 | ** of the SQL statement that triggered the call to the [xUpdate] method of the |
| 6637 | ** [virtual table]. |
| 6638 | */ |
| 6639 | SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *); |
| 6640 | |
| 6641 | /* |
| 6642 | ** CAPI3REF: Conflict resolution modes |
| 6643 | ** |
| 6644 | ** These constants are returned by [sqlite3_vtab_on_conflict()] to |
| 6645 | ** inform a [virtual table] implementation what the [ON CONFLICT] mode |
| 6646 | ** is for the SQL statement being evaluated. |
| 6647 | ** |
| 6648 | ** Note that the [SQLITE_IGNORE] constant is also used as a potential |
| 6649 | ** return value from the [sqlite3_set_authorizer()] callback and that |
| 6650 | ** [SQLITE_ABORT] is also a [result code]. |
| 6651 | */ |
| 6652 | #define SQLITE_ROLLBACK 1 |
| 6653 | /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */ |
| 6654 | #define SQLITE_FAIL 3 |
| 6655 | /* #define SQLITE_ABORT 4 // Also an error code */ |
| 6656 | #define SQLITE_REPLACE 5 |
| 6657 | |
| 6658 | |
| 6659 | |
| 6660 | /* |
| 6661 | ** Undo the hack that converts floating point types to integer for |
| 6662 | ** builds on processors without floating point support. |
| 6663 |