| | @@ -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 | |