Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Comment: | Merge fix for [5251bd0878]. Update SQLite core library to the latest trunk code. Bump version to 1.0.100.0. Update version history docs. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
59a224a9cfabfbfce1f294107341fc7b |
User & Date: | mistachkin 2015-12-31 22:58:57 |
2016-01-05
| ||
18:54 | Update SQLite core library to the latest trunk code. check-in: 70629abeb3 user: mistachkin tags: trunk | |
2015-12-31
| ||
22:58 | Merge fix for [5251bd0878]. Update SQLite core library to the latest trunk code. Bump version to 1.0.100.0. Update version history docs. check-in: 59a224a9cf user: mistachkin tags: trunk | |
22:58 | Merge System.Data.SQLite changes necessary to integrate with SQLite 3.10.0. Closed-Leaf check-in: b70f7a74f8 user: mistachkin tags: updates | |
2015-12-20
| ||
07:13 | Use save/restore semantics for environment variables modified by the test suite infrastructure. check-in: 90e981ea2d user: mistachkin tags: trunk | |
Changes to Doc/Extra/Provider/dbfactorysupport.html.
81 81 <configuration> 82 82 <system.data> 83 83 <DbProviderFactories> 84 84 <remove invariant="System.Data.SQLite"/> 85 85 <add name="SQLite Data Provider" invariant="System.Data.SQLite" 86 86 description=".NET Framework Data Provider for SQLite" 87 87 type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, 88 - Version=1.0.99.0, Culture=neutral, 88 + Version=1.0.100.0, Culture=neutral, 89 89 PublicKeyToken=db937bc2d44ff139"/> 90 90 </DbProviderFactories> 91 91 </system.data> 92 92 </configuration> 93 93 </pre> 94 94 </div> 95 95 <p>
Changes to Doc/Extra/Provider/version.html.
39 39 </td> 40 40 </tr> 41 41 </table> 42 42 </div> 43 43 <div id="mainSection"> 44 44 <div id="mainBody"> 45 45 <h1 class="heading">Version History</h1> 46 + <p><b>1.0.100.0 - February XX, 2016 <font color="red">(release scheduled)</font></b></p> 47 + <ul> 48 + <li>Updated to <a href="https://www.sqlite.org/draft/releaselog/3_10_0.html">SQLite 3.10.0</a>.</li> 49 + <li>Properly handle NULL values in the "name" column of the results returned by PRAGMA index_info(). Fix for <a href="https://system.data.sqlite.org/index.html/info/5251bd0878">[5251bd0878]</a>.</li> 50 + </ul> 46 51 <p><b>1.0.99.0 - December 9, 2015</b></p> 47 52 <ul> 48 53 <li>Updated to <a href="https://www.sqlite.org/releaselog/3_9_2.html">SQLite 3.9.2</a>.</li> 49 54 <li>Add preliminary support for the .NET Framework 4.6.1.</li> 50 55 <li>Fix handling of sqlite3_index_info members not available with older versions of the SQLite core library. <b>** Potentially Incompatible Change **</b></li> 51 56 <li>Update and improve documentation comments for the native virtual table methods.</li> 52 57 <li>Permit an existing registered function to be replaced. Fix for <a href="https://system.data.sqlite.org/index.html/info/2556655d1b">[2556655d1b]</a>.</li>
Changes to Doc/Extra/Provider/welcome.html.
156 156 <font color="red"> 157 157 Itanium processor support not currently included. 158 158 </font> 159 159 </p> 160 160 <h1 class="heading">Distributing the Binaries (Compact Framework)</h1> 161 161 <p>Both the <b>System.Data.SQLite.DLL </b>and <b>SQLite.Interop.XXX.DLL</b> files 162 162 must be deployed on the Compact Framework. The XXX is the build number of 163 - the System.Data.SQLite library (e.g. "099"). The 163 + the System.Data.SQLite library (e.g. "100"). The 164 164 <b>SQLite.Interop.XXX.DLL</b> file is a fully native assembly compiled for 165 165 the ARM processor, and System.Data.SQLite is the fully-managed Compact 166 166 Framework assembly.</p> 167 167 <hr /> 168 168 <div id="footer"> 169 169 <p> 170 170 <a href="mailto:sqlite-users@mailinglists.sqlite.org?subject=SQLite.NET%20Class%20Library%20Documentation%20Feedback:%20Welcome"> 171 171 Send comments on this topic.<!--[if gte IE 5]><tool:tip element="seeAlsoToolTip" avoidmouse="false" /><tool:tip element="languageFilterToolTip" avoidmouse="false" /><![endif]--> </div> 172 172 </div> 173 173 </body> 174 174 </html>
Changes to NuGet/SQLite.Beta.nuspec.
7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <package> 11 11 <metadata> 12 12 <id>System.Data.SQLite.Beta</id> 13 13 <title>System.Data.SQLite (x86/x64) Beta</title> 14 - <version>1.0.99.0</version> 14 + <version>1.0.100.0</version> 15 15 <authors>SQLite Development Team</authors> 16 16 <description>This is a "beta" package and is not intended for production use. The official SQLite database engine for both x86 and x64 along with the ADO.NET provider. This package includes support for LINQ and Entity Framework 6.</description> 17 17 <language>en-US</language> 18 18 <projectUrl>https://system.data.sqlite.org/</projectUrl> 19 19 <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl> 20 20 <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl> 21 21 <tags>sqlite database ado.net provider interop</tags> 22 22 <copyright>Public Domain</copyright> 23 23 <dependencies> 24 24 <group targetFramework="net20"> 25 - <dependency id="System.Data.SQLite.Core.Beta" version="1.0.99.0" /> 25 + <dependency id="System.Data.SQLite.Core.Beta" version="1.0.100.0" /> 26 26 </group> 27 27 <group targetFramework="net40"> 28 - <dependency id="System.Data.SQLite.Core.Beta" version="1.0.99.0" /> 28 + <dependency id="System.Data.SQLite.Core.Beta" version="1.0.100.0" /> 29 29 </group> 30 30 <group targetFramework="net45"> 31 - <dependency id="System.Data.SQLite.Core.Beta" version="1.0.99.0" /> 31 + <dependency id="System.Data.SQLite.Core.Beta" version="1.0.100.0" /> 32 32 </group> 33 33 <group targetFramework="net451"> 34 - <dependency id="System.Data.SQLite.Core.Beta" version="1.0.99.0" /> 34 + <dependency id="System.Data.SQLite.Core.Beta" version="1.0.100.0" /> 35 35 </group> 36 36 <group targetFramework="net46"> 37 - <dependency id="System.Data.SQLite.Core.Beta" version="1.0.99.0" /> 37 + <dependency id="System.Data.SQLite.Core.Beta" version="1.0.100.0" /> 38 38 </group> 39 39 <group targetFramework="net20"> 40 - <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" /> 40 + <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.100.0" /> 41 41 </group> 42 42 <group targetFramework="net40"> 43 - <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" /> 43 + <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.100.0" /> 44 44 </group> 45 45 <group targetFramework="net45"> 46 - <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" /> 46 + <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.100.0" /> 47 47 </group> 48 48 <group targetFramework="net451"> 49 - <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" /> 49 + <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.100.0" /> 50 50 </group> 51 51 <group targetFramework="net46"> 52 - <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" /> 52 + <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.100.0" /> 53 53 </group> 54 54 <group targetFramework="net40"> 55 - <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.0" /> 55 + <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.100.0" /> 56 56 </group> 57 57 <group targetFramework="net45"> 58 - <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.0" /> 58 + <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.100.0" /> 59 59 </group> 60 60 <group targetFramework="net451"> 61 - <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.0" /> 61 + <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.100.0" /> 62 62 </group> 63 63 <group targetFramework="net46"> 64 - <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.0" /> 64 + <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.100.0" /> 65 65 </group> 66 66 </dependencies> 67 67 </metadata> 68 68 <files /> 69 69 </package>
Changes to NuGet/SQLite.Core.Beta.nuspec.
7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <package> 11 11 <metadata> 12 12 <id>System.Data.SQLite.Core.Beta</id> 13 13 <title>System.Data.SQLite Core (x86/x64) Beta</title> 14 - <version>1.0.99.0</version> 14 + <version>1.0.100.0</version> 15 15 <authors>SQLite Development Team</authors> 16 16 <description>This is a "beta" package and is not intended for production use. The official SQLite database engine for both x86 and x64 along with the ADO.NET provider.</description> 17 17 <language>en-US</language> 18 18 <projectUrl>https://system.data.sqlite.org/</projectUrl> 19 19 <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl> 20 20 <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl> 21 21 <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.Core.MSIL.Beta.nuspec.
7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <package> 11 11 <metadata> 12 12 <id>System.Data.SQLite.Core.MSIL.Beta</id> 13 13 <title>System.Data.SQLite (MSIL) Beta</title> 14 - <version>1.0.99.0</version> 14 + <version>1.0.100.0</version> 15 15 <authors>SQLite Development Team</authors> 16 16 <description>This is a "beta" package and is not intended for production use. An ADO.NET provider for SQLite (managed-only).</description> 17 17 <language>en-US</language> 18 18 <projectUrl>https://system.data.sqlite.org/</projectUrl> 19 19 <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl> 20 20 <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl> 21 21 <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.Core.MSIL.Test.nuspec.
7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <package> 11 11 <metadata> 12 12 <id>System.Data.SQLite.Core.MSIL.Test</id> 13 13 <title>System.Data.SQLite (MSIL) Test</title> 14 - <version>1.0.99.0</version> 14 + <version>1.0.100.0</version> 15 15 <authors>SQLite Development Team</authors> 16 16 <description>This is a pre-release package and is not intended for production use. An ADO.NET provider for SQLite (managed-only).</description> 17 17 <language>en-US</language> 18 18 <projectUrl>https://system.data.sqlite.org/</projectUrl> 19 19 <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl> 20 20 <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl> 21 21 <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.Core.MSIL.nuspec.
7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <package> 11 11 <metadata> 12 12 <id>System.Data.SQLite.Core.MSIL</id> 13 13 <title>System.Data.SQLite Core (MSIL)</title> 14 - <version>1.0.99.0</version> 14 + <version>1.0.100.0</version> 15 15 <authors>SQLite Development Team</authors> 16 16 <description>An ADO.NET provider for SQLite (managed-only).</description> 17 17 <language>en-US</language> 18 18 <projectUrl>https://system.data.sqlite.org/</projectUrl> 19 19 <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl> 20 20 <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl> 21 21 <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.Core.Test.nuspec.
7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <package> 11 11 <metadata> 12 12 <id>System.Data.SQLite.Core.Test</id> 13 13 <title>System.Data.SQLite Core (x86/x64) Test</title> 14 - <version>1.0.99.0</version> 14 + <version>1.0.100.0</version> 15 15 <authors>SQLite Development Team</authors> 16 16 <description>This is a pre-release package and is not intended for production use. The official SQLite database engine for both x86 and x64 along with the ADO.NET provider.</description> 17 17 <language>en-US</language> 18 18 <projectUrl>https://system.data.sqlite.org/</projectUrl> 19 19 <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl> 20 20 <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl> 21 21 <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.Core.nuspec.
7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <package> 11 11 <metadata> 12 12 <id>System.Data.SQLite.Core</id> 13 13 <title>System.Data.SQLite Core (x86/x64)</title> 14 - <version>1.0.99.0</version> 14 + <version>1.0.100.0</version> 15 15 <authors>SQLite Development Team</authors> 16 16 <description>The official SQLite database engine for both x86 and x64 along with the ADO.NET provider.</description> 17 17 <language>en-US</language> 18 18 <projectUrl>https://system.data.sqlite.org/</projectUrl> 19 19 <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl> 20 20 <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl> 21 21 <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.EF6.Beta.nuspec.
7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <package> 11 11 <metadata> 12 12 <id>System.Data.SQLite.EF6.Beta</id> 13 13 <title>System.Data.SQLite EF6 Beta</title> 14 - <version>1.0.99.0</version> 14 + <version>1.0.100.0</version> 15 15 <authors>SQLite Development Team</authors> 16 16 <description>This is a "beta" package and is not intended for production use. Support for Entity Framework 6 using System.Data.SQLite.</description> 17 17 <language>en-US</language> 18 18 <projectUrl>https://system.data.sqlite.org/</projectUrl> 19 19 <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl> 20 20 <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl> 21 21 <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.EF6.Test.nuspec.
7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <package> 11 11 <metadata> 12 12 <id>System.Data.SQLite.EF6.Test</id> 13 13 <title>System.Data.SQLite EF6 Test</title> 14 - <version>1.0.99.0</version> 14 + <version>1.0.100.0</version> 15 15 <authors>SQLite Development Team</authors> 16 16 <description>This is a pre-release package and is not intended for production use. Support for Entity Framework 6 using System.Data.SQLite.</description> 17 17 <language>en-US</language> 18 18 <projectUrl>https://system.data.sqlite.org/</projectUrl> 19 19 <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl> 20 20 <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl> 21 21 <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.EF6.nuspec.
7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <package> 11 11 <metadata> 12 12 <id>System.Data.SQLite.EF6</id> 13 13 <title>System.Data.SQLite EF6</title> 14 - <version>1.0.99.0</version> 14 + <version>1.0.100.0</version> 15 15 <authors>SQLite Development Team</authors> 16 16 <description>Support for Entity Framework 6 using System.Data.SQLite.</description> 17 17 <language>en-US</language> 18 18 <projectUrl>https://system.data.sqlite.org/</projectUrl> 19 19 <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl> 20 20 <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl> 21 21 <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.Linq.Beta.nuspec.
7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <package> 11 11 <metadata> 12 12 <id>System.Data.SQLite.Linq.Beta</id> 13 13 <title>System.Data.SQLite LINQ Beta</title> 14 - <version>1.0.99.0</version> 14 + <version>1.0.100.0</version> 15 15 <authors>SQLite Development Team</authors> 16 16 <description>This is a "beta" package and is not intended for production use. Support for LINQ using System.Data.SQLite.</description> 17 17 <language>en-US</language> 18 18 <projectUrl>https://system.data.sqlite.org/</projectUrl> 19 19 <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl> 20 20 <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl> 21 21 <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.Linq.Test.nuspec.
7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <package> 11 11 <metadata> 12 12 <id>System.Data.SQLite.Linq.Test</id> 13 13 <title>System.Data.SQLite LINQ Test</title> 14 - <version>1.0.99.0</version> 14 + <version>1.0.100.0</version> 15 15 <authors>SQLite Development Team</authors> 16 16 <description>This is a pre-release package and is not intended for production use. Support for LINQ using System.Data.SQLite.</description> 17 17 <language>en-US</language> 18 18 <projectUrl>https://system.data.sqlite.org/</projectUrl> 19 19 <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl> 20 20 <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl> 21 21 <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.Linq.nuspec.
7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <package> 11 11 <metadata> 12 12 <id>System.Data.SQLite.Linq</id> 13 13 <title>System.Data.SQLite LINQ</title> 14 - <version>1.0.99.0</version> 14 + <version>1.0.100.0</version> 15 15 <authors>SQLite Development Team</authors> 16 16 <description>Support for LINQ using System.Data.SQLite.</description> 17 17 <language>en-US</language> 18 18 <projectUrl>https://system.data.sqlite.org/</projectUrl> 19 19 <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl> 20 20 <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl> 21 21 <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.MSIL.Beta.nuspec.
7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <package> 11 11 <metadata> 12 12 <id>System.Data.SQLite.MSIL.Beta</id> 13 13 <title>System.Data.SQLite (MSIL) Beta</title> 14 - <version>1.0.99.0</version> 14 + <version>1.0.100.0</version> 15 15 <authors>SQLite Development Team</authors> 16 16 <description>This is a "beta" package and is not intended for production use. This is a legacy package; if possible, please use either the "System.Data.SQLite.Beta" or "System.Data.SQLite.Core.Beta" package instead. An ADO.NET provider for SQLite (managed-only).</description> 17 17 <language>en-US</language> 18 18 <projectUrl>https://system.data.sqlite.org/</projectUrl> 19 19 <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl> 20 20 <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl> 21 21 <tags>sqlite database ado.net provider interop</tags> 22 22 <copyright>Public Domain</copyright> 23 23 <dependencies> 24 24 <group targetFramework="net20"> 25 - <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.99.0" /> 25 + <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.100.0" /> 26 26 </group> 27 27 <group targetFramework="net40"> 28 - <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.99.0" /> 28 + <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.100.0" /> 29 29 </group> 30 30 <group targetFramework="net45"> 31 - <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.99.0" /> 31 + <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.100.0" /> 32 32 </group> 33 33 <group targetFramework="net451"> 34 - <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.99.0" /> 34 + <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.100.0" /> 35 35 </group> 36 36 <group targetFramework="net46"> 37 - <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.99.0" /> 37 + <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.100.0" /> 38 38 </group> 39 39 <group targetFramework="net20"> 40 - <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" /> 40 + <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.100.0" /> 41 41 </group> 42 42 <group targetFramework="net40"> 43 - <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" /> 43 + <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.100.0" /> 44 44 </group> 45 45 <group targetFramework="net45"> 46 - <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" /> 46 + <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.100.0" /> 47 47 </group> 48 48 <group targetFramework="net451"> 49 - <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" /> 49 + <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.100.0" /> 50 50 </group> 51 51 <group targetFramework="net46"> 52 - <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" /> 52 + <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.100.0" /> 53 53 </group> 54 54 <group targetFramework="net40"> 55 - <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.0" /> 55 + <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.100.0" /> 56 56 </group> 57 57 <group targetFramework="net45"> 58 - <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.0" /> 58 + <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.100.0" /> 59 59 </group> 60 60 <group targetFramework="net451"> 61 - <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.0" /> 61 + <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.100.0" /> 62 62 </group> 63 63 <group targetFramework="net46"> 64 - <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.0" /> 64 + <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.100.0" /> 65 65 </group> 66 66 </dependencies> 67 67 </metadata> 68 68 <files /> 69 69 </package>
Changes to NuGet/SQLite.MSIL.Test.nuspec.
7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <package> 11 11 <metadata> 12 12 <id>System.Data.SQLite.MSIL.Test</id> 13 13 <title>System.Data.SQLite (MSIL) Test</title> 14 - <version>1.0.99.0</version> 14 + <version>1.0.100.0</version> 15 15 <authors>SQLite Development Team</authors> 16 16 <description>This is a pre-release package and is not intended for production use. This is a legacy package; if possible, please use either the "System.Data.SQLite.Test" or "System.Data.SQLite.Core.Test" package instead. An ADO.NET provider for SQLite (managed-only).</description> 17 17 <language>en-US</language> 18 18 <projectUrl>https://system.data.sqlite.org/</projectUrl> 19 19 <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl> 20 20 <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl> 21 21 <tags>sqlite database ado.net provider interop</tags> 22 22 <copyright>Public Domain</copyright> 23 23 <dependencies> 24 24 <group targetFramework="net20"> 25 - <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.99.0" /> 25 + <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.100.0" /> 26 26 </group> 27 27 <group targetFramework="net40"> 28 - <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.99.0" /> 28 + <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.100.0" /> 29 29 </group> 30 30 <group targetFramework="net45"> 31 - <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.99.0" /> 31 + <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.100.0" /> 32 32 </group> 33 33 <group targetFramework="net451"> 34 - <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.99.0" /> 34 + <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.100.0" /> 35 35 </group> 36 36 <group targetFramework="net46"> 37 - <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.99.0" /> 37 + <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.100.0" /> 38 38 </group> 39 39 <group targetFramework="net20"> 40 - <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" /> 40 + <dependency id="System.Data.SQLite.Linq.Test" version="1.0.100.0" /> 41 41 </group> 42 42 <group targetFramework="net40"> 43 - <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" /> 43 + <dependency id="System.Data.SQLite.Linq.Test" version="1.0.100.0" /> 44 44 </group> 45 45 <group targetFramework="net45"> 46 - <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" /> 46 + <dependency id="System.Data.SQLite.Linq.Test" version="1.0.100.0" /> 47 47 </group> 48 48 <group targetFramework="net451"> 49 - <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" /> 49 + <dependency id="System.Data.SQLite.Linq.Test" version="1.0.100.0" /> 50 50 </group> 51 51 <group targetFramework="net46"> 52 - <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" /> 52 + <dependency id="System.Data.SQLite.Linq.Test" version="1.0.100.0" /> 53 53 </group> 54 54 <group targetFramework="net40"> 55 - <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.0" /> 55 + <dependency id="System.Data.SQLite.EF6.Test" version="1.0.100.0" /> 56 56 </group> 57 57 <group targetFramework="net45"> 58 - <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.0" /> 58 + <dependency id="System.Data.SQLite.EF6.Test" version="1.0.100.0" /> 59 59 </group> 60 60 <group targetFramework="net451"> 61 - <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.0" /> 61 + <dependency id="System.Data.SQLite.EF6.Test" version="1.0.100.0" /> 62 62 </group> 63 63 <group targetFramework="net46"> 64 - <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.0" /> 64 + <dependency id="System.Data.SQLite.EF6.Test" version="1.0.100.0" /> 65 65 </group> 66 66 </dependencies> 67 67 </metadata> 68 68 <files /> 69 69 </package>
Changes to NuGet/SQLite.MSIL.nuspec.
7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <package> 11 11 <metadata> 12 12 <id>System.Data.SQLite.MSIL</id> 13 13 <title>System.Data.SQLite (MSIL)</title> 14 - <version>1.0.99.0</version> 14 + <version>1.0.100.0</version> 15 15 <authors>SQLite Development Team</authors> 16 16 <description>This is a legacy package; if possible, please use either the "System.Data.SQLite" or "System.Data.SQLite.Core" package instead. An ADO.NET provider for SQLite (managed-only).</description> 17 17 <language>en-US</language> 18 18 <projectUrl>https://system.data.sqlite.org/</projectUrl> 19 19 <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl> 20 20 <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl> 21 21 <tags>sqlite database ado.net provider interop</tags> 22 22 <copyright>Public Domain</copyright> 23 23 <dependencies> 24 24 <group targetFramework="net20"> 25 - <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.99.0" /> 25 + <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.100.0" /> 26 26 </group> 27 27 <group targetFramework="net40"> 28 - <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.99.0" /> 28 + <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.100.0" /> 29 29 </group> 30 30 <group targetFramework="net45"> 31 - <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.99.0" /> 31 + <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.100.0" /> 32 32 </group> 33 33 <group targetFramework="net451"> 34 - <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.99.0" /> 34 + <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.100.0" /> 35 35 </group> 36 36 <group targetFramework="net46"> 37 - <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.99.0" /> 37 + <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.100.0" /> 38 38 </group> 39 39 <group targetFramework="net20"> 40 - <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" /> 40 + <dependency id="System.Data.SQLite.Linq" version="1.0.100.0" /> 41 41 </group> 42 42 <group targetFramework="net40"> 43 - <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" /> 43 + <dependency id="System.Data.SQLite.Linq" version="1.0.100.0" /> 44 44 </group> 45 45 <group targetFramework="net45"> 46 - <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" /> 46 + <dependency id="System.Data.SQLite.Linq" version="1.0.100.0" /> 47 47 </group> 48 48 <group targetFramework="net451"> 49 - <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" /> 49 + <dependency id="System.Data.SQLite.Linq" version="1.0.100.0" /> 50 50 </group> 51 51 <group targetFramework="net46"> 52 - <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" /> 52 + <dependency id="System.Data.SQLite.Linq" version="1.0.100.0" /> 53 53 </group> 54 54 <group targetFramework="net40"> 55 - <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" /> 55 + <dependency id="System.Data.SQLite.EF6" version="1.0.100.0" /> 56 56 </group> 57 57 <group targetFramework="net45"> 58 - <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" /> 58 + <dependency id="System.Data.SQLite.EF6" version="1.0.100.0" /> 59 59 </group> 60 60 <group targetFramework="net451"> 61 - <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" /> 61 + <dependency id="System.Data.SQLite.EF6" version="1.0.100.0" /> 62 62 </group> 63 63 <group targetFramework="net46"> 64 - <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" /> 64 + <dependency id="System.Data.SQLite.EF6" version="1.0.100.0" /> 65 65 </group> 66 66 </dependencies> 67 67 </metadata> 68 68 <files /> 69 69 </package>
Changes to NuGet/SQLite.Test.nuspec.
7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <package> 11 11 <metadata> 12 12 <id>System.Data.SQLite.Test</id> 13 13 <title>System.Data.SQLite (x86/x64) Test</title> 14 - <version>1.0.99.0</version> 14 + <version>1.0.100.0</version> 15 15 <authors>SQLite Development Team</authors> 16 16 <description>This is a pre-release package and is not intended for production use. The official SQLite database engine for both x86 and x64 along with the ADO.NET provider. This package includes support for LINQ and Entity Framework 6.</description> 17 17 <language>en-US</language> 18 18 <projectUrl>https://system.data.sqlite.org/</projectUrl> 19 19 <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl> 20 20 <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl> 21 21 <tags>sqlite database ado.net provider interop</tags> 22 22 <copyright>Public Domain</copyright> 23 23 <dependencies> 24 24 <group targetFramework="net20"> 25 - <dependency id="System.Data.SQLite.Core.Test" version="1.0.99.0" /> 25 + <dependency id="System.Data.SQLite.Core.Test" version="1.0.100.0" /> 26 26 </group> 27 27 <group targetFramework="net40"> 28 - <dependency id="System.Data.SQLite.Core.Test" version="1.0.99.0" /> 28 + <dependency id="System.Data.SQLite.Core.Test" version="1.0.100.0" /> 29 29 </group> 30 30 <group targetFramework="net45"> 31 - <dependency id="System.Data.SQLite.Core.Test" version="1.0.99.0" /> 31 + <dependency id="System.Data.SQLite.Core.Test" version="1.0.100.0" /> 32 32 </group> 33 33 <group targetFramework="net451"> 34 - <dependency id="System.Data.SQLite.Core.Test" version="1.0.99.0" /> 34 + <dependency id="System.Data.SQLite.Core.Test" version="1.0.100.0" /> 35 35 </group> 36 36 <group targetFramework="net46"> 37 - <dependency id="System.Data.SQLite.Core.Test" version="1.0.99.0" /> 37 + <dependency id="System.Data.SQLite.Core.Test" version="1.0.100.0" /> 38 38 </group> 39 39 <group targetFramework="net20"> 40 - <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" /> 40 + <dependency id="System.Data.SQLite.Linq.Test" version="1.0.100.0" /> 41 41 </group> 42 42 <group targetFramework="net40"> 43 - <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" /> 43 + <dependency id="System.Data.SQLite.Linq.Test" version="1.0.100.0" /> 44 44 </group> 45 45 <group targetFramework="net45"> 46 - <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" /> 46 + <dependency id="System.Data.SQLite.Linq.Test" version="1.0.100.0" /> 47 47 </group> 48 48 <group targetFramework="net451"> 49 - <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" /> 49 + <dependency id="System.Data.SQLite.Linq.Test" version="1.0.100.0" /> 50 50 </group> 51 51 <group targetFramework="net46"> 52 - <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" /> 52 + <dependency id="System.Data.SQLite.Linq.Test" version="1.0.100.0" /> 53 53 </group> 54 54 <group targetFramework="net40"> 55 - <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.0" /> 55 + <dependency id="System.Data.SQLite.EF6.Test" version="1.0.100.0" /> 56 56 </group> 57 57 <group targetFramework="net45"> 58 - <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.0" /> 58 + <dependency id="System.Data.SQLite.EF6.Test" version="1.0.100.0" /> 59 59 </group> 60 60 <group targetFramework="net451"> 61 - <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.0" /> 61 + <dependency id="System.Data.SQLite.EF6.Test" version="1.0.100.0" /> 62 62 </group> 63 63 <group targetFramework="net46"> 64 - <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.0" /> 64 + <dependency id="System.Data.SQLite.EF6.Test" version="1.0.100.0" /> 65 65 </group> 66 66 </dependencies> 67 67 </metadata> 68 68 <files /> 69 69 </package>
Changes to NuGet/SQLite.nuspec.
7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <package> 11 11 <metadata> 12 12 <id>System.Data.SQLite</id> 13 13 <title>System.Data.SQLite (x86/x64)</title> 14 - <version>1.0.99.0</version> 14 + <version>1.0.100.0</version> 15 15 <authors>SQLite Development Team</authors> 16 16 <description>The official SQLite database engine for both x86 and x64 along with the ADO.NET provider. This package includes support for LINQ and Entity Framework 6.</description> 17 17 <language>en-US</language> 18 18 <projectUrl>https://system.data.sqlite.org/</projectUrl> 19 19 <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl> 20 20 <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl> 21 21 <tags>sqlite database ado.net provider interop</tags> 22 22 <copyright>Public Domain</copyright> 23 23 <dependencies> 24 24 <group targetFramework="net20"> 25 - <dependency id="System.Data.SQLite.Core" version="1.0.99.0" /> 25 + <dependency id="System.Data.SQLite.Core" version="1.0.100.0" /> 26 26 </group> 27 27 <group targetFramework="net40"> 28 - <dependency id="System.Data.SQLite.Core" version="1.0.99.0" /> 28 + <dependency id="System.Data.SQLite.Core" version="1.0.100.0" /> 29 29 </group> 30 30 <group targetFramework="net45"> 31 - <dependency id="System.Data.SQLite.Core" version="1.0.99.0" /> 31 + <dependency id="System.Data.SQLite.Core" version="1.0.100.0" /> 32 32 </group> 33 33 <group targetFramework="net451"> 34 - <dependency id="System.Data.SQLite.Core" version="1.0.99.0" /> 34 + <dependency id="System.Data.SQLite.Core" version="1.0.100.0" /> 35 35 </group> 36 36 <group targetFramework="net46"> 37 - <dependency id="System.Data.SQLite.Core" version="1.0.99.0" /> 37 + <dependency id="System.Data.SQLite.Core" version="1.0.100.0" /> 38 38 </group> 39 39 <group targetFramework="net20"> 40 - <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" /> 40 + <dependency id="System.Data.SQLite.Linq" version="1.0.100.0" /> 41 41 </group> 42 42 <group targetFramework="net40"> 43 - <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" /> 43 + <dependency id="System.Data.SQLite.Linq" version="1.0.100.0" /> 44 44 </group> 45 45 <group targetFramework="net45"> 46 - <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" /> 46 + <dependency id="System.Data.SQLite.Linq" version="1.0.100.0" /> 47 47 </group> 48 48 <group targetFramework="net451"> 49 - <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" /> 49 + <dependency id="System.Data.SQLite.Linq" version="1.0.100.0" /> 50 50 </group> 51 51 <group targetFramework="net46"> 52 - <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" /> 52 + <dependency id="System.Data.SQLite.Linq" version="1.0.100.0" /> 53 53 </group> 54 54 <group targetFramework="net40"> 55 - <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" /> 55 + <dependency id="System.Data.SQLite.EF6" version="1.0.100.0" /> 56 56 </group> 57 57 <group targetFramework="net45"> 58 - <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" /> 58 + <dependency id="System.Data.SQLite.EF6" version="1.0.100.0" /> 59 59 </group> 60 60 <group targetFramework="net451"> 61 - <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" /> 61 + <dependency id="System.Data.SQLite.EF6" version="1.0.100.0" /> 62 62 </group> 63 63 <group targetFramework="net46"> 64 - <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" /> 64 + <dependency id="System.Data.SQLite.EF6" version="1.0.100.0" /> 65 65 </group> 66 66 </dependencies> 67 67 </metadata> 68 68 <files /> 69 69 </package>
Changes to NuGet/SQLite.x64.nuspec.
6 6 * Written by Joe Mistachkin. 7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <package> 11 11 <metadata> 12 12 <id>System.Data.SQLite.x64</id> 13 - <version>1.0.99.0</version> 13 + <version>1.0.100.0</version> 14 14 <authors>SQLite Development Team</authors> 15 15 <description>This is a legacy package; if possible, please use either the "System.Data.SQLite" or "System.Data.SQLite.Core" package instead. The official SQLite database engine combined with a complete ADO.NET provider all rolled into a single mixed-mode assembly for x64.</description> 16 16 <language>en-US</language> 17 17 <projectUrl>https://system.data.sqlite.org/</projectUrl> 18 18 <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl> 19 19 <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl> 20 20 <tags>sqlite database ado.net provider interop</tags> 21 21 <copyright>Public Domain</copyright> 22 22 <dependencies> 23 23 <group targetFramework="net20"> 24 - <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" /> 24 + <dependency id="System.Data.SQLite.Linq" version="1.0.100.0" /> 25 25 </group> 26 26 <group targetFramework="net40"> 27 - <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" /> 27 + <dependency id="System.Data.SQLite.Linq" version="1.0.100.0" /> 28 28 </group> 29 29 <group targetFramework="net45"> 30 - <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" /> 30 + <dependency id="System.Data.SQLite.Linq" version="1.0.100.0" /> 31 31 </group> 32 32 <group targetFramework="net451"> 33 - <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" /> 33 + <dependency id="System.Data.SQLite.Linq" version="1.0.100.0" /> 34 34 </group> 35 35 <group targetFramework="net46"> 36 - <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" /> 36 + <dependency id="System.Data.SQLite.Linq" version="1.0.100.0" /> 37 37 </group> 38 38 <group targetFramework="net40"> 39 - <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" /> 39 + <dependency id="System.Data.SQLite.EF6" version="1.0.100.0" /> 40 40 </group> 41 41 <group targetFramework="net45"> 42 - <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" /> 42 + <dependency id="System.Data.SQLite.EF6" version="1.0.100.0" /> 43 43 </group> 44 44 <group targetFramework="net451"> 45 - <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" /> 45 + <dependency id="System.Data.SQLite.EF6" version="1.0.100.0" /> 46 46 </group> 47 47 <group targetFramework="net46"> 48 - <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" /> 48 + <dependency id="System.Data.SQLite.EF6" version="1.0.100.0" /> 49 49 </group> 50 50 </dependencies> 51 51 </metadata> 52 52 <files> 53 53 <file src="..\bin\2008\x64\ReleaseStatic\System.Data.SQLite.dll" target="lib\net20" /> 54 54 <file src="..\bin\2008\Release\bin\System.Data.SQLite.xml" target="lib\net20" /> 55 55 <file src="..\bin\2010\x64\ReleaseStatic\System.Data.SQLite.dll" target="lib\net40" />
Changes to NuGet/SQLite.x86.nuspec.
6 6 * Written by Joe Mistachkin. 7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <package> 11 11 <metadata> 12 12 <id>System.Data.SQLite.x86</id> 13 - <version>1.0.99.0</version> 13 + <version>1.0.100.0</version> 14 14 <authors>SQLite Development Team</authors> 15 15 <description>This is a legacy package; if possible, please use either the "System.Data.SQLite" or "System.Data.SQLite.Core" package instead. The official SQLite database engine combined with a complete ADO.NET provider all rolled into a single mixed-mode assembly for x86.</description> 16 16 <language>en-US</language> 17 17 <projectUrl>https://system.data.sqlite.org/</projectUrl> 18 18 <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl> 19 19 <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl> 20 20 <tags>sqlite database ado.net provider interop</tags> 21 21 <copyright>Public Domain</copyright> 22 22 <dependencies> 23 23 <group targetFramework="net20"> 24 - <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" /> 24 + <dependency id="System.Data.SQLite.Linq" version="1.0.100.0" /> 25 25 </group> 26 26 <group targetFramework="net40"> 27 - <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" /> 27 + <dependency id="System.Data.SQLite.Linq" version="1.0.100.0" /> 28 28 </group> 29 29 <group targetFramework="net45"> 30 - <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" /> 30 + <dependency id="System.Data.SQLite.Linq" version="1.0.100.0" /> 31 31 </group> 32 32 <group targetFramework="net451"> 33 - <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" /> 33 + <dependency id="System.Data.SQLite.Linq" version="1.0.100.0" /> 34 34 </group> 35 35 <group targetFramework="net46"> 36 - <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" /> 36 + <dependency id="System.Data.SQLite.Linq" version="1.0.100.0" /> 37 37 </group> 38 38 <group targetFramework="net40"> 39 - <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" /> 39 + <dependency id="System.Data.SQLite.EF6" version="1.0.100.0" /> 40 40 </group> 41 41 <group targetFramework="net45"> 42 - <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" /> 42 + <dependency id="System.Data.SQLite.EF6" version="1.0.100.0" /> 43 43 </group> 44 44 <group targetFramework="net451"> 45 - <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" /> 45 + <dependency id="System.Data.SQLite.EF6" version="1.0.100.0" /> 46 46 </group> 47 47 <group targetFramework="net46"> 48 - <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" /> 48 + <dependency id="System.Data.SQLite.EF6" version="1.0.100.0" /> 49 49 </group> 50 50 </dependencies> 51 51 </metadata> 52 52 <files> 53 53 <file src="..\bin\2008\Win32\ReleaseStatic\System.Data.SQLite.dll" target="lib\net20" /> 54 54 <file src="..\bin\2008\Release\bin\System.Data.SQLite.xml" target="lib\net20" /> 55 55 <file src="..\bin\2010\Win32\ReleaseStatic\System.Data.SQLite.dll" target="lib\net40" />
Changes to SQLite.Designer/AssemblyInfo.cs.
39 39 // Major Version 40 40 // Minor Version 41 41 // Build Number 42 42 // Revision 43 43 // 44 44 // You can specify all the values or you can default the Revision and Build Numbers 45 45 // by using the '*' as shown below: 46 -[assembly: AssemblyVersion("1.0.99.0")] 47 -[assembly: AssemblyFileVersion("1.0.99.0")] 46 +[assembly: AssemblyVersion("1.0.100.0")] 47 +[assembly: AssemblyFileVersion("1.0.100.0")]
Changes to SQLite.Designer/Design/Index.cs.
389 389 } 390 390 391 391 internal IndexColumn(Index parent, DataRow row) 392 392 { 393 393 _parent = parent; 394 394 if (row != null) 395 395 { 396 - _column = row["COLUMN_NAME"].ToString(); 396 + if (!row.IsNull("COLUMN_NAME")) 397 + _column = row["COLUMN_NAME"].ToString(); 398 + else 399 + _column = null; 400 + 397 401 if (row.IsNull("SORT_MODE") == false && (string)row["SORT_MODE"] != "ASC") 398 402 _mode = ColumnSortMode.Descending; 399 403 400 404 if (row.IsNull("COLLATION_NAME") == false) 401 405 _collate = row["COLLATION_NAME"].ToString().ToUpperInvariant(); 402 406 } 403 407 }
Changes to SQLite.Designer/source.extension.vsixmanifest.
1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <Vsix Version="1.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2010"> 3 3 <Identifier Id="67b5f3a9-cde1-430f-a12b-af95bb064851"> 4 4 <Name>System.Data.SQLite Designer</Name> 5 5 <Author>https://system.data.sqlite.org/</Author> 6 - <Version>1.0.99.0</Version> 6 + <Version>1.0.100.0</Version> 7 7 <Description>ADO.NET Data Designer for SQLite</Description> 8 8 <Locale>1033</Locale> 9 9 <InstalledByMsi>false</InstalledByMsi> 10 10 <SupportedProducts> 11 11 <VisualStudio Version="10.0"> 12 12 <Edition>Pro</Edition> 13 13 </VisualStudio>
Changes to SQLite.Interop/props/SQLite.Interop.2005.vsprops.
15 15 <UserMacro 16 16 Name="ConfigurationYear" 17 17 Value="2005" 18 18 PerformEnvironmentSet="true" 19 19 /> 20 20 <UserMacro 21 21 Name="INTEROP_BUILD_NUMBER" 22 - Value="099" 22 + Value="100" 23 23 PerformEnvironmentSet="true" 24 24 /> 25 25 <UserMacro 26 26 Name="INTEROP_LINKER_VERSION" 27 27 Value="1.0" 28 28 PerformEnvironmentSet="true" 29 29 /> 30 30 <UserMacro 31 31 Name="INTEROP_MANIFEST_VERSION" 32 - Value="1.0.99.0" 32 + Value="1.0.100.0" 33 33 PerformEnvironmentSet="true" 34 34 /> 35 35 <UserMacro 36 36 Name="INTEROP_RC_VERSION" 37 - Value="1,0,99,0" 37 + Value="1,0,100,0" 38 38 PerformEnvironmentSet="true" 39 39 /> 40 40 <UserMacro 41 41 Name="INTEROP_INCLUDE_DIRECTORIES" 42 42 Value="src\core" 43 43 PerformEnvironmentSet="true" 44 44 />
Changes to SQLite.Interop/props/SQLite.Interop.2008.vsprops.
15 15 <UserMacro 16 16 Name="ConfigurationYear" 17 17 Value="2008" 18 18 PerformEnvironmentSet="true" 19 19 /> 20 20 <UserMacro 21 21 Name="INTEROP_BUILD_NUMBER" 22 - Value="099" 22 + Value="100" 23 23 PerformEnvironmentSet="true" 24 24 /> 25 25 <UserMacro 26 26 Name="INTEROP_LINKER_VERSION" 27 27 Value="1.0" 28 28 PerformEnvironmentSet="true" 29 29 /> 30 30 <UserMacro 31 31 Name="INTEROP_MANIFEST_VERSION" 32 - Value="1.0.99.0" 32 + Value="1.0.100.0" 33 33 PerformEnvironmentSet="true" 34 34 /> 35 35 <UserMacro 36 36 Name="INTEROP_RC_VERSION" 37 - Value="1,0,99,0" 37 + Value="1,0,100,0" 38 38 PerformEnvironmentSet="true" 39 39 /> 40 40 <UserMacro 41 41 Name="INTEROP_INCLUDE_DIRECTORIES" 42 42 Value="src\core" 43 43 PerformEnvironmentSet="true" 44 44 />
Changes to SQLite.Interop/props/SQLite.Interop.2010.props.
6 6 * Written by Joe Mistachkin. 7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"> 11 11 <PropertyGroup Label="UserMacros"> 12 12 <ConfigurationYear>2010</ConfigurationYear> 13 - <INTEROP_BUILD_NUMBER>099</INTEROP_BUILD_NUMBER> 13 + <INTEROP_BUILD_NUMBER>100</INTEROP_BUILD_NUMBER> 14 14 <INTEROP_LINKER_VERSION>1.0</INTEROP_LINKER_VERSION> 15 - <INTEROP_MANIFEST_VERSION>1.0.99.0</INTEROP_MANIFEST_VERSION> 16 - <INTEROP_RC_VERSION>1,0,99,0</INTEROP_RC_VERSION> 15 + <INTEROP_MANIFEST_VERSION>1.0.100.0</INTEROP_MANIFEST_VERSION> 16 + <INTEROP_RC_VERSION>1,0,100,0</INTEROP_RC_VERSION> 17 17 <INTEROP_INCLUDE_DIRECTORIES>src\core</INTEROP_INCLUDE_DIRECTORIES> 18 18 <INTEROP_LIBRARY_DIRECTORIES></INTEROP_LIBRARY_DIRECTORIES> 19 19 <INTEROP_LIBRARY_DEPENDENCIES></INTEROP_LIBRARY_DEPENDENCIES> 20 20 <INTEROP_DEBUG_DEFINES>INTEROP_DEBUG=0x31F;INTEROP_LOG=1;INTEROP_TEST_EXTENSION=1</INTEROP_DEBUG_DEFINES> 21 21 <INTEROP_EXTRA_DEFINES>INTEROP_PLACEHOLDER=1;INTEROP_EXTENSION_FUNCTIONS=1;INTEROP_CODEC=1;INTEROP_VIRTUAL_TABLE=1;INTEROP_FTS5_EXTENSION=1;INTEROP_PERCENTILE_EXTENSION=1;INTEROP_TOTYPE_EXTENSION=1;INTEROP_REGEXP_EXTENSION=1;INTEROP_JSON1_EXTENSION=1</INTEROP_EXTRA_DEFINES> 22 22 <INTEROP_ASSEMBLY_RESOURCES>/ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteCommand.bmp,System.Data.SQLite.SQLiteCommand.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteConnection.bmp,System.Data.SQLite.SQLiteConnection.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteDataAdapter.bmp,System.Data.SQLite.SQLiteDataAdapter.bmp</INTEROP_ASSEMBLY_RESOURCES> 23 23 <INTEROP_KEY_FILE>$(ProjectDir)..\Keys\System.Data.SQLite.snk</INTEROP_KEY_FILE>
Changes to SQLite.Interop/props/SQLite.Interop.2012.props.
6 6 * Written by Joe Mistachkin. 7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"> 11 11 <PropertyGroup Label="UserMacros"> 12 12 <ConfigurationYear>2012</ConfigurationYear> 13 - <INTEROP_BUILD_NUMBER>099</INTEROP_BUILD_NUMBER> 13 + <INTEROP_BUILD_NUMBER>100</INTEROP_BUILD_NUMBER> 14 14 <INTEROP_LINKER_VERSION>1.0</INTEROP_LINKER_VERSION> 15 - <INTEROP_MANIFEST_VERSION>1.0.99.0</INTEROP_MANIFEST_VERSION> 16 - <INTEROP_RC_VERSION>1,0,99,0</INTEROP_RC_VERSION> 15 + <INTEROP_MANIFEST_VERSION>1.0.100.0</INTEROP_MANIFEST_VERSION> 16 + <INTEROP_RC_VERSION>1,0,100,0</INTEROP_RC_VERSION> 17 17 <INTEROP_INCLUDE_DIRECTORIES>src\core</INTEROP_INCLUDE_DIRECTORIES> 18 18 <INTEROP_LIBRARY_DIRECTORIES></INTEROP_LIBRARY_DIRECTORIES> 19 19 <INTEROP_LIBRARY_DEPENDENCIES></INTEROP_LIBRARY_DEPENDENCIES> 20 20 <INTEROP_DEBUG_DEFINES>INTEROP_DEBUG=0x31F;INTEROP_LOG=1;INTEROP_TEST_EXTENSION=1</INTEROP_DEBUG_DEFINES> 21 21 <INTEROP_EXTRA_DEFINES>INTEROP_PLACEHOLDER=1;INTEROP_EXTENSION_FUNCTIONS=1;INTEROP_CODEC=1;INTEROP_VIRTUAL_TABLE=1;INTEROP_FTS5_EXTENSION=1;INTEROP_PERCENTILE_EXTENSION=1;INTEROP_TOTYPE_EXTENSION=1;INTEROP_REGEXP_EXTENSION=1;INTEROP_JSON1_EXTENSION=1</INTEROP_EXTRA_DEFINES> 22 22 <INTEROP_ASSEMBLY_RESOURCES>/ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteCommand.bmp,System.Data.SQLite.SQLiteCommand.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteConnection.bmp,System.Data.SQLite.SQLiteConnection.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteDataAdapter.bmp,System.Data.SQLite.SQLiteDataAdapter.bmp</INTEROP_ASSEMBLY_RESOURCES> 23 23 <INTEROP_KEY_FILE>$(ProjectDir)..\Keys\System.Data.SQLite.snk</INTEROP_KEY_FILE>
Changes to SQLite.Interop/props/SQLite.Interop.2013.props.
6 6 * Written by Joe Mistachkin. 7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0"> 11 11 <PropertyGroup Label="UserMacros"> 12 12 <ConfigurationYear>2013</ConfigurationYear> 13 - <INTEROP_BUILD_NUMBER>099</INTEROP_BUILD_NUMBER> 13 + <INTEROP_BUILD_NUMBER>100</INTEROP_BUILD_NUMBER> 14 14 <INTEROP_LINKER_VERSION>1.0</INTEROP_LINKER_VERSION> 15 - <INTEROP_MANIFEST_VERSION>1.0.99.0</INTEROP_MANIFEST_VERSION> 16 - <INTEROP_RC_VERSION>1,0,99,0</INTEROP_RC_VERSION> 15 + <INTEROP_MANIFEST_VERSION>1.0.100.0</INTEROP_MANIFEST_VERSION> 16 + <INTEROP_RC_VERSION>1,0,100,0</INTEROP_RC_VERSION> 17 17 <INTEROP_INCLUDE_DIRECTORIES>src\core</INTEROP_INCLUDE_DIRECTORIES> 18 18 <INTEROP_LIBRARY_DIRECTORIES></INTEROP_LIBRARY_DIRECTORIES> 19 19 <INTEROP_LIBRARY_DEPENDENCIES></INTEROP_LIBRARY_DEPENDENCIES> 20 20 <INTEROP_DEBUG_DEFINES>INTEROP_DEBUG=0x31F;INTEROP_LOG=1;INTEROP_TEST_EXTENSION=1</INTEROP_DEBUG_DEFINES> 21 21 <INTEROP_EXTRA_DEFINES>INTEROP_PLACEHOLDER=1;INTEROP_EXTENSION_FUNCTIONS=1;INTEROP_CODEC=1;INTEROP_VIRTUAL_TABLE=1;INTEROP_FTS5_EXTENSION=1;INTEROP_PERCENTILE_EXTENSION=1;INTEROP_TOTYPE_EXTENSION=1;INTEROP_REGEXP_EXTENSION=1;INTEROP_JSON1_EXTENSION=1</INTEROP_EXTRA_DEFINES> 22 22 <INTEROP_ASSEMBLY_RESOURCES>/ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteCommand.bmp,System.Data.SQLite.SQLiteCommand.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteConnection.bmp,System.Data.SQLite.SQLiteConnection.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteDataAdapter.bmp,System.Data.SQLite.SQLiteDataAdapter.bmp</INTEROP_ASSEMBLY_RESOURCES> 23 23 <INTEROP_KEY_FILE>$(ProjectDir)..\Keys\System.Data.SQLite.snk</INTEROP_KEY_FILE>
Changes to SQLite.Interop/props/SQLite.Interop.2015.props.
6 6 * Written by Joe Mistachkin. 7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0"> 11 11 <PropertyGroup Label="UserMacros"> 12 12 <ConfigurationYear>2015</ConfigurationYear> 13 - <INTEROP_BUILD_NUMBER>099</INTEROP_BUILD_NUMBER> 13 + <INTEROP_BUILD_NUMBER>100</INTEROP_BUILD_NUMBER> 14 14 <INTEROP_LINKER_VERSION>1.0</INTEROP_LINKER_VERSION> 15 - <INTEROP_MANIFEST_VERSION>1.0.99.0</INTEROP_MANIFEST_VERSION> 16 - <INTEROP_RC_VERSION>1,0,99,0</INTEROP_RC_VERSION> 15 + <INTEROP_MANIFEST_VERSION>1.0.100.0</INTEROP_MANIFEST_VERSION> 16 + <INTEROP_RC_VERSION>1,0,100,0</INTEROP_RC_VERSION> 17 17 <INTEROP_INCLUDE_DIRECTORIES>src\core</INTEROP_INCLUDE_DIRECTORIES> 18 18 <INTEROP_LIBRARY_DIRECTORIES></INTEROP_LIBRARY_DIRECTORIES> 19 19 <INTEROP_LIBRARY_DEPENDENCIES></INTEROP_LIBRARY_DEPENDENCIES> 20 20 <INTEROP_DEBUG_DEFINES>INTEROP_DEBUG=0x31F;INTEROP_LOG=1;INTEROP_TEST_EXTENSION=1</INTEROP_DEBUG_DEFINES> 21 21 <INTEROP_EXTRA_DEFINES>INTEROP_PLACEHOLDER=1;INTEROP_EXTENSION_FUNCTIONS=1;INTEROP_CODEC=1;INTEROP_VIRTUAL_TABLE=1;INTEROP_FTS5_EXTENSION=1;INTEROP_PERCENTILE_EXTENSION=1;INTEROP_TOTYPE_EXTENSION=1;INTEROP_REGEXP_EXTENSION=1;INTEROP_JSON1_EXTENSION=1</INTEROP_EXTRA_DEFINES> 22 22 <INTEROP_ASSEMBLY_RESOURCES>/ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteCommand.bmp,System.Data.SQLite.SQLiteCommand.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteConnection.bmp,System.Data.SQLite.SQLiteConnection.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteDataAdapter.bmp,System.Data.SQLite.SQLiteDataAdapter.bmp</INTEROP_ASSEMBLY_RESOURCES> 23 23 <INTEROP_KEY_FILE>$(ProjectDir)..\Keys\System.Data.SQLite.snk</INTEROP_KEY_FILE>
Changes to SQLite.Interop/props/sqlite3.props.
5 5 * 6 6 * Written by Joe Mistachkin. 7 7 * Released to the public domain, use at your own risk! 8 8 * 9 9 --> 10 10 <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"> 11 11 <PropertyGroup Label="UserMacros"> 12 - <SQLITE_MANIFEST_VERSION>3.9.2.0</SQLITE_MANIFEST_VERSION> 13 - <SQLITE_RC_VERSION>3,9,2,0</SQLITE_RC_VERSION> 12 + <SQLITE_MANIFEST_VERSION>3.10.0.0</SQLITE_MANIFEST_VERSION> 13 + <SQLITE_RC_VERSION>3,10,0,0</SQLITE_RC_VERSION> 14 14 <SQLITE_COMMON_DEFINES>_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;SQLITE_THREADSAFE=1;SQLITE_USE_URI=1;SQLITE_ENABLE_COLUMN_METADATA=1;SQLITE_ENABLE_STAT4=1;SQLITE_ENABLE_FTS3=1;SQLITE_ENABLE_LOAD_EXTENSION=1;SQLITE_ENABLE_RTREE=1;SQLITE_SOUNDEX=1;SQLITE_ENABLE_MEMORY_MANAGEMENT=1;SQLITE_ENABLE_API_ARMOR=1</SQLITE_COMMON_DEFINES> 15 15 <SQLITE_EXTRA_DEFINES>SQLITE_PLACEHOLDER=1;SQLITE_HAS_CODEC=1</SQLITE_EXTRA_DEFINES> 16 16 <SQLITE_WINCE_200X_DEFINES>SQLITE_OMIT_WAL=1</SQLITE_WINCE_200X_DEFINES> 17 17 <SQLITE_WINCE_2013_DEFINES>HAVE_ERRNO_H=1;SQLITE_MSVC_LOCALTIME_API=1</SQLITE_WINCE_2013_DEFINES> 18 18 <SQLITE_DEBUG_DEFINES>SQLITE_DEBUG=1;SQLITE_MEMDEBUG=1;SQLITE_ENABLE_EXPENSIVE_ASSERT=1</SQLITE_DEBUG_DEFINES> 19 19 <SQLITE_RELEASE_DEFINES>SQLITE_WIN32_MALLOC=1</SQLITE_RELEASE_DEFINES> 20 20 <SQLITE_DISABLE_WARNINGS>4055;4100;4127;4146;4210;4232;4244;4245;4267;4306;4389;4701;4703;4706</SQLITE_DISABLE_WARNINGS>
Changes to SQLite.Interop/props/sqlite3.vsprops.
10 10 <VisualStudioPropertySheet 11 11 ProjectType="Visual C++" 12 12 Version="8.00" 13 13 Name="sqlite3" 14 14 > 15 15 <UserMacro 16 16 Name="SQLITE_MANIFEST_VERSION" 17 - Value="3.9.2.0" 17 + Value="3.10.0.0" 18 18 PerformEnvironmentSet="true" 19 19 /> 20 20 <UserMacro 21 21 Name="SQLITE_RC_VERSION" 22 - Value="3,9,2,0" 22 + Value="3,10,0,0" 23 23 PerformEnvironmentSet="true" 24 24 /> 25 25 <UserMacro 26 26 Name="SQLITE_COMMON_DEFINES" 27 27 Value="_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;SQLITE_THREADSAFE=1;SQLITE_USE_URI=1;SQLITE_ENABLE_COLUMN_METADATA=1;SQLITE_ENABLE_STAT4=1;SQLITE_ENABLE_FTS3=1;SQLITE_ENABLE_LOAD_EXTENSION=1;SQLITE_ENABLE_RTREE=1;SQLITE_SOUNDEX=1;SQLITE_ENABLE_MEMORY_MANAGEMENT=1;SQLITE_ENABLE_API_ARMOR=1" 28 28 PerformEnvironmentSet="true" 29 29 />
Changes to SQLite.Interop/src/core/sqlite3.c.
1 1 /****************************************************************************** 2 2 ** This file is an amalgamation of many separate C source files from SQLite 3 -** version 3.9.2. By combining all the individual C code files into this 3 +** version 3.10.0. 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. 9 9 ** 10 10 ** This file is all you need to compile SQLite. To use SQLite in other ................................................................................ 321 321 ** string contains the date and time of the check-in (UTC) and an SHA1 322 322 ** hash of the entire source tree. 323 323 ** 324 324 ** See also: [sqlite3_libversion()], 325 325 ** [sqlite3_libversion_number()], [sqlite3_sourceid()], 326 326 ** [sqlite_version()] and [sqlite_source_id()]. 327 327 */ 328 -#define SQLITE_VERSION "3.9.2" 329 -#define SQLITE_VERSION_NUMBER 3009002 330 -#define SQLITE_SOURCE_ID "2015-11-02 18:31:45 bda77dda9697c463c3d0704014d51627fceee328" 328 +#define SQLITE_VERSION "3.10.0" 329 +#define SQLITE_VERSION_NUMBER 3010000 330 +#define SQLITE_SOURCE_ID "2015-12-31 22:29:36 d41d4d7396fba60895535f21c438f8c75e7b2097" 331 331 332 332 /* 333 333 ** CAPI3REF: Run-Time Library Version Numbers 334 334 ** KEYWORDS: sqlite3_version, sqlite3_sourceid 335 335 ** 336 336 ** These interfaces provide the same information as the [SQLITE_VERSION], 337 337 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros ................................................................................ 688 688 #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) 689 689 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) 690 690 #define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8)) 691 691 #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8)) 692 692 #define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8)) 693 693 #define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8)) 694 694 #define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8)) 695 +#define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8)) 695 696 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) 696 697 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) 697 698 #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8)) 698 699 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) 699 700 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) 700 701 #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) 701 702 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) ................................................................................ 1090 1091 ** [sqlite3_malloc()] and the result is stored in the char* variable 1091 1092 ** that the fourth parameter of [sqlite3_file_control()] points to. 1092 1093 ** The caller is responsible for freeing the memory when done. As with 1093 1094 ** all file-control actions, there is no guarantee that this will actually 1094 1095 ** do anything. Callers should initialize the char* variable to a NULL 1095 1096 ** pointer in case this file-control is not implemented. This file-control 1096 1097 ** is intended for diagnostic use only. 1098 +** 1099 +** <li>[[SQLITE_FCNTL_VFS_POINTER]] 1100 +** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level 1101 +** [VFSes] currently in use. ^(The argument X in 1102 +** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be 1103 +** of type "[sqlite3_vfs] **". This opcodes will set *X 1104 +** to a pointer to the top-level VFS.)^ 1105 +** ^When there are multiple VFS shims in the stack, this opcode finds the 1106 +** upper-most shim only. 1097 1107 ** 1098 1108 ** <li>[[SQLITE_FCNTL_PRAGMA]] 1099 1109 ** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA] 1100 1110 ** file control is sent to the open [sqlite3_file] object corresponding 1101 1111 ** to the database file to which the pragma statement refers. ^The argument 1102 1112 ** to the [SQLITE_FCNTL_PRAGMA] file control is an array of 1103 1113 ** pointers to strings (char**) in which the second element of the array ................................................................................ 1209 1219 #define SQLITE_FCNTL_HAS_MOVED 20 1210 1220 #define SQLITE_FCNTL_SYNC 21 1211 1221 #define SQLITE_FCNTL_COMMIT_PHASETWO 22 1212 1222 #define SQLITE_FCNTL_WIN32_SET_HANDLE 23 1213 1223 #define SQLITE_FCNTL_WAL_BLOCK 24 1214 1224 #define SQLITE_FCNTL_ZIPVFS 25 1215 1225 #define SQLITE_FCNTL_RBU 26 1226 +#define SQLITE_FCNTL_VFS_POINTER 27 1216 1227 1217 1228 /* deprecated names */ 1218 1229 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE 1219 1230 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE 1220 1231 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO 1221 1232 1222 1233 ................................................................................ 1808 1819 ** SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary large 1809 1820 ** [sqlite3_malloc|heap allocations]. 1810 1821 ** This can help [Robson proof|prevent memory allocation failures] due to heap 1811 1822 ** fragmentation in low-memory embedded systems. 1812 1823 ** </dd> 1813 1824 ** 1814 1825 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt> 1815 -** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a static memory buffer 1826 +** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool 1816 1827 ** that SQLite can use for the database page cache with the default page 1817 1828 ** cache implementation. 1818 -** This configuration should not be used if an application-define page 1819 -** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2] 1820 -** configuration option. 1829 +** This configuration option is a no-op if an application-define page 1830 +** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2]. 1821 1831 ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to 1822 -** 8-byte aligned 1823 -** memory, the size of each page buffer (sz), and the number of pages (N). 1832 +** 8-byte aligned memory (pMem), the size of each page cache line (sz), 1833 +** and the number of cache lines (N). 1824 1834 ** The sz argument should be the size of the largest database page 1825 1835 ** (a power of two between 512 and 65536) plus some extra bytes for each 1826 1836 ** page header. ^The number of extra bytes needed by the page header 1827 -** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option 1828 -** to [sqlite3_config()]. 1837 +** can be determined using [SQLITE_CONFIG_PCACHE_HDRSZ]. 1829 1838 ** ^It is harmless, apart from the wasted memory, 1830 -** for the sz parameter to be larger than necessary. The first 1831 -** argument should pointer to an 8-byte aligned block of memory that 1832 -** is at least sz*N bytes of memory, otherwise subsequent behavior is 1833 -** undefined. 1834 -** ^SQLite will use the memory provided by the first argument to satisfy its 1835 -** memory needs for the first N pages that it adds to cache. ^If additional 1836 -** page cache memory is needed beyond what is provided by this option, then 1837 -** SQLite goes to [sqlite3_malloc()] for the additional storage space.</dd> 1839 +** for the sz parameter to be larger than necessary. The pMem 1840 +** argument must be either a NULL pointer or a pointer to an 8-byte 1841 +** aligned block of memory of at least sz*N bytes, otherwise 1842 +** subsequent behavior is undefined. 1843 +** ^When pMem is not NULL, SQLite will strive to use the memory provided 1844 +** to satisfy page cache needs, falling back to [sqlite3_malloc()] if 1845 +** a page cache line is larger than sz bytes or if all of the pMem buffer 1846 +** is exhausted. 1847 +** ^If pMem is NULL and N is non-zero, then each database connection 1848 +** does an initial bulk allocation for page cache memory 1849 +** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or 1850 +** of -1024*N bytes if N is negative, . ^If additional 1851 +** page cache memory is needed beyond what is provided by the initial 1852 +** allocation, then SQLite goes to [sqlite3_malloc()] separately for each 1853 +** additional cache line. </dd> 1838 1854 ** 1839 1855 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> 1840 1856 ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer 1841 1857 ** that SQLite will use for all of its dynamic memory allocation needs 1842 1858 ** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and 1843 1859 ** [SQLITE_CONFIG_PAGECACHE]. 1844 1860 ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled ................................................................................ 4599 4615 ** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a 4600 4616 ** memory allocation fails. 4601 4617 ** 4602 4618 ** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object 4603 4619 ** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer 4604 4620 ** then sqlite3_value_free(V) is a harmless no-op. 4605 4621 */ 4606 -SQLITE_API SQLITE_EXPERIMENTAL sqlite3_value *SQLITE_STDCALL sqlite3_value_dup(const sqlite3_value*); 4607 -SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_STDCALL sqlite3_value_free(sqlite3_value*); 4622 +SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_value_dup(const sqlite3_value*); 4623 +SQLITE_API void SQLITE_STDCALL sqlite3_value_free(sqlite3_value*); 4608 4624 4609 4625 /* 4610 4626 ** CAPI3REF: Obtain Aggregate Function Context 4611 4627 ** METHOD: sqlite3_context 4612 4628 ** 4613 4629 ** Implementations of aggregate SQL functions use this 4614 4630 ** routine to allocate memory for storing their state. ................................................................................ 5818 5834 ** and makes other simplifications to the WHERE clause in an attempt to 5819 5835 ** get as many WHERE clause terms into the form shown above as possible. 5820 5836 ** ^The aConstraint[] array only reports WHERE clause terms that are 5821 5837 ** relevant to the particular virtual table being queried. 5822 5838 ** 5823 5839 ** ^Information about the ORDER BY clause is stored in aOrderBy[]. 5824 5840 ** ^Each term of aOrderBy records a column of the ORDER BY clause. 5841 +** 5842 +** The colUsed field indicates which columns of the virtual table may be 5843 +** required by the current scan. Virtual table columns are numbered from 5844 +** zero in the order in which they appear within the CREATE TABLE statement 5845 +** passed to sqlite3_declare_vtab(). For the first 63 columns (columns 0-62), 5846 +** the corresponding bit is set within the colUsed mask if the column may be 5847 +** required by SQLite. If the table has at least 64 columns and any column 5848 +** to the right of the first 63 is required, then bit 63 of colUsed is also 5849 +** set. In other words, column iCol may be required if the expression 5850 +** (colUsed & ((sqlite3_uint64)1 << (iCol>=63 ? 63 : iCol))) evaluates to 5851 +** non-zero. 5825 5852 ** 5826 5853 ** The [xBestIndex] method must fill aConstraintUsage[] with information 5827 5854 ** about what parameters to pass to xFilter. ^If argvIndex>0 then 5828 5855 ** the right-hand side of the corresponding aConstraint[] is evaluated 5829 5856 ** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit 5830 5857 ** is true, then the constraint is assumed to be fully handled by the 5831 5858 ** virtual table and is not checked again by SQLite.)^ ................................................................................ 5898 5925 int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */ 5899 5926 int orderByConsumed; /* True if output is already ordered */ 5900 5927 double estimatedCost; /* Estimated cost of using this index */ 5901 5928 /* Fields below are only available in SQLite 3.8.2 and later */ 5902 5929 sqlite3_int64 estimatedRows; /* Estimated number of rows returned */ 5903 5930 /* Fields below are only available in SQLite 3.9.0 and later */ 5904 5931 int idxFlags; /* Mask of SQLITE_INDEX_SCAN_* flags */ 5932 + /* Fields below are only available in SQLite 3.10.0 and later */ 5933 + sqlite3_uint64 colUsed; /* Input: Mask of columns used by statement */ 5905 5934 }; 5906 5935 5907 5936 /* 5908 5937 ** CAPI3REF: Virtual Table Scan Flags 5909 5938 */ 5910 5939 #define SQLITE_INDEX_SCAN_UNIQUE 1 /* Scan visits at most 1 row */ 5911 5940 ................................................................................ 5913 5942 ** CAPI3REF: Virtual Table Constraint Operator Codes 5914 5943 ** 5915 5944 ** These macros defined the allowed values for the 5916 5945 ** [sqlite3_index_info].aConstraint[].op field. Each value represents 5917 5946 ** an operator that is part of a constraint term in the wHERE clause of 5918 5947 ** a query that uses a [virtual table]. 5919 5948 */ 5920 -#define SQLITE_INDEX_CONSTRAINT_EQ 2 5921 -#define SQLITE_INDEX_CONSTRAINT_GT 4 5922 -#define SQLITE_INDEX_CONSTRAINT_LE 8 5923 -#define SQLITE_INDEX_CONSTRAINT_LT 16 5924 -#define SQLITE_INDEX_CONSTRAINT_GE 32 5925 -#define SQLITE_INDEX_CONSTRAINT_MATCH 64 5949 +#define SQLITE_INDEX_CONSTRAINT_EQ 2 5950 +#define SQLITE_INDEX_CONSTRAINT_GT 4 5951 +#define SQLITE_INDEX_CONSTRAINT_LE 8 5952 +#define SQLITE_INDEX_CONSTRAINT_LT 16 5953 +#define SQLITE_INDEX_CONSTRAINT_GE 32 5954 +#define SQLITE_INDEX_CONSTRAINT_MATCH 64 5955 +#define SQLITE_INDEX_CONSTRAINT_LIKE 65 5956 +#define SQLITE_INDEX_CONSTRAINT_GLOB 66 5957 +#define SQLITE_INDEX_CONSTRAINT_REGEXP 67 5926 5958 5927 5959 /* 5928 5960 ** CAPI3REF: Register A Virtual Table Implementation 5929 5961 ** METHOD: sqlite3 5930 5962 ** 5931 5963 ** ^These routines are used to register a new [virtual table module] name. 5932 5964 ** ^Module names must be registered before ................................................................................ 6782 6814 ** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt> 6783 6815 ** <dd>This parameter records the largest memory allocation request 6784 6816 ** handed to [scratch memory allocator]. Only the value returned in the 6785 6817 ** *pHighwater parameter to [sqlite3_status()] is of interest. 6786 6818 ** The value written into the *pCurrent parameter is undefined.</dd>)^ 6787 6819 ** 6788 6820 ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt> 6789 -** <dd>This parameter records the deepest parser stack. It is only 6821 +** <dd>The *pHighwater parameter records the deepest parser stack. 6822 +** The *pCurrent value is undefined. The *pHighwater value is only 6790 6823 ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^ 6791 6824 ** </dl> 6792 6825 ** 6793 6826 ** New status parameters may be added from time to time. 6794 6827 */ 6795 6828 #define SQLITE_STATUS_MEMORY_USED 0 6796 6829 #define SQLITE_STATUS_PAGECACHE_USED 1 ................................................................................ 7568 7601 */ 7569 7602 SQLITE_API int SQLITE_STDCALL sqlite3_stricmp(const char *, const char *); 7570 7603 SQLITE_API int SQLITE_STDCALL sqlite3_strnicmp(const char *, const char *, int); 7571 7604 7572 7605 /* 7573 7606 ** CAPI3REF: String Globbing 7574 7607 * 7575 -** ^The [sqlite3_strglob(P,X)] interface returns zero if string X matches 7576 -** the glob pattern P, and it returns non-zero if string X does not match 7577 -** the glob pattern P. ^The definition of glob pattern matching used in 7608 +** ^The [sqlite3_strglob(P,X)] interface returns zero if and only if 7609 +** string X matches the [GLOB] pattern P. 7610 +** ^The definition of [GLOB] pattern matching used in 7578 7611 ** [sqlite3_strglob(P,X)] is the same as for the "X GLOB P" operator in the 7579 -** SQL dialect used by SQLite. ^The sqlite3_strglob(P,X) function is case 7580 -** sensitive. 7612 +** SQL dialect understood by SQLite. ^The [sqlite3_strglob(P,X)] function 7613 +** is case sensitive. 7614 +** 7615 +** Note that this routine returns zero on a match and non-zero if the strings 7616 +** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()]. 7617 +** 7618 +** See also: [sqlite3_strlike()]. 7619 +*/ 7620 +SQLITE_API int SQLITE_STDCALL sqlite3_strglob(const char *zGlob, const char *zStr); 7621 + 7622 +/* 7623 +** CAPI3REF: String LIKE Matching 7624 +* 7625 +** ^The [sqlite3_strlike(P,X,E)] interface returns zero if and only if 7626 +** string X matches the [LIKE] pattern P with escape character E. 7627 +** ^The definition of [LIKE] pattern matching used in 7628 +** [sqlite3_strlike(P,X,E)] is the same as for the "X LIKE P ESCAPE E" 7629 +** operator in the SQL dialect understood by SQLite. ^For "X LIKE P" without 7630 +** the ESCAPE clause, set the E parameter of [sqlite3_strlike(P,X,E)] to 0. 7631 +** ^As with the LIKE operator, the [sqlite3_strlike(P,X,E)] function is case 7632 +** insensitive - equivalent upper and lower case ASCII characters match 7633 +** one another. 7634 +** 7635 +** ^The [sqlite3_strlike(P,X,E)] function matches Unicode characters, though 7636 +** only ASCII characters are case folded. 7581 7637 ** 7582 7638 ** Note that this routine returns zero on a match and non-zero if the strings 7583 7639 ** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()]. 7640 +** 7641 +** See also: [sqlite3_strglob()]. 7584 7642 */ 7585 -SQLITE_API int SQLITE_STDCALL sqlite3_strglob(const char *zGlob, const char *zStr); 7643 +SQLITE_API int SQLITE_STDCALL sqlite3_strlike(const char *zGlob, const char *zStr, unsigned int cEsc); 7586 7644 7587 7645 /* 7588 7646 ** CAPI3REF: Error Logging Interface 7589 7647 ** 7590 7648 ** ^The [sqlite3_log()] interface writes a message into the [error log] 7591 7649 ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()]. 7592 7650 ** ^If logging is enabled, the zFormat string and subsequent arguments are ................................................................................ 8000 8058 ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters. 8001 8059 ** 8002 8060 ** This API is only available if the library is built with pre-processor 8003 8061 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. 8004 8062 */ 8005 8063 SQLITE_API void SQLITE_STDCALL sqlite3_stmt_scanstatus_reset(sqlite3_stmt*); 8006 8064 8065 +/* 8066 +** CAPI3REF: Flush caches to disk mid-transaction 8067 +** 8068 +** ^If a write-transaction is open on [database connection] D when the 8069 +** [sqlite3_db_cacheflush(D)] interface invoked, any dirty 8070 +** pages in the pager-cache that are not currently in use are written out 8071 +** to disk. A dirty page may be in use if a database cursor created by an 8072 +** active SQL statement is reading from it, or if it is page 1 of a database 8073 +** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)] 8074 +** interface flushes caches for all schemas - "main", "temp", and 8075 +** any [attached] databases. 8076 +** 8077 +** ^If this function needs to obtain extra database locks before dirty pages 8078 +** can be flushed to disk, it does so. ^If those locks cannot be obtained 8079 +** immediately and there is a busy-handler callback configured, it is invoked 8080 +** in the usual manner. ^If the required lock still cannot be obtained, then 8081 +** the database is skipped and an attempt made to flush any dirty pages 8082 +** belonging to the next (if any) database. ^If any databases are skipped 8083 +** because locks cannot be obtained, but no other error occurs, this 8084 +** function returns SQLITE_BUSY. 8085 +** 8086 +** ^If any other error occurs while flushing dirty pages to disk (for 8087 +** example an IO error or out-of-memory condition), then processing is 8088 +** abandoned and an SQLite [error code] is returned to the caller immediately. 8089 +** 8090 +** ^Otherwise, if no error occurs, [sqlite3_db_cacheflush()] returns SQLITE_OK. 8091 +** 8092 +** ^This function does not set the database handle error code or message 8093 +** returned by the [sqlite3_errcode()] and [sqlite3_errmsg()] functions. 8094 +*/ 8095 +SQLITE_API int SQLITE_STDCALL sqlite3_db_cacheflush(sqlite3*); 8096 + 8097 +/* 8098 +** CAPI3REF: Database Snapshot 8099 +** KEYWORDS: {snapshot} 8100 +** EXPERIMENTAL 8101 +** 8102 +** An instance of the snapshot object records the state of a [WAL mode] 8103 +** database for some specific point in history. 8104 +** 8105 +** In [WAL mode], multiple [database connections] that are open on the 8106 +** same database file can each be reading a different historical version 8107 +** of the database file. When a [database connection] begins a read 8108 +** transaction, that connection sees an unchanging copy of the database 8109 +** as it existed for the point in time when the transaction first started. 8110 +** Subsequent changes to the database from other connections are not seen 8111 +** by the reader until a new read transaction is started. 8112 +** 8113 +** The sqlite3_snapshot object records state information about an historical 8114 +** version of the database file so that it is possible to later open a new read 8115 +** transaction that sees that historical version of the database rather than 8116 +** the most recent version. 8117 +** 8118 +** The constructor for this object is [sqlite3_snapshot_get()]. The 8119 +** [sqlite3_snapshot_open()] method causes a fresh read transaction to refer 8120 +** to an historical snapshot (if possible). The destructor for 8121 +** sqlite3_snapshot objects is [sqlite3_snapshot_free()]. 8122 +*/ 8123 +typedef struct sqlite3_snapshot sqlite3_snapshot; 8124 + 8125 +/* 8126 +** CAPI3REF: Record A Database Snapshot 8127 +** EXPERIMENTAL 8128 +** 8129 +** ^The [sqlite3_snapshot_get(D,S,P)] interface attempts to make a 8130 +** new [sqlite3_snapshot] object that records the current state of 8131 +** schema S in database connection D. ^On success, the 8132 +** [sqlite3_snapshot_get(D,S,P)] interface writes a pointer to the newly 8133 +** created [sqlite3_snapshot] object into *P and returns SQLITE_OK. 8134 +** ^If schema S of [database connection] D is not a [WAL mode] database 8135 +** that is in a read transaction, then [sqlite3_snapshot_get(D,S,P)] 8136 +** leaves the *P value unchanged and returns an appropriate [error code]. 8137 +** 8138 +** The [sqlite3_snapshot] object returned from a successful call to 8139 +** [sqlite3_snapshot_get()] must be freed using [sqlite3_snapshot_free()] 8140 +** to avoid a memory leak. 8141 +** 8142 +** The [sqlite3_snapshot_get()] interface is only available when the 8143 +** SQLITE_ENABLE_SNAPSHOT compile-time option is used. 8144 +*/ 8145 +SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_get( 8146 + sqlite3 *db, 8147 + const char *zSchema, 8148 + sqlite3_snapshot **ppSnapshot 8149 +); 8150 + 8151 +/* 8152 +** CAPI3REF: Start a read transaction on an historical snapshot 8153 +** EXPERIMENTAL 8154 +** 8155 +** ^The [sqlite3_snapshot_open(D,S,P)] interface attempts to move the 8156 +** read transaction that is currently open on schema S of 8157 +** [database connection] D so that it refers to historical [snapshot] P. 8158 +** ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK on success 8159 +** or an appropriate [error code] if it fails. 8160 +** 8161 +** ^In order to succeed, a call to [sqlite3_snapshot_open(D,S,P)] must be 8162 +** the first operation, apart from other sqlite3_snapshot_open() calls, 8163 +** following the [BEGIN] that starts a new read transaction. 8164 +** ^A [snapshot] will fail to open if it has been overwritten by a 8165 +** [checkpoint]. 8166 +** 8167 +** The [sqlite3_snapshot_open()] interface is only available when the 8168 +** SQLITE_ENABLE_SNAPSHOT compile-time option is used. 8169 +*/ 8170 +SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_open( 8171 + sqlite3 *db, 8172 + const char *zSchema, 8173 + sqlite3_snapshot *pSnapshot 8174 +); 8175 + 8176 +/* 8177 +** CAPI3REF: Destroy a snapshot 8178 +** EXPERIMENTAL 8179 +** 8180 +** ^The [sqlite3_snapshot_free(P)] interface destroys [sqlite3_snapshot] P. 8181 +** The application must eventually free every [sqlite3_snapshot] object 8182 +** using this routine to avoid a memory leak. 8183 +** 8184 +** The [sqlite3_snapshot_free()] interface is only available when the 8185 +** SQLITE_ENABLE_SNAPSHOT compile-time option is used. 8186 +*/ 8187 +SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_STDCALL sqlite3_snapshot_free(sqlite3_snapshot*); 8007 8188 8008 8189 /* 8009 8190 ** Undo the hack that converts floating point types to integer for 8010 8191 ** builds on processors without floating point support. 8011 8192 */ 8012 8193 #ifdef SQLITE_OMIT_FLOATING_POINT 8013 8194 # undef double ................................................................................ 8928 9109 # define SQLITE_INT_TO_PTR(X) ((void*)(intptr_t)(X)) 8929 9110 # define SQLITE_PTR_TO_INT(X) ((int)(intptr_t)(X)) 8930 9111 #else /* Generates a warning - but it always works */ 8931 9112 # define SQLITE_INT_TO_PTR(X) ((void*)(X)) 8932 9113 # define SQLITE_PTR_TO_INT(X) ((int)(X)) 8933 9114 #endif 8934 9115 9116 +/* 9117 +** The SQLITE_WITHIN(P,S,E) macro checks to see if pointer P points to 9118 +** something between S (inclusive) and E (exclusive). 9119 +** 9120 +** In other words, S is a buffer and E is a pointer to the first byte after 9121 +** the end of buffer S. This macro returns true if P points to something 9122 +** contained within the buffer S. 9123 +*/ 9124 +#if defined(HAVE_STDINT_H) 9125 +# define SQLITE_WITHIN(P,S,E) \ 9126 + ((uintptr_t)(P)>=(uintptr_t)(S) && (uintptr_t)(P)<(uintptr_t)(E)) 9127 +#else 9128 +# define SQLITE_WITHIN(P,S,E) ((P)>=(S) && (P)<(E)) 9129 +#endif 9130 + 8935 9131 /* 8936 9132 ** A macro to hint to the compiler that a function should not be 8937 9133 ** inlined. 8938 9134 */ 8939 9135 #if defined(__GNUC__) 8940 9136 # define SQLITE_NOINLINE __attribute__((noinline)) 8941 9137 #elif defined(_MSC_VER) && _MSC_VER>=1310 ................................................................................ 9437 9633 #define TK_TO_TEXT 143 9438 9634 #define TK_TO_BLOB 144 9439 9635 #define TK_TO_NUMERIC 145 9440 9636 #define TK_TO_INT 146 9441 9637 #define TK_TO_REAL 147 9442 9638 #define TK_ISNOT 148 9443 9639 #define TK_END_OF_FILE 149 9444 -#define TK_ILLEGAL 150 9445 -#define TK_SPACE 151 9446 -#define TK_UNCLOSED_STRING 152 9447 -#define TK_FUNCTION 153 9448 -#define TK_COLUMN 154 9449 -#define TK_AGG_FUNCTION 155 9450 -#define TK_AGG_COLUMN 156 9451 -#define TK_UMINUS 157 9452 -#define TK_UPLUS 158 9453 -#define TK_REGISTER 159 9640 +#define TK_UNCLOSED_STRING 150 9641 +#define TK_FUNCTION 151 9642 +#define TK_COLUMN 152 9643 +#define TK_AGG_FUNCTION 153 9644 +#define TK_AGG_COLUMN 154 9645 +#define TK_UMINUS 155 9646 +#define TK_UPLUS 156 9647 +#define TK_REGISTER 157 9648 +#define TK_ASTERISK 158 9649 +#define TK_SPACE 159 9650 +#define TK_ILLEGAL 160 9651 + 9652 +/* The token codes above must all fit in 8 bits */ 9653 +#define TKFLG_MASK 0xff 9654 + 9655 +/* Flags that can be added to a token code when it is not 9656 +** being stored in a u8: */ 9657 +#define TKFLG_DONTFOLD 0x100 /* Omit constant folding optimizations */ 9454 9658 9455 9659 /************** End of parse.h ***********************************************/ 9456 9660 /************** Continuing where we left off in sqliteInt.h ******************/ 9457 9661 #include <stdio.h> 9458 9662 #include <stdlib.h> 9459 9663 #include <string.h> 9460 9664 #include <assert.h> ................................................................................ 9544 9748 ** pagecaches for each database connection. A positive number is the 9545 9749 ** number of pages. A negative number N translations means that a buffer 9546 9750 ** of -1024*N bytes is allocated and used for as many pages as it will hold. 9547 9751 */ 9548 9752 #ifndef SQLITE_DEFAULT_PCACHE_INITSZ 9549 9753 # define SQLITE_DEFAULT_PCACHE_INITSZ 100 9550 9754 #endif 9551 - 9552 9755 9553 9756 /* 9554 9757 ** GCC does not define the offsetof() macro so we'll have to do it 9555 9758 ** ourselves. 9556 9759 */ 9557 9760 #ifndef offsetof 9558 9761 #define offsetof(STRUCTURE,FIELD) ((int)((char*)&((STRUCTURE*)0)->FIELD)) ................................................................................ 9696 9899 ** and whether or not that determination is run-time or compile-time. 9697 9900 ** 9698 9901 ** For best performance, an attempt is made to guess at the byte-order 9699 9902 ** using C-preprocessor macros. If that is unsuccessful, or if 9700 9903 ** -DSQLITE_RUNTIME_BYTEORDER=1 is set, then byte-order is determined 9701 9904 ** at run-time. 9702 9905 */ 9703 -#ifdef SQLITE_AMALGAMATION 9704 -SQLITE_PRIVATE const int sqlite3one = 1; 9705 -#else 9706 -SQLITE_PRIVATE const int sqlite3one; 9707 -#endif 9708 9906 #if (defined(i386) || defined(__i386__) || defined(_M_IX86) || \ 9709 9907 defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \ 9710 9908 defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \ 9711 9909 defined(__arm__)) && !defined(SQLITE_RUNTIME_BYTEORDER) 9712 9910 # define SQLITE_BYTEORDER 1234 9713 9911 # define SQLITE_BIGENDIAN 0 9714 9912 # define SQLITE_LITTLEENDIAN 1 ................................................................................ 9718 9916 && !defined(SQLITE_RUNTIME_BYTEORDER) 9719 9917 # define SQLITE_BYTEORDER 4321 9720 9918 # define SQLITE_BIGENDIAN 1 9721 9919 # define SQLITE_LITTLEENDIAN 0 9722 9920 # define SQLITE_UTF16NATIVE SQLITE_UTF16BE 9723 9921 #endif 9724 9922 #if !defined(SQLITE_BYTEORDER) 9923 +# ifdef SQLITE_AMALGAMATION 9924 + const int sqlite3one = 1; 9925 +# else 9926 + extern const int sqlite3one; 9927 +# endif 9725 9928 # define SQLITE_BYTEORDER 0 /* 0 means "unknown at compile-time" */ 9726 9929 # define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0) 9727 9930 # define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1) 9728 9931 # define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE) 9729 9932 #endif 9730 9933 9731 9934 /* ................................................................................ 10050 10253 #define BTREE_OMIT_JOURNAL 1 /* Do not create or use a rollback journal */ 10051 10254 #define BTREE_MEMORY 2 /* This is an in-memory DB */ 10052 10255 #define BTREE_SINGLE 4 /* The file contains at most 1 b-tree */ 10053 10256 #define BTREE_UNORDERED 8 /* Use of a hash implementation is OK */ 10054 10257 10055 10258 SQLITE_PRIVATE int sqlite3BtreeClose(Btree*); 10056 10259 SQLITE_PRIVATE int sqlite3BtreeSetCacheSize(Btree*,int); 10260 +SQLITE_PRIVATE int sqlite3BtreeSetSpillSize(Btree*,int); 10057 10261 #if SQLITE_MAX_MMAP_SIZE>0 10058 10262 SQLITE_PRIVATE int sqlite3BtreeSetMmapLimit(Btree*,sqlite3_int64); 10059 10263 #endif 10060 10264 SQLITE_PRIVATE int sqlite3BtreeSetPagerFlags(Btree*,unsigned); 10061 10265 SQLITE_PRIVATE int sqlite3BtreeSyncDisabled(Btree*); 10062 10266 SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix); 10063 10267 SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree*); ................................................................................ 10137 10341 #define BTREE_TEXT_ENCODING 5 10138 10342 #define BTREE_USER_VERSION 6 10139 10343 #define BTREE_INCR_VACUUM 7 10140 10344 #define BTREE_APPLICATION_ID 8 10141 10345 #define BTREE_DATA_VERSION 15 /* A virtual meta-value */ 10142 10346 10143 10347 /* 10144 -** Values that may be OR'd together to form the second argument of an 10145 -** sqlite3BtreeCursorHints() call. 10348 +** Kinds of hints that can be passed into the sqlite3BtreeCursorHint() 10349 +** interface. 10350 +** 10351 +** BTREE_HINT_RANGE (arguments: Expr*, Mem*) 10352 +** 10353 +** The first argument is an Expr* (which is guaranteed to be constant for 10354 +** the lifetime of the cursor) that defines constraints on which rows 10355 +** might be fetched with this cursor. The Expr* tree may contain 10356 +** TK_REGISTER nodes that refer to values stored in the array of registers 10357 +** passed as the second parameter. In other words, if Expr.op==TK_REGISTER 10358 +** then the value of the node is the value in Mem[pExpr.iTable]. Any 10359 +** TK_COLUMN node in the expression tree refers to the Expr.iColumn-th 10360 +** column of the b-tree of the cursor. The Expr tree will not contain 10361 +** any function calls nor subqueries nor references to b-trees other than 10362 +** the cursor being hinted. 10363 +** 10364 +** The design of the _RANGE hint is aid b-tree implementations that try 10365 +** to prefetch content from remote machines - to provide those 10366 +** implementations with limits on what needs to be prefetched and thereby 10367 +** reduce network bandwidth. 10368 +** 10369 +** Note that BTREE_HINT_FLAGS with BTREE_BULKLOAD is the only hint used by 10370 +** standard SQLite. The other hints are provided for extentions that use 10371 +** the SQLite parser and code generator but substitute their own storage 10372 +** engine. 10373 +*/ 10374 +#define BTREE_HINT_RANGE 0 /* Range constraints on queries */ 10375 + 10376 +/* 10377 +** Values that may be OR'd together to form the argument to the 10378 +** BTREE_HINT_FLAGS hint for sqlite3BtreeCursorHint(): 10146 10379 ** 10147 10380 ** The BTREE_BULKLOAD flag is set on index cursors when the index is going 10148 10381 ** to be filled with content that is already in sorted order. 10149 10382 ** 10150 10383 ** The BTREE_SEEK_EQ flag is set on cursors that will get OP_SeekGE or 10151 10384 ** OP_SeekLE opcodes for a range search, but where the range of entries 10152 10385 ** selected will all have the same key. In other words, the cursor will 10153 10386 ** be used only for equality key searches. 10154 10387 ** 10155 10388 */ 10156 10389 #define BTREE_BULKLOAD 0x00000001 /* Used to full index in sorted order */ 10157 10390 #define BTREE_SEEK_EQ 0x00000002 /* EQ seeks only - no range seeks */ 10158 10391 10392 +/* 10393 +** Flags passed as the third argument to sqlite3BtreeCursor(). 10394 +** 10395 +** For read-only cursors the wrFlag argument is always zero. For read-write 10396 +** cursors it may be set to either (BTREE_WRCSR|BTREE_FORDELETE) or 10397 +** (BTREE_WRCSR). If the BTREE_FORDELETE flag is set, then the cursor will 10398 +** only be used by SQLite for the following: 10399 +** 10400 +** * to seek to and delete specific entries, and/or 10401 +** 10402 +** * to read values that will be used to create keys that other 10403 +** BTREE_FORDELETE cursors will seek to and delete. 10404 +*/ 10405 +#define BTREE_WRCSR 0x00000004 /* read-write cursor */ 10406 +#define BTREE_FORDELETE 0x00000008 /* Cursor is for seek/delete only */ 10407 + 10159 10408 SQLITE_PRIVATE int sqlite3BtreeCursor( 10160 10409 Btree*, /* BTree containing table to open */ 10161 10410 int iTable, /* Index of root page */ 10162 10411 int wrFlag, /* 1 for writing. 0 for read-only */ 10163 10412 struct KeyInfo*, /* First argument to compare function */ 10164 10413 BtCursor *pCursor /* Space to write cursor structure */ 10165 10414 ); 10166 10415 SQLITE_PRIVATE int sqlite3BtreeCursorSize(void); 10167 10416 SQLITE_PRIVATE void sqlite3BtreeCursorZero(BtCursor*); 10417 +SQLITE_PRIVATE void sqlite3BtreeCursorHintFlags(BtCursor*, unsigned); 10418 +#ifdef SQLITE_ENABLE_CURSOR_HINTS 10419 +SQLITE_PRIVATE void sqlite3BtreeCursorHint(BtCursor*, int, ...); 10420 +#endif 10168 10421 10169 10422 SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor*); 10170 10423 SQLITE_PRIVATE int sqlite3BtreeMovetoUnpacked( 10171 10424 BtCursor*, 10172 10425 UnpackedRecord *pUnKey, 10173 10426 i64 intKey, 10174 10427 int bias, ................................................................................ 10195 10448 SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*); 10196 10449 SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*); 10197 10450 10198 10451 SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*); 10199 10452 SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *); 10200 10453 SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *); 10201 10454 SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion); 10202 -SQLITE_PRIVATE void sqlite3BtreeCursorHints(BtCursor *, unsigned int mask); 10203 -#ifdef SQLITE_DEBUG 10204 10455 SQLITE_PRIVATE int sqlite3BtreeCursorHasHint(BtCursor*, unsigned int mask); 10205 -#endif 10206 10456 SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *pBt); 10207 10457 SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void); 10208 10458 10209 10459 #ifndef NDEBUG 10210 10460 SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*); 10211 10461 #endif 10212 10462 ................................................................................ 10326 10576 sqlite3_context *pCtx; /* Used when p4type is P4_FUNCCTX */ 10327 10577 CollSeq *pColl; /* Used when p4type is P4_COLLSEQ */ 10328 10578 Mem *pMem; /* Used when p4type is P4_MEM */ 10329 10579 VTable *pVtab; /* Used when p4type is P4_VTAB */ 10330 10580 KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */ 10331 10581 int *ai; /* Used when p4type is P4_INTARRAY */ 10332 10582 SubProgram *pProgram; /* Used when p4type is P4_SUBPROGRAM */ 10583 +#ifdef SQLITE_ENABLE_CURSOR_HINTS 10584 + Expr *pExpr; /* Used when p4type is P4_EXPR */ 10585 +#endif 10333 10586 int (*xAdvance)(BtCursor *, int *); 10334 10587 } p4; 10335 10588 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS 10336 10589 char *zComment; /* Comment to improve readability */ 10337 10590 #endif 10338 10591 #ifdef VDBE_PROFILE 10339 10592 u32 cnt; /* Number of times this instruction was executed */ ................................................................................ 10376 10629 */ 10377 10630 #define P4_NOTUSED 0 /* The P4 parameter is not used */ 10378 10631 #define P4_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */ 10379 10632 #define P4_STATIC (-2) /* Pointer to a static string */ 10380 10633 #define P4_COLLSEQ (-4) /* P4 is a pointer to a CollSeq structure */ 10381 10634 #define P4_FUNCDEF (-5) /* P4 is a pointer to a FuncDef structure */ 10382 10635 #define P4_KEYINFO (-6) /* P4 is a pointer to a KeyInfo structure */ 10636 +#define P4_EXPR (-7) /* P4 is a pointer to an Expr tree */ 10383 10637 #define P4_MEM (-8) /* P4 is a pointer to a Mem* structure */ 10384 10638 #define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */ 10385 10639 #define P4_VTAB (-10) /* P4 is a pointer to an sqlite3_vtab structure */ 10386 10640 #define P4_MPRINTF (-11) /* P4 is a string obtained from sqlite3_mprintf() */ 10387 10641 #define P4_REAL (-12) /* P4 is a 64-bit floating point value */ 10388 10642 #define P4_INT64 (-13) /* P4 is a 64-bit signed integer */ 10389 10643 #define P4_INT32 (-14) /* P4 is a 32-bit signed integer */ ................................................................................ 10428 10682 /* 10429 10683 ** The makefile scans the vdbe.c source file and creates the "opcodes.h" 10430 10684 ** header file that defines a number for each opcode used by the VDBE. 10431 10685 */ 10432 10686 /************** Include opcodes.h in the middle of vdbe.h ********************/ 10433 10687 /************** Begin file opcodes.h *****************************************/ 10434 10688 /* Automatically generated. Do not edit */ 10435 -/* See the mkopcodeh.awk script for details */ 10689 +/* See the tool/mkopcodeh.tcl script for details */ 10436 10690 #define OP_Savepoint 1 10437 10691 #define OP_AutoCommit 2 10438 10692 #define OP_Transaction 3 10439 10693 #define OP_SorterNext 4 10440 10694 #define OP_PrevIfOpen 5 10441 10695 #define OP_NextIfOpen 6 10442 10696 #define OP_Prev 7 ................................................................................ 10461 10715 #define OP_Null 26 /* synopsis: r[P2..P3]=NULL */ 10462 10716 #define OP_SoftNull 27 /* synopsis: r[P1]=NULL */ 10463 10717 #define OP_Blob 28 /* synopsis: r[P2]=P4 (len=P1) */ 10464 10718 #define OP_Variable 29 /* synopsis: r[P2]=parameter(P1,P4) */ 10465 10719 #define OP_Move 30 /* synopsis: r[P2@P3]=r[P1@P3] */ 10466 10720 #define OP_Copy 31 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */ 10467 10721 #define OP_SCopy 32 /* synopsis: r[P2]=r[P1] */ 10468 -#define OP_ResultRow 33 /* synopsis: output=r[P1@P2] */ 10469 -#define OP_CollSeq 34 10470 -#define OP_Function0 35 /* synopsis: r[P3]=func(r[P2@P5]) */ 10471 -#define OP_Function 36 /* synopsis: r[P3]=func(r[P2@P5]) */ 10472 -#define OP_AddImm 37 /* synopsis: r[P1]=r[P1]+P2 */ 10473 -#define OP_MustBeInt 38 10474 -#define OP_RealAffinity 39 10475 -#define OP_Cast 40 /* synopsis: affinity(r[P1]) */ 10476 -#define OP_Permutation 41 10477 -#define OP_Compare 42 /* synopsis: r[P1@P3] <-> r[P2@P3] */ 10478 -#define OP_Jump 43 10479 -#define OP_Once 44 10480 -#define OP_If 45 10481 -#define OP_IfNot 46 10482 -#define OP_Column 47 /* synopsis: r[P3]=PX */ 10483 -#define OP_Affinity 48 /* synopsis: affinity(r[P1@P2]) */ 10484 -#define OP_MakeRecord 49 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ 10485 -#define OP_Count 50 /* synopsis: r[P2]=count() */ 10486 -#define OP_ReadCookie 51 10487 -#define OP_SetCookie 52 10488 -#define OP_ReopenIdx 53 /* synopsis: root=P2 iDb=P3 */ 10489 -#define OP_OpenRead 54 /* synopsis: root=P2 iDb=P3 */ 10490 -#define OP_OpenWrite 55 /* synopsis: root=P2 iDb=P3 */ 10491 -#define OP_OpenAutoindex 56 /* synopsis: nColumn=P2 */ 10492 -#define OP_OpenEphemeral 57 /* synopsis: nColumn=P2 */ 10493 -#define OP_SorterOpen 58 10494 -#define OP_SequenceTest 59 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */ 10495 -#define OP_OpenPseudo 60 /* synopsis: P3 columns in r[P2] */ 10496 -#define OP_Close 61 10497 -#define OP_ColumnsUsed 62 10498 -#define OP_SeekLT 63 /* synopsis: key=r[P3@P4] */ 10499 -#define OP_SeekLE 64 /* synopsis: key=r[P3@P4] */ 10500 -#define OP_SeekGE 65 /* synopsis: key=r[P3@P4] */ 10501 -#define OP_SeekGT 66 /* synopsis: key=r[P3@P4] */ 10502 -#define OP_Seek 67 /* synopsis: intkey=r[P2] */ 10503 -#define OP_NoConflict 68 /* synopsis: key=r[P3@P4] */ 10504 -#define OP_NotFound 69 /* synopsis: key=r[P3@P4] */ 10505 -#define OP_Found 70 /* synopsis: key=r[P3@P4] */ 10722 +#define OP_IntCopy 33 /* synopsis: r[P2]=r[P1] */ 10723 +#define OP_ResultRow 34 /* synopsis: output=r[P1@P2] */ 10724 +#define OP_CollSeq 35 10725 +#define OP_Function0 36 /* synopsis: r[P3]=func(r[P2@P5]) */ 10726 +#define OP_Function 37 /* synopsis: r[P3]=func(r[P2@P5]) */ 10727 +#define OP_AddImm 38 /* synopsis: r[P1]=r[P1]+P2 */ 10728 +#define OP_MustBeInt 39 10729 +#define OP_RealAffinity 40 10730 +#define OP_Cast 41 /* synopsis: affinity(r[P1]) */ 10731 +#define OP_Permutation 42 10732 +#define OP_Compare 43 /* synopsis: r[P1@P3] <-> r[P2@P3] */ 10733 +#define OP_Jump 44 10734 +#define OP_Once 45 10735 +#define OP_If 46 10736 +#define OP_IfNot 47 10737 +#define OP_Column 48 /* synopsis: r[P3]=PX */ 10738 +#define OP_Affinity 49 /* synopsis: affinity(r[P1@P2]) */ 10739 +#define OP_MakeRecord 50 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ 10740 +#define OP_Count 51 /* synopsis: r[P2]=count() */ 10741 +#define OP_ReadCookie 52 10742 +#define OP_SetCookie 53 10743 +#define OP_ReopenIdx 54 /* synopsis: root=P2 iDb=P3 */ 10744 +#define OP_OpenRead 55 /* synopsis: root=P2 iDb=P3 */ 10745 +#define OP_OpenWrite 56 /* synopsis: root=P2 iDb=P3 */ 10746 +#define OP_OpenAutoindex 57 /* synopsis: nColumn=P2 */ 10747 +#define OP_OpenEphemeral 58 /* synopsis: nColumn=P2 */ 10748 +#define OP_SorterOpen 59 10749 +#define OP_SequenceTest 60 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */ 10750 +#define OP_OpenPseudo 61 /* synopsis: P3 columns in r[P2] */ 10751 +#define OP_Close 62 10752 +#define OP_ColumnsUsed 63 10753 +#define OP_SeekLT 64 /* synopsis: key=r[P3@P4] */ 10754 +#define OP_SeekLE 65 /* synopsis: key=r[P3@P4] */ 10755 +#define OP_SeekGE 66 /* synopsis: key=r[P3@P4] */ 10756 +#define OP_SeekGT 67 /* synopsis: key=r[P3@P4] */ 10757 +#define OP_Seek 68 /* synopsis: intkey=r[P2] */ 10758 +#define OP_NoConflict 69 /* synopsis: key=r[P3@P4] */ 10759 +#define OP_NotFound 70 /* synopsis: key=r[P3@P4] */ 10506 10760 #define OP_Or 71 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */ 10507 10761 #define OP_And 72 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */ 10508 -#define OP_NotExists 73 /* synopsis: intkey=r[P3] */ 10509 -#define OP_Sequence 74 /* synopsis: r[P2]=cursor[P1].ctr++ */ 10510 -#define OP_NewRowid 75 /* synopsis: r[P2]=rowid */ 10762 +#define OP_Found 73 /* synopsis: key=r[P3@P4] */ 10763 +#define OP_NotExists 74 /* synopsis: intkey=r[P3] */ 10764 +#define OP_Sequence 75 /* synopsis: r[P2]=cursor[P1].ctr++ */ 10511 10765 #define OP_IsNull 76 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */ 10512 10766 #define OP_NotNull 77 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */ 10513 10767 #define OP_Ne 78 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */ 10514 10768 #define OP_Eq 79 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */ 10515 10769 #define OP_Gt 80 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */ 10516 10770 #define OP_Le 81 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */ 10517 10771 #define OP_Lt 82 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */ 10518 10772 #define OP_Ge 83 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */ 10519 -#define OP_Insert 84 /* synopsis: intkey=r[P3] data=r[P2] */ 10773 +#define OP_NewRowid 84 /* synopsis: r[P2]=rowid */ 10520 10774 #define OP_BitAnd 85 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */ 10521 10775 #define OP_BitOr 86 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */ 10522 10776 #define OP_ShiftLeft 87 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */ 10523 10777 #define OP_ShiftRight 88 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */ 10524 10778 #define OP_Add 89 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */ 10525 10779 #define OP_Subtract 90 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */ 10526 10780 #define OP_Multiply 91 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */ 10527 10781 #define OP_Divide 92 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */ 10528 10782 #define OP_Remainder 93 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */ 10529 10783 #define OP_Concat 94 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */ 10530 -#define OP_InsertInt 95 /* synopsis: intkey=P3 data=r[P2] */ 10784 +#define OP_Insert 95 /* synopsis: intkey=r[P3] data=r[P2] */ 10531 10785 #define OP_BitNot 96 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */ 10532 10786 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */ 10533 -#define OP_Delete 98 10534 -#define OP_ResetCount 99 10535 -#define OP_SorterCompare 100 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ 10536 -#define OP_SorterData 101 /* synopsis: r[P2]=data */ 10537 -#define OP_RowKey 102 /* synopsis: r[P2]=key */ 10538 -#define OP_RowData 103 /* synopsis: r[P2]=data */ 10539 -#define OP_Rowid 104 /* synopsis: r[P2]=rowid */ 10540 -#define OP_NullRow 105 10541 -#define OP_Last 106 10542 -#define OP_SorterSort 107 10543 -#define OP_Sort 108 10544 -#define OP_Rewind 109 10545 -#define OP_SorterInsert 110 10546 -#define OP_IdxInsert 111 /* synopsis: key=r[P2] */ 10547 -#define OP_IdxDelete 112 /* synopsis: key=r[P2@P3] */ 10548 -#define OP_IdxRowid 113 /* synopsis: r[P2]=rowid */ 10549 -#define OP_IdxLE 114 /* synopsis: key=r[P3@P4] */ 10550 -#define OP_IdxGT 115 /* synopsis: key=r[P3@P4] */ 10551 -#define OP_IdxLT 116 /* synopsis: key=r[P3@P4] */ 10552 -#define OP_IdxGE 117 /* synopsis: key=r[P3@P4] */ 10553 -#define OP_Destroy 118 10554 -#define OP_Clear 119 10555 -#define OP_ResetSorter 120 10556 -#define OP_CreateIndex 121 /* synopsis: r[P2]=root iDb=P1 */ 10557 -#define OP_CreateTable 122 /* synopsis: r[P2]=root iDb=P1 */ 10558 -#define OP_ParseSchema 123 10559 -#define OP_LoadAnalysis 124 10560 -#define OP_DropTable 125 10561 -#define OP_DropIndex 126 10562 -#define OP_DropTrigger 127 10563 -#define OP_IntegrityCk 128 10564 -#define OP_RowSetAdd 129 /* synopsis: rowset(P1)=r[P2] */ 10565 -#define OP_RowSetRead 130 /* synopsis: r[P3]=rowset(P1) */ 10566 -#define OP_RowSetTest 131 /* synopsis: if r[P3] in rowset(P1) goto P2 */ 10567 -#define OP_Program 132 10787 +#define OP_InsertInt 98 /* synopsis: intkey=P3 data=r[P2] */ 10788 +#define OP_Delete 99 10789 +#define OP_ResetCount 100 10790 +#define OP_SorterCompare 101 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ 10791 +#define OP_SorterData 102 /* synopsis: r[P2]=data */ 10792 +#define OP_RowKey 103 /* synopsis: r[P2]=key */ 10793 +#define OP_RowData 104 /* synopsis: r[P2]=data */ 10794 +#define OP_Rowid 105 /* synopsis: r[P2]=rowid */ 10795 +#define OP_NullRow 106 10796 +#define OP_Last 107 10797 +#define OP_SorterSort 108 10798 +#define OP_Sort 109 10799 +#define OP_Rewind 110 10800 +#define OP_SorterInsert 111 10801 +#define OP_IdxInsert 112 /* synopsis: key=r[P2] */ 10802 +#define OP_IdxDelete 113 /* synopsis: key=r[P2@P3] */ 10803 +#define OP_IdxRowid 114 /* synopsis: r[P2]=rowid */ 10804 +#define OP_IdxLE 115 /* synopsis: key=r[P3@P4] */ 10805 +#define OP_IdxGT 116 /* synopsis: key=r[P3@P4] */ 10806 +#define OP_IdxLT 117 /* synopsis: key=r[P3@P4] */ 10807 +#define OP_IdxGE 118 /* synopsis: key=r[P3@P4] */ 10808 +#define OP_Destroy 119 10809 +#define OP_Clear 120 10810 +#define OP_ResetSorter 121 10811 +#define OP_CreateIndex 122 /* synopsis: r[P2]=root iDb=P1 */ 10812 +#define OP_CreateTable 123 /* synopsis: r[P2]=root iDb=P1 */ 10813 +#define OP_ParseSchema 124 10814 +#define OP_LoadAnalysis 125 10815 +#define OP_DropTable 126 10816 +#define OP_DropIndex 127 10817 +#define OP_DropTrigger 128 10818 +#define OP_IntegrityCk 129 10819 +#define OP_RowSetAdd 130 /* synopsis: rowset(P1)=r[P2] */ 10820 +#define OP_RowSetRead 131 /* synopsis: r[P3]=rowset(P1) */ 10821 +#define OP_RowSetTest 132 /* synopsis: if r[P3] in rowset(P1) goto P2 */ 10568 10822 #define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */ 10569 -#define OP_Param 134 10570 -#define OP_FkCounter 135 /* synopsis: fkctr[P1]+=P2 */ 10571 -#define OP_FkIfZero 136 /* synopsis: if fkctr[P1]==0 goto P2 */ 10572 -#define OP_MemMax 137 /* synopsis: r[P1]=max(r[P1],r[P2]) */ 10573 -#define OP_IfPos 138 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */ 10574 -#define OP_SetIfNotPos 139 /* synopsis: if r[P1]<=0 then r[P2]=P3 */ 10575 -#define OP_IfNotZero 140 /* synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2 */ 10576 -#define OP_DecrJumpZero 141 /* synopsis: if (--r[P1])==0 goto P2 */ 10577 -#define OP_JumpZeroIncr 142 /* synopsis: if (r[P1]++)==0 ) goto P2 */ 10578 -#define OP_AggStep0 143 /* synopsis: accum=r[P3] step(r[P2@P5]) */ 10579 -#define OP_AggStep 144 /* synopsis: accum=r[P3] step(r[P2@P5]) */ 10580 -#define OP_AggFinal 145 /* synopsis: accum=r[P1] N=P2 */ 10581 -#define OP_IncrVacuum 146 10582 -#define OP_Expire 147 10583 -#define OP_TableLock 148 /* synopsis: iDb=P1 root=P2 write=P3 */ 10584 -#define OP_VBegin 149 10585 -#define OP_VCreate 150 10586 -#define OP_VDestroy 151 10587 -#define OP_VOpen 152 10588 -#define OP_VColumn 153 /* synopsis: r[P3]=vcolumn(P2) */ 10589 -#define OP_VNext 154 10590 -#define OP_VRename 155 10591 -#define OP_Pagecount 156 10592 -#define OP_MaxPgcnt 157 10593 -#define OP_Init 158 /* synopsis: Start at P2 */ 10594 -#define OP_Noop 159 10595 -#define OP_Explain 160 10596 - 10823 +#define OP_Program 134 10824 +#define OP_Param 135 10825 +#define OP_FkCounter 136 /* synopsis: fkctr[P1]+=P2 */ 10826 +#define OP_FkIfZero 137 /* synopsis: if fkctr[P1]==0 goto P2 */ 10827 +#define OP_MemMax 138 /* synopsis: r[P1]=max(r[P1],r[P2]) */ 10828 +#define OP_IfPos 139 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */ 10829 +#define OP_SetIfNotPos 140 /* synopsis: if r[P1]<=0 then r[P2]=P3 */ 10830 +#define OP_IfNotZero 141 /* synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2 */ 10831 +#define OP_DecrJumpZero 142 /* synopsis: if (--r[P1])==0 goto P2 */ 10832 +#define OP_JumpZeroIncr 143 /* synopsis: if (r[P1]++)==0 ) goto P2 */ 10833 +#define OP_AggStep0 144 /* synopsis: accum=r[P3] step(r[P2@P5]) */ 10834 +#define OP_AggStep 145 /* synopsis: accum=r[P3] step(r[P2@P5]) */ 10835 +#define OP_AggFinal 146 /* synopsis: accum=r[P1] N=P2 */ 10836 +#define OP_IncrVacuum 147 10837 +#define OP_Expire 148 10838 +#define OP_TableLock 149 /* synopsis: iDb=P1 root=P2 write=P3 */ 10839 +#define OP_VBegin 150 10840 +#define OP_VCreate 151 10841 +#define OP_VDestroy 152 10842 +#define OP_VOpen 153 10843 +#define OP_VColumn 154 /* synopsis: r[P3]=vcolumn(P2) */ 10844 +#define OP_VNext 155 10845 +#define OP_VRename 156 10846 +#define OP_Pagecount 157 10847 +#define OP_MaxPgcnt 158 10848 +#define OP_Init 159 /* synopsis: Start at P2 */ 10849 +#define OP_CursorHint 160 10850 +#define OP_Noop 161 10851 +#define OP_Explain 162 10597 10852 10598 10853 /* Properties such as "out2" or "jump" that are specified in 10599 10854 ** comments following the "case" for each opcode in the vdbe.c 10600 10855 ** are encoded into bitvectors as follows: 10601 10856 */ 10602 10857 #define OPFLG_JUMP 0x0001 /* jump: P2 holds jmp target */ 10603 10858 #define OPFLG_IN1 0x0002 /* in1: P1 is an input */ ................................................................................ 10606 10861 #define OPFLG_OUT2 0x0010 /* out2: P2 is an output */ 10607 10862 #define OPFLG_OUT3 0x0020 /* out3: P3 is an output */ 10608 10863 #define OPFLG_INITIALIZER {\ 10609 10864 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01,\ 10610 10865 /* 8 */ 0x01, 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01,\ 10611 10866 /* 16 */ 0x02, 0x01, 0x02, 0x12, 0x03, 0x08, 0x00, 0x10,\ 10612 10867 /* 24 */ 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00,\ 10613 -/* 32 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x02,\ 10614 -/* 40 */ 0x02, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x00,\ 10615 -/* 48 */ 0x00, 0x00, 0x10, 0x10, 0x08, 0x00, 0x00, 0x00,\ 10616 -/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09,\ 10617 -/* 64 */ 0x09, 0x09, 0x09, 0x04, 0x09, 0x09, 0x09, 0x26,\ 10618 -/* 72 */ 0x26, 0x09, 0x10, 0x10, 0x03, 0x03, 0x0b, 0x0b,\ 10619 -/* 80 */ 0x0b, 0x0b, 0x0b, 0x0b, 0x00, 0x26, 0x26, 0x26,\ 10868 +/* 32 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03,\ 10869 +/* 40 */ 0x02, 0x02, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03,\ 10870 +/* 48 */ 0x00, 0x00, 0x00, 0x10, 0x10, 0x08, 0x00, 0x00,\ 10871 +/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ 10872 +/* 64 */ 0x09, 0x09, 0x09, 0x09, 0x04, 0x09, 0x09, 0x26,\ 10873 +/* 72 */ 0x26, 0x09, 0x09, 0x10, 0x03, 0x03, 0x0b, 0x0b,\ 10874 +/* 80 */ 0x0b, 0x0b, 0x0b, 0x0b, 0x10, 0x26, 0x26, 0x26,\ 10620 10875 /* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00,\ 10621 10876 /* 96 */ 0x12, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ 10622 -/* 104 */ 0x10, 0x00, 0x01, 0x01, 0x01, 0x01, 0x04, 0x04,\ 10623 -/* 112 */ 0x00, 0x10, 0x01, 0x01, 0x01, 0x01, 0x10, 0x00,\ 10624 -/* 120 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\ 10625 -/* 128 */ 0x00, 0x06, 0x23, 0x0b, 0x01, 0x10, 0x10, 0x00,\ 10626 -/* 136 */ 0x01, 0x04, 0x03, 0x06, 0x03, 0x03, 0x03, 0x00,\ 10627 -/* 144 */ 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,\ 10628 -/* 152 */ 0x00, 0x00, 0x01, 0x00, 0x10, 0x10, 0x01, 0x00,\ 10629 -/* 160 */ 0x00,} 10877 +/* 104 */ 0x00, 0x10, 0x00, 0x01, 0x01, 0x01, 0x01, 0x04,\ 10878 +/* 112 */ 0x04, 0x00, 0x10, 0x01, 0x01, 0x01, 0x01, 0x10,\ 10879 +/* 120 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\ 10880 +/* 128 */ 0x00, 0x00, 0x06, 0x23, 0x0b, 0x10, 0x01, 0x10,\ 10881 +/* 136 */ 0x00, 0x01, 0x04, 0x03, 0x06, 0x03, 0x03, 0x03,\ 10882 +/* 144 */ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,\ 10883 +/* 152 */ 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x10, 0x01,\ 10884 +/* 160 */ 0x00, 0x00, 0x00,} 10630 10885 10631 10886 /************** End of opcodes.h *********************************************/ 10632 10887 /************** Continuing where we left off in vdbe.h ***********************/ 10633 10888 10634 10889 /* 10635 10890 ** Prototypes for the VDBE interface. See comments on the implementation 10636 10891 ** for a description of what each of these routines does. ................................................................................ 10849 11104 #define PAGER_JOURNALMODE_PERSIST 1 /* Commit by zeroing journal header */ 10850 11105 #define PAGER_JOURNALMODE_OFF 2 /* Journal omitted. */ 10851 11106 #define PAGER_JOURNALMODE_TRUNCATE 3 /* Commit by truncating journal */ 10852 11107 #define PAGER_JOURNALMODE_MEMORY 4 /* In-memory journal file */ 10853 11108 #define PAGER_JOURNALMODE_WAL 5 /* Use write-ahead logging */ 10854 11109 10855 11110 /* 10856 -** Flags that make up the mask passed to sqlite3PagerAcquire(). 11111 +** Flags that make up the mask passed to sqlite3PagerGet(). 10857 11112 */ 10858 11113 #define PAGER_GET_NOCONTENT 0x01 /* Do not load data from disk */ 10859 11114 #define PAGER_GET_READONLY 0x02 /* Read-only page is acceptable */ 10860 11115 10861 11116 /* 10862 11117 ** Flags for sqlite3PagerSetFlags() 10863 11118 */ ................................................................................ 10893 11148 SQLITE_PRIVATE void sqlite3PagerSetBusyhandler(Pager*, int(*)(void *), void *); 10894 11149 SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u32*, int); 10895 11150 #ifdef SQLITE_HAS_CODEC 10896 11151 SQLITE_PRIVATE void sqlite3PagerAlignReserve(Pager*,Pager*); 10897 11152 #endif 10898 11153 SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager*, int); 10899 11154 SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager*, int); 11155 +SQLITE_PRIVATE int sqlite3PagerSetSpillsize(Pager*, int); 10900 11156 SQLITE_PRIVATE void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64); 10901 11157 SQLITE_PRIVATE void sqlite3PagerShrink(Pager*); 10902 11158 SQLITE_PRIVATE void sqlite3PagerSetFlags(Pager*,unsigned); 10903 11159 SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *, int); 10904 11160 SQLITE_PRIVATE int sqlite3PagerSetJournalMode(Pager *, int); 10905 11161 SQLITE_PRIVATE int sqlite3PagerGetJournalMode(Pager*); 10906 11162 SQLITE_PRIVATE int sqlite3PagerOkToChangeJournalMode(Pager*); 10907 11163 SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *, i64); 10908 11164 SQLITE_PRIVATE sqlite3_backup **sqlite3PagerBackupPtr(Pager*); 11165 +SQLITE_PRIVATE int sqlite3PagerFlush(Pager*); 10909 11166 10910 11167 /* Functions used to obtain and release page references. */ 10911 -SQLITE_PRIVATE int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag); 10912 -#define sqlite3PagerGet(A,B,C) sqlite3PagerAcquire(A,B,C,0) 11168 +SQLITE_PRIVATE int sqlite3PagerGet(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag); 10913 11169 SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno); 10914 11170 SQLITE_PRIVATE void sqlite3PagerRef(DbPage*); 10915 11171 SQLITE_PRIVATE void sqlite3PagerUnref(DbPage*); 10916 11172 SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage*); 10917 11173 10918 11174 /* Operations on page references. */ 10919 11175 SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*); ................................................................................ 10937 11193 10938 11194 #ifndef SQLITE_OMIT_WAL 10939 11195 SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, int, int*, int*); 10940 11196 SQLITE_PRIVATE int sqlite3PagerWalSupported(Pager *pPager); 10941 11197 SQLITE_PRIVATE int sqlite3PagerWalCallback(Pager *pPager); 10942 11198 SQLITE_PRIVATE int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen); 10943 11199 SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager); 11200 +# ifdef SQLITE_ENABLE_SNAPSHOT 11201 +SQLITE_PRIVATE int sqlite3PagerSnapshotGet(Pager *pPager, sqlite3_snapshot **ppSnapshot); 11202 +SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *pSnapshot); 11203 +# endif 10944 11204 #endif 10945 11205 10946 11206 #ifdef SQLITE_ENABLE_ZIPVFS 10947 11207 SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager); 10948 11208 #endif 10949 11209 10950 11210 /* Functions used to query pager state and configuration. */ ................................................................................ 10951 11211 SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*); 10952 11212 SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager*); 10953 11213 #ifdef SQLITE_DEBUG 10954 11214 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*); 10955 11215 #endif 10956 11216 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*); 10957 11217 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*, int); 10958 -SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*); 11218 +SQLITE_PRIVATE sqlite3_vfs *sqlite3PagerVfs(Pager*); 10959 11219 SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*); 10960 11220 SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*); 10961 11221 SQLITE_PRIVATE int sqlite3PagerNosync(Pager*); 10962 11222 SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*); 10963 11223 SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*); 10964 11224 SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *, int, int, int *); 10965 11225 SQLITE_PRIVATE void sqlite3PagerClearCache(Pager *); ................................................................................ 11138 11398 ** the total number of pages cached by purgeable pager-caches to the sum 11139 11399 ** of the suggested cache-sizes. 11140 11400 */ 11141 11401 SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *, int); 11142 11402 #ifdef SQLITE_TEST 11143 11403 SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *); 11144 11404 #endif 11405 + 11406 +/* Set or get the suggested spill-size for the specified pager-cache. 11407 +** 11408 +** The spill-size is the minimum number of pages in cache before the cache 11409 +** will attempt to spill dirty pages by calling xStress. 11410 +*/ 11411 +SQLITE_PRIVATE int sqlite3PcacheSetSpillsize(PCache *, int); 11145 11412 11146 11413 /* Free up as much memory as possible from the page cache */ 11147 11414 SQLITE_PRIVATE void sqlite3PcacheShrink(PCache*); 11148 11415 11149 11416 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT 11150 11417 /* Try to return memory used by the pcache module to the main memory heap */ 11151 11418 SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int); ................................................................................ 11850 12117 #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */ 11851 12118 #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */ 11852 12119 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */ 11853 12120 #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */ 11854 12121 #define SQLITE_Transitive 0x0200 /* Transitive constraints */ 11855 12122 #define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */ 11856 12123 #define SQLITE_Stat34 0x0800 /* Use STAT3 or STAT4 data */ 12124 +#define SQLITE_CursorHints 0x2000 /* Add OP_CursorHint opcodes */ 11857 12125 #define SQLITE_AllOpts 0xffff /* All optimizations */ 11858 12126 11859 12127 /* 11860 12128 ** Macros for testing whether or not optimizations are enabled or disabled. 11861 12129 */ 11862 12130 #ifndef SQLITE_OMIT_BUILTIN_TEST 11863 12131 #define OptimizationDisabled(db, mask) (((db)->dbOptFlags&(mask))!=0) ................................................................................ 11922 12190 int nRef; 11923 12191 void (*xDestroy)(void *); 11924 12192 void *pUserData; 11925 12193 }; 11926 12194 11927 12195 /* 11928 12196 ** Possible values for FuncDef.flags. Note that the _LENGTH and _TYPEOF 11929 -** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. There 12197 +** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. And 12198 +** SQLITE_FUNC_CONSTANT must be the same as SQLITE_DETERMINISTIC. There 11930 12199 ** are assert() statements in the code to verify this. 11931 12200 */ 11932 12201 #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */ 11933 12202 #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */ 11934 12203 #define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */ 11935 12204 #define SQLITE_FUNC_EPHEM 0x0010 /* Ephemeral. Delete with VDBE */ 11936 12205 #define SQLITE_FUNC_NEEDCOLL 0x0020 /* sqlite3GetFuncCollSeq() might be called*/ ................................................................................ 12046 12315 char *zName; /* Name of this column */ 12047 12316 Expr *pDflt; /* Default value of this column */ 12048 12317 char *zDflt; /* Original text of the default value */ 12049 12318 char *zType; /* Data type for this column */ 12050 12319 char *zColl; /* Collating sequence. If NULL, use the default */ 12051 12320 u8 notNull; /* An OE_ code for handling a NOT NULL constraint */ 12052 12321 char affinity; /* One of the SQLITE_AFF_... values */ 12053 - u8 szEst; /* Estimated size of this column. INT==1 */ 12322 + u8 szEst; /* Estimated size of value in this column. sizeof(INT)==1 */ 12054 12323 u8 colFlags; /* Boolean properties. See COLFLAG_ defines below */ 12055 12324 }; 12056 12325 12057 12326 /* Allowed values for Column.colFlags: 12058 12327 */ 12059 12328 #define COLFLAG_PRIMKEY 0x0001 /* Column is part of the primary key */ 12060 12329 #define COLFLAG_HIDDEN 0x0002 /* A hidden column in a virtual table */ ................................................................................ 12213 12482 Schema *pSchema; /* Schema that contains this table */ 12214 12483 Table *pNextZombie; /* Next on the Parse.pZombieTab list */ 12215 12484 }; 12216 12485 12217 12486 /* 12218 12487 ** Allowed values for Table.tabFlags. 12219 12488 ** 12220 -** TF_OOOHidden applies to virtual tables that have hidden columns that are 12489 +** TF_OOOHidden applies to tables or view that have hidden columns that are 12221 12490 ** followed by non-hidden columns. Example: "CREATE VIRTUAL TABLE x USING 12222 12491 ** vtab1(a HIDDEN, b);". Since "b" is a non-hidden column but "a" is hidden, 12223 12492 ** the TF_OOOHidden attribute would apply in this case. Such tables require 12224 12493 ** special handling during INSERT processing. 12225 12494 */ 12226 12495 #define TF_Readonly 0x01 /* Read-only system table */ 12227 12496 #define TF_Ephemeral 0x02 /* An ephemeral table */ ................................................................................ 12236 12505 /* 12237 12506 ** Test to see whether or not a table is a virtual table. This is 12238 12507 ** done as a macro so that it will be optimized out when virtual 12239 12508 ** table support is omitted from the build. 12240 12509 */ 12241 12510 #ifndef SQLITE_OMIT_VIRTUALTABLE 12242 12511 # define IsVirtual(X) (((X)->tabFlags & TF_Virtual)!=0) 12243 -# define IsHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0) 12244 12512 #else 12245 12513 # define IsVirtual(X) 0 12246 -# define IsHiddenColumn(X) 0 12247 12514 #endif 12515 + 12516 +/* 12517 +** Macros to determine if a column is hidden. IsOrdinaryHiddenColumn() 12518 +** only works for non-virtual tables (ordinary tables and views) and is 12519 +** always false unless SQLITE_ENABLE_HIDDEN_COLUMNS is defined. The 12520 +** IsHiddenColumn() macro is general purpose. 12521 +*/ 12522 +#if defined(SQLITE_ENABLE_HIDDEN_COLUMNS) 12523 +# define IsHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0) 12524 +# define IsOrdinaryHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0) 12525 +#elif !defined(SQLITE_OMIT_VIRTUALTABLE) 12526 +# define IsHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0) 12527 +# define IsOrdinaryHiddenColumn(X) 0 12528 +#else 12529 +# define IsHiddenColumn(X) 0 12530 +# define IsOrdinaryHiddenColumn(X) 0 12531 +#endif 12532 + 12248 12533 12249 12534 /* Does the table have a rowid */ 12250 12535 #define HasRowid(X) (((X)->tabFlags & TF_WithoutRowid)==0) 12251 12536 #define VisibleRowid(X) (((X)->tabFlags & TF_NoVisibleRowid)==0) 12252 12537 12253 12538 /* 12254 12539 ** Each foreign key constraint is an instance of the following structure. ................................................................................ 12351 12636 u16 nXField; /* Number of columns beyond the key columns */ 12352 12637 sqlite3 *db; /* The database connection */ 12353 12638 u8 *aSortOrder; /* Sort order for each column. */ 12354 12639 CollSeq *aColl[1]; /* Collating sequence for each term of the key */ 12355 12640 }; 12356 12641 12357 12642 /* 12358 -** An instance of the following structure holds information about a 12359 -** single index record that has already been parsed out into individual 12360 -** values. 12643 +** This object holds a record which has been parsed out into individual 12644 +** fields, for the purposes of doing a comparison. 12361 12645 ** 12362 12646 ** A record is an object that contains one or more fields of data. 12363 12647 ** Records are used to store the content of a table row and to store 12364 12648 ** the key of an index. A blob encoding of a record is created by 12365 12649 ** the OP_MakeRecord opcode of the VDBE and is disassembled by the 12366 12650 ** OP_Column opcode. 12367 12651 ** 12368 -** This structure holds a record that has already been disassembled 12369 -** into its constituent fields. 12652 +** An instance of this object serves as a "key" for doing a search on 12653 +** an index b+tree. The goal of the search is to find the entry that 12654 +** is closed to the key described by this object. This object might hold 12655 +** just a prefix of the key. The number of fields is given by 12656 +** pKeyInfo->nField. 12370 12657 ** 12371 -** The r1 and r2 member variables are only used by the optimized comparison 12372 -** functions vdbeRecordCompareInt() and vdbeRecordCompareString(). 12658 +** The r1 and r2 fields are the values to return if this key is less than 12659 +** or greater than a key in the btree, respectively. These are normally 12660 +** -1 and +1 respectively, but might be inverted to +1 and -1 if the b-tree 12661 +** is in DESC order. 12662 +** 12663 +** The key comparison functions actually return default_rc when they find 12664 +** an equals comparison. default_rc can be -1, 0, or +1. If there are 12665 +** multiple entries in the b-tree with the same key (when only looking 12666 +** at the first pKeyInfo->nFields,) then default_rc can be set to -1 to 12667 +** cause the search to find the last match, or +1 to cause the search to 12668 +** find the first match. 12669 +** 12670 +** The key comparison functions will set eqSeen to true if they ever 12671 +** get and equal results when comparing this structure to a b-tree record. 12672 +** When default_rc!=0, the search might end up on the record immediately 12673 +** before the first match or immediately after the last match. The 12674 +** eqSeen field will indicate whether or not an exact match exists in the 12675 +** b-tree. 12373 12676 */ 12374 12677 struct UnpackedRecord { 12375 12678 KeyInfo *pKeyInfo; /* Collation and sort-order information */ 12679 + Mem *aMem; /* Values */ 12376 12680 u16 nField; /* Number of entries in apMem[] */ 12377 12681 i8 default_rc; /* Comparison result if keys are equal */ 12378 12682 u8 errCode; /* Error detected by xRecordCompare (CORRUPT or NOMEM) */ 12379 - Mem *aMem; /* Values */ 12380 - int r1; /* Value to return if (lhs > rhs) */ 12381 - int r2; /* Value to return if (rhs < lhs) */ 12683 + i8 r1; /* Value to return if (lhs > rhs) */ 12684 + i8 r2; /* Value to return if (rhs < lhs) */ 12685 + u8 eqSeen; /* True if an equality comparison has been seen */ 12382 12686 }; 12383 12687 12384 12688 12385 12689 /* 12386 12690 ** Each SQL index is represented in memory by an 12387 12691 ** instance of the following structure. 12388 12692 ** ................................................................................ 12421 12725 i16 *aiColumn; /* Which columns are used by this index. 1st is 0 */ 12422 12726 LogEst *aiRowLogEst; /* From ANALYZE: Est. rows selected by each column */ 12423 12727 Table *pTable; /* The SQL table being indexed */ 12424 12728 char *zColAff; /* String defining the affinity of each column */ 12425 12729 Index *pNext; /* The next index associated with the same table */ 12426 12730 Schema *pSchema; /* Schema containing this index */ 12427 12731 u8 *aSortOrder; /* for each column: True==DESC, False==ASC */ 12428 - char **azColl; /* Array of collation sequence names for index */ 12732 + const char **azColl; /* Array of collation sequence names for index */ 12429 12733 Expr *pPartIdxWhere; /* WHERE clause for partial indices */ 12430 12734 ExprList *aColExpr; /* Column expressions */ 12431 12735 int tnum; /* DB Page containing root of this index */ 12432 12736 LogEst szIdxRow; /* Estimated average row size in bytes */ 12433 12737 u16 nKeyCol; /* Number of columns forming the key */ 12434 12738 u16 nColumn; /* Number of columns stored in the index */ 12435 12739 u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */ ................................................................................ 13016 13320 #define SF_Values 0x0100 /* Synthesized from VALUES clause */ 13017 13321 #define SF_MultiValue 0x0200 /* Single VALUES term with multiple rows */ 13018 13322 #define SF_NestedFrom 0x0400 /* Part of a parenthesized FROM clause */ 13019 13323 #define SF_MaybeConvert 0x0800 /* Need convertCompoundSelectToSubquery() */ 13020 13324 #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */ 13021 13325 #define SF_Recursive 0x2000 /* The recursive part of a recursive CTE */ 13022 13326 #define SF_Converted 0x4000 /* By convertCompoundSelectToSubquery() */ 13327 +#define SF_IncludeHidden 0x8000 /* Include hidden columns in output */ 13023 13328 13024 13329 13025 13330 /* 13026 13331 ** The results of a SELECT can be distributed in several ways, as defined 13027 13332 ** by one of the following macros. The "SRT" prefix means "SELECT Result 13028 13333 ** Type". 13029 13334 ** ................................................................................ 13274 13579 ** using offsetof(Parse,nVar) so the nVar field must be the first field 13275 13580 ** in the recursive region. 13276 13581 ************************************************************************/ 13277 13582 13278 13583 int nVar; /* Number of '?' variables seen in the SQL so far */ 13279 13584 int nzVar; /* Number of available slots in azVar[] */ 13280 13585 u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */ 13281 - u8 bFreeWith; /* True if pWith should be freed with parser */ 13282 13586 u8 explain; /* True if the EXPLAIN flag is found on the query */ 13283 13587 #ifndef SQLITE_OMIT_VIRTUALTABLE 13284 13588 u8 declareVtab; /* True if inside sqlite3_declare_vtab() */ 13285 13589 int nVtabLock; /* Number of virtual tables to lock */ 13286 13590 #endif 13287 13591 int nAlias; /* Number of aliased result set columns */ 13288 13592 int nHeight; /* Expression tree height of current sub-select */ ................................................................................ 13301 13605 #ifndef SQLITE_OMIT_VIRTUALTABLE 13302 13606 Token sArg; /* Complete text of a module argument */ 13303 13607 Table **apVtabLock; /* Pointer to virtual tables needing locking */ 13304 13608 #endif 13305 13609 Table *pZombieTab; /* List of Table objects to delete after code gen */ 13306 13610 TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */ 13307 13611 With *pWith; /* Current WITH clause, or NULL */ 13612 + With *pWithToFree; /* Free this WITH object at the end of the parse */ 13308 13613 }; 13309 13614 13310 13615 /* 13311 13616 ** Return true if currently inside an sqlite3_declare_vtab() call. 13312 13617 */ 13313 13618 #ifdef SQLITE_OMIT_VIRTUALTABLE 13314 13619 #define IN_DECLARE_VTAB 0 ................................................................................ 13334 13639 #define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */ 13335 13640 #define OPFLAG_APPEND 0x08 /* This is likely to be an append */ 13336 13641 #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */ 13337 13642 #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */ 13338 13643 #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */ 13339 13644 #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */ 13340 13645 #define OPFLAG_SEEKEQ 0x02 /* OP_Open** cursor uses EQ seek only */ 13341 -#define OPFLAG_P2ISREG 0x04 /* P2 to OP_Open** is a register number */ 13646 +#define OPFLAG_FORDELETE 0x08 /* OP_Open is opening for-delete csr */ 13647 +#define OPFLAG_P2ISREG 0x10 /* P2 to OP_Open** is a register number */ 13342 13648 #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */ 13343 13649 13344 13650 /* 13345 13651 * Each trigger present in the database schema is stored as an instance of 13346 13652 * struct Trigger. 13347 13653 * 13348 13654 * Pointers to instances of struct Trigger are stored in two ways. ................................................................................ 13454 13760 sqlite3 *db; /* Optional database for lookaside. Can be NULL */ 13455 13761 char *zBase; /* A base allocation. Not from malloc. */ 13456 13762 char *zText; /* The string collected so far */ 13457 13763 int nChar; /* Length of the string so far */ 13458 13764 int nAlloc; /* Amount of space allocated in zText */ 13459 13765 int mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */ 13460 13766 u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */ 13767 + u8 bMalloced; /* zText points to allocated space */ 13461 13768 }; 13462 13769 #define STRACCUM_NOMEM 1 13463 13770 #define STRACCUM_TOOBIG 2 13464 13771 13465 13772 /* 13466 13773 ** A pointer to this structure is used to communicate information 13467 13774 ** from sqlite3Init and OP_ParseSchema into the sqlite3InitCallback. ................................................................................ 13563 13870 u8 eCode; /* A small processing code */ 13564 13871 union { /* Extra data for callback */ 13565 13872 NameContext *pNC; /* Naming context */ 13566 13873 int n; /* A counter */ 13567 13874 int iCur; /* A cursor number */ 13568 13875 SrcList *pSrcList; /* FROM clause */ 13569 13876 struct SrcCount *pSrcCount; /* Counting column references */ 13877 + struct CCurHint *pCCurHint; /* Used by codeCursorHint() */ 13570 13878 } u; 13571 13879 }; 13572 13880 13573 13881 /* Forward declarations */ 13574 13882 SQLITE_PRIVATE int sqlite3WalkExpr(Walker*, Expr*); 13575 13883 SQLITE_PRIVATE int sqlite3WalkExprList(Walker*, ExprList*); 13576 13884 SQLITE_PRIVATE int sqlite3WalkSelect(Walker*, Select*); 13577 13885 SQLITE_PRIVATE int sqlite3WalkSelectExpr(Walker*, Select*); 13578 13886 SQLITE_PRIVATE int sqlite3WalkSelectFrom(Walker*, Select*); 13887 +SQLITE_PRIVATE int sqlite3ExprWalkNoop(Walker*, Expr*); 13579 13888 13580 13889 /* 13581 13890 ** Return code from the parse-tree walking primitives and their 13582 13891 ** callbacks. 13583 13892 */ 13584 13893 #define WRC_Continue 0 /* Continue down into children */ 13585 13894 #define WRC_Prune 1 /* Omit children but continue walking siblings */ ................................................................................ 13749 14058 #else 13750 14059 # define sqlite3MemoryBarrier() 13751 14060 #endif 13752 14061 13753 14062 SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue(int); 13754 14063 SQLITE_PRIVATE void sqlite3StatusUp(int, int); 13755 14064 SQLITE_PRIVATE void sqlite3StatusDown(int, int); 13756 -SQLITE_PRIVATE void sqlite3StatusSet(int, int); 14065 +SQLITE_PRIVATE void sqlite3StatusHighwater(int, int); 13757 14066 13758 14067 /* Access to mutexes used by sqlite3_status() */ 13759 14068 SQLITE_PRIVATE sqlite3_mutex *sqlite3Pcache1Mutex(void); 13760 14069 SQLITE_PRIVATE sqlite3_mutex *sqlite3MallocMutex(void); 13761 14070 13762 14071 #ifndef SQLITE_OMIT_FLOATING_POINT 13763 14072 SQLITE_PRIVATE int sqlite3IsNaN(double); ................................................................................ 13788 14097 SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*); 13789 14098 #endif 13790 14099 13791 14100 #if defined(SQLITE_DEBUG) 13792 14101 SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView*, const Expr*, u8); 13793 14102 SQLITE_PRIVATE void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*); 13794 14103 SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView*, const Select*, u8); 14104 +SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView*, const With*, u8); 13795 14105 #endif 13796 14106 13797 14107 13798 14108 SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*); 13799 14109 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...); 13800 14110 SQLITE_PRIVATE int sqlite3Dequote(char*); 13801 14111 SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char*, int); ................................................................................ 13831 14141 SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3*,Table*); 13832 14142 SQLITE_PRIVATE int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**); 13833 14143 SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*); 13834 14144 SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *, int); 13835 14145 SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table*); 13836 14146 SQLITE_PRIVATE i16 sqlite3ColumnOfIndex(Index*, i16); 13837 14147 SQLITE_PRIVATE void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int); 14148 +#if SQLITE_ENABLE_HIDDEN_COLUMNS 14149 +SQLITE_PRIVATE void sqlite3ColumnPropertiesFromName(Table*, Column*); 14150 +#else 14151 +# define sqlite3ColumnPropertiesFromName(T,C) /* no-op */ 14152 +#endif 13838 14153 SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token*); 13839 14154 SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int); 13840 14155 SQLITE_PRIVATE void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int); 13841 14156 SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*); 13842 14157 SQLITE_PRIVATE void sqlite3AddColumnType(Parse*,Token*); 13843 14158 SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,ExprSpan*); 13844 14159 SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*); ................................................................................ 13933 14248 SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*); 13934 14249 SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo*, int*); 13935 14250 #define ONEPASS_OFF 0 /* Use of ONEPASS not allowed */ 13936 14251 #define ONEPASS_SINGLE 1 /* ONEPASS valid for a single row update */ 13937 14252 #define ONEPASS_MULTI 2 /* ONEPASS is valid for multiple rows */ 13938 14253 SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn(Parse*, Index*, int, int, int); 13939 14254 SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8); 14255 +SQLITE_PRIVATE void sqlite3ExprCodeGetColumnToReg(Parse*, Table*, int, int, int); 13940 14256 SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int); 13941 14257 SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int); 13942 14258 SQLITE_PRIVATE void sqlite3ExprCacheStore(Parse*, int, int, int); 13943 14259 SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*); 13944 14260 SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*); 13945 14261 SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int); 13946 14262 SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*); 13947 14263 SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int); 13948 14264 SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int); 14265 +SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, Expr*, int); 13949 14266 SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int); 13950 14267 SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8); 13951 14268 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*); 13952 14269 SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int); 13953 14270 SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int); 13954 14271 SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int, u8); 13955 14272 #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */ ................................................................................ 13987 14304 SQLITE_PRIVATE void sqlite3Savepoint(Parse*, int, Token*); 13988 14305 SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *); 13989 14306 SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*); 13990 14307 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*); 13991 14308 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*); 13992 14309 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8); 13993 14310 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int); 14311 +#ifdef SQLITE_ENABLE_CURSOR_HINTS 14312 +SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*); 14313 +#endif 13994 14314 SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*); 13995 14315 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*); 13996 14316 SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char); 13997 14317 SQLITE_PRIVATE int sqlite3IsRowid(const char*); 13998 14318 SQLITE_PRIVATE void sqlite3GenerateRowDelete( 13999 14319 Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8,int); 14000 14320 SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*, int); 14001 14321 SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int); 14002 14322 SQLITE_PRIVATE void sqlite3ResolvePartIdxLabel(Parse*,int); 14003 14323 SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int, 14004 14324 u8,u8,int,int*); 14005 14325 SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int); 14006 -SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, int, u8*, int*, int*); 14326 +SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, u8, int, u8*, int*, int*); 14007 14327 SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse*, int, int); 14008 14328 SQLITE_PRIVATE void sqlite3MultiWrite(Parse*); 14009 14329 SQLITE_PRIVATE void sqlite3MayAbort(Parse*); 14010 14330 SQLITE_PRIVATE void sqlite3HaltConstraint(Parse*, int, int, char*, i8, u8); 14011 14331 SQLITE_PRIVATE void sqlite3UniqueConstraint(Parse*, int, Index*); 14012 14332 SQLITE_PRIVATE void sqlite3RowidConstraint(Parse*, int, Table*); 14013 14333 SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3*,Expr*,int); ................................................................................ 14176 14496 SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value*); 14177 14497 SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *); 14178 14498 SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8); 14179 14499 SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **); 14180 14500 SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8); 14181 14501 #ifndef SQLITE_AMALGAMATION 14182 14502 SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[]; 14503 +SQLITE_PRIVATE const char sqlite3StrBINARY[]; 14183 14504 SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[]; 14184 14505 SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[]; 14185 14506 SQLITE_PRIVATE const Token sqlite3IntTokens[]; 14186 14507 SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config; 14187 14508 SQLITE_PRIVATE SQLITE_WSD FuncDefHash sqlite3GlobalFunctions; 14188 14509 #ifndef SQLITE_OMIT_WSD 14189 14510 SQLITE_PRIVATE int sqlite3PendingByte; ................................................................................ 14781 15102 ** Properties of opcodes. The OPFLG_INITIALIZER macro is 14782 15103 ** created by mkopcodeh.awk during compilation. Data is obtained 14783 15104 ** from the comments following the "case OP_xxxx:" statements in 14784 15105 ** the vdbe.c file. 14785 15106 */ 14786 15107 SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[] = OPFLG_INITIALIZER; 14787 15108 15109 +/* 15110 +** Name of the default collating sequence 15111 +*/ 15112 +SQLITE_PRIVATE const char sqlite3StrBINARY[] = "BINARY"; 15113 + 14788 15114 /************** End of global.c **********************************************/ 14789 15115 /************** Begin file ctime.c *******************************************/ 14790 15116 /* 14791 15117 ** 2010 February 23 14792 15118 ** 14793 15119 ** The author disclaims copyright to this source code. In place of 14794 15120 ** a legal notice, here is a blessing: ................................................................................ 14847 15173 "DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE), 14848 15174 #endif 14849 15175 #if SQLITE_DISABLE_DIRSYNC 14850 15176 "DISABLE_DIRSYNC", 14851 15177 #endif 14852 15178 #if SQLITE_DISABLE_LFS 14853 15179 "DISABLE_LFS", 15180 +#endif 15181 +#if SQLITE_ENABLE_8_3_NAMES 15182 + "ENABLE_8_3_NAMES", 14854 15183 #endif 14855 15184 #if SQLITE_ENABLE_API_ARMOR 14856 15185 "ENABLE_API_ARMOR", 14857 15186 #endif 14858 15187 #if SQLITE_ENABLE_ATOMIC_WRITE 14859 15188 "ENABLE_ATOMIC_WRITE", 14860 15189 #endif ................................................................................ 14942 15271 "IGNORE_AFP_LOCK_ERRORS", 14943 15272 #endif 14944 15273 #if SQLITE_IGNORE_FLOCK_LOCK_ERRORS 14945 15274 "IGNORE_FLOCK_LOCK_ERRORS", 14946 15275 #endif 14947 15276 #ifdef SQLITE_INT64_TYPE 14948 15277 "INT64_TYPE", 15278 +#endif 15279 +#ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS 15280 + "LIKE_DOESNT_MATCH_BLOBS", 14949 15281 #endif 14950 15282 #if SQLITE_LOCK_TRACE 14951 15283 "LOCK_TRACE", 14952 15284 #endif 14953 15285 #if defined(SQLITE_MAX_MMAP_SIZE) && !defined(SQLITE_MAX_MMAP_SIZE_xc) 14954 15286 "MAX_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_MMAP_SIZE), 14955 15287 #endif ................................................................................ 15268 15600 ** The maximum number of times that a statement will try to reparse 15269 15601 ** itself before giving up and returning SQLITE_SCHEMA. 15270 15602 */ 15271 15603 #ifndef SQLITE_MAX_SCHEMA_RETRY 15272 15604 # define SQLITE_MAX_SCHEMA_RETRY 50 15273 15605 #endif 15274 15606 15607 +/* 15608 +** VDBE_DISPLAY_P4 is true or false depending on whether or not the 15609 +** "explain" P4 display logic is enabled. 15610 +*/ 15611 +#if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) \ 15612 + || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG) 15613 +# define VDBE_DISPLAY_P4 1 15614 +#else 15615 +# define VDBE_DISPLAY_P4 0 15616 +#endif 15617 + 15275 15618 /* 15276 15619 ** SQL is translated into a sequence of instructions to be 15277 15620 ** executed by a virtual machine. Each instruction is an instance 15278 15621 ** of the following structure. 15279 15622 */ 15280 15623 typedef struct VdbeOp Op; 15281 15624 ................................................................................ 15289 15632 15290 15633 /* Opaque type used by the explainer */ 15291 15634 typedef struct Explain Explain; 15292 15635 15293 15636 /* Elements of the linked list at Vdbe.pAuxData */ 15294 15637 typedef struct AuxData AuxData; 15295 15638 15639 +/* Types of VDBE cursors */ 15640 +#define CURTYPE_BTREE 0 15641 +#define CURTYPE_SORTER 1 15642 +#define CURTYPE_VTAB 2 15643 +#define CURTYPE_PSEUDO 3 15644 + 15296 15645 /* 15297 -** A cursor is a pointer into a single BTree within a database file. 15298 -** The cursor can seek to a BTree entry with a particular key, or 15299 -** loop over all entries of the Btree. You can also insert new BTree 15300 -** entries or retrieve the key or data from the entry that the cursor 15301 -** is currently pointing to. 15646 +** A VdbeCursor is an superclass (a wrapper) for various cursor objects: 15302 15647 ** 15303 -** Cursors can also point to virtual tables, sorters, or "pseudo-tables". 15304 -** A pseudo-table is a single-row table implemented by registers. 15305 -** 15306 -** Every cursor that the virtual machine has open is represented by an 15307 -** instance of the following structure. 15648 +** * A b-tree cursor 15649 +** - In the main database or in an ephemeral database 15650 +** - On either an index or a table 15651 +** * A sorter 15652 +** * A virtual table 15653 +** * A one-row "pseudotable" stored in a single register 15308 15654 */ 15309 15655 struct VdbeCursor { 15310 - BtCursor *pCursor; /* The cursor structure of the backend */ 15311 - Btree *pBt; /* Separate file holding temporary table */ 15312 - KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */ 15313 - int seekResult; /* Result of previous sqlite3BtreeMoveto() */ 15314 - int pseudoTableReg; /* Register holding pseudotable content. */ 15315 - i16 nField; /* Number of fields in the header */ 15316 - u16 nHdrParsed; /* Number of header fields parsed so far */ 15656 + u8 eCurType; /* One of the CURTYPE_* values above */ 15657 + i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */ 15658 + u8 nullRow; /* True if pointing to a row with no data */ 15659 + u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */ 15660 + u8 isTable; /* True for rowid tables. False for indexes */ 15317 15661 #ifdef SQLITE_DEBUG 15318 15662 u8 seekOp; /* Most recent seek operation on this cursor */ 15319 15663 #endif 15320 - i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */ 15321 - u8 nullRow; /* True if pointing to a row with no data */ 15322 - u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */ 15323 15664 Bool isEphemeral:1; /* True for an ephemeral table */ 15324 15665 Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */ 15325 - Bool isTable:1; /* True if a table requiring integer keys */ 15326 15666 Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */ 15327 15667 Pgno pgnoRoot; /* Root page of the open btree cursor */ 15328 - sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */ 15668 + i16 nField; /* Number of fields in the header */ 15669 + u16 nHdrParsed; /* Number of header fields parsed so far */ 15670 + union { 15671 + BtCursor *pCursor; /* CURTYPE_BTREE. Btree cursor */ 15672 + sqlite3_vtab_cursor *pVCur; /* CURTYPE_VTAB. Vtab cursor */ 15673 + int pseudoTableReg; /* CURTYPE_PSEUDO. Reg holding content. */ 15674 + VdbeSorter *pSorter; /* CURTYPE_SORTER. Sorter object */ 15675 + } uc; 15676 + Btree *pBt; /* Separate file holding temporary table */ 15677 + KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */ 15678 + int seekResult; /* Result of previous sqlite3BtreeMoveto() */ 15329 15679 i64 seqCount; /* Sequence counter */ 15330 15680 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */ 15331 - VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */ 15332 15681 #ifdef SQLITE_ENABLE_COLUMN_USED_MASK 15333 15682 u64 maskUsed; /* Mask of columns used by this cursor */ 15334 15683 #endif 15335 15684 15336 15685 /* Cached information about the header for the data record that the 15337 15686 ** cursor is currently pointing to. Only valid if cacheStatus matches 15338 15687 ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of ................................................................................ 15654 16003 void sqliteVdbePopStack(Vdbe*,int); 15655 16004 SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor*); 15656 16005 SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*); 15657 16006 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) 15658 16007 SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*); 15659 16008 #endif 15660 16009 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32); 15661 -SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int); 16010 +SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen(u8); 16011 +SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int, u32*); 15662 16012 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32); 15663 16013 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*); 15664 16014 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int); 15665 16015 15666 16016 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *); 15667 16017 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(sqlite3*,VdbeCursor*,UnpackedRecord*,int*); 15668 16018 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor*, i64*); ................................................................................ 15755 16105 15756 16106 /************** End of vdbeInt.h *********************************************/ 15757 16107 /************** Continuing where we left off in status.c *********************/ 15758 16108 15759 16109 /* 15760 16110 ** Variables in which to record status information. 15761 16111 */ 16112 +#if SQLITE_PTRSIZE>4 16113 +typedef sqlite3_int64 sqlite3StatValueType; 16114 +#else 16115 +typedef u32 sqlite3StatValueType; 16116 +#endif 15762 16117 typedef struct sqlite3StatType sqlite3StatType; 15763 16118 static SQLITE_WSD struct sqlite3StatType { 15764 -#if SQLITE_PTRSIZE>4 15765 - sqlite3_int64 nowValue[10]; /* Current value */ 15766 - sqlite3_int64 mxValue[10]; /* Maximum value */ 15767 -#else 15768 - u32 nowValue[10]; /* Current value */ 15769 - u32 mxValue[10]; /* Maximum value */ 15770 -#endif 16119 + sqlite3StatValueType nowValue[10]; /* Current value */ 16120 + sqlite3StatValueType mxValue[10]; /* Maximum value */ 15771 16121 } sqlite3Stat = { {0,}, {0,} }; 15772 16122 15773 16123 /* 15774 16124 ** Elements of sqlite3Stat[] are protected by either the memory allocator 15775 16125 ** mutex, or by the pcache1 mutex. The following array determines which. 15776 16126 */ 15777 16127 static const char statMutex[] = { ................................................................................ 15844 16194 assert( sqlite3_mutex_held(statMutex[op] ? sqlite3Pcache1Mutex() 15845 16195 : sqlite3MallocMutex()) ); 15846 16196 assert( op>=0 && op<ArraySize(wsdStat.nowValue) ); 15847 16197 wsdStat.nowValue[op] -= N; 15848 16198 } 15849 16199 15850 16200 /* 15851 -** Set the value of a status to X. The highwater mark is adjusted if 15852 -** necessary. The caller must hold the appropriate mutex. 16201 +** Adjust the highwater mark if necessary. 16202 +** The caller must hold the appropriate mutex. 15853 16203 */ 15854 -SQLITE_PRIVATE void sqlite3StatusSet(int op, int X){ 16204 +SQLITE_PRIVATE void sqlite3StatusHighwater(int op, int X){ 16205 + sqlite3StatValueType newValue; 15855 16206 wsdStatInit; 16207 + assert( X>=0 ); 16208 + newValue = (sqlite3StatValueType)X; 15856 16209 assert( op>=0 && op<ArraySize(wsdStat.nowValue) ); 15857 16210 assert( op>=0 && op<ArraySize(statMutex) ); 15858 16211 assert( sqlite3_mutex_held(statMutex[op] ? sqlite3Pcache1Mutex() 15859 16212 : sqlite3MallocMutex()) ); 15860 - wsdStat.nowValue[op] = X; 15861 - if( wsdStat.nowValue[op]>wsdStat.mxValue[op] ){ 15862 - wsdStat.mxValue[op] = wsdStat.nowValue[op]; 16213 + assert( op==SQLITE_STATUS_MALLOC_SIZE 16214 + || op==SQLITE_STATUS_PAGECACHE_SIZE 16215 + || op==SQLITE_STATUS_SCRATCH_SIZE 16216 + || op==SQLITE_STATUS_PARSER_STACK ); 16217 + if( newValue>wsdStat.mxValue[op] ){ 16218 + wsdStat.mxValue[op] = newValue; 15863 16219 } 15864 16220 } 15865 16221 15866 16222 /* 15867 16223 ** Query status information. 15868 16224 */ 15869 16225 SQLITE_API int SQLITE_STDCALL sqlite3_status64( ................................................................................ 15988 16344 15989 16345 nByte += sqlite3GlobalConfig.m.xRoundup(sizeof(HashElem)) * ( 15990 16346 pSchema->tblHash.count 15991 16347 + pSchema->trigHash.count 15992 16348 + pSchema->idxHash.count 15993 16349 + pSchema->fkeyHash.count 15994 16350 ); 15995 - nByte += sqlite3MallocSize(pSchema->tblHash.ht); 15996 - nByte += sqlite3MallocSize(pSchema->trigHash.ht); 15997 - nByte += sqlite3MallocSize(pSchema->idxHash.ht); 15998 - nByte += sqlite3MallocSize(pSchema->fkeyHash.ht); 16351 + nByte += sqlite3_msize(pSchema->tblHash.ht); 16352 + nByte += sqlite3_msize(pSchema->trigHash.ht); 16353 + nByte += sqlite3_msize(pSchema->idxHash.ht); 16354 + nByte += sqlite3_msize(pSchema->fkeyHash.ht); 15999 16355 16000 16356 for(p=sqliteHashFirst(&pSchema->trigHash); p; p=sqliteHashNext(p)){ 16001 16357 sqlite3DeleteTrigger(db, (Trigger*)sqliteHashData(p)); 16002 16358 } 16003 16359 for(p=sqliteHashFirst(&pSchema->tblHash); p; p=sqliteHashNext(p)){ 16004 16360 sqlite3DeleteTable(db, (Table *)sqliteHashData(p)); 16005 16361 } ................................................................................ 16144 16500 int h, m; /* Hour and minutes */ 16145 16501 int tz; /* Timezone offset in minutes */ 16146 16502 double s; /* Seconds */ 16147 16503 char validYMD; /* True (1) if Y,M,D are valid */ 16148 16504 char validHMS; /* True (1) if h,m,s are valid */ 16149 16505 char validJD; /* True (1) if iJD is valid */ 16150 16506 char validTZ; /* True (1) if tz is valid */ 16507 + char tzSet; /* Timezone was set explicitly */ 16151 16508 }; 16152 16509 16153 16510 16154 16511 /* 16155 16512 ** Convert zDate into one or more integers. Additional arguments 16156 16513 ** come in groups of 5 as follows: 16157 16514 ** ................................................................................ 16237 16594 if( getDigits(zDate, 2, 0, 14, ':', &nHr, 2, 0, 59, 0, &nMn)!=2 ){ 16238 16595 return 1; 16239 16596 } 16240 16597 zDate += 5; 16241 16598 p->tz = sgn*(nMn + nHr*60); 16242 16599 zulu_time: 16243 16600 while( sqlite3Isspace(*zDate) ){ zDate++; } 16601 + p->tzSet = 1; 16244 16602 return *zDate!=0; 16245 16603 } 16246 16604 16247 16605 /* 16248 16606 ** Parse times of the form HH:MM or HH:MM:SS or HH:MM:SS.FFFF. 16249 16607 ** The HH, MM, and SS must each be exactly 2 digits. The 16250 16608 ** fractional seconds FFFF can be one or more digits. ................................................................................ 16669 17027 if( strcmp(z, "unixepoch")==0 && p->validJD ){ 16670 17028 p->iJD = (p->iJD + 43200)/86400 + 21086676*(i64)10000000; 16671 17029 clearYMD_HMS_TZ(p); 16672 17030 rc = 0; 16673 17031 } 16674 17032 #ifndef SQLITE_OMIT_LOCALTIME 16675 17033 else if( strcmp(z, "utc")==0 ){ 16676 - sqlite3_int64 c1; 16677 - computeJD(p); 16678 - c1 = localtimeOffset(p, pCtx, &rc); 16679 - if( rc==SQLITE_OK ){ 16680 - p->iJD -= c1; 16681 - clearYMD_HMS_TZ(p); 16682 - p->iJD += c1 - localtimeOffset(p, pCtx, &rc); 17034 + if( p->tzSet==0 ){ 17035 + sqlite3_int64 c1; 17036 + computeJD(p); 17037 + c1 = localtimeOffset(p, pCtx, &rc); 17038 + if( rc==SQLITE_OK ){ 17039 + p->iJD -= c1; 17040 + clearYMD_HMS_TZ(p); 17041 + p->iJD += c1 - localtimeOffset(p, pCtx, &rc); 17042 + } 17043 + p->tzSet = 1; 17044 + }else{ 17045 + rc = SQLITE_OK; 16683 17046 } 16684 17047 } 16685 17048 #endif 16686 17049 break; 16687 17050 } 16688 17051 case 'w': { 16689 17052 /* ................................................................................ 17942 18305 17943 18306 /* 17944 18307 ** Report the allocated size of a prior return from xMalloc() 17945 18308 ** or xRealloc(). 17946 18309 */ 17947 18310 static int sqlite3MemSize(void *pPrior){ 17948 18311 #ifdef SQLITE_MALLOCSIZE 17949 - return pPrior ? (int)SQLITE_MALLOCSIZE(pPrior) : 0; 18312 + assert( pPrior!=0 ); 18313 + return (int)SQLITE_MALLOCSIZE(pPrior); 17950 18314 #else 17951 18315 sqlite3_int64 *p; 17952 - if( pPrior==0 ) return 0; 18316 + assert( pPrior!=0 ); 17953 18317 p = (sqlite3_int64*)pPrior; 17954 18318 p--; 17955 18319 return (int)p[0]; 17956 18320 #endif 17957 18321 } 17958 18322 17959 18323 /* ................................................................................ 19075 19439 /* 19076 19440 ** Return the size of an outstanding allocation, in bytes. The 19077 19441 ** size returned omits the 8-byte header overhead. This only 19078 19442 ** works for chunks that are currently checked out. 19079 19443 */ 19080 19444 static int memsys3Size(void *p){ 19081 19445 Mem3Block *pBlock; 19082 - if( p==0 ) return 0; 19446 + assert( p!=0 ); 19083 19447 pBlock = (Mem3Block*)p; 19084 19448 assert( (pBlock[-1].u.hdr.size4x&1)!=0 ); 19085 19449 return (pBlock[-1].u.hdr.size4x&~3)*2 - 4; 19086 19450 } 19087 19451 19088 19452 /* 19089 19453 ** Round up a request size to the next valid allocation size. ................................................................................ 19314 19678 ** be changed. 19315 19679 ** 19316 19680 ** This version of the memory allocation subsystem is included 19317 19681 ** in the build only if SQLITE_ENABLE_MEMSYS5 is defined. 19318 19682 ** 19319 19683 ** This memory allocator uses the following algorithm: 19320 19684 ** 19321 -** 1. All memory allocations sizes are rounded up to a power of 2. 19685 +** 1. All memory allocation sizes are rounded up to a power of 2. 19322 19686 ** 19323 19687 ** 2. If two adjacent free blocks are the halves of a larger block, 19324 19688 ** then the two blocks are coalesced into the single larger block. 19325 19689 ** 19326 19690 ** 3. New memory is allocated from the first available free block. 19327 19691 ** 19328 19692 ** This algorithm is described in: J. M. Robson. "Bounds for Some Functions ................................................................................ 19406 19770 u32 maxOut; /* Maximum instantaneous currentOut */ 19407 19771 u32 maxCount; /* Maximum instantaneous currentCount */ 19408 19772 u32 maxRequest; /* Largest allocation (exclusive of internal frag) */ 19409 19773 19410 19774 /* 19411 19775 ** Lists of free blocks. aiFreelist[0] is a list of free blocks of 19412 19776 ** size mem5.szAtom. aiFreelist[1] holds blocks of size szAtom*2. 19413 - ** and so forth. 19777 + ** aiFreelist[2] holds free blocks of size szAtom*4. And so forth. 19414 19778 */ 19415 19779 int aiFreelist[LOGMAX+1]; 19416 19780 19417 19781 /* 19418 19782 ** Space for tracking which blocks are checked out and the size 19419 19783 ** of each block. One byte per block. 19420 19784 */ ................................................................................ 19472 19836 assert( x<mem5.nBlock ); 19473 19837 MEM5LINK(x)->prev = i; 19474 19838 } 19475 19839 mem5.aiFreelist[iLogsize] = i; 19476 19840 } 19477 19841 19478 19842 /* 19479 -** If the STATIC_MEM mutex is not already held, obtain it now. The mutex 19480 -** will already be held (obtained by code in malloc.c) if 19481 -** sqlite3GlobalConfig.bMemStat is true. 19843 +** Obtain or release the mutex needed to access global data structures. 19482 19844 */ 19483 19845 static void memsys5Enter(void){ 19484 19846 sqlite3_mutex_enter(mem5.mutex); 19485 19847 } 19486 19848 static void memsys5Leave(void){ 19487 19849 sqlite3_mutex_leave(mem5.mutex); 19488 19850 } 19489 19851 19490 19852 /* 19491 -** Return the size of an outstanding allocation, in bytes. The 19492 -** size returned omits the 8-byte header overhead. This only 19493 -** works for chunks that are currently checked out. 19853 +** Return the size of an outstanding allocation, in bytes. 19854 +** This only works for chunks that are currently checked out. 19494 19855 */ 19495 19856 static int memsys5Size(void *p){ 19496 - int iSize = 0; 19497 - if( p ){ 19498 - int i = (int)(((u8 *)p-mem5.zPool)/mem5.szAtom); 19499 - assert( i>=0 && i<mem5.nBlock ); 19500 - iSize = mem5.szAtom * (1 << (mem5.aCtrl[i]&CTRL_LOGSIZE)); 19501 - } 19857 + int iSize, i; 19858 + assert( p!=0 ); 19859 + i = (int)(((u8 *)p-mem5.zPool)/mem5.szAtom); 19860 + assert( i>=0 && i<mem5.nBlock ); 19861 + iSize = mem5.szAtom * (1 << (mem5.aCtrl[i]&CTRL_LOGSIZE)); 19502 19862 return iSize; 19503 19863 } 19504 19864 19505 19865 /* 19506 19866 ** Return a block of memory of at least nBytes in size. 19507 19867 ** Return NULL if unable. Return NULL if nBytes==0. 19508 19868 ** ................................................................................ 19520 19880 19521 19881 /* nByte must be a positive */ 19522 19882 assert( nByte>0 ); 19523 19883 19524 19884 /* Keep track of the maximum allocation request. Even unfulfilled 19525 19885 ** requests are counted */ 19526 19886 if( (u32)nByte>mem5.maxRequest ){ 19887 + /* Abort if the requested allocation size is larger than the largest 19888 + ** power of two that we can represent using 32-bit signed integers. */ 19889 + if( nByte > 0x40000000 ) return 0; 19527 19890 mem5.maxRequest = nByte; 19528 19891 } 19529 19892 19530 - /* Abort if the requested allocation size is larger than the largest 19531 - ** power of two that we can represent using 32-bit signed integers. 19532 - */ 19533 - if( nByte > 0x40000000 ){ 19534 - return 0; 19535 - } 19536 - 19537 19893 /* Round nByte up to the next valid power of two */ 19538 - for(iFullSz=mem5.szAtom, iLogsize=0; iFullSz<nByte; iFullSz *= 2, iLogsize++){} 19894 + for(iFullSz=mem5.szAtom,iLogsize=0; iFullSz<nByte; iFullSz*=2,iLogsize++){} 19539 19895 19540 19896 /* Make sure mem5.aiFreelist[iLogsize] contains at least one free 19541 19897 ** block. If not, then split a block of the next larger power of 19542 19898 ** two in order to create a new free block of size iLogsize. 19543 19899 */ 19544 19900 for(iBin=iLogsize; iBin<=LOGMAX && mem5.aiFreelist[iBin]<0; iBin++){} 19545 19901 if( iBin>LOGMAX ){ ................................................................................ 19688 20044 if( nBytes==0 ){ 19689 20045 return 0; 19690 20046 } 19691 20047 nOld = memsys5Size(pPrior); 19692 20048 if( nBytes<=nOld ){ 19693 20049 return pPrior; 19694 20050 } 19695 - memsys5Enter(); 19696 - p = memsys5MallocUnsafe(nBytes); 20051 + p = memsys5Malloc(nBytes); 19697 20052 if( p ){ 19698 20053 memcpy(p, pPrior, nOld); 19699 - memsys5FreeUnsafe(pPrior); 20054 + memsys5Free(pPrior); 19700 20055 } 19701 - memsys5Leave(); 19702 20056 return p; 19703 20057 } 19704 20058 19705 20059 /* 19706 20060 ** Round up a request size to the next valid allocation size. If 19707 20061 ** the allocation is too large to be handled by this allocation system, 19708 20062 ** return 0. ................................................................................ 20308 20662 #if SQLITE_MUTEX_NREF 20309 20663 volatile int nRef; /* Number of entrances */ 20310 20664 volatile pthread_t owner; /* Thread that is within this mutex */ 20311 20665 int trace; /* True to trace changes */ 20312 20666 #endif 20313 20667 }; 20314 20668 #if SQLITE_MUTEX_NREF 20315 -#define SQLITE3_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, 0, 0, (pthread_t)0, 0 } 20669 +#define SQLITE3_MUTEX_INITIALIZER {PTHREAD_MUTEX_INITIALIZER,0,0,(pthread_t)0,0} 20670 +#elif defined(SQLITE_ENABLE_API_ARMOR) 20671 +#define SQLITE3_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, 0 } 20316 20672 #else 20317 20673 #define SQLITE3_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER } 20318 20674 #endif 20319 20675 20320 20676 /* 20321 20677 ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are 20322 20678 ** intended for use only inside assert() statements. On some platforms, ................................................................................ 21470 21826 */ 21471 21827 SQLITE_PRIVATE int sqlite3MallocInit(void){ 21472 21828 int rc; 21473 21829 if( sqlite3GlobalConfig.m.xMalloc==0 ){ 21474 21830 sqlite3MemSetDefault(); 21475 21831 } 21476 21832 memset(&mem0, 0, sizeof(mem0)); 21477 - if( sqlite3GlobalConfig.bCoreMutex ){ 21478 - mem0.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); 21479 - } 21833 + mem0.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); 21480 21834 if( sqlite3GlobalConfig.pScratch && sqlite3GlobalConfig.szScratch>=100 21481 21835 && sqlite3GlobalConfig.nScratch>0 ){ 21482 21836 int i, n, sz; 21483 21837 ScratchFreeslot *pSlot; 21484 21838 sz = ROUNDDOWN8(sqlite3GlobalConfig.szScratch); 21485 21839 sqlite3GlobalConfig.szScratch = sz; 21486 21840 pSlot = (ScratchFreeslot*)sqlite3GlobalConfig.pScratch; ................................................................................ 21563 21917 ** lock is already held. 21564 21918 */ 21565 21919 static int mallocWithAlarm(int n, void **pp){ 21566 21920 int nFull; 21567 21921 void *p; 21568 21922 assert( sqlite3_mutex_held(mem0.mutex) ); 21569 21923 nFull = sqlite3GlobalConfig.m.xRoundup(n); 21570 - sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n); 21924 + sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, n); 21571 21925 if( mem0.alarmThreshold>0 ){ 21572 21926 sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED); 21573 21927 if( nUsed >= mem0.alarmThreshold - nFull ){ 21574 21928 mem0.nearlyFull = 1; 21575 21929 sqlite3MallocAlarm(nFull); 21576 21930 }else{ 21577 21931 mem0.nearlyFull = 0; ................................................................................ 21655 22009 ** embedded processor. 21656 22010 */ 21657 22011 SQLITE_PRIVATE void *sqlite3ScratchMalloc(int n){ 21658 22012 void *p; 21659 22013 assert( n>0 ); 21660 22014 21661 22015 sqlite3_mutex_enter(mem0.mutex); 21662 - sqlite3StatusSet(SQLITE_STATUS_SCRATCH_SIZE, n); 22016 + sqlite3StatusHighwater(SQLITE_STATUS_SCRATCH_SIZE, n); 21663 22017 if( mem0.nScratchFree && sqlite3GlobalConfig.szScratch>=n ){ 21664 22018 p = mem0.pScratchFree; 21665 22019 mem0.pScratchFree = mem0.pScratchFree->pNext; 21666 22020 mem0.nScratchFree--; 21667 22021 sqlite3StatusUp(SQLITE_STATUS_SCRATCH_USED, 1); 21668 22022 sqlite3_mutex_leave(mem0.mutex); 21669 22023 }else{ ................................................................................ 21699 22053 ** is outstanding at one time. (This is only checked in the 21700 22054 ** single-threaded case since checking in the multi-threaded case 21701 22055 ** would be much more complicated.) */ 21702 22056 assert( scratchAllocOut>=1 && scratchAllocOut<=2 ); 21703 22057 scratchAllocOut--; 21704 22058 #endif 21705 22059 21706 - if( p>=sqlite3GlobalConfig.pScratch && p<mem0.pScratchEnd ){ 22060 + if( SQLITE_WITHIN(p, sqlite3GlobalConfig.pScratch, mem0.pScratchEnd) ){ 21707 22061 /* Release memory from the SQLITE_CONFIG_SCRATCH allocation */ 21708 22062 ScratchFreeslot *pSlot; 21709 22063 pSlot = (ScratchFreeslot*)p; 21710 22064 sqlite3_mutex_enter(mem0.mutex); 21711 22065 pSlot->pNext = mem0.pScratchFree; 21712 22066 mem0.pScratchFree = pSlot; 21713 22067 mem0.nScratchFree++; ................................................................................ 21735 22089 } 21736 22090 21737 22091 /* 21738 22092 ** TRUE if p is a lookaside memory allocation from db 21739 22093 */ 21740 22094 #ifndef SQLITE_OMIT_LOOKASIDE 21741 22095 static int isLookaside(sqlite3 *db, void *p){ 21742 - return p>=db->lookaside.pStart && p<db->lookaside.pEnd; 22096 + return SQLITE_WITHIN(p, db->lookaside.pStart, db->lookaside.pEnd); 21743 22097 } 21744 22098 #else 21745 22099 #define isLookaside(A,B) 0 21746 22100 #endif 21747 22101 21748 22102 /* 21749 22103 ** Return the size of a memory allocation previously obtained from ................................................................................ 21750 22104 ** sqlite3Malloc() or sqlite3_malloc(). 21751 22105 */ 21752 22106 SQLITE_PRIVATE int sqlite3MallocSize(void *p){ 21753 22107 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); 21754 22108 return sqlite3GlobalConfig.m.xSize(p); 21755 22109 } 21756 22110 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){ 22111 + assert( p!=0 ); 21757 22112 if( db==0 || !isLookaside(db,p) ){ 21758 22113 #if SQLITE_DEBUG 21759 22114 if( db==0 ){ 21760 22115 assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) ); 21761 22116 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); 21762 22117 }else{ 21763 22118 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); ................................................................................ 21769 22124 assert( sqlite3_mutex_held(db->mutex) ); 21770 22125 return db->lookaside.sz; 21771 22126 } 21772 22127 } 21773 22128 SQLITE_API sqlite3_uint64 SQLITE_STDCALL sqlite3_msize(void *p){ 21774 22129 assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) ); 21775 22130 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); 21776 - return (sqlite3_uint64)sqlite3GlobalConfig.m.xSize(p); 22131 + return p ? sqlite3GlobalConfig.m.xSize(p) : 0; 21777 22132 } 21778 22133 21779 22134 /* 21780 22135 ** Free memory previously obtained from sqlite3Malloc(). 21781 22136 */ 21782 22137 SQLITE_API void SQLITE_STDCALL sqlite3_free(void *p){ 21783 22138 if( p==0 ) return; /* IMP: R-49053-54554 */ ................................................................................ 21857 22212 ** argument to xRealloc is always a value returned by a prior call to 21858 22213 ** xRoundup. */ 21859 22214 nNew = sqlite3GlobalConfig.m.xRoundup((int)nBytes); 21860 22215 if( nOld==nNew ){ 21861 22216 pNew = pOld; 21862 22217 }else if( sqlite3GlobalConfig.bMemstat ){ 21863 22218 sqlite3_mutex_enter(mem0.mutex); 21864 - sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, (int)nBytes); 22219 + sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, (int)nBytes); 21865 22220 nDiff = nNew - nOld; 21866 22221 if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >= 21867 22222 mem0.alarmThreshold-nDiff ){ 21868 22223 sqlite3MallocAlarm(nDiff); 21869 22224 } 21870 22225 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); 21871 22226 if( pNew==0 && mem0.alarmThreshold>0 ){ ................................................................................ 22380 22735 while( c>='0' && c<='9' ){ 22381 22736 wx = wx*10 + c - '0'; 22382 22737 c = *++fmt; 22383 22738 } 22384 22739 testcase( wx>0x7fffffff ); 22385 22740 width = wx & 0x7fffffff; 22386 22741 } 22742 + assert( width>=0 ); 22743 +#ifdef SQLITE_PRINTF_PRECISION_LIMIT 22744 + if( width>SQLITE_PRINTF_PRECISION_LIMIT ){ 22745 + width = SQLITE_PRINTF_PRECISION_LIMIT; 22746 + } 22747 +#endif 22387 22748 22388 22749 /* Get the precision */ 22389 22750 if( c=='.' ){ 22390 22751 c = *++fmt; 22391 22752 if( c=='*' ){ 22392 22753 if( bArgList ){ 22393 22754 precision = (int)getIntArg(pArgList); ................................................................................ 22406 22767 } 22407 22768 testcase( px>0x7fffffff ); 22408 22769 precision = px & 0x7fffffff; 22409 22770 } 22410 22771 }else{ 22411 22772 precision = -1; 22412 22773 } 22774 + assert( precision>=(-1) ); 22775 +#ifdef SQLITE_PRINTF_PRECISION_LIMIT 22776 + if( precision>SQLITE_PRINTF_PRECISION_LIMIT ){ 22777 + precision = SQLITE_PRINTF_PRECISION_LIMIT; 22778 + } 22779 +#endif 22780 + 22781 + 22413 22782 /* Get the conversion type modifier */ 22414 22783 if( c=='l' ){ 22415 22784 flag_long = 1; 22416 22785 c = *++fmt; 22417 22786 if( c=='l' ){ 22418 22787 flag_longlong = 1; 22419 22788 c = *++fmt; ................................................................................ 22836 23205 */ 22837 23206 width -= length; 22838 23207 if( width>0 && !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' '); 22839 23208 sqlite3StrAccumAppend(pAccum, bufpt, length); 22840 23209 if( width>0 && flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' '); 22841 23210 22842 23211 if( zExtra ){ 22843 - sqlite3_free(zExtra); 23212 + sqlite3DbFree(pAccum->db, zExtra); 22844 23213 zExtra = 0; 22845 23214 } 22846 23215 }/* End for loop over the format string */ 22847 23216 } /* End of function */ 22848 23217 22849 23218 /* 22850 23219 ** Enlarge the memory allocation on a StrAccum object so that it is ................................................................................ 22862 23231 return 0; 22863 23232 } 22864 23233 if( p->mxAlloc==0 ){ 22865 23234 N = p->nAlloc - p->nChar - 1; 22866 23235 setStrAccumError(p, STRACCUM_TOOBIG); 22867 23236 return N; 22868 23237 }else{ 22869 - char *zOld = (p->zText==p->zBase ? 0 : p->zText); 23238 + char *zOld = p->bMalloced ? p->zText : 0; 22870 23239 i64 szNew = p->nChar; 23240 + assert( (p->zText==0 || p->zText==p->zBase)==(p->bMalloced==0) ); 22871 23241 szNew += N + 1; 22872 23242 if( szNew+p->nChar<=p->mxAlloc ){ 22873 23243 /* Force exponential buffer size growth as long as it does not overflow, 22874 23244 ** to avoid having to call this routine too often */ 22875 23245 szNew += p->nChar; 22876 23246 } 22877 23247 if( szNew > p->mxAlloc ){ ................................................................................ 22884 23254 if( p->db ){ 22885 23255 zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc); 22886 23256 }else{ 22887 23257 zNew = sqlite3_realloc64(zOld, p->nAlloc); 22888 23258 } 22889 23259 if( zNew ){ 22890 23260 assert( p->zText!=0 || p->nChar==0 ); 22891 - if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); 23261 + if( !p->bMalloced && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); 22892 23262 p->zText = zNew; 22893 23263 p->nAlloc = sqlite3DbMallocSize(p->db, zNew); 23264 + p->bMalloced = 1; 22894 23265 }else{ 22895 23266 sqlite3StrAccumReset(p); 22896 23267 setStrAccumError(p, STRACCUM_NOMEM); 22897 23268 return 0; 22898 23269 } 22899 23270 } 22900 23271 return N; ................................................................................ 22904 23275 ** Append N copies of character c to the given string buffer. 22905 23276 */ 22906 23277 SQLITE_PRIVATE void sqlite3AppendChar(StrAccum *p, int N, char c){ 22907 23278 testcase( p->nChar + (i64)N > 0x7fffffff ); 22908 23279 if( p->nChar+(i64)N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ){ 22909 23280 return; 22910 23281 } 23282 + assert( (p->zText==p->zBase)==(p->bMalloced==0) ); 22911 23283 while( (N--)>0 ) p->zText[p->nChar++] = c; 22912 23284 } 22913 23285 22914 23286 /* 22915 23287 ** The StrAccum "p" is not large enough to accept N new bytes of z[]. 22916 23288 ** So enlarge if first, then do the append. 22917 23289 ** ................................................................................ 22921 23293 */ 22922 23294 static void SQLITE_NOINLINE enlargeAndAppend(StrAccum *p, const char *z, int N){ 22923 23295 N = sqlite3StrAccumEnlarge(p, N); 22924 23296 if( N>0 ){ 22925 23297 memcpy(&p->zText[p->nChar], z, N); 22926 23298 p->nChar += N; 22927 23299 } 23300 + assert( (p->zText==0 || p->zText==p->zBase)==(p->bMalloced==0) ); 22928 23301 } 22929 23302 22930 23303 /* 22931 23304 ** Append N bytes of text from z to the StrAccum object. Increase the 22932 23305 ** size of the memory allocation for StrAccum if necessary. 22933 23306 */ 22934 23307 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ ................................................................................ 22956 23329 /* 22957 23330 ** Finish off a string by making sure it is zero-terminated. 22958 23331 ** Return a pointer to the resulting string. Return a NULL 22959 23332 ** pointer if any kind of error was encountered. 22960 23333 */ 22961 23334 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){ 22962 23335 if( p->zText ){ 23336 + assert( (p->zText==p->zBase)==(p->bMalloced==0) ); 22963 23337 p->zText[p->nChar] = 0; 22964 - if( p->mxAlloc>0 && p->zText==p->zBase ){ 23338 + if( p->mxAlloc>0 && p->bMalloced==0 ){ 22965 23339 p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 ); 22966 23340 if( p->zText ){ 22967 23341 memcpy(p->zText, p->zBase, p->nChar+1); 23342 + p->bMalloced = 1; 22968 23343 }else{ 22969 23344 setStrAccumError(p, STRACCUM_NOMEM); 22970 23345 } 22971 23346 } 22972 23347 } 22973 23348 return p->zText; 22974 23349 } 22975 23350 22976 23351 /* 22977 23352 ** Reset an StrAccum string. Reclaim all malloced memory. 22978 23353 */ 22979 23354 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum *p){ 22980 - if( p->zText!=p->zBase ){ 23355 + assert( (p->zText==0 || p->zText==p->zBase)==(p->bMalloced==0) ); 23356 + if( p->bMalloced ){ 22981 23357 sqlite3DbFree(p->db, p->zText); 23358 + p->bMalloced = 0; 22982 23359 } 22983 23360 p->zText = 0; 22984 23361 } 22985 23362 22986 23363 /* 22987 23364 ** Initialize a string accumulator. 22988 23365 ** ................................................................................ 23000 23377 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, sqlite3 *db, char *zBase, int n, int mx){ 23001 23378 p->zText = p->zBase = zBase; 23002 23379 p->db = db; 23003 23380 p->nChar = 0; 23004 23381 p->nAlloc = n; 23005 23382 p->mxAlloc = mx; 23006 23383 p->accError = 0; 23384 + p->bMalloced = 0; 23007 23385 } 23008 23386 23009 23387 /* 23010 23388 ** Print into memory obtained from sqliteMalloc(). Use the internal 23011 23389 ** %-conversion extensions. 23012 23390 */ 23013 23391 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){ ................................................................................ 23261 23639 ** Shorthand for starting a new tree item that consists of a single label 23262 23640 */ 23263 23641 static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){ 23264 23642 p = sqlite3TreeViewPush(p, moreFollows); 23265 23643 sqlite3TreeViewLine(p, "%s", zLabel); 23266 23644 } 23267 23645 23646 +/* 23647 +** Generate a human-readable description of a WITH clause. 23648 +*/ 23649 +SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 moreToFollow){ 23650 + int i; 23651 + if( pWith==0 ) return; 23652 + if( pWith->nCte==0 ) return; 23653 + if( pWith->pOuter ){ 23654 + sqlite3TreeViewLine(pView, "WITH (0x%p, pOuter=0x%p)",pWith,pWith->pOuter); 23655 + }else{ 23656 + sqlite3TreeViewLine(pView, "WITH (0x%p)", pWith); 23657 + } 23658 + if( pWith->nCte>0 ){ 23659 + pView = sqlite3TreeViewPush(pView, 1); 23660 + for(i=0; i<pWith->nCte; i++){ 23661 + StrAccum x; 23662 + char zLine[1000]; 23663 + const struct Cte *pCte = &pWith->a[i]; 23664 + sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); 23665 + sqlite3XPrintf(&x, 0, "%s", pCte->zName); 23666 + if( pCte->pCols && pCte->pCols->nExpr>0 ){ 23667 + char cSep = '('; 23668 + int j; 23669 + for(j=0; j<pCte->pCols->nExpr; j++){ 23670 + sqlite3XPrintf(&x, 0, "%c%s", cSep, pCte->pCols->a[j].zName); 23671 + cSep = ','; 23672 + } 23673 + sqlite3XPrintf(&x, 0, ")"); 23674 + } 23675 + sqlite3XPrintf(&x, 0, " AS"); 23676 + sqlite3StrAccumFinish(&x); 23677 + sqlite3TreeViewItem(pView, zLine, i<pWith->nCte-1); 23678 + sqlite3TreeViewSelect(pView, pCte->pSelect, 0); 23679 + sqlite3TreeViewPop(pView); 23680 + } 23681 + sqlite3TreeViewPop(pView); 23682 + } 23683 +} 23684 + 23268 23685 23269 23686 /* 23270 23687 ** Generate a human-readable description of a the Select object. 23271 23688 */ 23272 23689 SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){ 23273 23690 int n = 0; 23274 23691 int cnt = 0; 23275 23692 pView = sqlite3TreeViewPush(pView, moreToFollow); 23693 + if( p->pWith ){ 23694 + sqlite3TreeViewWith(pView, p->pWith, 1); 23695 + cnt = 1; 23696 + sqlite3TreeViewPush(pView, 1); 23697 + } 23276 23698 do{ 23277 23699 sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p) selFlags=0x%x", 23278 23700 ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""), 23279 23701 ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p, p->selFlags 23280 23702 ); 23281 23703 if( cnt++ ) sqlite3TreeViewPop(pView); 23282 23704 if( p->pPrior ){ ................................................................................ 24078 24500 ** 0xfe 0xff big-endian utf-16 follows 24079 24501 ** 24080 24502 */ 24081 24503 /* #include "sqliteInt.h" */ 24082 24504 /* #include <assert.h> */ 24083 24505 /* #include "vdbeInt.h" */ 24084 24506 24085 -#ifndef SQLITE_AMALGAMATION 24507 +#if !defined(SQLITE_AMALGAMATION) && SQLITE_BYTEORDER==0 24086 24508 /* 24087 24509 ** The following constant value is used by the SQLITE_BIGENDIAN and 24088 24510 ** SQLITE_LITTLEENDIAN macros. 24089 24511 */ 24090 24512 SQLITE_PRIVATE const int sqlite3one = 1; 24091 -#endif /* SQLITE_AMALGAMATION */ 24513 +#endif /* SQLITE_AMALGAMATION && SQLITE_BYTEORDER==0 */ 24092 24514 24093 24515 /* 24094 24516 ** This lookup table is used to help decode the first byte of 24095 24517 ** a multi-byte UTF8 character. 24096 24518 */ 24097 24519 static const unsigned char sqlite3Utf8Trans1[] = { 24098 24520 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, ................................................................................ 25129 25551 *pNum = -(i64)u; 25130 25552 }else{ 25131 25553 *pNum = (i64)u; 25132 25554 } 25133 25555 testcase( i==18 ); 25134 25556 testcase( i==19 ); 25135 25557 testcase( i==20 ); 25136 - if( (c!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum) || i>19*incr || nonNum ){ 25558 + if( (c!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum) 25559 + || i>19*incr || nonNum ){ 25137 25560 /* zNum is empty or contains non-numeric text or is longer 25138 25561 ** than 19 digits (thus guaranteeing that it is too large) */ 25139 25562 return 1; 25140 25563 }else if( i<19*incr ){ 25141 25564 /* Less than 19 digits, so we know that it fits in 64 bits */ 25142 25565 assert( u<=LARGEST_INT64 ); 25143 25566 return 0; ................................................................................ 25418 25841 25419 25842 p++; 25420 25843 a = a<<14; 25421 25844 a |= *p; 25422 25845 /* a: p0<<28 | p2<<14 | p4 (unmasked) */ 25423 25846 if (!(a&0x80)) 25424 25847 { 25425 - /* we can skip these cause they were (effectively) done above in calc'ing s */ 25848 + /* we can skip these cause they were (effectively) done above 25849 + ** while calculating s */ 25426 25850 /* a &= (0x7f<<28)|(0x7f<<14)|(0x7f); */ 25427 25851 /* b &= (0x7f<<14)|(0x7f); */ 25428 25852 b = b<<7; 25429 25853 a |= b; 25430 25854 s = s>>18; 25431 25855 *v = ((u64)s)<<32 | a; 25432 25856 return 5; ................................................................................ 26242 26666 insertElement(pH, pH->ht ? &pH->ht[h] : 0, new_elem); 26243 26667 return 0; 26244 26668 } 26245 26669 26246 26670 /************** End of hash.c ************************************************/ 26247 26671 /************** Begin file opcodes.c *****************************************/ 26248 26672 /* Automatically generated. Do not edit */ 26249 -/* See the mkopcodec.awk script for details. */ 26250 -#if !defined(SQLITE_OMIT_EXPLAIN) || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG) 26673 +/* See the tool/mkopcodec.tcl script for details. */ 26674 +#if !defined(SQLITE_OMIT_EXPLAIN) \ 26675 + || defined(VDBE_PROFILE) \ 26676 + || defined(SQLITE_DEBUG) 26251 26677 #if defined(SQLITE_ENABLE_EXPLAIN_COMMENTS) || defined(SQLITE_DEBUG) 26252 26678 # define OpHelp(X) "\0" X 26253 26679 #else 26254 26680 # define OpHelp(X) 26255 26681 #endif 26256 26682 SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){ 26257 26683 static const char *const azName[] = { "?", 26258 - /* 1 */ "Savepoint" OpHelp(""), 26259 - /* 2 */ "AutoCommit" OpHelp(""), 26260 - /* 3 */ "Transaction" OpHelp(""), 26261 - /* 4 */ "SorterNext" OpHelp(""), 26262 - /* 5 */ "PrevIfOpen" OpHelp(""), 26263 - /* 6 */ "NextIfOpen" OpHelp(""), 26264 - /* 7 */ "Prev" OpHelp(""), 26265 - /* 8 */ "Next" OpHelp(""), 26266 - /* 9 */ "Checkpoint" OpHelp(""), 26267 - /* 10 */ "JournalMode" OpHelp(""), 26268 - /* 11 */ "Vacuum" OpHelp(""), 26269 - /* 12 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"), 26270 - /* 13 */ "VUpdate" OpHelp("data=r[P3@P2]"), 26271 - /* 14 */ "Goto" OpHelp(""), 26272 - /* 15 */ "Gosub" OpHelp(""), 26273 - /* 16 */ "Return" OpHelp(""), 26274 - /* 17 */ "InitCoroutine" OpHelp(""), 26275 - /* 18 */ "EndCoroutine" OpHelp(""), 26276 - /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"), 26277 - /* 20 */ "Yield" OpHelp(""), 26278 - /* 21 */ "HaltIfNull" OpHelp("if r[P3]=null halt"), 26279 - /* 22 */ "Halt" OpHelp(""), 26280 - /* 23 */ "Integer" OpHelp("r[P2]=P1"), 26281 - /* 24 */ "Int64" OpHelp("r[P2]=P4"), 26282 - /* 25 */ "String" OpHelp("r[P2]='P4' (len=P1)"), 26283 - /* 26 */ "Null" OpHelp("r[P2..P3]=NULL"), 26284 - /* 27 */ "SoftNull" OpHelp("r[P1]=NULL"), 26285 - /* 28 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), 26286 - /* 29 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), 26287 - /* 30 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), 26288 - /* 31 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"), 26289 - /* 32 */ "SCopy" OpHelp("r[P2]=r[P1]"), 26290 - /* 33 */ "ResultRow" OpHelp("output=r[P1@P2]"), 26291 - /* 34 */ "CollSeq" OpHelp(""), 26292 - /* 35 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"), 26293 - /* 36 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"), 26294 - /* 37 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), 26295 - /* 38 */ "MustBeInt" OpHelp(""), 26296 - /* 39 */ "RealAffinity" OpHelp(""), 26297 - /* 40 */ "Cast" OpHelp("affinity(r[P1])"), 26298 - /* 41 */ "Permutation" OpHelp(""), 26299 - /* 42 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"), 26300 - /* 43 */ "Jump" OpHelp(""), 26301 - /* 44 */ "Once" OpHelp(""), 26302 - /* 45 */ "If" OpHelp(""), 26303 - /* 46 */ "IfNot" OpHelp(""), 26304 - /* 47 */ "Column" OpHelp("r[P3]=PX"), 26305 - /* 48 */ "Affinity" OpHelp("affinity(r[P1@P2])"), 26306 - /* 49 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), 26307 - /* 50 */ "Count" OpHelp("r[P2]=count()"), 26308 - /* 51 */ "ReadCookie" OpHelp(""), 26309 - /* 52 */ "SetCookie" OpHelp(""), 26310 - /* 53 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"), 26311 - /* 54 */ "OpenRead" OpHelp("root=P2 iDb=P3"), 26312 - /* 55 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), 26313 - /* 56 */ "OpenAutoindex" OpHelp("nColumn=P2"), 26314 - /* 57 */ "OpenEphemeral" OpHelp("nColumn=P2"), 26315 - /* 58 */ "SorterOpen" OpHelp(""), 26316 - /* 59 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"), 26317 - /* 60 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), 26318 - /* 61 */ "Close" OpHelp(""), 26319 - /* 62 */ "ColumnsUsed" OpHelp(""), 26320 - /* 63 */ "SeekLT" OpHelp("key=r[P3@P4]"), 26321 - /* 64 */ "SeekLE" OpHelp("key=r[P3@P4]"), 26322 - /* 65 */ "SeekGE" OpHelp("key=r[P3@P4]"), 26323 - /* 66 */ "SeekGT" OpHelp("key=r[P3@P4]"), 26324 - /* 67 */ "Seek" OpHelp("intkey=r[P2]"), 26325 - /* 68 */ "NoConflict" OpHelp("key=r[P3@P4]"), 26326 - /* 69 */ "NotFound" OpHelp("key=r[P3@P4]"), 26327 - /* 70 */ "Found" OpHelp("key=r[P3@P4]"), 26328 - /* 71 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"), 26329 - /* 72 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"), 26330 - /* 73 */ "NotExists" OpHelp("intkey=r[P3]"), 26331 - /* 74 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"), 26332 - /* 75 */ "NewRowid" OpHelp("r[P2]=rowid"), 26333 - /* 76 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"), 26334 - /* 77 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"), 26335 - /* 78 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"), 26336 - /* 79 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"), 26337 - /* 80 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"), 26338 - /* 81 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"), 26339 - /* 82 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"), 26340 - /* 83 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"), 26341 - /* 84 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), 26342 - /* 85 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"), 26343 - /* 86 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"), 26344 - /* 87 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"), 26345 - /* 88 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"), 26346 - /* 89 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"), 26347 - /* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"), 26348 - /* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"), 26349 - /* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"), 26350 - /* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"), 26351 - /* 94 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"), 26352 - /* 95 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"), 26353 - /* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"), 26354 - /* 97 */ "String8" OpHelp("r[P2]='P4'"), 26355 - /* 98 */ "Delete" OpHelp(""), 26356 - /* 99 */ "ResetCount" OpHelp(""), 26357 - /* 100 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"), 26358 - /* 101 */ "SorterData" OpHelp("r[P2]=data"), 26359 - /* 102 */ "RowKey" OpHelp("r[P2]=key"), 26360 - /* 103 */ "RowData" OpHelp("r[P2]=data"), 26361 - /* 104 */ "Rowid" OpHelp("r[P2]=rowid"), 26362 - /* 105 */ "NullRow" OpHelp(""), 26363 - /* 106 */ "Last" OpHelp(""), 26364 - /* 107 */ "SorterSort" OpHelp(""), 26365 - /* 108 */ "Sort" OpHelp(""), 26366 - /* 109 */ "Rewind" OpHelp(""), 26367 - /* 110 */ "SorterInsert" OpHelp(""), 26368 - /* 111 */ "IdxInsert" OpHelp("key=r[P2]"), 26369 - /* 112 */ "IdxDelete" OpHelp("key=r[P2@P3]"), 26370 - /* 113 */ "IdxRowid" OpHelp("r[P2]=rowid"), 26371 - /* 114 */ "IdxLE" OpHelp("key=r[P3@P4]"), 26372 - /* 115 */ "IdxGT" OpHelp("key=r[P3@P4]"), 26373 - /* 116 */ "IdxLT" OpHelp("key=r[P3@P4]"), 26374 - /* 117 */ "IdxGE" OpHelp("key=r[P3@P4]"), 26375 - /* 118 */ "Destroy" OpHelp(""), 26376 - /* 119 */ "Clear" OpHelp(""), 26377 - /* 120 */ "ResetSorter" OpHelp(""), 26378 - /* 121 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"), 26379 - /* 122 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"), 26380 - /* 123 */ "ParseSchema" OpHelp(""), 26381 - /* 124 */ "LoadAnalysis" OpHelp(""), 26382 - /* 125 */ "DropTable" OpHelp(""), 26383 - /* 126 */ "DropIndex" OpHelp(""), 26384 - /* 127 */ "DropTrigger" OpHelp(""), 26385 - /* 128 */ "IntegrityCk" OpHelp(""), 26386 - /* 129 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), 26387 - /* 130 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"), 26388 - /* 131 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"), 26389 - /* 132 */ "Program" OpHelp(""), 26390 - /* 133 */ "Real" OpHelp("r[P2]=P4"), 26391 - /* 134 */ "Param" OpHelp(""), 26392 - /* 135 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), 26393 - /* 136 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"), 26394 - /* 137 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), 26395 - /* 138 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"), 26396 - /* 139 */ "SetIfNotPos" OpHelp("if r[P1]<=0 then r[P2]=P3"), 26397 - /* 140 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]-=P3, goto P2"), 26398 - /* 141 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"), 26399 - /* 142 */ "JumpZeroIncr" OpHelp("if (r[P1]++)==0 ) goto P2"), 26400 - /* 143 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"), 26401 - /* 144 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), 26402 - /* 145 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), 26403 - /* 146 */ "IncrVacuum" OpHelp(""), 26404 - /* 147 */ "Expire" OpHelp(""), 26405 - /* 148 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), 26406 - /* 149 */ "VBegin" OpHelp(""), 26407 - /* 150 */ "VCreate" OpHelp(""), 26408 - /* 151 */ "VDestroy" OpHelp(""), 26409 - /* 152 */ "VOpen" OpHelp(""), 26410 - /* 153 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), 26411 - /* 154 */ "VNext" OpHelp(""), 26412 - /* 155 */ "VRename" OpHelp(""), 26413 - /* 156 */ "Pagecount" OpHelp(""), 26414 - /* 157 */ "MaxPgcnt" OpHelp(""), 26415 - /* 158 */ "Init" OpHelp("Start at P2"), 26416 - /* 159 */ "Noop" OpHelp(""), 26417 - /* 160 */ "Explain" OpHelp(""), 26684 + /* 1 */ "Savepoint" OpHelp(""), 26685 + /* 2 */ "AutoCommit" OpHelp(""), 26686 + /* 3 */ "Transaction" OpHelp(""), 26687 + /* 4 */ "SorterNext" OpHelp(""), 26688 + /* 5 */ "PrevIfOpen" OpHelp(""), 26689 + /* 6 */ "NextIfOpen" OpHelp(""), 26690 + /* 7 */ "Prev" OpHelp(""), 26691 + /* 8 */ "Next" OpHelp(""), 26692 + /* 9 */ "Checkpoint" OpHelp(""), 26693 + /* 10 */ "JournalMode" OpHelp(""), 26694 + /* 11 */ "Vacuum" OpHelp(""), 26695 + /* 12 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"), 26696 + /* 13 */ "VUpdate" OpHelp("data=r[P3@P2]"), 26697 + /* 14 */ "Goto" OpHelp(""), 26698 + /* 15 */ "Gosub" OpHelp(""), 26699 + /* 16 */ "Return" OpHelp(""), 26700 + /* 17 */ "InitCoroutine" OpHelp(""), 26701 + /* 18 */ "EndCoroutine" OpHelp(""), 26702 + /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"), 26703 + /* 20 */ "Yield" OpHelp(""), 26704 + /* 21 */ "HaltIfNull" OpHelp("if r[P3]=null halt"), 26705 + /* 22 */ "Halt" OpHelp(""), 26706 + /* 23 */ "Integer" OpHelp("r[P2]=P1"), 26707 + /* 24 */ "Int64" OpHelp("r[P2]=P4"), 26708 + /* 25 */ "String" OpHelp("r[P2]='P4' (len=P1)"), 26709 + /* 26 */ "Null" OpHelp("r[P2..P3]=NULL"), 26710 + /* 27 */ "SoftNull" OpHelp("r[P1]=NULL"), 26711 + /* 28 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), 26712 + /* 29 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), 26713 + /* 30 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), 26714 + /* 31 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"), 26715 + /* 32 */ "SCopy" OpHelp("r[P2]=r[P1]"), 26716 + /* 33 */ "IntCopy" OpHelp("r[P2]=r[P1]"), 26717 + /* 34 */ "ResultRow" OpHelp("output=r[P1@P2]"), 26718 + /* 35 */ "CollSeq" OpHelp(""), 26719 + /* 36 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"), 26720 + /* 37 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"), 26721 + /* 38 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), 26722 + /* 39 */ "MustBeInt" OpHelp(""), 26723 + /* 40 */ "RealAffinity" OpHelp(""), 26724 + /* 41 */ "Cast" OpHelp("affinity(r[P1])"), 26725 + /* 42 */ "Permutation" OpHelp(""), 26726 + /* 43 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"), 26727 + /* 44 */ "Jump" OpHelp(""), 26728 + /* 45 */ "Once" OpHelp(""), 26729 + /* 46 */ "If" OpHelp(""), 26730 + /* 47 */ "IfNot" OpHelp(""), 26731 + /* 48 */ "Column" OpHelp("r[P3]=PX"), 26732 + /* 49 */ "Affinity" OpHelp("affinity(r[P1@P2])"), 26733 + /* 50 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), 26734 + /* 51 */ "Count" OpHelp("r[P2]=count()"), 26735 + /* 52 */ "ReadCookie" OpHelp(""), 26736 + /* 53 */ "SetCookie" OpHelp(""), 26737 + /* 54 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"), 26738 + /* 55 */ "OpenRead" OpHelp("root=P2 iDb=P3"), 26739 + /* 56 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), 26740 + /* 57 */ "OpenAutoindex" OpHelp("nColumn=P2"), 26741 + /* 58 */ "OpenEphemeral" OpHelp("nColumn=P2"), 26742 + /* 59 */ "SorterOpen" OpHelp(""), 26743 + /* 60 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"), 26744 + /* 61 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), 26745 + /* 62 */ "Close" OpHelp(""), 26746 + /* 63 */ "ColumnsUsed" OpHelp(""), 26747 + /* 64 */ "SeekLT" OpHelp("key=r[P3@P4]"), 26748 + /* 65 */ "SeekLE" OpHelp("key=r[P3@P4]"), 26749 + /* 66 */ "SeekGE" OpHelp("key=r[P3@P4]"), 26750 + /* 67 */ "SeekGT" OpHelp("key=r[P3@P4]"), 26751 + /* 68 */ "Seek" OpHelp("intkey=r[P2]"), 26752 + /* 69 */ "NoConflict" OpHelp("key=r[P3@P4]"), 26753 + /* 70 */ "NotFound" OpHelp("key=r[P3@P4]"), 26754 + /* 71 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"), 26755 + /* 72 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"), 26756 + /* 73 */ "Found" OpHelp("key=r[P3@P4]"), 26757 + /* 74 */ "NotExists" OpHelp("intkey=r[P3]"), 26758 + /* 75 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"), 26759 + /* 76 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"), 26760 + /* 77 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"), 26761 + /* 78 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"), 26762 + /* 79 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"), 26763 + /* 80 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"), 26764 + /* 81 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"), 26765 + /* 82 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"), 26766 + /* 83 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"), 26767 + /* 84 */ "NewRowid" OpHelp("r[P2]=rowid"), 26768 + /* 85 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"), 26769 + /* 86 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"), 26770 + /* 87 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"), 26771 + /* 88 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"), 26772 + /* 89 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"), 26773 + /* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"), 26774 + /* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"), 26775 + /* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"), 26776 + /* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"), 26777 + /* 94 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"), 26778 + /* 95 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), 26779 + /* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"), 26780 + /* 97 */ "String8" OpHelp("r[P2]='P4'"), 26781 + /* 98 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"), 26782 + /* 99 */ "Delete" OpHelp(""), 26783 + /* 100 */ "ResetCount" OpHelp(""), 26784 + /* 101 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"), 26785 + /* 102 */ "SorterData" OpHelp("r[P2]=data"), 26786 + /* 103 */ "RowKey" OpHelp("r[P2]=key"), 26787 + /* 104 */ "RowData" OpHelp("r[P2]=data"), 26788 + /* 105 */ "Rowid" OpHelp("r[P2]=rowid"), 26789 + /* 106 */ "NullRow" OpHelp(""), 26790 + /* 107 */ "Last" OpHelp(""), 26791 + /* 108 */ "SorterSort" OpHelp(""), 26792 + /* 109 */ "Sort" OpHelp(""), 26793 + /* 110 */ "Rewind" OpHelp(""), 26794 + /* 111 */ "SorterInsert" OpHelp(""), 26795 + /* 112 */ "IdxInsert" OpHelp("key=r[P2]"), 26796 + /* 113 */ "IdxDelete" OpHelp("key=r[P2@P3]"), 26797 + /* 114 */ "IdxRowid" OpHelp("r[P2]=rowid"), 26798 + /* 115 */ "IdxLE" OpHelp("key=r[P3@P4]"), 26799 + /* 116 */ "IdxGT" OpHelp("key=r[P3@P4]"), 26800 + /* 117 */ "IdxLT" OpHelp("key=r[P3@P4]"), 26801 + /* 118 */ "IdxGE" OpHelp("key=r[P3@P4]"), 26802 + /* 119 */ "Destroy" OpHelp(""), 26803 + /* 120 */ "Clear" OpHelp(""), 26804 + /* 121 */ "ResetSorter" OpHelp(""), 26805 + /* 122 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"), 26806 + /* 123 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"), 26807 + /* 124 */ "ParseSchema" OpHelp(""), 26808 + /* 125 */ "LoadAnalysis" OpHelp(""), 26809 + /* 126 */ "DropTable" OpHelp(""), 26810 + /* 127 */ "DropIndex" OpHelp(""), 26811 + /* 128 */ "DropTrigger" OpHelp(""), 26812 + /* 129 */ "IntegrityCk" OpHelp(""), 26813 + /* 130 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), 26814 + /* 131 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"), 26815 + /* 132 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"), 26816 + /* 133 */ "Real" OpHelp("r[P2]=P4"), 26817 + /* 134 */ "Program" OpHelp(""), 26818 + /* 135 */ "Param" OpHelp(""), 26819 + /* 136 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), 26820 + /* 137 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"), 26821 + /* 138 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), 26822 + /* 139 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"), 26823 + /* 140 */ "SetIfNotPos" OpHelp("if r[P1]<=0 then r[P2]=P3"), 26824 + /* 141 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]-=P3, goto P2"), 26825 + /* 142 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"), 26826 + /* 143 */ "JumpZeroIncr" OpHelp("if (r[P1]++)==0 ) goto P2"), 26827 + /* 144 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"), 26828 + /* 145 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), 26829 + /* 146 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), 26830 + /* 147 */ "IncrVacuum" OpHelp(""), 26831 + /* 148 */ "Expire" OpHelp(""), 26832 + /* 149 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), 26833 + /* 150 */ "VBegin" OpHelp(""), 26834 + /* 151 */ "VCreate" OpHelp(""), 26835 + /* 152 */ "VDestroy" OpHelp(""), 26836 + /* 153 */ "VOpen" OpHelp(""), 26837 + /* 154 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), 26838 + /* 155 */ "VNext" OpHelp(""), 26839 + /* 156 */ "VRename" OpHelp(""), 26840 + /* 157 */ "Pagecount" OpHelp(""), 26841 + /* 158 */ "MaxPgcnt" OpHelp(""), 26842 + /* 159 */ "Init" OpHelp("Start at P2"), 26843 + /* 160 */ "CursorHint" OpHelp(""), 26844 + /* 161 */ "Noop" OpHelp(""), 26845 + /* 162 */ "Explain" OpHelp(""), 26418 26846 }; 26419 26847 return azName[i]; 26420 26848 } 26421 26849 #endif 26422 26850 26423 26851 /************** End of opcodes.c *********************************************/ 26424 26852 /************** Begin file os_unix.c *****************************************/ ................................................................................ 26678 27106 #else 26679 27107 # define UNIXFILE_DIRSYNC 0x00 26680 27108 #endif 26681 27109 #define UNIXFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */ 26682 27110 #define UNIXFILE_DELETE 0x20 /* Delete on close */ 26683 27111 #define UNIXFILE_URI 0x40 /* Filename might have query parameters */ 26684 27112 #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */ 26685 -#define UNIXFILE_WARNED 0x0100 /* verifyDbFile() warnings issued */ 26686 -#define UNIXFILE_BLOCK 0x0200 /* Next SHM lock might block */ 26687 27113 26688 27114 /* 26689 27115 ** Include code that is common to all os_*.c files 26690 27116 */ 26691 27117 /************** Include os_common.h in the middle of os_unix.c ***************/ 26692 27118 /************** Begin file os_common.h ***************************************/ 26693 27119 /* ................................................................................ 26942 27368 ** The safest way to deal with the problem is to always use this wrapper 26943 27369 ** which always has the same well-defined interface. 26944 27370 */ 26945 27371 static int posixOpen(const char *zFile, int flags, int mode){ 26946 27372 return open(zFile, flags, mode); 26947 27373 } 26948 27374 26949 -/* 26950 -** On some systems, calls to fchown() will trigger a message in a security 26951 -** log if they come from non-root processes. So avoid calling fchown() if 26952 -** we are not running as root. 26953 -*/ 26954 -static int posixFchown(int fd, uid_t uid, gid_t gid){ 26955 -#if OS_VXWORKS 26956 - return 0; 26957 -#else 26958 - return geteuid() ? 0 : fchown(fd,uid,gid); 26959 -#endif 26960 -} 26961 - 26962 27375 /* Forward reference */ 26963 27376 static int openDirectory(const char*, int*); 26964 27377 static int unixGetpagesize(void); 26965 27378 26966 27379 /* 26967 27380 ** Many system calls are accessed through pointer-to-functions so that 26968 27381 ** they may be overridden at runtime to facilitate fault injection during ................................................................................ 27041 27454 { "pwrite64", (sqlite3_syscall_ptr)pwrite64, 0 }, 27042 27455 #else 27043 27456 { "pwrite64", (sqlite3_syscall_ptr)0, 0 }, 27044 27457 #endif 27045 27458 #define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\ 27046 27459 aSyscall[13].pCurrent) 27047 27460 27048 - { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 }, 27461 + { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 }, 27049 27462 #define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent) 27050 27463 27051 27464 #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE 27052 27465 { "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 }, 27053 27466 #else 27054 27467 { "fallocate", (sqlite3_syscall_ptr)0, 0 }, 27055 27468 #endif ................................................................................ 27063 27476 27064 27477 { "mkdir", (sqlite3_syscall_ptr)mkdir, 0 }, 27065 27478 #define osMkdir ((int(*)(const char*,mode_t))aSyscall[18].pCurrent) 27066 27479 27067 27480 { "rmdir", (sqlite3_syscall_ptr)rmdir, 0 }, 27068 27481 #define osRmdir ((int(*)(const char*))aSyscall[19].pCurrent) 27069 27482 27070 - { "fchown", (sqlite3_syscall_ptr)posixFchown, 0 }, 27483 + { "fchown", (sqlite3_syscall_ptr)fchown, 0 }, 27071 27484 #define osFchown ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent) 27485 + 27486 + { "geteuid", (sqlite3_syscall_ptr)geteuid, 0 }, 27487 +#define osGeteuid ((uid_t(*)(void))aSyscall[21].pCurrent) 27072 27488 27073 27489 #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 27074 27490 { "mmap", (sqlite3_syscall_ptr)mmap, 0 }, 27075 -#define osMmap ((void*(*)(void*,size_t,int,int,int,off_t))aSyscall[21].pCurrent) 27491 +#define osMmap ((void*(*)(void*,size_t,int,int,int,off_t))aSyscall[22].pCurrent) 27076 27492 27077 27493 { "munmap", (sqlite3_syscall_ptr)munmap, 0 }, 27078 -#define osMunmap ((void*(*)(void*,size_t))aSyscall[22].pCurrent) 27494 +#define osMunmap ((void*(*)(void*,size_t))aSyscall[23].pCurrent) 27079 27495 27080 27496 #if HAVE_MREMAP 27081 27497 { "mremap", (sqlite3_syscall_ptr)mremap, 0 }, 27082 27498 #else 27083 27499 { "mremap", (sqlite3_syscall_ptr)0, 0 }, 27084 27500 #endif 27085 -#define osMremap ((void*(*)(void*,size_t,size_t,int,...))aSyscall[23].pCurrent) 27501 +#define osMremap ((void*(*)(void*,size_t,size_t,int,...))aSyscall[24].pCurrent) 27502 + 27086 27503 { "getpagesize", (sqlite3_syscall_ptr)unixGetpagesize, 0 }, 27087 -#define osGetpagesize ((int(*)(void))aSyscall[24].pCurrent) 27504 +#define osGetpagesize ((int(*)(void))aSyscall[25].pCurrent) 27505 + 27506 + { "readlink", (sqlite3_syscall_ptr)readlink, 0 }, 27507 +#define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[26].pCurrent) 27088 27508 27089 27509 #endif 27090 27510 27091 27511 }; /* End of the overrideable system calls */ 27092 27512 27513 + 27514 +/* 27515 +** On some systems, calls to fchown() will trigger a message in a security 27516 +** log if they come from non-root processes. So avoid calling fchown() if 27517 +** we are not running as root. 27518 +*/ 27519 +static int robustFchown(int fd, uid_t uid, gid_t gid){ 27520 +#if OS_VXWORKS 27521 + return 0; 27522 +#else 27523 + return osGeteuid() ? 0 : osFchown(fd,uid,gid); 27524 +#endif 27525 +} 27526 + 27093 27527 /* 27094 27528 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the 27095 27529 ** "unix" VFSes. Return SQLITE_OK opon successfully updating the 27096 27530 ** system call pointer, or SQLITE_NOTFOUND if there is no configurable 27097 27531 ** system call named zName. 27098 27532 */ 27099 27533 static int unixSetSystemCall( ................................................................................ 27370 27804 ** and a variety of "please close the file descriptor NOW" errors into 27371 27805 ** SQLITE_IOERR 27372 27806 ** 27373 27807 ** Errors during initialization of locks, or file system support for locks, 27374 27808 ** should handle ENOLCK, ENOTSUP, EOPNOTSUPP separately. 27375 27809 */ 27376 27810 static int sqliteErrorFromPosixError(int posixError, int sqliteIOErr) { 27811 + assert( (sqliteIOErr == SQLITE_IOERR_LOCK) || 27812 + (sqliteIOErr == SQLITE_IOERR_UNLOCK) || 27813 + (sqliteIOErr == SQLITE_IOERR_RDLOCK) || 27814 + (sqliteIOErr == SQLITE_IOERR_CHECKRESERVEDLOCK) ); 27377 27815 switch (posixError) { 27378 -#if 0 27379 - /* At one point this code was not commented out. In theory, this branch 27380 - ** should never be hit, as this function should only be called after 27381 - ** a locking-related function (i.e. fcntl()) has returned non-zero with 27382 - ** the value of errno as the first argument. Since a system call has failed, 27383 - ** errno should be non-zero. 27384 - ** 27385 - ** Despite this, if errno really is zero, we still don't want to return 27386 - ** SQLITE_OK. The system call failed, and *some* SQLite error should be 27387 - ** propagated back to the caller. Commenting this branch out means errno==0 27388 - ** will be handled by the "default:" case below. 27389 - */ 27390 - case 0: 27391 - return SQLITE_OK; 27392 -#endif 27393 - 27816 + case EACCES: 27394 27817 case EAGAIN: 27395 27818 case ETIMEDOUT: 27396 27819 case EBUSY: 27397 27820 case EINTR: 27398 27821 case ENOLCK: 27399 27822 /* random NFS retry error, unless during file system support 27400 27823 * introspection, in which it actually means what it says */ 27401 27824 return SQLITE_BUSY; 27402 27825 27403 - case EACCES: 27404 - /* EACCES is like EAGAIN during locking operations, but not any other time*/ 27405 - if( (sqliteIOErr == SQLITE_IOERR_LOCK) || 27406 - (sqliteIOErr == SQLITE_IOERR_UNLOCK) || 27407 - (sqliteIOErr == SQLITE_IOERR_RDLOCK) || 27408 - (sqliteIOErr == SQLITE_IOERR_CHECKRESERVEDLOCK) ){ 27409 - return SQLITE_BUSY; 27410 - } 27411 - /* else fall through */ 27412 27826 case EPERM: 27413 27827 return SQLITE_PERM; 27414 27828 27415 -#if EOPNOTSUPP!=ENOTSUP 27416 - case EOPNOTSUPP: 27417 - /* something went terribly awry, unless during file system support 27418 - * introspection, in which it actually means what it says */ 27419 -#endif 27420 -#ifdef ENOTSUP 27421 - case ENOTSUP: 27422 - /* invalid fd, unless during file system support introspection, in which 27423 - * it actually means what it says */ 27424 -#endif 27425 - case EIO: 27426 - case EBADF: 27427 - case EINVAL: 27428 - case ENOTCONN: 27429 - case ENODEV: 27430 - case ENXIO: 27431 - case ENOENT: 27432 -#ifdef ESTALE /* ESTALE is not defined on Interix systems */ 27433 - case ESTALE: 27434 -#endif 27435 - case ENOSYS: 27436 - /* these should force the client to close the file and reconnect */ 27437 - 27438 27829 default: 27439 27830 return sqliteIOErr; 27440 27831 } 27441 27832 } 27442 27833 27443 27834 27444 27835 /****************************************************************************** ................................................................................ 27714 28105 /* 27715 28106 ** A lists of all unixInodeInfo objects. 27716 28107 */ 27717 28108 static unixInodeInfo *inodeList = 0; 27718 28109 27719 28110 /* 27720 28111 ** 27721 -** This function - unixLogError_x(), is only ever called via the macro 28112 +** This function - unixLogErrorAtLine(), is only ever called via the macro 27722 28113 ** unixLogError(). 27723 28114 ** 27724 28115 ** It is invoked after an error occurs in an OS function and errno has been 27725 28116 ** set. It logs a message using sqlite3_log() containing the current value of 27726 28117 ** errno and, if possible, the human-readable equivalent from strerror() or 27727 28118 ** strerror_r(). 27728 28119 ** ................................................................................ 27883 28274 /* Get low-level information about the file that we can used to 27884 28275 ** create a unique name for the file. 27885 28276 */ 27886 28277 fd = pFile->h; 27887 28278 rc = osFstat(fd, &statbuf); 27888 28279 if( rc!=0 ){ 27889 28280 storeLastErrno(pFile, errno); 27890 -#ifdef EOVERFLOW 28281 +#if defined(EOVERFLOW) && defined(SQLITE_DISABLE_LFS) 27891 28282 if( pFile->lastErrno==EOVERFLOW ) return SQLITE_NOLFS; 27892 28283 #endif 27893 28284 return SQLITE_IOERR; 27894 28285 } 27895 28286 27896 28287 #ifdef __APPLE__ 27897 28288 /* On OS X on an msdos filesystem, the inode number is reported ................................................................................ 27970 28361 ** (3) The file has not been renamed or unlinked 27971 28362 ** 27972 28363 ** Issue sqlite3_log(SQLITE_WARNING,...) messages if anything is not right. 27973 28364 */ 27974 28365 static void verifyDbFile(unixFile *pFile){ 27975 28366 struct stat buf; 27976 28367 int rc; 27977 - if( pFile->ctrlFlags & UNIXFILE_WARNED ){ 27978 - /* One or more of the following warnings have already been issued. Do not 27979 - ** repeat them so as not to clutter the error log */ 27980 - return; 27981 - } 27982 28368 rc = osFstat(pFile->h, &buf); 27983 28369 if( rc!=0 ){ 27984 28370 sqlite3_log(SQLITE_WARNING, "cannot fstat db file %s", pFile->zPath); 27985 - pFile->ctrlFlags |= UNIXFILE_WARNED; 27986 28371 return; 27987 28372 } 27988 28373 if( buf.st_nlink==0 && (pFile->ctrlFlags & UNIXFILE_DELETE)==0 ){ 27989 28374 sqlite3_log(SQLITE_WARNING, "file unlinked while open: %s", pFile->zPath); 27990 - pFile->ctrlFlags |= UNIXFILE_WARNED; 27991 28375 return; 27992 28376 } 27993 28377 if( buf.st_nlink>1 ){ 27994 28378 sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath); 27995 - pFile->ctrlFlags |= UNIXFILE_WARNED; 27996 28379 return; 27997 28380 } 27998 28381 if( fileHasMoved(pFile) ){ 27999 28382 sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath); 28000 - pFile->ctrlFlags |= UNIXFILE_WARNED; 28001 28383 return; 28002 28384 } 28003 28385 } 28004 28386 28005 28387 28006 28388 /* 28007 28389 ** This routine checks if there is a RESERVED lock held on the specified ................................................................................ 28013 28395 int rc = SQLITE_OK; 28014 28396 int reserved = 0; 28015 28397 unixFile *pFile = (unixFile*)id; 28016 28398 28017 28399 SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; ); 28018 28400 28019 28401 assert( pFile ); 28402 + assert( pFile->eFileLock<=SHARED_LOCK ); 28020 28403 unixEnterMutex(); /* Because pFile->pInode is shared across threads */ 28021 28404 28022 28405 /* Check if a thread in this process holds such a lock */ 28023 28406 if( pFile->pInode->eFileLock>SHARED_LOCK ){ 28024 28407 reserved = 1; 28025 28408 } 28026 28409 ................................................................................ 28069 28452 ** to fcntl() fails. In this case, errno is set appropriately (by fcntl()). 28070 28453 */ 28071 28454 static int unixFileLock(unixFile *pFile, struct flock *pLock){ 28072 28455 int rc; 28073 28456 unixInodeInfo *pInode = pFile->pInode; 28074 28457 assert( unixMutexHeld() ); 28075 28458 assert( pInode!=0 ); 28076 - if( ((pFile->ctrlFlags & UNIXFILE_EXCL)!=0 || pInode->bProcessLock) 28077 - && ((pFile->ctrlFlags & UNIXFILE_RDONLY)==0) 28078 - ){ 28459 + if( (pFile->ctrlFlags & (UNIXFILE_EXCL|UNIXFILE_RDONLY))==UNIXFILE_EXCL ){ 28079 28460 if( pInode->bProcessLock==0 ){ 28080 28461 struct flock lock; 28081 28462 assert( pInode->nLock==0 ); 28082 28463 lock.l_whence = SEEK_SET; 28083 28464 lock.l_start = SHARED_FIRST; 28084 28465 lock.l_len = SHARED_SIZE; 28085 28466 lock.l_type = F_WRLCK; ................................................................................ 28423 28804 lock.l_type = F_UNLCK; 28424 28805 lock.l_whence = SEEK_SET; 28425 28806 lock.l_start = SHARED_FIRST; 28426 28807 lock.l_len = divSize; 28427 28808 if( unixFileLock(pFile, &lock)==(-1) ){ 28428 28809 tErrno = errno; 28429 28810 rc = SQLITE_IOERR_UNLOCK; 28430 - if( IS_LOCK_ERROR(rc) ){ 28431 - storeLastErrno(pFile, tErrno); 28432 - } 28811 + storeLastErrno(pFile, tErrno); 28433 28812 goto end_unlock; 28434 28813 } 28435 28814 lock.l_type = F_RDLCK; 28436 28815 lock.l_whence = SEEK_SET; 28437 28816 lock.l_start = SHARED_FIRST; 28438 28817 lock.l_len = divSize; 28439 28818 if( unixFileLock(pFile, &lock)==(-1) ){ ................................................................................ 28447 28826 lock.l_type = F_UNLCK; 28448 28827 lock.l_whence = SEEK_SET; 28449 28828 lock.l_start = SHARED_FIRST+divSize; 28450 28829 lock.l_len = SHARED_SIZE-divSize; 28451 28830 if( unixFileLock(pFile, &lock)==(-1) ){ 28452 28831 tErrno = errno; 28453 28832 rc = SQLITE_IOERR_UNLOCK; 28454 - if( IS_LOCK_ERROR(rc) ){ 28455 - storeLastErrno(pFile, tErrno); 28456 - } 28833 + storeLastErrno(pFile, tErrno); 28457 28834 goto end_unlock; 28458 28835 } 28459 28836 }else 28460 28837 #endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */ 28461 28838 { 28462 28839 lock.l_type = F_RDLCK; 28463 28840 lock.l_whence = SEEK_SET; ................................................................................ 28700 29077 int rc = SQLITE_OK; 28701 29078 int reserved = 0; 28702 29079 unixFile *pFile = (unixFile*)id; 28703 29080 28704 29081 SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; ); 28705 29082 28706 29083 assert( pFile ); 28707 - 28708 - /* Check if a thread in this process holds such a lock */ 28709 - if( pFile->eFileLock>SHARED_LOCK ){ 28710 - /* Either this connection or some other connection in the same process 28711 - ** holds a lock on the file. No need to check further. */ 28712 - reserved = 1; 28713 - }else{ 28714 - /* The lock is held if and only if the lockfile exists */ 28715 - const char *zLockFile = (const char*)pFile->lockingContext; 28716 - reserved = osAccess(zLockFile, 0)==0; 28717 - } 29084 + reserved = osAccess((const char*)pFile->lockingContext, 0)==0; 28718 29085 OSTRACE(("TEST WR-LOCK %d %d %d (dotlock)\n", pFile->h, rc, reserved)); 28719 29086 *pResOut = reserved; 28720 29087 return rc; 28721 29088 } 28722 29089 28723 29090 /* 28724 29091 ** Lock the file with the lock specified by parameter eFileLock - one ................................................................................ 28772 29139 if( rc<0 ){ 28773 29140 /* failed to open/create the lock directory */ 28774 29141 int tErrno = errno; 28775 29142 if( EEXIST == tErrno ){ 28776 29143 rc = SQLITE_BUSY; 28777 29144 } else { 28778 29145 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); 28779 - if( IS_LOCK_ERROR(rc) ){ 29146 + if( rc!=SQLITE_BUSY ){ 28780 29147 storeLastErrno(pFile, tErrno); 28781 29148 } 28782 29149 } 28783 29150 return rc; 28784 29151 } 28785 29152 28786 29153 /* got it, set the type and return ok */ ................................................................................ 28819 29186 pFile->eFileLock = SHARED_LOCK; 28820 29187 return SQLITE_OK; 28821 29188 } 28822 29189 28823 29190 /* To fully unlock the database, delete the lock file */ 28824 29191 assert( eFileLock==NO_LOCK ); 28825 29192 rc = osRmdir(zLockFile); 28826 - if( rc<0 && errno==ENOTDIR ) rc = osUnlink(zLockFile); 28827 29193 if( rc<0 ){ 28828 29194 int tErrno = errno; 28829 - rc = 0; 28830 - if( ENOENT != tErrno ){ 29195 + if( tErrno==ENOENT ){ 29196 + rc = SQLITE_OK; 29197 + }else{ 28831 29198 rc = SQLITE_IOERR_UNLOCK; 28832 - } 28833 - if( IS_LOCK_ERROR(rc) ){ 28834 29199 storeLastErrno(pFile, tErrno); 28835 29200 } 28836 29201 return rc; 28837 29202 } 28838 29203 pFile->eFileLock = NO_LOCK; 28839 29204 return SQLITE_OK; 28840 29205 } 28841 29206 28842 29207 /* 28843 29208 ** Close a file. Make sure the lock has been released before closing. 28844 29209 */ 28845 29210 static int dotlockClose(sqlite3_file *id) { 28846 - int rc = SQLITE_OK; 28847 - if( id ){ 28848 - unixFile *pFile = (unixFile*)id; 28849 - dotlockUnlock(id, NO_LOCK); 28850 - sqlite3_free(pFile->lockingContext); 28851 - rc = closeUnixFile(id); 28852 - } 28853 - return rc; 29211 + unixFile *pFile = (unixFile*)id; 29212 + assert( id!=0 ); 29213 + dotlockUnlock(id, NO_LOCK); 29214 + sqlite3_free(pFile->lockingContext); 29215 + return closeUnixFile(id); 28854 29216 } 28855 29217 /****************** End of the dot-file lock implementation ******************* 28856 29218 ******************************************************************************/ 28857 29219 28858 29220 /****************************************************************************** 28859 29221 ************************** Begin flock Locking ******************************** 28860 29222 ** ................................................................................ 28912 29274 if( !lrc ){ 28913 29275 /* got the lock, unlock it */ 28914 29276 lrc = robust_flock(pFile->h, LOCK_UN); 28915 29277 if ( lrc ) { 28916 29278 int tErrno = errno; 28917 29279 /* unlock failed with an error */ 28918 29280 lrc = SQLITE_IOERR_UNLOCK; 28919 - if( IS_LOCK_ERROR(lrc) ){ 28920 - storeLastErrno(pFile, tErrno); 28921 - rc = lrc; 28922 - } 29281 + storeLastErrno(pFile, tErrno); 29282 + rc = lrc; 28923 29283 } 28924 29284 } else { 28925 29285 int tErrno = errno; 28926 29286 reserved = 1; 28927 29287 /* someone else might have it reserved */ 28928 29288 lrc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); 28929 29289 if( IS_LOCK_ERROR(lrc) ){ ................................................................................ 29048 29408 } 29049 29409 } 29050 29410 29051 29411 /* 29052 29412 ** Close a file. 29053 29413 */ 29054 29414 static int flockClose(sqlite3_file *id) { 29055 - int rc = SQLITE_OK; 29056 - if( id ){ 29057 - flockUnlock(id, NO_LOCK); 29058 - rc = closeUnixFile(id); 29059 - } 29060 - return rc; 29415 + assert( id!=0 ); 29416 + flockUnlock(id, NO_LOCK); 29417 + return closeUnixFile(id); 29061 29418 } 29062 29419 29063 29420 #endif /* SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORK */ 29064 29421 29065 29422 /******************* End of the flock lock implementation ********************* 29066 29423 ******************************************************************************/ 29067 29424 ................................................................................ 29678 30035 } 29679 30036 29680 30037 /* 29681 30038 ** Close a file & cleanup AFP specific locking context 29682 30039 */ 29683 30040 static int afpClose(sqlite3_file *id) { 29684 30041 int rc = SQLITE_OK; 29685 - if( id ){ 29686 - unixFile *pFile = (unixFile*)id; 29687 - afpUnlock(id, NO_LOCK); 29688 - unixEnterMutex(); 29689 - if( pFile->pInode && pFile->pInode->nLock ){ 29690 - /* If there are outstanding locks, do not actually close the file just 29691 - ** yet because that would clear those locks. Instead, add the file 29692 - ** descriptor to pInode->aPending. It will be automatically closed when 29693 - ** the last lock is cleared. 29694 - */ 29695 - setPendingFd(pFile); 29696 - } 29697 - releaseInodeInfo(pFile); 29698 - sqlite3_free(pFile->lockingContext); 29699 - rc = closeUnixFile(id); 29700 - unixLeaveMutex(); 30042 + unixFile *pFile = (unixFile*)id; 30043 + assert( id!=0 ); 30044 + afpUnlock(id, NO_LOCK); 30045 + unixEnterMutex(); 30046 + if( pFile->pInode && pFile->pInode->nLock ){ 30047 + /* If there are outstanding locks, do not actually close the file just 30048 + ** yet because that would clear those locks. Instead, add the file 30049 + ** descriptor to pInode->aPending. It will be automatically closed when 30050 + ** the last lock is cleared. 30051 + */ 30052 + setPendingFd(pFile); 29701 30053 } 30054 + releaseInodeInfo(pFile); 30055 + sqlite3_free(pFile->lockingContext); 30056 + rc = closeUnixFile(id); 30057 + unixLeaveMutex(); 29702 30058 return rc; 29703 30059 } 29704 30060 29705 30061 #endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */ 29706 30062 /* 29707 30063 ** The code above is the AFP lock implementation. The code is specific 29708 30064 ** to MacOSX and does not work on other unix platforms. No alternative ................................................................................ 29773 30129 got = osPread(id->h, pBuf, cnt, offset); 29774 30130 SimulateIOError( got = -1 ); 29775 30131 #elif defined(USE_PREAD64) 29776 30132 got = osPread64(id->h, pBuf, cnt, offset); 29777 30133 SimulateIOError( got = -1 ); 29778 30134 #else 29779 30135 newOffset = lseek(id->h, offset, SEEK_SET); 29780 - SimulateIOError( newOffset-- ); 29781 - if( newOffset!=offset ){ 29782 - if( newOffset == -1 ){ 29783 - storeLastErrno((unixFile*)id, errno); 29784 - }else{ 29785 - storeLastErrno((unixFile*)id, 0); 29786 - } 30136 + SimulateIOError( newOffset = -1 ); 30137 + if( newOffset<0 ){ 30138 + storeLastErrno((unixFile*)id, errno); 29787 30139 return -1; 29788 30140 } 29789 30141 got = osRead(id->h, pBuf, cnt); 29790 30142 #endif 29791 30143 if( got==cnt ) break; 29792 30144 if( got<0 ){ 29793 30145 if( errno==EINTR ){ got = 1; continue; } ................................................................................ 29878 30230 int nBuf, /* Size of buffer pBuf in bytes */ 29879 30231 int *piErrno /* OUT: Error number if error occurs */ 29880 30232 ){ 29881 30233 int rc = 0; /* Value returned by system call */ 29882 30234 29883 30235 assert( nBuf==(nBuf&0x1ffff) ); 29884 30236 assert( fd>2 ); 30237 + assert( piErrno!=0 ); 29885 30238 nBuf &= 0x1ffff; 29886 30239 TIMER_START; 29887 30240 29888 30241 #if defined(USE_PREAD) 29889 30242 do{ rc = (int)osPwrite(fd, pBuf, nBuf, iOff); }while( rc<0 && errno==EINTR ); 29890 30243 #elif defined(USE_PREAD64) 29891 30244 do{ rc = (int)osPwrite64(fd, pBuf, nBuf, iOff);}while( rc<0 && errno==EINTR); 29892 30245 #else 29893 30246 do{ 29894 30247 i64 iSeek = lseek(fd, iOff, SEEK_SET); 29895 - SimulateIOError( iSeek-- ); 29896 - 29897 - if( iSeek!=iOff ){ 29898 - if( piErrno ) *piErrno = (iSeek==-1 ? errno : 0); 29899 - return -1; 30248 + SimulateIOError( iSeek = -1 ); 30249 + if( iSeek<0 ){ 30250 + rc = -1; 30251 + break; 29900 30252 } 29901 30253 rc = osWrite(fd, pBuf, nBuf); 29902 30254 }while( rc<0 && errno==EINTR ); 29903 30255 #endif 29904 30256 29905 30257 TIMER_END; 29906 30258 OSTRACE(("WRITE %-3d %5d %7lld %llu\n", fd, rc, iOff, TIMER_ELAPSED)); 29907 30259 29908 - if( rc<0 && piErrno ) *piErrno = errno; 30260 + if( rc<0 ) *piErrno = errno; 29909 30261 return rc; 29910 30262 } 29911 30263 29912 30264 29913 30265 /* 29914 30266 ** Seek to the offset in id->offset then read cnt bytes into pBuf. 29915 30267 ** Return the number of bytes actually read. Update the offset. ................................................................................ 29964 30316 if( rc!=4 || memcmp(oldCntr, &((char*)pBuf)[24-offset], 4)!=0 ){ 29965 30317 pFile->transCntrChng = 1; /* The transaction counter has changed */ 29966 30318 } 29967 30319 } 29968 30320 } 29969 30321 #endif 29970 30322 29971 -#if SQLITE_MAX_MMAP_SIZE>0 30323 +#if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0 29972 30324 /* Deal with as much of this write request as possible by transfering 29973 30325 ** data from the memory mapping using memcpy(). */ 29974 30326 if( offset<pFile->mmapSize ){ 29975 30327 if( offset+amt <= pFile->mmapSize ){ 29976 30328 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt); 29977 30329 return SQLITE_OK; 29978 30330 }else{ ................................................................................ 30085 30437 */ 30086 30438 #ifdef SQLITE_TEST 30087 30439 if( fullSync ) sqlite3_fullsync_count++; 30088 30440 sqlite3_sync_count++; 30089 30441 #endif 30090 30442 30091 30443 /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a 30092 - ** no-op 30444 + ** no-op. But go ahead and call fstat() to validate the file 30445 + ** descriptor as we need a method to provoke a failure during 30446 + ** coverate testing. 30093 30447 */ 30094 30448 #ifdef SQLITE_NO_SYNC 30095 - rc = SQLITE_OK; 30449 + { 30450 + struct stat buf; 30451 + rc = osFstat(fd, &buf); 30452 + } 30096 30453 #elif HAVE_FULLFSYNC 30097 30454 if( fullSync ){ 30098 30455 rc = osFcntl(fd, F_FULLFSYNC, 0); 30099 30456 }else{ 30100 30457 rc = 1; 30101 30458 } 30102 30459 /* If the FULLFSYNC failed, fall back to attempting an fsync(). ................................................................................ 30154 30511 */ 30155 30512 static int openDirectory(const char *zFilename, int *pFd){ 30156 30513 int ii; 30157 30514 int fd = -1; 30158 30515 char zDirname[MAX_PATHNAME+1]; 30159 30516 30160 30517 sqlite3_snprintf(MAX_PATHNAME, zDirname, "%s", zFilename); 30161 - for(ii=(int)strlen(zDirname); ii>1 && zDirname[ii]!='/'; ii--); 30518 + for(ii=(int)strlen(zDirname); ii>0 && zDirname[ii]!='/'; ii--); 30162 30519 if( ii>0 ){ 30163 30520 zDirname[ii] = '\0'; 30164 - fd = robust_open(zDirname, O_RDONLY|O_BINARY, 0); 30165 - if( fd>=0 ){ 30166 - OSTRACE(("OPENDIR %-3d %s\n", fd, zDirname)); 30167 - } 30521 + }else{ 30522 + if( zDirname[0]!='/' ) zDirname[0] = '.'; 30523 + zDirname[1] = 0; 30524 + } 30525 + fd = robust_open(zDirname, O_RDONLY|O_BINARY, 0); 30526 + if( fd>=0 ){ 30527 + OSTRACE(("OPENDIR %-3d %s\n", fd, zDirname)); 30168 30528 } 30169 30529 *pFd = fd; 30170 - return (fd>=0?SQLITE_OK:unixLogError(SQLITE_CANTOPEN_BKPT, "open", zDirname)); 30530 + if( fd>=0 ) return SQLITE_OK; 30531 + return unixLogError(SQLITE_CANTOPEN_BKPT, "openDirectory", zDirname); 30171 30532 } 30172 30533 30173 30534 /* 30174 30535 ** Make sure all writes to a particular file are committed to disk. 30175 30536 ** 30176 30537 ** If dataOnly==0 then both the file itself and its metadata (file 30177 30538 ** size, access time, etc) are synced. If dataOnly!=0 then only the ................................................................................ 30216 30577 ** are unable to fsync a directory, so ignore errors on the fsync. 30217 30578 */ 30218 30579 if( pFile->ctrlFlags & UNIXFILE_DIRSYNC ){ 30219 30580 int dirfd; 30220 30581 OSTRACE(("DIRSYNC %s (have_fullfsync=%d fullsync=%d)\n", pFile->zPath, 30221 30582 HAVE_FULLFSYNC, isFullsync)); 30222 30583 rc = osOpenDirectory(pFile->zPath, &dirfd); 30223 - if( rc==SQLITE_OK && dirfd>=0 ){ 30584 + if( rc==SQLITE_OK ){ 30224 30585 full_fsync(dirfd, 0, 0); 30225 30586 robust_close(pFile, dirfd, __LINE__); 30226 - }else if( rc==SQLITE_CANTOPEN ){ 30587 + }else{ 30588 + assert( rc==SQLITE_CANTOPEN ); 30227 30589 rc = SQLITE_OK; 30228 30590 } 30229 30591 pFile->ctrlFlags &= ~UNIXFILE_DIRSYNC; 30230 30592 } 30231 30593 return rc; 30232 30594 } 30233 30595 ................................................................................ 30351 30713 ** This is a similar technique to that used by glibc on systems 30352 30714 ** that do not have a real fallocate() call. 30353 30715 */ 30354 30716 int nBlk = buf.st_blksize; /* File-system block size */ 30355 30717 int nWrite = 0; /* Number of bytes written by seekAndWrite */ 30356 30718 i64 iWrite; /* Next offset to write to */ 30357 30719 30358 - iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1; 30720 + iWrite = (buf.st_size/nBlk)*nBlk + nBlk - 1; 30359 30721 assert( iWrite>=buf.st_size ); 30360 - assert( (iWrite/nBlk)==((buf.st_size+nBlk-1)/nBlk) ); 30361 30722 assert( ((iWrite+1)%nBlk)==0 ); 30362 - for(/*no-op*/; iWrite<nSize; iWrite+=nBlk ){ 30723 + for(/*no-op*/; iWrite<nSize+nBlk-1; iWrite+=nBlk ){ 30724 + if( iWrite>=nSize ) iWrite = nSize - 1; 30363 30725 nWrite = seekAndWrite(pFile, iWrite, "", 1); 30364 30726 if( nWrite!=1 ) return SQLITE_IOERR_WRITE; 30365 30727 } 30366 - if( nWrite==0 || (nSize%nBlk) ){ 30367 - nWrite = seekAndWrite(pFile, nSize-1, "", 1); 30368 - if( nWrite!=1 ) return SQLITE_IOERR_WRITE; 30369 - } 30370 30728 #endif 30371 30729 } 30372 30730 } 30373 30731 30374 30732 #if SQLITE_MAX_MMAP_SIZE>0 30375 30733 if( pFile->mmapSizeMax>0 && nByte>pFile->mmapSize ){ 30376 30734 int rc; ................................................................................ 30410 30768 30411 30769 /* 30412 30770 ** Information and control of an open file handle. 30413 30771 */ 30414 30772 static int unixFileControl(sqlite3_file *id, int op, void *pArg){ 30415 30773 unixFile *pFile = (unixFile*)id; 30416 30774 switch( op ){ 30417 - case SQLITE_FCNTL_WAL_BLOCK: { 30418 - /* pFile->ctrlFlags |= UNIXFILE_BLOCK; // Deferred feature */ 30419 - return SQLITE_OK; 30420 - } 30421 30775 case SQLITE_FCNTL_LOCKSTATE: { 30422 30776 *(int*)pArg = pFile->eFileLock; 30423 30777 return SQLITE_OK; 30424 30778 } 30425 30779 case SQLITE_FCNTL_LAST_ERRNO: { 30426 30780 *(int*)pArg = pFile->lastErrno; 30427 30781 return SQLITE_OK; ................................................................................ 30740 31094 pShmNode = pFile->pInode->pShmNode; 30741 31095 assert( sqlite3_mutex_held(pShmNode->mutex) || pShmNode->nRef==0 ); 30742 31096 30743 31097 /* Shared locks never span more than one byte */ 30744 31098 assert( n==1 || lockType!=F_RDLCK ); 30745 31099 30746 31100 /* Locks are within range */ 30747 - assert( n>=1 && n<SQLITE_SHM_NLOCK ); 31101 + assert( n>=1 && n<=SQLITE_SHM_NLOCK ); 30748 31102 30749 31103 if( pShmNode->h>=0 ){ 30750 - int lkType; 30751 31104 /* Initialize the locking parameters */ 30752 31105 memset(&f, 0, sizeof(f)); 30753 31106 f.l_type = lockType; 30754 31107 f.l_whence = SEEK_SET; 30755 31108 f.l_start = ofst; 30756 31109 f.l_len = n; 30757 31110 30758 - lkType = (pFile->ctrlFlags & UNIXFILE_BLOCK)!=0 ? F_SETLKW : F_SETLK; 30759 - rc = osFcntl(pShmNode->h, lkType, &f); 31111 + rc = osFcntl(pShmNode->h, F_SETLK, &f); 30760 31112 rc = (rc!=(-1)) ? SQLITE_OK : SQLITE_BUSY; 30761 - pFile->ctrlFlags &= ~UNIXFILE_BLOCK; 30762 31113 } 30763 31114 30764 31115 /* Update the global lock state and do debug tracing */ 30765 31116 #ifdef SQLITE_DEBUG 30766 31117 { u16 mask; 30767 31118 OSTRACE(("SHM-LOCK ")); 30768 31119 mask = ofst>31 ? 0xffff : (1<<(ofst+n)) - (1<<ofst); ................................................................................ 30821 31172 ** 30822 31173 ** This is not a VFS shared-memory method; it is a utility function called 30823 31174 ** by VFS shared-memory methods. 30824 31175 */ 30825 31176 static void unixShmPurge(unixFile *pFd){ 30826 31177 unixShmNode *p = pFd->pInode->pShmNode; 30827 31178 assert( unixMutexHeld() ); 30828 - if( p && p->nRef==0 ){ 31179 + if( p && ALWAYS(p->nRef==0) ){ 30829 31180 int nShmPerMap = unixShmRegionPerMap(); 30830 31181 int i; 30831 31182 assert( p->pInode==pFd->pInode ); 30832 31183 sqlite3_mutex_free(p->mutex); 30833 31184 for(i=0; i<p->nRegion; i+=nShmPerMap){ 30834 31185 if( p->h>=0 ){ 30835 31186 osMunmap(p->apRegion[i], p->szRegion); ................................................................................ 30908 31259 const char *zBasePath = pDbFd->zPath; 30909 31260 #endif 30910 31261 30911 31262 /* Call fstat() to figure out the permissions on the database file. If 30912 31263 ** a new *-shm file is created, an attempt will be made to create it 30913 31264 ** with the same permissions. 30914 31265 */ 30915 - if( osFstat(pDbFd->h, &sStat) && pInode->bProcessLock==0 ){ 31266 + if( osFstat(pDbFd->h, &sStat) ){ 30916 31267 rc = SQLITE_IOERR_FSTAT; 30917 31268 goto shm_open_err; 30918 31269 } 30919 31270 30920 31271 #ifdef SQLITE_SHM_DIRECTORY 30921 31272 nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31; 30922 31273 #else ................................................................................ 30958 31309 goto shm_open_err; 30959 31310 } 30960 31311 30961 31312 /* If this process is running as root, make sure that the SHM file 30962 31313 ** is owned by the same user that owns the original database. Otherwise, 30963 31314 ** the original owner will not be able to connect. 30964 31315 */ 30965 - osFchown(pShmNode->h, sStat.st_uid, sStat.st_gid); 31316 + robustFchown(pShmNode->h, sStat.st_uid, sStat.st_gid); 30966 31317 30967 31318 /* Check to see if another process is holding the dead-man switch. 30968 31319 ** If not, truncate the file to zero length. 30969 31320 */ 30970 31321 rc = SQLITE_OK; 30971 31322 if( unixShmSystemLock(pDbFd, F_WRLCK, UNIX_SHM_DMS, 1)==SQLITE_OK ){ 30972 31323 if( robust_ftruncate(pShmNode->h, 0) ){ ................................................................................ 31095 31446 else{ 31096 31447 static const int pgsz = 4096; 31097 31448 int iPg; 31098 31449 31099 31450 /* Write to the last byte of each newly allocated or extended page */ 31100 31451 assert( (nByte % pgsz)==0 ); 31101 31452 for(iPg=(sStat.st_size/pgsz); iPg<(nByte/pgsz); iPg++){ 31102 - if( seekAndWriteFd(pShmNode->h, iPg*pgsz + pgsz-1, "", 1, 0)!=1 ){ 31453 + int x = 0; 31454 + if( seekAndWriteFd(pShmNode->h, iPg*pgsz + pgsz-1, "", 1, &x)!=1 ){ 31103 31455 const char *zFile = pShmNode->zFilename; 31104 31456 rc = unixLogError(SQLITE_IOERR_SHMSIZE, "write", zFile); 31105 31457 goto shmpage_out; 31106 31458 } 31107 31459 } 31108 31460 } 31109 31461 } ................................................................................ 31389 31741 assert( pFd->nFetchOut==0 ); 31390 31742 assert( nNew>pFd->mmapSize ); 31391 31743 assert( nNew<=pFd->mmapSizeMax ); 31392 31744 assert( nNew>0 ); 31393 31745 assert( pFd->mmapSizeActual>=pFd->mmapSize ); 31394 31746 assert( MAP_FAILED!=0 ); 31395 31747 31748 +#ifdef SQLITE_MMAP_READWRITE 31396 31749 if( (pFd->ctrlFlags & UNIXFILE_RDONLY)==0 ) flags |= PROT_WRITE; 31750 +#endif 31397 31751 31398 31752 if( pOrig ){ 31399 31753 #if HAVE_MREMAP 31400 31754 i64 nReuse = pFd->mmapSize; 31401 31755 #else 31402 31756 const int szSyspage = osGetpagesize(); 31403 31757 i64 nReuse = (pFd->mmapSize & ~(szSyspage-1)); ................................................................................ 31461 31815 ** created mapping is either the requested size or the value configured 31462 31816 ** using SQLITE_FCNTL_MMAP_LIMIT, whichever is smaller. 31463 31817 ** 31464 31818 ** SQLITE_OK is returned if no error occurs (even if the mapping is not 31465 31819 ** recreated as a result of outstanding references) or an SQLite error 31466 31820 ** code otherwise. 31467 31821 */ 31468 -static int unixMapfile(unixFile *pFd, i64 nByte){ 31469 - i64 nMap = nByte; 31470 - int rc; 31471 - 31822 +static int unixMapfile(unixFile *pFd, i64 nMap){ 31472 31823 assert( nMap>=0 || pFd->nFetchOut==0 ); 31824 + assert( nMap>0 || (pFd->mmapSize==0 && pFd->pMapRegion==0) ); 31473 31825 if( pFd->nFetchOut>0 ) return SQLITE_OK; 31474 31826 31475 31827 if( nMap<0 ){ 31476 31828 struct stat statbuf; /* Low-level file information */ 31477 - rc = osFstat(pFd->h, &statbuf); 31478 - if( rc!=SQLITE_OK ){ 31829 + if( osFstat(pFd->h, &statbuf) ){ 31479 31830 return SQLITE_IOERR_FSTAT; 31480 31831 } 31481 31832 nMap = statbuf.st_size; 31482 31833 } 31483 31834 if( nMap>pFd->mmapSizeMax ){ 31484 31835 nMap = pFd->mmapSizeMax; 31485 31836 } 31486 31837 31838 + assert( nMap>0 || (pFd->mmapSize==0 && pFd->pMapRegion==0) ); 31487 31839 if( nMap!=pFd->mmapSize ){ 31488 - if( nMap>0 ){ 31489 - unixRemapfile(pFd, nMap); 31490 - }else{ 31491 - unixUnmapfile(pFd); 31492 - } 31840 + unixRemapfile(pFd, nMap); 31493 31841 } 31494 31842 31495 31843 return SQLITE_OK; 31496 31844 } 31497 31845 #endif /* SQLITE_MAX_MMAP_SIZE>0 */ 31498 31846 31499 31847 /* ................................................................................ 32056 32404 ** Return the name of a directory in which to put temporary files. 32057 32405 ** If no suitable temporary file directory can be found, return NULL. 32058 32406 */ 32059 32407 static const char *unixTempFileDir(void){ 32060 32408 static const char *azDirs[] = { 32061 32409 0, 32062 32410 0, 32063 - 0, 32064 32411 "/var/tmp", 32065 32412 "/usr/tmp", 32066 32413 "/tmp", 32067 - 0 /* List terminator */ 32414 + "." 32068 32415 }; 32069 32416 unsigned int i; 32070 32417 struct stat buf; 32071 - const char *zDir = 0; 32418 + const char *zDir = sqlite3_temp_directory; 32072 32419 32073 - azDirs[0] = sqlite3_temp_directory; 32074 - if( !azDirs[1] ) azDirs[1] = getenv("SQLITE_TMPDIR"); 32075 - if( !azDirs[2] ) azDirs[2] = getenv("TMPDIR"); 32420 + if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR"); 32421 + if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR"); 32076 32422 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){ 32077 32423 if( zDir==0 ) continue; 32078 32424 if( osStat(zDir, &buf) ) continue; 32079 32425 if( !S_ISDIR(buf.st_mode) ) continue; 32080 32426 if( osAccess(zDir, 07) ) continue; 32081 32427 break; 32082 32428 } ................................................................................ 32085 32431 32086 32432 /* 32087 32433 ** Create a temporary file name in zBuf. zBuf must be allocated 32088 32434 ** by the calling process and must be big enough to hold at least 32089 32435 ** pVfs->mxPathname bytes. 32090 32436 */ 32091 32437 static int unixGetTempname(int nBuf, char *zBuf){ 32092 - static const unsigned char zChars[] = 32093 - "abcdefghijklmnopqrstuvwxyz" 32094 - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 32095 - "0123456789"; 32096 - unsigned int i, j; 32097 32438 const char *zDir; 32439 + int iLimit = 0; 32098 32440 32099 32441 /* It's odd to simulate an io-error here, but really this is just 32100 32442 ** using the io-error infrastructure to test that SQLite handles this 32101 32443 ** function failing. 32102 32444 */ 32103 32445 SimulateIOError( return SQLITE_IOERR ); 32104 32446 32105 32447 zDir = unixTempFileDir(); 32106 - if( zDir==0 ) zDir = "."; 32107 - 32108 - /* Check that the output buffer is large enough for the temporary file 32109 - ** name. If it is not, return SQLITE_ERROR. 32110 - */ 32111 - if( (strlen(zDir) + strlen(SQLITE_TEMP_FILE_PREFIX) + 18) >= (size_t)nBuf ){ 32112 - return SQLITE_ERROR; 32113 - } 32114 - 32115 32448 do{ 32116 - sqlite3_snprintf(nBuf-18, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX, zDir); 32117 - j = (int)strlen(zBuf); 32118 - sqlite3_randomness(15, &zBuf[j]); 32119 - for(i=0; i<15; i++, j++){ 32120 - zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ]; 32121 - } 32122 - zBuf[j] = 0; 32123 - zBuf[j+1] = 0; 32449 + u64 r; 32450 + sqlite3_randomness(sizeof(r), &r); 32451 + assert( nBuf>2 ); 32452 + zBuf[nBuf-2] = 0; 32453 + sqlite3_snprintf(nBuf, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX"%llx%c", 32454 + zDir, r, 0); 32455 + if( zBuf[nBuf-2]!=0 || (iLimit++)>10 ) return SQLITE_ERROR; 32124 32456 }while( osAccess(zBuf,0)==0 ); 32125 32457 return SQLITE_OK; 32126 32458 } 32127 32459 32128 32460 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) 32129 32461 /* 32130 32462 ** Routine to transform a unixFile into a proxy-locking unixFile. ................................................................................ 32238 32570 ** "<path to db>-journalNN" 32239 32571 ** "<path to db>-walNN" 32240 32572 ** 32241 32573 ** where NN is a decimal number. The NN naming schemes are 32242 32574 ** used by the test_multiplex.c module. 32243 32575 */ 32244 32576 nDb = sqlite3Strlen30(zPath) - 1; 32245 -#ifdef SQLITE_ENABLE_8_3_NAMES 32246 - while( nDb>0 && sqlite3Isalnum(zPath[nDb]) ) nDb--; 32247 - if( nDb==0 || zPath[nDb]!='-' ) return SQLITE_OK; 32248 -#else 32249 32577 while( zPath[nDb]!='-' ){ 32578 +#ifndef SQLITE_ENABLE_8_3_NAMES 32579 + /* In the normal case (8+3 filenames disabled) the journal filename 32580 + ** is guaranteed to contain a '-' character. */ 32250 32581 assert( nDb>0 ); 32251 - assert( zPath[nDb]!='\n' ); 32582 + assert( sqlite3Isalnum(zPath[nDb]) ); 32583 +#else 32584 + /* If 8+3 names are possible, then the journal file might not contain 32585 + ** a '-' character. So check for that case and return early. */ 32586 + if( nDb==0 || zPath[nDb]=='.' ) return SQLITE_OK; 32587 +#endif 32252 32588 nDb--; 32253 32589 } 32254 -#endif 32255 32590 memcpy(zDb, zPath, nDb); 32256 32591 zDb[nDb] = '\0'; 32257 32592 32258 32593 if( 0==osStat(zDb, &sStat) ){ 32259 32594 *pMode = sStat.st_mode & 0777; 32260 32595 *pUid = sStat.st_uid; 32261 32596 *pGid = sStat.st_gid; ................................................................................ 32388 32723 ** URIs with parameters. Hence, they can always be passed into 32389 32724 ** sqlite3_uri_parameter(). */ 32390 32725 assert( (flags & SQLITE_OPEN_URI) || zName[strlen(zName)+1]==0 ); 32391 32726 32392 32727 }else if( !zName ){ 32393 32728 /* If zName is NULL, the upper layer is requesting a temp file. */ 32394 32729 assert(isDelete && !syncDir); 32395 - rc = unixGetTempname(MAX_PATHNAME+2, zTmpname); 32730 + rc = unixGetTempname(pVfs->mxPathname, zTmpname); 32396 32731 if( rc!=SQLITE_OK ){ 32397 32732 return rc; 32398 32733 } 32399 32734 zName = zTmpname; 32400 32735 32401 32736 /* Generated temporary filenames are always double-zero terminated 32402 32737 ** for use by sqlite3_uri_parameter(). */ ................................................................................ 32421 32756 if( rc!=SQLITE_OK ){ 32422 32757 assert( !p->pUnused ); 32423 32758 assert( eType==SQLITE_OPEN_WAL || eType==SQLITE_OPEN_MAIN_JOURNAL ); 32424 32759 return rc; 32425 32760 } 32426 32761 fd = robust_open(zName, openFlags, openMode); 32427 32762 OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags)); 32428 - if( fd<0 && errno!=EISDIR && isReadWrite && !isExclusive ){ 32763 + assert( !isExclusive || (openFlags & O_CREAT)!=0 ); 32764 + if( fd<0 && errno!=EISDIR && isReadWrite ){ 32429 32765 /* Failed to open the file for read/write access. Try read-only. */ 32430 32766 flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE); 32431 32767 openFlags &= ~(O_RDWR|O_CREAT); 32432 32768 flags |= SQLITE_OPEN_READONLY; 32433 32769 openFlags |= O_RDONLY; 32434 32770 isReadonly = 1; 32435 32771 fd = robust_open(zName, openFlags, openMode); ................................................................................ 32440 32776 } 32441 32777 32442 32778 /* If this process is running as root and if creating a new rollback 32443 32779 ** journal or WAL file, set the ownership of the journal or WAL to be 32444 32780 ** the same as the original database. 32445 32781 */ 32446 32782 if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){ 32447 - osFchown(fd, uid, gid); 32783 + robustFchown(fd, uid, gid); 32448 32784 } 32449 32785 } 32450 32786 assert( fd>=0 ); 32451 32787 if( pOutFlags ){ 32452 32788 *pOutFlags = flags; 32453 32789 } 32454 32790 ................................................................................ 32577 32913 #else 32578 32914 if( fsync(fd) ) 32579 32915 #endif 32580 32916 { 32581 32917 rc = unixLogError(SQLITE_IOERR_DIR_FSYNC, "fsync", zPath); 32582 32918 } 32583 32919 robust_close(0, fd, __LINE__); 32584 - }else if( rc==SQLITE_CANTOPEN ){ 32920 + }else{ 32921 + assert( rc==SQLITE_CANTOPEN ); 32585 32922 rc = SQLITE_OK; 32586 32923 } 32587 32924 } 32588 32925 #endif 32589 32926 return rc; 32590 32927 } 32591 32928 ................................................................................ 32601 32938 */ 32602 32939 static int unixAccess( 32603 32940 sqlite3_vfs *NotUsed, /* The VFS containing this xAccess method */ 32604 32941 const char *zPath, /* Path of the file to examine */ 32605 32942 int flags, /* What do we want to learn about the zPath file? */ 32606 32943 int *pResOut /* Write result boolean here */ 32607 32944 ){ 32608 - int amode = 0; 32609 32945 UNUSED_PARAMETER(NotUsed); 32610 32946 SimulateIOError( return SQLITE_IOERR_ACCESS; ); 32611 - switch( flags ){ 32612 - case SQLITE_ACCESS_EXISTS: 32613 - amode = F_OK; 32614 - break; 32615 - case SQLITE_ACCESS_READWRITE: 32616 - amode = W_OK|R_OK; 32617 - break; 32618 - case SQLITE_ACCESS_READ: 32619 - amode = R_OK; 32620 - break; 32947 + assert( pResOut!=0 ); 32621 32948 32622 - default: 32623 - assert(!"Invalid flags argument"); 32624 - } 32625 - *pResOut = (osAccess(zPath, amode)==0); 32626 - if( flags==SQLITE_ACCESS_EXISTS && *pResOut ){ 32949 + /* The spec says there are three possible values for flags. But only 32950 + ** two of them are actually used */ 32951 + assert( flags==SQLITE_ACCESS_EXISTS || flags==SQLITE_ACCESS_READWRITE ); 32952 + 32953 + if( flags==SQLITE_ACCESS_EXISTS ){ 32627 32954 struct stat buf; 32628 - if( 0==osStat(zPath, &buf) && buf.st_size==0 ){ 32629 - *pResOut = 0; 32630 - } 32955 + *pResOut = (0==osStat(zPath, &buf) && buf.st_size>0); 32956 + }else{ 32957 + *pResOut = osAccess(zPath, W_OK|R_OK)==0; 32631 32958 } 32632 32959 return SQLITE_OK; 32633 32960 } 32634 32961 32635 32962 32636 32963 /* 32637 32964 ** Turn a relative pathname into a full pathname. The relative path ................................................................................ 32644 32971 */ 32645 32972 static int unixFullPathname( 32646 32973 sqlite3_vfs *pVfs, /* Pointer to vfs object */ 32647 32974 const char *zPath, /* Possibly relative input path */ 32648 32975 int nOut, /* Size of output buffer in bytes */ 32649 32976 char *zOut /* Output buffer */ 32650 32977 ){ 32978 + int nByte; 32651 32979 32652 32980 /* It's odd to simulate an io-error here, but really this is just 32653 32981 ** using the io-error infrastructure to test that SQLite handles this 32654 32982 ** function failing. This function could fail if, for example, the 32655 32983 ** current working directory has been unlinked. 32656 32984 */ 32657 32985 SimulateIOError( return SQLITE_ERROR ); 32658 32986 32659 32987 assert( pVfs->mxPathname==MAX_PATHNAME ); 32660 32988 UNUSED_PARAMETER(pVfs); 32661 32989 32662 - zOut[nOut-1] = '\0'; 32663 - if( zPath[0]=='/' ){ 32990 + /* Attempt to resolve the path as if it were a symbolic link. If it is 32991 + ** a symbolic link, the resolved path is stored in buffer zOut[]. Or, if 32992 + ** the identified file is not a symbolic link or does not exist, then 32993 + ** zPath is copied directly into zOut. Either way, nByte is left set to 32994 + ** the size of the string copied into zOut[] in bytes. */ 32995 + nByte = osReadlink(zPath, zOut, nOut-1); 32996 + if( nByte<0 ){ 32997 + if( errno!=EINVAL && errno!=ENOENT ){ 32998 + return unixLogError(SQLITE_CANTOPEN_BKPT, "readlink", zPath); 32999 + } 32664 33000 sqlite3_snprintf(nOut, zOut, "%s", zPath); 33001 + nByte = sqlite3Strlen30(zOut); 32665 33002 }else{ 33003 + zOut[nByte] = '\0'; 33004 + } 33005 + 33006 + /* If buffer zOut[] now contains an absolute path there is nothing more 33007 + ** to do. If it contains a relative path, do the following: 33008 + ** 33009 + ** * move the relative path string so that it is at the end of th 33010 + ** zOut[] buffer. 33011 + ** * Call getcwd() to read the path of the current working directory 33012 + ** into the start of the zOut[] buffer. 33013 + ** * Append a '/' character to the cwd string and move the 33014 + ** relative path back within the buffer so that it immediately 33015 + ** follows the '/'. 33016 + ** 33017 + ** This code is written so that if the combination of the CWD and relative 33018 + ** path are larger than the allocated size of zOut[] the CWD is silently 33019 + ** truncated to make it fit. This is Ok, as SQLite refuses to open any 33020 + ** file for which this function returns a full path larger than (nOut-8) 33021 + ** bytes in size. */ 33022 + testcase( nByte==nOut-5 ); 33023 + testcase( nByte==nOut-4 ); 33024 + if( zOut[0]!='/' && nByte<nOut-4 ){ 32666 33025 int nCwd; 32667 - if( osGetcwd(zOut, nOut-1)==0 ){ 33026 + int nRem = nOut-nByte-1; 33027 + memmove(&zOut[nRem], zOut, nByte+1); 33028 + zOut[nRem-1] = '\0'; 33029 + if( osGetcwd(zOut, nRem-1)==0 ){ 32668 33030 return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath); 32669 33031 } 32670 - nCwd = (int)strlen(zOut); 32671 - sqlite3_snprintf(nOut-nCwd, &zOut[nCwd], "/%s", zPath); 33032 + nCwd = sqlite3Strlen30(zOut); 33033 + assert( nCwd<=nRem-1 ); 33034 + zOut[nCwd] = '/'; 33035 + memmove(&zOut[nCwd+1], &zOut[nRem], nByte+1); 32672 33036 } 33037 + 32673 33038 return SQLITE_OK; 32674 33039 } 32675 33040 32676 33041 32677 33042 #ifndef SQLITE_OMIT_LOAD_EXTENSION 32678 33043 /* 32679 33044 ** Interfaces for opening a shared library, finding entry points ................................................................................ 32835 33200 *piNow = ((sqlite3_int64)t)*1000 + unixEpoch; 32836 33201 #elif OS_VXWORKS 32837 33202 struct timespec sNow; 32838 33203 clock_gettime(CLOCK_REALTIME, &sNow); 32839 33204 *piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_nsec/1000000; 32840 33205 #else 32841 33206 struct timeval sNow; 32842 - if( gettimeofday(&sNow, 0)==0 ){ 32843 - *piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_usec/1000; 32844 - }else{ 32845 - rc = SQLITE_ERROR; 32846 - } 33207 + (void)gettimeofday(&sNow, 0); /* Cannot fail given valid arguments */ 33208 + *piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_usec/1000; 32847 33209 #endif 32848 33210 32849 33211 #ifdef SQLITE_TEST 32850 33212 if( sqlite3_current_time ){ 32851 33213 *piNow = 1000*(sqlite3_int64)sqlite3_current_time + unixEpoch; 32852 33214 } 32853 33215 #endif 32854 33216 UNUSED_PARAMETER(NotUsed); 32855 33217 return rc; 32856 33218 } 32857 33219 33220 +#if 0 /* Not used */ 32858 33221 /* 32859 33222 ** Find the current time (in Universal Coordinated Time). Write the 32860 33223 ** current time and date as a Julian Day number into *prNow and 32861 33224 ** return 0. Return 1 if the time and date cannot be found. 32862 33225 */ 32863 33226 static int unixCurrentTime(sqlite3_vfs *NotUsed, double *prNow){ 32864 33227 sqlite3_int64 i = 0; 32865 33228 int rc; 32866 33229 UNUSED_PARAMETER(NotUsed); 32867 33230 rc = unixCurrentTimeInt64(0, &i); 32868 33231 *prNow = i/86400000.0; 32869 33232 return rc; 32870 33233 } 33234 +#else 33235 +# define unixCurrentTime 0 33236 +#endif 32871 33237 33238 +#if 0 /* Not used */ 32872 33239 /* 32873 33240 ** We added the xGetLastError() method with the intention of providing 32874 33241 ** better low-level error messages when operating-system problems come up 32875 33242 ** during SQLite operation. But so far, none of that has been implemented 32876 33243 ** in the core. So this routine is never called. For now, it is merely 32877 33244 ** a place-holder. 32878 33245 */ 32879 33246 static int unixGetLastError(sqlite3_vfs *NotUsed, int NotUsed2, char *NotUsed3){ 32880 33247 UNUSED_PARAMETER(NotUsed); 32881 33248 UNUSED_PARAMETER(NotUsed2); 32882 33249 UNUSED_PARAMETER(NotUsed3); 32883 33250 return 0; 32884 33251 } 33252 +#else 33253 +# define unixGetLastError 0 33254 +#endif 32885 33255 32886 33256 32887 33257 /* 32888 33258 ************************ End of sqlite3_vfs methods *************************** 32889 33259 ******************************************************************************/ 32890 33260 32891 33261 /****************************************************************************** ................................................................................ 33131 33501 } 33132 33502 } 33133 33503 } 33134 33504 start=i+1; 33135 33505 } 33136 33506 buf[i] = lockPath[i]; 33137 33507 } 33138 - OSTRACE(("CREATELOCKPATH proxy lock path=%s pid=%d\n", lockPath, osGetpid(0))); 33508 + OSTRACE(("CREATELOCKPATH proxy lock path=%s pid=%d\n",lockPath,osGetpid(0))); 33139 33509 return 0; 33140 33510 } 33141 33511 33142 33512 /* 33143 33513 ** Create a new VFS file descriptor (stored in memory obtained from 33144 33514 ** sqlite3_malloc) and open the file named "path" in the file descriptor. 33145 33515 ** ................................................................................ 34016 34386 return rc; 34017 34387 } 34018 34388 34019 34389 /* 34020 34390 ** Close a file that uses proxy locks. 34021 34391 */ 34022 34392 static int proxyClose(sqlite3_file *id) { 34023 - if( id ){ 34393 + if( ALWAYS(id) ){ 34024 34394 unixFile *pFile = (unixFile*)id; 34025 34395 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext; 34026 34396 unixFile *lockProxy = pCtx->lockProxy; 34027 34397 unixFile *conchFile = pCtx->conchFile; 34028 34398 int rc = SQLITE_OK; 34029 34399 34030 34400 if( lockProxy ){ ................................................................................ 34160 34530 UNIXVFS("unix-proxy", proxyIoFinder ), 34161 34531 #endif 34162 34532 }; 34163 34533 unsigned int i; /* Loop counter */ 34164 34534 34165 34535 /* Double-check that the aSyscall[] array has been constructed 34166 34536 ** correctly. See ticket [bb3a86e890c8e96ab] */ 34167 - assert( ArraySize(aSyscall)==25 ); 34537 + assert( ArraySize(aSyscall)==27 ); 34168 34538 34169 34539 /* Register all VFSes defined in the aVfs[] array */ 34170 34540 for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){ 34171 34541 sqlite3_vfs_register(&aVfs[i], i==0); 34172 34542 } 34173 34543 return SQLITE_OK; 34174 34544 } ................................................................................ 36986 37356 SimulateIOError(return SQLITE_IOERR_WRITE); 36987 37357 SimulateDiskfullError(return SQLITE_FULL); 36988 37358 36989 37359 OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, " 36990 37360 "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile, 36991 37361 pFile->h, pBuf, amt, offset, pFile->locktype)); 36992 37362 36993 -#if SQLITE_MAX_MMAP_SIZE>0 37363 +#if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0 36994 37364 /* Deal with as much of this write request as possible by transfering 36995 37365 ** data from the memory mapping using memcpy(). */ 36996 37366 if( offset<pFile->mmapSize ){ 36997 37367 if( offset+amt <= pFile->mmapSize ){ 36998 37368 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt); 36999 37369 OSTRACE(("WRITE-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", 37000 37370 osGetCurrentProcessId(), pFile, pFile->h)); ................................................................................ 37534 37904 OSTRACE(("TEST-WR-LOCK file=%p, pResOut=%p\n", pFile->h, pResOut)); 37535 37905 37536 37906 assert( id!=0 ); 37537 37907 if( pFile->locktype>=RESERVED_LOCK ){ 37538 37908 res = 1; 37539 37909 OSTRACE(("TEST-WR-LOCK file=%p, result=%d (local)\n", pFile->h, res)); 37540 37910 }else{ 37541 - res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS,RESERVED_BYTE, 0, 1, 0); 37911 + res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS,RESERVED_BYTE,0,1,0); 37542 37912 if( res ){ 37543 37913 winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0); 37544 37914 } 37545 37915 res = !res; 37546 37916 OSTRACE(("TEST-WR-LOCK file=%p, result=%d (remote)\n", pFile->h, res)); 37547 37917 } 37548 37918 *pResOut = res; ................................................................................ 38480 38850 } 38481 38851 if( nMap!=pFd->mmapSize ){ 38482 38852 void *pNew = 0; 38483 38853 DWORD protect = PAGE_READONLY; 38484 38854 DWORD flags = FILE_MAP_READ; 38485 38855 38486 38856 winUnmapfile(pFd); 38857 +#ifdef SQLITE_MMAP_READWRITE 38487 38858 if( (pFd->ctrlFlags & WINFILE_RDONLY)==0 ){ 38488 38859 protect = PAGE_READWRITE; 38489 38860 flags |= FILE_MAP_WRITE; 38490 38861 } 38862 +#endif 38491 38863 #if SQLITE_OS_WINRT 38492 38864 pFd->hMap = osCreateFileMappingFromApp(pFd->h, NULL, protect, nMap, NULL); 38493 38865 #elif defined(SQLITE_WIN32_HAS_WIDE) 38494 38866 pFd->hMap = osCreateFileMappingW(pFd->h, NULL, protect, 38495 38867 (DWORD)((nMap>>32) & 0xffffffff), 38496 38868 (DWORD)(nMap & 0xffffffff), NULL); 38497 38869 #elif defined(SQLITE_WIN32_HAS_ANSI) ................................................................................ 40068 40440 /* #include "sqliteInt.h" */ 40069 40441 40070 40442 /* Size of the Bitvec structure in bytes. */ 40071 40443 #define BITVEC_SZ 512 40072 40444 40073 40445 /* Round the union size down to the nearest pointer boundary, since that's how 40074 40446 ** it will be aligned within the Bitvec struct. */ 40075 -#define BITVEC_USIZE (((BITVEC_SZ-(3*sizeof(u32)))/sizeof(Bitvec*))*sizeof(Bitvec*)) 40447 +#define BITVEC_USIZE \ 40448 + (((BITVEC_SZ-(3*sizeof(u32)))/sizeof(Bitvec*))*sizeof(Bitvec*)) 40076 40449 40077 40450 /* Type of the array "element" for the bitmap representation. 40078 40451 ** Should be a power of 2, and ideally, evenly divide into BITVEC_USIZE. 40079 40452 ** Setting this to the "natural word" size of your CPU may improve 40080 40453 ** performance. */ 40081 40454 #define BITVEC_TELEM u8 40082 40455 /* Size, in bits, of the bitmap element. */ ................................................................................ 40461 40834 ** A complete page cache is an instance of this structure. 40462 40835 */ 40463 40836 struct PCache { 40464 40837 PgHdr *pDirty, *pDirtyTail; /* List of dirty pages in LRU order */ 40465 40838 PgHdr *pSynced; /* Last synced page in dirty page list */ 40466 40839 int nRefSum; /* Sum of ref counts over all pages */ 40467 40840 int szCache; /* Configured cache size */ 40841 + int szSpill; /* Size before spilling occurs */ 40468 40842 int szPage; /* Size of every page in this cache */ 40469 40843 int szExtra; /* Size of extra space for each page */ 40470 40844 u8 bPurgeable; /* True if pages are on backing store */ 40471 40845 u8 eCreate; /* eCreate value for for xFetch() */ 40472 40846 int (*xStress)(void*,PgHdr*); /* Call to try make a page clean */ 40473 40847 void *pStress; /* Argument to xStress */ 40474 40848 sqlite3_pcache *pCache; /* Pluggable cache module */ ................................................................................ 40550 40924 static void pcacheUnpin(PgHdr *p){ 40551 40925 if( p->pCache->bPurgeable ){ 40552 40926 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0); 40553 40927 } 40554 40928 } 40555 40929 40556 40930 /* 40557 -** Compute the number of pages of cache requested. p->szCache is the 40931 +** Compute the number of pages of cache requested. p->szCache is the 40558 40932 ** cache size requested by the "PRAGMA cache_size" statement. 40559 -** 40560 -** 40561 40933 */ 40562 40934 static int numberOfCachePages(PCache *p){ 40563 40935 if( p->szCache>=0 ){ 40564 40936 /* IMPLEMENTATION-OF: R-42059-47211 If the argument N is positive then the 40565 40937 ** suggested cache size is set to N. */ 40566 40938 return p->szCache; 40567 40939 }else{ ................................................................................ 40616 40988 p->szPage = 1; 40617 40989 p->szExtra = szExtra; 40618 40990 p->bPurgeable = bPurgeable; 40619 40991 p->eCreate = 2; 40620 40992 p->xStress = xStress; 40621 40993 p->pStress = pStress; 40622 40994 p->szCache = 100; 40995 + p->szSpill = 1; 40623 40996 return sqlite3PcacheSetPageSize(p, szPage); 40624 40997 } 40625 40998 40626 40999 /* 40627 41000 ** Change the page size for PCache object. The caller must ensure that there 40628 41001 ** are no outstanding page references when this function is called. 40629 41002 */ ................................................................................ 40711 41084 PCache *pCache, /* Obtain the page from this cache */ 40712 41085 Pgno pgno, /* Page number to obtain */ 40713 41086 sqlite3_pcache_page **ppPage /* Write result here */ 40714 41087 ){ 40715 41088 PgHdr *pPg; 40716 41089 if( pCache->eCreate==2 ) return 0; 40717 41090 40718 - 40719 - /* Find a dirty page to write-out and recycle. First try to find a 40720 - ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC 40721 - ** cleared), but if that is not possible settle for any other 40722 - ** unreferenced dirty page. 40723 - */ 40724 - for(pPg=pCache->pSynced; 40725 - pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC)); 40726 - pPg=pPg->pDirtyPrev 40727 - ); 40728 - pCache->pSynced = pPg; 40729 - if( !pPg ){ 40730 - for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev); 40731 - } 40732 - if( pPg ){ 40733 - int rc; 41091 + if( sqlite3PcachePagecount(pCache)>pCache->szSpill ){ 41092 + /* Find a dirty page to write-out and recycle. First try to find a 41093 + ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC 41094 + ** cleared), but if that is not possible settle for any other 41095 + ** unreferenced dirty page. 41096 + */ 41097 + for(pPg=pCache->pSynced; 41098 + pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC)); 41099 + pPg=pPg->pDirtyPrev 41100 + ); 41101 + pCache->pSynced = pPg; 41102 + if( !pPg ){ 41103 + for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev); 41104 + } 41105 + if( pPg ){ 41106 + int rc; 40734 41107 #ifdef SQLITE_LOG_CACHE_SPILL 40735 - sqlite3_log(SQLITE_FULL, 40736 - "spill page %d making room for %d - cache used: %d/%d", 40737 - pPg->pgno, pgno, 40738 - sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache), 41108 + sqlite3_log(SQLITE_FULL, 41109 + "spill page %d making room for %d - cache used: %d/%d", 41110 + pPg->pgno, pgno, 41111 + sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache), 40739 41112 numberOfCachePages(pCache)); 40740 41113 #endif 40741 - rc = pCache->xStress(pCache->pStress, pPg); 40742 - if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){ 40743 - return rc; 41114 + rc = pCache->xStress(pCache->pStress, pPg); 41115 + if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){ 41116 + return rc; 41117 + } 40744 41118 } 40745 41119 } 40746 41120 *ppPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, 2); 40747 41121 return *ppPage==0 ? SQLITE_NOMEM : SQLITE_OK; 40748 41122 } 40749 41123 40750 41124 /* ................................................................................ 41080 41454 */ 41081 41455 SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage){ 41082 41456 assert( pCache->pCache!=0 ); 41083 41457 pCache->szCache = mxPage; 41084 41458 sqlite3GlobalConfig.pcache2.xCachesize(pCache->pCache, 41085 41459 numberOfCachePages(pCache)); 41086 41460 } 41461 + 41462 +/* 41463 +** Set the suggested cache-spill value. Make no changes if if the 41464 +** argument is zero. Return the effective cache-spill size, which will 41465 +** be the larger of the szSpill and szCache. 41466 +*/ 41467 +SQLITE_PRIVATE int sqlite3PcacheSetSpillsize(PCache *p, int mxPage){ 41468 + int res; 41469 + assert( p->pCache!=0 ); 41470 + if( mxPage ){ 41471 + if( mxPage<0 ){ 41472 + mxPage = (int)((-1024*(i64)mxPage)/(p->szPage+p->szExtra)); 41473 + } 41474 + p->szSpill = mxPage; 41475 + } 41476 + res = numberOfCachePages(p); 41477 + if( res<p->szSpill ) res = p->szSpill; 41478 + return res; 41479 +} 41087 41480 41088 41481 /* 41089 41482 ** Free up as much memory as possible from the page cache. 41090 41483 */ 41091 41484 SQLITE_PRIVATE void sqlite3PcacheShrink(PCache *pCache){ 41092 41485 assert( pCache->pCache!=0 ); 41093 41486 sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache); ................................................................................ 41179 41572 ** SQLITE_CONFIG_PAGECACHE. 41180 41573 ** (3) PCache-local bulk allocation. 41181 41574 ** 41182 41575 ** The third case is a chunk of heap memory (defaulting to 100 pages worth) 41183 41576 ** that is allocated when the page cache is created. The size of the local 41184 41577 ** bulk allocation can be adjusted using 41185 41578 ** 41186 -** sqlite3_config(SQLITE_CONFIG_PAGECACHE, 0, 0, N). 41579 +** sqlite3_config(SQLITE_CONFIG_PAGECACHE, (void*)0, 0, N). 41187 41580 ** 41188 41581 ** If N is positive, then N pages worth of memory are allocated using a single 41189 41582 ** sqlite3Malloc() call and that memory is used for the first N pages allocated. 41190 41583 ** Or if N is negative, then -1024*N bytes of memory are allocated and used 41191 41584 ** for as many pages as can be accomodated. 41192 41585 ** 41193 41586 ** Only one of (2) or (3) can be used. Once the memory available to (2) or ................................................................................ 41434 41827 sqlite3_mutex_enter(pcache1.mutex); 41435 41828 p = (PgHdr1 *)pcache1.pFree; 41436 41829 if( p ){ 41437 41830 pcache1.pFree = pcache1.pFree->pNext; 41438 41831 pcache1.nFreeSlot--; 41439 41832 pcache1.bUnderPressure = pcache1.nFreeSlot<pcache1.nReserve; 41440 41833 assert( pcache1.nFreeSlot>=0 ); 41441 - sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte); 41834 + sqlite3StatusHighwater(SQLITE_STATUS_PAGECACHE_SIZE, nByte); 41442 41835 sqlite3StatusUp(SQLITE_STATUS_PAGECACHE_USED, 1); 41443 41836 } 41444 41837 sqlite3_mutex_leave(pcache1.mutex); 41445 41838 } 41446 41839 if( p==0 ){ 41447 41840 /* Memory is not available in the SQLITE_CONFIG_PAGECACHE pool. Get 41448 41841 ** it from sqlite3Malloc instead. 41449 41842 */ 41450 41843 p = sqlite3Malloc(nByte); 41451 41844 #ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS 41452 41845 if( p ){ 41453 41846 int sz = sqlite3MallocSize(p); 41454 41847 sqlite3_mutex_enter(pcache1.mutex); 41455 - sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte); 41848 + sqlite3StatusHighwater(SQLITE_STATUS_PAGECACHE_SIZE, nByte); 41456 41849 sqlite3StatusUp(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz); 41457 41850 sqlite3_mutex_leave(pcache1.mutex); 41458 41851 } 41459 41852 #endif 41460 41853 sqlite3MemdebugSetType(p, MEMTYPE_PCACHE); 41461 41854 } 41462 41855 return p; ................................................................................ 41464 41857 41465 41858 /* 41466 41859 ** Free an allocated buffer obtained from pcache1Alloc(). 41467 41860 */ 41468 41861 static void pcache1Free(void *p){ 41469 41862 int nFreed = 0; 41470 41863 if( p==0 ) return; 41471 - if( p>=pcache1.pStart && p<pcache1.pEnd ){ 41864 + if( SQLITE_WITHIN(p, pcache1.pStart, pcache1.pEnd) ){ 41472 41865 PgFreeslot *pSlot; 41473 41866 sqlite3_mutex_enter(pcache1.mutex); 41474 41867 sqlite3StatusDown(SQLITE_STATUS_PAGECACHE_USED, 1); 41475 41868 pSlot = (PgFreeslot*)p; 41476 41869 pSlot->pNext = pcache1.pFree; 41477 41870 pcache1.pFree = pSlot; 41478 41871 pcache1.nFreeSlot++; ................................................................................ 43012 43405 SQLITE_PRIVATE int sqlite3WalExclusiveMode(Wal *pWal, int op); 43013 43406 43014 43407 /* Return true if the argument is non-NULL and the WAL module is using 43015 43408 ** heap-memory for the wal-index. Otherwise, if the argument is NULL or the 43016 43409 ** WAL module is using shared-memory, return false. 43017 43410 */ 43018 43411 SQLITE_PRIVATE int sqlite3WalHeapMemory(Wal *pWal); 43412 + 43413 +#ifdef SQLITE_ENABLE_SNAPSHOT 43414 +SQLITE_PRIVATE int sqlite3WalSnapshotGet(Wal *pWal, sqlite3_snapshot **ppSnapshot); 43415 +SQLITE_PRIVATE void sqlite3WalSnapshotOpen(Wal *pWal, sqlite3_snapshot *pSnapshot); 43416 +#endif 43019 43417 43020 43418 #ifdef SQLITE_ENABLE_ZIPVFS 43021 43419 /* If the WAL file is not empty, return the number of bytes of content 43022 43420 ** stored in each frame (i.e. the db page-size when the WAL was created). 43023 43421 */ 43024 43422 SQLITE_PRIVATE int sqlite3WalFramesize(Wal *pWal); 43025 43423 #endif ................................................................................ 45337 45735 ** the data just read from the sub-journal. Mark the page as dirty 45338 45736 ** and if the pager requires a journal-sync, then mark the page as 45339 45737 ** requiring a journal-sync before it is written. 45340 45738 */ 45341 45739 assert( isSavepnt ); 45342 45740 assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)==0 ); 45343 45741 pPager->doNotSpill |= SPILLFLAG_ROLLBACK; 45344 - rc = sqlite3PagerAcquire(pPager, pgno, &pPg, 1); 45742 + rc = sqlite3PagerGet(pPager, pgno, &pPg, 1); 45345 45743 assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)!=0 ); 45346 45744 pPager->doNotSpill &= ~SPILLFLAG_ROLLBACK; 45347 45745 if( rc!=SQLITE_OK ) return rc; 45348 45746 pPg->flags &= ~PGHDR_NEED_READ; 45349 45747 sqlite3PcacheMakeDirty(pPg); 45350 45748 } 45351 45749 if( pPg ){ ................................................................................ 46396 46794 pPager->journalOff = szJ; 46397 46795 } 46398 46796 46399 46797 return rc; 46400 46798 } 46401 46799 46402 46800 /* 46403 -** Change the maximum number of in-memory pages that are allowed. 46801 +** Change the maximum number of in-memory pages that are allowed 46802 +** before attempting to recycle clean and unused pages. 46404 46803 */ 46405 46804 SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager *pPager, int mxPage){ 46406 46805 sqlite3PcacheSetCachesize(pPager->pPCache, mxPage); 46407 46806 } 46807 + 46808 +/* 46809 +** Change the maximum number of in-memory pages that are allowed 46810 +** before attempting to spill pages to journal. 46811 +*/ 46812 +SQLITE_PRIVATE int sqlite3PagerSetSpillsize(Pager *pPager, int mxPage){ 46813 + return sqlite3PcacheSetSpillsize(pPager->pPCache, mxPage); 46814 +} 46408 46815 46409 46816 /* 46410 46817 ** Invoke SQLITE_FCNTL_MMAP_SIZE based on the current value of szMmap. 46411 46818 */ 46412 46819 static void pagerFixMaplimit(Pager *pPager){ 46413 46820 #if SQLITE_MAX_MMAP_SIZE>0 46414 46821 sqlite3_file *fd = pPager->fd; ................................................................................ 47477 47884 PAGERTRACE(("STRESS %d page %d\n", PAGERID(pPager), pPg->pgno)); 47478 47885 sqlite3PcacheMakeClean(pPg); 47479 47886 } 47480 47887 47481 47888 return pager_error(pPager, rc); 47482 47889 } 47483 47890 47891 +/* 47892 +** Flush all unreferenced dirty pages to disk. 47893 +*/ 47894 +SQLITE_PRIVATE int sqlite3PagerFlush(Pager *pPager){ 47895 + int rc = pPager->errCode; 47896 + if( !MEMDB ){ 47897 + PgHdr *pList = sqlite3PcacheDirtyList(pPager->pPCache); 47898 + assert( assert_pager_state(pPager) ); 47899 + while( rc==SQLITE_OK && pList ){ 47900 + PgHdr *pNext = pList->pDirty; 47901 + if( pList->nRef==0 ){ 47902 + rc = pagerStress((void*)pPager, pList); 47903 + } 47904 + pList = pNext; 47905 + } 47906 + } 47907 + 47908 + return rc; 47909 +} 47484 47910 47485 47911 /* 47486 47912 ** Allocate and initialize a new Pager object and put a pointer to it 47487 47913 ** in *ppPager. The pager should eventually be freed by passing it 47488 47914 ** to sqlite3PagerClose(). 47489 47915 ** 47490 47916 ** The zFilename argument is the path to the database file to open. ................................................................................ 47954 48380 } 47955 48381 47956 48382 return rc; 47957 48383 } 47958 48384 47959 48385 /* 47960 48386 ** This function is called to obtain a shared lock on the database file. 47961 -** It is illegal to call sqlite3PagerAcquire() until after this function 48387 +** It is illegal to call sqlite3PagerGet() until after this function 47962 48388 ** has been successfully called. If a shared-lock is already held when 47963 48389 ** this function is called, it is a no-op. 47964 48390 ** 47965 48391 ** The following operations are also performed by this function. 47966 48392 ** 47967 48393 ** 1) If the pager is currently in PAGER_OPEN state (no lock held 47968 48394 ** on the database file), then an attempt is made to obtain a ................................................................................ 48257 48683 ** to find a page in the in-memory cache first. If the page is not already 48258 48684 ** in memory, this routine goes to disk to read it in whereas Lookup() 48259 48685 ** just returns 0. This routine acquires a read-lock the first time it 48260 48686 ** has to go to disk, and could also playback an old journal if necessary. 48261 48687 ** Since Lookup() never goes to disk, it never has to deal with locks 48262 48688 ** or journal files. 48263 48689 */ 48264 -SQLITE_PRIVATE int sqlite3PagerAcquire( 48690 +SQLITE_PRIVATE int sqlite3PagerGet( 48265 48691 Pager *pPager, /* The pager open on the database file */ 48266 48692 Pgno pgno, /* Page number to fetch */ 48267 48693 DbPage **ppPage, /* Write a pointer to the page here */ 48268 48694 int flags /* PAGER_GET_XXX flags */ 48269 48695 ){ 48270 48696 int rc = SQLITE_OK; 48271 48697 PgHdr *pPg = 0; ................................................................................ 48843 49269 assert((pg1+nPage)>pPg->pgno); 48844 49270 48845 49271 for(ii=0; ii<nPage && rc==SQLITE_OK; ii++){ 48846 49272 Pgno pg = pg1+ii; 48847 49273 PgHdr *pPage; 48848 49274 if( pg==pPg->pgno || !sqlite3BitvecTest(pPager->pInJournal, pg) ){ 48849 49275 if( pg!=PAGER_MJ_PGNO(pPager) ){ 48850 - rc = sqlite3PagerGet(pPager, pg, &pPage); 49276 + rc = sqlite3PagerGet(pPager, pg, &pPage, 0); 48851 49277 if( rc==SQLITE_OK ){ 48852 49278 rc = pager_write(pPage); 48853 49279 if( pPage->flags&PGHDR_NEED_SYNC ){ 48854 49280 needSync = 1; 48855 49281 } 48856 49282 sqlite3PagerUnrefNotNull(pPage); 48857 49283 } ................................................................................ 48900 49326 ** If an error occurs, SQLITE_NOMEM or an IO error code is returned 48901 49327 ** as appropriate. Otherwise, SQLITE_OK. 48902 49328 */ 48903 49329 SQLITE_PRIVATE int sqlite3PagerWrite(PgHdr *pPg){ 48904 49330 Pager *pPager = pPg->pPager; 48905 49331 assert( (pPg->flags & PGHDR_MMAP)==0 ); 48906 49332 assert( pPager->eState>=PAGER_WRITER_LOCKED ); 48907 - assert( pPager->eState!=PAGER_ERROR ); 48908 49333 assert( assert_pager_state(pPager) ); 48909 - if( (pPg->flags & PGHDR_WRITEABLE)!=0 && pPager->dbSize>=pPg->pgno ){ 49334 + if( pPager->errCode ){ 49335 + return pPager->errCode; 49336 + }else if( (pPg->flags & PGHDR_WRITEABLE)!=0 && pPager->dbSize>=pPg->pgno ){ 48910 49337 if( pPager->nSavepoint ) return subjournalPageIfRequired(pPg); 48911 49338 return SQLITE_OK; 48912 49339 }else if( pPager->sectorSize > (u32)pPager->pageSize ){ 48913 49340 return pagerWriteLargeSector(pPg); 48914 49341 }else{ 48915 49342 return pager_write(pPg); 48916 49343 } ................................................................................ 49002 49429 49003 49430 if( !pPager->changeCountDone && ALWAYS(pPager->dbSize>0) ){ 49004 49431 PgHdr *pPgHdr; /* Reference to page 1 */ 49005 49432 49006 49433 assert( !pPager->tempFile && isOpen(pPager->fd) ); 49007 49434 49008 49435 /* Open page 1 of the file for writing. */ 49009 - rc = sqlite3PagerGet(pPager, 1, &pPgHdr); 49436 + rc = sqlite3PagerGet(pPager, 1, &pPgHdr, 0); 49010 49437 assert( pPgHdr==0 || rc==SQLITE_OK ); 49011 49438 49012 49439 /* If page one was fetched successfully, and this function is not 49013 49440 ** operating in direct-mode, make page 1 writable. When not in 49014 49441 ** direct mode, page 1 is always held in cache and hence the PagerGet() 49015 49442 ** above is always successful - hence the ALWAYS on rc==SQLITE_OK. 49016 49443 */ ................................................................................ 49080 49507 ** 49081 49508 ** If the EXCLUSIVE lock is already held or the attempt to obtain it is 49082 49509 ** successful, or the connection is in WAL mode, SQLITE_OK is returned. 49083 49510 ** Otherwise, either SQLITE_BUSY or an SQLITE_IOERR_XXX error code is 49084 49511 ** returned. 49085 49512 */ 49086 49513 SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager *pPager){ 49087 - int rc = SQLITE_OK; 49088 - assert( pPager->eState==PAGER_WRITER_CACHEMOD 49089 - || pPager->eState==PAGER_WRITER_DBMOD 49090 - || pPager->eState==PAGER_WRITER_LOCKED 49091 - ); 49514 + int rc = pPager->errCode; 49092 49515 assert( assert_pager_state(pPager) ); 49093 - if( 0==pagerUseWal(pPager) ){ 49094 - rc = pager_wait_on_lock(pPager, EXCLUSIVE_LOCK); 49516 + if( rc==SQLITE_OK ){ 49517 + assert( pPager->eState==PAGER_WRITER_CACHEMOD 49518 + || pPager->eState==PAGER_WRITER_DBMOD 49519 + || pPager->eState==PAGER_WRITER_LOCKED 49520 + ); 49521 + assert( assert_pager_state(pPager) ); 49522 + if( 0==pagerUseWal(pPager) ){ 49523 + rc = pager_wait_on_lock(pPager, EXCLUSIVE_LOCK); 49524 + } 49095 49525 } 49096 49526 return rc; 49097 49527 } 49098 49528 49099 49529 /* 49100 49530 ** Sync the database file for the pager pPager. zMaster points to the name 49101 49531 ** of a master journal file that should be written into the individual ................................................................................ 49154 49584 }else{ 49155 49585 if( pagerUseWal(pPager) ){ 49156 49586 PgHdr *pList = sqlite3PcacheDirtyList(pPager->pPCache); 49157 49587 PgHdr *pPageOne = 0; 49158 49588 if( pList==0 ){ 49159 49589 /* Must have at least one page for the WAL commit flag. 49160 49590 ** Ticket [2d1a5c67dfc2363e44f29d9bbd57f] 2011-05-18 */ 49161 - rc = sqlite3PagerGet(pPager, 1, &pPageOne); 49591 + rc = sqlite3PagerGet(pPager, 1, &pPageOne, 0); 49162 49592 pList = pPageOne; 49163 49593 pList->pDirty = 0; 49164 49594 } 49165 49595 assert( rc==SQLITE_OK ); 49166 49596 if( ALWAYS(pList) ){ 49167 49597 rc = pagerWalFrames(pPager, pList, pPager->dbSize, 1); 49168 49598 } ................................................................................ 49651 50081 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager *pPager, int nullIfMemDb){ 49652 50082 return (nullIfMemDb && pPager->memDb) ? "" : pPager->zFilename; 49653 50083 } 49654 50084 49655 50085 /* 49656 50086 ** Return the VFS structure for the pager. 49657 50087 */ 49658 -SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager *pPager){ 50088 +SQLITE_PRIVATE sqlite3_vfs *sqlite3PagerVfs(Pager *pPager){ 49659 50089 return pPager->pVfs; 49660 50090 } 49661 50091 49662 50092 /* 49663 50093 ** Return the file handle for the database file associated 49664 50094 ** with the pager. This might return NULL if the file has 49665 50095 ** not yet been opened. ................................................................................ 49859 50289 ** to a malloc() or IO failure), clear the bit in the pInJournal[] 49860 50290 ** array. Otherwise, if the page is loaded and written again in 49861 50291 ** this transaction, it may be written to the database file before 49862 50292 ** it is synced into the journal file. This way, it may end up in 49863 50293 ** the journal file twice, but that is not a problem. 49864 50294 */ 49865 50295 PgHdr *pPgHdr; 49866 - rc = sqlite3PagerGet(pPager, needSyncPgno, &pPgHdr); 50296 + rc = sqlite3PagerGet(pPager, needSyncPgno, &pPgHdr, 0); 49867 50297 if( rc!=SQLITE_OK ){ 49868 50298 if( needSyncPgno<=pPager->dbOrigSize ){ 49869 50299 assert( pPager->pTmpSpace!=0 ); 49870 50300 sqlite3BitvecClear(pPager->pInJournal, needSyncPgno, pPager->pTmpSpace); 49871 50301 } 49872 50302 return rc; 49873 50303 } ................................................................................ 50273 50703 pPager->pWal = 0; 50274 50704 pagerFixMaplimit(pPager); 50275 50705 } 50276 50706 } 50277 50707 return rc; 50278 50708 } 50279 50709 50710 +#ifdef SQLITE_ENABLE_SNAPSHOT 50711 +/* 50712 +** If this is a WAL database, obtain a snapshot handle for the snapshot 50713 +** currently open. Otherwise, return an error. 50714 +*/ 50715 +SQLITE_PRIVATE int sqlite3PagerSnapshotGet(Pager *pPager, sqlite3_snapshot **ppSnapshot){ 50716 + int rc = SQLITE_ERROR; 50717 + if( pPager->pWal ){ 50718 + rc = sqlite3WalSnapshotGet(pPager->pWal, ppSnapshot); 50719 + } 50720 + return rc; 50721 +} 50722 + 50723 +/* 50724 +** If this is a WAL database, store a pointer to pSnapshot. Next time a 50725 +** read transaction is opened, attempt to read from the snapshot it 50726 +** identifies. If this is not a WAL database, return an error. 50727 +*/ 50728 +SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *pSnapshot){ 50729 + int rc = SQLITE_OK; 50730 + if( pPager->pWal ){ 50731 + sqlite3WalSnapshotOpen(pPager->pWal, pSnapshot); 50732 + }else{ 50733 + rc = SQLITE_ERROR; 50734 + } 50735 + return rc; 50736 +} 50737 +#endif /* SQLITE_ENABLE_SNAPSHOT */ 50280 50738 #endif /* !SQLITE_OMIT_WAL */ 50281 50739 50282 50740 #ifdef SQLITE_ENABLE_ZIPVFS 50283 50741 /* 50284 50742 ** A read-lock must be held on the pager when this function is called. If 50285 50743 ** the pager is in WAL mode and the WAL file currently contains one or more 50286 50744 ** frames, return the size in bytes of the page images stored within the ................................................................................ 50568 51026 ** returns SQLITE_CANTOPEN. 50569 51027 */ 50570 51028 #define WAL_MAX_VERSION 3007000 50571 51029 #define WALINDEX_MAX_VERSION 3007000 50572 51030 50573 51031 /* 50574 51032 ** Indices of various locking bytes. WAL_NREADER is the number 50575 -** of available reader locks and should be at least 3. 51033 +** of available reader locks and should be at least 3. The default 51034 +** is SQLITE_SHM_NLOCK==8 and WAL_NREADER==5. 50576 51035 */ 50577 51036 #define WAL_WRITE_LOCK 0 50578 51037 #define WAL_ALL_BUT_WRITE 1 50579 51038 #define WAL_CKPT_LOCK 1 50580 51039 #define WAL_RECOVER_LOCK 2 50581 51040 #define WAL_READ_LOCK(I) (3+(I)) 50582 51041 #define WAL_NREADER (SQLITE_SHM_NLOCK-3) ................................................................................ 50588 51047 typedef struct WalCkptInfo WalCkptInfo; 50589 51048 50590 51049 50591 51050 /* 50592 51051 ** The following object holds a copy of the wal-index header content. 50593 51052 ** 50594 51053 ** The actual header in the wal-index consists of two copies of this 50595 -** object. 51054 +** object followed by one instance of the WalCkptInfo object. 51055 +** For all versions of SQLite through 3.10.0 and probably beyond, 51056 +** the locking bytes (WalCkptInfo.aLock) start at offset 120 and 51057 +** the total header size is 136 bytes. 50596 51058 ** 50597 51059 ** The szPage value can be any power of 2 between 512 and 32768, inclusive. 50598 51060 ** Or it can be 1 to represent a 65536-byte page. The latter case was 50599 51061 ** added in 3.7.1 when support for 64K pages was added. 50600 51062 */ 50601 51063 struct WalIndexHdr { 50602 51064 u32 iVersion; /* Wal-index version */ ................................................................................ 50620 51082 ** nBackfill is the number of frames in the WAL that have been written 50621 51083 ** back into the database. (We call the act of moving content from WAL to 50622 51084 ** database "backfilling".) The nBackfill number is never greater than 50623 51085 ** WalIndexHdr.mxFrame. nBackfill can only be increased by threads 50624 51086 ** holding the WAL_CKPT_LOCK lock (which includes a recovery thread). 50625 51087 ** However, a WAL_WRITE_LOCK thread can move the value of nBackfill from 50626 51088 ** mxFrame back to zero when the WAL is reset. 51089 +** 51090 +** nBackfillAttempted is the largest value of nBackfill that a checkpoint 51091 +** has attempted to achieve. Normally nBackfill==nBackfillAtempted, however 51092 +** the nBackfillAttempted is set before any backfilling is done and the 51093 +** nBackfill is only set after all backfilling completes. So if a checkpoint 51094 +** crashes, nBackfillAttempted might be larger than nBackfill. The 51095 +** WalIndexHdr.mxFrame must never be less than nBackfillAttempted. 51096 +** 51097 +** The aLock[] field is a set of bytes used for locking. These bytes should 51098 +** never be read or written. 50627 51099 ** 50628 51100 ** There is one entry in aReadMark[] for each reader lock. If a reader 50629 51101 ** holds read-lock K, then the value in aReadMark[K] is no greater than 50630 51102 ** the mxFrame for that reader. The value READMARK_NOT_USED (0xffffffff) 50631 51103 ** for any aReadMark[] means that entry is unused. aReadMark[0] is 50632 51104 ** a special case; its value is never used and it exists as a place-holder 50633 51105 ** to avoid having to offset aReadMark[] indexs by one. Readers holding ................................................................................ 50660 51132 ** 50661 51133 ** We assume that 32-bit loads are atomic and so no locks are needed in 50662 51134 ** order to read from any aReadMark[] entries. 50663 51135 */ 50664 51136 struct WalCkptInfo { 50665 51137 u32 nBackfill; /* Number of WAL frames backfilled into DB */ 50666 51138 u32 aReadMark[WAL_NREADER]; /* Reader marks */ 51139 + u8 aLock[SQLITE_SHM_NLOCK]; /* Reserved space for locks */ 51140 + u32 nBackfillAttempted; /* WAL frames perhaps written, or maybe not */ 51141 + u32 notUsed0; /* Available for future enhancements */ 50667 51142 }; 50668 51143 #define READMARK_NOT_USED 0xffffffff 50669 51144 50670 51145 50671 51146 /* A block of WALINDEX_LOCK_RESERVED bytes beginning at 50672 51147 ** WALINDEX_LOCK_OFFSET is reserved for locks. Since some systems 50673 51148 ** only support mandatory file-locks, we do not read or write data 50674 51149 ** from the region of the file on which locks are applied. 50675 51150 */ 50676 -#define WALINDEX_LOCK_OFFSET (sizeof(WalIndexHdr)*2 + sizeof(WalCkptInfo)) 50677 -#define WALINDEX_LOCK_RESERVED 16 50678 -#define WALINDEX_HDR_SIZE (WALINDEX_LOCK_OFFSET+WALINDEX_LOCK_RESERVED) 51151 +#define WALINDEX_LOCK_OFFSET (sizeof(WalIndexHdr)*2+offsetof(WalCkptInfo,aLock)) 51152 +#define WALINDEX_HDR_SIZE (sizeof(WalIndexHdr)*2+sizeof(WalCkptInfo)) 50679 51153 50680 51154 /* Size of header before each frame in wal */ 50681 51155 #define WAL_FRAME_HDRSIZE 24 50682 51156 50683 51157 /* Size of write ahead log header, including checksum. */ 50684 51158 /* #define WAL_HDRSIZE 24 */ 50685 51159 #define WAL_HDRSIZE 32 ................................................................................ 50730 51204 WalIndexHdr hdr; /* Wal-index header for current transaction */ 50731 51205 u32 minFrame; /* Ignore wal frames before this one */ 50732 51206 const char *zWalName; /* Name of WAL file */ 50733 51207 u32 nCkpt; /* Checkpoint sequence counter in the wal-header */ 50734 51208 #ifdef SQLITE_DEBUG 50735 51209 u8 lockError; /* True if a locking error has occurred */ 50736 51210 #endif 51211 +#ifdef SQLITE_ENABLE_SNAPSHOT 51212 + WalIndexHdr *pSnapshot; /* Start transaction here if not NULL */ 51213 +#endif 50737 51214 }; 50738 51215 50739 51216 /* 50740 51217 ** Candidate values for Wal.exclusiveMode. 50741 51218 */ 50742 51219 #define WAL_NORMAL_MODE 0 50743 51220 #define WAL_EXCLUSIVE_MODE 1 ................................................................................ 51085 51562 } 51086 51563 static void walUnlockShared(Wal *pWal, int lockIdx){ 51087 51564 if( pWal->exclusiveMode ) return; 51088 51565 (void)sqlite3OsShmLock(pWal->pDbFd, lockIdx, 1, 51089 51566 SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED); 51090 51567 WALTRACE(("WAL%p: release SHARED-%s\n", pWal, walLockName(lockIdx))); 51091 51568 } 51092 -static int walLockExclusive(Wal *pWal, int lockIdx, int n, int fBlock){ 51569 +static int walLockExclusive(Wal *pWal, int lockIdx, int n){ 51093 51570 int rc; 51094 51571 if( pWal->exclusiveMode ) return SQLITE_OK; 51095 - if( fBlock ) sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_WAL_BLOCK, 0); 51096 51572 rc = sqlite3OsShmLock(pWal->pDbFd, lockIdx, n, 51097 51573 SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE); 51098 51574 WALTRACE(("WAL%p: acquire EXCLUSIVE-%s cnt=%d %s\n", pWal, 51099 51575 walLockName(lockIdx), n, rc ? "failed" : "ok")); 51100 51576 VVA_ONLY( pWal->lockError = (u8)(rc!=SQLITE_OK && rc!=SQLITE_BUSY); ) 51101 51577 return rc; 51102 51578 } ................................................................................ 51374 51850 */ 51375 51851 assert( pWal->ckptLock==1 || pWal->ckptLock==0 ); 51376 51852 assert( WAL_ALL_BUT_WRITE==WAL_WRITE_LOCK+1 ); 51377 51853 assert( WAL_CKPT_LOCK==WAL_ALL_BUT_WRITE ); 51378 51854 assert( pWal->writeLock ); 51379 51855 iLock = WAL_ALL_BUT_WRITE + pWal->ckptLock; 51380 51856 nLock = SQLITE_SHM_NLOCK - iLock; 51381 - rc = walLockExclusive(pWal, iLock, nLock, 0); 51857 + rc = walLockExclusive(pWal, iLock, nLock); 51382 51858 if( rc ){ 51383 51859 return rc; 51384 51860 } 51385 51861 WALTRACE(("WAL%p: recovery begin...\n", pWal)); 51386 51862 51387 51863 memset(&pWal->hdr, 0, sizeof(WalIndexHdr)); 51388 51864 ................................................................................ 51495 51971 51496 51972 /* Reset the checkpoint-header. This is safe because this thread is 51497 51973 ** currently holding locks that exclude all other readers, writers and 51498 51974 ** checkpointers. 51499 51975 */ 51500 51976 pInfo = walCkptInfo(pWal); 51501 51977 pInfo->nBackfill = 0; 51978 + pInfo->nBackfillAttempted = pWal->hdr.mxFrame; 51502 51979 pInfo->aReadMark[0] = 0; 51503 51980 for(i=1; i<WAL_NREADER; i++) pInfo->aReadMark[i] = READMARK_NOT_USED; 51504 51981 if( pWal->hdr.mxFrame ) pInfo->aReadMark[1] = pWal->hdr.mxFrame; 51505 51982 51506 51983 /* If more than one frame was recovered from the log file, report an 51507 51984 ** event via sqlite3_log(). This is to help with identifying performance 51508 51985 ** problems caused by applications routinely shutting down without ................................................................................ 51566 52043 51567 52044 assert( zWalName && zWalName[0] ); 51568 52045 assert( pDbFd ); 51569 52046 51570 52047 /* In the amalgamation, the os_unix.c and os_win.c source files come before 51571 52048 ** this source file. Verify that the #defines of the locking byte offsets 51572 52049 ** in os_unix.c and os_win.c agree with the WALINDEX_LOCK_OFFSET value. 52050 + ** For that matter, if the lock offset ever changes from its initial design 52051 + ** value of 120, we need to know that so there is an assert() to check it. 51573 52052 */ 52053 + assert( 120==WALINDEX_LOCK_OFFSET ); 52054 + assert( 136==WALINDEX_HDR_SIZE ); 51574 52055 #ifdef WIN_SHM_BASE 51575 52056 assert( WIN_SHM_BASE==WALINDEX_LOCK_OFFSET ); 51576 52057 #endif 51577 52058 #ifdef UNIX_SHM_BASE 51578 52059 assert( UNIX_SHM_BASE==WALINDEX_LOCK_OFFSET ); 51579 52060 #endif 51580 52061 ................................................................................ 51912 52393 int (*xBusy)(void*), /* Function to call when busy */ 51913 52394 void *pBusyArg, /* Context argument for xBusyHandler */ 51914 52395 int lockIdx, /* Offset of first byte to lock */ 51915 52396 int n /* Number of bytes to lock */ 51916 52397 ){ 51917 52398 int rc; 51918 52399 do { 51919 - rc = walLockExclusive(pWal, lockIdx, n, 0); 52400 + rc = walLockExclusive(pWal, lockIdx, n); 51920 52401 }while( xBusy && rc==SQLITE_BUSY && xBusy(pBusyArg) ); 51921 52402 return rc; 51922 52403 } 51923 52404 51924 52405 /* 51925 52406 ** The cache of the wal-index header must be valid to call this function. 51926 52407 ** Return the page-size in bytes used by the database. ................................................................................ 51952 52433 u32 *aSalt = pWal->hdr.aSalt; /* Big-endian salt values */ 51953 52434 pWal->nCkpt++; 51954 52435 pWal->hdr.mxFrame = 0; 51955 52436 sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0])); 51956 52437 memcpy(&pWal->hdr.aSalt[1], &salt1, 4); 51957 52438 walIndexWriteHdr(pWal); 51958 52439 pInfo->nBackfill = 0; 52440 + pInfo->nBackfillAttempted = 0; 51959 52441 pInfo->aReadMark[1] = 0; 51960 52442 for(i=2; i<WAL_NREADER; i++) pInfo->aReadMark[i] = READMARK_NOT_USED; 51961 52443 assert( pInfo->aReadMark[0]==0 ); 51962 52444 } 51963 52445 51964 52446 /* 51965 52447 ** Copy as much content as we can from the WAL back into the database file ................................................................................ 52060 52542 } 52061 52543 52062 52544 if( pInfo->nBackfill<mxSafeFrame 52063 52545 && (rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(0),1))==SQLITE_OK 52064 52546 ){ 52065 52547 i64 nSize; /* Current size of database file */ 52066 52548 u32 nBackfill = pInfo->nBackfill; 52549 + 52550 + pInfo->nBackfillAttempted = mxSafeFrame; 52067 52551 52068 52552 /* Sync the WAL to disk */ 52069 52553 if( sync_flags ){ 52070 52554 rc = sqlite3OsSync(pWal->pWalFd, sync_flags); 52071 52555 } 52072 52556 52073 52557 /* If the database may grow as a result of this checkpoint, hint ................................................................................ 52353 52837 assert( badHdr==0 || pWal->writeLock==0 ); 52354 52838 if( badHdr ){ 52355 52839 if( pWal->readOnly & WAL_SHM_RDONLY ){ 52356 52840 if( SQLITE_OK==(rc = walLockShared(pWal, WAL_WRITE_LOCK)) ){ 52357 52841 walUnlockShared(pWal, WAL_WRITE_LOCK); 52358 52842 rc = SQLITE_READONLY_RECOVERY; 52359 52843 } 52360 - }else if( SQLITE_OK==(rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1, 1)) ){ 52844 + }else if( SQLITE_OK==(rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1)) ){ 52361 52845 pWal->writeLock = 1; 52362 52846 if( SQLITE_OK==(rc = walIndexPage(pWal, 0, &page0)) ){ 52363 52847 badHdr = walIndexTryHdr(pWal, pChanged); 52364 52848 if( badHdr ){ 52365 52849 /* If the wal-index header is still malformed even while holding 52366 52850 ** a WRITE lock, it can only mean that the header is corrupted and 52367 52851 ** needs to be reconstructed. So run recovery to do exactly that. ................................................................................ 52444 52928 */ 52445 52929 static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int cnt){ 52446 52930 volatile WalCkptInfo *pInfo; /* Checkpoint information in wal-index */ 52447 52931 u32 mxReadMark; /* Largest aReadMark[] value */ 52448 52932 int mxI; /* Index of largest aReadMark[] value */ 52449 52933 int i; /* Loop counter */ 52450 52934 int rc = SQLITE_OK; /* Return code */ 52935 + u32 mxFrame; /* Wal frame to lock to */ 52451 52936 52452 52937 assert( pWal->readLock<0 ); /* Not currently locked */ 52453 52938 52454 52939 /* Take steps to avoid spinning forever if there is a protocol error. 52455 52940 ** 52456 52941 ** Circumstances that cause a RETRY should only last for the briefest 52457 52942 ** instances of time. No I/O or other system calls are done while the ................................................................................ 52507 52992 } 52508 52993 if( rc!=SQLITE_OK ){ 52509 52994 return rc; 52510 52995 } 52511 52996 } 52512 52997 52513 52998 pInfo = walCkptInfo(pWal); 52514 - if( !useWal && pInfo->nBackfill==pWal->hdr.mxFrame ){ 52999 + if( !useWal && pInfo->nBackfill==pWal->hdr.mxFrame 53000 +#ifdef SQLITE_ENABLE_SNAPSHOT 53001 + && (pWal->pSnapshot==0 || pWal->hdr.mxFrame==0 53002 + || 0==memcmp(&pWal->hdr, pWal->pSnapshot, sizeof(WalIndexHdr))) 53003 +#endif 53004 + ){ 52515 53005 /* The WAL has been completely backfilled (or it is empty). 52516 53006 ** and can be safely ignored. 52517 53007 */ 52518 53008 rc = walLockShared(pWal, WAL_READ_LOCK(0)); 52519 53009 walShmBarrier(pWal); 52520 53010 if( rc==SQLITE_OK ){ 52521 53011 if( memcmp((void *)walIndexHdr(pWal), &pWal->hdr, sizeof(WalIndexHdr)) ){ ................................................................................ 52545 53035 /* If we get this far, it means that the reader will want to use 52546 53036 ** the WAL to get at content from recent commits. The job now is 52547 53037 ** to select one of the aReadMark[] entries that is closest to 52548 53038 ** but not exceeding pWal->hdr.mxFrame and lock that entry. 52549 53039 */ 52550 53040 mxReadMark = 0; 52551 53041 mxI = 0; 53042 + mxFrame = pWal->hdr.mxFrame; 53043 +#ifdef SQLITE_ENABLE_SNAPSHOT 53044 + if( pWal->pSnapshot && pWal->pSnapshot->mxFrame<mxFrame ){ 53045 + mxFrame = pWal->pSnapshot->mxFrame; 53046 + } 53047 +#endif 52552 53048 for(i=1; i<WAL_NREADER; i++){ 52553 53049 u32 thisMark = pInfo->aReadMark[i]; 52554 - if( mxReadMark<=thisMark && thisMark<=pWal->hdr.mxFrame ){ 53050 + if( mxReadMark<=thisMark && thisMark<=mxFrame ){ 52555 53051 assert( thisMark!=READMARK_NOT_USED ); 52556 53052 mxReadMark = thisMark; 52557 53053 mxI = i; 52558 53054 } 52559 53055 } 52560 - /* There was once an "if" here. The extra "{" is to preserve indentation. */ 52561 - { 52562 - if( (pWal->readOnly & WAL_SHM_RDONLY)==0 52563 - && (mxReadMark<pWal->hdr.mxFrame || mxI==0) 52564 - ){ 52565 - for(i=1; i<WAL_NREADER; i++){ 52566 - rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1, 0); 52567 - if( rc==SQLITE_OK ){ 52568 - mxReadMark = pInfo->aReadMark[i] = pWal->hdr.mxFrame; 52569 - mxI = i; 52570 - walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1); 52571 - break; 52572 - }else if( rc!=SQLITE_BUSY ){ 52573 - return rc; 52574 - } 52575 - } 52576 - } 52577 - if( mxI==0 ){ 52578 - assert( rc==SQLITE_BUSY || (pWal->readOnly & WAL_SHM_RDONLY)!=0 ); 52579 - return rc==SQLITE_BUSY ? WAL_RETRY : SQLITE_READONLY_CANTLOCK; 52580 - } 52581 - 52582 - rc = walLockShared(pWal, WAL_READ_LOCK(mxI)); 52583 - if( rc ){ 52584 - return rc==SQLITE_BUSY ? WAL_RETRY : rc; 52585 - } 52586 - /* Now that the read-lock has been obtained, check that neither the 52587 - ** value in the aReadMark[] array or the contents of the wal-index 52588 - ** header have changed. 52589 - ** 52590 - ** It is necessary to check that the wal-index header did not change 52591 - ** between the time it was read and when the shared-lock was obtained 52592 - ** on WAL_READ_LOCK(mxI) was obtained to account for the possibility 52593 - ** that the log file may have been wrapped by a writer, or that frames 52594 - ** that occur later in the log than pWal->hdr.mxFrame may have been 52595 - ** copied into the database by a checkpointer. If either of these things 52596 - ** happened, then reading the database with the current value of 52597 - ** pWal->hdr.mxFrame risks reading a corrupted snapshot. So, retry 52598 - ** instead. 52599 - ** 52600 - ** Before checking that the live wal-index header has not changed 52601 - ** since it was read, set Wal.minFrame to the first frame in the wal 52602 - ** file that has not yet been checkpointed. This client will not need 52603 - ** to read any frames earlier than minFrame from the wal file - they 52604 - ** can be safely read directly from the database file. 52605 - ** 52606 - ** Because a ShmBarrier() call is made between taking the copy of 52607 - ** nBackfill and checking that the wal-header in shared-memory still 52608 - ** matches the one cached in pWal->hdr, it is guaranteed that the 52609 - ** checkpointer that set nBackfill was not working with a wal-index 52610 - ** header newer than that cached in pWal->hdr. If it were, that could 52611 - ** cause a problem. The checkpointer could omit to checkpoint 52612 - ** a version of page X that lies before pWal->minFrame (call that version 52613 - ** A) on the basis that there is a newer version (version B) of the same 52614 - ** page later in the wal file. But if version B happens to like past 52615 - ** frame pWal->hdr.mxFrame - then the client would incorrectly assume 52616 - ** that it can read version A from the database file. However, since 52617 - ** we can guarantee that the checkpointer that set nBackfill could not 52618 - ** see any pages past pWal->hdr.mxFrame, this problem does not come up. 52619 - */ 52620 - pWal->minFrame = pInfo->nBackfill+1; 52621 - walShmBarrier(pWal); 52622 - if( pInfo->aReadMark[mxI]!=mxReadMark 52623 - || memcmp((void *)walIndexHdr(pWal), &pWal->hdr, sizeof(WalIndexHdr)) 52624 - ){ 52625 - walUnlockShared(pWal, WAL_READ_LOCK(mxI)); 52626 - return WAL_RETRY; 52627 - }else{ 52628 - assert( mxReadMark<=pWal->hdr.mxFrame ); 52629 - pWal->readLock = (i16)mxI; 52630 - } 53056 + if( (pWal->readOnly & WAL_SHM_RDONLY)==0 53057 + && (mxReadMark<mxFrame || mxI==0) 53058 + ){ 53059 + for(i=1; i<WAL_NREADER; i++){ 53060 + rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1); 53061 + if( rc==SQLITE_OK ){ 53062 + mxReadMark = pInfo->aReadMark[i] = mxFrame; 53063 + mxI = i; 53064 + walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1); 53065 + break; 53066 + }else if( rc!=SQLITE_BUSY ){ 53067 + return rc; 53068 + } 53069 + } 53070 + } 53071 + if( mxI==0 ){ 53072 + assert( rc==SQLITE_BUSY || (pWal->readOnly & WAL_SHM_RDONLY)!=0 ); 53073 + return rc==SQLITE_BUSY ? WAL_RETRY : SQLITE_READONLY_CANTLOCK; 53074 + } 53075 + 53076 + rc = walLockShared(pWal, WAL_READ_LOCK(mxI)); 53077 + if( rc ){ 53078 + return rc==SQLITE_BUSY ? WAL_RETRY : rc; 53079 + } 53080 + /* Now that the read-lock has been obtained, check that neither the 53081 + ** value in the aReadMark[] array or the contents of the wal-index 53082 + ** header have changed. 53083 + ** 53084 + ** It is necessary to check that the wal-index header did not change 53085 + ** between the time it was read and when the shared-lock was obtained 53086 + ** on WAL_READ_LOCK(mxI) was obtained to account for the possibility 53087 + ** that the log file may have been wrapped by a writer, or that frames 53088 + ** that occur later in the log than pWal->hdr.mxFrame may have been 53089 + ** copied into the database by a checkpointer. If either of these things 53090 + ** happened, then reading the database with the current value of 53091 + ** pWal->hdr.mxFrame risks reading a corrupted snapshot. So, retry 53092 + ** instead. 53093 + ** 53094 + ** Before checking that the live wal-index header has not changed 53095 + ** since it was read, set Wal.minFrame to the first frame in the wal 53096 + ** file that has not yet been checkpointed. This client will not need 53097 + ** to read any frames earlier than minFrame from the wal file - they 53098 + ** can be safely read directly from the database file. 53099 + ** 53100 + ** Because a ShmBarrier() call is made between taking the copy of 53101 + ** nBackfill and checking that the wal-header in shared-memory still 53102 + ** matches the one cached in pWal->hdr, it is guaranteed that the 53103 + ** checkpointer that set nBackfill was not working with a wal-index 53104 + ** header newer than that cached in pWal->hdr. If it were, that could 53105 + ** cause a problem. The checkpointer could omit to checkpoint 53106 + ** a version of page X that lies before pWal->minFrame (call that version 53107 + ** A) on the basis that there is a newer version (version B) of the same 53108 + ** page later in the wal file. But if version B happens to like past 53109 + ** frame pWal->hdr.mxFrame - then the client would incorrectly assume 53110 + ** that it can read version A from the database file. However, since 53111 + ** we can guarantee that the checkpointer that set nBackfill could not 53112 + ** see any pages past pWal->hdr.mxFrame, this problem does not come up. 53113 + */ 53114 + pWal->minFrame = pInfo->nBackfill+1; 53115 + walShmBarrier(pWal); 53116 + if( pInfo->aReadMark[mxI]!=mxReadMark 53117 + || memcmp((void *)walIndexHdr(pWal), &pWal->hdr, sizeof(WalIndexHdr)) 53118 + ){ 53119 + walUnlockShared(pWal, WAL_READ_LOCK(mxI)); 53120 + return WAL_RETRY; 53121 + }else{ 53122 + assert( mxReadMark<=pWal->hdr.mxFrame ); 53123 + pWal->readLock = (i16)mxI; 52631 53124 } 52632 53125 return rc; 52633 53126 } 52634 53127 52635 53128 /* 52636 53129 ** Begin a read transaction on the database. 52637 53130 ** ................................................................................ 52646 53139 ** Pager layer will use this to know that is cache is stale and 52647 53140 ** needs to be flushed. 52648 53141 */ 52649 53142 SQLITE_PRIVATE int sqlite3WalBeginReadTransaction(Wal *pWal, int *pChanged){ 52650 53143 int rc; /* Return code */ 52651 53144 int cnt = 0; /* Number of TryBeginRead attempts */ 52652 53145 53146 +#ifdef SQLITE_ENABLE_SNAPSHOT 53147 + int bChanged = 0; 53148 + WalIndexHdr *pSnapshot = pWal->pSnapshot; 53149 + if( pSnapshot && memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){ 53150 + bChanged = 1; 53151 + } 53152 +#endif 53153 + 52653 53154 do{ 52654 53155 rc = walTryBeginRead(pWal, pChanged, 0, ++cnt); 52655 53156 }while( rc==WAL_RETRY ); 52656 53157 testcase( (rc&0xff)==SQLITE_BUSY ); 52657 53158 testcase( (rc&0xff)==SQLITE_IOERR ); 52658 53159 testcase( rc==SQLITE_PROTOCOL ); 52659 53160 testcase( rc==SQLITE_OK ); 53161 + 53162 +#ifdef SQLITE_ENABLE_SNAPSHOT 53163 + if( rc==SQLITE_OK ){ 53164 + if( pSnapshot && memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){ 53165 + /* At this point the client has a lock on an aReadMark[] slot holding 53166 + ** a value equal to or smaller than pSnapshot->mxFrame, but pWal->hdr 53167 + ** is populated with the wal-index header corresponding to the head 53168 + ** of the wal file. Verify that pSnapshot is still valid before 53169 + ** continuing. Reasons why pSnapshot might no longer be valid: 53170 + ** 53171 + ** (1) The WAL file has been reset since the snapshot was taken. 53172 + ** In this case, the salt will have changed. 53173 + ** 53174 + ** (2) A checkpoint as been attempted that wrote frames past 53175 + ** pSnapshot->mxFrame into the database file. Note that the 53176 + ** checkpoint need not have completed for this to cause problems. 53177 + */ 53178 + volatile WalCkptInfo *pInfo = walCkptInfo(pWal); 53179 + 53180 + assert( pWal->readLock>0 || pWal->hdr.mxFrame==0 ); 53181 + assert( pInfo->aReadMark[pWal->readLock]<=pSnapshot->mxFrame ); 53182 + 53183 + /* It is possible that there is a checkpointer thread running 53184 + ** concurrent with this code. If this is the case, it may be that the 53185 + ** checkpointer has already determined that it will checkpoint 53186 + ** snapshot X, where X is later in the wal file than pSnapshot, but 53187 + ** has not yet set the pInfo->nBackfillAttempted variable to indicate 53188 + ** its intent. To avoid the race condition this leads to, ensure that 53189 + ** there is no checkpointer process by taking a shared CKPT lock 53190 + ** before checking pInfo->nBackfillAttempted. */ 53191 + rc = walLockShared(pWal, WAL_CKPT_LOCK); 53192 + 53193 + if( rc==SQLITE_OK ){ 53194 + /* Check that the wal file has not been wrapped. Assuming that it has 53195 + ** not, also check that no checkpointer has attempted to checkpoint any 53196 + ** frames beyond pSnapshot->mxFrame. If either of these conditions are 53197 + ** true, return SQLITE_BUSY_SNAPSHOT. Otherwise, overwrite pWal->hdr 53198 + ** with *pSnapshot and set *pChanged as appropriate for opening the 53199 + ** snapshot. */ 53200 + if( !memcmp(pSnapshot->aSalt, pWal->hdr.aSalt, sizeof(pWal->hdr.aSalt)) 53201 + && pSnapshot->mxFrame>=pInfo->nBackfillAttempted 53202 + ){ 53203 + assert( pWal->readLock>0 ); 53204 + memcpy(&pWal->hdr, pSnapshot, sizeof(WalIndexHdr)); 53205 + *pChanged = bChanged; 53206 + }else{ 53207 + rc = SQLITE_BUSY_SNAPSHOT; 53208 + } 53209 + 53210 + /* Release the shared CKPT lock obtained above. */ 53211 + walUnlockShared(pWal, WAL_CKPT_LOCK); 53212 + } 53213 + 53214 + 53215 + if( rc!=SQLITE_OK ){ 53216 + sqlite3WalEndReadTransaction(pWal); 53217 + } 53218 + } 53219 + } 53220 +#endif 52660 53221 return rc; 52661 53222 } 52662 53223 52663 53224 /* 52664 53225 ** Finish with a read transaction. All this does is release the 52665 53226 ** read-lock. 52666 53227 */ ................................................................................ 52833 53394 if( pWal->readOnly ){ 52834 53395 return SQLITE_READONLY; 52835 53396 } 52836 53397 52837 53398 /* Only one writer allowed at a time. Get the write lock. Return 52838 53399 ** SQLITE_BUSY if unable. 52839 53400 */ 52840 - rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1, 0); 53401 + rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1); 52841 53402 if( rc ){ 52842 53403 return rc; 52843 53404 } 52844 53405 pWal->writeLock = 1; 52845 53406 52846 53407 /* If another connection has written to the database file since the 52847 53408 ** time the read transaction on this connection was started, then ................................................................................ 52978 53539 52979 53540 if( pWal->readLock==0 ){ 52980 53541 volatile WalCkptInfo *pInfo = walCkptInfo(pWal); 52981 53542 assert( pInfo->nBackfill==pWal->hdr.mxFrame ); 52982 53543 if( pInfo->nBackfill>0 ){ 52983 53544 u32 salt1; 52984 53545 sqlite3_randomness(4, &salt1); 52985 - rc = walLockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1, 0); 53546 + rc = walLockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1); 52986 53547 if( rc==SQLITE_OK ){ 52987 53548 /* If all readers are using WAL_READ_LOCK(0) (in other words if no 52988 53549 ** readers are currently using the WAL), then the transactions 52989 53550 ** frames will overwrite the start of the existing log. Update the 52990 53551 ** wal-index header to reflect this. 52991 53552 ** 52992 53553 ** In theory it would be Ok to update the cache of the header only ................................................................................ 53303 53864 assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 ); 53304 53865 53305 53866 if( pWal->readOnly ) return SQLITE_READONLY; 53306 53867 WALTRACE(("WAL%p: checkpoint begins\n", pWal)); 53307 53868 53308 53869 /* IMPLEMENTATION-OF: R-62028-47212 All calls obtain an exclusive 53309 53870 ** "checkpoint" lock on the database file. */ 53310 - rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1, 0); 53871 + rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1); 53311 53872 if( rc ){ 53312 53873 /* EVIDENCE-OF: R-10421-19736 If any other process is running a 53313 53874 ** checkpoint operation at the same time, the lock cannot be obtained and 53314 53875 ** SQLITE_BUSY is returned. 53315 53876 ** EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured, 53316 53877 ** it will not be invoked in this case. 53317 53878 */ ................................................................................ 53462 54023 ** heap-memory for the wal-index. Otherwise, if the argument is NULL or the 53463 54024 ** WAL module is using shared-memory, return false. 53464 54025 */ 53465 54026 SQLITE_PRIVATE int sqlite3WalHeapMemory(Wal *pWal){ 53466 54027 return (pWal && pWal->exclusiveMode==WAL_HEAPMEMORY_MODE ); 53467 54028 } 53468 54029 54030 +#ifdef SQLITE_ENABLE_SNAPSHOT 54031 +/* Create a snapshot object. The content of a snapshot is opaque to 54032 +** every other subsystem, so the WAL module can put whatever it needs 54033 +** in the object. 54034 +*/ 54035 +SQLITE_PRIVATE int sqlite3WalSnapshotGet(Wal *pWal, sqlite3_snapshot **ppSnapshot){ 54036 + int rc = SQLITE_OK; 54037 + WalIndexHdr *pRet; 54038 + 54039 + assert( pWal->readLock>=0 && pWal->writeLock==0 ); 54040 + 54041 + pRet = (WalIndexHdr*)sqlite3_malloc(sizeof(WalIndexHdr)); 54042 + if( pRet==0 ){ 54043 + rc = SQLITE_NOMEM; 54044 + }else{ 54045 + memcpy(pRet, &pWal->hdr, sizeof(WalIndexHdr)); 54046 + *ppSnapshot = (sqlite3_snapshot*)pRet; 54047 + } 54048 + 54049 + return rc; 54050 +} 54051 + 54052 +/* Try to open on pSnapshot when the next read-transaction starts 54053 +*/ 54054 +SQLITE_PRIVATE void sqlite3WalSnapshotOpen(Wal *pWal, sqlite3_snapshot *pSnapshot){ 54055 + pWal->pSnapshot = (WalIndexHdr*)pSnapshot; 54056 +} 54057 +#endif /* SQLITE_ENABLE_SNAPSHOT */ 54058 + 53469 54059 #ifdef SQLITE_ENABLE_ZIPVFS 53470 54060 /* 53471 54061 ** If the argument is not NULL, it points to a Wal object that holds a 53472 54062 ** read-lock. This function returns the database page-size if it is known, 53473 54063 ** or zero if it is not (or if pWal is NULL). 53474 54064 */ 53475 54065 SQLITE_PRIVATE int sqlite3WalFramesize(Wal *pWal){ ................................................................................ 53969 54559 ** based on information extract from the raw disk page. 53970 54560 */ 53971 54561 struct CellInfo { 53972 54562 i64 nKey; /* The key for INTKEY tables, or nPayload otherwise */ 53973 54563 u8 *pPayload; /* Pointer to the start of payload */ 53974 54564 u32 nPayload; /* Bytes of payload */ 53975 54565 u16 nLocal; /* Amount of payload held locally, not on overflow */ 53976 - u16 iOverflow; /* Offset to overflow page number. Zero if no overflow */ 53977 54566 u16 nSize; /* Size of the cell content on the main b-tree page */ 53978 54567 }; 53979 54568 53980 54569 /* 53981 54570 ** Maximum depth of an SQLite B-Tree structure. Any B-Tree deeper than 53982 54571 ** this will be declared corrupt. This value is calculated based on a 53983 54572 ** maximum database size of 2^31 pages a minimum fanout of 2 for a ................................................................................ 54016 54605 i64 nKey; /* Size of pKey, or last integer key */ 54017 54606 void *pKey; /* Saved key that was cursor last known position */ 54018 54607 Pgno pgnoRoot; /* The root page of this tree */ 54019 54608 int nOvflAlloc; /* Allocated size of aOverflow[] array */ 54020 54609 int skipNext; /* Prev() is noop if negative. Next() is noop if positive. 54021 54610 ** Error code if eState==CURSOR_FAULT */ 54022 54611 u8 curFlags; /* zero or more BTCF_* flags defined below */ 54023 - u8 curPagerFlags; /* Flags to send to sqlite3PagerAcquire() */ 54612 + u8 curPagerFlags; /* Flags to send to sqlite3PagerGet() */ 54024 54613 u8 eState; /* One of the CURSOR_XXX constants (see below) */ 54025 54614 u8 hints; /* As configured by CursorSetHints() */ 54026 54615 /* All fields above are zeroed when the cursor is allocated. See 54027 54616 ** sqlite3BtreeCursorZero(). Fields that follow must be manually 54028 54617 ** initialized. */ 54029 54618 i8 iPage; /* Index of current page in apPage */ 54030 54619 u8 curIntKey; /* Value of apPage[0]->intKey */ ................................................................................ 55356 55945 *pDifferentRow = 1; 55357 55946 }else{ 55358 55947 assert( pCur->skipNext==0 ); 55359 55948 *pDifferentRow = 0; 55360 55949 } 55361 55950 return SQLITE_OK; 55362 55951 } 55952 + 55953 +#ifdef SQLITE_ENABLE_CURSOR_HINTS 55954 +/* 55955 +** Provide hints to the cursor. The particular hint given (and the type 55956 +** and number of the varargs parameters) is determined by the eHintType 55957 +** parameter. See the definitions of the BTREE_HINT_* macros for details. 55958 +*/ 55959 +SQLITE_PRIVATE void sqlite3BtreeCursorHint(BtCursor *pCur, int eHintType, ...){ 55960 + /* Used only by system that substitute their own storage engine */ 55961 +} 55962 +#endif 55963 + 55964 +/* 55965 +** Provide flag hints to the cursor. 55966 +*/ 55967 +SQLITE_PRIVATE void sqlite3BtreeCursorHintFlags(BtCursor *pCur, unsigned x){ 55968 + assert( x==BTREE_SEEK_EQ || x==BTREE_BULKLOAD || x==0 ); 55969 + pCur->hints = x; 55970 +} 55971 + 55363 55972 55364 55973 #ifndef SQLITE_OMIT_AUTOVACUUM 55365 55974 /* 55366 55975 ** Given a page number of a regular database page, return the page 55367 55976 ** number for the pointer-map page that contains the entry for the 55368 55977 ** input page number. 55369 55978 ** ................................................................................ 55410 56019 55411 56020 assert( pBt->autoVacuum ); 55412 56021 if( key==0 ){ 55413 56022 *pRC = SQLITE_CORRUPT_BKPT; 55414 56023 return; 55415 56024 } 55416 56025 iPtrmap = PTRMAP_PAGENO(pBt, key); 55417 - rc = sqlite3PagerGet(pBt->pPager, iPtrmap, &pDbPage); 56026 + rc = sqlite3PagerGet(pBt->pPager, iPtrmap, &pDbPage, 0); 55418 56027 if( rc!=SQLITE_OK ){ 55419 56028 *pRC = rc; 55420 56029 return; 55421 56030 } 55422 56031 offset = PTRMAP_PTROFFSET(iPtrmap, key); 55423 56032 if( offset<0 ){ 55424 56033 *pRC = SQLITE_CORRUPT_BKPT; ................................................................................ 55453 56062 u8 *pPtrmap; /* Pointer map page data */ 55454 56063 int offset; /* Offset of entry in pointer map */ 55455 56064 int rc; 55456 56065 55457 56066 assert( sqlite3_mutex_held(pBt->mutex) ); 55458 56067 55459 56068 iPtrmap = PTRMAP_PAGENO(pBt, key); 55460 - rc = sqlite3PagerGet(pBt->pPager, iPtrmap, &pDbPage); 56069 + rc = sqlite3PagerGet(pBt->pPager, iPtrmap, &pDbPage, 0); 55461 56070 if( rc!=0 ){ 55462 56071 return rc; 55463 56072 } 55464 56073 pPtrmap = (u8 *)sqlite3PagerGetData(pDbPage); 55465 56074 55466 56075 offset = PTRMAP_PTROFFSET(iPtrmap, key); 55467 56076 if( offset<0 ){ ................................................................................ 55530 56139 testcase( surplus==maxLocal ); 55531 56140 testcase( surplus==maxLocal+1 ); 55532 56141 if( surplus <= maxLocal ){ 55533 56142 pInfo->nLocal = (u16)surplus; 55534 56143 }else{ 55535 56144 pInfo->nLocal = (u16)minLocal; 55536 56145 } 55537 - pInfo->iOverflow = (u16)(&pInfo->pPayload[pInfo->nLocal] - pCell); 55538 - pInfo->nSize = pInfo->iOverflow + 4; 56146 + pInfo->nSize = (u16)(&pInfo->pPayload[pInfo->nLocal] - pCell) + 4; 55539 56147 } 55540 56148 55541 56149 /* 55542 56150 ** The following routines are implementations of the MemPage.xParseCell() 55543 56151 ** method. 55544 56152 ** 55545 56153 ** Parse a cell content block and fill in the CellInfo structure. ................................................................................ 55563 56171 assert( pPage->childPtrSize==4 ); 55564 56172 #ifndef SQLITE_DEBUG 55565 56173 UNUSED_PARAMETER(pPage); 55566 56174 #endif 55567 56175 pInfo->nSize = 4 + getVarint(&pCell[4], (u64*)&pInfo->nKey); 55568 56176 pInfo->nPayload = 0; 55569 56177 pInfo->nLocal = 0; 55570 - pInfo->iOverflow = 0; 55571 56178 pInfo->pPayload = 0; 55572 56179 return; 55573 56180 } 55574 56181 static void btreeParseCellPtr( 55575 56182 MemPage *pPage, /* Page containing the cell */ 55576 56183 u8 *pCell, /* Pointer to the cell text. */ 55577 56184 CellInfo *pInfo /* Fill in this structure */ ................................................................................ 55633 56240 if( nPayload<=pPage->maxLocal ){ 55634 56241 /* This is the (easy) common case where the entire payload fits 55635 56242 ** on the local page. No overflow is required. 55636 56243 */ 55637 56244 pInfo->nSize = nPayload + (u16)(pIter - pCell); 55638 56245 if( pInfo->nSize<4 ) pInfo->nSize = 4; 55639 56246 pInfo->nLocal = (u16)nPayload; 55640 - pInfo->iOverflow = 0; 55641 56247 }else{ 55642 56248 btreeParseCellAdjustSizeForOverflow(pPage, pCell, pInfo); 55643 56249 } 55644 56250 } 55645 56251 static void btreeParseCellPtrIndex( 55646 56252 MemPage *pPage, /* Page containing the cell */ 55647 56253 u8 *pCell, /* Pointer to the cell text. */ ................................................................................ 55672 56278 if( nPayload<=pPage->maxLocal ){ 55673 56279 /* This is the (easy) common case where the entire payload fits 55674 56280 ** on the local page. No overflow is required. 55675 56281 */ 55676 56282 pInfo->nSize = nPayload + (u16)(pIter - pCell); 55677 56283 if( pInfo->nSize<4 ) pInfo->nSize = 4; 55678 56284 pInfo->nLocal = (u16)nPayload; 55679 - pInfo->iOverflow = 0; 55680 56285 }else{ 55681 56286 btreeParseCellAdjustSizeForOverflow(pPage, pCell, pInfo); 55682 56287 } 55683 56288 } 55684 56289 static void btreeParseCell( 55685 56290 MemPage *pPage, /* Page containing the cell */ 55686 56291 int iCell, /* The cell index. First cell is 0 */ ................................................................................ 55788 56393 ** for the overflow page. 55789 56394 */ 55790 56395 static void ptrmapPutOvflPtr(MemPage *pPage, u8 *pCell, int *pRC){ 55791 56396 CellInfo info; 55792 56397 if( *pRC ) return; 55793 56398 assert( pCell!=0 ); 55794 56399 pPage->xParseCell(pPage, pCell, &info); 55795 - if( info.iOverflow ){ 55796 - Pgno ovfl = get4byte(&pCell[info.iOverflow]); 56400 + if( info.nLocal<info.nPayload ){ 56401 + Pgno ovfl = get4byte(&pCell[info.nSize-4]); 55797 56402 ptrmapPut(pPage->pBt, ovfl, PTRMAP_OVERFLOW1, pPage->pgno, pRC); 55798 56403 } 55799 56404 } 55800 56405 #endif 55801 56406 55802 56407 55803 56408 /* ................................................................................ 56380 56985 56381 56986 /* 56382 56987 ** Convert a DbPage obtained from the pager into a MemPage used by 56383 56988 ** the btree layer. 56384 56989 */ 56385 56990 static MemPage *btreePageFromDbPage(DbPage *pDbPage, Pgno pgno, BtShared *pBt){ 56386 56991 MemPage *pPage = (MemPage*)sqlite3PagerGetExtra(pDbPage); 56387 - pPage->aData = sqlite3PagerGetData(pDbPage); 56388 - pPage->pDbPage = pDbPage; 56389 - pPage->pBt = pBt; 56390 - pPage->pgno = pgno; 56391 - pPage->hdrOffset = pgno==1 ? 100 : 0; 56992 + if( pgno!=pPage->pgno ){ 56993 + pPage->aData = sqlite3PagerGetData(pDbPage); 56994 + pPage->pDbPage = pDbPage; 56995 + pPage->pBt = pBt; 56996 + pPage->pgno = pgno; 56997 + pPage->hdrOffset = pgno==1 ? 100 : 0; 56998 + } 56999 + assert( pPage->aData==sqlite3PagerGetData(pDbPage) ); 56392 57000 return pPage; 56393 57001 } 56394 57002 56395 57003 /* 56396 57004 ** Get a page from the pager. Initialize the MemPage.pBt and 56397 57005 ** MemPage.aData elements if needed. See also: btreeGetUnusedPage(). 56398 57006 ** ................................................................................ 56410 57018 int flags /* PAGER_GET_NOCONTENT or PAGER_GET_READONLY */ 56411 57019 ){ 56412 57020 int rc; 56413 57021 DbPage *pDbPage; 56414 57022 56415 57023 assert( flags==0 || flags==PAGER_GET_NOCONTENT || flags==PAGER_GET_READONLY ); 56416 57024 assert( sqlite3_mutex_held(pBt->mutex) ); 56417 - rc = sqlite3PagerAcquire(pBt->pPager, pgno, (DbPage**)&pDbPage, flags); 57025 + rc = sqlite3PagerGet(pBt->pPager, pgno, (DbPage**)&pDbPage, flags); 56418 57026 if( rc ) return rc; 56419 57027 *ppPage = btreePageFromDbPage(pDbPage, pgno, pBt); 56420 57028 return SQLITE_OK; 56421 57029 } 56422 57030 56423 57031 /* 56424 57032 ** Retrieve a page from the pager cache. If the requested page is not ................................................................................ 56475 57083 assert( pCur==0 || bReadOnly==pCur->curPagerFlags ); 56476 57084 assert( pCur==0 || pCur->iPage>0 ); 56477 57085 56478 57086 if( pgno>btreePagecount(pBt) ){ 56479 57087 rc = SQLITE_CORRUPT_BKPT; 56480 57088 goto getAndInitPage_error; 56481 57089 } 56482 - rc = sqlite3PagerAcquire(pBt->pPager, pgno, (DbPage**)&pDbPage, bReadOnly); 57090 + rc = sqlite3PagerGet(pBt->pPager, pgno, (DbPage**)&pDbPage, bReadOnly); 56483 57091 if( rc ){ 56484 57092 goto getAndInitPage_error; 56485 57093 } 56486 - *ppPage = btreePageFromDbPage(pDbPage, pgno, pBt); 57094 + *ppPage = (MemPage*)sqlite3PagerGetExtra(pDbPage); 56487 57095 if( (*ppPage)->isInit==0 ){ 57096 + btreePageFromDbPage(pDbPage, pgno, pBt); 56488 57097 rc = btreeInitPage(*ppPage); 56489 57098 if( rc!=SQLITE_OK ){ 56490 57099 releasePage(*ppPage); 56491 57100 goto getAndInitPage_error; 56492 57101 } 56493 57102 } 57103 + assert( (*ppPage)->pgno==pgno ); 57104 + assert( (*ppPage)->aData==sqlite3PagerGetData(pDbPage) ); 56494 57105 56495 57106 /* If obtaining a child page for a cursor, we must verify that the page is 56496 57107 ** compatible with the root page. */ 56497 - if( pCur 56498 - && ((*ppPage)->nCell<1 || (*ppPage)->intKey!=pCur->curIntKey) 56499 - ){ 57108 + if( pCur && ((*ppPage)->nCell<1 || (*ppPage)->intKey!=pCur->curIntKey) ){ 56500 57109 rc = SQLITE_CORRUPT_BKPT; 56501 57110 releasePage(*ppPage); 56502 57111 goto getAndInitPage_error; 56503 57112 } 56504 57113 return SQLITE_OK; 56505 57114 56506 57115 getAndInitPage_error: ................................................................................ 57031 57640 #endif 57032 57641 57033 57642 sqlite3_free(p); 57034 57643 return SQLITE_OK; 57035 57644 } 57036 57645 57037 57646 /* 57038 -** Change the limit on the number of pages allowed in the cache. 57039 -** 57040 -** The maximum number of cache pages is set to the absolute 57041 -** value of mxPage. If mxPage is negative, the pager will 57042 -** operate asynchronously - it will not stop to do fsync()s 57043 -** to insure data is written to the disk surface before 57044 -** continuing. Transactions still work if synchronous is off, 57045 -** and the database cannot be corrupted if this program 57046 -** crashes. But if the operating system crashes or there is 57047 -** an abrupt power failure when synchronous is off, the database 57048 -** could be left in an inconsistent and unrecoverable state. 57049 -** Synchronous is on by default so database corruption is not 57050 -** normally a worry. 57647 +** Change the "soft" limit on the number of pages in the cache. 57648 +** Unused and unmodified pages will be recycled when the number of 57649 +** pages in the cache exceeds this soft limit. But the size of the 57650 +** cache is allowed to grow larger than this limit if it contains 57651 +** dirty pages or pages still in active use. 57051 57652 */ 57052 57653 SQLITE_PRIVATE int sqlite3BtreeSetCacheSize(Btree *p, int mxPage){ 57053 57654 BtShared *pBt = p->pBt; 57054 57655 assert( sqlite3_mutex_held(p->db->mutex) ); 57055 57656 sqlite3BtreeEnter(p); 57056 57657 sqlite3PagerSetCachesize(pBt->pPager, mxPage); 57057 57658 sqlite3BtreeLeave(p); 57058 57659 return SQLITE_OK; 57059 57660 } 57661 + 57662 +/* 57663 +** Change the "spill" limit on the number of pages in the cache. 57664 +** If the number of pages exceeds this limit during a write transaction, 57665 +** the pager might attempt to "spill" pages to the journal early in 57666 +** order to free up memory. 57667 +** 57668 +** The value returned is the current spill size. If zero is passed 57669 +** as an argument, no changes are made to the spill size setting, so 57670 +** using mxPage of 0 is a way to query the current spill size. 57671 +*/ 57672 +SQLITE_PRIVATE int sqlite3BtreeSetSpillSize(Btree *p, int mxPage){ 57673 + BtShared *pBt = p->pBt; 57674 + int res; 57675 + assert( sqlite3_mutex_held(p->db->mutex) ); 57676 + sqlite3BtreeEnter(p); 57677 + res = sqlite3PagerSetSpillsize(pBt->pPager, mxPage); 57678 + sqlite3BtreeLeave(p); 57679 + return res; 57680 +} 57060 57681 57061 57682 #if SQLITE_MAX_MMAP_SIZE>0 57062 57683 /* 57063 57684 ** Change the limit on the amount of the database file that may be 57064 57685 ** memory mapped. 57065 57686 */ 57066 57687 SQLITE_PRIVATE int sqlite3BtreeSetMmapLimit(Btree *p, sqlite3_int64 szMmap){ ................................................................................ 57811 58432 nCell = pPage->nCell; 57812 58433 57813 58434 for(i=0; i<nCell; i++){ 57814 58435 u8 *pCell = findCell(pPage, i); 57815 58436 if( eType==PTRMAP_OVERFLOW1 ){ 57816 58437 CellInfo info; 57817 58438 pPage->xParseCell(pPage, pCell, &info); 57818 - if( info.iOverflow 57819 - && pCell+info.iOverflow+3<=pPage->aData+pPage->maskPage 57820 - && iFrom==get4byte(&pCell[info.iOverflow]) 58439 + if( info.nLocal<info.nPayload 58440 + && pCell+info.nSize-1<=pPage->aData+pPage->maskPage 58441 + && iFrom==get4byte(pCell+info.nSize-4) 57821 58442 ){ 57822 - put4byte(&pCell[info.iOverflow], iTo); 58443 + put4byte(pCell+info.nSize-4, iTo); 57823 58444 break; 57824 58445 } 57825 58446 }else{ 57826 58447 if( get4byte(pCell)==iFrom ){ 57827 58448 put4byte(pCell, iTo); 57828 58449 break; 57829 58450 } ................................................................................ 58554 59175 struct KeyInfo *pKeyInfo, /* First arg to comparison function */ 58555 59176 BtCursor *pCur /* Space for new cursor */ 58556 59177 ){ 58557 59178 BtShared *pBt = p->pBt; /* Shared b-tree handle */ 58558 59179 BtCursor *pX; /* Looping over other all cursors */ 58559 59180 58560 59181 assert( sqlite3BtreeHoldsMutex(p) ); 58561 - assert( wrFlag==0 || wrFlag==1 ); 59182 + assert( wrFlag==0 59183 + || wrFlag==BTREE_WRCSR 59184 + || wrFlag==(BTREE_WRCSR|BTREE_FORDELETE) 59185 + ); 58562 59186 58563 59187 /* The following assert statements verify that if this is a sharable 58564 59188 ** b-tree database, the connection is holding the required table locks, 58565 59189 ** and that no other connection has any open cursor that conflicts with 58566 59190 ** this lock. */ 58567 - assert( hasSharedCacheTableLock(p, iTable, pKeyInfo!=0, wrFlag+1) ); 59191 + assert( hasSharedCacheTableLock(p, iTable, pKeyInfo!=0, (wrFlag?2:1)) ); 58568 59192 assert( wrFlag==0 || !hasReadConflicts(p, iTable) ); 58569 59193 58570 59194 /* Assert that the caller has opened the required transaction. */ 58571 59195 assert( p->inTrans>TRANS_NONE ); 58572 59196 assert( wrFlag==0 || p->inTrans==TRANS_WRITE ); 58573 59197 assert( pBt->pPage1 && pBt->pPage1->aData ); 58574 59198 assert( wrFlag==0 || (pBt->btsFlags & BTS_READ_ONLY)==0 ); ................................................................................ 58585 59209 /* Now that no other errors can occur, finish filling in the BtCursor 58586 59210 ** variables and link the cursor into the BtShared list. */ 58587 59211 pCur->pgnoRoot = (Pgno)iTable; 58588 59212 pCur->iPage = -1; 58589 59213 pCur->pKeyInfo = pKeyInfo; 58590 59214 pCur->pBtree = p; 58591 59215 pCur->pBt = pBt; 58592 - assert( wrFlag==0 || wrFlag==BTCF_WriteFlag ); 58593 - pCur->curFlags = wrFlag; 59216 + pCur->curFlags = wrFlag ? BTCF_WriteFlag : 0; 58594 59217 pCur->curPagerFlags = wrFlag ? 0 : PAGER_GET_READONLY; 58595 59218 /* If there are two or more cursors on the same btree, then all such 58596 59219 ** cursors *must* have the BTCF_Multiple flag set. */ 58597 59220 for(pX=pBt->pCursor; pX; pX=pX->pNext){ 58598 59221 if( pX->pgnoRoot==(Pgno)iTable ){ 58599 59222 pX->curFlags |= BTCF_Multiple; 58600 59223 pCur->curFlags |= BTCF_Multiple; ................................................................................ 58998 59621 offset = (offset%ovflSize); 58999 59622 } 59000 59623 59001 59624 for( ; rc==SQLITE_OK && amt>0 && nextPage; iIdx++){ 59002 59625 59003 59626 /* If required, populate the overflow page-list cache. */ 59004 59627 if( (pCur->curFlags & BTCF_ValidOvfl)!=0 ){ 59005 - assert(!pCur->aOverflow[iIdx] || pCur->aOverflow[iIdx]==nextPage); 59628 + assert( pCur->aOverflow[iIdx]==0 59629 + || pCur->aOverflow[iIdx]==nextPage 59630 + || CORRUPT_DB ); 59006 59631 pCur->aOverflow[iIdx] = nextPage; 59007 59632 } 59008 59633 59009 59634 if( offset>=ovflSize ){ 59010 59635 /* The only reason to read this page is to obtain the page 59011 59636 ** number for the next page in the overflow chain. The page 59012 59637 ** data is not required. So first try to lookup the overflow ................................................................................ 59068 59693 nextPage = get4byte(aWrite); 59069 59694 memcpy(aWrite, aSave, 4); 59070 59695 }else 59071 59696 #endif 59072 59697 59073 59698 { 59074 59699 DbPage *pDbPage; 59075 - rc = sqlite3PagerAcquire(pBt->pPager, nextPage, &pDbPage, 59700 + rc = sqlite3PagerGet(pBt->pPager, nextPage, &pDbPage, 59076 59701 ((eOp&0x01)==0 ? PAGER_GET_READONLY : 0) 59077 59702 ); 59078 59703 if( rc==SQLITE_OK ){ 59079 59704 aPayload = sqlite3PagerGetData(pDbPage); 59080 59705 nextPage = get4byte(aPayload); 59081 59706 rc = copyPayload(&aPayload[offset+4], pBuf, a, (eOp&0x01), pDbPage); 59082 59707 sqlite3PagerUnref(pDbPage); ................................................................................ 59512 60137 ** 59513 60138 ** *pRes==0 The cursor is left pointing at an entry that 59514 60139 ** exactly matches intKey/pIdxKey. 59515 60140 ** 59516 60141 ** *pRes>0 The cursor is left pointing at an entry that 59517 60142 ** is larger than intKey/pIdxKey. 59518 60143 ** 60144 +** For index tables, the pIdxKey->eqSeen field is set to 1 if there 60145 +** exists an entry in the table that exactly matches pIdxKey. 59519 60146 */ 59520 60147 SQLITE_PRIVATE int sqlite3BtreeMovetoUnpacked( 59521 60148 BtCursor *pCur, /* The cursor to be moved */ 59522 60149 UnpackedRecord *pIdxKey, /* Unpacked index key */ 59523 60150 i64 intKey, /* The table key */ 59524 60151 int biasRight, /* If true, bias the search to the high end */ 59525 60152 int *pRes /* Write search results here */ ................................................................................ 60451 61078 int rc; 60452 61079 int nOvfl; 60453 61080 u32 ovflPageSize; 60454 61081 60455 61082 assert( sqlite3_mutex_held(pPage->pBt->mutex) ); 60456 61083 pPage->xParseCell(pPage, pCell, &info); 60457 61084 *pnSize = info.nSize; 60458 - if( info.iOverflow==0 ){ 61085 + if( info.nLocal==info.nPayload ){ 60459 61086 return SQLITE_OK; /* No overflow pages. Return without doing anything */ 60460 61087 } 60461 - if( pCell+info.iOverflow+3 > pPage->aData+pPage->maskPage ){ 61088 + if( pCell+info.nSize-1 > pPage->aData+pPage->maskPage ){ 60462 61089 return SQLITE_CORRUPT_BKPT; /* Cell extends past end of page */ 60463 61090 } 60464 - ovflPgno = get4byte(&pCell[info.iOverflow]); 61091 + ovflPgno = get4byte(pCell + info.nSize - 4); 60465 61092 assert( pBt->usableSize > 4 ); 60466 61093 ovflPageSize = pBt->usableSize - 4; 60467 61094 nOvfl = (info.nPayload - info.nLocal + ovflPageSize - 1)/ovflPageSize; 60468 61095 assert( nOvfl>0 || 60469 61096 (CORRUPT_DB && (info.nPayload + ovflPageSize)<ovflPageSize) 60470 61097 ); 60471 61098 while( nOvfl-- ){ ................................................................................ 60606 61233 { 60607 61234 CellInfo info; 60608 61235 pPage->xParseCell(pPage, pCell, &info); 60609 61236 assert( nHeader=(int)(info.pPayload - pCell) ); 60610 61237 assert( info.nKey==nKey ); 60611 61238 assert( *pnSize == info.nSize ); 60612 61239 assert( spaceLeft == info.nLocal ); 60613 - assert( pPrior == &pCell[info.iOverflow] ); 60614 61240 } 60615 61241 #endif 60616 61242 60617 61243 /* Write the payload into the local Cell and any extra into overflow pages */ 60618 61244 while( nPayload>0 ){ 60619 61245 if( spaceLeft==0 ){ 60620 61246 #ifndef SQLITE_OMIT_AUTOVACUUM ................................................................................ 60927 61553 60928 61554 i = get2byte(&aData[hdr+5]); 60929 61555 memcpy(&pTmp[i], &aData[i], usableSize - i); 60930 61556 60931 61557 pData = pEnd; 60932 61558 for(i=0; i<nCell; i++){ 60933 61559 u8 *pCell = apCell[i]; 60934 - if( pCell>aData && pCell<pEnd ){ 61560 + if( SQLITE_WITHIN(pCell,aData,pEnd) ){ 60935 61561 pCell = &pTmp[pCell - aData]; 60936 61562 } 60937 61563 pData -= szCell[i]; 60938 61564 put2byte(pCellptr, (pData - aData)); 60939 61565 pCellptr += 2; 60940 61566 if( pData < pCellptr ) return SQLITE_CORRUPT_BKPT; 60941 61567 memcpy(pData, pCell, szCell[i]); ................................................................................ 61038 61664 int i; 61039 61665 int iEnd = iFirst + nCell; 61040 61666 u8 *pFree = 0; 61041 61667 int szFree = 0; 61042 61668 61043 61669 for(i=iFirst; i<iEnd; i++){ 61044 61670 u8 *pCell = pCArray->apCell[i]; 61045 - if( pCell>=pStart && pCell<pEnd ){ 61671 + if( SQLITE_WITHIN(pCell, pStart, pEnd) ){ 61046 61672 int sz; 61047 61673 /* No need to use cachedCellSize() here. The sizes of all cells that 61048 61674 ** are to be freed have already been computing while deciding which 61049 61675 ** cells need freeing */ 61050 61676 sz = pCArray->szCell[i]; assert( sz>0 ); 61051 61677 if( pFree!=(pCell + sz) ){ 61052 61678 if( pFree ){ ................................................................................ 61316 61942 61317 61943 for(j=0; j<pPage->nCell; j++){ 61318 61944 CellInfo info; 61319 61945 u8 *z; 61320 61946 61321 61947 z = findCell(pPage, j); 61322 61948 pPage->xParseCell(pPage, z, &info); 61323 - if( info.iOverflow ){ 61324 - Pgno ovfl = get4byte(&z[info.iOverflow]); 61949 + if( info.nLocal<info.nPayload ){ 61950 + Pgno ovfl = get4byte(&z[info.nSize-4]); 61325 61951 ptrmapGet(pBt, ovfl, &e, &n); 61326 61952 assert( n==pPage->pgno && e==PTRMAP_OVERFLOW1 ); 61327 61953 } 61328 61954 if( !pPage->leaf ){ 61329 61955 Pgno child = get4byte(z); 61330 61956 ptrmapGet(pBt, child, &e, &n); 61331 61957 assert( n==pPage->pgno && e==PTRMAP_BTREE ); ................................................................................ 61435 62061 ** size of a cell stored within an internal node is always less than 1/4 61436 62062 ** of the page-size, the aOvflSpace[] buffer is guaranteed to be large 61437 62063 ** enough for all overflow cells. 61438 62064 ** 61439 62065 ** If aOvflSpace is set to a null pointer, this function returns 61440 62066 ** SQLITE_NOMEM. 61441 62067 */ 61442 -#if defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_M_ARM) 61443 -#pragma optimize("", off) 61444 -#endif 61445 62068 static int balance_nonroot( 61446 62069 MemPage *pParent, /* Parent page of siblings being balanced */ 61447 62070 int iParentIdx, /* Index of "the page" in pParent */ 61448 62071 u8 *aOvflSpace, /* page-size bytes of space for parent ovfl */ 61449 62072 int isRoot, /* True if pParent is a root-page */ 61450 62073 int bBulk /* True if this call is part of a bulk load */ 61451 62074 ){ ................................................................................ 61981 62604 ** was either part of sibling page iOld (possibly an overflow cell), 61982 62605 ** or else the divider cell to the left of sibling page iOld. So, 61983 62606 ** if sibling page iOld had the same page number as pNew, and if 61984 62607 ** pCell really was a part of sibling page iOld (not a divider or 61985 62608 ** overflow cell), we can skip updating the pointer map entries. */ 61986 62609 if( iOld>=nNew 61987 62610 || pNew->pgno!=aPgno[iOld] 61988 - || pCell<aOld 61989 - || pCell>=&aOld[usableSize] 62611 + || !SQLITE_WITHIN(pCell,aOld,&aOld[usableSize]) 61990 62612 ){ 61991 62613 if( !leafCorrection ){ 61992 62614 ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc); 61993 62615 } 61994 62616 if( cachedCellSize(&b,i)>pNew->minLocal ){ 61995 62617 ptrmapPutOvflPtr(pNew, pCell, &rc); 61996 62618 } ................................................................................ 62183 62805 } 62184 62806 for(i=0; i<nNew; i++){ 62185 62807 releasePage(apNew[i]); 62186 62808 } 62187 62809 62188 62810 return rc; 62189 62811 } 62190 -#if defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_M_ARM) 62191 -#pragma optimize("", on) 62192 -#endif 62193 62812 62194 62813 62195 62814 /* 62196 62815 ** This function is called when the root page of a b-tree structure is 62197 62816 ** overfull (has one or more overflow pages). 62198 62817 ** 62199 62818 ** A new child page is allocated and the contents of the current root ................................................................................ 63384 64003 if( iPage<1 ){ 63385 64004 checkAppendMsg(pCheck, 63386 64005 "%d of %d pages missing from overflow list starting at %d", 63387 64006 N+1, expected, iFirst); 63388 64007 break; 63389 64008 } 63390 64009 if( checkRef(pCheck, iPage) ) break; 63391 - if( sqlite3PagerGet(pCheck->pPager, (Pgno)iPage, &pOvflPage) ){ 64010 + if( sqlite3PagerGet(pCheck->pPager, (Pgno)iPage, &pOvflPage, 0) ){ 63392 64011 checkAppendMsg(pCheck, "failed to get page %d", iPage); 63393 64012 break; 63394 64013 } 63395 64014 pOvflData = (unsigned char *)sqlite3PagerGetData(pOvflPage); 63396 64015 if( isFreeList ){ 63397 64016 int n = get4byte(&pOvflData[4]); 63398 64017 #ifndef SQLITE_OMIT_AUTOVACUUM ................................................................................ 63630 64249 maxKey = info.nKey; 63631 64250 } 63632 64251 63633 64252 /* Check the content overflow list */ 63634 64253 if( info.nPayload>info.nLocal ){ 63635 64254 int nPage; /* Number of pages on the overflow chain */ 63636 64255 Pgno pgnoOvfl; /* First page of the overflow chain */ 63637 - assert( pc + info.iOverflow <= usableSize ); 64256 + assert( pc + info.nSize - 4 <= usableSize ); 63638 64257 nPage = (info.nPayload - info.nLocal + usableSize - 5)/(usableSize - 4); 63639 - pgnoOvfl = get4byte(&pCell[info.iOverflow]); 64258 + pgnoOvfl = get4byte(&pCell[info.nSize - 4]); 63640 64259 #ifndef SQLITE_OMIT_AUTOVACUUM 63641 64260 if( pBt->autoVacuum ){ 63642 64261 checkPtrmap(pCheck, pgnoOvfl, PTRMAP_OVERFLOW1, iPage); 63643 64262 } 63644 64263 #endif 63645 64264 checkList(pCheck, 0, pgnoOvfl, nPage); 63646 64265 } ................................................................................ 64122 64741 } 64123 64742 64124 64743 pBt->btsFlags &= ~BTS_NO_WAL; 64125 64744 return rc; 64126 64745 } 64127 64746 64128 64747 /* 64129 -** set the mask of hint flags for cursor pCsr. 64130 -*/ 64131 -SQLITE_PRIVATE void sqlite3BtreeCursorHints(BtCursor *pCsr, unsigned int mask){ 64132 - assert( mask==BTREE_BULKLOAD || mask==BTREE_SEEK_EQ || mask==0 ); 64133 - pCsr->hints = mask; 64134 -} 64135 - 64136 -#ifdef SQLITE_DEBUG 64137 -/* 64138 64748 ** Return true if the cursor has a hint specified. This routine is 64139 64749 ** only used from within assert() statements 64140 64750 */ 64141 64751 SQLITE_PRIVATE int sqlite3BtreeCursorHasHint(BtCursor *pCsr, unsigned int mask){ 64142 64752 return (pCsr->hints & mask)!=0; 64143 64753 } 64144 -#endif 64145 64754 64146 64755 /* 64147 64756 ** Return true if the given Btree is read-only. 64148 64757 */ 64149 64758 SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *p){ 64150 64759 return (p->pBt->btsFlags & BTS_READ_ONLY)!=0; 64151 64760 } ................................................................................ 64448 65057 ** page. For each iteration, variable iOff is set to the byte offset 64449 65058 ** of the destination page. 64450 65059 */ 64451 65060 for(iOff=iEnd-(i64)nSrcPgsz; rc==SQLITE_OK && iOff<iEnd; iOff+=nDestPgsz){ 64452 65061 DbPage *pDestPg = 0; 64453 65062 Pgno iDest = (Pgno)(iOff/nDestPgsz)+1; 64454 65063 if( iDest==PENDING_BYTE_PAGE(p->pDest->pBt) ) continue; 64455 - if( SQLITE_OK==(rc = sqlite3PagerGet(pDestPager, iDest, &pDestPg)) 65064 + if( SQLITE_OK==(rc = sqlite3PagerGet(pDestPager, iDest, &pDestPg, 0)) 64456 65065 && SQLITE_OK==(rc = sqlite3PagerWrite(pDestPg)) 64457 65066 ){ 64458 65067 const u8 *zIn = &zSrcData[iOff%nSrcPgsz]; 64459 65068 u8 *zDestData = sqlite3PagerGetData(pDestPg); 64460 65069 u8 *zOut = &zDestData[iOff%nDestPgsz]; 64461 65070 64462 65071 /* Copy the data from the source page into the destination page. ................................................................................ 64574 65183 */ 64575 65184 nSrcPage = (int)sqlite3BtreeLastPage(p->pSrc); 64576 65185 assert( nSrcPage>=0 ); 64577 65186 for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){ 64578 65187 const Pgno iSrcPg = p->iNext; /* Source page number */ 64579 65188 if( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ){ 64580 65189 DbPage *pSrcPg; /* Source page object */ 64581 - rc = sqlite3PagerAcquire(pSrcPager, iSrcPg, &pSrcPg, 64582 - PAGER_GET_READONLY); 65190 + rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg,PAGER_GET_READONLY); 64583 65191 if( rc==SQLITE_OK ){ 64584 65192 rc = backupOnePage(p, iSrcPg, sqlite3PagerGetData(pSrcPg), 0); 64585 65193 sqlite3PagerUnref(pSrcPg); 64586 65194 } 64587 65195 } 64588 65196 p->iNext++; 64589 65197 } ................................................................................ 64675 65283 ** the database file in any way, knowing that if a power failure 64676 65284 ** occurs, the original database will be reconstructed from the 64677 65285 ** journal file. */ 64678 65286 sqlite3PagerPagecount(pDestPager, &nDstPage); 64679 65287 for(iPg=nDestTruncate; rc==SQLITE_OK && iPg<=(Pgno)nDstPage; iPg++){ 64680 65288 if( iPg!=PENDING_BYTE_PAGE(p->pDest->pBt) ){ 64681 65289 DbPage *pPg; 64682 - rc = sqlite3PagerGet(pDestPager, iPg, &pPg); 65290 + rc = sqlite3PagerGet(pDestPager, iPg, &pPg, 0); 64683 65291 if( rc==SQLITE_OK ){ 64684 65292 rc = sqlite3PagerWrite(pPg); 64685 65293 sqlite3PagerUnref(pPg); 64686 65294 } 64687 65295 } 64688 65296 } 64689 65297 if( rc==SQLITE_OK ){ ................................................................................ 64695 65303 for( 64696 65304 iOff=PENDING_BYTE+pgszSrc; 64697 65305 rc==SQLITE_OK && iOff<iEnd; 64698 65306 iOff+=pgszSrc 64699 65307 ){ 64700 65308 PgHdr *pSrcPg = 0; 64701 65309 const Pgno iSrcPg = (Pgno)((iOff/pgszSrc)+1); 64702 - rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg); 65310 + rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg, 0); 64703 65311 if( rc==SQLITE_OK ){ 64704 65312 u8 *zData = sqlite3PagerGetData(pSrcPg); 64705 65313 rc = sqlite3OsWrite(pFile, zData, pgszSrc, iOff); 64706 65314 } 64707 65315 sqlite3PagerUnref(pSrcPg); 64708 65316 } 64709 65317 if( rc==SQLITE_OK ){ ................................................................................ 66383 66991 */ 66384 66992 static void recordFunc( 66385 66993 sqlite3_context *context, 66386 66994 int argc, 66387 66995 sqlite3_value **argv 66388 66996 ){ 66389 66997 const int file_format = 1; 66390 - int iSerial; /* Serial type */ 66998 + u32 iSerial; /* Serial type */ 66391 66999 int nSerial; /* Bytes of space for iSerial as varint */ 66392 - int nVal; /* Bytes of space required for argv[0] */ 67000 + u32 nVal; /* Bytes of space required for argv[0] */ 66393 67001 int nRet; 66394 67002 sqlite3 *db; 66395 67003 u8 *aRet; 66396 67004 66397 67005 UNUSED_PARAMETER( argc ); 66398 - iSerial = sqlite3VdbeSerialType(argv[0], file_format); 67006 + iSerial = sqlite3VdbeSerialType(argv[0], file_format, &nVal); 66399 67007 nSerial = sqlite3VarintLen(iSerial); 66400 - nVal = sqlite3VdbeSerialTypeLen(iSerial); 66401 67008 db = sqlite3_context_db_handle(context); 66402 67009 66403 67010 nRet = 1 + nSerial + nVal; 66404 67011 aRet = sqlite3DbMallocRaw(db, nRet); 66405 67012 if( aRet==0 ){ 66406 67013 sqlite3_result_error_nomem(context); 66407 67014 }else{ ................................................................................ 66835 67442 ** 66836 67443 ** p1, p2, p3 Operands 66837 67444 ** 66838 67445 ** Use the sqlite3VdbeResolveLabel() function to fix an address and 66839 67446 ** the sqlite3VdbeChangeP4() function to change the value of the P4 66840 67447 ** operand. 66841 67448 */ 67449 +static SQLITE_NOINLINE int growOp3(Vdbe *p, int op, int p1, int p2, int p3){ 67450 + assert( p->pParse->nOpAlloc<=p->nOp ); 67451 + if( growOpArray(p, 1) ) return 1; 67452 + assert( p->pParse->nOpAlloc>p->nOp ); 67453 + return sqlite3VdbeAddOp3(p, op, p1, p2, p3); 67454 +} 66842 67455 SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){ 66843 67456 int i; 66844 67457 VdbeOp *pOp; 66845 67458 66846 67459 i = p->nOp; 66847 67460 assert( p->magic==VDBE_MAGIC_INIT ); 66848 67461 assert( op>0 && op<0xff ); 66849 67462 if( p->pParse->nOpAlloc<=i ){ 66850 - if( growOpArray(p, 1) ){ 66851 - return 1; 66852 - } 67463 + return growOp3(p, op, p1, p2, p3); 66853 67464 } 66854 67465 p->nOp++; 66855 67466 pOp = &p->aOp[i]; 66856 67467 pOp->opcode = (u8)op; 66857 67468 pOp->p5 = 0; 66858 67469 pOp->p1 = p1; 66859 67470 pOp->p2 = p2; ................................................................................ 67023 67634 if( (i & (i-1))==0 ){ 67024 67635 p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel, 67025 67636 (i*2+1)*sizeof(p->aLabel[0])); 67026 67637 } 67027 67638 if( p->aLabel ){ 67028 67639 p->aLabel[i] = -1; 67029 67640 } 67030 - return -1-i; 67641 + return ADDR(i); 67031 67642 } 67032 67643 67033 67644 /* 67034 67645 ** Resolve label "x" to be the address of the next instruction to 67035 67646 ** be inserted. The parameter "x" must have been obtained from 67036 67647 ** a prior call to sqlite3VdbeMakeLabel(). 67037 67648 */ 67038 67649 SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){ 67039 67650 Parse *p = v->pParse; 67040 - int j = -1-x; 67651 + int j = ADDR(x); 67041 67652 assert( v->magic==VDBE_MAGIC_INIT ); 67042 67653 assert( j<p->nLabel ); 67043 67654 assert( j>=0 ); 67044 67655 if( p->aLabel ){ 67045 67656 p->aLabel[j] = v->nOp; 67046 67657 } 67047 67658 p->iFixedOp = v->nOp - 1; ................................................................................ 67260 67871 pOp->p4type = P4_ADVANCE; 67261 67872 break; 67262 67873 } 67263 67874 } 67264 67875 67265 67876 pOp->opflags = sqlite3OpcodeProperty[opcode]; 67266 67877 if( (pOp->opflags & OPFLG_JUMP)!=0 && pOp->p2<0 ){ 67267 - assert( -1-pOp->p2<pParse->nLabel ); 67268 - pOp->p2 = aLabel[-1-pOp->p2]; 67878 + assert( ADDR(pOp->p2)<pParse->nLabel ); 67879 + pOp->p2 = aLabel[ADDR(pOp->p2)]; 67269 67880 } 67270 67881 } 67271 67882 sqlite3DbFree(p->db, pParse->aLabel); 67272 67883 pParse->aLabel = 0; 67273 67884 pParse->nLabel = 0; 67274 67885 *pMaxFuncArgs = nMaxArgs; 67275 67886 assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) ); ................................................................................ 67318 67929 assert( p->magic==VDBE_MAGIC_INIT ); 67319 67930 if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p, nOp) ){ 67320 67931 return 0; 67321 67932 } 67322 67933 addr = p->nOp; 67323 67934 pOut = &p->aOp[addr]; 67324 67935 for(i=0; i<nOp; i++, aOp++, pOut++){ 67325 - int p2 = aOp->p2; 67326 67936 pOut->opcode = aOp->opcode; 67327 67937 pOut->p1 = aOp->p1; 67328 - if( p2<0 ){ 67329 - assert( sqlite3OpcodeProperty[pOut->opcode] & OPFLG_JUMP ); 67330 - pOut->p2 = addr + ADDR(p2); 67331 - }else{ 67332 - pOut->p2 = p2; 67333 - } 67938 + pOut->p2 = aOp->p2; 67939 + assert( aOp->p2>=0 ); 67334 67940 pOut->p3 = aOp->p3; 67335 67941 pOut->p4type = P4_NOTUSED; 67336 67942 pOut->p4.p = 0; 67337 67943 pOut->p5 = 0; 67338 67944 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS 67339 67945 pOut->zComment = 0; 67340 67946 #endif ................................................................................ 67441 68047 sqlite3DbFree(db, p4); 67442 68048 break; 67443 68049 } 67444 68050 case P4_KEYINFO: { 67445 68051 if( db->pnBytesFreed==0 ) sqlite3KeyInfoUnref((KeyInfo*)p4); 67446 68052 break; 67447 68053 } 68054 +#ifdef SQLITE_ENABLE_CURSOR_HINTS 68055 + case P4_EXPR: { 68056 + sqlite3ExprDelete(db, (Expr*)p4); 68057 + break; 68058 + } 68059 +#endif 67448 68060 case P4_MPRINTF: { 67449 68061 if( db->pnBytesFreed==0 ) sqlite3_free(p4); 67450 68062 break; 67451 68063 } 67452 68064 case P4_FUNCDEF: { 67453 68065 freeEphemeralFunction(db, (FuncDef*)p4); 67454 68066 break; ................................................................................ 67505 68117 SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe *p, int addr){ 67506 68118 if( addr<p->nOp ){ 67507 68119 VdbeOp *pOp = &p->aOp[addr]; 67508 68120 sqlite3 *db = p->db; 67509 68121 freeP4(db, pOp->p4type, pOp->p4.p); 67510 68122 memset(pOp, 0, sizeof(pOp[0])); 67511 68123 pOp->opcode = OP_Noop; 67512 - if( addr==p->nOp-1 ) p->nOp--; 67513 68124 } 67514 68125 } 67515 68126 67516 68127 /* 67517 68128 ** If the last opcode is "op" and it is not a jump destination, 67518 68129 ** then remove it. Return true if and only if an opcode was removed. 67519 68130 */ ................................................................................ 67573 68184 pOp->p4type = P4_INT32; 67574 68185 }else if( zP4==0 ){ 67575 68186 pOp->p4.p = 0; 67576 68187 pOp->p4type = P4_NOTUSED; 67577 68188 }else if( n==P4_KEYINFO ){ 67578 68189 pOp->p4.p = (void*)zP4; 67579 68190 pOp->p4type = P4_KEYINFO; 68191 +#ifdef SQLITE_ENABLE_CURSOR_HINTS 68192 + }else if( n==P4_EXPR ){ 68193 + /* Responsibility for deleting the Expr tree is handed over to the 68194 + ** VDBE by this operation. The caller should have already invoked 68195 + ** sqlite3ExprDup() or whatever other routine is needed to make a 68196 + ** private copy of the tree. */ 68197 + pOp->p4.pExpr = (Expr*)zP4; 68198 + pOp->p4type = P4_EXPR; 68199 +#endif 67580 68200 }else if( n==P4_VTAB ){ 67581 68201 pOp->p4.p = (void*)zP4; 67582 68202 pOp->p4type = P4_VTAB; 67583 68203 sqlite3VtabLock((VTable *)zP4); 67584 68204 assert( ((VTable *)zP4)->db==p->db ); 67585 68205 }else if( n<0 ){ 67586 68206 pOp->p4.p = (void*)zP4; ................................................................................ 67763 68383 zTemp[0] = 0; 67764 68384 jj = 0; 67765 68385 } 67766 68386 return jj; 67767 68387 } 67768 68388 #endif /* SQLITE_DEBUG */ 67769 68389 68390 +#if VDBE_DISPLAY_P4 && defined(SQLITE_ENABLE_CURSOR_HINTS) 68391 +/* 68392 +** Translate the P4.pExpr value for an OP_CursorHint opcode into text 68393 +** that can be displayed in the P4 column of EXPLAIN output. 68394 +*/ 68395 +static int displayP4Expr(int nTemp, char *zTemp, Expr *pExpr){ 68396 + const char *zOp = 0; 68397 + int n; 68398 + switch( pExpr->op ){ 68399 + case TK_STRING: 68400 + sqlite3_snprintf(nTemp, zTemp, "%Q", pExpr->u.zToken); 68401 + break; 68402 + case TK_INTEGER: 68403 + sqlite3_snprintf(nTemp, zTemp, "%d", pExpr->u.iValue); 68404 + break; 68405 + case TK_NULL: 68406 + sqlite3_snprintf(nTemp, zTemp, "NULL"); 68407 + break; 68408 + case TK_REGISTER: { 68409 + sqlite3_snprintf(nTemp, zTemp, "r[%d]", pExpr->iTable); 68410 + break; 68411 + } 68412 + case TK_COLUMN: { 68413 + if( pExpr->iColumn<0 ){ 68414 + sqlite3_snprintf(nTemp, zTemp, "rowid"); 68415 + }else{ 68416 + sqlite3_snprintf(nTemp, zTemp, "c%d", (int)pExpr->iColumn); 68417 + } 68418 + break; 68419 + } 68420 + case TK_LT: zOp = "LT"; break; 68421 + case TK_LE: zOp = "LE"; break; 68422 + case TK_GT: zOp = "GT"; break; 68423 + case TK_GE: zOp = "GE"; break; 68424 + case TK_NE: zOp = "NE"; break; 68425 + case TK_EQ: zOp = "EQ"; break; 68426 + case TK_IS: zOp = "IS"; break; 68427 + case TK_ISNOT: zOp = "ISNOT"; break; 68428 + case TK_AND: zOp = "AND"; break; 68429 + case TK_OR: zOp = "OR"; break; 68430 + case TK_PLUS: zOp = "ADD"; break; 68431 + case TK_STAR: zOp = "MUL"; break; 68432 + case TK_MINUS: zOp = "SUB"; break; 68433 + case TK_REM: zOp = "REM"; break; 68434 + case TK_BITAND: zOp = "BITAND"; break; 68435 + case TK_BITOR: zOp = "BITOR"; break; 68436 + case TK_SLASH: zOp = "DIV"; break; 68437 + case TK_LSHIFT: zOp = "LSHIFT"; break; 68438 + case TK_RSHIFT: zOp = "RSHIFT"; break; 68439 + case TK_CONCAT: zOp = "CONCAT"; break; 68440 + case TK_UMINUS: zOp = "MINUS"; break; 68441 + case TK_UPLUS: zOp = "PLUS"; break; 68442 + case TK_BITNOT: zOp = "BITNOT"; break; 68443 + case TK_NOT: zOp = "NOT"; break; 68444 + case TK_ISNULL: zOp = "ISNULL"; break; 68445 + case TK_NOTNULL: zOp = "NOTNULL"; break; 67770 68446 67771 -#if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) \ 67772 - || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG) 68447 + default: 68448 + sqlite3_snprintf(nTemp, zTemp, "%s", "expr"); 68449 + break; 68450 + } 68451 + 68452 + if( zOp ){ 68453 + sqlite3_snprintf(nTemp, zTemp, "%s(", zOp); 68454 + n = sqlite3Strlen30(zTemp); 68455 + n += displayP4Expr(nTemp-n, zTemp+n, pExpr->pLeft); 68456 + if( n<nTemp-1 && pExpr->pRight ){ 68457 + zTemp[n++] = ','; 68458 + n += displayP4Expr(nTemp-n, zTemp+n, pExpr->pRight); 68459 + } 68460 + sqlite3_snprintf(nTemp-n, zTemp+n, ")"); 68461 + } 68462 + return sqlite3Strlen30(zTemp); 68463 +} 68464 +#endif /* VDBE_DISPLAY_P4 && defined(SQLITE_ENABLE_CURSOR_HINTS) */ 68465 + 68466 + 68467 +#if VDBE_DISPLAY_P4 67773 68468 /* 67774 68469 ** Compute a string that describes the P4 parameter for an opcode. 67775 68470 ** Use zTemp for any required temporary buffer space. 67776 68471 */ 67777 68472 static char *displayP4(Op *pOp, char *zTemp, int nTemp){ 67778 68473 char *zP4 = zTemp; 67779 68474 assert( nTemp>=20 ); ................................................................................ 67805 68500 i += n; 67806 68501 } 67807 68502 zTemp[i++] = ')'; 67808 68503 zTemp[i] = 0; 67809 68504 assert( i<nTemp ); 67810 68505 break; 67811 68506 } 68507 +#ifdef SQLITE_ENABLE_CURSOR_HINTS 68508 + case P4_EXPR: { 68509 + displayP4Expr(nTemp, zTemp, pOp->p4.pExpr); 68510 + break; 68511 + } 68512 +#endif 67812 68513 case P4_COLLSEQ: { 67813 68514 CollSeq *pColl = pOp->p4.pColl; 67814 68515 sqlite3_snprintf(nTemp, zTemp, "(%.20s)", pColl->zName); 67815 68516 break; 67816 68517 } 67817 68518 case P4_FUNCDEF: { 67818 68519 FuncDef *pDef = pOp->p4.pFunc; ................................................................................ 67880 68581 zTemp[0] = 0; 67881 68582 } 67882 68583 } 67883 68584 } 67884 68585 assert( zP4!=0 ); 67885 68586 return zP4; 67886 68587 } 67887 -#endif 68588 +#endif /* VDBE_DISPLAY_P4 */ 67888 68589 67889 68590 /* 67890 68591 ** Declare to the Vdbe that the BTree object at db->aDb[i] is used. 67891 68592 ** 67892 68593 ** The prepared statements need to know in advance the complete set of 67893 68594 ** attached databases that will be use. A mask of these databases 67894 68595 ** is maintained in p->btreeMask. The p->lockMask value is the subset of ................................................................................ 68194 68895 pMem->u.i = pOp->p2; /* P2 */ 68195 68896 pMem++; 68196 68897 68197 68898 pMem->flags = MEM_Int; 68198 68899 pMem->u.i = pOp->p3; /* P3 */ 68199 68900 pMem++; 68200 68901 68201 - if( sqlite3VdbeMemClearAndResize(pMem, 32) ){ /* P4 */ 68902 + if( sqlite3VdbeMemClearAndResize(pMem, 100) ){ /* P4 */ 68202 68903 assert( p->db->mallocFailed ); 68203 68904 return SQLITE_ERROR; 68204 68905 } 68205 68906 pMem->flags = MEM_Str|MEM_Term; 68206 - zP4 = displayP4(pOp, pMem->z, 32); 68907 + zP4 = displayP4(pOp, pMem->z, pMem->szMalloc); 68207 68908 if( zP4!=pMem->z ){ 68208 68909 sqlite3VdbeMemSetStr(pMem, zP4, -1, SQLITE_UTF8, 0); 68209 68910 }else{ 68210 68911 assert( pMem->z!=0 ); 68211 68912 pMem->n = sqlite3Strlen30(pMem->z); 68212 68913 pMem->enc = SQLITE_UTF8; 68213 68914 } ................................................................................ 68304 69005 ** NULL, it means that memory space has already been allocated and that 68305 69006 ** this routine should not allocate any new memory. When pBuf is not 68306 69007 ** NULL simply return pBuf. Only allocate new memory space when pBuf 68307 69008 ** is NULL. 68308 69009 ** 68309 69010 ** nByte is the number of bytes of space needed. 68310 69011 ** 68311 -** *ppFrom points to available space and pEnd points to the end of the 68312 -** available space. When space is allocated, *ppFrom is advanced past 68313 -** the end of the allocated space. 69012 +** pFrom points to *pnFrom bytes of available space. New space is allocated 69013 +** from the end of the pFrom buffer and *pnFrom is decremented. 68314 69014 ** 68315 -** *pnByte is a counter of the number of bytes of space that have failed 68316 -** to allocate. If there is insufficient space in *ppFrom to satisfy the 68317 -** request, then increment *pnByte by the amount of the request. 69015 +** *pnNeeded is a counter of the number of bytes of space that have failed 69016 +** to allocate. If there is insufficient space in pFrom to satisfy the 69017 +** request, then increment *pnNeeded by the amount of the request. 68318 69018 */ 68319 69019 static void *allocSpace( 68320 69020 void *pBuf, /* Where return pointer will be stored */ 68321 69021 int nByte, /* Number of bytes to allocate */ 68322 - u8 **ppFrom, /* IN/OUT: Allocate from *ppFrom */ 68323 - u8 *pEnd, /* Pointer to 1 byte past the end of *ppFrom buffer */ 68324 - int *pnByte /* If allocation cannot be made, increment *pnByte */ 69022 + u8 *pFrom, /* Memory available for allocation */ 69023 + int *pnFrom, /* IN/OUT: Space available at pFrom */ 69024 + int *pnNeeded /* If allocation cannot be made, increment *pnByte */ 68325 69025 ){ 68326 - assert( EIGHT_BYTE_ALIGNMENT(*ppFrom) ); 68327 - if( pBuf ) return pBuf; 68328 - nByte = ROUND8(nByte); 68329 - if( &(*ppFrom)[nByte] <= pEnd ){ 68330 - pBuf = (void*)*ppFrom; 68331 - *ppFrom += nByte; 68332 - }else{ 68333 - *pnByte += nByte; 69026 + assert( EIGHT_BYTE_ALIGNMENT(pFrom) ); 69027 + if( pBuf==0 ){ 69028 + nByte = ROUND8(nByte); 69029 + if( nByte <= *pnFrom ){ 69030 + *pnFrom -= nByte; 69031 + pBuf = &pFrom[*pnFrom]; 69032 + }else{ 69033 + *pnNeeded += nByte; 69034 + } 68334 69035 } 69036 + assert( EIGHT_BYTE_ALIGNMENT(pBuf) ); 68335 69037 return pBuf; 68336 69038 } 68337 69039 68338 69040 /* 68339 69041 ** Rewind the VDBE back to the beginning in preparation for 68340 69042 ** running it. 68341 69043 */ ................................................................................ 68400 69102 sqlite3 *db; /* The database connection */ 68401 69103 int nVar; /* Number of parameters */ 68402 69104 int nMem; /* Number of VM memory registers */ 68403 69105 int nCursor; /* Number of cursors required */ 68404 69106 int nArg; /* Number of arguments in subprograms */ 68405 69107 int nOnce; /* Number of OP_Once instructions */ 68406 69108 int n; /* Loop counter */ 69109 + int nFree; /* Available free space */ 68407 69110 u8 *zCsr; /* Memory available for allocation */ 68408 - u8 *zEnd; /* First byte past allocated memory */ 68409 69111 int nByte; /* How much extra memory is needed */ 68410 69112 68411 69113 assert( p!=0 ); 68412 69114 assert( p->nOp>0 ); 68413 69115 assert( pParse!=0 ); 68414 69116 assert( p->magic==VDBE_MAGIC_INIT ); 68415 69117 assert( pParse==p->pParse ); ................................................................................ 68433 69135 */ 68434 69136 nMem += nCursor; 68435 69137 68436 69138 /* Allocate space for memory registers, SQL variables, VDBE cursors and 68437 69139 ** an array to marshal SQL function arguments in. 68438 69140 */ 68439 69141 zCsr = (u8*)&p->aOp[p->nOp]; /* Memory avaliable for allocation */ 68440 - zEnd = (u8*)&p->aOp[pParse->nOpAlloc]; /* First byte past end of zCsr[] */ 69142 + assert( pParse->nOpAlloc*sizeof(Op) <= 0x7fffff00 ); 69143 + nFree = (pParse->nOpAlloc - p->nOp)*sizeof(p->aOp[0]); /* Available space */ 68441 69144 68442 69145 resolveP2Values(p, &nArg); 68443 69146 p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort); 68444 69147 if( pParse->explain && nMem<10 ){ 68445 69148 nMem = 10; 68446 69149 } 68447 - memset(zCsr, 0, zEnd-zCsr); 68448 - zCsr += (zCsr - (u8*)0)&7; 68449 - assert( EIGHT_BYTE_ALIGNMENT(zCsr) ); 69150 + memset(zCsr, 0, nFree); 69151 + assert( EIGHT_BYTE_ALIGNMENT(&zCsr[nFree]) ); 68450 69152 p->expired = 0; 68451 69153 68452 69154 /* Memory for registers, parameters, cursor, etc, is allocated in two 68453 69155 ** passes. On the first pass, we try to reuse unused space at the 68454 69156 ** end of the opcode array. If we are unable to satisfy all memory 68455 69157 ** requirements by reusing the opcode array tail, then the second 68456 69158 ** pass will fill in the rest using a fresh allocation. ................................................................................ 68457 69159 ** 68458 69160 ** This two-pass approach that reuses as much memory as possible from 68459 69161 ** the leftover space at the end of the opcode array can significantly 68460 69162 ** reduce the amount of memory held by a prepared statement. 68461 69163 */ 68462 69164 do { 68463 69165 nByte = 0; 68464 - p->aMem = allocSpace(p->aMem, nMem*sizeof(Mem), &zCsr, zEnd, &nByte); 68465 - p->aVar = allocSpace(p->aVar, nVar*sizeof(Mem), &zCsr, zEnd, &nByte); 68466 - p->apArg = allocSpace(p->apArg, nArg*sizeof(Mem*), &zCsr, zEnd, &nByte); 68467 - p->azVar = allocSpace(p->azVar, nVar*sizeof(char*), &zCsr, zEnd, &nByte); 69166 + p->aMem = allocSpace(p->aMem, nMem*sizeof(Mem), zCsr, &nFree, &nByte); 69167 + p->aVar = allocSpace(p->aVar, nVar*sizeof(Mem), zCsr, &nFree, &nByte); 69168 + p->apArg = allocSpace(p->apArg, nArg*sizeof(Mem*), zCsr, &nFree, &nByte); 69169 + p->azVar = allocSpace(p->azVar, nVar*sizeof(char*), zCsr, &nFree, &nByte); 68468 69170 p->apCsr = allocSpace(p->apCsr, nCursor*sizeof(VdbeCursor*), 68469 - &zCsr, zEnd, &nByte); 68470 - p->aOnceFlag = allocSpace(p->aOnceFlag, nOnce, &zCsr, zEnd, &nByte); 69171 + zCsr, &nFree, &nByte); 69172 + p->aOnceFlag = allocSpace(p->aOnceFlag, nOnce, zCsr, &nFree, &nByte); 68471 69173 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS 68472 - p->anExec = allocSpace(p->anExec, p->nOp*sizeof(i64), &zCsr, zEnd, &nByte); 69174 + p->anExec = allocSpace(p->anExec, p->nOp*sizeof(i64), zCsr, &nFree, &nByte); 68473 69175 #endif 68474 69176 if( nByte ){ 68475 69177 p->pFree = sqlite3DbMallocZero(db, nByte); 68476 69178 } 68477 69179 zCsr = p->pFree; 68478 - zEnd = &zCsr[nByte]; 69180 + nFree = nByte; 68479 69181 }while( nByte && !db->mallocFailed ); 68480 69182 68481 69183 p->nCursor = nCursor; 68482 69184 p->nOnceFlag = nOnce; 68483 69185 if( p->aVar ){ 68484 69186 p->nVar = (ynVar)nVar; 68485 69187 for(n=0; n<nVar; n++){ ................................................................................ 68508 69210 ** Close a VDBE cursor and release all the resources that cursor 68509 69211 ** happens to hold. 68510 69212 */ 68511 69213 SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){ 68512 69214 if( pCx==0 ){ 68513 69215 return; 68514 69216 } 68515 - sqlite3VdbeSorterClose(p->db, pCx); 68516 - if( pCx->pBt ){ 68517 - sqlite3BtreeClose(pCx->pBt); 68518 - /* The pCx->pCursor will be close automatically, if it exists, by 68519 - ** the call above. */ 68520 - }else if( pCx->pCursor ){ 68521 - sqlite3BtreeCloseCursor(pCx->pCursor); 68522 - } 68523 -#ifndef SQLITE_OMIT_VIRTUALTABLE 68524 - else if( pCx->pVtabCursor ){ 68525 - sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor; 68526 - const sqlite3_module *pModule = pVtabCursor->pVtab->pModule; 68527 - assert( pVtabCursor->pVtab->nRef>0 ); 68528 - pVtabCursor->pVtab->nRef--; 68529 - pModule->xClose(pVtabCursor); 68530 - } 68531 -#endif 69217 + assert( pCx->pBt==0 || pCx->eCurType==CURTYPE_BTREE ); 69218 + switch( pCx->eCurType ){ 69219 + case CURTYPE_SORTER: { 69220 + sqlite3VdbeSorterClose(p->db, pCx); 69221 + break; 69222 + } 69223 + case CURTYPE_BTREE: { 69224 + if( pCx->pBt ){ 69225 + sqlite3BtreeClose(pCx->pBt); 69226 + /* The pCx->pCursor will be close automatically, if it exists, by 69227 + ** the call above. */ 69228 + }else{ 69229 + assert( pCx->uc.pCursor!=0 ); 69230 + sqlite3BtreeCloseCursor(pCx->uc.pCursor); 69231 + } 69232 + break; 69233 + } 69234 +#ifndef SQLITE_OMIT_VIRTUALTABLE 69235 + case CURTYPE_VTAB: { 69236 + sqlite3_vtab_cursor *pVCur = pCx->uc.pVCur; 69237 + const sqlite3_module *pModule = pVCur->pVtab->pModule; 69238 + assert( pVCur->pVtab->nRef>0 ); 69239 + pVCur->pVtab->nRef--; 69240 + pModule->xClose(pVCur); 69241 + break; 69242 + } 69243 +#endif 69244 + } 68532 69245 } 68533 69246 68534 69247 /* 68535 69248 ** Close all cursors in the current frame. 68536 69249 */ 68537 69250 static void closeCursorsInFrame(Vdbe *p){ 68538 69251 if( p->apCsr ){ ................................................................................ 69511 70224 static int SQLITE_NOINLINE handleDeferredMoveto(VdbeCursor *p){ 69512 70225 int res, rc; 69513 70226 #ifdef SQLITE_TEST 69514 70227 extern int sqlite3_search_count; 69515 70228 #endif 69516 70229 assert( p->deferredMoveto ); 69517 70230 assert( p->isTable ); 69518 - rc = sqlite3BtreeMovetoUnpacked(p->pCursor, 0, p->movetoTarget, 0, &res); 70231 + assert( p->eCurType==CURTYPE_BTREE ); 70232 + rc = sqlite3BtreeMovetoUnpacked(p->uc.pCursor, 0, p->movetoTarget, 0, &res); 69519 70233 if( rc ) return rc; 69520 70234 if( res!=0 ) return SQLITE_CORRUPT_BKPT; 69521 70235 #ifdef SQLITE_TEST 69522 70236 sqlite3_search_count++; 69523 70237 #endif 69524 70238 p->deferredMoveto = 0; 69525 70239 p->cacheStatus = CACHE_STALE; ................................................................................ 69531 70245 ** pointed to was deleted out from under it. Or maybe the btree was 69532 70246 ** rebalanced. Whatever the cause, try to restore "p" to the place it 69533 70247 ** is supposed to be pointing. If the row was deleted out from under the 69534 70248 ** cursor, set the cursor to point to a NULL row. 69535 70249 */ 69536 70250 static int SQLITE_NOINLINE handleMovedCursor(VdbeCursor *p){ 69537 70251 int isDifferentRow, rc; 69538 - assert( p->pCursor!=0 ); 69539 - assert( sqlite3BtreeCursorHasMoved(p->pCursor) ); 69540 - rc = sqlite3BtreeCursorRestore(p->pCursor, &isDifferentRow); 70252 + assert( p->eCurType==CURTYPE_BTREE ); 70253 + assert( p->uc.pCursor!=0 ); 70254 + assert( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ); 70255 + rc = sqlite3BtreeCursorRestore(p->uc.pCursor, &isDifferentRow); 69541 70256 p->cacheStatus = CACHE_STALE; 69542 70257 if( isDifferentRow ) p->nullRow = 1; 69543 70258 return rc; 69544 70259 } 69545 70260 69546 70261 /* 69547 70262 ** Check to ensure that the cursor is valid. Restore the cursor 69548 70263 ** if need be. Return any I/O error from the restore operation. 69549 70264 */ 69550 70265 SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor *p){ 69551 - if( sqlite3BtreeCursorHasMoved(p->pCursor) ){ 70266 + assert( p->eCurType==CURTYPE_BTREE ); 70267 + if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){ 69552 70268 return handleMovedCursor(p); 69553 70269 } 69554 70270 return SQLITE_OK; 69555 70271 } 69556 70272 69557 70273 /* 69558 70274 ** Make sure the cursor p is ready to read or write the row to which it ................................................................................ 69564 70280 ** deleted out from under the cursor and if it has, mark the row as 69565 70281 ** a NULL row. 69566 70282 ** 69567 70283 ** If the cursor is already pointing to the correct row and that row has 69568 70284 ** not been deleted out from under the cursor, then this routine is a no-op. 69569 70285 */ 69570 70286 SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor *p){ 69571 - if( p->deferredMoveto ){ 69572 - return handleDeferredMoveto(p); 69573 - } 69574 - if( p->pCursor && sqlite3BtreeCursorHasMoved(p->pCursor) ){ 69575 - return handleMovedCursor(p); 70287 + if( p->eCurType==CURTYPE_BTREE ){ 70288 + if( p->deferredMoveto ){ 70289 + return handleDeferredMoveto(p); 70290 + } 70291 + if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){ 70292 + return handleMovedCursor(p); 70293 + } 69576 70294 } 69577 70295 return SQLITE_OK; 69578 70296 } 69579 70297 69580 70298 /* 69581 70299 ** The following functions: 69582 70300 ** ................................................................................ 69618 70336 ** The 8 and 9 types were added in 3.3.0, file format 4. Prior versions 69619 70337 ** of SQLite will not understand those serial types. 69620 70338 */ 69621 70339 69622 70340 /* 69623 70341 ** Return the serial-type for the value stored in pMem. 69624 70342 */ 69625 -SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem *pMem, int file_format){ 70343 +SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem *pMem, int file_format, u32 *pLen){ 69626 70344 int flags = pMem->flags; 69627 70345 u32 n; 69628 70346 70347 + assert( pLen!=0 ); 69629 70348 if( flags&MEM_Null ){ 70349 + *pLen = 0; 69630 70350 return 0; 69631 70351 } 69632 70352 if( flags&MEM_Int ){ 69633 70353 /* Figure out whether to use 1, 2, 4, 6 or 8 bytes. */ 69634 70354 # define MAX_6BYTE ((((i64)0x00008000)<<32)-1) 69635 70355 i64 i = pMem->u.i; 69636 70356 u64 u; 69637 70357 if( i<0 ){ 69638 70358 u = ~i; 69639 70359 }else{ 69640 70360 u = i; 69641 70361 } 69642 70362 if( u<=127 ){ 69643 - return ((i&1)==i && file_format>=4) ? 8+(u32)u : 1; 70363 + if( (i&1)==i && file_format>=4 ){ 70364 + *pLen = 0; 70365 + return 8+(u32)u; 70366 + }else{ 70367 + *pLen = 1; 70368 + return 1; 70369 + } 69644 70370 } 69645 - if( u<=32767 ) return 2; 69646 - if( u<=8388607 ) return 3; 69647 - if( u<=2147483647 ) return 4; 69648 - if( u<=MAX_6BYTE ) return 5; 70371 + if( u<=32767 ){ *pLen = 2; return 2; } 70372 + if( u<=8388607 ){ *pLen = 3; return 3; } 70373 + if( u<=2147483647 ){ *pLen = 4; return 4; } 70374 + if( u<=MAX_6BYTE ){ *pLen = 6; return 5; } 70375 + *pLen = 8; 69649 70376 return 6; 69650 70377 } 69651 70378 if( flags&MEM_Real ){ 70379 + *pLen = 8; 69652 70380 return 7; 69653 70381 } 69654 70382 assert( pMem->db->mallocFailed || flags&(MEM_Str|MEM_Blob) ); 69655 70383 assert( pMem->n>=0 ); 69656 70384 n = (u32)pMem->n; 69657 70385 if( flags & MEM_Zero ){ 69658 70386 n += pMem->u.nZero; 69659 70387 } 70388 + *pLen = n; 69660 70389 return ((n*2) + 12 + ((flags&MEM_Str)!=0)); 69661 70390 } 69662 70391 69663 70392 /* 69664 -** The sizes for serial types less than 12 70393 +** The sizes for serial types less than 128 69665 70394 */ 69666 70395 static const u8 sqlite3SmallTypeSizes[] = { 69667 - 0, 1, 2, 3, 4, 6, 8, 8, 0, 0, 0, 0 70396 + /* 0 1 2 3 4 5 6 7 8 9 */ 70397 +/* 0 */ 0, 1, 2, 3, 4, 6, 8, 8, 0, 0, 70398 +/* 10 */ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 70399 +/* 20 */ 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 70400 +/* 30 */ 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 70401 +/* 40 */ 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 70402 +/* 50 */ 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 70403 +/* 60 */ 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 70404 +/* 70 */ 29, 29, 30, 30, 31, 31, 32, 32, 33, 33, 70405 +/* 80 */ 34, 34, 35, 35, 36, 36, 37, 37, 38, 38, 70406 +/* 90 */ 39, 39, 40, 40, 41, 41, 42, 42, 43, 43, 70407 +/* 100 */ 44, 44, 45, 45, 46, 46, 47, 47, 48, 48, 70408 +/* 110 */ 49, 49, 50, 50, 51, 51, 52, 52, 53, 53, 70409 +/* 120 */ 54, 54, 55, 55, 56, 56, 57, 57 69668 70410 }; 69669 70411 69670 70412 /* 69671 70413 ** Return the length of the data corresponding to the supplied serial-type. 69672 70414 */ 69673 70415 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32 serial_type){ 69674 - if( serial_type>=12 ){ 70416 + if( serial_type>=128 ){ 69675 70417 return (serial_type-12)/2; 69676 70418 }else{ 70419 + assert( serial_type<12 70420 + || sqlite3SmallTypeSizes[serial_type]==(serial_type - 12)/2 ); 69677 70421 return sqlite3SmallTypeSizes[serial_type]; 69678 70422 } 70423 +} 70424 +SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen(u8 serial_type){ 70425 + assert( serial_type<128 ); 70426 + return sqlite3SmallTypeSizes[serial_type]; 69679 70427 } 69680 70428 69681 70429 /* 69682 70430 ** If we are on an architecture with mixed-endian floating 69683 70431 ** points (ex: ARM7) then swap the lower 4 bytes with the 69684 70432 ** upper 4 bytes. Return the result. 69685 70433 ** ................................................................................ 69768 70516 } 69769 70517 69770 70518 /* String or blob */ 69771 70519 if( serial_type>=12 ){ 69772 70520 assert( pMem->n + ((pMem->flags & MEM_Zero)?pMem->u.nZero:0) 69773 70521 == (int)sqlite3VdbeSerialTypeLen(serial_type) ); 69774 70522 len = pMem->n; 69775 - memcpy(buf, pMem->z, len); 70523 + if( len>0 ) memcpy(buf, pMem->z, len); 69776 70524 return len; 69777 70525 } 69778 70526 69779 70527 /* NULL or constants 0 or 1 */ 69780 70528 return 0; 69781 70529 } 69782 70530 ................................................................................ 69871 70619 testcase( pMem->u.i<0 ); 69872 70620 return 3; 69873 70621 } 69874 70622 case 4: { /* 4-byte signed integer */ 69875 70623 /* EVIDENCE-OF: R-01849-26079 Value is a big-endian 32-bit 69876 70624 ** twos-complement integer. */ 69877 70625 pMem->u.i = FOUR_BYTE_INT(buf); 70626 +#ifdef __HP_cc 70627 + /* Work around a sign-extension bug in the HP compiler for HP/UX */ 70628 + if( buf[0]&0x80 ) pMem->u.i |= 0xffffffff80000000LL; 70629 +#endif 69878 70630 pMem->flags = MEM_Int; 69879 70631 testcase( pMem->u.i<0 ); 69880 70632 return 4; 69881 70633 } 69882 70634 case 5: { /* 6-byte signed integer */ 69883 70635 /* EVIDENCE-OF: R-50385-09674 Value is a big-endian 48-bit 69884 70636 ** twos-complement integer. */ ................................................................................ 70186 70938 */ 70187 70939 static SQLITE_NOINLINE int sqlite3BlobCompare(const Mem *pB1, const Mem *pB2){ 70188 70940 int c = memcmp(pB1->z, pB2->z, pB1->n>pB2->n ? pB2->n : pB1->n); 70189 70941 if( c ) return c; 70190 70942 return pB1->n - pB2->n; 70191 70943 } 70192 70944 70945 +/* 70946 +** Do a comparison between a 64-bit signed integer and a 64-bit floating-point 70947 +** number. Return negative, zero, or positive if the first (i64) is less than, 70948 +** equal to, or greater than the second (double). 70949 +*/ 70950 +static int sqlite3IntFloatCompare(i64 i, double r){ 70951 + if( sizeof(LONGDOUBLE_TYPE)>8 ){ 70952 + LONGDOUBLE_TYPE x = (LONGDOUBLE_TYPE)i; 70953 + if( x<r ) return -1; 70954 + if( x>r ) return +1; 70955 + return 0; 70956 + }else{ 70957 + i64 y; 70958 + double s; 70959 + if( r<-9223372036854775808.0 ) return +1; 70960 + if( r>9223372036854775807.0 ) return -1; 70961 + y = (i64)r; 70962 + if( i<y ) return -1; 70963 + if( i>y ){ 70964 + if( y==SMALLEST_INT64 && r>0.0 ) return -1; 70965 + return +1; 70966 + } 70967 + s = (double)i; 70968 + if( s<r ) return -1; 70969 + if( s>r ) return +1; 70970 + return 0; 70971 + } 70972 +} 70193 70973 70194 70974 /* 70195 70975 ** Compare the values contained by the two memory cells, returning 70196 70976 ** negative, zero or positive if pMem1 is less than, equal to, or greater 70197 70977 ** than pMem2. Sorting order is NULL's first, followed by numbers (integers 70198 70978 ** and reals) sorted numerically, followed by text ordered by the collating 70199 70979 ** sequence pColl and finally blob's ordered by memcmp(). ................................................................................ 70212 70992 /* If one value is NULL, it is less than the other. If both values 70213 70993 ** are NULL, return 0. 70214 70994 */ 70215 70995 if( combined_flags&MEM_Null ){ 70216 70996 return (f2&MEM_Null) - (f1&MEM_Null); 70217 70997 } 70218 70998 70219 - /* If one value is a number and the other is not, the number is less. 70220 - ** If both are numbers, compare as reals if one is a real, or as integers 70221 - ** if both values are integers. 70999 + /* At least one of the two values is a number 70222 71000 */ 70223 71001 if( combined_flags&(MEM_Int|MEM_Real) ){ 70224 - double r1, r2; 70225 71002 if( (f1 & f2 & MEM_Int)!=0 ){ 70226 71003 if( pMem1->u.i < pMem2->u.i ) return -1; 70227 - if( pMem1->u.i > pMem2->u.i ) return 1; 71004 + if( pMem1->u.i > pMem2->u.i ) return +1; 70228 71005 return 0; 71006 + } 71007 + if( (f1 & f2 & MEM_Real)!=0 ){ 71008 + if( pMem1->u.r < pMem2->u.r ) return -1; 71009 + if( pMem1->u.r > pMem2->u.r ) return +1; 71010 + return 0; 71011 + } 71012 + if( (f1&MEM_Int)!=0 ){ 71013 + if( (f2&MEM_Real)!=0 ){ 71014 + return sqlite3IntFloatCompare(pMem1->u.i, pMem2->u.r); 71015 + }else{ 71016 + return -1; 71017 + } 70229 71018 } 70230 71019 if( (f1&MEM_Real)!=0 ){ 70231 - r1 = pMem1->u.r; 70232 - }else if( (f1&MEM_Int)!=0 ){ 70233 - r1 = (double)pMem1->u.i; 70234 - }else{ 70235 - return 1; 71020 + if( (f2&MEM_Int)!=0 ){ 71021 + return -sqlite3IntFloatCompare(pMem2->u.i, pMem1->u.r); 71022 + }else{ 71023 + return -1; 71024 + } 70236 71025 } 70237 - if( (f2&MEM_Real)!=0 ){ 70238 - r2 = pMem2->u.r; 70239 - }else if( (f2&MEM_Int)!=0 ){ 70240 - r2 = (double)pMem2->u.i; 70241 - }else{ 70242 - return -1; 70243 - } 70244 - if( r1<r2 ) return -1; 70245 - if( r1>r2 ) return 1; 70246 - return 0; 71026 + return +1; 70247 71027 } 70248 71028 70249 71029 /* If one value is a string and the other is a blob, the string is less. 70250 71030 ** If both are strings, compare using the collating functions. 70251 71031 */ 70252 71032 if( combined_flags&MEM_Str ){ 70253 71033 if( (f1 & MEM_Str)==0 ){ 70254 71034 return 1; 70255 71035 } 70256 71036 if( (f2 & MEM_Str)==0 ){ 70257 71037 return -1; 70258 71038 } 70259 71039 70260 - assert( pMem1->enc==pMem2->enc ); 71040 + assert( pMem1->enc==pMem2->enc || pMem1->db->mallocFailed ); 70261 71041 assert( pMem1->enc==SQLITE_UTF8 || 70262 71042 pMem1->enc==SQLITE_UTF16LE || pMem1->enc==SQLITE_UTF16BE ); 70263 71043 70264 71044 /* The collation sequence must be defined at this point, even if 70265 71045 ** the user deletes the collation sequence after the vdbe program is 70266 71046 ** compiled (this was not always the case). 70267 71047 */ ................................................................................ 70390 71170 serial_type = aKey1[idx1]; 70391 71171 testcase( serial_type==12 ); 70392 71172 if( serial_type>=10 ){ 70393 71173 rc = +1; 70394 71174 }else if( serial_type==0 ){ 70395 71175 rc = -1; 70396 71176 }else if( serial_type==7 ){ 70397 - double rhs = (double)pRhs->u.i; 70398 71177 sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1); 70399 - if( mem1.u.r<rhs ){ 70400 - rc = -1; 70401 - }else if( mem1.u.r>rhs ){ 70402 - rc = +1; 70403 - } 71178 + rc = -sqlite3IntFloatCompare(pRhs->u.i, mem1.u.r); 70404 71179 }else{ 70405 71180 i64 lhs = vdbeRecordDecodeInt(serial_type, &aKey1[d1]); 70406 71181 i64 rhs = pRhs->u.i; 70407 71182 if( lhs<rhs ){ 70408 71183 rc = -1; 70409 71184 }else if( lhs>rhs ){ 70410 71185 rc = +1; ................................................................................ 70420 71195 ** numbers). Types 10 and 11 are currently "reserved for future 70421 71196 ** use", so it doesn't really matter what the results of comparing 70422 71197 ** them to numberic values are. */ 70423 71198 rc = +1; 70424 71199 }else if( serial_type==0 ){ 70425 71200 rc = -1; 70426 71201 }else{ 70427 - double rhs = pRhs->u.r; 70428 - double lhs; 70429 71202 sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1); 70430 71203 if( serial_type==7 ){ 70431 - lhs = mem1.u.r; 71204 + if( mem1.u.r<pRhs->u.r ){ 71205 + rc = -1; 71206 + }else if( mem1.u.r>pRhs->u.r ){ 71207 + rc = +1; 71208 + } 70432 71209 }else{ 70433 - lhs = (double)mem1.u.i; 70434 - } 70435 - if( lhs<rhs ){ 70436 - rc = -1; 70437 - }else if( lhs>rhs ){ 70438 - rc = +1; 71210 + rc = sqlite3IntFloatCompare(mem1.u.i, pRhs->u.r); 70439 71211 } 70440 71212 } 70441 71213 } 70442 71214 70443 71215 /* RHS is a string */ 70444 71216 else if( pRhs->flags & MEM_Str ){ 70445 71217 getVarint32(&aKey1[idx1], serial_type); ................................................................................ 70521 71293 /* rc==0 here means that one or both of the keys ran out of fields and 70522 71294 ** all the fields up to that point were equal. Return the default_rc 70523 71295 ** value. */ 70524 71296 assert( CORRUPT_DB 70525 71297 || vdbeRecordCompareDebug(nKey1, pKey1, pPKey2, pPKey2->default_rc) 70526 71298 || pKeyInfo->db->mallocFailed 70527 71299 ); 71300 + pPKey2->eqSeen = 1; 70528 71301 return pPKey2->default_rc; 70529 71302 } 70530 71303 SQLITE_PRIVATE int sqlite3VdbeRecordCompare( 70531 71304 int nKey1, const void *pKey1, /* Left key */ 70532 71305 UnpackedRecord *pPKey2 /* Right key */ 70533 71306 ){ 70534 71307 return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0); ................................................................................ 70620 71393 /* The first fields of the two keys are equal. Compare the trailing 70621 71394 ** fields. */ 70622 71395 res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); 70623 71396 }else{ 70624 71397 /* The first fields of the two keys are equal and there are no trailing 70625 71398 ** fields. Return pPKey2->default_rc in this case. */ 70626 71399 res = pPKey2->default_rc; 71400 + pPKey2->eqSeen = 1; 70627 71401 } 70628 71402 70629 71403 assert( vdbeRecordCompareDebug(nKey1, pKey1, pPKey2, res) ); 70630 71404 return res; 70631 71405 } 70632 71406 70633 71407 /* ................................................................................ 70640 71414 int nKey1, const void *pKey1, /* Left key */ 70641 71415 UnpackedRecord *pPKey2 /* Right key */ 70642 71416 ){ 70643 71417 const u8 *aKey1 = (const u8*)pKey1; 70644 71418 int serial_type; 70645 71419 int res; 70646 71420 71421 + assert( pPKey2->aMem[0].flags & MEM_Str ); 70647 71422 vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo); 70648 71423 getVarint32(&aKey1[1], serial_type); 70649 71424 if( serial_type<12 ){ 70650 71425 res = pPKey2->r1; /* (pKey1/nKey1) is a number or a null */ 70651 71426 }else if( !(serial_type & 0x01) ){ 70652 71427 res = pPKey2->r2; /* (pKey1/nKey1) is a blob */ 70653 71428 }else{ ................................................................................ 70666 71441 if( res==0 ){ 70667 71442 res = nStr - pPKey2->aMem[0].n; 70668 71443 if( res==0 ){ 70669 71444 if( pPKey2->nField>1 ){ 70670 71445 res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); 70671 71446 }else{ 70672 71447 res = pPKey2->default_rc; 71448 + pPKey2->eqSeen = 1; 70673 71449 } 70674 71450 }else if( res>0 ){ 70675 71451 res = pPKey2->r2; 70676 71452 }else{ 70677 71453 res = pPKey2->r1; 70678 71454 } 70679 71455 }else if( res>0 ){ ................................................................................ 70823 71599 sqlite3 *db, /* Database connection */ 70824 71600 VdbeCursor *pC, /* The cursor to compare against */ 70825 71601 UnpackedRecord *pUnpacked, /* Unpacked version of key */ 70826 71602 int *res /* Write the comparison result here */ 70827 71603 ){ 70828 71604 i64 nCellKey = 0; 70829 71605 int rc; 70830 - BtCursor *pCur = pC->pCursor; 71606 + BtCursor *pCur; 70831 71607 Mem m; 70832 71608 71609 + assert( pC->eCurType==CURTYPE_BTREE ); 71610 + pCur = pC->uc.pCursor; 70833 71611 assert( sqlite3BtreeCursorIsValid(pCur) ); 70834 71612 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey); 70835 71613 assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */ 70836 71614 /* nCellKey will always be between 0 and 0xffffffff because of the way 70837 71615 ** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */ 70838 71616 if( nCellKey<=0 || nCellKey>0x7fffffff ){ 70839 71617 *res = 0; 70840 71618 return SQLITE_CORRUPT_BKPT; 70841 71619 } 70842 71620 sqlite3VdbeMemInit(&m, db, 0); 70843 - rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (u32)nCellKey, 1, &m); 71621 + rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, 1, &m); 70844 71622 if( rc ){ 70845 71623 return rc; 70846 71624 } 70847 71625 *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked); 70848 71626 sqlite3VdbeMemRelease(&m); 70849 71627 return SQLITE_OK; 70850 71628 } ................................................................................ 72971 73749 ** converts an MEM_Ephem string into a string with P.z==P.zMalloc. 72972 73750 */ 72973 73751 #define Deephemeralize(P) \ 72974 73752 if( ((P)->flags&MEM_Ephem)!=0 \ 72975 73753 && sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;} 72976 73754 72977 73755 /* Return true if the cursor was opened using the OP_OpenSorter opcode. */ 72978 -#define isSorter(x) ((x)->pSorter!=0) 73756 +#define isSorter(x) ((x)->eCurType==CURTYPE_SORTER) 72979 73757 72980 73758 /* 72981 73759 ** Allocate VdbeCursor number iCur. Return a pointer to it. Return NULL 72982 73760 ** if we run out of memory. 72983 73761 */ 72984 73762 static VdbeCursor *allocateCursor( 72985 73763 Vdbe *p, /* The virtual machine */ 72986 73764 int iCur, /* Index of the new VdbeCursor */ 72987 73765 int nField, /* Number of fields in the table or index */ 72988 73766 int iDb, /* Database the cursor belongs to, or -1 */ 72989 - int isBtreeCursor /* True for B-Tree. False for pseudo-table or vtab */ 73767 + u8 eCurType /* Type of the new cursor */ 72990 73768 ){ 72991 73769 /* Find the memory cell that will be used to store the blob of memory 72992 73770 ** required for this VdbeCursor structure. It is convenient to use a 72993 73771 ** vdbe memory cell to manage the memory allocation required for a 72994 73772 ** VdbeCursor structure for the following reasons: 72995 73773 ** 72996 73774 ** * Sometimes cursor numbers are used for a couple of different ................................................................................ 73008 73786 */ 73009 73787 Mem *pMem = &p->aMem[p->nMem-iCur]; 73010 73788 73011 73789 int nByte; 73012 73790 VdbeCursor *pCx = 0; 73013 73791 nByte = 73014 73792 ROUND8(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField + 73015 - (isBtreeCursor?sqlite3BtreeCursorSize():0); 73793 + (eCurType==CURTYPE_BTREE?sqlite3BtreeCursorSize():0); 73016 73794 73017 73795 assert( iCur<p->nCursor ); 73018 73796 if( p->apCsr[iCur] ){ 73019 73797 sqlite3VdbeFreeCursor(p, p->apCsr[iCur]); 73020 73798 p->apCsr[iCur] = 0; 73021 73799 } 73022 73800 if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){ 73023 73801 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z; 73024 73802 memset(pCx, 0, sizeof(VdbeCursor)); 73803 + pCx->eCurType = eCurType; 73025 73804 pCx->iDb = iDb; 73026 73805 pCx->nField = nField; 73027 73806 pCx->aOffset = &pCx->aType[nField]; 73028 - if( isBtreeCursor ){ 73029 - pCx->pCursor = (BtCursor*) 73807 + if( eCurType==CURTYPE_BTREE ){ 73808 + pCx->uc.pCursor = (BtCursor*) 73030 73809 &pMem->z[ROUND8(sizeof(VdbeCursor))+2*sizeof(u32)*nField]; 73031 - sqlite3BtreeCursorZero(pCx->pCursor); 73810 + sqlite3BtreeCursorZero(pCx->uc.pCursor); 73032 73811 } 73033 73812 } 73034 73813 return pCx; 73035 73814 } 73036 73815 73037 73816 /* 73038 73817 ** Try to convert a value into a numeric representation if we can ................................................................................ 73413 74192 return 1; 73414 74193 } 73415 74194 #endif 73416 74195 73417 74196 /* 73418 74197 ** Return the register of pOp->p2 after first preparing it to be 73419 74198 ** overwritten with an integer value. 73420 -*/ 74199 +*/ 74200 +static SQLITE_NOINLINE Mem *out2PrereleaseWithClear(Mem *pOut){ 74201 + sqlite3VdbeMemSetNull(pOut); 74202 + pOut->flags = MEM_Int; 74203 + return pOut; 74204 +} 73421 74205 static Mem *out2Prerelease(Vdbe *p, VdbeOp *pOp){ 73422 74206 Mem *pOut; 73423 74207 assert( pOp->p2>0 ); 73424 74208 assert( pOp->p2<=(p->nMem-p->nCursor) ); 73425 74209 pOut = &p->aMem[pOp->p2]; 73426 74210 memAboutToChange(p, pOut); 73427 - if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut); 73428 - pOut->flags = MEM_Int; 73429 - return pOut; 74211 + if( VdbeMemDynamic(pOut) ){ 74212 + return out2PrereleaseWithClear(pOut); 74213 + }else{ 74214 + pOut->flags = MEM_Int; 74215 + return pOut; 74216 + } 73430 74217 } 73431 74218 73432 74219 73433 74220 /* 73434 74221 ** Execute as much of a VDBE program as we can. 73435 74222 ** This is the core of sqlite3_step(). 73436 74223 */ ................................................................................ 73974 74761 assert( pOp->p4.z!=0 ); 73975 74762 pOut = out2Prerelease(p, pOp); 73976 74763 pOut->flags = MEM_Str|MEM_Static|MEM_Term; 73977 74764 pOut->z = pOp->p4.z; 73978 74765 pOut->n = pOp->p1; 73979 74766 pOut->enc = encoding; 73980 74767 UPDATE_MAX_BLOBSIZE(pOut); 74768 +#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS 73981 74769 if( pOp->p5 ){ 73982 74770 assert( pOp->p3>0 ); 73983 74771 assert( pOp->p3<=(p->nMem-p->nCursor) ); 73984 74772 pIn3 = &aMem[pOp->p3]; 73985 74773 assert( pIn3->flags & MEM_Int ); 73986 74774 if( pIn3->u.i ) pOut->flags = MEM_Blob|MEM_Static|MEM_Term; 73987 74775 } 74776 +#endif 73988 74777 break; 73989 74778 } 73990 74779 73991 74780 /* Opcode: Null P1 P2 P3 * * 73992 74781 ** Synopsis: r[P2..P3]=NULL 73993 74782 ** 73994 74783 ** Write a NULL into registers P2. If P3 greater than P2, then also write ................................................................................ 74159 74948 assert( pOut!=pIn1 ); 74160 74949 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem); 74161 74950 #ifdef SQLITE_DEBUG 74162 74951 if( pOut->pScopyFrom==0 ) pOut->pScopyFrom = pIn1; 74163 74952 #endif 74164 74953 break; 74165 74954 } 74955 + 74956 +/* Opcode: IntCopy P1 P2 * * * 74957 +** Synopsis: r[P2]=r[P1] 74958 +** 74959 +** Transfer the integer value held in register P1 into register P2. 74960 +** 74961 +** This is an optimized version of SCopy that works only for integer 74962 +** values. 74963 +*/ 74964 +case OP_IntCopy: { /* out2 */ 74965 + pIn1 = &aMem[pOp->p1]; 74966 + assert( (pIn1->flags & MEM_Int)!=0 ); 74967 + pOut = &aMem[pOp->p2]; 74968 + sqlite3VdbeMemSetInt64(pOut, pIn1->u.i); 74969 + break; 74970 +} 74166 74971 74167 74972 /* Opcode: ResultRow P1 P2 * * * 74168 74973 ** Synopsis: output=r[P1@P2] 74169 74974 ** 74170 74975 ** The registers P1 through P1+P2-1 contain a single row of 74171 74976 ** results. This opcode causes the sqlite3_step() call to terminate 74172 74977 ** with an SQLITE_ROW return code and it sets up the sqlite3_stmt ................................................................................ 74849 75654 }else{ 74850 75655 /* SQLITE_NULLEQ is clear and at least one operand is NULL, 74851 75656 ** then the result is always NULL. 74852 75657 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set. 74853 75658 */ 74854 75659 if( pOp->p5 & SQLITE_STOREP2 ){ 74855 75660 pOut = &aMem[pOp->p2]; 75661 + memAboutToChange(p, pOut); 74856 75662 MemSetTypeFlag(pOut, MEM_Null); 74857 75663 REGISTER_TRACE(pOp->p2, pOut); 74858 75664 }else{ 74859 75665 VdbeBranchTaken(2,3); 74860 75666 if( pOp->p5 & SQLITE_JUMPIFNULL ){ 74861 75667 goto jump_to_p2; 74862 75668 } ................................................................................ 74863 75669 } 74864 75670 break; 74865 75671 } 74866 75672 }else{ 74867 75673 /* Neither operand is NULL. Do a comparison. */ 74868 75674 affinity = pOp->p5 & SQLITE_AFF_MASK; 74869 75675 if( affinity>=SQLITE_AFF_NUMERIC ){ 74870 - if( (pIn1->flags & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){ 75676 + if( (flags1 & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){ 74871 75677 applyNumericAffinity(pIn1,0); 74872 75678 } 74873 - if( (pIn3->flags & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){ 75679 + if( (flags3 & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){ 74874 75680 applyNumericAffinity(pIn3,0); 74875 75681 } 74876 75682 }else if( affinity==SQLITE_AFF_TEXT ){ 74877 - if( (pIn1->flags & MEM_Str)==0 && (pIn1->flags & (MEM_Int|MEM_Real))!=0 ){ 75683 + if( (flags1 & MEM_Str)==0 && (flags1 & (MEM_Int|MEM_Real))!=0 ){ 74878 75684 testcase( pIn1->flags & MEM_Int ); 74879 75685 testcase( pIn1->flags & MEM_Real ); 74880 75686 sqlite3VdbeMemStringify(pIn1, encoding, 1); 74881 75687 testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) ); 74882 75688 flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask); 74883 75689 } 74884 - if( (pIn3->flags & MEM_Str)==0 && (pIn3->flags & (MEM_Int|MEM_Real))!=0 ){ 75690 + if( (flags3 & MEM_Str)==0 && (flags3 & (MEM_Int|MEM_Real))!=0 ){ 74885 75691 testcase( pIn3->flags & MEM_Int ); 74886 75692 testcase( pIn3->flags & MEM_Real ); 74887 75693 sqlite3VdbeMemStringify(pIn3, encoding, 1); 74888 75694 testcase( (flags3&MEM_Dyn) != (pIn3->flags&MEM_Dyn) ); 74889 75695 flags3 = (pIn3->flags & ~MEM_TypeMask) | (flags3 & MEM_TypeMask); 74890 75696 } 74891 75697 } 74892 75698 assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 ); 74893 - if( pIn1->flags & MEM_Zero ){ 75699 + if( flags1 & MEM_Zero ){ 74894 75700 sqlite3VdbeMemExpandBlob(pIn1); 74895 75701 flags1 &= ~MEM_Zero; 74896 75702 } 74897 - if( pIn3->flags & MEM_Zero ){ 75703 + if( flags3 & MEM_Zero ){ 74898 75704 sqlite3VdbeMemExpandBlob(pIn3); 74899 75705 flags3 &= ~MEM_Zero; 74900 75706 } 74901 - if( db->mallocFailed ) goto no_mem; 74902 75707 res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl); 74903 75708 } 74904 75709 switch( pOp->opcode ){ 74905 75710 case OP_Eq: res = res==0; break; 74906 75711 case OP_Ne: res = res!=0; break; 74907 75712 case OP_Lt: res = res<0; break; 74908 75713 case OP_Le: res = res<=0; break; ................................................................................ 75239 76044 int i; /* Loop counter */ 75240 76045 Mem *pDest; /* Where to write the extracted value */ 75241 76046 Mem sMem; /* For storing the record being decoded */ 75242 76047 const u8 *zData; /* Part of the record being decoded */ 75243 76048 const u8 *zHdr; /* Next unparsed byte of the header */ 75244 76049 const u8 *zEndHdr; /* Pointer to first byte after the header */ 75245 76050 u32 offset; /* Offset into the data */ 75246 - u32 szField; /* Number of bytes in the content of a field */ 76051 + u64 offset64; /* 64-bit offset */ 75247 76052 u32 avail; /* Number of bytes of available data */ 75248 76053 u32 t; /* A type code from the record header */ 75249 76054 u16 fx; /* pDest->flags value */ 75250 76055 Mem *pReg; /* PseudoTable input register */ 75251 76056 75252 76057 p2 = pOp->p2; 75253 76058 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); ................................................................................ 75254 76059 pDest = &aMem[pOp->p3]; 75255 76060 memAboutToChange(p, pDest); 75256 76061 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 75257 76062 pC = p->apCsr[pOp->p1]; 75258 76063 assert( pC!=0 ); 75259 76064 assert( p2<pC->nField ); 75260 76065 aOffset = pC->aOffset; 75261 -#ifndef SQLITE_OMIT_VIRTUALTABLE 75262 - assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */ 75263 -#endif 75264 - pCrsr = pC->pCursor; 75265 - assert( pCrsr!=0 || pC->pseudoTableReg>0 ); /* pCrsr NULL on PseudoTables */ 75266 - assert( pCrsr!=0 || pC->nullRow ); /* pC->nullRow on PseudoTables */ 76066 + assert( pC->eCurType!=CURTYPE_VTAB ); 76067 + assert( pC->eCurType!=CURTYPE_PSEUDO || pC->nullRow ); 76068 + assert( pC->eCurType!=CURTYPE_SORTER ); 76069 + pCrsr = pC->uc.pCursor; 75267 76070 75268 76071 /* If the cursor cache is stale, bring it up-to-date */ 75269 76072 rc = sqlite3VdbeCursorMoveto(pC); 75270 76073 if( rc ) goto abort_due_to_error; 75271 76074 if( pC->cacheStatus!=p->cacheCtr ){ 75272 76075 if( pC->nullRow ){ 75273 - if( pCrsr==0 ){ 75274 - assert( pC->pseudoTableReg>0 ); 75275 - pReg = &aMem[pC->pseudoTableReg]; 76076 + if( pC->eCurType==CURTYPE_PSEUDO ){ 76077 + assert( pC->uc.pseudoTableReg>0 ); 76078 + pReg = &aMem[pC->uc.pseudoTableReg]; 75276 76079 assert( pReg->flags & MEM_Blob ); 75277 76080 assert( memIsValid(pReg) ); 75278 76081 pC->payloadSize = pC->szRow = avail = pReg->n; 75279 76082 pC->aRow = (u8*)pReg->z; 75280 76083 }else{ 75281 76084 sqlite3VdbeMemSetNull(pDest); 75282 76085 goto op_column_out; 75283 76086 } 75284 76087 }else{ 76088 + assert( pC->eCurType==CURTYPE_BTREE ); 75285 76089 assert( pCrsr ); 75286 76090 if( pC->isTable==0 ){ 75287 76091 assert( sqlite3BtreeCursorIsValid(pCrsr) ); 75288 76092 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &payloadSize64); 75289 76093 assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */ 75290 76094 /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the 75291 76095 ** payload size, so it is impossible for payloadSize64 to be ................................................................................ 75298 76102 VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &pC->payloadSize); 75299 76103 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ 75300 76104 pC->aRow = sqlite3BtreeDataFetch(pCrsr, &avail); 75301 76105 } 75302 76106 assert( avail<=65536 ); /* Maximum page size is 64KiB */ 75303 76107 if( pC->payloadSize <= (u32)avail ){ 75304 76108 pC->szRow = pC->payloadSize; 75305 - }else{ 75306 - pC->szRow = avail; 75307 - } 75308 - if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ 76109 + }else if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ 75309 76110 goto too_big; 76111 + }else{ 76112 + pC->szRow = avail; 75310 76113 } 75311 76114 } 75312 76115 pC->cacheStatus = p->cacheCtr; 75313 76116 pC->iHdrOffset = getVarint32(pC->aRow, offset); 75314 76117 pC->nHdrParsed = 0; 75315 76118 aOffset[0] = offset; 75316 76119 75317 - /* Make sure a corrupt database has not given us an oversize header. 75318 - ** Do this now to avoid an oversize memory allocation. 75319 - ** 75320 - ** Type entries can be between 1 and 5 bytes each. But 4 and 5 byte 75321 - ** types use so much data space that there can only be 4096 and 32 of 75322 - ** them, respectively. So the maximum header length results from a 75323 - ** 3-byte type for each of the maximum of 32768 columns plus three 75324 - ** extra bytes for the header length itself. 32768*3 + 3 = 98307. 75325 - */ 75326 - if( offset > 98307 || offset > pC->payloadSize ){ 75327 - rc = SQLITE_CORRUPT_BKPT; 75328 - goto op_column_error; 75329 - } 75330 76120 75331 76121 if( avail<offset ){ 75332 76122 /* pC->aRow does not have to hold the entire row, but it does at least 75333 76123 ** need to cover the header of the record. If pC->aRow does not contain 75334 76124 ** the complete header, then set it to zero, forcing the header to be 75335 76125 ** dynamically allocated. */ 75336 76126 pC->aRow = 0; 75337 76127 pC->szRow = 0; 76128 + 76129 + /* Make sure a corrupt database has not given us an oversize header. 76130 + ** Do this now to avoid an oversize memory allocation. 76131 + ** 76132 + ** Type entries can be between 1 and 5 bytes each. But 4 and 5 byte 76133 + ** types use so much data space that there can only be 4096 and 32 of 76134 + ** them, respectively. So the maximum header length results from a 76135 + ** 3-byte type for each of the maximum of 32768 columns plus three 76136 + ** extra bytes for the header length itself. 32768*3 + 3 = 98307. 76137 + */ 76138 + if( offset > 98307 || offset > pC->payloadSize ){ 76139 + rc = SQLITE_CORRUPT_BKPT; 76140 + goto op_column_error; 76141 + } 75338 76142 } 75339 76143 75340 76144 /* The following goto is an optimization. It can be omitted and 75341 76145 ** everything will still work. But OP_Column is measurably faster 75342 76146 ** by skipping the subsequent conditional, which is always true. 75343 76147 */ 75344 76148 assert( pC->nHdrParsed<=p2 ); /* Conditional skipped */ ................................................................................ 75353 76157 ** to extract additional fields up through the p2+1-th field 75354 76158 */ 75355 76159 op_column_read_header: 75356 76160 if( pC->iHdrOffset<aOffset[0] ){ 75357 76161 /* Make sure zData points to enough of the record to cover the header. */ 75358 76162 if( pC->aRow==0 ){ 75359 76163 memset(&sMem, 0, sizeof(sMem)); 75360 - rc = sqlite3VdbeMemFromBtree(pCrsr, 0, aOffset[0], 75361 - !pC->isTable, &sMem); 75362 - if( rc!=SQLITE_OK ){ 75363 - goto op_column_error; 75364 - } 76164 + rc = sqlite3VdbeMemFromBtree(pCrsr, 0, aOffset[0], !pC->isTable, &sMem); 76165 + if( rc!=SQLITE_OK ) goto op_column_error; 75365 76166 zData = (u8*)sMem.z; 75366 76167 }else{ 75367 76168 zData = pC->aRow; 75368 76169 } 75369 76170 75370 76171 /* Fill in pC->aType[i] and aOffset[i] values through the p2-th field. */ 75371 76172 i = pC->nHdrParsed; 75372 - offset = aOffset[i]; 76173 + offset64 = aOffset[i]; 75373 76174 zHdr = zData + pC->iHdrOffset; 75374 76175 zEndHdr = zData + aOffset[0]; 75375 76176 assert( i<=p2 && zHdr<zEndHdr ); 75376 76177 do{ 75377 - if( zHdr[0]<0x80 ){ 75378 - t = zHdr[0]; 76178 + if( (t = zHdr[0])<0x80 ){ 75379 76179 zHdr++; 76180 + offset64 += sqlite3VdbeOneByteSerialTypeLen(t); 75380 76181 }else{ 75381 76182 zHdr += sqlite3GetVarint32(zHdr, &t); 76183 + offset64 += sqlite3VdbeSerialTypeLen(t); 75382 76184 } 75383 - pC->aType[i] = t; 75384 - szField = sqlite3VdbeSerialTypeLen(t); 75385 - offset += szField; 75386 - if( offset<szField ){ /* True if offset overflows */ 75387 - zHdr = &zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */ 75388 - break; 75389 - } 75390 - i++; 75391 - aOffset[i] = offset; 76185 + pC->aType[i++] = t; 76186 + aOffset[i] = (u32)(offset64 & 0xffffffff); 75392 76187 }while( i<=p2 && zHdr<zEndHdr ); 75393 76188 pC->nHdrParsed = i; 75394 76189 pC->iHdrOffset = (u32)(zHdr - zData); 75395 - if( pC->aRow==0 ){ 75396 - sqlite3VdbeMemRelease(&sMem); 75397 - sMem.flags = MEM_Null; 75398 - } 76190 + if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem); 75399 76191 75400 76192 /* The record is corrupt if any of the following are true: 75401 76193 ** (1) the bytes of the header extend past the declared header size 75402 - ** (zHdr>zEndHdr) 75403 76194 ** (2) the entire header was used but not all data was used 75404 - ** (zHdr==zEndHdr && offset!=pC->payloadSize) 75405 76195 ** (3) the end of the data extends beyond the end of the record. 75406 - ** (offset > pC->payloadSize) 75407 76196 */ 75408 - if( (zHdr>=zEndHdr && (zHdr>zEndHdr || offset!=pC->payloadSize)) 75409 - || (offset > pC->payloadSize) 76197 + if( (zHdr>=zEndHdr && (zHdr>zEndHdr || offset64!=pC->payloadSize)) 76198 + || (offset64 > pC->payloadSize) 75410 76199 ){ 75411 76200 rc = SQLITE_CORRUPT_BKPT; 75412 76201 goto op_column_error; 75413 76202 } 76203 + }else{ 76204 + VVA_ONLY( t = 0; ) /* Only needed by assert() statements */ 75414 76205 } 75415 76206 75416 76207 /* If after trying to extract new entries from the header, nHdrParsed is 75417 76208 ** still not up to p2, that means that the record has fewer than p2 75418 76209 ** columns. So the result will be either the default value or a NULL. 75419 76210 */ 75420 76211 if( pC->nHdrParsed<=p2 ){ ................................................................................ 75421 76212 if( pOp->p4type==P4_MEM ){ 75422 76213 sqlite3VdbeMemShallowCopy(pDest, pOp->p4.pMem, MEM_Static); 75423 76214 }else{ 75424 76215 sqlite3VdbeMemSetNull(pDest); 75425 76216 } 75426 76217 goto op_column_out; 75427 76218 } 76219 + }else{ 76220 + t = pC->aType[p2]; 75428 76221 } 75429 76222 75430 76223 /* Extract the content for the p2+1-th column. Control can only 75431 76224 ** reach this point if aOffset[p2], aOffset[p2+1], and pC->aType[p2] are 75432 76225 ** all valid. 75433 76226 */ 75434 76227 assert( p2<pC->nHdrParsed ); 75435 76228 assert( rc==SQLITE_OK ); 75436 76229 assert( sqlite3VdbeCheckMemInvariants(pDest) ); 75437 76230 if( VdbeMemDynamic(pDest) ) sqlite3VdbeMemSetNull(pDest); 75438 - t = pC->aType[p2]; 76231 + assert( t==pC->aType[p2] ); 75439 76232 if( pC->szRow>=aOffset[p2+1] ){ 75440 76233 /* This is the common case where the desired content fits on the original 75441 76234 ** page - where the content is not on an overflow page */ 75442 76235 sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], t, pDest); 75443 76236 }else{ 75444 76237 /* This branch happens only when content is on overflow pages */ 75445 76238 if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0 ................................................................................ 75543 76336 Mem *pData0; /* First field to be combined into the record */ 75544 76337 Mem *pLast; /* Last field of the record */ 75545 76338 int nField; /* Number of fields in the record */ 75546 76339 char *zAffinity; /* The affinity string for the record */ 75547 76340 int file_format; /* File format to use for encoding */ 75548 76341 int i; /* Space used in zNewRecord[] header */ 75549 76342 int j; /* Space used in zNewRecord[] content */ 75550 - int len; /* Length of a field */ 76343 + u32 len; /* Length of a field */ 75551 76344 75552 76345 /* Assuming the record contains N fields, the record format looks 75553 76346 ** like this: 75554 76347 ** 75555 76348 ** ------------------------------------------------------------------------ 75556 76349 ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 | 75557 76350 ** ------------------------------------------------------------------------ ................................................................................ 75593 76386 75594 76387 /* Loop through the elements that will make up the record to figure 75595 76388 ** out how much space is required for the new record. 75596 76389 */ 75597 76390 pRec = pLast; 75598 76391 do{ 75599 76392 assert( memIsValid(pRec) ); 75600 - pRec->uTemp = serial_type = sqlite3VdbeSerialType(pRec, file_format); 75601 - len = sqlite3VdbeSerialTypeLen(serial_type); 76393 + pRec->uTemp = serial_type = sqlite3VdbeSerialType(pRec, file_format, &len); 75602 76394 if( pRec->flags & MEM_Zero ){ 75603 76395 if( nData ){ 75604 76396 if( sqlite3VdbeMemExpandBlob(pRec) ) goto no_mem; 75605 76397 }else{ 75606 76398 nZero += pRec->u.nZero; 75607 76399 len -= pRec->u.nZero; 75608 76400 } ................................................................................ 75680 76472 ** opened by cursor P1 in register P2 75681 76473 */ 75682 76474 #ifndef SQLITE_OMIT_BTREECOUNT 75683 76475 case OP_Count: { /* out2 */ 75684 76476 i64 nEntry; 75685 76477 BtCursor *pCrsr; 75686 76478 75687 - pCrsr = p->apCsr[pOp->p1]->pCursor; 76479 + assert( p->apCsr[pOp->p1]->eCurType==CURTYPE_BTREE ); 76480 + pCrsr = p->apCsr[pOp->p1]->uc.pCursor; 75688 76481 assert( pCrsr ); 75689 76482 nEntry = 0; /* Not needed. Only used to silence a warning. */ 75690 76483 rc = sqlite3BtreeCount(pCrsr, &nEntry); 75691 76484 pOut = out2Prerelease(p, pOp); 75692 76485 pOut->u.i = nEntry; 75693 76486 break; 75694 76487 } ................................................................................ 76208 77001 goto open_cursor_set_hints; 76209 77002 } 76210 77003 /* If the cursor is not currently open or is open on a different 76211 77004 ** index, then fall through into OP_OpenRead to force a reopen */ 76212 77005 case OP_OpenRead: 76213 77006 case OP_OpenWrite: 76214 77007 76215 - assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR|OPFLAG_SEEKEQ))==pOp->p5 ); 76216 77008 assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ ); 76217 77009 assert( p->bIsReader ); 76218 77010 assert( pOp->opcode==OP_OpenRead || pOp->opcode==OP_ReopenIdx 76219 77011 || p->readOnly==0 ); 76220 77012 76221 77013 if( p->expired ){ 76222 77014 rc = SQLITE_ABORT_ROLLBACK; ................................................................................ 76229 77021 iDb = pOp->p3; 76230 77022 assert( iDb>=0 && iDb<db->nDb ); 76231 77023 assert( DbMaskTest(p->btreeMask, iDb) ); 76232 77024 pDb = &db->aDb[iDb]; 76233 77025 pX = pDb->pBt; 76234 77026 assert( pX!=0 ); 76235 77027 if( pOp->opcode==OP_OpenWrite ){ 76236 - wrFlag = 1; 77028 + assert( OPFLAG_FORDELETE==BTREE_FORDELETE ); 77029 + wrFlag = BTREE_WRCSR | (pOp->p5 & OPFLAG_FORDELETE); 76237 77030 assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); 76238 77031 if( pDb->pSchema->file_format < p->minWriteFileFormat ){ 76239 77032 p->minWriteFileFormat = pDb->pSchema->file_format; 76240 77033 } 76241 77034 }else{ 76242 77035 wrFlag = 0; 76243 77036 } ................................................................................ 76265 77058 nField = pKeyInfo->nField+pKeyInfo->nXField; 76266 77059 }else if( pOp->p4type==P4_INT32 ){ 76267 77060 nField = pOp->p4.i; 76268 77061 } 76269 77062 assert( pOp->p1>=0 ); 76270 77063 assert( nField>=0 ); 76271 77064 testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */ 76272 - pCur = allocateCursor(p, pOp->p1, nField, iDb, 1); 77065 + pCur = allocateCursor(p, pOp->p1, nField, iDb, CURTYPE_BTREE); 76273 77066 if( pCur==0 ) goto no_mem; 76274 77067 pCur->nullRow = 1; 76275 77068 pCur->isOrdered = 1; 76276 77069 pCur->pgnoRoot = p2; 76277 - rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->pCursor); 77070 + rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->uc.pCursor); 76278 77071 pCur->pKeyInfo = pKeyInfo; 76279 77072 /* Set the VdbeCursor.isTable variable. Previous versions of 76280 77073 ** SQLite used to check if the root-page flags were sane at this point 76281 77074 ** and report database corruption if they were not, but this check has 76282 77075 ** since moved into the btree layer. */ 76283 77076 pCur->isTable = pOp->p4type!=P4_KEYINFO; 76284 77077 76285 77078 open_cursor_set_hints: 76286 77079 assert( OPFLAG_BULKCSR==BTREE_BULKLOAD ); 76287 77080 assert( OPFLAG_SEEKEQ==BTREE_SEEK_EQ ); 76288 - sqlite3BtreeCursorHints(pCur->pCursor, 76289 - (pOp->p5 & (OPFLAG_BULKCSR|OPFLAG_SEEKEQ))); 77081 + testcase( pOp->p5 & OPFLAG_BULKCSR ); 77082 +#ifdef SQLITE_ENABLE_CURSOR_HINT 77083 + testcase( pOp->p2 & OPFLAG_SEEKEQ ); 77084 +#endif 77085 + sqlite3BtreeCursorHintFlags(pCur->uc.pCursor, 77086 + (pOp->p5 & (OPFLAG_BULKCSR|OPFLAG_SEEKEQ))); 76290 77087 break; 76291 77088 } 76292 77089 76293 77090 /* Opcode: OpenEphemeral P1 P2 * P4 P5 76294 77091 ** Synopsis: nColumn=P2 76295 77092 ** 76296 77093 ** Open a new cursor P1 to a transient table. ................................................................................ 76325 77122 SQLITE_OPEN_READWRITE | 76326 77123 SQLITE_OPEN_CREATE | 76327 77124 SQLITE_OPEN_EXCLUSIVE | 76328 77125 SQLITE_OPEN_DELETEONCLOSE | 76329 77126 SQLITE_OPEN_TRANSIENT_DB; 76330 77127 assert( pOp->p1>=0 ); 76331 77128 assert( pOp->p2>=0 ); 76332 - pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1); 77129 + pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_BTREE); 76333 77130 if( pCx==0 ) goto no_mem; 76334 77131 pCx->nullRow = 1; 76335 77132 pCx->isEphemeral = 1; 76336 77133 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBt, 76337 77134 BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags); 76338 77135 if( rc==SQLITE_OK ){ 76339 77136 rc = sqlite3BtreeBeginTrans(pCx->pBt, 1); ................................................................................ 76349 77146 assert( pOp->p4type==P4_KEYINFO ); 76350 77147 rc = sqlite3BtreeCreateTable(pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5); 76351 77148 if( rc==SQLITE_OK ){ 76352 77149 assert( pgno==MASTER_ROOT+1 ); 76353 77150 assert( pKeyInfo->db==db ); 76354 77151 assert( pKeyInfo->enc==ENC(db) ); 76355 77152 pCx->pKeyInfo = pKeyInfo; 76356 - rc = sqlite3BtreeCursor(pCx->pBt, pgno, 1, pKeyInfo, pCx->pCursor); 77153 + rc = sqlite3BtreeCursor(pCx->pBt, pgno, BTREE_WRCSR, 77154 + pKeyInfo, pCx->uc.pCursor); 76357 77155 } 76358 77156 pCx->isTable = 0; 76359 77157 }else{ 76360 - rc = sqlite3BtreeCursor(pCx->pBt, MASTER_ROOT, 1, 0, pCx->pCursor); 77158 + rc = sqlite3BtreeCursor(pCx->pBt, MASTER_ROOT, BTREE_WRCSR, 77159 + 0, pCx->uc.pCursor); 76361 77160 pCx->isTable = 1; 76362 77161 } 76363 77162 } 76364 77163 pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED); 76365 77164 break; 76366 77165 } 76367 77166 ................................................................................ 76376 77175 ** key is sufficient to produce the required results. 76377 77176 */ 76378 77177 case OP_SorterOpen: { 76379 77178 VdbeCursor *pCx; 76380 77179 76381 77180 assert( pOp->p1>=0 ); 76382 77181 assert( pOp->p2>=0 ); 76383 - pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1); 77182 + pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_SORTER); 76384 77183 if( pCx==0 ) goto no_mem; 76385 77184 pCx->pKeyInfo = pOp->p4.pKeyInfo; 76386 77185 assert( pCx->pKeyInfo->db==db ); 76387 77186 assert( pCx->pKeyInfo->enc==ENC(db) ); 76388 77187 rc = sqlite3VdbeSorterInit(db, pOp->p3, pCx); 76389 77188 break; 76390 77189 } ................................................................................ 76396 77195 ** to P2. Regardless of whether or not the jump is taken, increment the 76397 77196 ** the sequence value. 76398 77197 */ 76399 77198 case OP_SequenceTest: { 76400 77199 VdbeCursor *pC; 76401 77200 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 76402 77201 pC = p->apCsr[pOp->p1]; 76403 - assert( pC->pSorter ); 77202 + assert( isSorter(pC) ); 76404 77203 if( (pC->seqCount++)==0 ){ 76405 77204 goto jump_to_p2; 76406 77205 } 76407 77206 break; 76408 77207 } 76409 77208 76410 77209 /* Opcode: OpenPseudo P1 P2 P3 * * ................................................................................ 76424 77223 ** the pseudo-table. 76425 77224 */ 76426 77225 case OP_OpenPseudo: { 76427 77226 VdbeCursor *pCx; 76428 77227 76429 77228 assert( pOp->p1>=0 ); 76430 77229 assert( pOp->p3>=0 ); 76431 - pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0); 77230 + pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, CURTYPE_PSEUDO); 76432 77231 if( pCx==0 ) goto no_mem; 76433 77232 pCx->nullRow = 1; 76434 - pCx->pseudoTableReg = pOp->p2; 77233 + pCx->uc.pseudoTableReg = pOp->p2; 76435 77234 pCx->isTable = 1; 76436 77235 assert( pOp->p5==0 ); 76437 77236 break; 76438 77237 } 76439 77238 76440 77239 /* Opcode: Close P1 * * * * 76441 77240 ** ................................................................................ 76459 77258 ** first 63 columns of the table or index that are actually used 76460 77259 ** by the cursor. The high-order bit is set if any column after 76461 77260 ** the 64th is used. 76462 77261 */ 76463 77262 case OP_ColumnsUsed: { 76464 77263 VdbeCursor *pC; 76465 77264 pC = p->apCsr[pOp->p1]; 76466 - assert( pC->pCursor ); 77265 + assert( pC->eCurType==CURTYPE_BTREE ); 76467 77266 pC->maskUsed = *(u64*)pOp->p4.pI64; 76468 77267 break; 76469 77268 } 76470 77269 #endif 76471 77270 76472 77271 /* Opcode: SeekGE P1 P2 P3 P4 * 76473 77272 ** Synopsis: key=r[P3@P4] ................................................................................ 76476 77275 ** use the value in register P3 as the key. If cursor P1 refers 76477 77276 ** to an SQL index, then P3 is the first in an array of P4 registers 76478 77277 ** that are used as an unpacked index key. 76479 77278 ** 76480 77279 ** Reposition cursor P1 so that it points to the smallest entry that 76481 77280 ** is greater than or equal to the key value. If there are no records 76482 77281 ** greater than or equal to the key and P2 is not zero, then jump to P2. 77282 +** 77283 +** If the cursor P1 was opened using the OPFLAG_SEEKEQ flag, then this 77284 +** opcode will always land on a record that equally equals the key, or 77285 +** else jump immediately to P2. When the cursor is OPFLAG_SEEKEQ, this 77286 +** opcode must be followed by an IdxLE opcode with the same arguments. 77287 +** The IdxLE opcode will be skipped if this opcode succeeds, but the 77288 +** IdxLE opcode will be used on subsequent loop iterations. 76483 77289 ** 76484 77290 ** This opcode leaves the cursor configured to move in forward order, 76485 77291 ** from the beginning toward the end. In other words, the cursor is 76486 77292 ** configured to use Next, not Prev. 76487 77293 ** 76488 77294 ** See also: Found, NotFound, SeekLt, SeekGt, SeekLe 76489 77295 */ ................................................................................ 76535 77341 ** is less than or equal to the key value. If there are no records 76536 77342 ** less than or equal to the key and P2 is not zero, then jump to P2. 76537 77343 ** 76538 77344 ** This opcode leaves the cursor configured to move in reverse order, 76539 77345 ** from the end toward the beginning. In other words, the cursor is 76540 77346 ** configured to use Prev, not Next. 76541 77347 ** 77348 +** If the cursor P1 was opened using the OPFLAG_SEEKEQ flag, then this 77349 +** opcode will always land on a record that equally equals the key, or 77350 +** else jump immediately to P2. When the cursor is OPFLAG_SEEKEQ, this 77351 +** opcode must be followed by an IdxGE opcode with the same arguments. 77352 +** The IdxGE opcode will be skipped if this opcode succeeds, but the 77353 +** IdxGE opcode will be used on subsequent loop iterations. 77354 +** 76542 77355 ** See also: Found, NotFound, SeekGt, SeekGe, SeekLt 76543 77356 */ 76544 77357 case OP_SeekLT: /* jump, in3 */ 76545 77358 case OP_SeekLE: /* jump, in3 */ 76546 77359 case OP_SeekGE: /* jump, in3 */ 76547 77360 case OP_SeekGT: { /* jump, in3 */ 76548 - int res; 76549 - int oc; 76550 - VdbeCursor *pC; 76551 - UnpackedRecord r; 76552 - int nField; 76553 - i64 iKey; /* The rowid we are to seek to */ 77361 + int res; /* Comparison result */ 77362 + int oc; /* Opcode */ 77363 + VdbeCursor *pC; /* The cursor to seek */ 77364 + UnpackedRecord r; /* The key to seek for */ 77365 + int nField; /* Number of columns or fields in the key */ 77366 + i64 iKey; /* The rowid we are to seek to */ 77367 + int eqOnly; /* Only interested in == results */ 76554 77368 76555 77369 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 76556 77370 assert( pOp->p2!=0 ); 76557 77371 pC = p->apCsr[pOp->p1]; 76558 77372 assert( pC!=0 ); 76559 - assert( pC->pseudoTableReg==0 ); 77373 + assert( pC->eCurType==CURTYPE_BTREE ); 76560 77374 assert( OP_SeekLE == OP_SeekLT+1 ); 76561 77375 assert( OP_SeekGE == OP_SeekLT+2 ); 76562 77376 assert( OP_SeekGT == OP_SeekLT+3 ); 76563 77377 assert( pC->isOrdered ); 76564 - assert( pC->pCursor!=0 ); 77378 + assert( pC->uc.pCursor!=0 ); 76565 77379 oc = pOp->opcode; 77380 + eqOnly = 0; 76566 77381 pC->nullRow = 0; 76567 77382 #ifdef SQLITE_DEBUG 76568 77383 pC->seekOp = pOp->opcode; 76569 77384 #endif 76570 77385 76571 - /* For a cursor with the BTREE_SEEK_EQ hint, only the OP_SeekGE and 76572 - ** OP_SeekLE opcodes are allowed, and these must be immediately followed 76573 - ** by an OP_IdxGT or OP_IdxLT opcode, respectively, with the same key. 76574 - */ 76575 -#ifdef SQLITE_DEBUG 76576 - if( sqlite3BtreeCursorHasHint(pC->pCursor, BTREE_SEEK_EQ) ){ 76577 - assert( pOp->opcode==OP_SeekGE || pOp->opcode==OP_SeekLE ); 76578 - assert( pOp[1].opcode==OP_IdxLT || pOp[1].opcode==OP_IdxGT ); 76579 - assert( pOp[1].p1==pOp[0].p1 ); 76580 - assert( pOp[1].p2==pOp[0].p2 ); 76581 - assert( pOp[1].p3==pOp[0].p3 ); 76582 - assert( pOp[1].p4.i==pOp[0].p4.i ); 76583 - } 76584 -#endif 76585 - 76586 77386 if( pC->isTable ){ 77387 + /* The BTREE_SEEK_EQ flag is only set on index cursors */ 77388 + assert( sqlite3BtreeCursorHasHint(pC->uc.pCursor, BTREE_SEEK_EQ)==0 ); 77389 + 76587 77390 /* The input value in P3 might be of any type: integer, real, string, 76588 77391 ** blob, or NULL. But it needs to be an integer before we can do 76589 77392 ** the seek, so convert it. */ 76590 77393 pIn3 = &aMem[pOp->p3]; 76591 77394 if( (pIn3->flags & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){ 76592 77395 applyNumericAffinity(pIn3, 0); 76593 77396 } ................................................................................ 76622 77425 else if( pIn3->u.r>(double)iKey ){ 76623 77426 assert( OP_SeekLE==(OP_SeekLT+1) ); 76624 77427 assert( OP_SeekGT==(OP_SeekGE+1) ); 76625 77428 assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) ); 76626 77429 if( (oc & 0x0001)==(OP_SeekLT & 0x0001) ) oc++; 76627 77430 } 76628 77431 } 76629 - rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res); 77432 + rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, 0, (u64)iKey, 0, &res); 76630 77433 pC->movetoTarget = iKey; /* Used by OP_Delete */ 76631 77434 if( rc!=SQLITE_OK ){ 76632 77435 goto abort_due_to_error; 76633 77436 } 76634 77437 }else{ 77438 + /* For a cursor with the BTREE_SEEK_EQ hint, only the OP_SeekGE and 77439 + ** OP_SeekLE opcodes are allowed, and these must be immediately followed 77440 + ** by an OP_IdxGT or OP_IdxLT opcode, respectively, with the same key. 77441 + */ 77442 + if( sqlite3BtreeCursorHasHint(pC->uc.pCursor, BTREE_SEEK_EQ) ){ 77443 + eqOnly = 1; 77444 + assert( pOp->opcode==OP_SeekGE || pOp->opcode==OP_SeekLE ); 77445 + assert( pOp[1].opcode==OP_IdxLT || pOp[1].opcode==OP_IdxGT ); 77446 + assert( pOp[1].p1==pOp[0].p1 ); 77447 + assert( pOp[1].p2==pOp[0].p2 ); 77448 + assert( pOp[1].p3==pOp[0].p3 ); 77449 + assert( pOp[1].p4.i==pOp[0].p4.i ); 77450 + } 77451 + 76635 77452 nField = pOp->p4.i; 76636 77453 assert( pOp->p4type==P4_INT32 ); 76637 77454 assert( nField>0 ); 76638 77455 r.pKeyInfo = pC->pKeyInfo; 76639 77456 r.nField = (u16)nField; 76640 77457 76641 77458 /* The next line of code computes as follows, only faster: ................................................................................ 76652 77469 assert( oc!=OP_SeekLT || r.default_rc==+1 ); 76653 77470 76654 77471 r.aMem = &aMem[pOp->p3]; 76655 77472 #ifdef SQLITE_DEBUG 76656 77473 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } 76657 77474 #endif 76658 77475 ExpandBlob(r.aMem); 76659 - rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, &r, 0, 0, &res); 77476 + r.eqSeen = 0; 77477 + rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, &r, 0, 0, &res); 76660 77478 if( rc!=SQLITE_OK ){ 76661 77479 goto abort_due_to_error; 77480 + } 77481 + if( eqOnly && r.eqSeen==0 ){ 77482 + assert( res!=0 ); 77483 + goto seek_not_found; 76662 77484 } 76663 77485 } 76664 77486 pC->deferredMoveto = 0; 76665 77487 pC->cacheStatus = CACHE_STALE; 76666 77488 #ifdef SQLITE_TEST 76667 77489 sqlite3_search_count++; 76668 77490 #endif 76669 77491 if( oc>=OP_SeekGE ){ assert( oc==OP_SeekGE || oc==OP_SeekGT ); 76670 77492 if( res<0 || (res==0 && oc==OP_SeekGT) ){ 76671 77493 res = 0; 76672 - rc = sqlite3BtreeNext(pC->pCursor, &res); 77494 + rc = sqlite3BtreeNext(pC->uc.pCursor, &res); 76673 77495 if( rc!=SQLITE_OK ) goto abort_due_to_error; 76674 77496 }else{ 76675 77497 res = 0; 76676 77498 } 76677 77499 }else{ 76678 77500 assert( oc==OP_SeekLT || oc==OP_SeekLE ); 76679 77501 if( res>0 || (res==0 && oc==OP_SeekLT) ){ 76680 77502 res = 0; 76681 - rc = sqlite3BtreePrevious(pC->pCursor, &res); 77503 + rc = sqlite3BtreePrevious(pC->uc.pCursor, &res); 76682 77504 if( rc!=SQLITE_OK ) goto abort_due_to_error; 76683 77505 }else{ 76684 77506 /* res might be negative because the table is empty. Check to 76685 77507 ** see if this is the case. 76686 77508 */ 76687 - res = sqlite3BtreeEof(pC->pCursor); 77509 + res = sqlite3BtreeEof(pC->uc.pCursor); 76688 77510 } 76689 77511 } 77512 +seek_not_found: 76690 77513 assert( pOp->p2>0 ); 76691 77514 VdbeBranchTaken(res!=0,2); 76692 77515 if( res ){ 76693 77516 goto jump_to_p2; 77517 + }else if( eqOnly ){ 77518 + assert( pOp[1].opcode==OP_IdxLT || pOp[1].opcode==OP_IdxGT ); 77519 + pOp++; /* Skip the OP_IdxLt or OP_IdxGT that follows */ 76694 77520 } 76695 77521 break; 76696 77522 } 76697 77523 76698 77524 /* Opcode: Seek P1 P2 * * * 76699 77525 ** Synopsis: intkey=r[P2] 76700 77526 ** ................................................................................ 76707 77533 */ 76708 77534 case OP_Seek: { /* in2 */ 76709 77535 VdbeCursor *pC; 76710 77536 76711 77537 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 76712 77538 pC = p->apCsr[pOp->p1]; 76713 77539 assert( pC!=0 ); 76714 - assert( pC->pCursor!=0 ); 77540 + assert( pC->eCurType==CURTYPE_BTREE ); 77541 + assert( pC->uc.pCursor!=0 ); 76715 77542 assert( pC->isTable ); 76716 77543 pC->nullRow = 0; 76717 77544 pIn2 = &aMem[pOp->p2]; 76718 77545 pC->movetoTarget = sqlite3VdbeIntValue(pIn2); 76719 77546 pC->deferredMoveto = 1; 76720 77547 break; 76721 77548 } ................................................................................ 76801 77628 assert( pOp->p4type==P4_INT32 ); 76802 77629 pC = p->apCsr[pOp->p1]; 76803 77630 assert( pC!=0 ); 76804 77631 #ifdef SQLITE_DEBUG 76805 77632 pC->seekOp = pOp->opcode; 76806 77633 #endif 76807 77634 pIn3 = &aMem[pOp->p3]; 76808 - assert( pC->pCursor!=0 ); 77635 + assert( pC->eCurType==CURTYPE_BTREE ); 77636 + assert( pC->uc.pCursor!=0 ); 76809 77637 assert( pC->isTable==0 ); 76810 77638 pFree = 0; 76811 77639 if( pOp->p4.i>0 ){ 76812 77640 r.pKeyInfo = pC->pKeyInfo; 76813 77641 r.nField = (u16)pOp->p4.i; 76814 77642 r.aMem = pIn3; 76815 77643 for(ii=0; ii<r.nField; ii++){ ................................................................................ 76838 77666 for(ii=0; ii<pIdxKey->nField; ii++){ 76839 77667 if( pIdxKey->aMem[ii].flags & MEM_Null ){ 76840 77668 takeJump = 1; 76841 77669 break; 76842 77670 } 76843 77671 } 76844 77672 } 76845 - rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res); 77673 + rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, pIdxKey, 0, 0, &res); 76846 77674 sqlite3DbFree(db, pFree); 76847 77675 if( rc!=SQLITE_OK ){ 76848 77676 break; 76849 77677 } 76850 77678 pC->seekResult = res; 76851 77679 alreadyExists = (res==0); 76852 77680 pC->nullRow = 1-alreadyExists; ................................................................................ 76892 77720 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 76893 77721 pC = p->apCsr[pOp->p1]; 76894 77722 assert( pC!=0 ); 76895 77723 #ifdef SQLITE_DEBUG 76896 77724 pC->seekOp = 0; 76897 77725 #endif 76898 77726 assert( pC->isTable ); 76899 - assert( pC->pseudoTableReg==0 ); 76900 - pCrsr = pC->pCursor; 77727 + assert( pC->eCurType==CURTYPE_BTREE ); 77728 + pCrsr = pC->uc.pCursor; 76901 77729 assert( pCrsr!=0 ); 76902 77730 res = 0; 76903 77731 iKey = pIn3->u.i; 76904 77732 rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res); 76905 77733 assert( rc==SQLITE_OK || res==0 ); 76906 77734 pC->movetoTarget = iKey; /* Used by OP_Delete */ 76907 77735 pC->nullRow = 0; ................................................................................ 76927 77755 ** Write the sequence number into register P2. 76928 77756 ** The sequence number on the cursor is incremented after this 76929 77757 ** instruction. 76930 77758 */ 76931 77759 case OP_Sequence: { /* out2 */ 76932 77760 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 76933 77761 assert( p->apCsr[pOp->p1]!=0 ); 77762 + assert( p->apCsr[pOp->p1]->eCurType!=CURTYPE_VTAB ); 76934 77763 pOut = out2Prerelease(p, pOp); 76935 77764 pOut->u.i = p->apCsr[pOp->p1]->seqCount++; 76936 77765 break; 76937 77766 } 76938 77767 76939 77768 76940 77769 /* Opcode: NewRowid P1 P2 P3 * * ................................................................................ 76962 77791 76963 77792 v = 0; 76964 77793 res = 0; 76965 77794 pOut = out2Prerelease(p, pOp); 76966 77795 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 76967 77796 pC = p->apCsr[pOp->p1]; 76968 77797 assert( pC!=0 ); 76969 - assert( pC->pCursor!=0 ); 77798 + assert( pC->eCurType==CURTYPE_BTREE ); 77799 + assert( pC->uc.pCursor!=0 ); 76970 77800 { 76971 77801 /* The next rowid or record number (different terms for the same 76972 77802 ** thing) is obtained in a two-step algorithm. 76973 77803 ** 76974 77804 ** First we attempt to find the largest existing rowid and add one 76975 77805 ** to that. But if the largest existing rowid is already the maximum 76976 77806 ** positive integer, we have to fall through to the second ................................................................................ 76990 77820 ** Others complain about 0x7ffffffffffffffffLL. The following macro seems 76991 77821 ** to provide the constant while making all compilers happy. 76992 77822 */ 76993 77823 # define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff ) 76994 77824 #endif 76995 77825 76996 77826 if( !pC->useRandomRowid ){ 76997 - rc = sqlite3BtreeLast(pC->pCursor, &res); 77827 + rc = sqlite3BtreeLast(pC->uc.pCursor, &res); 76998 77828 if( rc!=SQLITE_OK ){ 76999 77829 goto abort_due_to_error; 77000 77830 } 77001 77831 if( res ){ 77002 77832 v = 1; /* IMP: R-61914-48074 */ 77003 77833 }else{ 77004 - assert( sqlite3BtreeCursorIsValid(pC->pCursor) ); 77005 - rc = sqlite3BtreeKeySize(pC->pCursor, &v); 77834 + assert( sqlite3BtreeCursorIsValid(pC->uc.pCursor) ); 77835 + rc = sqlite3BtreeKeySize(pC->uc.pCursor, &v); 77006 77836 assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */ 77007 77837 if( v>=MAX_ROWID ){ 77008 77838 pC->useRandomRowid = 1; 77009 77839 }else{ 77010 77840 v++; /* IMP: R-29538-34987 */ 77011 77841 } 77012 77842 } ................................................................................ 77049 77879 ** it finds one that is not previously used. */ 77050 77880 assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is 77051 77881 ** an AUTOINCREMENT table. */ 77052 77882 cnt = 0; 77053 77883 do{ 77054 77884 sqlite3_randomness(sizeof(v), &v); 77055 77885 v &= (MAX_ROWID>>1); v++; /* Ensure that v is greater than zero */ 77056 - }while( ((rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)v, 77886 + }while( ((rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, 0, (u64)v, 77057 77887 0, &res))==SQLITE_OK) 77058 77888 && (res==0) 77059 77889 && (++cnt<100)); 77060 77890 if( rc==SQLITE_OK && res==0 ){ 77061 77891 rc = SQLITE_FULL; /* IMP: R-38219-53002 */ 77062 77892 goto abort_due_to_error; 77063 77893 } ................................................................................ 77129 77959 int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */ 77130 77960 77131 77961 pData = &aMem[pOp->p2]; 77132 77962 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 77133 77963 assert( memIsValid(pData) ); 77134 77964 pC = p->apCsr[pOp->p1]; 77135 77965 assert( pC!=0 ); 77136 - assert( pC->pCursor!=0 ); 77137 - assert( pC->pseudoTableReg==0 ); 77966 + assert( pC->eCurType==CURTYPE_BTREE ); 77967 + assert( pC->uc.pCursor!=0 ); 77138 77968 assert( pC->isTable ); 77139 77969 REGISTER_TRACE(pOp->p2, pData); 77140 77970 77141 77971 if( pOp->opcode==OP_Insert ){ 77142 77972 pKey = &aMem[pOp->p3]; 77143 77973 assert( pKey->flags & MEM_Int ); 77144 77974 assert( memIsValid(pKey) ); ................................................................................ 77159 77989 } 77160 77990 seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0); 77161 77991 if( pData->flags & MEM_Zero ){ 77162 77992 nZero = pData->u.nZero; 77163 77993 }else{ 77164 77994 nZero = 0; 77165 77995 } 77166 - rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey, 77996 + rc = sqlite3BtreeInsert(pC->uc.pCursor, 0, iKey, 77167 77997 pData->z, pData->n, nZero, 77168 77998 (pOp->p5 & OPFLAG_APPEND)!=0, seekResult 77169 77999 ); 77170 78000 pC->deferredMoveto = 0; 77171 78001 pC->cacheStatus = CACHE_STALE; 77172 78002 77173 78003 /* Invoke the update-hook if required. */ ................................................................................ 77206 78036 case OP_Delete: { 77207 78037 VdbeCursor *pC; 77208 78038 u8 hasUpdateCallback; 77209 78039 77210 78040 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 77211 78041 pC = p->apCsr[pOp->p1]; 77212 78042 assert( pC!=0 ); 77213 - assert( pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */ 78043 + assert( pC->eCurType==CURTYPE_BTREE ); 78044 + assert( pC->uc.pCursor!=0 ); 77214 78045 assert( pC->deferredMoveto==0 ); 77215 78046 77216 78047 hasUpdateCallback = db->xUpdateCallback && pOp->p4.z && pC->isTable; 77217 78048 if( pOp->p5 && hasUpdateCallback ){ 77218 - sqlite3BtreeKeySize(pC->pCursor, &pC->movetoTarget); 78049 + sqlite3BtreeKeySize(pC->uc.pCursor, &pC->movetoTarget); 77219 78050 } 77220 78051 77221 78052 #ifdef SQLITE_DEBUG 77222 78053 /* The seek operation that positioned the cursor prior to OP_Delete will 77223 78054 ** have also set the pC->movetoTarget field to the rowid of the row that 77224 78055 ** is being deleted */ 77225 78056 if( pOp->p4.z && pC->isTable && pOp->p5==0 ){ 77226 78057 i64 iKey = 0; 77227 - sqlite3BtreeKeySize(pC->pCursor, &iKey); 78058 + sqlite3BtreeKeySize(pC->uc.pCursor, &iKey); 77228 78059 assert( pC->movetoTarget==iKey ); 77229 78060 } 77230 78061 #endif 77231 78062 77232 - rc = sqlite3BtreeDelete(pC->pCursor, pOp->p5); 78063 + rc = sqlite3BtreeDelete(pC->uc.pCursor, pOp->p5); 77233 78064 pC->cacheStatus = CACHE_STALE; 77234 78065 77235 78066 /* Invoke the update-hook if required. */ 77236 78067 if( rc==SQLITE_OK && hasUpdateCallback ){ 77237 78068 db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, 77238 78069 db->aDb[pC->iDb].zName, pOp->p4.z, pC->movetoTarget); 77239 78070 assert( pC->iDb>=0 ); ................................................................................ 77342 78173 77343 78174 pOut = &aMem[pOp->p2]; 77344 78175 memAboutToChange(p, pOut); 77345 78176 77346 78177 /* Note that RowKey and RowData are really exactly the same instruction */ 77347 78178 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 77348 78179 pC = p->apCsr[pOp->p1]; 78180 + assert( pC!=0 ); 78181 + assert( pC->eCurType==CURTYPE_BTREE ); 77349 78182 assert( isSorter(pC)==0 ); 77350 78183 assert( pC->isTable || pOp->opcode!=OP_RowData ); 77351 78184 assert( pC->isTable==0 || pOp->opcode==OP_RowData ); 77352 - assert( pC!=0 ); 77353 78185 assert( pC->nullRow==0 ); 77354 - assert( pC->pseudoTableReg==0 ); 77355 - assert( pC->pCursor!=0 ); 77356 - pCrsr = pC->pCursor; 78186 + assert( pC->uc.pCursor!=0 ); 78187 + pCrsr = pC->uc.pCursor; 77357 78188 77358 78189 /* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or 77359 78190 ** OP_Rewind/Op_Next with no intervening instructions that might invalidate 77360 78191 ** the cursor. If this where not the case, on of the following assert()s 77361 78192 ** would fail. Should this ever change (because of changes in the code 77362 78193 ** generator) then the fix would be to insert a call to 77363 78194 ** sqlite3VdbeCursorMoveto(). ................................................................................ 77417 78248 sqlite3_vtab *pVtab; 77418 78249 const sqlite3_module *pModule; 77419 78250 77420 78251 pOut = out2Prerelease(p, pOp); 77421 78252 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 77422 78253 pC = p->apCsr[pOp->p1]; 77423 78254 assert( pC!=0 ); 77424 - assert( pC->pseudoTableReg==0 || pC->nullRow ); 78255 + assert( pC->eCurType!=CURTYPE_PSEUDO || pC->nullRow ); 77425 78256 if( pC->nullRow ){ 77426 78257 pOut->flags = MEM_Null; 77427 78258 break; 77428 78259 }else if( pC->deferredMoveto ){ 77429 78260 v = pC->movetoTarget; 77430 78261 #ifndef SQLITE_OMIT_VIRTUALTABLE 77431 - }else if( pC->pVtabCursor ){ 77432 - pVtab = pC->pVtabCursor->pVtab; 78262 + }else if( pC->eCurType==CURTYPE_VTAB ){ 78263 + assert( pC->uc.pVCur!=0 ); 78264 + pVtab = pC->uc.pVCur->pVtab; 77433 78265 pModule = pVtab->pModule; 77434 78266 assert( pModule->xRowid ); 77435 - rc = pModule->xRowid(pC->pVtabCursor, &v); 78267 + rc = pModule->xRowid(pC->uc.pVCur, &v); 77436 78268 sqlite3VtabImportErrmsg(p, pVtab); 77437 78269 #endif /* SQLITE_OMIT_VIRTUALTABLE */ 77438 78270 }else{ 77439 - assert( pC->pCursor!=0 ); 78271 + assert( pC->eCurType==CURTYPE_BTREE ); 78272 + assert( pC->uc.pCursor!=0 ); 77440 78273 rc = sqlite3VdbeCursorRestore(pC); 77441 78274 if( rc ) goto abort_due_to_error; 77442 78275 if( pC->nullRow ){ 77443 78276 pOut->flags = MEM_Null; 77444 78277 break; 77445 78278 } 77446 - rc = sqlite3BtreeKeySize(pC->pCursor, &v); 78279 + rc = sqlite3BtreeKeySize(pC->uc.pCursor, &v); 77447 78280 assert( rc==SQLITE_OK ); /* Always so because of CursorRestore() above */ 77448 78281 } 77449 78282 pOut->u.i = v; 77450 78283 break; 77451 78284 } 77452 78285 77453 78286 /* Opcode: NullRow P1 * * * * ................................................................................ 77460 78293 VdbeCursor *pC; 77461 78294 77462 78295 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 77463 78296 pC = p->apCsr[pOp->p1]; 77464 78297 assert( pC!=0 ); 77465 78298 pC->nullRow = 1; 77466 78299 pC->cacheStatus = CACHE_STALE; 77467 - if( pC->pCursor ){ 77468 - sqlite3BtreeClearCursor(pC->pCursor); 78300 + if( pC->eCurType==CURTYPE_BTREE ){ 78301 + assert( pC->uc.pCursor!=0 ); 78302 + sqlite3BtreeClearCursor(pC->uc.pCursor); 77469 78303 } 77470 78304 break; 77471 78305 } 77472 78306 77473 78307 /* Opcode: Last P1 P2 P3 * * 77474 78308 ** 77475 78309 ** The next use of the Rowid or Column or Prev instruction for P1 ................................................................................ 77486 78320 VdbeCursor *pC; 77487 78321 BtCursor *pCrsr; 77488 78322 int res; 77489 78323 77490 78324 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 77491 78325 pC = p->apCsr[pOp->p1]; 77492 78326 assert( pC!=0 ); 77493 - pCrsr = pC->pCursor; 78327 + assert( pC->eCurType==CURTYPE_BTREE ); 78328 + pCrsr = pC->uc.pCursor; 77494 78329 res = 0; 77495 78330 assert( pCrsr!=0 ); 77496 78331 rc = sqlite3BtreeLast(pCrsr, &res); 77497 78332 pC->nullRow = (u8)res; 77498 78333 pC->deferredMoveto = 0; 77499 78334 pC->cacheStatus = CACHE_STALE; 77500 78335 pC->seekResult = pOp->p3; ................................................................................ 77554 78389 res = 1; 77555 78390 #ifdef SQLITE_DEBUG 77556 78391 pC->seekOp = OP_Rewind; 77557 78392 #endif 77558 78393 if( isSorter(pC) ){ 77559 78394 rc = sqlite3VdbeSorterRewind(pC, &res); 77560 78395 }else{ 77561 - pCrsr = pC->pCursor; 78396 + assert( pC->eCurType==CURTYPE_BTREE ); 78397 + pCrsr = pC->uc.pCursor; 77562 78398 assert( pCrsr ); 77563 78399 rc = sqlite3BtreeFirst(pCrsr, &res); 77564 78400 pC->deferredMoveto = 0; 77565 78401 pC->cacheStatus = CACHE_STALE; 77566 78402 } 77567 78403 pC->nullRow = (u8)res; 77568 78404 assert( pOp->p2>0 && pOp->p2<p->nOp ); ................................................................................ 77651 78487 case OP_Next: /* jump */ 77652 78488 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 77653 78489 assert( pOp->p5<ArraySize(p->aCounter) ); 77654 78490 pC = p->apCsr[pOp->p1]; 77655 78491 res = pOp->p3; 77656 78492 assert( pC!=0 ); 77657 78493 assert( pC->deferredMoveto==0 ); 77658 - assert( pC->pCursor ); 78494 + assert( pC->eCurType==CURTYPE_BTREE ); 77659 78495 assert( res==0 || (res==1 && pC->isTable==0) ); 77660 78496 testcase( res==1 ); 77661 78497 assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext ); 77662 78498 assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious ); 77663 78499 assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext ); 77664 78500 assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious); 77665 78501 ................................................................................ 77668 78504 assert( pOp->opcode!=OP_Next || pOp->opcode!=OP_NextIfOpen 77669 78505 || pC->seekOp==OP_SeekGT || pC->seekOp==OP_SeekGE 77670 78506 || pC->seekOp==OP_Rewind || pC->seekOp==OP_Found); 77671 78507 assert( pOp->opcode!=OP_Prev || pOp->opcode!=OP_PrevIfOpen 77672 78508 || pC->seekOp==OP_SeekLT || pC->seekOp==OP_SeekLE 77673 78509 || pC->seekOp==OP_Last ); 77674 78510 77675 - rc = pOp->p4.xAdvance(pC->pCursor, &res); 78511 + rc = pOp->p4.xAdvance(pC->uc.pCursor, &res); 77676 78512 next_tail: 77677 78513 pC->cacheStatus = CACHE_STALE; 77678 78514 VdbeBranchTaken(res==0,2); 77679 78515 if( res==0 ){ 77680 78516 pC->nullRow = 0; 77681 78517 p->aCounter[pOp->p5]++; 77682 78518 #ifdef SQLITE_TEST ................................................................................ 77719 78555 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 77720 78556 pC = p->apCsr[pOp->p1]; 77721 78557 assert( pC!=0 ); 77722 78558 assert( isSorter(pC)==(pOp->opcode==OP_SorterInsert) ); 77723 78559 pIn2 = &aMem[pOp->p2]; 77724 78560 assert( pIn2->flags & MEM_Blob ); 77725 78561 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; 77726 - assert( pC->pCursor!=0 ); 78562 + assert( pC->eCurType==CURTYPE_BTREE || pOp->opcode==OP_SorterInsert ); 77727 78563 assert( pC->isTable==0 ); 77728 78564 rc = ExpandBlob(pIn2); 77729 78565 if( rc==SQLITE_OK ){ 77730 78566 if( pOp->opcode==OP_SorterInsert ){ 77731 78567 rc = sqlite3VdbeSorterWrite(pC, pIn2); 77732 78568 }else{ 77733 78569 nKey = pIn2->n; 77734 78570 zKey = pIn2->z; 77735 - rc = sqlite3BtreeInsert(pC->pCursor, zKey, nKey, "", 0, 0, pOp->p3, 78571 + rc = sqlite3BtreeInsert(pC->uc.pCursor, zKey, nKey, "", 0, 0, pOp->p3, 77736 78572 ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0) 77737 78573 ); 77738 78574 assert( pC->deferredMoveto==0 ); 77739 78575 pC->cacheStatus = CACHE_STALE; 77740 78576 } 77741 78577 } 77742 78578 break; ................................................................................ 77756 78592 UnpackedRecord r; 77757 78593 77758 78594 assert( pOp->p3>0 ); 77759 78595 assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem-p->nCursor)+1 ); 77760 78596 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 77761 78597 pC = p->apCsr[pOp->p1]; 77762 78598 assert( pC!=0 ); 77763 - pCrsr = pC->pCursor; 78599 + assert( pC->eCurType==CURTYPE_BTREE ); 78600 + pCrsr = pC->uc.pCursor; 77764 78601 assert( pCrsr!=0 ); 77765 78602 assert( pOp->p5==0 ); 77766 78603 r.pKeyInfo = pC->pKeyInfo; 77767 78604 r.nField = (u16)pOp->p3; 77768 78605 r.default_rc = 0; 77769 78606 r.aMem = &aMem[pOp->p2]; 77770 78607 #ifdef SQLITE_DEBUG ................................................................................ 77793 78630 VdbeCursor *pC; 77794 78631 i64 rowid; 77795 78632 77796 78633 pOut = out2Prerelease(p, pOp); 77797 78634 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 77798 78635 pC = p->apCsr[pOp->p1]; 77799 78636 assert( pC!=0 ); 77800 - pCrsr = pC->pCursor; 78637 + assert( pC->eCurType==CURTYPE_BTREE ); 78638 + pCrsr = pC->uc.pCursor; 77801 78639 assert( pCrsr!=0 ); 77802 78640 pOut->flags = MEM_Null; 77803 78641 assert( pC->isTable==0 ); 77804 78642 assert( pC->deferredMoveto==0 ); 77805 78643 77806 78644 /* sqlite3VbeCursorRestore() can only fail if the record has been deleted 77807 78645 ** out from under the cursor. That will never happend for an IdxRowid ................................................................................ 77874 78712 int res; 77875 78713 UnpackedRecord r; 77876 78714 77877 78715 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 77878 78716 pC = p->apCsr[pOp->p1]; 77879 78717 assert( pC!=0 ); 77880 78718 assert( pC->isOrdered ); 77881 - assert( pC->pCursor!=0); 78719 + assert( pC->eCurType==CURTYPE_BTREE ); 78720 + assert( pC->uc.pCursor!=0); 77882 78721 assert( pC->deferredMoveto==0 ); 77883 78722 assert( pOp->p5==0 || pOp->p5==1 ); 77884 78723 assert( pOp->p4type==P4_INT32 ); 77885 78724 r.pKeyInfo = pC->pKeyInfo; 77886 78725 r.nField = (u16)pOp->p4.i; 77887 78726 if( pOp->opcode<OP_IdxLT ){ 77888 78727 assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxGT ); ................................................................................ 78007 78846 */ 78008 78847 case OP_ResetSorter: { 78009 78848 VdbeCursor *pC; 78010 78849 78011 78850 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 78012 78851 pC = p->apCsr[pOp->p1]; 78013 78852 assert( pC!=0 ); 78014 - if( pC->pSorter ){ 78015 - sqlite3VdbeSorterReset(db, pC->pSorter); 78853 + if( isSorter(pC) ){ 78854 + sqlite3VdbeSorterReset(db, pC->uc.pSorter); 78016 78855 }else{ 78856 + assert( pC->eCurType==CURTYPE_BTREE ); 78017 78857 assert( pC->isEphemeral ); 78018 - rc = sqlite3BtreeClearTableOfCursor(pC->pCursor); 78858 + rc = sqlite3BtreeClearTableOfCursor(pC->uc.pCursor); 78019 78859 } 78020 78860 break; 78021 78861 } 78022 78862 78023 78863 /* Opcode: CreateTable P1 P2 * * * 78024 78864 ** Synopsis: r[P2]=root iDb=P1 78025 78865 ** ................................................................................ 79085 79925 ** 79086 79926 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure. 79087 79927 ** P1 is a cursor number. This opcode opens a cursor to the virtual 79088 79928 ** table and stores that cursor in P1. 79089 79929 */ 79090 79930 case OP_VOpen: { 79091 79931 VdbeCursor *pCur; 79092 - sqlite3_vtab_cursor *pVtabCursor; 79932 + sqlite3_vtab_cursor *pVCur; 79093 79933 sqlite3_vtab *pVtab; 79094 79934 const sqlite3_module *pModule; 79095 79935 79096 79936 assert( p->bIsReader ); 79097 79937 pCur = 0; 79098 - pVtabCursor = 0; 79938 + pVCur = 0; 79099 79939 pVtab = pOp->p4.pVtab->pVtab; 79100 79940 if( pVtab==0 || NEVER(pVtab->pModule==0) ){ 79101 79941 rc = SQLITE_LOCKED; 79102 79942 break; 79103 79943 } 79104 79944 pModule = pVtab->pModule; 79105 - rc = pModule->xOpen(pVtab, &pVtabCursor); 79945 + rc = pModule->xOpen(pVtab, &pVCur); 79106 79946 sqlite3VtabImportErrmsg(p, pVtab); 79107 79947 if( SQLITE_OK==rc ){ 79108 79948 /* Initialize sqlite3_vtab_cursor base class */ 79109 - pVtabCursor->pVtab = pVtab; 79949 + pVCur->pVtab = pVtab; 79110 79950 79111 79951 /* Initialize vdbe cursor object */ 79112 - pCur = allocateCursor(p, pOp->p1, 0, -1, 0); 79952 + pCur = allocateCursor(p, pOp->p1, 0, -1, CURTYPE_VTAB); 79113 79953 if( pCur ){ 79114 - pCur->pVtabCursor = pVtabCursor; 79954 + pCur->uc.pVCur = pVCur; 79115 79955 pVtab->nRef++; 79116 79956 }else{ 79117 79957 assert( db->mallocFailed ); 79118 - pModule->xClose(pVtabCursor); 79958 + pModule->xClose(pVCur); 79119 79959 goto no_mem; 79120 79960 } 79121 79961 } 79122 79962 break; 79123 79963 } 79124 79964 #endif /* SQLITE_OMIT_VIRTUALTABLE */ 79125 79965 ................................................................................ 79145 79985 */ 79146 79986 case OP_VFilter: { /* jump */ 79147 79987 int nArg; 79148 79988 int iQuery; 79149 79989 const sqlite3_module *pModule; 79150 79990 Mem *pQuery; 79151 79991 Mem *pArgc; 79152 - sqlite3_vtab_cursor *pVtabCursor; 79992 + sqlite3_vtab_cursor *pVCur; 79153 79993 sqlite3_vtab *pVtab; 79154 79994 VdbeCursor *pCur; 79155 79995 int res; 79156 79996 int i; 79157 79997 Mem **apArg; 79158 79998 79159 79999 pQuery = &aMem[pOp->p3]; 79160 80000 pArgc = &pQuery[1]; 79161 80001 pCur = p->apCsr[pOp->p1]; 79162 80002 assert( memIsValid(pQuery) ); 79163 80003 REGISTER_TRACE(pOp->p3, pQuery); 79164 - assert( pCur->pVtabCursor ); 79165 - pVtabCursor = pCur->pVtabCursor; 79166 - pVtab = pVtabCursor->pVtab; 80004 + assert( pCur->eCurType==CURTYPE_VTAB ); 80005 + pVCur = pCur->uc.pVCur; 80006 + pVtab = pVCur->pVtab; 79167 80007 pModule = pVtab->pModule; 79168 80008 79169 80009 /* Grab the index number and argc parameters */ 79170 80010 assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int ); 79171 80011 nArg = (int)pArgc->u.i; 79172 80012 iQuery = (int)pQuery->u.i; 79173 80013 79174 80014 /* Invoke the xFilter method */ 79175 80015 res = 0; 79176 80016 apArg = p->apArg; 79177 80017 for(i = 0; i<nArg; i++){ 79178 80018 apArg[i] = &pArgc[i+1]; 79179 80019 } 79180 - rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg); 80020 + rc = pModule->xFilter(pVCur, iQuery, pOp->p4.z, nArg, apArg); 79181 80021 sqlite3VtabImportErrmsg(p, pVtab); 79182 80022 if( rc==SQLITE_OK ){ 79183 - res = pModule->xEof(pVtabCursor); 80023 + res = pModule->xEof(pVCur); 79184 80024 } 79185 80025 pCur->nullRow = 0; 79186 80026 VdbeBranchTaken(res!=0,2); 79187 80027 if( res ) goto jump_to_p2; 79188 80028 break; 79189 80029 } 79190 80030 #endif /* SQLITE_OMIT_VIRTUALTABLE */ ................................................................................ 79200 80040 case OP_VColumn: { 79201 80041 sqlite3_vtab *pVtab; 79202 80042 const sqlite3_module *pModule; 79203 80043 Mem *pDest; 79204 80044 sqlite3_context sContext; 79205 80045 79206 80046 VdbeCursor *pCur = p->apCsr[pOp->p1]; 79207 - assert( pCur->pVtabCursor ); 80047 + assert( pCur->eCurType==CURTYPE_VTAB ); 79208 80048 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); 79209 80049 pDest = &aMem[pOp->p3]; 79210 80050 memAboutToChange(p, pDest); 79211 80051 if( pCur->nullRow ){ 79212 80052 sqlite3VdbeMemSetNull(pDest); 79213 80053 break; 79214 80054 } 79215 - pVtab = pCur->pVtabCursor->pVtab; 80055 + pVtab = pCur->uc.pVCur->pVtab; 79216 80056 pModule = pVtab->pModule; 79217 80057 assert( pModule->xColumn ); 79218 80058 memset(&sContext, 0, sizeof(sContext)); 79219 80059 sContext.pOut = pDest; 79220 80060 MemSetTypeFlag(pDest, MEM_Null); 79221 - rc = pModule->xColumn(pCur->pVtabCursor, &sContext, pOp->p2); 80061 + rc = pModule->xColumn(pCur->uc.pVCur, &sContext, pOp->p2); 79222 80062 sqlite3VtabImportErrmsg(p, pVtab); 79223 80063 if( sContext.isError ){ 79224 80064 rc = sContext.isError; 79225 80065 } 79226 80066 sqlite3VdbeChangeEncoding(pDest, encoding); 79227 80067 REGISTER_TRACE(pOp->p3, pDest); 79228 80068 UPDATE_MAX_BLOBSIZE(pDest); ................................................................................ 79245 80085 sqlite3_vtab *pVtab; 79246 80086 const sqlite3_module *pModule; 79247 80087 int res; 79248 80088 VdbeCursor *pCur; 79249 80089 79250 80090 res = 0; 79251 80091 pCur = p->apCsr[pOp->p1]; 79252 - assert( pCur->pVtabCursor ); 80092 + assert( pCur->eCurType==CURTYPE_VTAB ); 79253 80093 if( pCur->nullRow ){ 79254 80094 break; 79255 80095 } 79256 - pVtab = pCur->pVtabCursor->pVtab; 80096 + pVtab = pCur->uc.pVCur->pVtab; 79257 80097 pModule = pVtab->pModule; 79258 80098 assert( pModule->xNext ); 79259 80099 79260 80100 /* Invoke the xNext() method of the module. There is no way for the 79261 80101 ** underlying implementation to return an error if one occurs during 79262 80102 ** xNext(). Instead, if an error occurs, true is returned (indicating that 79263 80103 ** data is available) and the error code returned when xColumn or 79264 80104 ** some other method is next invoked on the save virtual table cursor. 79265 80105 */ 79266 - rc = pModule->xNext(pCur->pVtabCursor); 80106 + rc = pModule->xNext(pCur->uc.pVCur); 79267 80107 sqlite3VtabImportErrmsg(p, pVtab); 79268 80108 if( rc==SQLITE_OK ){ 79269 - res = pModule->xEof(pCur->pVtabCursor); 80109 + res = pModule->xEof(pCur->uc.pVCur); 79270 80110 } 79271 80111 VdbeBranchTaken(!res,2); 79272 80112 if( !res ){ 79273 80113 /* If there is data, jump to P2 */ 79274 80114 goto jump_to_p2_and_check_for_interrupt; 79275 80115 } 79276 80116 goto check_for_interrupt; ................................................................................ 79471 80311 } 79472 80312 #endif /* SQLITE_DEBUG */ 79473 80313 #endif /* SQLITE_OMIT_TRACE */ 79474 80314 if( pOp->p2 ) goto jump_to_p2; 79475 80315 break; 79476 80316 } 79477 80317 80318 +#ifdef SQLITE_ENABLE_CURSOR_HINTS 80319 +/* Opcode: CursorHint P1 * * P4 * 80320 +** 80321 +** Provide a hint to cursor P1 that it only needs to return rows that 80322 +** satisfy the Expr in P4. TK_REGISTER terms in the P4 expression refer 80323 +** to values currently held in registers. TK_COLUMN terms in the P4 80324 +** expression refer to columns in the b-tree to which cursor P1 is pointing. 80325 +*/ 80326 +case OP_CursorHint: { 80327 + VdbeCursor *pC; 80328 + 80329 + assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 80330 + assert( pOp->p4type==P4_EXPR ); 80331 + pC = p->apCsr[pOp->p1]; 80332 + if( pC ){ 80333 + assert( pC->eCurType==CURTYPE_BTREE ); 80334 + sqlite3BtreeCursorHint(pC->uc.pCursor, BTREE_HINT_RANGE, 80335 + pOp->p4.pExpr, aMem); 80336 + } 80337 + break; 80338 +} 80339 +#endif /* SQLITE_ENABLE_CURSOR_HINTS */ 79478 80340 79479 80341 /* Opcode: Noop * * * * * 79480 80342 ** 79481 80343 ** Do nothing. This instruction is often useful as a jump 79482 80344 ** destination. 79483 80345 */ 79484 80346 /* ................................................................................ 79671 80533 ); 79672 80534 rc = SQLITE_ERROR; 79673 80535 sqlite3_finalize(p->pStmt); 79674 80536 p->pStmt = 0; 79675 80537 }else{ 79676 80538 p->iOffset = pC->aType[p->iCol + pC->nField]; 79677 80539 p->nByte = sqlite3VdbeSerialTypeLen(type); 79678 - p->pCsr = pC->pCursor; 80540 + p->pCsr = pC->uc.pCursor; 79679 80541 sqlite3BtreeIncrblobCursor(p->pCsr); 79680 80542 } 79681 80543 } 79682 80544 79683 80545 if( rc==SQLITE_ROW ){ 79684 80546 rc = SQLITE_OK; 79685 80547 }else if( p->pStmt ){ ................................................................................ 81035 81897 #if SQLITE_MAX_WORKER_THREADS>=SORTER_MAX_MERGE_COUNT 81036 81898 if( nWorker>=SORTER_MAX_MERGE_COUNT ){ 81037 81899 nWorker = SORTER_MAX_MERGE_COUNT-1; 81038 81900 } 81039 81901 #endif 81040 81902 81041 81903 assert( pCsr->pKeyInfo && pCsr->pBt==0 ); 81904 + assert( pCsr->eCurType==CURTYPE_SORTER ); 81042 81905 szKeyInfo = sizeof(KeyInfo) + (pCsr->pKeyInfo->nField-1)*sizeof(CollSeq*); 81043 81906 sz = sizeof(VdbeSorter) + nWorker * sizeof(SortSubtask); 81044 81907 81045 81908 pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo); 81046 - pCsr->pSorter = pSorter; 81909 + pCsr->uc.pSorter = pSorter; 81047 81910 if( pSorter==0 ){ 81048 81911 rc = SQLITE_NOMEM; 81049 81912 }else{ 81050 81913 pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz); 81051 81914 memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo); 81052 81915 pKeyInfo->db = 0; 81053 81916 if( nField && nWorker==0 ){ 81054 81917 pKeyInfo->nXField += (pKeyInfo->nField - nField); 81055 81918 pKeyInfo->nField = nField; 81056 81919 } 81057 81920 pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt); 81058 81921 pSorter->nTask = nWorker + 1; 81059 - pSorter->iPrev = nWorker-1; 81922 + pSorter->iPrev = (u8)(nWorker - 1); 81060 81923 pSorter->bUseThreads = (pSorter->nTask>1); 81061 81924 pSorter->db = db; 81062 81925 for(i=0; i<pSorter->nTask; i++){ 81063 81926 SortSubtask *pTask = &pSorter->aTask[i]; 81064 81927 pTask->pSorter = pSorter; 81065 81928 } 81066 81929 ................................................................................ 81323 82186 pSorter->pUnpacked = 0; 81324 82187 } 81325 82188 81326 82189 /* 81327 82190 ** Free any cursor components allocated by sqlite3VdbeSorterXXX routines. 81328 82191 */ 81329 82192 SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *db, VdbeCursor *pCsr){ 81330 - VdbeSorter *pSorter = pCsr->pSorter; 82193 + VdbeSorter *pSorter; 82194 + assert( pCsr->eCurType==CURTYPE_SORTER ); 82195 + pSorter = pCsr->uc.pSorter; 81331 82196 if( pSorter ){ 81332 82197 sqlite3VdbeSorterReset(db, pSorter); 81333 82198 sqlite3_free(pSorter->list.aMemory); 81334 82199 sqlite3DbFree(db, pSorter); 81335 - pCsr->pSorter = 0; 82200 + pCsr->uc.pSorter = 0; 81336 82201 } 81337 82202 } 81338 82203 81339 82204 #if SQLITE_MAX_MMAP_SIZE>0 81340 82205 /* 81341 82206 ** The first argument is a file-handle open on a temporary file. The file 81342 82207 ** is guaranteed to be nByte bytes or smaller in size. This function ................................................................................ 81826 82691 /* 81827 82692 ** Add a record to the sorter. 81828 82693 */ 81829 82694 SQLITE_PRIVATE int sqlite3VdbeSorterWrite( 81830 82695 const VdbeCursor *pCsr, /* Sorter cursor */ 81831 82696 Mem *pVal /* Memory cell containing record */ 81832 82697 ){ 81833 - VdbeSorter *pSorter = pCsr->pSorter; 82698 + VdbeSorter *pSorter; 81834 82699 int rc = SQLITE_OK; /* Return Code */ 81835 82700 SorterRecord *pNew; /* New list element */ 81836 - 81837 82701 int bFlush; /* True to flush contents of memory to PMA */ 81838 82702 int nReq; /* Bytes of memory required */ 81839 82703 int nPMA; /* Bytes of PMA space required */ 81840 82704 int t; /* serial type of first record field */ 81841 82705 82706 + assert( pCsr->eCurType==CURTYPE_SORTER ); 82707 + pSorter = pCsr->uc.pSorter; 81842 82708 getVarint32((const u8*)&pVal->z[1], t); 81843 82709 if( t>0 && t<10 && t!=7 ){ 81844 82710 pSorter->typeMask &= SORTER_TYPE_INTEGER; 81845 82711 }else if( t>10 && (t & 0x01) ){ 81846 82712 pSorter->typeMask &= SORTER_TYPE_TEXT; 81847 82713 }else{ 81848 82714 pSorter->typeMask = 0; ................................................................................ 82626 83492 82627 83493 /* 82628 83494 ** Once the sorter has been populated by calls to sqlite3VdbeSorterWrite, 82629 83495 ** this function is called to prepare for iterating through the records 82630 83496 ** in sorted order. 82631 83497 */ 82632 83498 SQLITE_PRIVATE int sqlite3VdbeSorterRewind(const VdbeCursor *pCsr, int *pbEof){ 82633 - VdbeSorter *pSorter = pCsr->pSorter; 83499 + VdbeSorter *pSorter; 82634 83500 int rc = SQLITE_OK; /* Return code */ 82635 83501 83502 + assert( pCsr->eCurType==CURTYPE_SORTER ); 83503 + pSorter = pCsr->uc.pSorter; 82636 83504 assert( pSorter ); 82637 83505 82638 83506 /* If no data has been written to disk, then do not do so now. Instead, 82639 83507 ** sort the VdbeSorter.pRecord list. The vdbe layer will read data directly 82640 83508 ** from the in-memory list. */ 82641 83509 if( pSorter->bUsePMA==0 ){ 82642 83510 if( pSorter->list.pList ){ ................................................................................ 82672 83540 return rc; 82673 83541 } 82674 83542 82675 83543 /* 82676 83544 ** Advance to the next element in the sorter. 82677 83545 */ 82678 83546 SQLITE_PRIVATE int sqlite3VdbeSorterNext(sqlite3 *db, const VdbeCursor *pCsr, int *pbEof){ 82679 - VdbeSorter *pSorter = pCsr->pSorter; 83547 + VdbeSorter *pSorter; 82680 83548 int rc; /* Return code */ 82681 83549 83550 + assert( pCsr->eCurType==CURTYPE_SORTER ); 83551 + pSorter = pCsr->uc.pSorter; 82682 83552 assert( pSorter->bUsePMA || (pSorter->pReader==0 && pSorter->pMerger==0) ); 82683 83553 if( pSorter->bUsePMA ){ 82684 83554 assert( pSorter->pReader==0 || pSorter->pMerger==0 ); 82685 83555 assert( pSorter->bUseThreads==0 || pSorter->pReader ); 82686 83556 assert( pSorter->bUseThreads==1 || pSorter->pMerger ); 82687 83557 #if SQLITE_MAX_WORKER_THREADS>0 82688 83558 if( pSorter->bUseThreads ){ ................................................................................ 82734 83604 return pKey; 82735 83605 } 82736 83606 82737 83607 /* 82738 83608 ** Copy the current sorter key into the memory cell pOut. 82739 83609 */ 82740 83610 SQLITE_PRIVATE int sqlite3VdbeSorterRowkey(const VdbeCursor *pCsr, Mem *pOut){ 82741 - VdbeSorter *pSorter = pCsr->pSorter; 83611 + VdbeSorter *pSorter; 82742 83612 void *pKey; int nKey; /* Sorter key to copy into pOut */ 82743 83613 83614 + assert( pCsr->eCurType==CURTYPE_SORTER ); 83615 + pSorter = pCsr->uc.pSorter; 82744 83616 pKey = vdbeSorterRowkey(pSorter, &nKey); 82745 83617 if( sqlite3VdbeMemClearAndResize(pOut, nKey) ){ 82746 83618 return SQLITE_NOMEM; 82747 83619 } 82748 83620 pOut->n = nKey; 82749 83621 MemSetTypeFlag(pOut, MEM_Blob); 82750 83622 memcpy(pOut->z, pKey, nKey); ................................................................................ 82770 83642 */ 82771 83643 SQLITE_PRIVATE int sqlite3VdbeSorterCompare( 82772 83644 const VdbeCursor *pCsr, /* Sorter cursor */ 82773 83645 Mem *pVal, /* Value to compare to current sorter key */ 82774 83646 int nKeyCol, /* Compare this many columns */ 82775 83647 int *pRes /* OUT: Result of comparison */ 82776 83648 ){ 82777 - VdbeSorter *pSorter = pCsr->pSorter; 82778 - UnpackedRecord *r2 = pSorter->pUnpacked; 82779 - KeyInfo *pKeyInfo = pCsr->pKeyInfo; 83649 + VdbeSorter *pSorter; 83650 + UnpackedRecord *r2; 83651 + KeyInfo *pKeyInfo; 82780 83652 int i; 82781 83653 void *pKey; int nKey; /* Sorter key to compare pVal with */ 82782 83654 83655 + assert( pCsr->eCurType==CURTYPE_SORTER ); 83656 + pSorter = pCsr->uc.pSorter; 83657 + r2 = pSorter->pUnpacked; 83658 + pKeyInfo = pCsr->pKeyInfo; 82783 83659 if( r2==0 ){ 82784 83660 char *p; 82785 83661 r2 = pSorter->pUnpacked = sqlite3VdbeAllocUnpackedRecord(pKeyInfo,0,0,&p); 82786 83662 assert( pSorter->pUnpacked==(UnpackedRecord*)p ); 82787 83663 if( r2==0 ) return SQLITE_NOMEM; 82788 83664 r2->nField = nKeyCol; 82789 83665 } ................................................................................ 83809 84685 iCol = -1; 83810 84686 } 83811 84687 break; 83812 84688 } 83813 84689 } 83814 84690 if( iCol>=pTab->nCol && sqlite3IsRowid(zCol) && VisibleRowid(pTab) ){ 83815 84691 /* IMP: R-51414-32910 */ 83816 - /* IMP: R-44911-55124 */ 83817 84692 iCol = -1; 83818 84693 } 83819 84694 if( iCol<pTab->nCol ){ 83820 84695 cnt++; 83821 84696 if( iCol<0 ){ 83822 84697 pExpr->affinity = SQLITE_AFF_INTEGER; 83823 84698 }else if( pExpr->iTable==0 ){ ................................................................................ 83844 84719 && cntTab==1 83845 84720 && pMatch 83846 84721 && (pNC->ncFlags & NC_IdxExpr)==0 83847 84722 && sqlite3IsRowid(zCol) 83848 84723 && VisibleRowid(pMatch->pTab) 83849 84724 ){ 83850 84725 cnt = 1; 83851 - pExpr->iColumn = -1; /* IMP: R-44911-55124 */ 84726 + pExpr->iColumn = -1; 83852 84727 pExpr->affinity = SQLITE_AFF_INTEGER; 83853 84728 } 83854 84729 83855 84730 /* 83856 84731 ** If the input is of the form Z (not Y.Z or X.Y.Z) then the name Z 83857 84732 ** might refer to an result-set alias. This happens, for example, when 83858 84733 ** we are resolving names in the WHERE clause of the following command: ................................................................................ 84904 85779 ** list rather than a single expression. 84905 85780 */ 84906 85781 SQLITE_PRIVATE int sqlite3ResolveExprListNames( 84907 85782 NameContext *pNC, /* Namespace to resolve expressions in. */ 84908 85783 ExprList *pList /* The expression list to be analyzed. */ 84909 85784 ){ 84910 85785 int i; 84911 - assert( pList!=0 ); 84912 - for(i=0; i<pList->nExpr; i++){ 84913 - if( sqlite3ResolveExprNames(pNC, pList->a[i].pExpr) ) return WRC_Abort; 85786 + if( pList ){ 85787 + for(i=0; i<pList->nExpr; i++){ 85788 + if( sqlite3ResolveExprNames(pNC, pList->a[i].pExpr) ) return WRC_Abort; 85789 + } 84914 85790 } 84915 85791 return WRC_Continue; 84916 85792 } 84917 85793 84918 85794 /* 84919 85795 ** Resolve all names in all expressions of a SELECT and in all 84920 85796 ** decendents of the SELECT, including compounds off of p->pPrior, ................................................................................ 85526 86402 Parse *pParse, /* Parsing context */ 85527 86403 int op, /* Expression opcode */ 85528 86404 Expr *pLeft, /* Left operand */ 85529 86405 Expr *pRight, /* Right operand */ 85530 86406 const Token *pToken /* Argument token */ 85531 86407 ){ 85532 86408 Expr *p; 85533 - if( op==TK_AND && pLeft && pRight && pParse->nErr==0 ){ 86409 + if( op==TK_AND && pParse->nErr==0 ){ 85534 86410 /* Take advantage of short-circuit false optimization for AND */ 85535 86411 p = sqlite3ExprAnd(pParse->db, pLeft, pRight); 85536 86412 }else{ 85537 - p = sqlite3ExprAlloc(pParse->db, op, pToken, 1); 86413 + p = sqlite3ExprAlloc(pParse->db, op & TKFLG_MASK, pToken, 1); 85538 86414 sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight); 85539 86415 } 85540 86416 if( p ) { 85541 86417 sqlite3ExprCheckHeight(pParse, p->nHeight); 85542 86418 } 85543 86419 return p; 85544 86420 } ................................................................................ 85831 86707 ** to store the copy of expression p, the copies of p->u.zToken 85832 86708 ** (if applicable), and the copies of the p->pLeft and p->pRight expressions, 85833 86709 ** if any. Before returning, *pzBuffer is set to the first byte past the 85834 86710 ** portion of the buffer copied into by this function. 85835 86711 */ 85836 86712 static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){ 85837 86713 Expr *pNew = 0; /* Value to return */ 86714 + assert( flags==0 || flags==EXPRDUP_REDUCE ); 85838 86715 if( p ){ 85839 86716 const int isReduced = (flags&EXPRDUP_REDUCE); 85840 86717 u8 *zAlloc; 85841 86718 u32 staticFlag = 0; 85842 86719 85843 86720 assert( pzBuffer==0 || isReduced ); 85844 86721 ................................................................................ 85865 86742 }else{ 85866 86743 nToken = 0; 85867 86744 } 85868 86745 if( isReduced ){ 85869 86746 assert( ExprHasProperty(p, EP_Reduced)==0 ); 85870 86747 memcpy(zAlloc, p, nNewSize); 85871 86748 }else{ 85872 - int nSize = exprStructSize(p); 86749 + u32 nSize = (u32)exprStructSize(p); 85873 86750 memcpy(zAlloc, p, nSize); 85874 - memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize); 86751 + if( nSize<EXPR_FULLSIZE ){ 86752 + memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize); 86753 + } 85875 86754 } 85876 86755 85877 86756 /* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */ 85878 86757 pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static|EP_MemToken); 85879 86758 pNew->flags |= nStructSize & (EP_Reduced|EP_TokenOnly); 85880 86759 pNew->flags |= staticFlag; 85881 86760 ................................................................................ 85957 86836 ** 85958 86837 ** The flags parameter contains a combination of the EXPRDUP_XXX flags. 85959 86838 ** If the EXPRDUP_REDUCE flag is set, then the structure returned is a 85960 86839 ** truncated version of the usual Expr structure that will be stored as 85961 86840 ** part of the in-memory representation of the database schema. 85962 86841 */ 85963 86842 SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3 *db, Expr *p, int flags){ 86843 + assert( flags==0 || flags==EXPRDUP_REDUCE ); 85964 86844 return exprDup(db, p, flags, 0); 85965 86845 } 85966 86846 SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){ 85967 86847 ExprList *pNew; 85968 86848 struct ExprList_item *pItem, *pOldItem; 85969 86849 int i; 85970 86850 if( p==0 ) return 0; ................................................................................ 86392 87272 ** is considered a variable but a single-quoted string (ex: 'abc') is 86393 87273 ** a constant. 86394 87274 */ 86395 87275 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr *p, u8 isInit){ 86396 87276 assert( isInit==0 || isInit==1 ); 86397 87277 return exprIsConst(p, 4+isInit, 0); 86398 87278 } 87279 + 87280 +#ifdef SQLITE_ENABLE_CURSOR_HINTS 87281 +/* 87282 +** Walk an expression tree. Return 1 if the expression contains a 87283 +** subquery of some kind. Return 0 if there are no subqueries. 87284 +*/ 87285 +SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr *p){ 87286 + Walker w; 87287 + memset(&w, 0, sizeof(w)); 87288 + w.eCode = 1; 87289 + w.xExprCallback = sqlite3ExprWalkNoop; 87290 + w.xSelectCallback = selectNodeIsConstant; 87291 + sqlite3WalkExpr(&w, p); 87292 + return w.eCode==0; 87293 +} 87294 +#endif 86399 87295 86400 87296 /* 86401 87297 ** If the expression p codes a constant integer that is small enough 86402 87298 ** to fit in a 32-bit integer, return 1 and put the value of the integer 86403 87299 ** in *pValue. If the expression is not an integer or if it is too big 86404 87300 ** to fit in a signed 32-bit integer, return 0 and leave *pValue unchanged. 86405 87301 */ ................................................................................ 86851 87747 */ 86852 87748 if( !ExprHasProperty(pExpr, EP_VarSelect) ){ 86853 87749 jmpIfDynamic = sqlite3CodeOnce(pParse); VdbeCoverage(v); 86854 87750 } 86855 87751 86856 87752 #ifndef SQLITE_OMIT_EXPLAIN 86857 87753 if( pParse->explain==2 ){ 86858 - char *zMsg = sqlite3MPrintf( 86859 - pParse->db, "EXECUTE %s%s SUBQUERY %d", jmpIfDynamic>=0?"":"CORRELATED ", 86860 - pExpr->op==TK_IN?"LIST":"SCALAR", pParse->iNextSelectId 87754 + char *zMsg = sqlite3MPrintf(pParse->db, "EXECUTE %s%s SUBQUERY %d", 87755 + jmpIfDynamic>=0?"":"CORRELATED ", 87756 + pExpr->op==TK_IN?"LIST":"SCALAR", 87757 + pParse->iNextSelectId 86861 87758 ); 86862 87759 sqlite3VdbeAddOp4(v, OP_Explain, pParse->iSelectId, 0, 0, zMsg, P4_DYNAMIC); 86863 87760 } 86864 87761 #endif 86865 87762 86866 87763 switch( pExpr->op ){ 86867 87764 case TK_IN: { ................................................................................ 87425 88322 int regOut /* Store the index column value in this register */ 87426 88323 ){ 87427 88324 i16 iTabCol = pIdx->aiColumn[iIdxCol]; 87428 88325 if( iTabCol==XN_EXPR ){ 87429 88326 assert( pIdx->aColExpr ); 87430 88327 assert( pIdx->aColExpr->nExpr>iIdxCol ); 87431 88328 pParse->iSelfTab = iTabCur; 87432 - sqlite3ExprCode(pParse, pIdx->aColExpr->a[iIdxCol].pExpr, regOut); 88329 + sqlite3ExprCodeCopy(pParse, pIdx->aColExpr->a[iIdxCol].pExpr, regOut); 87433 88330 }else{ 87434 88331 sqlite3ExprCodeGetColumnOfTable(pParse->pVdbe, pIdx->pTable, iTabCur, 87435 88332 iTabCol, regOut); 87436 88333 } 87437 88334 } 87438 88335 87439 88336 /* ................................................................................ 87459 88356 if( iCol>=0 ){ 87460 88357 sqlite3ColumnDefault(v, pTab, iCol, regOut); 87461 88358 } 87462 88359 } 87463 88360 87464 88361 /* 87465 88362 ** Generate code that will extract the iColumn-th column from 87466 -** table pTab and store the column value in a register. An effort 87467 -** is made to store the column value in register iReg, but this is 87468 -** not guaranteed. The location of the column value is returned. 88363 +** table pTab and store the column value in a register. 88364 +** 88365 +** An effort is made to store the column value in register iReg. This 88366 +** is not garanteeed for GetColumn() - the result can be stored in 88367 +** any register. But the result is guaranteed to land in register iReg 88368 +** for GetColumnToReg(). 87469 88369 ** 87470 88370 ** There must be an open cursor to pTab in iTable when this routine 87471 88371 ** is called. If iColumn<0 then code is generated that extracts the rowid. 87472 88372 */ 87473 88373 SQLITE_PRIVATE int sqlite3ExprCodeGetColumn( 87474 88374 Parse *pParse, /* Parsing and code generating context */ 87475 88375 Table *pTab, /* Description of the table we are reading from */ 87476 88376 int iColumn, /* Index of the table column */ 87477 88377 int iTable, /* The cursor pointing to the table */ 87478 88378 int iReg, /* Store results here */ 87479 - u8 p5 /* P5 value for OP_Column */ 88379 + u8 p5 /* P5 value for OP_Column + FLAGS */ 87480 88380 ){ 87481 88381 Vdbe *v = pParse->pVdbe; 87482 88382 int i; 87483 88383 struct yColCache *p; 87484 88384 87485 88385 for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ 87486 88386 if( p->iReg>0 && p->iTable==iTable && p->iColumn==iColumn ){ ................................................................................ 87494 88394 if( p5 ){ 87495 88395 sqlite3VdbeChangeP5(v, p5); 87496 88396 }else{ 87497 88397 sqlite3ExprCacheStore(pParse, iTable, iColumn, iReg); 87498 88398 } 87499 88399 return iReg; 87500 88400 } 88401 +SQLITE_PRIVATE void sqlite3ExprCodeGetColumnToReg( 88402 + Parse *pParse, /* Parsing and code generating context */ 88403 + Table *pTab, /* Description of the table we are reading from */ 88404 + int iColumn, /* Index of the table column */ 88405 + int iTable, /* The cursor pointing to the table */ 88406 + int iReg /* Store results here */ 88407 +){ 88408 + int r1 = sqlite3ExprCodeGetColumn(pParse, pTab, iColumn, iTable, iReg, 0); 88409 + if( r1!=iReg ) sqlite3VdbeAddOp2(pParse->pVdbe, OP_SCopy, r1, iReg); 88410 +} 88411 + 87501 88412 87502 88413 /* 87503 88414 ** Clear all column cache entries. 87504 88415 */ 87505 88416 SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse *pParse){ 87506 88417 int i; 87507 88418 struct yColCache *p; ................................................................................ 88264 89175 int inReg; 88265 89176 88266 89177 assert( target>0 && target<=pParse->nMem ); 88267 89178 if( pExpr && pExpr->op==TK_REGISTER ){ 88268 89179 sqlite3VdbeAddOp2(pParse->pVdbe, OP_Copy, pExpr->iTable, target); 88269 89180 }else{ 88270 89181 inReg = sqlite3ExprCodeTarget(pParse, pExpr, target); 88271 - assert( pParse->pVdbe || pParse->db->mallocFailed ); 89182 + assert( pParse->pVdbe!=0 || pParse->db->mallocFailed ); 88272 89183 if( inReg!=target && pParse->pVdbe ){ 88273 89184 sqlite3VdbeAddOp2(pParse->pVdbe, OP_SCopy, inReg, target); 88274 89185 } 88275 89186 } 88276 89187 } 89188 + 89189 +/* 89190 +** Make a transient copy of expression pExpr and then code it using 89191 +** sqlite3ExprCode(). This routine works just like sqlite3ExprCode() 89192 +** except that the input expression is guaranteed to be unchanged. 89193 +*/ 89194 +SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse *pParse, Expr *pExpr, int target){ 89195 + sqlite3 *db = pParse->db; 89196 + pExpr = sqlite3ExprDup(db, pExpr, 0); 89197 + if( !db->mallocFailed ) sqlite3ExprCode(pParse, pExpr, target); 89198 + sqlite3ExprDelete(db, pExpr); 89199 +} 88277 89200 88278 89201 /* 88279 89202 ** Generate code that will evaluate expression pExpr and store the 88280 89203 ** results in register target. The results are guaranteed to appear 88281 89204 ** in register target. If the expression is constant, then this routine 88282 89205 ** might choose to code the expression at initialization time. 88283 89206 */ ................................................................................ 88320 89243 ** Return the number of elements evaluated. 88321 89244 ** 88322 89245 ** The SQLITE_ECEL_DUP flag prevents the arguments from being 88323 89246 ** filled using OP_SCopy. OP_Copy must be used instead. 88324 89247 ** 88325 89248 ** The SQLITE_ECEL_FACTOR argument allows constant arguments to be 88326 89249 ** factored out into initialization code. 89250 +** 89251 +** The SQLITE_ECEL_REF flag means that expressions in the list with 89252 +** ExprList.a[].u.x.iOrderByCol>0 have already been evaluated and stored 89253 +** in registers at srcReg, and so the value can be copied from there. 88327 89254 */ 88328 89255 SQLITE_PRIVATE int sqlite3ExprCodeExprList( 88329 89256 Parse *pParse, /* Parsing context */ 88330 89257 ExprList *pList, /* The expression list to be coded */ 88331 89258 int target, /* Where to write results */ 88332 89259 int srcReg, /* Source registers if SQLITE_ECEL_REF */ 88333 89260 u8 flags /* SQLITE_ECEL_* flags */ ................................................................................ 88761 89688 return 1; 88762 89689 } 88763 89690 if( pB->op==TK_COLLATE && sqlite3ExprCompare(pA, pB->pLeft, iTab)<2 ){ 88764 89691 return 1; 88765 89692 } 88766 89693 return 2; 88767 89694 } 88768 - if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken ){ 89695 + if( pA->op!=TK_COLUMN && pA->op!=TK_AGG_COLUMN && pA->u.zToken ){ 88769 89696 if( pA->op==TK_FUNCTION ){ 88770 89697 if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2; 88771 89698 }else if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){ 88772 89699 return pA->op==TK_COLLATE ? 1 : 2; 88773 89700 } 88774 89701 } 88775 89702 if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2; ................................................................................ 91006 91933 if( v==0 || NEVER(pTab==0) ){ 91007 91934 return; 91008 91935 } 91009 91936 if( pTab->tnum==0 ){ 91010 91937 /* Do not gather statistics on views or virtual tables */ 91011 91938 return; 91012 91939 } 91013 - if( sqlite3_strnicmp(pTab->zName, "sqlite_", 7)==0 ){ 91940 + if( sqlite3_strlike("sqlite_%", pTab->zName, 0)==0 ){ 91014 91941 /* Do not gather statistics on system tables */ 91015 91942 return; 91016 91943 } 91017 91944 assert( sqlite3BtreeHoldsAllMutexes(db) ); 91018 91945 iDb = sqlite3SchemaToIndex(db, pTab->pSchema); 91019 91946 assert( iDb>=0 ); 91020 91947 assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); ................................................................................ 93136 94063 if( zDbase ){ 93137 94064 sqlite3ErrorMsg(pParse, "%s: %s.%s", zMsg, zDbase, zName); 93138 94065 }else{ 93139 94066 sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName); 93140 94067 } 93141 94068 pParse->checkSchema = 1; 93142 94069 } 93143 -#if SQLITE_USER_AUTHENTICATION 93144 - else if( pParse->db->auth.authLevel<UAUTH_User ){ 93145 - sqlite3ErrorMsg(pParse, "user not authenticated"); 93146 - p = 0; 93147 - } 93148 -#endif 94070 + 93149 94071 return p; 93150 94072 } 93151 94073 93152 94074 /* 93153 94075 ** Locate the table identified by *p. 93154 94076 ** 93155 94077 ** This is a wrapper around sqlite3LocateTable(). The difference between ................................................................................ 93209 94131 static void freeIndex(sqlite3 *db, Index *p){ 93210 94132 #ifndef SQLITE_OMIT_ANALYZE 93211 94133 sqlite3DeleteIndexSamples(db, p); 93212 94134 #endif 93213 94135 sqlite3ExprDelete(db, p->pPartIdxWhere); 93214 94136 sqlite3ExprListDelete(db, p->aColExpr); 93215 94137 sqlite3DbFree(db, p->zColAff); 93216 - if( p->isResized ) sqlite3DbFree(db, p->azColl); 94138 + if( p->isResized ) sqlite3DbFree(db, (void *)p->azColl); 93217 94139 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 93218 94140 sqlite3_free(p->aiRowEst); 93219 94141 #endif 93220 94142 sqlite3DbFree(db, p); 93221 94143 } 93222 94144 93223 94145 /* ................................................................................ 93809 94731 93810 94732 /* If an error occurs, we jump here */ 93811 94733 begin_table_error: 93812 94734 sqlite3DbFree(db, zName); 93813 94735 return; 93814 94736 } 93815 94737 93816 -/* 93817 -** This macro is used to compare two strings in a case-insensitive manner. 93818 -** It is slightly faster than calling sqlite3StrICmp() directly, but 93819 -** produces larger code. 93820 -** 93821 -** WARNING: This macro is not compatible with the strcmp() family. It 93822 -** returns true if the two strings are equal, otherwise false. 94738 +/* Set properties of a table column based on the (magical) 94739 +** name of the column. 93823 94740 */ 93824 -#define STRICMP(x, y) (\ 93825 -sqlite3UpperToLower[*(unsigned char *)(x)]== \ 93826 -sqlite3UpperToLower[*(unsigned char *)(y)] \ 93827 -&& sqlite3StrICmp((x)+1,(y)+1)==0 ) 94741 +#if SQLITE_ENABLE_HIDDEN_COLUMNS 94742 +SQLITE_PRIVATE void sqlite3ColumnPropertiesFromName(Table *pTab, Column *pCol){ 94743 + if( sqlite3_strnicmp(pCol->zName, "__hidden__", 10)==0 ){ 94744 + pCol->colFlags |= COLFLAG_HIDDEN; 94745 + }else if( pTab && pCol!=pTab->aCol && (pCol[-1].colFlags & COLFLAG_HIDDEN) ){ 94746 + pTab->tabFlags |= TF_OOOHidden; 94747 + } 94748 +} 94749 +#endif 94750 +